Gears now work omni-directional
This commit is contained in:
parent
4c4423e282
commit
102db7356d
5 changed files with 201 additions and 170 deletions
|
@ -19,7 +19,7 @@ public class TileGenerator extends TileElectrical implements IMechanical
|
|||
|
||||
public TileGenerator()
|
||||
{
|
||||
energy = new EnergyStorageHandler(10000);
|
||||
energy = new EnergyStorageHandler(10000, 100);
|
||||
this.ioMap = 728;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class TileGenerator extends TileElectrical implements IMechanical
|
|||
{
|
||||
if (!isInversed)
|
||||
{
|
||||
this.energy.receiveEnergy(power, true);
|
||||
this.power -= this.energy.receiveEnergy(power, true);
|
||||
this.produce();
|
||||
}
|
||||
else
|
||||
|
@ -51,6 +51,12 @@ public class TileGenerator extends TileElectrical implements IMechanical
|
|||
this.power = (long) Math.abs(torque * speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPower()
|
||||
{
|
||||
return this.power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTorqueChange(ForgeDirection side, int speed)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@ public class RenderPipe extends TileEntitySpecialRenderer
|
|||
public static ModelPipe MODEL_PIPE = new ModelPipe();
|
||||
public static ModelOpenTrough MODEL_TROUGH_PIPE = new ModelOpenTrough();
|
||||
private static HashMap<Pair<FluidContainerMaterial, Integer>, ResourceLocation> TEXTURES = new HashMap<Pair<FluidContainerMaterial, Integer>, ResourceLocation>();
|
||||
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_DIRECTORY + "pipe/iron.png");
|
||||
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "pipe/iron.png");
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity te, double d, double d1, double d2, float f)
|
||||
|
|
|
@ -77,18 +77,17 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
|
||||
public long getTorque()
|
||||
{
|
||||
return (long) (force * radius);
|
||||
return (long) torque;// (force * radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
/**
|
||||
* Update angle rotation.
|
||||
*/
|
||||
if (angularVelocity > 0 && torque > 0)
|
||||
|
||||
if (angularVelocity < 0 || torque == 0)
|
||||
{
|
||||
angle += angularVelocity / 20;
|
||||
angularVelocity = 0;
|
||||
torque = 0;
|
||||
}
|
||||
|
||||
// TODO: Should we average the torque?
|
||||
|
@ -103,12 +102,12 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
|
||||
if (part instanceof PartGear)
|
||||
{
|
||||
torque = (torque + ((PartGear) part).torque) / 2;
|
||||
((PartGear) part).torque = torque;
|
||||
equatePower((PartGear) part, false);
|
||||
}
|
||||
}
|
||||
else if (tile instanceof IMechanical)
|
||||
{
|
||||
torque = (long) (((IMechanical) tile).getPower() / angularVelocity);
|
||||
((IMechanical) tile).setPower(torque, angularVelocity);
|
||||
}
|
||||
|
||||
|
@ -124,10 +123,9 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
{
|
||||
TMultiPart neighbor = ((TileMultipart) checkTile).partMap(this.placementSide.ordinal());
|
||||
|
||||
if (neighbor instanceof PartGear)
|
||||
if (neighbor != this && neighbor instanceof PartGear)
|
||||
{
|
||||
torque = (torque - ((PartGear) neighbor).torque) / 2;
|
||||
((PartGear) neighbor).torque = -torque;
|
||||
equatePower((PartGear) neighbor, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,28 +134,53 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
// TODO: Make it work with UP-DOWN
|
||||
if (i < 2)
|
||||
if (i < 4)
|
||||
{
|
||||
TMultiPart neighbor = tile().partMap(this.placementSide.getRotation(ForgeDirection.getOrientation(i)).ordinal());
|
||||
|
||||
if (neighbor instanceof PartGear)
|
||||
if (neighbor != this && neighbor instanceof PartGear)
|
||||
{
|
||||
equatePower((PartGear) neighbor, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update angle rotation.
|
||||
*/
|
||||
if (angularVelocity > 0 && torque != 0)
|
||||
{
|
||||
angle += angularVelocity / 20;
|
||||
}
|
||||
}
|
||||
|
||||
public void equatePower(PartGear neighbor, boolean isPositive)
|
||||
{
|
||||
if (isPositive)
|
||||
{
|
||||
torque = (torque + ((PartGear) neighbor).torque) / 2;
|
||||
((PartGear) neighbor).torque = torque;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
torque = (torque - ((PartGear) neighbor).torque) / 2;
|
||||
((PartGear) neighbor).torque = -torque;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
angularVelocity = (angularVelocity + ((PartGear) neighbor).angularVelocity) / 2;
|
||||
((PartGear) neighbor).angularVelocity = angularVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item)
|
||||
{
|
||||
System.out.println("Torque" + this.torque + " Angular Velocity" + this.angularVelocity);
|
||||
System.out.println("Torque" + torque + " Angular Velocity" + angularVelocity);
|
||||
|
||||
if (player.isSneaking())
|
||||
{
|
||||
this.torque += 10;
|
||||
this.angularVelocity += 0.1f;
|
||||
this.angularVelocity += 0.2f;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -63,7 +63,7 @@ public class RenderGear
|
|||
break;
|
||||
}
|
||||
|
||||
GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0);
|
||||
GL11.glRotatef((float) Math.toDegrees(part.angle) * (part.getTorque() > 0 ? 1 : -1), 0, 1, 0);
|
||||
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
||||
MODEL.renderAll();
|
||||
|
|
|
@ -12,6 +12,8 @@ public interface IMechanical extends IConnectable
|
|||
{
|
||||
public void setPower(long torque, float speed);
|
||||
|
||||
public long getPower();
|
||||
|
||||
/** Called by the network when its torque value changes. */
|
||||
public void onTorqueChange(ForgeDirection side, int speed);
|
||||
|
||||
|
|
Loading…
Reference in a new issue