Some more work on gears
|
@ -68,7 +68,10 @@ jar {
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven { url 'file://var/www/maven/' }
|
maven {
|
||||||
|
name 'Calclavia Maven'
|
||||||
|
url 'http://calclavia.com/maven'
|
||||||
|
}
|
||||||
|
|
||||||
ivy {
|
ivy {
|
||||||
name 'CB FS'
|
name 'CB FS'
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package resonantinduction.electrical.generator;
|
package resonantinduction.electrical.generator;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.mechanical.network.IMechConnector;
|
import resonantinduction.mechanical.network.IMechanicalConnector;
|
||||||
import resonantinduction.mechanical.network.IMechMachine;
|
import resonantinduction.mechanical.network.IMechanical;
|
||||||
import universalelectricity.api.energy.EnergyStorageHandler;
|
import universalelectricity.api.energy.EnergyStorageHandler;
|
||||||
import calclavia.lib.prefab.tile.TileElectrical;
|
import calclavia.lib.prefab.tile.TileElectrical;
|
||||||
|
|
||||||
/** A kinetic energy to electrical energy converter.
|
/** A kinetic energy to electrical energy converter.
|
||||||
*
|
*
|
||||||
* @author Calclavia */
|
* @author Calclavia */
|
||||||
public class TileGenerator extends TileElectrical implements IMechMachine
|
public class TileGenerator extends TileElectrical implements IMechanical
|
||||||
{
|
{
|
||||||
//P = \tau \times 2 \pi \times \omega
|
//P = \tau \times 2 \pi \times \omega
|
||||||
private long power;
|
private long power;
|
||||||
|
|
|
@ -3,9 +3,9 @@ package resonantinduction.mechanical.belt;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import resonantinduction.api.IBelt;
|
import resonantinduction.api.IBelt;
|
||||||
import resonantinduction.api.IBeltNetwork;
|
import resonantinduction.api.IBeltNetwork;
|
||||||
import resonantinduction.mechanical.network.IMechConnector;
|
import resonantinduction.mechanical.network.IMechanicalConnector;
|
||||||
import resonantinduction.mechanical.network.IMechNetwork;
|
import resonantinduction.mechanical.network.IMechanicalNetwork;
|
||||||
import resonantinduction.mechanical.network.MechNetwork;
|
import resonantinduction.mechanical.network.MechanicalNetwork;
|
||||||
import universalelectricity.api.net.IConnector;
|
import universalelectricity.api.net.IConnector;
|
||||||
import universalelectricity.core.net.ConnectionPathfinder;
|
import universalelectricity.core.net.ConnectionPathfinder;
|
||||||
import universalelectricity.core.net.Network;
|
import universalelectricity.core.net.Network;
|
||||||
|
@ -122,13 +122,13 @@ public class BeltNetwork extends Network<IBeltNetwork, IBelt, TileEntity> implem
|
||||||
{
|
{
|
||||||
/** The connections A and B are not connected anymore. Give them both a new common
|
/** The connections A and B are not connected anymore. Give them both a new common
|
||||||
* network. */
|
* network. */
|
||||||
IMechNetwork newNetwork = new MechNetwork();
|
IMechanicalNetwork newNetwork = new MechanicalNetwork();
|
||||||
|
|
||||||
for (IConnector node : finder.closedSet)
|
for (IConnector node : finder.closedSet)
|
||||||
{
|
{
|
||||||
if (node instanceof IMechConnector)
|
if (node instanceof IMechanicalConnector)
|
||||||
{
|
{
|
||||||
newNetwork.addConnector((IMechConnector) node);
|
newNetwork.addConnector((IMechanicalConnector) node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -290,19 +290,19 @@ public class TileFluidNetwork extends TileEntityFluidDevice implements IFluidPar
|
||||||
@Override
|
@Override
|
||||||
public Packet getDescriptionPacket()
|
public Packet getDescriptionPacket()
|
||||||
{
|
{
|
||||||
return ResonantInduction.PACKET_TILE.getPacket(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
|
return ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_DESCRIPTION, this, this.colorID, this.renderSides, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendRenderUpdate()
|
public void sendRenderUpdate()
|
||||||
{
|
{
|
||||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(PACKET_RENDER, this, this.colorID, this.renderSides));
|
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_RENDER, this, this.colorID, this.renderSides));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendTankUpdate(int index)
|
public void sendTankUpdate(int index)
|
||||||
{
|
{
|
||||||
if (this.getInternalTank() != null && index == 0)
|
if (this.getInternalTank() != null && index == 0)
|
||||||
{
|
{
|
||||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(PACKET_TANK, this, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
|
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_TANK, this, this.getInternalTank().getCapacity(), this.getInternalTank().writeToNBT(new NBTTagCompound())), this.worldObj, new Vector3(this), 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import resonantinduction.mechanical.Mechanical;
|
import resonantinduction.mechanical.Mechanical;
|
||||||
import resonantinduction.mechanical.network.IMechConnector;
|
import resonantinduction.mechanical.network.IMechanicalConnector;
|
||||||
import resonantinduction.mechanical.network.IMechNetwork;
|
import resonantinduction.mechanical.network.IMechanicalNetwork;
|
||||||
import resonantinduction.mechanical.network.MechNetwork;
|
import resonantinduction.mechanical.network.MechanicalNetwork;
|
||||||
import universalelectricity.api.UniversalElectricity;
|
import universalelectricity.api.UniversalElectricity;
|
||||||
import codechicken.lib.data.MCDataInput;
|
import codechicken.lib.data.MCDataInput;
|
||||||
import codechicken.lib.data.MCDataOutput;
|
import codechicken.lib.data.MCDataOutput;
|
||||||
|
@ -30,11 +30,17 @@ import codechicken.multipart.TileMultipart;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart, IMechConnector
|
/**
|
||||||
|
* We assume all the force acting on the gear is 90 degrees.
|
||||||
|
*
|
||||||
|
* @author Calclavia
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart, IMechanicalConnector
|
||||||
{
|
{
|
||||||
public static Cuboid6[][] oBoxes = new Cuboid6[6][2];
|
public static Cuboid6[][] oBoxes = new Cuboid6[6][2];
|
||||||
|
|
||||||
private IMechNetwork network;
|
private IMechanicalNetwork network;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
|
@ -53,11 +59,27 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
||||||
/** Positive torque means it is spinning clockwise */
|
/** Positive torque means it is spinning clockwise */
|
||||||
private long torque = 0;
|
private long torque = 0;
|
||||||
|
|
||||||
|
private long force = 0;
|
||||||
|
|
||||||
|
/** The size of the gear */
|
||||||
|
private float radius = 0.5f;
|
||||||
|
|
||||||
|
/** The angular velocity, radians per second. */
|
||||||
|
private float angularVelocity = 0;
|
||||||
|
|
||||||
|
/** The current angle the gear is on. In radians. */
|
||||||
|
private float angle = 0;
|
||||||
|
|
||||||
public void preparePlacement(int side, int itemDamage)
|
public void preparePlacement(int side, int itemDamage)
|
||||||
{
|
{
|
||||||
this.placementSide = ForgeDirection.getOrientation((byte) (side ^ 1));
|
this.placementSide = ForgeDirection.getOrientation((byte) (side ^ 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getTorque()
|
||||||
|
{
|
||||||
|
return (long) (force * radius);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
|
@ -224,18 +246,18 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMechNetwork getNetwork()
|
public IMechanicalNetwork getNetwork()
|
||||||
{
|
{
|
||||||
if (this.network == null)
|
if (this.network == null)
|
||||||
{
|
{
|
||||||
this.network = new MechNetwork();
|
this.network = new MechanicalNetwork();
|
||||||
this.network.addConnector(this);
|
this.network.addConnector(this);
|
||||||
}
|
}
|
||||||
return this.network;
|
return this.network;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNetwork(IMechNetwork network)
|
public void setNetwork(IMechanicalNetwork network)
|
||||||
{
|
{
|
||||||
this.network = network;
|
this.network = network;
|
||||||
}
|
}
|
||||||
|
@ -243,7 +265,7 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
|
||||||
@Override
|
@Override
|
||||||
public boolean canConnect(ForgeDirection direction)
|
public boolean canConnect(ForgeDirection direction)
|
||||||
{
|
{
|
||||||
return new universalelectricity.api.vector.Vector3(this.x() + direction.offsetX, this.y() + direction.offsetY, this.z() + direction.offsetZ).getTileEntity(this.world()) instanceof IMechConnector;
|
return new universalelectricity.api.vector.Vector3(this.x() + direction.offsetX, this.y() + direction.offsetY, this.z() + direction.offsetZ).getTileEntity(this.world()) instanceof IMechanicalConnector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
package resonantinduction.mechanical.network;
|
|
||||||
|
|
||||||
import universalelectricity.api.net.INetwork;
|
|
||||||
|
|
||||||
/** Mechanical network in interface form for interaction or extension
|
|
||||||
*
|
|
||||||
* @author DarkGuardsman */
|
|
||||||
public interface IMechNetwork extends INetwork<IMechNetwork, IMechConnector, IMechMachine>
|
|
||||||
{
|
|
||||||
/** Power applied by the network at the given speed */
|
|
||||||
public int getTorque();
|
|
||||||
|
|
||||||
/** Rotation of the the network in a single update */
|
|
||||||
public int getRotationPerTick();
|
|
||||||
|
|
||||||
/** Called to rebuild the network */
|
|
||||||
public void reconstruct();
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ import universalelectricity.api.net.IConnectable;
|
||||||
/** Applied to machines that connect to a mech network
|
/** Applied to machines that connect to a mech network
|
||||||
*
|
*
|
||||||
* @author Darkguardsman */
|
* @author Darkguardsman */
|
||||||
public interface IMechMachine extends IConnectable
|
public interface IMechanical extends IConnectable
|
||||||
{
|
{
|
||||||
/** Called by the network when its torque value changes. */
|
/** Called by the network when its torque value changes. */
|
||||||
public void onTorqueChange(ForgeDirection side, int speed);
|
public void onTorqueChange(ForgeDirection side, int speed);
|
|
@ -5,7 +5,7 @@ import universalelectricity.api.net.IConnector;
|
||||||
/** For the mechanical network.
|
/** For the mechanical network.
|
||||||
*
|
*
|
||||||
* @author Calclavia */
|
* @author Calclavia */
|
||||||
public interface IMechConnector extends IConnector<IMechNetwork>
|
public interface IMechanicalConnector extends IConnector<IMechanicalNetwork>
|
||||||
{
|
{
|
||||||
public int getResistance();
|
public int getResistance();
|
||||||
}
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package resonantinduction.mechanical.network;
|
||||||
|
|
||||||
|
import universalelectricity.api.net.INetwork;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mechanical network in interface form for interaction or extension
|
||||||
|
*
|
||||||
|
* @author DarkGuardsman
|
||||||
|
*/
|
||||||
|
public interface IMechanicalNetwork extends INetwork<IMechanicalNetwork, IMechanicalConnector, IMechanical>
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Gets the power of the network.
|
||||||
|
*
|
||||||
|
* @return Power in Watts.
|
||||||
|
*/
|
||||||
|
public long getPower();
|
||||||
|
|
||||||
|
/** Torque applied by the network at the given speed */
|
||||||
|
public int getTorque();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the angular velocity of the network.
|
||||||
|
* @return In radians per second.
|
||||||
|
*/
|
||||||
|
public int getAngularVelocity();
|
||||||
|
|
||||||
|
/** Called to rebuild the network */
|
||||||
|
public void reconstruct();
|
||||||
|
}
|
|
@ -1,234 +0,0 @@
|
||||||
package resonantinduction.mechanical.network;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
import universalelectricity.api.net.IConnector;
|
|
||||||
import universalelectricity.core.net.ConnectionPathfinder;
|
|
||||||
import universalelectricity.core.net.Network;
|
|
||||||
import universalelectricity.core.net.NetworkTickHandler;
|
|
||||||
|
|
||||||
/** Simple network to translate speed and force using mechanical rotation
|
|
||||||
*
|
|
||||||
* @author DarkGuardsman */
|
|
||||||
public class MechNetwork extends Network<IMechNetwork, IMechConnector, IMechMachine> implements IMechNetwork
|
|
||||||
{
|
|
||||||
private int force = 0;
|
|
||||||
private int speed = 0;
|
|
||||||
private int resistance = 0;
|
|
||||||
|
|
||||||
private HashMap<IMechMachine, ForceWrapper[]> forceMap = new HashMap<IMechMachine, ForceWrapper[]>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reconstruct()
|
|
||||||
{
|
|
||||||
if (this.getConnectors().size() > 0)
|
|
||||||
{
|
|
||||||
// Reset all values related to wires
|
|
||||||
this.getNodes().clear();
|
|
||||||
this.forceMap.clear();
|
|
||||||
this.resistance = 0;
|
|
||||||
this.force = 0;
|
|
||||||
this.speed = 0;
|
|
||||||
|
|
||||||
// Iterate threw list of wires
|
|
||||||
Iterator<IMechConnector> it = this.getConnectors().iterator();
|
|
||||||
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
IMechConnector conductor = it.next();
|
|
||||||
|
|
||||||
if (conductor != null)
|
|
||||||
{
|
|
||||||
this.reconstructConductor(conductor);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getNodes().size() > 0)
|
|
||||||
{
|
|
||||||
NetworkTickHandler.addNetwork(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Segmented out call so overriding can be done when conductors are reconstructed. */
|
|
||||||
protected void reconstructConductor(IMechConnector conductor)
|
|
||||||
{
|
|
||||||
conductor.setNetwork(this);
|
|
||||||
|
|
||||||
for (int i = 0; i < conductor.getConnections().length; i++)
|
|
||||||
{
|
|
||||||
reconstructHandler(conductor.getConnections()[i], ForgeDirection.getOrientation(i).getOpposite());
|
|
||||||
}
|
|
||||||
|
|
||||||
this.resistance += conductor.getResistance();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Segmented out call so overriding can be done when machines are reconstructed. */
|
|
||||||
protected void reconstructHandler(Object obj, ForgeDirection side)
|
|
||||||
{
|
|
||||||
if (obj != null && !(obj instanceof IMechConnector))
|
|
||||||
{
|
|
||||||
if (obj instanceof IMechMachine)
|
|
||||||
{
|
|
||||||
ForceWrapper[] set = this.forceMap.get((IMechMachine)obj);
|
|
||||||
if (set == null)
|
|
||||||
{
|
|
||||||
set = new ForceWrapper[6];
|
|
||||||
}
|
|
||||||
this.getNodes().add((IMechMachine) obj);
|
|
||||||
set[side.ordinal()] = new ForceWrapper(((IMechMachine) obj).getForceSide(side.getOpposite()),((IMechMachine) obj).getForceSide(side.getOpposite()));
|
|
||||||
this.forceMap.put((IMechMachine) obj, set);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canUpdate()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean continueUpdate()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMechNetwork merge(IMechNetwork network)
|
|
||||||
{
|
|
||||||
if (network.getClass().isAssignableFrom(this.getClass()) && network != this)
|
|
||||||
{
|
|
||||||
MechNetwork newNetwork = new MechNetwork();
|
|
||||||
newNetwork.getConnectors().addAll(this.getConnectors());
|
|
||||||
newNetwork.getConnectors().addAll(network.getConnectors());
|
|
||||||
|
|
||||||
network.getConnectors().clear();
|
|
||||||
network.getNodes().clear();
|
|
||||||
this.getConnectors().clear();
|
|
||||||
this.getNodes().clear();
|
|
||||||
|
|
||||||
newNetwork.reconstruct();
|
|
||||||
return newNetwork;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void split(IMechConnector splitPoint)
|
|
||||||
{
|
|
||||||
this.removeConnector(splitPoint);
|
|
||||||
this.reconstruct();
|
|
||||||
|
|
||||||
/** Loop through the connected blocks and attempt to see if there are connections between the
|
|
||||||
* two points elsewhere. */
|
|
||||||
Object[] connectedBlocks = splitPoint.getConnections();
|
|
||||||
|
|
||||||
for (int i = 0; i < connectedBlocks.length; i++)
|
|
||||||
{
|
|
||||||
Object connectedBlockA = connectedBlocks[i];
|
|
||||||
|
|
||||||
if (connectedBlockA instanceof IMechConnector)
|
|
||||||
{
|
|
||||||
for (int ii = 0; ii < connectedBlocks.length; ii++)
|
|
||||||
{
|
|
||||||
final Object connectedBlockB = connectedBlocks[ii];
|
|
||||||
|
|
||||||
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof IMechConnector)
|
|
||||||
{
|
|
||||||
ConnectionPathfinder finder = new ConnectionPathfinder((IConnector) connectedBlockB, splitPoint);
|
|
||||||
finder.findNodes((IConnector) connectedBlockA);
|
|
||||||
|
|
||||||
if (finder.results.size() <= 0)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
/** The connections A and B are not connected anymore. Give them both
|
|
||||||
* a new common network. */
|
|
||||||
IMechNetwork newNetwork = new MechNetwork();
|
|
||||||
for (IConnector node : finder.closedSet)
|
|
||||||
{
|
|
||||||
if (node != splitPoint && node instanceof IMechConnector)
|
|
||||||
{
|
|
||||||
newNetwork.addConnector((IMechConnector) node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
newNetwork.reconstruct();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void split(IMechConnector connectorA, IMechConnector connectorB)
|
|
||||||
{
|
|
||||||
this.reconstruct();
|
|
||||||
|
|
||||||
/** Check if connectorA connects with connectorB. */
|
|
||||||
ConnectionPathfinder finder = new ConnectionPathfinder(connectorB);
|
|
||||||
finder.findNodes(connectorA);
|
|
||||||
|
|
||||||
if (finder.results.size() <= 0)
|
|
||||||
{
|
|
||||||
/** The connections A and B are not connected anymore. Give them both a new common
|
|
||||||
* network. */
|
|
||||||
IMechNetwork newNetwork = new MechNetwork();
|
|
||||||
|
|
||||||
for (IConnector node : finder.closedSet)
|
|
||||||
{
|
|
||||||
if (node instanceof IMechConnector)
|
|
||||||
{
|
|
||||||
newNetwork.addConnector((IMechConnector) node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newNetwork.reconstruct();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTorque()
|
|
||||||
{
|
|
||||||
return this.force;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRotationPerTick()
|
|
||||||
{
|
|
||||||
return this.speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ForceWrapper
|
|
||||||
{
|
|
||||||
public int force = 0;
|
|
||||||
public int speed = 0;
|
|
||||||
|
|
||||||
public ForceWrapper(int force, int speed)
|
|
||||||
{
|
|
||||||
this.force = force;
|
|
||||||
this.speed = speed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,259 @@
|
||||||
|
package resonantinduction.mechanical.network;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
import universalelectricity.api.net.IConnector;
|
||||||
|
import universalelectricity.core.net.ConnectionPathfinder;
|
||||||
|
import universalelectricity.core.net.Network;
|
||||||
|
import universalelectricity.core.net.NetworkTickHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A mechanical network for translate speed and force using mechanical rotations.
|
||||||
|
*
|
||||||
|
* Useful Formula:
|
||||||
|
*
|
||||||
|
* Power is the work per unit time.
|
||||||
|
* Power (W) = Torque (Strength of the rotation, Newton Meters) x Speed (Angular Velocity, RADIAN
|
||||||
|
* PER SECOND).
|
||||||
|
* *OR*
|
||||||
|
* Power = Torque / Time
|
||||||
|
*
|
||||||
|
* Torque = r (Radius) * F (Force) * sin0 (Direction/Angle of the force applied. 90 degrees if
|
||||||
|
* optimal.)
|
||||||
|
*
|
||||||
|
* @author DarkGuardsman
|
||||||
|
*/
|
||||||
|
public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalConnector, IMechanical> implements IMechanicalNetwork
|
||||||
|
{
|
||||||
|
private int force = 0;
|
||||||
|
private int speed = 0;
|
||||||
|
private int resistance = 0;
|
||||||
|
|
||||||
|
private HashMap<IMechanical, ForceWrapper[]> forceMap = new HashMap<IMechanical, ForceWrapper[]>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reconstruct()
|
||||||
|
{
|
||||||
|
if (this.getConnectors().size() > 0)
|
||||||
|
{
|
||||||
|
// Reset all values related to wires
|
||||||
|
this.getNodes().clear();
|
||||||
|
this.forceMap.clear();
|
||||||
|
this.resistance = 0;
|
||||||
|
this.force = 0;
|
||||||
|
this.speed = 0;
|
||||||
|
|
||||||
|
// Iterate threw list of wires
|
||||||
|
Iterator<IMechanicalConnector> it = this.getConnectors().iterator();
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
IMechanicalConnector conductor = it.next();
|
||||||
|
|
||||||
|
if (conductor != null)
|
||||||
|
{
|
||||||
|
this.reconstructConductor(conductor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getNodes().size() > 0)
|
||||||
|
{
|
||||||
|
NetworkTickHandler.addNetwork(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Segmented out call so overriding can be done when conductors are reconstructed. */
|
||||||
|
protected void reconstructConductor(IMechanicalConnector conductor)
|
||||||
|
{
|
||||||
|
conductor.setNetwork(this);
|
||||||
|
|
||||||
|
for (int i = 0; i < conductor.getConnections().length; i++)
|
||||||
|
{
|
||||||
|
reconstructHandler(conductor.getConnections()[i], ForgeDirection.getOrientation(i).getOpposite());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.resistance += conductor.getResistance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Segmented out call so overriding can be done when machines are reconstructed. */
|
||||||
|
protected void reconstructHandler(Object obj, ForgeDirection side)
|
||||||
|
{
|
||||||
|
if (obj != null && !(obj instanceof IMechanicalConnector))
|
||||||
|
{
|
||||||
|
if (obj instanceof IMechanical)
|
||||||
|
{
|
||||||
|
ForceWrapper[] set = this.forceMap.get((IMechanical) obj);
|
||||||
|
if (set == null)
|
||||||
|
{
|
||||||
|
set = new ForceWrapper[6];
|
||||||
|
}
|
||||||
|
this.getNodes().add((IMechanical) obj);
|
||||||
|
set[side.ordinal()] = new ForceWrapper(((IMechanical) obj).getForceSide(side.getOpposite()), ((IMechanical) obj).getForceSide(side.getOpposite()));
|
||||||
|
this.forceMap.put((IMechanical) obj, set);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUpdate()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean continueUpdate()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMechanicalNetwork merge(IMechanicalNetwork network)
|
||||||
|
{
|
||||||
|
if (network.getClass().isAssignableFrom(this.getClass()) && network != this)
|
||||||
|
{
|
||||||
|
MechanicalNetwork newNetwork = new MechanicalNetwork();
|
||||||
|
newNetwork.getConnectors().addAll(this.getConnectors());
|
||||||
|
newNetwork.getConnectors().addAll(network.getConnectors());
|
||||||
|
|
||||||
|
network.getConnectors().clear();
|
||||||
|
network.getNodes().clear();
|
||||||
|
this.getConnectors().clear();
|
||||||
|
this.getNodes().clear();
|
||||||
|
|
||||||
|
newNetwork.reconstruct();
|
||||||
|
return newNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void split(IMechanicalConnector splitPoint)
|
||||||
|
{
|
||||||
|
this.removeConnector(splitPoint);
|
||||||
|
this.reconstruct();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loop through the connected blocks and attempt to see if there are connections between the
|
||||||
|
* two points elsewhere.
|
||||||
|
*/
|
||||||
|
Object[] connectedBlocks = splitPoint.getConnections();
|
||||||
|
|
||||||
|
for (int i = 0; i < connectedBlocks.length; i++)
|
||||||
|
{
|
||||||
|
Object connectedBlockA = connectedBlocks[i];
|
||||||
|
|
||||||
|
if (connectedBlockA instanceof IMechanicalConnector)
|
||||||
|
{
|
||||||
|
for (int ii = 0; ii < connectedBlocks.length; ii++)
|
||||||
|
{
|
||||||
|
final Object connectedBlockB = connectedBlocks[ii];
|
||||||
|
|
||||||
|
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof IMechanicalConnector)
|
||||||
|
{
|
||||||
|
ConnectionPathfinder finder = new ConnectionPathfinder((IConnector) connectedBlockB, splitPoint);
|
||||||
|
finder.findNodes((IConnector) connectedBlockA);
|
||||||
|
|
||||||
|
if (finder.results.size() <= 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connections A and B are not connected anymore. Give them both
|
||||||
|
* a new common network.
|
||||||
|
*/
|
||||||
|
IMechanicalNetwork newNetwork = new MechanicalNetwork();
|
||||||
|
for (IConnector node : finder.closedSet)
|
||||||
|
{
|
||||||
|
if (node != splitPoint && node instanceof IMechanicalConnector)
|
||||||
|
{
|
||||||
|
newNetwork.addConnector((IMechanicalConnector) node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newNetwork.reconstruct();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void split(IMechanicalConnector connectorA, IMechanicalConnector connectorB)
|
||||||
|
{
|
||||||
|
this.reconstruct();
|
||||||
|
|
||||||
|
/** Check if connectorA connects with connectorB. */
|
||||||
|
ConnectionPathfinder finder = new ConnectionPathfinder(connectorB);
|
||||||
|
finder.findNodes(connectorA);
|
||||||
|
|
||||||
|
if (finder.results.size() <= 0)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connections A and B are not connected anymore. Give them both a new common
|
||||||
|
* network.
|
||||||
|
*/
|
||||||
|
IMechanicalNetwork newNetwork = new MechanicalNetwork();
|
||||||
|
|
||||||
|
for (IConnector node : finder.closedSet)
|
||||||
|
{
|
||||||
|
if (node instanceof IMechanicalConnector)
|
||||||
|
{
|
||||||
|
newNetwork.addConnector((IMechanicalConnector) node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newNetwork.reconstruct();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTorque()
|
||||||
|
{
|
||||||
|
return this.force;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAngularVelocity()
|
||||||
|
{
|
||||||
|
return this.speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ForceWrapper
|
||||||
|
{
|
||||||
|
public int force = 0;
|
||||||
|
public int speed = 0;
|
||||||
|
|
||||||
|
public ForceWrapper(int force, int speed)
|
||||||
|
{
|
||||||
|
this.force = force;
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPower()
|
||||||
|
{
|
||||||
|
return this.getTorque() * this.getAngularVelocity();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.2 KiB |