more work on assembly power network
This commit is contained in:
parent
353333f80a
commit
4f4225d6f8
2 changed files with 38 additions and 35 deletions
|
@ -5,7 +5,6 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
import universalelectricity.core.block.IConductor;
|
import universalelectricity.core.block.IConductor;
|
||||||
import universalelectricity.core.block.IConnectionProvider;
|
import universalelectricity.core.block.IConnectionProvider;
|
||||||
import universalelectricity.core.electricity.ElectricityPack;
|
import universalelectricity.core.electricity.ElectricityPack;
|
||||||
|
@ -22,7 +21,7 @@ public class NetworkAssembly extends NetworkPowerTiles
|
||||||
{
|
{
|
||||||
/** List of network members that are providing power for the network */
|
/** List of network members that are providing power for the network */
|
||||||
private List<TileEntity> powerSources = new ArrayList<TileEntity>();
|
private List<TileEntity> powerSources = new ArrayList<TileEntity>();
|
||||||
public double wattStored = 0.0;
|
private double wattStored = 0.0;
|
||||||
|
|
||||||
public NetworkAssembly(INetworkPart... parts)
|
public NetworkAssembly(INetworkPart... parts)
|
||||||
{
|
{
|
||||||
|
@ -43,7 +42,7 @@ public class NetworkAssembly extends NetworkPowerTiles
|
||||||
/** Gets the amount of power this network needs
|
/** Gets the amount of power this network needs
|
||||||
*
|
*
|
||||||
* @param total - true for total network, false for amount equal to each power connection */
|
* @param total - true for total network, false for amount equal to each power connection */
|
||||||
public double getRequest(boolean total)
|
public double getRequest()
|
||||||
{
|
{
|
||||||
double watt = 1;
|
double watt = 1;
|
||||||
for (INetworkPart part : this.getNetworkMemebers())
|
for (INetworkPart part : this.getNetworkMemebers())
|
||||||
|
@ -53,13 +52,19 @@ public class NetworkAssembly extends NetworkPowerTiles
|
||||||
watt += ((TileEntityAssembly) part).getRequest(ForgeDirection.UNKNOWN);
|
watt += ((TileEntityAssembly) part).getRequest(ForgeDirection.UNKNOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!total)
|
|
||||||
{
|
|
||||||
return watt / this.powerSources.size();
|
|
||||||
}
|
|
||||||
return watt;
|
return watt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getMaxBattery()
|
||||||
|
{
|
||||||
|
return this.getRequest() * 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getCurrentBattery()
|
||||||
|
{
|
||||||
|
return this.wattStored;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postMergeProcessing(NetworkTileEntities network)
|
public void postMergeProcessing(NetworkTileEntities network)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,8 @@ package assemblyline.common.machine;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -12,11 +14,14 @@ import net.minecraft.network.packet.Packet250CustomPayload;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import universalelectricity.core.block.IConductor;
|
import universalelectricity.core.block.IConductor;
|
||||||
|
import universalelectricity.core.electricity.ElectricityNetworkHelper;
|
||||||
|
import universalelectricity.core.electricity.ElectricityPack;
|
||||||
import universalelectricity.core.vector.Vector3;
|
import universalelectricity.core.vector.Vector3;
|
||||||
import universalelectricity.prefab.network.IPacketReceiver;
|
import universalelectricity.prefab.network.IPacketReceiver;
|
||||||
import universalelectricity.prefab.network.PacketManager;
|
import universalelectricity.prefab.network.PacketManager;
|
||||||
import universalelectricity.prefab.tile.TileEntityElectrical;
|
import universalelectricity.prefab.tile.TileEntityElectrical;
|
||||||
import assemblyline.common.AssemblyLine;
|
import assemblyline.common.AssemblyLine;
|
||||||
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
||||||
|
@ -28,7 +33,7 @@ import dark.library.machine.TileEntityRunnableMachine;
|
||||||
* able to be powered through the powering of only one machine.
|
* able to be powered through the powering of only one machine.
|
||||||
*
|
*
|
||||||
* @author Calclavia */
|
* @author Calclavia */
|
||||||
public abstract class TileEntityAssembly extends TileEntityElectrical implements INetworkPart, IPacketReceiver
|
public abstract class TileEntityAssembly extends TileEntityRunnableMachine implements INetworkPart, IPacketReceiver
|
||||||
{
|
{
|
||||||
/** Is this tile being powered by a non-network connection */
|
/** Is this tile being powered by a non-network connection */
|
||||||
public boolean powered = false;
|
public boolean powered = false;
|
||||||
|
@ -36,8 +41,7 @@ public abstract class TileEntityAssembly extends TileEntityElectrical implements
|
||||||
/** 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 */
|
||||||
private TileEntity[] connectedTiles = new TileEntity[6];
|
private List<TileEntity> connectedTiles = new ArrayList<TileEntity>();
|
||||||
private TileEntity[] tiles = new TileEntity[6];
|
|
||||||
/** Random instance */
|
/** Random instance */
|
||||||
public Random random = new Random();
|
public Random random = new Random();
|
||||||
/** percent tick rate this tile will update at */
|
/** percent tick rate this tile will update at */
|
||||||
|
@ -61,8 +65,9 @@ public abstract class TileEntityAssembly extends TileEntityElectrical implements
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
super.updateEntity();
|
|
||||||
boolean prevRun = this.running;
|
boolean prevRun = this.running;
|
||||||
|
this.powered = false;
|
||||||
|
super.updateEntity();
|
||||||
if (!this.worldObj.isRemote)
|
if (!this.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
if (ticks % updateTick == 0)
|
if (ticks % updateTick == 0)
|
||||||
|
@ -70,20 +75,6 @@ public abstract class TileEntityAssembly extends TileEntityElectrical implements
|
||||||
this.updateTick = ((int) random.nextInt(10) + 20);
|
this.updateTick = ((int) random.nextInt(10) + 20);
|
||||||
this.updateNetworkConnections();
|
this.updateNetworkConnections();
|
||||||
}
|
}
|
||||||
for (int i = 0; i < this.tiles.length; i++)
|
|
||||||
{
|
|
||||||
TileEntity ent = this.tiles[i];
|
|
||||||
if (ent instanceof IConductor)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.getTileNetwork() instanceof NetworkAssembly)
|
|
||||||
{
|
|
||||||
NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork());
|
|
||||||
net.markAsPowerSource(this, this.powered);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.running = this.isRunning();
|
this.running = this.isRunning();
|
||||||
if (running != prevRun)
|
if (running != prevRun)
|
||||||
{
|
{
|
||||||
|
@ -117,11 +108,23 @@ public abstract class TileEntityAssembly extends TileEntityElectrical implements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getRequest(ForgeDirection side)
|
public double getRequest()
|
||||||
{
|
{
|
||||||
return .1;
|
return .1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getRequest(ForgeDirection side)
|
||||||
|
{
|
||||||
|
if (this.getTileNetwork() instanceof NetworkAssembly)
|
||||||
|
{
|
||||||
|
NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork());
|
||||||
|
double room = net.getMaxBattery() - net.getCurrentBattery();
|
||||||
|
return Math.min(100, Math.max(0, room));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canTileConnect(TileEntity entity, ForgeDirection dir)
|
public boolean canTileConnect(TileEntity entity, ForgeDirection dir)
|
||||||
{
|
{
|
||||||
|
@ -133,27 +136,22 @@ public abstract class TileEntityAssembly extends TileEntityElectrical implements
|
||||||
{
|
{
|
||||||
if (this.worldObj != null && !this.worldObj.isRemote)
|
if (this.worldObj != null && !this.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
this.connectedTiles = new TileEntity[6];
|
this.connectedTiles.clear();
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++)
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
ForgeDirection dir = ForgeDirection.getOrientation(i);
|
|
||||||
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||||
if (tileEntity instanceof TileEntityAssembly)
|
if (tileEntity instanceof TileEntityAssembly)
|
||||||
{
|
{
|
||||||
this.getTileNetwork().merge(((TileEntityAssembly) tileEntity).getTileNetwork(), this);
|
this.getTileNetwork().merge(((TileEntityAssembly) tileEntity).getTileNetwork(), this);
|
||||||
connectedTiles[dir.ordinal()] = tileEntity;
|
connectedTiles.add(tileEntity);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.tiles[dir.ordinal()] = tileEntity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity[] getNetworkConnections()
|
public List<TileEntity> getNetworkConnections()
|
||||||
{
|
{
|
||||||
return this.connectedTiles;
|
return this.connectedTiles;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue