Added mechanical resistance
This commit is contained in:
parent
2cfd22a8d3
commit
8cab946411
3 changed files with 26 additions and 21 deletions
|
@ -111,8 +111,9 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onNetworkChanged()
|
||||
public float getResistance()
|
||||
{
|
||||
return 0.1f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -337,7 +338,10 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
|||
@Override
|
||||
public void sendNetworkPacket(long torque, float angularVelocity)
|
||||
{
|
||||
tile().getWriteStream(this).writeByte(0).writeLong(torque).writeFloat(angularVelocity).writeBoolean(isClockwise);
|
||||
if (tile() != null)
|
||||
{
|
||||
tile().getWriteStream(this).writeByte(0).writeLong(torque).writeFloat(angularVelocity).writeBoolean(isClockwise);
|
||||
}
|
||||
}
|
||||
|
||||
public void read(MCDataInput packet, int packetID)
|
||||
|
|
|
@ -10,13 +10,15 @@ import universalelectricity.api.net.IConnector;
|
|||
*/
|
||||
public interface IMechanicalConnector extends IMechanical, IConnector<IMechanicalNetwork>
|
||||
{
|
||||
/**
|
||||
* An update called by the network.
|
||||
*/
|
||||
public void onNetworkChanged();
|
||||
|
||||
/**
|
||||
* Uses this connector to send a packet to the client.
|
||||
*/
|
||||
public void sendNetworkPacket(long torque, float angularVelocity);
|
||||
|
||||
/**
|
||||
* The percentage of resistance caused by this connector.
|
||||
*
|
||||
* @return A small value, most likely less than one.
|
||||
*/
|
||||
public float getResistance();
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
|
|||
private long torque = 0;
|
||||
private float angularVelocity = 0;
|
||||
|
||||
/** The cached resistance caused by all connectors */
|
||||
private float connectorResistance = 0;
|
||||
|
||||
/** The direction in which a conductor is placed relative to a specific conductor. */
|
||||
protected final HashMap<Object, EnumSet<ForgeDirection>> handlerDirectionMap = new LinkedHashMap<Object, EnumSet<ForgeDirection>>();
|
||||
|
||||
|
@ -49,7 +52,7 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
|
|||
*/
|
||||
if (getPower() > 0)
|
||||
{
|
||||
float division = 0;
|
||||
float division = connectorResistance;
|
||||
|
||||
for (IMechanical node : this.getNodes())
|
||||
{
|
||||
|
@ -74,17 +77,10 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
|
|||
/**
|
||||
* Send network update packet for connectors.
|
||||
*/
|
||||
boolean isFirst = true;
|
||||
|
||||
for (IMechanicalConnector connector : this.getConnectors())
|
||||
{
|
||||
if (isFirst)
|
||||
{
|
||||
connector.sendNetworkPacket(torque, angularVelocity);
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
connector.onNetworkChanged();
|
||||
connector.sendNetworkPacket(torque, angularVelocity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,6 +170,11 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
|
|||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
// Reset
|
||||
prevTorque = torque = 0;
|
||||
prevAngularVelocity = angularVelocity = 0;
|
||||
connectorResistance = 0;
|
||||
|
||||
if (this.getConnectors().size() > 0)
|
||||
{
|
||||
// Reset all values related to wires
|
||||
|
@ -196,10 +197,6 @@ 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. */
|
||||
|
@ -211,6 +208,8 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
|
|||
{
|
||||
reconstructHandler(connector.getConnections()[i], ForgeDirection.getOrientation(i).getOpposite());
|
||||
}
|
||||
|
||||
connectorResistance += connector.getResistance();
|
||||
}
|
||||
|
||||
/** Segmented out call so overriding can be done when machines are reconstructed. */
|
||||
|
|
Loading…
Reference in a new issue