Multimeters now have a network
This commit is contained in:
parent
356edf9b62
commit
8b8d2b9ee7
3 changed files with 189 additions and 8 deletions
|
@ -65,13 +65,11 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryNet
|
|||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
for (Object obj : getConnections())
|
||||
{
|
||||
TileEntity tile = new Vector3(this).translate(dir).getTileEntity(this.worldObj);
|
||||
|
||||
if (tile instanceof TileBattery)
|
||||
if (obj instanceof TileBattery)
|
||||
{
|
||||
this.getNetwork().merge(((TileBattery) tile).getNetwork());
|
||||
this.getNetwork().merge(((TileBattery) obj).getNetwork());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package resonantinduction.electrical.multimeter;
|
||||
|
||||
import universalelectricity.api.vector.Vector2;
|
||||
import universalelectricity.core.net.Network;
|
||||
|
||||
public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter>
|
||||
{
|
||||
/**
|
||||
* The absolute center of the multimeter screens.
|
||||
*/
|
||||
public Vector2 center = new Vector2();
|
||||
|
||||
/**
|
||||
* The relative bound sizes.
|
||||
*/
|
||||
public Vector2 upperBound = new Vector2();
|
||||
public Vector2 lowerBound = new Vector2();
|
||||
|
||||
@Override
|
||||
public void reconstruct()
|
||||
{
|
||||
super.reconstruct();
|
||||
center = upperBound.midPoint(lowerBound);
|
||||
upperBound.subtract(center);
|
||||
lowerBound.subtract(center);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reconstructConnector(PartMultimeter node)
|
||||
{
|
||||
node.setNetwork(this);
|
||||
|
||||
/**
|
||||
* Computer upper bound
|
||||
*/
|
||||
if (node.getPosition().y > upperBound.x)
|
||||
{
|
||||
upperBound.x = node.getPosition().y;
|
||||
}
|
||||
|
||||
if (node.getDirection().offsetX == 0)
|
||||
{
|
||||
if (node.getPosition().x > upperBound.y)
|
||||
{
|
||||
upperBound.y = node.getPosition().x;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.getDirection().offsetZ == 0)
|
||||
{
|
||||
if (node.getPosition().z > upperBound.y)
|
||||
{
|
||||
upperBound.y = node.getPosition().z;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computer lower bound
|
||||
*/
|
||||
if (node.getPosition().y < lowerBound.x)
|
||||
{
|
||||
lowerBound.x = node.getPosition().y;
|
||||
}
|
||||
|
||||
if (node.getDirection().offsetX == 0)
|
||||
{
|
||||
if (node.getPosition().x < lowerBound.y)
|
||||
{
|
||||
lowerBound.y = node.getPosition().x;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.getDirection().offsetZ == 0)
|
||||
{
|
||||
if (node.getPosition().z < lowerBound.y)
|
||||
{
|
||||
lowerBound.y = node.getPosition().z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultimeterNetwork newInstance()
|
||||
{
|
||||
return new MultimeterNetwork();
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ import net.minecraft.util.MovingObjectPosition;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.electrical.Electrical;
|
||||
import resonantinduction.electrical.battery.TileBattery;
|
||||
import universalelectricity.api.CompatibilityModule;
|
||||
import universalelectricity.api.energy.IConductor;
|
||||
import universalelectricity.api.energy.IEnergyNetwork;
|
||||
|
@ -49,7 +50,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcclusion, IRedstonePart, IPacketReceiver
|
||||
public class PartMultimeter extends JCuboidPart implements IConnector<MultimeterNetwork>, TFacePart, JNormalOcclusion, IRedstonePart, IPacketReceiver
|
||||
{
|
||||
public static Cuboid6[][] bounds = new Cuboid6[6][2];
|
||||
|
||||
|
@ -89,6 +90,9 @@ public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcc
|
|||
private byte side;
|
||||
private int ticks;
|
||||
|
||||
private MultimeterNetwork network;
|
||||
|
||||
public List<String> displayInformation;
|
||||
public Graph graph;
|
||||
|
||||
public void preparePlacement(int side, int itemDamage)
|
||||
|
@ -97,6 +101,46 @@ public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcc
|
|||
}
|
||||
|
||||
public boolean hasMultimeter(int x, int y, int z)
|
||||
{
|
||||
return getMultimeter(x, y, z) != null;
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
if (!world().isRemote)
|
||||
{
|
||||
for (Object obj : getConnections())
|
||||
{
|
||||
if (obj instanceof PartMultimeter)
|
||||
{
|
||||
this.getNetwork().merge(((PartMultimeter) obj).getNetwork());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldJoin()
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartChanged(TMultiPart part)
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the multimeter on the same plane.
|
||||
*/
|
||||
public PartMultimeter getMultimeter(int x, int y, int z)
|
||||
{
|
||||
TileEntity tileEntity = world().getBlockTileEntity(x, y, z);
|
||||
|
||||
|
@ -106,11 +150,11 @@ public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcc
|
|||
|
||||
if (part instanceof PartMultimeter)
|
||||
{
|
||||
return true;
|
||||
return (PartMultimeter) part;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -415,4 +459,56 @@ public class PartMultimeter extends JCuboidPart implements TFacePart, JNormalOcc
|
|||
return redstoneOn ? 14 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultimeterNetwork getNetwork()
|
||||
{
|
||||
if (network == null)
|
||||
{
|
||||
network = new MultimeterNetwork();
|
||||
network.addConnector(this);
|
||||
}
|
||||
|
||||
return network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(MultimeterNetwork network)
|
||||
{
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
Object[] connections = new Object[6];
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
universalelectricity.api.vector.Vector3 vector = getPosition().translate(dir);
|
||||
|
||||
if (hasMultimeter(vector.intX(), vector.intY(), vector.intZ()))
|
||||
{
|
||||
connections[dir.ordinal()] = getMultimeter(vector.intX(), vector.intY(), vector.intZ());
|
||||
}
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConnector<MultimeterNetwork> getInstance(ForgeDirection dir)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public universalelectricity.api.vector.Vector3 getPosition()
|
||||
{
|
||||
return new universalelectricity.api.vector.Vector3(x(), y(), z());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue