Reworking assembly network

Changing the fake network like power system for the belts into a better
network. This way i can start to do more with the network and manage it
better.
This commit is contained in:
DarkGuardsman 2013-06-25 22:30:27 -04:00
parent b5bb3e6316
commit f23892e224
18 changed files with 200 additions and 448 deletions

View file

@ -39,7 +39,7 @@ 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.TileEntityAssemblyNetwork;
import assemblyline.common.machine.TileEntityAssembly;
import assemblyline.common.machine.encoder.ItemDisk;
import com.google.common.io.ByteArrayDataInput;
@ -51,7 +51,7 @@ import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral;
import dark.helpers.ItemFindingHelper;
public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMultiBlock, IInventory, IPacketReceiver, IElectricityStorage, IArmbot, IPeripheral
public class TileEntityArmbot extends TileEntityAssembly implements IMultiBlock, IInventory, IPacketReceiver, IElectricityStorage, IArmbot, IPeripheral
{
private final CommandManager commandManager = new CommandManager();
private static final int PACKET_COMMANDS = 128;
@ -311,7 +311,7 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
{
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.powerTransferRange, nbt);
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, nbt);
}
/**
@ -331,9 +331,8 @@ public class TileEntityArmbot extends TileEntityAssemblyNetwork implements IMult
x = dis.readInt();
y = dis.readInt();
z = dis.readInt();
this.powerTransferRange = dis.readInt();
NBTTagCompound tag = Packet.readNBTTagCompound(dis);
readFromNBT(tag);
this.readFromNBT(tag);
}
catch (IOException e)
{

View file

@ -9,7 +9,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import assemblyline.common.machine.InvExtractionHelper;
import assemblyline.common.machine.InvInteractionHelper;
public class CommandGive extends Command
{
@ -63,7 +63,7 @@ public class CommandGive extends Command
{
stacks.add(stack);
}
InvExtractionHelper invEx = new InvExtractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false);
InvInteractionHelper invEx = new InvInteractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false);
Iterator<ItemStack> targetIt = this.tileEntity.getGrabbedItems().iterator();
boolean flag = true;

View file

@ -8,7 +8,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import assemblyline.common.machine.InvExtractionHelper;
import assemblyline.common.machine.InvInteractionHelper;
public class CommandTake extends Command
{
@ -62,7 +62,7 @@ public class CommandTake extends Command
{
stacks.add(stack);
}
InvExtractionHelper invEx = new InvExtractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false);
InvInteractionHelper invEx = new InvInteractionHelper(this.tileEntity.worldObj, new Vector3(this.tileEntity), stacks, false);
this.tileEntity.grabItem(invEx.tryGrabFromPosition(new Vector3(targetTile), direction, this.stack != null ? stack.stackSize : 1));
return !(this.tileEntity.getGrabbedItems().size() > 0);

View file

@ -20,14 +20,14 @@ import universalelectricity.prefab.network.PacketManager;
import assemblyline.api.IFilterable;
import assemblyline.common.AssemblyLine;
import assemblyline.common.imprinter.ItemImprinter;
import assemblyline.common.machine.TileEntityAssemblyNetwork;
import assemblyline.common.machine.TileEntityAssembly;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork implements IRotatable, IFilterable, IPacketReceiver
public abstract class TileEntityFilterable extends TileEntityAssembly implements IRotatable, IFilterable, IPacketReceiver
{
private ItemStack filterItem;
private boolean inverted;

View file

@ -1,17 +0,0 @@
package assemblyline.common.machine;
import net.minecraft.block.material.Material;
import assemblyline.common.TabAssemblyLine;
import assemblyline.common.block.BlockALMachine;
public class BlockBeltSorter extends BlockALMachine
{
public BlockBeltSorter(int id)
{
super(id, Material.iron);
this.setCreativeTab(TabAssemblyLine.INSTANCE);
this.setUnlocalizedName("BeltSorter");
}
}

View file

@ -17,14 +17,14 @@ import assemblyline.common.block.BlockCrate;
import assemblyline.common.block.TileEntityCrate;
import assemblyline.common.imprinter.ItemImprinter;
public class InvExtractionHelper
public class InvInteractionHelper
{
World world;
Vector3 location;
List<ItemStack> filterItems;
boolean inverted;
public InvExtractionHelper(World world, Vector3 location, List<ItemStack> filters, boolean inverted)
public InvInteractionHelper(World world, Vector3 location, List<ItemStack> filters, boolean inverted)
{
this.world = world;
this.location = location;

View file

@ -0,0 +1,59 @@
package assemblyline.common.machine;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
import dark.core.api.INetworkPart;
import dark.core.tile.network.NetworkTileEntities;
public class NetworkAssembly extends NetworkTileEntities
{
/** List of network members that are providing power for the network */
private List<TileEntity> powerSources = new ArrayList<TileEntity>();
public NetworkAssembly(INetworkPart... parts)
{
super(parts);
}
public boolean canRun(TileEntityAssembly tile)
{
return false;
}
@Override
public void postMergeProcessing(NetworkTileEntities network)
{
NetworkAssembly newNetwork = new NetworkAssembly();
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
newNetwork.getNetworkMemebers().addAll(network.getNetworkMemebers());
newNetwork.cleanUpConductors();
}
public boolean addNetworkPart(INetworkPart part)
{
boolean added = super.addNetworkPart(part);
if (added)
{
}
return added;
}
/** Marks a tile as the source of power for the network */
public void markAsPowerSource(TileEntity entity)
{
if (!this.powerSources.contains(entity))
{
this.powerSources.add(entity);
}
}
/** unmarks or removes the tile as a source of power for the network */
public void removeAsPowerSource(TileEntity entity)
{
this.powerSources.remove(entity);
}
}

View file

@ -0,0 +1,96 @@
package assemblyline.common.machine;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.prefab.network.PacketManager;
import assemblyline.common.AssemblyLine;
import dark.core.api.INetworkPart;
import dark.core.tile.network.NetworkTileEntities;
import dark.library.machine.TileEntityRunnableMachine;
/** A class to be inherited by all machines on the assembly line. This will allow all machines to be
* able to be powered through the powering of only one machine.
*
* @author Calclavia */
public abstract class TileEntityAssembly extends TileEntityRunnableMachine implements INetworkPart
{
boolean powered = false;
/** Network used to link assembly machines together */
private NetworkAssembly assemblyNetwork;
public boolean isRunning()
{
boolean running = AssemblyLine.REQUIRE_NO_POWER || this.powered;
if (!running && this.getTileNetwork() instanceof NetworkAssembly)
{
}
return running;
}
@Override
public void updateEntity()
{
super.updateEntity();
this.onUpdate();
if (this.wattsReceived >= this.getRequest().getWatts())
{
this.wattsReceived -= getRequest().getWatts();
}
}
public abstract void onUpdate();
@Override
public ElectricityPack getRequest()
{
return new ElectricityPack(1, this.getVoltage());
}
protected int getMaxTransferRange()
{
return 30;
}
@Override
public boolean canTileConnect(TileEntity entity, ForgeDirection dir)
{
return entity != null && entity instanceof TileEntityAssembly;
}
@Override
public TileEntity[] getNetworkConnections()
{
// TODO Auto-generated method stub
return null;
}
@Override
public void updateNetworkConnections()
{
// TODO Auto-generated method stub
}
@Override
public NetworkTileEntities getTileNetwork()
{
if (this.assemblyNetwork == null)
{
this.assemblyNetwork = new NetworkAssembly(this);
}
return null;
}
@Override
public void setTileNetwork(NetworkTileEntities network)
{
if(network instanceof NetworkAssembly)
{
this.assemblyNetwork = (NetworkAssembly) network;
}
}
}

View file

@ -1,100 +0,0 @@
package assemblyline.common.machine;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.prefab.network.PacketManager;
import assemblyline.common.AssemblyLine;
import dark.library.machine.TileEntityRunnableMachine;
/**
* A class to be inherited by all machines on the assembly line. This will allow all machines to be
* able to be powered through the powering of only one machine.
*
* @author Calclavia
*
*/
public abstract class TileEntityAssemblyNetwork extends TileEntityRunnableMachine
{
/**
* The range in which power can be transfered.
*/
public int powerTransferRange = 0;
public boolean isRunning()
{
return AssemblyLine.REQUIRE_NO_POWER || this.powerTransferRange > 0 || this.wattsReceived > this.getRequest().getWatts();
}
public void updatePowerTransferRange()
{
int maximumTransferRange = 0;
for (int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
TileEntity tileEntity = worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ);
if (tileEntity != null)
{
if (tileEntity instanceof TileEntityAssemblyNetwork)
{
TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork) tileEntity;
if (assemblyNetwork.powerTransferRange > maximumTransferRange)
{
maximumTransferRange = assemblyNetwork.powerTransferRange;
}
}
}
}
this.powerTransferRange = Math.max(maximumTransferRange - 1, 0);
}
@Override
public void updateEntity()
{
super.updateEntity();
this.onUpdate();
if (this.ticks % 10 == 0)
{
if (this.wattsReceived >= this.getRequest().getWatts())
{
this.wattsReceived -= getRequest().getWatts();
this.powerTransferRange = this.getMaxTransferRange();
}
else
{
this.powerTransferRange = 0;
this.updatePowerTransferRange();
}
if (!this.worldObj.isRemote)
{
if (this.getDescriptionPacket() != null)
{
PacketManager.sendPacketToClients(this.getDescriptionPacket());
}
}
}
}
protected void onUpdate()
{
}
@Override
public ElectricityPack getRequest()
{
return new ElectricityPack(1, this.getVoltage());
}
protected int getMaxTransferRange()
{
return 30;
}
}

View file

@ -25,10 +25,10 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
/** True if is currently powered by redstone */
private boolean isRedstonePowered = false;
/** The class that interacts with inventories for this machine */
private InvExtractionHelper invExtractionHelper;
private InvInteractionHelper invExtractionHelper;
@Override
protected void onUpdate()
public void onUpdate()
{
if (!this.worldObj.isRemote)
{
@ -201,11 +201,11 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
}
/** Gets the class that managed extracting and placing items into inventories */
public InvExtractionHelper invHelper()
public InvInteractionHelper invHelper()
{
if (invExtractionHelper == null || invExtractionHelper.world != this.worldObj)
{
this.invExtractionHelper = new InvExtractionHelper(this.worldObj, new Vector3(this), this.getFilter() != null ? ItemImprinter.getFilters(getFilter()) : null, this.isInverted());
this.invExtractionHelper = new InvInteractionHelper(this.worldObj, new Vector3(this), this.getFilter() != null ? ItemImprinter.getFilters(getFilter()) : null, this.isInverted());
}
return invExtractionHelper;
}

View file

@ -39,7 +39,6 @@ public class TileEntityRejector extends TileEntityFilterable
@Override
public void onUpdate()
{
super.onUpdate();
/**
* Has to update a bit faster than a conveyer belt
*/

View file

@ -1,233 +0,0 @@
package assemblyline.common.machine;
import net.minecraft.entity.player.EntityPlayer;
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.Packet250CustomPayload;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityRoboticSorter extends TileEntityElectricityRunnable implements IPacketReceiver, IInventory
{
/**
* The items this container contains.
*/
protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()];
/**
* Used to id the packet types
*/
private enum PacketTypes
{
ANIMATION, GUI, SETTINGON
}
/**
* Joules required per tick.
*/
public static final int WATT_REQUEST = 10;
/**
* Stored energy
*/
public double wattsReceived = 0;
/**
* on/off value for the GUI buttons
*/
public boolean[] guiButtons = new boolean[] { true, true, true, true, true };
/**
* the belt found in the search area
*/
public TileEntityConveyorBelt[] beltSide = new TileEntityConveyorBelt[6];
private int playerUsing = 0;
@Override
public String getInvName()
{
return "Sorter";
}
@Override
public int getSizeInventory()
{
return 4;
}
/**
* Inventory functions.
*/
@Override
public ItemStack getStackInSlot(int par1)
{
return this.containingItems[par1];
}
@Override
public ItemStack decrStackSize(int par1, int par2)
{
if (this.containingItems[par1] != null)
{
ItemStack var3;
if (this.containingItems[par1].stackSize <= par2)
{
var3 = this.containingItems[par1];
this.containingItems[par1] = null;
return var3;
}
else
{
var3 = this.containingItems[par1].splitStack(par2);
if (this.containingItems[par1].stackSize == 0)
{
this.containingItems[par1] = null;
}
return var3;
}
}
else
{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.containingItems[par1] != null)
{
ItemStack var2 = this.containingItems[par1];
this.containingItems[par1] = null;
return var2;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{
this.containingItems[par1] = par2ItemStack;
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
{
par2ItemStack.stackSize = this.getInventoryStackLimit();
}
}
@Override
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
{
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D;
}
@Override
public void openChest()
{
this.playerUsing++;
}
@Override
public void closeChest()
{
this.playerUsing--;
}
/**
* NBT Data
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
for (int i = 0; i < this.guiButtons.length; i++)
{
this.guiButtons[i] = nbt.getBoolean("guiButton" + i);
}
NBTTagList var2 = nbt.getTagList("Items");
this.containingItems = new ItemStack[this.getSizeInventory()];
for (int var3 = 0; var3 < var2.tagCount(); ++var3)
{
NBTTagCompound var4 = (NBTTagCompound) var2.tagAt(var3);
byte var5 = var4.getByte("Slot");
if (var5 >= 0 && var5 < this.containingItems.length)
{
this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4);
}
}
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
// TODO Auto-generated method stub
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
for (int i = 0; i < this.guiButtons.length; i++)
{
nbt.setBoolean("guiButton" + i, this.guiButtons[i]);
}
NBTTagList var2 = new NBTTagList();
for (int var3 = 0; var3 < this.containingItems.length; ++var3)
{
if (this.containingItems[var3] != null)
{
NBTTagCompound var4 = new NBTTagCompound();
var4.setByte("Slot", (byte) var3);
this.containingItems[var3].writeToNBT(var4);
var2.appendTag(var4);
}
}
nbt.setTag("Items", var2);
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean canConnect(ForgeDirection dir)
{
return dir == ForgeDirection.DOWN;
}
@Override
public boolean isInvNameLocalized()
{
return false;
}
@Override
public boolean isStackValidForSlot(int i, ItemStack itemstack)
{
return false;
}
}

View file

@ -246,7 +246,6 @@ public class BlockConveyorBelt extends BlockALMachine
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity)
{
TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt) world.getBlockTileEntity(x, y, z);
tileEntity.updatePowerTransferRange();
if (tileEntity.IgnoreList.contains(entity))
{
return;

View file

@ -19,14 +19,14 @@ import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import assemblyline.api.IBelt;
import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.TileEntityAssemblyNetwork;
import assemblyline.common.machine.TileEntityAssembly;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements IPacketReceiver, IBelt, IRotatable
public class TileEntityConveyorBelt extends TileEntityAssembly implements IPacketReceiver, IBelt, IRotatable
{
public enum SlantType
{
@ -45,67 +45,10 @@ public class TileEntityConveyorBelt extends TileEntityAssemblyNetwork implements
public float wheelRotation = 0;
private int animFrame = 0; // this is from 0 to 15
private SlantType slantType = SlantType.NONE;
/** Entities that are ignored allowing for other tiles to interact with them */
public List<Entity> IgnoreList = new ArrayList<Entity>();
public List<Entity> IgnoreList = new ArrayList<Entity>();// Entities that need to be ignored to
// prevent movement
/**
* This function is overriden to allow conveyor belts to power belts that are diagonally going
* up.
*/
@Override
public void updatePowerTransferRange()
{
int maximumTransferRange = 0;
for (int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
TileEntity tileEntity = worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ);
if (tileEntity != null)
{
if (tileEntity instanceof TileEntityAssemblyNetwork)
{
TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork) tileEntity;
if (assemblyNetwork.powerTransferRange > maximumTransferRange)
{
maximumTransferRange = assemblyNetwork.powerTransferRange;
}
}
}
}
for (int d = 0; d <= 1; d++)
{
ForgeDirection direction = this.getDirection();
if (d == 1)
{
direction = direction.getOpposite();
}
for (int i = -1; i <= 1; i++)
{
TileEntity tileEntity = worldObj.getBlockTileEntity(this.xCoord + direction.offsetX, this.yCoord + i, this.zCoord + direction.offsetZ);
if (tileEntity != null)
{
if (tileEntity instanceof TileEntityAssemblyNetwork)
{
TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork) tileEntity;
if (assemblyNetwork.powerTransferRange > maximumTransferRange)
{
maximumTransferRange = assemblyNetwork.powerTransferRange;
}
}
}
}
}
this.powerTransferRange = Math.max(maximumTransferRange - 1, 0);
}
@Override
public void onUpdate()

View file

@ -1,13 +0,0 @@
package assemblyline.common.machine.belt;
/**
* For the moment this is just a render place holder, but will be convered to prevent item pickups
* from the belts.
*
* @author Rseifert
*
*/
public class TileEntityCoveredBelt extends TileEntityConveyorBelt
{
}

View file

@ -7,9 +7,9 @@ import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import assemblyline.api.ICraneStructure;
import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.TileEntityAssemblyNetwork;
import assemblyline.common.machine.TileEntityAssembly;
public class TileEntityCraneController extends TileEntityAssemblyNetwork implements ICraneStructure
public class TileEntityCraneController extends TileEntityAssembly implements ICraneStructure
{
int width, depth;
boolean isCraneValid;
@ -213,4 +213,10 @@ public class TileEntityCraneController extends TileEntityAssemblyNetwork impleme
{
return true;
}
@Override
public void onUpdate()
{
// TODO Auto-generated method stub
}
}

View file

@ -2,9 +2,9 @@ package assemblyline.common.machine.crane;
import net.minecraftforge.common.ForgeDirection;
import assemblyline.api.ICraneStructure;
import assemblyline.common.machine.TileEntityAssemblyNetwork;
import assemblyline.common.machine.TileEntityAssembly;
public class TileEntityCraneRail extends TileEntityAssemblyNetwork implements ICraneStructure
public class TileEntityCraneRail extends TileEntityAssembly implements ICraneStructure
{
@Override
@ -19,4 +19,11 @@ public class TileEntityCraneRail extends TileEntityAssemblyNetwork implements IC
return false;
}
@Override
public void onUpdate()
{
// TODO Auto-generated method stub
}
}

View file

@ -110,4 +110,11 @@ public class TileEntityDetector extends TileEntityFilterable
{
return direction != this.getDirection();
}
@Override
public void onUpdate()
{
// TODO Auto-generated method stub
}
}