Worked on Assembly TileNetwork

Right now its just an extended version of the Shared power network. This
should get the network moving towards running first. Then i can slowly
add in support for powering UE machines back. UE support should auto
cover BC, & IC2. So only thing to do after that is refine and add fluid
support.
This commit is contained in:
DarkGuardsman 2013-08-24 09:51:02 -04:00
parent 5e3a440ff0
commit d0b5f22900
2 changed files with 60 additions and 39 deletions

View file

@ -1,15 +1,17 @@
package dark.assembly.common.machine; package dark.assembly.common.machine;
import dark.api.INetworkPart; import dark.api.INetworkPart;
import dark.core.tile.network.NetworkSharedPower;
import dark.core.tile.network.NetworkTileEntities; import dark.core.tile.network.NetworkTileEntities;
public class NetworkAssembly extends NetworkTileEntities public class NetworkAssembly extends NetworkSharedPower
{ {
public NetworkAssembly(INetworkPart... parts) public NetworkAssembly(INetworkPart... parts)
{ {
super(parts); super(parts);
} }
@Override
public NetworkTileEntities newInstance() public NetworkTileEntities newInstance()
{ {
return new NetworkAssembly(); return new NetworkAssembly();

View file

@ -5,22 +5,24 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.IPacketReceiver;
import dark.api.INetworkPart; import dark.api.INetworkEnergyPart;
import dark.assembly.common.AssemblyLine; import dark.assembly.common.AssemblyLine;
import dark.core.blocks.TileEntityMachine; import dark.core.blocks.TileEntityMachine;
import dark.core.tile.network.NetworkSharedPower;
import dark.core.tile.network.NetworkTileEntities; import dark.core.tile.network.NetworkTileEntities;
/** A class to be inherited by all machines on the assembly line. This class acts as a single peace /** A class to be inherited by all machines on the assembly line. This class acts as a single peace
* in a network of similar tiles allowing all to share power from one or more sources * in a network of similar tiles allowing all to share power from one or more sources
* *
* @author DarkGuardsman */ * @author DarkGuardsman */
public abstract class TileEntityAssembly extends TileEntityMachine implements INetworkPart, IPacketReceiver, IConductor public abstract class TileEntityAssembly extends TileEntityMachine implements IPacketReceiver, INetworkEnergyPart
{ {
public static int refresh_min_rate = 20;
public static int refresh_diff = 9;
/** Network used to link assembly machines together */ /** Network used to link assembly machines together */
private NetworkAssembly assemblyNetwork; private NetworkAssembly assemblyNetwork;
/** Tiles that are connected to this */ /** Tiles that are connected to this */
@ -54,13 +56,14 @@ public abstract class TileEntityAssembly extends TileEntityMachine implements IN
@Override @Override
public void updateEntity() public void updateEntity()
{ {
super.updateEntity();
if (!this.worldObj.isRemote) if (!this.worldObj.isRemote)
{ {
this.prevRunning = this.running; this.prevRunning = this.running;
super.updateEntity();
if (ticks % updateTick == 0) if (ticks % updateTick == 0)
{ {
this.updateTick = ((int) random.nextInt(10) + 20); this.updateTick = ((int) random.nextInt(1 + refresh_diff) + refresh_min_rate);
this.refresh(); this.refresh();
} }
this.running = this.canRun(); this.running = this.canRun();
@ -156,6 +159,48 @@ public abstract class TileEntityAssembly extends TileEntityMachine implements IN
} }
@Override
public boolean consumePower(float watts, boolean doDrain)
{
return ((NetworkSharedPower) this.getTileNetwork()).drainPower(this, watts, doDrain);
}
@Override
public float getRequest(ForgeDirection direction)
{
return this.WATTS_PER_TICK;
}
@Override
public void togglePowerMode()
{
((NetworkSharedPower) this.getTileNetwork()).setPowerLess(this.runPowerLess());
}
@Override
public float getEnergyStored()
{
return ((NetworkSharedPower) this.getTileNetwork()).getEnergyStored();
}
@Override
public float getPartEnergy()
{
return this.energyStored;
}
@Override
public float getPartMaxEnergy()
{
return this.MAX_WATTS;
}
@Override
public void setPartEnergy(float energy)
{
this.energyStored = energy;
}
@Override @Override
public boolean mergeDamage(String effect) public boolean mergeDamage(String effect)
{ {
@ -163,40 +208,14 @@ public abstract class TileEntityAssembly extends TileEntityMachine implements IN
return true; return true;
} }
@Override
public AxisAlignedBB getRenderBoundingBox()
{
return INFINITE_EXTENT_AABB;
}
public String toString() public String toString()
{ {
return "[AssemblyTile]@" + (new Vector3(this).toString()); return "[AssemblyTile]@" + (new Vector3(this).toString());
} }
@Override
public IElectricityNetwork getNetwork()
{
return (this.getTileNetwork() instanceof IElectricityNetwork ? (IElectricityNetwork) this.getTileNetwork() : null);
}
@Override
public void setNetwork(IElectricityNetwork network)
{
// TODO Auto-generated method stub
}
@Override
public TileEntity[] getAdjacentConnections()
{
return this.connectedTiles.toArray(new TileEntity[this.connectedTiles.size()]);
}
@Override
public float getResistance()
{
return 0.01f;
}
@Override
public float getCurrentCapacity()
{
return 1000;
}
} }