general work on belt network
This commit is contained in:
parent
6dc9cb3255
commit
976f382fbd
11 changed files with 87 additions and 122 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 2a52d4415f4d45b1307900e9427bd817f48f8f4e
|
||||
Subproject commit f3030ef09eb2f8ed6f28b4ffbf4fe8c1145ce2ea
|
|
@ -1 +1 @@
|
|||
Subproject commit cf1d9f45980405e4872b67e61a589989d5fb6ebd
|
||||
Subproject commit fe90843d440be93a48d631278364259797b65cfd
|
|
@ -1,8 +1,5 @@
|
|||
package assemblyline.common.armbot;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -15,14 +12,11 @@ import net.minecraft.inventory.IInventory;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IElectricityStorage;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.TranslationHelper;
|
||||
import universalelectricity.prefab.multiblock.IMultiBlock;
|
||||
|
@ -39,19 +33,15 @@ import assemblyline.common.armbot.command.CommandReturn;
|
|||
import assemblyline.common.armbot.command.CommandRotateBy;
|
||||
import assemblyline.common.armbot.command.CommandRotateTo;
|
||||
import assemblyline.common.armbot.command.CommandUse;
|
||||
import assemblyline.common.machine.TileEntityAssembly;
|
||||
import assemblyline.common.block.TileEntityAssembly;
|
||||
import assemblyline.common.machine.encoder.ItemDisk;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import dan200.computer.api.IComputerAccess;
|
||||
import dan200.computer.api.IPeripheral;
|
||||
import dark.helpers.ItemFindingHelper;
|
||||
|
||||
public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IInventory, IPacketReceiver, IElectricityStorage, IArmbot, IPeripheral
|
||||
public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IInventory, IPacketReceiver, IArmbot, IPeripheral
|
||||
{
|
||||
private final CommandManager commandManager = new CommandManager();
|
||||
private static final int PACKET_COMMANDS = 128;
|
||||
|
@ -59,7 +49,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
/** The items this container contains. */
|
||||
protected ItemStack disk = null;
|
||||
public final double WATT_REQUEST = 20;
|
||||
private int playerUsing = 0;
|
||||
private int computersAttached = 0;
|
||||
private List<IComputerAccess> connectedComputers = new ArrayList<IComputerAccess>();
|
||||
/** The rotation of the arms. In Degrees. */
|
||||
|
@ -67,7 +56,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
public float rotationYaw = 0;
|
||||
public float renderPitch = 0;
|
||||
public float renderYaw = 0;
|
||||
private int ticksSincePower = 0;
|
||||
public final float ROTATION_SPEED = 2.0f;
|
||||
|
||||
private String displayText = "";
|
||||
|
@ -141,12 +129,9 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
}
|
||||
if (!this.worldObj.isRemote)
|
||||
this.commandManager.onUpdate();
|
||||
|
||||
this.ticksSincePower = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ticksSincePower++;
|
||||
}
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
|
@ -392,13 +377,11 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
@Override
|
||||
public void openChest()
|
||||
{
|
||||
this.playerUsing++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest()
|
||||
{
|
||||
this.playerUsing--;
|
||||
}
|
||||
|
||||
public String getCommandDisplayText()
|
||||
|
@ -512,24 +495,6 @@ public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock,
|
|||
nbt.setTag("items", items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getJoules()
|
||||
{
|
||||
return this.wattsReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJoules(double joules)
|
||||
{
|
||||
this.wattsReceived = joules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxJoules()
|
||||
{
|
||||
return 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivated(EntityPlayer player)
|
||||
{
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.minecraft.world.World;
|
|||
import universalelectricity.prefab.block.BlockAdvanced;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
import assemblyline.common.TabAssemblyLine;
|
||||
import assemblyline.common.machine.TileEntityAssembly;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import dark.core.api.INetworkPart;
|
||||
|
@ -37,10 +36,10 @@ public class BlockALMachine extends BlockAdvanced
|
|||
{
|
||||
TileEntityAssembly asm = (TileEntityAssembly) ent;
|
||||
String output = "Debug>>>";
|
||||
output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|";
|
||||
output += "Channel:" + (asm.getTileNetwork() != null ? asm.getTileNetwork().toString() : "Error") + "|";
|
||||
entityPlayer.sendChatToPlayer(output);
|
||||
output = "Debug>>>";
|
||||
output += "Powered:"+asm.powered + " By:"+(asm.powerSource != null ? asm.powerSource.toString() : "null");
|
||||
output += "Powered:" + asm.running;
|
||||
entityPlayer.sendChatToPlayer(output);
|
||||
}
|
||||
return super.onBlockActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package assemblyline.common.machine;
|
||||
package assemblyline.common.block;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
|
@ -11,11 +11,13 @@ import net.minecraft.network.packet.Packet;
|
|||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.network.IPacketReceiver;
|
||||
import universalelectricity.prefab.network.PacketManager;
|
||||
import universalelectricity.prefab.tile.TileEntityElectrical;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
import assemblyline.common.machine.NetworkAssembly;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
|
@ -27,7 +29,7 @@ import dark.library.machine.TileEntityRunnableMachine;
|
|||
* able to be powered through the powering of only one machine.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public abstract class TileEntityAssembly extends TileEntityRunnableMachine implements INetworkPart, IPacketReceiver
|
||||
public abstract class TileEntityAssembly extends TileEntityElectrical implements INetworkPart, IPacketReceiver
|
||||
{
|
||||
/** Is this tile being powered by a non-network connection */
|
||||
public boolean powered = false;
|
||||
|
@ -36,8 +38,7 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
|
|||
private NetworkAssembly assemblyNetwork;
|
||||
/** Tiles that are connected to this */
|
||||
private TileEntity[] connectedTiles = new TileEntity[6];
|
||||
/** Cached power source to reduce the need to path find for a new one each tick */
|
||||
public TileEntityAssembly powerSource;
|
||||
private TileEntity[] tiles = new TileEntity[6];
|
||||
/** Random instance */
|
||||
public Random random = new Random();
|
||||
/** percent tick rate this tile will update at */
|
||||
|
@ -70,14 +71,13 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
|
|||
this.updateTick = ((int) random.nextInt(10) + 20);
|
||||
this.updateNetworkConnections();
|
||||
}
|
||||
if (this.wattsReceived >= this.getRequest())
|
||||
for (int i = 0; i < this.tiles.length; i++)
|
||||
{
|
||||
this.wattsReceived -= getRequest();
|
||||
this.powered = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.powered = false;
|
||||
TileEntity ent = this.tiles[i];
|
||||
if (ent instanceof IConductor)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
if (this.getTileNetwork() instanceof NetworkAssembly)
|
||||
{
|
||||
|
@ -104,25 +104,10 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
|
|||
{
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
boolean running = AssemblyLine.REQUIRE_NO_POWER || this.powered;
|
||||
if (!running && this.powerSource != null && this.getTileNetwork() instanceof NetworkAssembly)
|
||||
boolean running = AssemblyLine.REQUIRE_NO_POWER;
|
||||
if (!running && this.getTileNetwork() instanceof NetworkAssembly)
|
||||
{
|
||||
NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork());
|
||||
running = net.getNetworkMemebers().contains(this.powerSource) && this.powerSource.powered;
|
||||
if (!running)
|
||||
{
|
||||
this.lastPoweredTicks++;
|
||||
if (this.lastPoweredTicks >= 20 || !net.getNetworkMemebers().contains(this.powerSource))
|
||||
{
|
||||
this.powerSource = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((!running || this.powerSource == null) && this.getTileNetwork() instanceof NetworkAssembly)
|
||||
{
|
||||
NetworkAssembly net = ((NetworkAssembly) this.getTileNetwork());
|
||||
this.powerSource = net.canRun(this);
|
||||
running = this.powerSource != null && this.powerSource.powered;
|
||||
running = ((NetworkAssembly) this.getTileNetwork()).canRun(this);
|
||||
}
|
||||
return running;
|
||||
}
|
||||
|
@ -133,10 +118,9 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getRequest()
|
||||
public double getRequest(ForgeDirection side)
|
||||
{
|
||||
return .1D;
|
||||
return .1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,19 +129,6 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
|
|||
return entity != null && entity instanceof TileEntityAssembly;
|
||||
}
|
||||
|
||||
/** Validates and adds a connection on a given side from a given tileEntity */
|
||||
public void validateConnectionSide(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (tileEntity instanceof TileEntityAssembly)
|
||||
{
|
||||
this.getTileNetwork().merge(((TileEntityAssembly) tileEntity).getTileNetwork(), this);
|
||||
connectedTiles[side.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNetworkConnections()
|
||||
{
|
||||
|
@ -168,8 +139,16 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
|
|||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(i);
|
||||
this.validateConnectionSide(this.worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ), dir);
|
||||
|
||||
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(dir).getTileEntity(this.worldObj);
|
||||
if (tileEntity instanceof TileEntityAssembly)
|
||||
{
|
||||
this.getTileNetwork().merge(((TileEntityAssembly) tileEntity).getTileNetwork(), this);
|
||||
connectedTiles[dir.ordinal()] = tileEntity;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tiles[dir.ordinal()] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +187,7 @@ public abstract class TileEntityAssembly extends TileEntityRunnableMachine imple
|
|||
@Override
|
||||
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
|
||||
{
|
||||
boolean packetSize = true;
|
||||
boolean packetSize = false;
|
||||
try
|
||||
{
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(packet.data);
|
|
@ -19,8 +19,8 @@ import universalelectricity.prefab.network.IPacketReceiver;
|
|||
import universalelectricity.prefab.network.PacketManager;
|
||||
import assemblyline.api.IFilterable;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
import assemblyline.common.block.TileEntityAssembly;
|
||||
import assemblyline.common.imprinter.ItemImprinter;
|
||||
import assemblyline.common.machine.TileEntityAssembly;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
|
@ -114,7 +114,7 @@ public abstract class TileEntityFilterable extends TileEntityAssembly implements
|
|||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, AssemblyTilePacket.NBT, this.getPacketData().toArray());
|
||||
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, AssemblyTilePacket.NBT.ordinal(), this.getPacketData().toArray());
|
||||
}
|
||||
|
||||
public ArrayList getPacketData()
|
||||
|
|
|
@ -1,54 +1,64 @@
|
|||
package assemblyline.common.machine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import assemblyline.common.block.TileEntityAssembly;
|
||||
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IConnectionProvider;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.electricity.IElectricityNetwork;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import dark.core.api.INetworkPart;
|
||||
import dark.core.tile.network.NetworkPowerTiles;
|
||||
import dark.core.tile.network.NetworkTileEntities;
|
||||
|
||||
public class NetworkAssembly extends NetworkTileEntities
|
||||
public class NetworkAssembly extends NetworkPowerTiles
|
||||
{
|
||||
/** List of network members that are providing power for the network */
|
||||
private List<TileEntity> powerSources = new ArrayList<TileEntity>();
|
||||
public final int MAX_POWER_RANGE = 20;
|
||||
public double wattStored = 0.0;
|
||||
|
||||
public NetworkAssembly(INetworkPart... parts)
|
||||
{
|
||||
super(parts);
|
||||
}
|
||||
|
||||
/** Detects if the tile can run by tracking down a tileEntity marked as a power provider in the
|
||||
* network. Does use a pathfinder that will work threw at least a sphere with a radius the same
|
||||
* as the max power range of the network
|
||||
*
|
||||
* @param tile - tileEntity which is mainly used as a way to locate the tile and gets its world
|
||||
* @return true if the tile can be powered by the network */
|
||||
public TileEntityAssembly canRun(TileEntityAssembly tile)
|
||||
/** Checks if the tile can run as well sucks up energy for the tile to run */
|
||||
public boolean canRun(TileEntityAssembly tile)
|
||||
{
|
||||
if (tile != null && !tile.powered && this.powerSources.size() > 0)
|
||||
if (tile != null && this.wattStored >= tile.getRequest(ForgeDirection.UNKNOWN))
|
||||
{
|
||||
for (TileEntity entity : powerSources)
|
||||
this.wattStored -= tile.getRequest(ForgeDirection.UNKNOWN);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Gets the amount of power this network needs
|
||||
*
|
||||
* @param total - true for total network, false for amount equal to each power connection */
|
||||
public double getRequest(boolean total)
|
||||
{
|
||||
double watt = 1;
|
||||
for (INetworkPart part : this.getNetworkMemebers())
|
||||
{
|
||||
if (part instanceof TileEntityAssembly)
|
||||
{
|
||||
if (entity instanceof TileEntityAssembly && ((TileEntityAssembly) entity).powered)
|
||||
{
|
||||
Vector3 start = new Vector3(tile);
|
||||
Vector3 end = new Vector3(entity);
|
||||
if (start.distanceTo(end) <= this.MAX_POWER_RANGE)
|
||||
{
|
||||
PowerPathFinder path = new PowerPathFinder(tile.worldObj, start, end, MAX_POWER_RANGE);
|
||||
path.init(start);
|
||||
if (path.results.size() > 0)
|
||||
{
|
||||
return (TileEntityAssembly) entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
watt += ((TileEntityAssembly) part).getRequest(ForgeDirection.UNKNOWN);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if (!total)
|
||||
{
|
||||
return watt / this.powerSources.size();
|
||||
}
|
||||
return watt;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,6 +82,10 @@ public class NetworkAssembly extends NetworkTileEntities
|
|||
this.markAsPowerSource((TileEntity) part, true);
|
||||
}
|
||||
}
|
||||
if (added)
|
||||
{
|
||||
this.doCalc();
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
|
@ -81,6 +95,11 @@ public class NetworkAssembly extends NetworkTileEntities
|
|||
return super.isValidMember(part) && part instanceof TileEntityAssembly;
|
||||
}
|
||||
|
||||
public void doCalc()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** Marks a tile as the source of power for the network
|
||||
*
|
||||
* @param powered true to add, false to remove */
|
||||
|
@ -98,4 +117,5 @@ public class NetworkAssembly extends NetworkTileEntities
|
|||
this.powerSources.remove(entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package assemblyline.common.machine;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import assemblyline.common.block.TileEntityAssembly;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
|
|
@ -22,7 +22,7 @@ import universalelectricity.prefab.network.IPacketReceiver;
|
|||
import universalelectricity.prefab.network.PacketManager;
|
||||
import assemblyline.api.IBelt;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
import assemblyline.common.machine.TileEntityAssembly;
|
||||
import assemblyline.common.block.TileEntityAssembly;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
import universalelectricity.core.vector.Vector3;
|
||||
import assemblyline.api.ICraneStructure;
|
||||
import assemblyline.common.AssemblyLine;
|
||||
import assemblyline.common.machine.TileEntityAssembly;
|
||||
import assemblyline.common.block.TileEntityAssembly;
|
||||
|
||||
public class TileEntityCraneController extends TileEntityAssembly implements ICraneStructure
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@ package assemblyline.common.machine.crane;
|
|||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import assemblyline.api.ICraneStructure;
|
||||
import assemblyline.common.machine.TileEntityAssembly;
|
||||
import assemblyline.common.block.TileEntityAssembly;
|
||||
|
||||
public class TileEntityCraneRail extends TileEntityAssembly implements ICraneStructure
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue