Updated UE

This commit is contained in:
Calclavia 2014-01-20 15:24:50 +08:00
parent 29d55d3aa8
commit afd1bbde71
5 changed files with 21 additions and 234 deletions

View file

@ -48,7 +48,7 @@ public class BatteryStructure extends Structure<TileBattery>
}
@Override
protected void refreshNode(TileBattery node)
protected void reconstructNode(TileBattery node)
{
node.setNetwork(this);
}

View file

@ -177,132 +177,6 @@ public abstract class FluidNetwork extends Network<IFluidNetwork, IFluidConnecto
}
}
@Override
public IFluidNetwork merge(IFluidNetwork network)
{
FluidNetwork newNetwork = null;
if (network != null && network.getClass().isAssignableFrom(this.getClass()) && network != this)
{
try
{
newNetwork = this.getClass().newInstance();
newNetwork.getConnectors().addAll(this.getConnectors());
newNetwork.getConnectors().addAll(network.getConnectors());
network.getConnectors().clear();
network.getNodes().clear();
this.getConnectors().clear();
this.getNodes().clear();
newNetwork.reconstruct();
}
catch (Exception e)
{
e.printStackTrace();
}
}
return newNetwork;
}
@Override
public void split(IFluidConnector 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 IFluidConnector)
{
for (int ii = 0; ii < connectedBlocks.length; ii++)
{
final Object connectedBlockB = connectedBlocks[ii];
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof IFluidConnector)
{
ConnectionPathfinder finder = new ConnectionPathfinder((IFluidConnector) connectedBlockB, splitPoint);
finder.findNodes((IFluidConnector) connectedBlockA);
if (finder.results.size() <= 0)
{
try
{
/**
* The connections A and B are not connected anymore. Give them both
* a new common network.
*/
IFluidNetwork newNetwork = this.getClass().newInstance();
for (IConnector node : finder.closedSet)
{
if (node != splitPoint && node instanceof IFluidConnector)
{
newNetwork.addConnector((IFluidConnector) node);
}
}
newNetwork.reconstruct();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}
}
}
@Override
public void split(IFluidConnector connectorA, IFluidConnector 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.
*/
IFluidNetwork newNetwork;
try
{
newNetwork = this.getClass().newInstance();
for (IConnector node : finder.closedSet)
{
if (node instanceof IFluidConnector)
{
newNetwork.addConnector((IFluidConnector) node);
}
}
newNetwork.reconstruct();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
@Override
public FluidTank getTank()
{

View file

@ -9,6 +9,7 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.api.fluid.IFluidConnector;
import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.api.fluid.IFluidPipe;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.utility.FluidUtility;
@ -120,4 +121,10 @@ public class PipeNetwork extends FluidNetwork
{
return null;
}
@Override
public IFluidNetwork newInstance()
{
return new PipeNetwork();
}
}

View file

@ -6,6 +6,7 @@ import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import resonantinduction.api.fluid.IFluidConnector;
import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.mechanical.fluid.network.FluidNetwork;
/**
@ -69,4 +70,10 @@ public class TankNetwork extends FluidNetwork
}
}
@Override
public IFluidNetwork newInstance()
{
return new TankNetwork();
}
}

View file

@ -246,112 +246,6 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
}
}
@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 float getRotation()
{
@ -366,10 +260,15 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanicalCo
return rotation;
}
@Override
public IMechanicalNetwork newInstance()
{
return new MechanicalNetwork();
}
@Override
public String toString()
{
return this.getClass().getSimpleName() + "[" + this.hashCode() + ", Handlers: " + getNodes().size() + ", Connectors: " + getConnectors().size() + ", Power:" + getPower() + "]";
}
}