cleanup
This commit is contained in:
parent
d4cdd93130
commit
cb320b6115
3 changed files with 96 additions and 26 deletions
|
@ -26,6 +26,12 @@ public class NetworkPowerTiles extends NetworkTileEntities implements IElectrici
|
||||||
super(conductors);
|
super(conductors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkTileEntities newInstance()
|
||||||
|
{
|
||||||
|
return new NetworkPowerTiles();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack)
|
public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack)
|
||||||
{
|
{
|
||||||
|
@ -320,4 +326,5 @@ public class NetworkPowerTiles extends NetworkTileEntities implements IElectrici
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import cpw.mods.fml.common.FMLLog;
|
||||||
import dark.core.api.INetworkPart;
|
import dark.core.api.INetworkPart;
|
||||||
import dark.helpers.ConnectionHelper;
|
import dark.helpers.ConnectionHelper;
|
||||||
|
|
||||||
public class NetworkTileEntities
|
public abstract class NetworkTileEntities
|
||||||
{
|
{
|
||||||
/* BLOCK THAT ACT AS FLUID CONVEYORS ** */
|
/* BLOCK THAT ACT AS FLUID CONVEYORS ** */
|
||||||
public final List<INetworkPart> networkMember = new ArrayList<INetworkPart>();
|
public final List<INetworkPart> networkMember = new ArrayList<INetworkPart>();
|
||||||
|
@ -25,29 +25,31 @@ public class NetworkTileEntities
|
||||||
this.networkMember.addAll(Arrays.asList(parts));
|
this.networkMember.addAll(Arrays.asList(parts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds a TileEntity to the network
|
/** Creates a new instance of this network to be used to merge or split networks while still
|
||||||
|
* maintaining each class that extends the base network class
|
||||||
*
|
*
|
||||||
* @param ent - tileEntity instance
|
* @return - new network instance using the current networks properties */
|
||||||
|
public abstract NetworkTileEntities newInstance();
|
||||||
|
|
||||||
|
/** Adds a TileEntity to the network. extends this to catch non-network parts and add them to
|
||||||
|
* other tile lists
|
||||||
|
*
|
||||||
|
* @param tileEntity - tileEntity instance
|
||||||
* @param member - add to network member list
|
* @param member - add to network member list
|
||||||
* @return */
|
* @return */
|
||||||
public boolean addEntity(TileEntity ent, boolean member)
|
public boolean addTile(TileEntity tileEntity, boolean member)
|
||||||
{
|
{
|
||||||
if (ent == null || this.isPartOfNetwork(ent))
|
if (tileEntity == null || this.isPartOfNetwork(tileEntity))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (ent instanceof INetworkPart && member)
|
else if (tileEntity instanceof INetworkPart && member)
|
||||||
{
|
{
|
||||||
return this.addNetworkPart((INetworkPart) ent);
|
return this.addNetworkPart((INetworkPart) tileEntity);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPartOfNetwork(TileEntity ent)
|
|
||||||
{
|
|
||||||
return this.networkMember.contains(ent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Adds a new part to the network member list */
|
/** Adds a new part to the network member list */
|
||||||
public boolean addNetworkPart(INetworkPart part)
|
public boolean addNetworkPart(INetworkPart part)
|
||||||
{
|
{
|
||||||
|
@ -61,6 +63,11 @@ public class NetworkTileEntities
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPartOfNetwork(TileEntity ent)
|
||||||
|
{
|
||||||
|
return this.networkMember.contains(ent);
|
||||||
|
}
|
||||||
|
|
||||||
/** Removes a tileEntity from any of the valid lists */
|
/** Removes a tileEntity from any of the valid lists */
|
||||||
public void removeEntity(TileEntity ent)
|
public void removeEntity(TileEntity ent)
|
||||||
{
|
{
|
||||||
|
@ -131,24 +138,34 @@ public class NetworkTileEntities
|
||||||
{
|
{
|
||||||
if (this.preMergeProcessing(network, part))
|
if (this.preMergeProcessing(network, part))
|
||||||
{
|
{
|
||||||
this.postMergeProcessing(network);
|
this.mergeDo(network);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Processing that needs too be done before the network merges
|
/** Processing that needs too be done before the network merges. Use this to do final network
|
||||||
|
* merge calculations and to cause network merge failure
|
||||||
*
|
*
|
||||||
* @return false if the merge needs to be canceled */
|
* @param network the network that is to merge with this one
|
||||||
|
* @param part the part at which started the network merge. Use this to cause damage if two
|
||||||
|
* networks merge with real world style failures
|
||||||
|
*
|
||||||
|
* @return false if the merge needs to be canceled.
|
||||||
|
*
|
||||||
|
* Cases in which the network should fail to merge are were the two networks merge with error.
|
||||||
|
* Or, in the case of pipes the two networks merge and the merge point was destroyed by
|
||||||
|
* combination of liquids.
|
||||||
|
*
|
||||||
|
* Ex Lava and water */
|
||||||
public boolean preMergeProcessing(NetworkTileEntities network, INetworkPart part)
|
public boolean preMergeProcessing(NetworkTileEntities network, INetworkPart part)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Finalizing the merge of two networks by creating the new network and importing all network
|
/** Merges the two networks together */
|
||||||
* parts */
|
protected void mergeDo(NetworkTileEntities network)
|
||||||
public void postMergeProcessing(NetworkTileEntities network)
|
|
||||||
{
|
{
|
||||||
NetworkTileEntities newNetwork = new NetworkTileEntities();
|
NetworkTileEntities newNetwork = this.newInstance();
|
||||||
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
|
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
|
||||||
newNetwork.getNetworkMemebers().addAll(network.getNetworkMemebers());
|
newNetwork.getNetworkMemebers().addAll(network.getNetworkMemebers());
|
||||||
|
|
||||||
|
@ -199,7 +216,7 @@ public class NetworkTileEntities
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* NO LONGER CONNECTED ELSE WHERE SO SPLIT AND REFRESH */
|
/* NO LONGER CONNECTED ELSE WHERE SO SPLIT AND REFRESH */
|
||||||
NetworkTileEntities newNetwork = new NetworkTileEntities();
|
NetworkTileEntities newNetwork = this.newInstance();
|
||||||
int parts = 0;
|
int parts = 0;
|
||||||
for (Vector3 node : finder.closedSet)
|
for (Vector3 node : finder.closedSet)
|
||||||
{
|
{
|
||||||
|
@ -226,9 +243,12 @@ public class NetworkTileEntities
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "TileNetwork[" + this.hashCode() + "|parts:" + this.networkMember.size() + "]";
|
return "TileNetwork[" + this.hashCode() + "| Parts:" + this.networkMember.size() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** invalidates/remove a tile from the networks that surround and connect to it
|
||||||
|
*
|
||||||
|
* @param tileEntity - tile */
|
||||||
public static void invalidate(TileEntity tileEntity)
|
public static void invalidate(TileEntity tileEntity)
|
||||||
{
|
{
|
||||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package dark.library.machine;
|
package dark.library.machine;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
import universalelectricity.core.UniversalElectricity;
|
import universalelectricity.core.UniversalElectricity;
|
||||||
|
@ -11,12 +13,14 @@ import universalelectricity.core.block.IConnector;
|
||||||
import universalelectricity.core.block.IVoltage;
|
import universalelectricity.core.block.IVoltage;
|
||||||
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
import universalelectricity.core.electricity.ElectricityPack;
|
||||||
|
import universalelectricity.core.electricity.IElectricityNetwork;
|
||||||
import universalelectricity.prefab.tile.TileEntityElectrical;
|
import universalelectricity.prefab.tile.TileEntityElectrical;
|
||||||
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
|
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
|
||||||
import buildcraft.api.power.IPowerProvider;
|
import buildcraft.api.power.IPowerProvider;
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
import buildcraft.api.power.PowerFramework;
|
import buildcraft.api.power.PowerFramework;
|
||||||
import dark.core.PowerSystems;
|
import dark.core.PowerSystems;
|
||||||
|
import dark.core.api.INetworkPart;
|
||||||
|
|
||||||
public abstract class TileEntityRunnableMachine extends TileEntityElectrical implements IPowerReceptor, IConnector, IVoltage
|
public abstract class TileEntityRunnableMachine extends TileEntityElectrical implements IPowerReceptor, IConnector, IVoltage
|
||||||
{
|
{
|
||||||
|
@ -54,8 +58,8 @@ public abstract class TileEntityRunnableMachine extends TileEntityElectrical imp
|
||||||
// UNIVERSAL ELECTRICITY UPDATE
|
// UNIVERSAL ELECTRICITY UPDATE
|
||||||
if (!this.isDisabled())
|
if (!this.isDisabled())
|
||||||
{
|
{
|
||||||
ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), ElectricityPack.getFromWatts(this.getRequest(ForgeDirection.UNKNOWN), this.getVoltage()));
|
ElectricityPack electricityPack = TileEntityRunnableMachine.consumeFromMultipleSides(this, this.getConsumingSides(), ElectricityPack.getFromWatts(this.getRequest(ForgeDirection.UNKNOWN), this.getVoltage()));
|
||||||
this.onReceive(ForgeDirection.UNKNOWN,electricityPack.voltage, electricityPack.amperes);
|
this.onReceive(ForgeDirection.UNKNOWN, electricityPack.voltage, electricityPack.amperes);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -74,8 +78,8 @@ public abstract class TileEntityRunnableMachine extends TileEntityElectrical imp
|
||||||
if (this.powerProvider != null)
|
if (this.powerProvider != null)
|
||||||
{
|
{
|
||||||
float requiredEnergy = (float) (this.getRequest(ForgeDirection.UNKNOWN) * UniversalElectricity.TO_BC_RATIO);
|
float requiredEnergy = (float) (this.getRequest(ForgeDirection.UNKNOWN) * UniversalElectricity.TO_BC_RATIO);
|
||||||
float energyReceived = this.powerProvider.useEnergy(0, requiredEnergy, true);
|
float energyReceived = this.powerProvider.useEnergy(requiredEnergy, requiredEnergy, true);
|
||||||
this.onReceive(ForgeDirection.UNKNOWN,this.getVoltage(), (UniversalElectricity.BC3_RATIO * energyReceived) / this.getVoltage());
|
this.onReceive(ForgeDirection.UNKNOWN, this.getVoltage(), (UniversalElectricity.BC3_RATIO * energyReceived) / this.getVoltage());
|
||||||
}
|
}
|
||||||
//TODO add other power systems
|
//TODO add other power systems
|
||||||
}
|
}
|
||||||
|
@ -170,4 +174,43 @@ public abstract class TileEntityRunnableMachine extends TileEntityElectrical imp
|
||||||
nbt.setBoolean("shouldPower", this.runPowerless);
|
nbt.setBoolean("shouldPower", this.runPowerless);
|
||||||
nbt.setInteger("disabledTicks", this.disabledTicks);
|
nbt.setInteger("disabledTicks", this.disabledTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, EnumSet<ForgeDirection> approachingDirection, ElectricityPack requestPack)
|
||||||
|
{
|
||||||
|
ElectricityPack consumedPack = new ElectricityPack();
|
||||||
|
|
||||||
|
if (tileEntity != null && approachingDirection != null)
|
||||||
|
{
|
||||||
|
final List<IElectricityNetwork> connectedNetworks = ElectricityNetworkHelper.getNetworksFromMultipleSides(tileEntity, approachingDirection);
|
||||||
|
|
||||||
|
if (connectedNetworks.size() > 0)
|
||||||
|
{
|
||||||
|
/** Requests an even amount of electricity from all sides. */
|
||||||
|
double wattsPerSide = (requestPack.getWatts() / connectedNetworks.size());
|
||||||
|
double voltage = requestPack.voltage;
|
||||||
|
|
||||||
|
for (IElectricityNetwork network : connectedNetworks)
|
||||||
|
{
|
||||||
|
boolean flag = false;
|
||||||
|
if (tileEntity instanceof INetworkPart && ((INetworkPart) tileEntity).getTileNetwork() instanceof IElectricityNetwork)
|
||||||
|
{
|
||||||
|
flag = network.equals(((IElectricityNetwork) ((INetworkPart) tileEntity).getTileNetwork()));
|
||||||
|
}
|
||||||
|
if (!flag && wattsPerSide > 0 && requestPack.getWatts() > 0)
|
||||||
|
{
|
||||||
|
network.startRequesting(tileEntity, wattsPerSide / voltage, voltage);
|
||||||
|
ElectricityPack receivedPack = network.consumeElectricity(tileEntity);
|
||||||
|
consumedPack.amperes += receivedPack.amperes;
|
||||||
|
consumedPack.voltage = Math.max(consumedPack.voltage, receivedPack.voltage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
network.stopRequesting(tileEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumedPack;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue