Added gear disabling upon wrong rotation

This commit is contained in:
Calclavia 2014-01-21 18:37:45 +08:00
parent 5bc0d45912
commit 18ae602065
6 changed files with 30 additions and 11 deletions

View file

@ -30,7 +30,7 @@ public class PartGear extends PartMechanical implements IMechanical
{
if (manualCrankTime > 0)
{
getNetwork().onReceiveEnergy(this, 20, 0.2f);
getNetwork().onReceiveEnergy(this, 20, 0.4f);
manualCrankTime--;
}
}
@ -62,7 +62,7 @@ public class PartGear extends PartMechanical implements IMechanical
else
{
this.manualCrankTime = 20;
this.manualCrankTime = 10;
}
}

View file

@ -38,4 +38,9 @@ public interface IMechanicalNetwork extends INetwork<IMechanicalNetwork, IMechan
* @return The current rotation value of the network.
*/
public float getRotation();
/**
* Disables the network due to rotation issues.
*/
public void setDisabled();
}

View file

@ -56,6 +56,7 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
private Set<IMechanical> prevGenerators = new LinkedHashSet<IMechanical>();
private Set<IMechanical> generators = new LinkedHashSet<IMechanical>();
private boolean disabled;
@Override
public void addConnector(IMechanical connector)
@ -117,7 +118,7 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
@Override
public boolean canUpdate()
{
return true;
return !disabled;
}
@Override
@ -133,9 +134,10 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
{
for (IMechanical connector : this.getConnectors())
{
if (connector instanceof TileEntity)
int[] location = connector.getLocation();
if (location != null)
{
int[] location = connector.getLocation();
PacketDispatcher.sendPacketToAllPlayers(Mechanical.PACKET_NETWORK.getPacket(location[0], location[1], location[2], location[3], (byte) 0, torque, angularVelocity));
break;
}
@ -145,7 +147,9 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
public void sendRotationUpdatePacket(IMechanical connector)
{
int[] location = connector.getLocation();
PacketDispatcher.sendPacketToAllPlayers(Mechanical.PACKET_NETWORK.getPacket(location[0], location[1], location[2], location[3], (byte) 1, connector.isClockwise()));
if (location != null)
PacketDispatcher.sendPacketToAllPlayers(Mechanical.PACKET_NETWORK.getPacket(location[0], location[1], location[2], location[3], (byte) 1, connector.isClockwise()));
}
@Override
@ -163,7 +167,6 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
updateNode.setClockwise(data.readBoolean());
PathfinderUpdateRotation rotationPathfinder = new PathfinderUpdateRotation(updateNode, this, null);
rotationPathfinder.findNodes(updateNode);
System.out.println("UPDATE");
break;
}
}
@ -229,6 +232,7 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
@Override
public void reconstruct()
{
disabled = false;
// Reset
prevTorque = torque = 0;
prevAngularVelocity = angularVelocity = 0;
@ -277,6 +281,13 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
return rotation;
}
@Override
public void setDisabled()
{
System.out.println("NETWORK DISABLED");
disabled = true;
}
@Override
public IMechanicalNetwork newInstance()
{
@ -294,4 +305,5 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
{
return this.getClass().getSimpleName() + "[" + this.hashCode() + ", Handlers: " + getConnectors().size() + ", Connectors: " + getConnectors().size() + ", Power:" + getPower() + "]";
}
}

View file

@ -49,7 +49,7 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
protected Object[] connections = new Object[6];
/** Side of the block this is placed on */
public ForgeDirection placementSide;
public ForgeDirection placementSide = ForgeDirection.UNKNOWN;
/** The size of the gear */
private float radius = 0.5f;
@ -318,6 +318,8 @@ public abstract class PartMechanical extends JCuboidPart implements JNormalOcclu
@Override
public int[] getLocation()
{
return new int[] { x(), y(), z(), placementSide.ordinal() };
if (tile() != null)
return new int[] { x(), y(), z(), placementSide.ordinal() };
return null;
}
}

View file

@ -48,7 +48,7 @@ public class PathfinderUpdateRotation extends ConnectionPathfinder<IMechanical>
if ((prevClosedSet != null && prevClosedSet.contains(node)) && (node.isClockwise() != currentRotationFlag))
{
// We have conflicting rotations. Network is now stuck.
network.setPower(0, 0);
network.setDisabled();
}
findNodes(node);

View file

@ -62,7 +62,7 @@ public abstract class TileMechanical extends TileAdvanced implements IMechanical
@Override
public boolean isRotationInversed()
{
return false;
return true;
}
@Override