Added ability to change torque to velocity ratio in generator
This commit is contained in:
parent
883930a1bf
commit
a5c124eeac
4 changed files with 41 additions and 16 deletions
|
@ -35,6 +35,23 @@ public class BlockGenerator extends BlockRIRotatable
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileGenerator)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
entityPlayer.addChatMessage("Generator torque ratio: " + ((TileGenerator) tileEntity).toggleRatio());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world)
|
||||
{
|
||||
|
|
|
@ -19,12 +19,19 @@ public class TileGenerator extends TileElectrical implements IMechanical
|
|||
/** Generator turns KE -> EE. Inverted one will turn EE -> KE. */
|
||||
public boolean isInversed = false;
|
||||
|
||||
private float torqueRatio = 500;
|
||||
|
||||
public TileGenerator()
|
||||
{
|
||||
energy = new EnergyStorageHandler(10000, 1000);
|
||||
energy = new EnergyStorageHandler(10000);
|
||||
this.ioMap = 728;
|
||||
}
|
||||
|
||||
public float toggleRatio()
|
||||
{
|
||||
return torqueRatio = (torqueRatio + 100) % energy.getMaxExtract();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
|
@ -44,7 +51,11 @@ public class TileGenerator extends TileElectrical implements IMechanical
|
|||
long extract = energy.extractEnergy();
|
||||
|
||||
if (extract > 0)
|
||||
((IMechanical) mechanical).onReceiveEnergy(getOuputDirection().getOpposite(), (long) (500), extract / 500f);
|
||||
{
|
||||
float angularVelocity = extract / torqueRatio;
|
||||
long torque = (long) (extract / angularVelocity);
|
||||
((IMechanical) mechanical).onReceiveEnergy(getOuputDirection().getOpposite(), torque, angularVelocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,11 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
@Override
|
||||
public void update()
|
||||
{
|
||||
if (markRotationUpdate)
|
||||
{
|
||||
updateRotations();
|
||||
}
|
||||
|
||||
if (!this.world().isRemote)
|
||||
{
|
||||
if (manualCrankTime > 0)
|
||||
|
@ -91,11 +96,6 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
}
|
||||
else
|
||||
{
|
||||
if (markRotationUpdate)
|
||||
{
|
||||
updateRotations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update angle rotation.
|
||||
*/
|
||||
|
@ -110,13 +110,6 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
@Override
|
||||
public void onNetworkChanged()
|
||||
{
|
||||
if (world() != null)
|
||||
{
|
||||
if (markRotationUpdate)
|
||||
{
|
||||
updateRotations();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -338,7 +331,7 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
|
||||
@Override
|
||||
public void sendNetworkPacket(long torque, float angularVelocity)
|
||||
{System.out.println("SEND");
|
||||
{
|
||||
tile().getWriteStream(this).writeByte(0).writeLong(torque).writeFloat(angularVelocity).writeBoolean(isClockwise);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
|
|||
connector.sendNetworkPacket(torque, angularVelocity);
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
|
||||
connector.onNetworkChanged();
|
||||
}
|
||||
}
|
||||
|
@ -162,6 +162,10 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset energy.
|
||||
prevTorque = torque = 0;
|
||||
prevAngularVelocity = angularVelocity = 0;
|
||||
}
|
||||
|
||||
/** Segmented out call so overriding can be done when conductors are reconstructed. */
|
||||
|
|
Loading…
Reference in a new issue