From 5d41e8644df59bff0c6330f0c3d9e08326aded1e Mon Sep 17 00:00:00 2001 From: AtomicStryker Date: Sat, 8 Dec 2012 18:26:28 +0100 Subject: [PATCH 1/2] Atomic's Once-over See issues for comments --- src/common/assemblyline/AssemblyLine.java | 2 +- src/common/assemblyline/ai/Task.java | 13 +- src/common/assemblyline/ai/TaskIdle.java | 2 +- src/common/assemblyline/ai/TaskManager.java | 24 +- src/common/assemblyline/api/IBelt.java | 8 +- .../machine/belt/TileEntityConveyorBelt.java | 11 +- .../machine/crafter/BlockCrafter.java | 129 ++++++++ .../machine/crafter/ContainerCrafter.java | 95 ++++++ .../machine/crafter/EntityCraftingArm.java | 72 +++++ .../machine/crafter/ItemCrafterArm.java | 14 + .../machine/crafter/TaskArmCollect.java | 38 +++ .../machine/crafter/TaskArmSearch.java | 61 ++++ .../crafter/TileEntityAutoCrafter.java | 27 ++ .../crafter/TileEntityCraftingArm.java | 282 ++++++++++++++++++ .../render/RenderConveyorBelt.java | 12 +- .../render/RenderManipulator.java | 8 +- .../assemblyline/render/RenderSorter.java | 6 +- 17 files changed, 768 insertions(+), 36 deletions(-) create mode 100644 src/common/assemblyline/machine/crafter/BlockCrafter.java create mode 100644 src/common/assemblyline/machine/crafter/ContainerCrafter.java create mode 100644 src/common/assemblyline/machine/crafter/EntityCraftingArm.java create mode 100644 src/common/assemblyline/machine/crafter/ItemCrafterArm.java create mode 100644 src/common/assemblyline/machine/crafter/TaskArmCollect.java create mode 100644 src/common/assemblyline/machine/crafter/TaskArmSearch.java create mode 100644 src/common/assemblyline/machine/crafter/TileEntityAutoCrafter.java create mode 100644 src/common/assemblyline/machine/crafter/TileEntityCraftingArm.java diff --git a/src/common/assemblyline/AssemblyLine.java b/src/common/assemblyline/AssemblyLine.java index 494f7e949..fdd8b6126 100644 --- a/src/common/assemblyline/AssemblyLine.java +++ b/src/common/assemblyline/AssemblyLine.java @@ -33,7 +33,7 @@ import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; -@Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "after:BasicComponents") +@Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "required-after:BasicComponents") @NetworkMod(channels = { AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class) public class AssemblyLine { diff --git a/src/common/assemblyline/ai/Task.java b/src/common/assemblyline/ai/Task.java index 9ea554f46..1e01480a6 100644 --- a/src/common/assemblyline/ai/Task.java +++ b/src/common/assemblyline/ai/Task.java @@ -1,6 +1,6 @@ package assemblyline.ai; -import assemblyline.machines.crafter.TileEntityCraftingArm; +import assemblyline.machine.crafter.TileEntityCraftingArm; /** * An AI Task that is used by TileEntities with AI. @@ -19,11 +19,11 @@ public abstract class Task } /** - * Called when a task is being done. + * Called by the TaskManager to propagate tick updates * * @param ticks - * The amount of ticks this task has been elapsed for. - * @return Return true if the task is not finished and false if it is. + * The amount of ticks this task has been running + * @return false if the task is finished and can be removed, true otherwise */ protected boolean doTask() { @@ -33,7 +33,6 @@ public abstract class Task public void onTaskStart() { - } public void onTaskEnd() @@ -41,10 +40,10 @@ public abstract class Task } /** - * @return The tick interval of this task. Return 0 for no ticks. + * @return The tick interval of this task. 0 means it will receive no update ticks. */ public int getTickInterval() { - return 1; + return 0; } } diff --git a/src/common/assemblyline/ai/TaskIdle.java b/src/common/assemblyline/ai/TaskIdle.java index da12f162a..077651be6 100644 --- a/src/common/assemblyline/ai/TaskIdle.java +++ b/src/common/assemblyline/ai/TaskIdle.java @@ -1,6 +1,6 @@ package assemblyline.ai; -import assemblyline.machines.crafter.TileEntityCraftingArm; +import assemblyline.machine.crafter.TileEntityCraftingArm; public class TaskIdle extends Task { diff --git a/src/common/assemblyline/ai/TaskManager.java b/src/common/assemblyline/ai/TaskManager.java index af5c7add2..784ced88e 100644 --- a/src/common/assemblyline/ai/TaskManager.java +++ b/src/common/assemblyline/ai/TaskManager.java @@ -1,6 +1,7 @@ package assemblyline.ai; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import net.minecraft.src.TileEntity; @@ -22,8 +23,11 @@ public class TaskManager */ try { - for (Task task : this.tasks) + Task task; + Iterator iter = tasks.iterator(); + while (iter.hasNext()) { + task = iter.next(); if (task.getTickInterval() > 0) { if (this.ticks % task.getTickInterval() == 0) @@ -31,7 +35,7 @@ public class TaskManager if (!task.doTask()) { task.onTaskEnd(); - tasks.remove(task); + iter.remove(); } } } @@ -46,14 +50,24 @@ public class TaskManager this.ticks++; } + /** + * Used to register Tasks for a TileEntity, executes onTaskStart + * for the Task after registering it + * + * @param tileEntity TE instance to register the task for + * @param task Task instance to register + */ public void addTask(TileEntity tileEntity, Task task) { - task.onTaskStart(); tasks.add(task); + task.onTaskStart(); } - public boolean hasTask() + /** + * @return true when there are tasks registered, false otherwise + */ + public boolean hasTasks() { - return this.tasks.size() > 0; + return !tasks.isEmpty(); } } diff --git a/src/common/assemblyline/api/IBelt.java b/src/common/assemblyline/api/IBelt.java index 9f9b7567a..75c507d3b 100644 --- a/src/common/assemblyline/api/IBelt.java +++ b/src/common/assemblyline/api/IBelt.java @@ -17,7 +17,7 @@ public interface IBelt /** * Causes the belt to ignore the entity for a few updates help in cases where another machine - * need to effect this entity without the belt doing so as well. + * needs to affect this particular entity without the belt interfering * * @param entity * - entity being ignored @@ -25,9 +25,9 @@ public interface IBelt public void ignoreEntity(Entity entity); /** - * Used to get a list of entities above this belt + * Used to get a list of entities the belt exerts an effect upon. * - * @return list of entities + * @return list of entities in the belts are of effect */ - public List getEntityAbove(); + public List getAffectedEntities(); } diff --git a/src/common/assemblyline/machine/belt/TileEntityConveyorBelt.java b/src/common/assemblyline/machine/belt/TileEntityConveyorBelt.java index 99dcdde1d..24e66410d 100644 --- a/src/common/assemblyline/machine/belt/TileEntityConveyorBelt.java +++ b/src/common/assemblyline/machine/belt/TileEntityConveyorBelt.java @@ -177,7 +177,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem { try { - List entityOnTop = this.getEntityAbove(); + List entityOnTop = this.getAffectedEntities(); for (Entity entity : entityOnTop) { @@ -263,7 +263,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem return 0; } - public boolean middleBelt() + public boolean getIsMiddleBelt() { ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection()); @@ -280,7 +280,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem return false; } - public boolean FrontCap() + public boolean getIsFrontCap() { ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection()); @@ -296,7 +296,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem return false; } - public boolean BackCap() + public boolean getIsBackCap() { ForgeDirection front = ForgeDirection.getOrientation(getBeltDirection()); @@ -345,7 +345,8 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem return ForgeDirection.getOrientation(this.getBeltDirection()); } - public List getEntityAbove() + @Override + public List getAffectedEntities() { AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1); return worldObj.getEntitiesWithinAABB(Entity.class, bounds); diff --git a/src/common/assemblyline/machine/crafter/BlockCrafter.java b/src/common/assemblyline/machine/crafter/BlockCrafter.java new file mode 100644 index 000000000..ec944a340 --- /dev/null +++ b/src/common/assemblyline/machine/crafter/BlockCrafter.java @@ -0,0 +1,129 @@ +package assemblyline.machine.crafter; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.TileEntity; +import net.minecraft.src.World; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.prefab.BlockMachine; +import universalelectricity.prefab.UETab; +import assemblyline.AssemblyLine; + +public class BlockCrafter extends BlockMachine +{ + protected BlockCrafter(int id) + { + super("AutoCrafter", id, UniversalElectricity.machine); + this.setResistance(5.0f); + this.setHardness(5.0f); + this.setCreativeTab(UETab.INSTANCE); + } + + public static enum CrafterType + { + CRAFTER("Crafter", 0, -1, TileEntityAutoCrafter.class); + + public String name; + public int metadata; + public int guiID; + public Class tileEntity; + + CrafterType(String name, int metadata, int guiID, Class tileEntity) + { + this.name = name; + this.metadata = metadata; + this.guiID = guiID; + this.tileEntity = tileEntity; + } + + public static CrafterType get(int metadata) + { + for (CrafterType value : CrafterType.values()) + { + if (metadata >= value.metadata && metadata < value.metadata + 4) { return value; } + } + + return null; + } + + /** + * Gets the direction based on the metadata + * + * @return A direction value from 0 to 4. + */ + public static int getDirection(int metadata) + { + return metadata - CrafterType.get(metadata).metadata; + } + + /** + * @param currentDirection - An integer from 0 to 4. + * @return The metadata this block should change into. + */ + public int getNextDirectionMeta(int currentDirection) + { + currentDirection++; + + if (currentDirection >= 4) + { + currentDirection = 0; + } + + return currentDirection + this.metadata; + } + + /** + * Creates a new TIleEntity. + */ + public TileEntity instantiateTileEntity() + { + try + { + return this.tileEntity.newInstance(); + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + } + + @Override + public TileEntity createNewTileEntity(World var1) + { + + return null; + } + + @Override + public TileEntity createNewTileEntity(World var1, int metadata) + { + return CrafterType.get(metadata).instantiateTileEntity(); + } + + @Override + public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) + { + if (!par1World.isRemote) + { + int metadata = par1World.getBlockMetadata(x, y, z); + int guiID = CrafterType.get(metadata).metadata; + if (guiID == -1) + return false; + par5EntityPlayer.openGui(AssemblyLine.instance, guiID, par1World, x, y, z); + return true; + } + return true; + } + + @Override + public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) + { + return false; + } + + public int getRenderType() + { + return 0; + } +} diff --git a/src/common/assemblyline/machine/crafter/ContainerCrafter.java b/src/common/assemblyline/machine/crafter/ContainerCrafter.java new file mode 100644 index 000000000..32df1e239 --- /dev/null +++ b/src/common/assemblyline/machine/crafter/ContainerCrafter.java @@ -0,0 +1,95 @@ +package assemblyline.machine.crafter; + +import net.minecraft.src.Container; +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.InventoryPlayer; +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; +import net.minecraft.src.Slot; + +/** + * I am planning to make the crafter not use a GUI. + * + * @author Calclavia + * + */ +@Deprecated +public class ContainerCrafter extends Container +{ + private TileEntityAutoCrafter tileEntity; + + public ContainerCrafter(InventoryPlayer par1InventoryPlayer, TileEntityAutoCrafter tileEntity) + { + this.tileEntity = tileEntity; + for (int r = 0; r < 3; r++) + { + for (int i = 0; i < 3; i++) + { + // this.addSlotToContainer(new + // Slot(tileEntity, i + r * 3, 33 + // + i * 18, 34 + r * 18)); + } + } + int var3; + + for (var3 = 0; var3 < 3; ++var3) + { + for (int var4 = 0; var4 < 9; ++var4) + { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); + } + } + + for (var3 = 0; var3 < 9; ++var3) + { + this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142)); + } + } + + @Override + public boolean canInteractWith(EntityPlayer par1EntityPlayer) + { + return true; + } + + /** + * Called to transfer a stack from one inventory to the other eg. when shift clicking. + */ + @Override + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) + { + ItemStack itemStack3 = null; + Slot itemStack = (Slot) this.inventorySlots.get(par1); + + if (itemStack != null && itemStack.getHasStack()) + { + ItemStack itemStack2 = itemStack.getStack(); + itemStack3 = itemStack2.copy(); + + if (par1 != 0) + { + if (itemStack2.itemID == Item.coal.shiftedIndex) + { + if (!this.mergeItemStack(itemStack2, 0, 1, false)) { return null; } + } + else if (par1 >= 30 && par1 < 37 && !this.mergeItemStack(itemStack2, 3, 30, false)) { return null; } + } + else if (!this.mergeItemStack(itemStack2, 3, 37, false)) { return null; } + + if (itemStack2.stackSize == 0) + { + itemStack.putStack((ItemStack) null); + } + else + { + itemStack.onSlotChanged(); + } + + if (itemStack2.stackSize == itemStack3.stackSize) { return null; } + + itemStack.onPickupFromSlot(par1EntityPlayer, itemStack2); + } + + return itemStack3; + } +} diff --git a/src/common/assemblyline/machine/crafter/EntityCraftingArm.java b/src/common/assemblyline/machine/crafter/EntityCraftingArm.java new file mode 100644 index 000000000..78e014709 --- /dev/null +++ b/src/common/assemblyline/machine/crafter/EntityCraftingArm.java @@ -0,0 +1,72 @@ +package assemblyline.machine.crafter; + +import net.minecraft.src.Entity; +import net.minecraft.src.EntityItem; +import net.minecraft.src.ItemStack; +import net.minecraft.src.NBTTagCompound; +import net.minecraft.src.World; +import universalelectricity.core.vector.Vector3; + +public class EntityCraftingArm extends Entity +{ + /** + * Used to ID the type of arm + */ + static enum armType + { + ARM, SOLDER, DRILL, BREAKER + } + + /** + * type of arm this robotic arm currently is + */ + public armType arm = armType.ARM; + /** + * stack this arm is holding if any + */ + public ItemStack stack = null; + /** + * TileEntity this arm is working with + */ + public TileEntityCraftingArm blockArm = null; + /** + * position that the arms claw should be at + */ + public Vector3 clawPos = new Vector3(); + + public boolean isWorking = false; + + public EntityCraftingArm(World par1World) + { + super(par1World); + } + + @Override + protected void entityInit() + { + + } + + @Override + protected void readEntityFromNBT(NBTTagCompound nbt) + { + this.arm = armType.values()[nbt.getInteger("type")]; + + } + + @Override + protected void writeEntityToNBT(NBTTagCompound nbt) + { + nbt.setInteger("type", arm.ordinal()); + } + + public boolean grabItem(EntityItem item) + { + if (this.stack == null) + { + // TODO set current stack to item as + // soon as it reaches coords + } + return false; + } +} diff --git a/src/common/assemblyline/machine/crafter/ItemCrafterArm.java b/src/common/assemblyline/machine/crafter/ItemCrafterArm.java new file mode 100644 index 000000000..abd743c61 --- /dev/null +++ b/src/common/assemblyline/machine/crafter/ItemCrafterArm.java @@ -0,0 +1,14 @@ +package assemblyline.machine.crafter; + +import net.minecraft.src.Item; + +public class ItemCrafterArm extends Item +{ + + protected ItemCrafterArm(int par1) + { + super(par1); + this.setHasSubtypes(true); + } + +} diff --git a/src/common/assemblyline/machine/crafter/TaskArmCollect.java b/src/common/assemblyline/machine/crafter/TaskArmCollect.java new file mode 100644 index 000000000..943a4b303 --- /dev/null +++ b/src/common/assemblyline/machine/crafter/TaskArmCollect.java @@ -0,0 +1,38 @@ +package assemblyline.machine.crafter; + +import net.minecraft.src.EntityItem; +import assemblyline.ai.Task; + +/** + * Used by arms to collect items in a specific region. + * + * @author Calclavia + */ +public class TaskArmCollect extends Task +{ + + /** + * The item to be collected. + */ + private EntityItem entityItem; + + public TaskArmCollect(TileEntityCraftingArm arm, EntityItem entityItem) + { + super(arm); + this.entityItem = entityItem; + } + + @Override + protected boolean doTask() + { + super.doTask(); + + if (entityItem == null) { return false; } + + /** + * Slowly stretch down the arm's model and grab the item + */ + + return true; + } +} diff --git a/src/common/assemblyline/machine/crafter/TaskArmSearch.java b/src/common/assemblyline/machine/crafter/TaskArmSearch.java new file mode 100644 index 000000000..9d1d23ba2 --- /dev/null +++ b/src/common/assemblyline/machine/crafter/TaskArmSearch.java @@ -0,0 +1,61 @@ +package assemblyline.machine.crafter; + +import java.util.List; + +import net.minecraft.src.AxisAlignedBB; +import net.minecraft.src.Entity; +import assemblyline.ai.Task; + +/** + * Used by arms to search for entities in a region + * + * @author Calclavia + */ +public class TaskArmSearch extends Task +{ + + /** + * The item to be collected. + */ + private Class entityToInclude; + + private float searchSpeed; + + private double radius; + + private Entity foundEntity; + + public TaskArmSearch(TileEntityCraftingArm arm, Class entityToInclude, double radius, float searchSpeed) + { + super(arm); + this.entityToInclude = entityToInclude; + this.radius = radius; + this.searchSpeed = searchSpeed; + } + + @Override + public void onTaskStart() + { + List found = tileEntity.worldObj.getEntitiesWithinAABB(entityToInclude, + AxisAlignedBB.getBoundingBox(tileEntity.xCoord - radius, tileEntity.yCoord - radius, tileEntity.zCoord - radius, + tileEntity.xCoord + radius, tileEntity.yCoord + radius, tileEntity.zCoord + radius)); + if (found != null && !found.isEmpty()) + { + foundEntity = (Entity) found.get(0); + } + } + + @Override + protected boolean doTask() + { + super.doTask(); + + if (this.entityToInclude == null || this.foundEntity == null) { return false; } + + /** + * Move the robotic arm around and emulate an item search. Then initiate a collect task. + */ + + return true; + } +} diff --git a/src/common/assemblyline/machine/crafter/TileEntityAutoCrafter.java b/src/common/assemblyline/machine/crafter/TileEntityAutoCrafter.java new file mode 100644 index 000000000..35df0967b --- /dev/null +++ b/src/common/assemblyline/machine/crafter/TileEntityAutoCrafter.java @@ -0,0 +1,27 @@ +package assemblyline.machine.crafter; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.INetworkManager; +import net.minecraft.src.Packet250CustomPayload; +import universalelectricity.prefab.tile.TileEntityAdvanced; + +import com.google.common.io.ByteArrayDataInput; + +public class TileEntityAutoCrafter extends TileEntityAdvanced +{ + public String getInvName() + { + return "Auto Crafter"; + } + + public int getSizeInventory() + { + return 10; + } + + public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) + { + + } + +} diff --git a/src/common/assemblyline/machine/crafter/TileEntityCraftingArm.java b/src/common/assemblyline/machine/crafter/TileEntityCraftingArm.java new file mode 100644 index 000000000..30734836f --- /dev/null +++ b/src/common/assemblyline/machine/crafter/TileEntityCraftingArm.java @@ -0,0 +1,282 @@ +package assemblyline.machine.crafter; + +import java.util.EnumSet; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.IInventory; +import net.minecraft.src.INetworkManager; +import net.minecraft.src.ItemStack; +import net.minecraft.src.NBTTagCompound; +import net.minecraft.src.NBTTagList; +import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.electricity.ElectricityConnections; +import universalelectricity.core.implement.IConductor; +import universalelectricity.core.implement.IJouleStorage; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.network.IPacketReceiver; +import universalelectricity.prefab.tile.TileEntityElectricityReceiver; +import assemblyline.ai.TaskManager; + +import com.google.common.io.ByteArrayDataInput; + +public class TileEntityCraftingArm extends TileEntityElectricityReceiver implements IInventory, IPacketReceiver, IJouleStorage +{ + /** + * The items this container contains. + */ + protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()]; + + private TaskManager taskManager = new TaskManager(); + + /** + * Entity robotic arm to be used with this tileEntity + */ + public EntityCraftingArm EntityArm = null; + + public final double WATT_REQUEST = 20; + + public double wattsReceived = 0; + + private int playerUsing = 0; + + @Override + public void initiate() + { + ElectricityConnections.registerConnector(this, EnumSet.of(ForgeDirection.DOWN, ForgeDirection.SOUTH, ForgeDirection.NORTH, ForgeDirection.EAST, ForgeDirection.WEST)); + } + + public void updateEntity() + { + super.updateEntity(); + + if (!this.worldObj.isRemote) + { + for (int i = 0; i < 6; i++) + { + ForgeDirection inputDirection = ForgeDirection.getOrientation(i); + + if (inputDirection != ForgeDirection.UP) + { + TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, Vector3.get(this), inputDirection); + + if (inputTile != null) + { + if (inputTile instanceof IConductor) + { + if (this.getJoules() >= this.getMaxJoules()) + { + ((IConductor) inputTile).getNetwork().stopRequesting(this); + } + else + { + ((IConductor) inputTile).getNetwork().startRequesting(this, this.WATT_REQUEST / this.getVoltage(), this.getVoltage()); + this.setJoules(this.getJoules() + ((IConductor) inputTile).getNetwork().consumeElectricity(this).getWatts()); + } + } + } + } + } + } + + taskManager.onUpdate(); + + if (this.ticks % 5 == 0 && !this.isDisabled() && this.taskManager.hasTasks() && EntityArm != null) + { + this.wattsReceived -= this.WATT_REQUEST; + this.doWork(); + } + } + + /** + * controls the robotic arm into doing a set task + */ + public void doWork() + { + + } + + @Override + public double getVoltage() + { + return 120; + } + + /** + * Data + */ + @Override + public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) + { + + } + + /** + * inventory + */ + @Override + public int getSizeInventory() + { + return 1; + } + + @Override + public String getInvName() + { + return "RoboticArm"; + } + + /** + * 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 int getInventoryStackLimit() + { + return 64; + } + + @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); + + 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); + } + } + } + + /** + * Writes a tile entity to NBT. + */ + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + 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 double getJoules(Object... data) + { + return this.wattsReceived; + } + + @Override + public void setJoules(double joules, Object... data) + { + this.wattsReceived = joules; + } + + @Override + public double getMaxJoules(Object... data) + { + return 1000; + } + +} diff --git a/src/minecraft/assemblyline/render/RenderConveyorBelt.java b/src/minecraft/assemblyline/render/RenderConveyorBelt.java index aab6ffe87..a05f8d950 100644 --- a/src/minecraft/assemblyline/render/RenderConveyorBelt.java +++ b/src/minecraft/assemblyline/render/RenderConveyorBelt.java @@ -13,11 +13,11 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer { private ModelConveyorBelt model = new ModelConveyorBelt(); - public void renderAModelAt(TileEntityConveyorBelt tileEntity, double x, double y, double z, float f) + private void renderAModelAt(TileEntityConveyorBelt tileEntity, double x, double y, double z, float f) { String flip = "";// if(tileEntity.flip){flip // = "F";} - boolean mid = tileEntity.middleBelt(); + boolean mid = tileEntity.getIsMiddleBelt(); int face = tileEntity.getBeltDirection(); GL11.glPushMatrix(); @@ -29,20 +29,20 @@ public class RenderConveyorBelt extends TileEntitySpecialRenderer { GL11.glRotatef(180f, 0f, 1f, 0f); } - if (face == 3) + else if (face == 3) { GL11.glRotatef(0f, 0f, 1f, 0f); } - if (face == 4) + else if (face == 4) { GL11.glRotatef(90f, 0f, 1f, 0f); } - if (face == 5) + else if (face == 5) { GL11.glRotatef(270f, 0f, 1f, 0f); } int ent = tileEntity.worldObj.getBlockId(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); - model.render(0.0625F, (float) Math.toRadians(tileEntity.wheelRotation), tileEntity.BackCap(), tileEntity.FrontCap(), false); + model.render(0.0625F, (float) Math.toRadians(tileEntity.wheelRotation), tileEntity.getIsBackCap(), tileEntity.getIsFrontCap(), false); GL11.glPopMatrix(); diff --git a/src/minecraft/assemblyline/render/RenderManipulator.java b/src/minecraft/assemblyline/render/RenderManipulator.java index 81e7ce9b5..68dd2f33f 100644 --- a/src/minecraft/assemblyline/render/RenderManipulator.java +++ b/src/minecraft/assemblyline/render/RenderManipulator.java @@ -13,7 +13,7 @@ public class RenderManipulator extends TileEntitySpecialRenderer { private ModelManipulator model = new ModelManipulator(); - public void renderAModelAt(TileEntityManipulator tileEntity, double x, double y, double z, float f) + private void renderAModelAt(TileEntityManipulator tileEntity, double x, double y, double z, float f) { int face = tileEntity.getBeltDirection().ordinal(); @@ -34,15 +34,15 @@ public class RenderManipulator extends TileEntitySpecialRenderer { GL11.glRotatef(0f, 0f, 1f, 0f); } - if (face == 3) + else if (face == 3) { GL11.glRotatef(180f, 0f, 1f, 0f); } - if (face == 4) + else if (face == 4) { GL11.glRotatef(270f, 0f, 1f, 0f); } - if (face == 5) + else if (face == 5) { GL11.glRotatef(90f, 0f, 1f, 0f); } diff --git a/src/minecraft/assemblyline/render/RenderSorter.java b/src/minecraft/assemblyline/render/RenderSorter.java index 4d5684de0..61c166fa9 100644 --- a/src/minecraft/assemblyline/render/RenderSorter.java +++ b/src/minecraft/assemblyline/render/RenderSorter.java @@ -13,7 +13,7 @@ public class RenderSorter extends TileEntitySpecialRenderer { private ModelSorter model = new ModelSorter(); - public void renderAModelAt(TileEntityRejector tileEntity, double x, double y, double z, float f) + private void renderAModelAt(TileEntityRejector tileEntity, double x, double y, double z, float f) { boolean fire = tileEntity.firePiston; int face = tileEntity.getDirection(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); @@ -34,11 +34,11 @@ public class RenderSorter extends TileEntitySpecialRenderer { GL11.glRotatef(0f, 0f, 1f, 0f); } - if (face == 4) + else if (face == 4) { GL11.glRotatef(90f, 0f, 1f, 0f); } - if (face == 5) + else if (face == 5) { GL11.glRotatef(270f, 0f, 1f, 0f); } From 7215733690c26ae0e14320e06dede9f868b005af Mon Sep 17 00:00:00 2001 From: AtomicStryker Date: Sat, 8 Dec 2012 18:28:48 +0100 Subject: [PATCH 2/2] The files Atomic refactored Delete! Exterminate! --- .../machines/crafter/BlockCrafter.java | 129 -------- .../machines/crafter/ContainerCrafter.java | 95 ------ .../machines/crafter/EntityCraftingArm.java | 72 ----- .../machines/crafter/ItemCrafterArm.java | 14 - .../machines/crafter/TaskArmCollect.java | 38 --- .../machines/crafter/TaskArmSearch.java | 53 ---- .../crafter/TileEntityAutoCrafter.java | 27 -- .../crafter/TileEntityCraftingArm.java | 282 ------------------ 8 files changed, 710 deletions(-) delete mode 100644 src/common/assemblyline/machines/crafter/BlockCrafter.java delete mode 100644 src/common/assemblyline/machines/crafter/ContainerCrafter.java delete mode 100644 src/common/assemblyline/machines/crafter/EntityCraftingArm.java delete mode 100644 src/common/assemblyline/machines/crafter/ItemCrafterArm.java delete mode 100644 src/common/assemblyline/machines/crafter/TaskArmCollect.java delete mode 100644 src/common/assemblyline/machines/crafter/TaskArmSearch.java delete mode 100644 src/common/assemblyline/machines/crafter/TileEntityAutoCrafter.java delete mode 100644 src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java diff --git a/src/common/assemblyline/machines/crafter/BlockCrafter.java b/src/common/assemblyline/machines/crafter/BlockCrafter.java deleted file mode 100644 index 119fe7cf5..000000000 --- a/src/common/assemblyline/machines/crafter/BlockCrafter.java +++ /dev/null @@ -1,129 +0,0 @@ -package assemblyline.machines.crafter; - -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.TileEntity; -import net.minecraft.src.World; -import universalelectricity.core.UniversalElectricity; -import universalelectricity.prefab.BlockMachine; -import universalelectricity.prefab.UETab; -import assemblyline.AssemblyLine; - -public class BlockCrafter extends BlockMachine -{ - protected BlockCrafter(int id) - { - super("AutoCrafter", id, UniversalElectricity.machine); - this.setResistance(5.0f); - this.setHardness(5.0f); - this.setCreativeTab(UETab.INSTANCE); - } - - public static enum CrafterType - { - CRAFTER("Crafter", 0, -1, TileEntityAutoCrafter.class); - - public String name; - public int metadata; - public int guiID; - public Class tileEntity; - - CrafterType(String name, int metadata, int guiID, Class tileEntity) - { - this.name = name; - this.metadata = metadata; - this.guiID = guiID; - this.tileEntity = tileEntity; - } - - public static CrafterType get(int metadata) - { - for (CrafterType value : CrafterType.values()) - { - if (metadata >= value.metadata && metadata < value.metadata + 4) { return value; } - } - - return null; - } - - /** - * Gets the direction based on the metadata - * - * @return A direction value from 0 to 4. - */ - public static int getDirection(int metadata) - { - return metadata - CrafterType.get(metadata).metadata; - } - - /** - * @param currentDirection - An integer from 0 to 4. - * @return The metadata this block should change into. - */ - public int getNextDirectionMeta(int currentDirection) - { - currentDirection++; - - if (currentDirection >= 4) - { - currentDirection = 0; - } - - return currentDirection + this.metadata; - } - - /** - * Creates a new TIleEntity. - */ - public TileEntity instantiateTileEntity() - { - try - { - return this.tileEntity.newInstance(); - } - catch (Exception e) - { - e.printStackTrace(); - return null; - } - } - } - - @Override - public TileEntity createNewTileEntity(World var1) - { - - return null; - } - - @Override - public TileEntity createNewTileEntity(World var1, int metadata) - { - return CrafterType.get(metadata).instantiateTileEntity(); - } - - @Override - public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) - { - if (!par1World.isRemote) - { - int metadata = par1World.getBlockMetadata(x, y, z); - int guiID = CrafterType.get(metadata).metadata; - if (guiID == -1) - return false; - par5EntityPlayer.openGui(AssemblyLine.instance, guiID, par1World, x, y, z); - return true; - } - return true; - } - - @Override - public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) - { - return false; - } - - public int getRenderType() - { - return 0; - } -} diff --git a/src/common/assemblyline/machines/crafter/ContainerCrafter.java b/src/common/assemblyline/machines/crafter/ContainerCrafter.java deleted file mode 100644 index 3f855378c..000000000 --- a/src/common/assemblyline/machines/crafter/ContainerCrafter.java +++ /dev/null @@ -1,95 +0,0 @@ -package assemblyline.machines.crafter; - -import net.minecraft.src.Container; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.InventoryPlayer; -import net.minecraft.src.Item; -import net.minecraft.src.ItemStack; -import net.minecraft.src.Slot; - -/** - * I am planning to make the crafter not use a GUI. - * - * @author Calclavia - * - */ -@Deprecated -public class ContainerCrafter extends Container -{ - private TileEntityAutoCrafter tileEntity; - - public ContainerCrafter(InventoryPlayer par1InventoryPlayer, TileEntityAutoCrafter tileEntity) - { - this.tileEntity = tileEntity; - for (int r = 0; r < 3; r++) - { - for (int i = 0; i < 3; i++) - { - // this.addSlotToContainer(new - // Slot(tileEntity, i + r * 3, 33 - // + i * 18, 34 + r * 18)); - } - } - int var3; - - for (var3 = 0; var3 < 3; ++var3) - { - for (int var4 = 0; var4 < 9; ++var4) - { - this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18)); - } - } - - for (var3 = 0; var3 < 9; ++var3) - { - this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142)); - } - } - - @Override - public boolean canInteractWith(EntityPlayer par1EntityPlayer) - { - return true; - } - - /** - * Called to transfer a stack from one inventory to the other eg. when shift clicking. - */ - @Override - public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par1) - { - ItemStack itemStack3 = null; - Slot itemStack = (Slot) this.inventorySlots.get(par1); - - if (itemStack != null && itemStack.getHasStack()) - { - ItemStack itemStack2 = itemStack.getStack(); - itemStack3 = itemStack2.copy(); - - if (par1 != 0) - { - if (itemStack2.itemID == Item.coal.shiftedIndex) - { - if (!this.mergeItemStack(itemStack2, 0, 1, false)) { return null; } - } - else if (par1 >= 30 && par1 < 37 && !this.mergeItemStack(itemStack2, 3, 30, false)) { return null; } - } - else if (!this.mergeItemStack(itemStack2, 3, 37, false)) { return null; } - - if (itemStack2.stackSize == 0) - { - itemStack.putStack((ItemStack) null); - } - else - { - itemStack.onSlotChanged(); - } - - if (itemStack2.stackSize == itemStack3.stackSize) { return null; } - - itemStack.onPickupFromSlot(par1EntityPlayer, itemStack2); - } - - return itemStack3; - } -} diff --git a/src/common/assemblyline/machines/crafter/EntityCraftingArm.java b/src/common/assemblyline/machines/crafter/EntityCraftingArm.java deleted file mode 100644 index 3205cd182..000000000 --- a/src/common/assemblyline/machines/crafter/EntityCraftingArm.java +++ /dev/null @@ -1,72 +0,0 @@ -package assemblyline.machines.crafter; - -import net.minecraft.src.Entity; -import net.minecraft.src.EntityItem; -import net.minecraft.src.ItemStack; -import net.minecraft.src.NBTTagCompound; -import net.minecraft.src.World; -import universalelectricity.core.vector.Vector3; - -public class EntityCraftingArm extends Entity -{ - /** - * Used to ID the type of arm - */ - static enum armType - { - ARM, SOLDER, DRILL, BREAKER - } - - /** - * type of arm this robotic arm currently is - */ - public armType arm = armType.ARM; - /** - * stack this arm is holding if any - */ - public ItemStack stack = null; - /** - * TileEntity this arm is working with - */ - public TileEntityCraftingArm blockArm = null; - /** - * position that the arms claw should be at - */ - public Vector3 clawPos = new Vector3(); - - public boolean isWorking = false; - - public EntityCraftingArm(World par1World) - { - super(par1World); - } - - @Override - protected void entityInit() - { - - } - - @Override - protected void readEntityFromNBT(NBTTagCompound nbt) - { - this.arm = armType.values()[nbt.getInteger("type")]; - - } - - @Override - protected void writeEntityToNBT(NBTTagCompound nbt) - { - nbt.setInteger("type", arm.ordinal()); - } - - public boolean grabItem(EntityItem item) - { - if (this.stack == null) - { - // TODO set current stack to item as - // soon as it reaches coords - } - return false; - } -} diff --git a/src/common/assemblyline/machines/crafter/ItemCrafterArm.java b/src/common/assemblyline/machines/crafter/ItemCrafterArm.java deleted file mode 100644 index bd2ce3f52..000000000 --- a/src/common/assemblyline/machines/crafter/ItemCrafterArm.java +++ /dev/null @@ -1,14 +0,0 @@ -package assemblyline.machines.crafter; - -import net.minecraft.src.Item; - -public class ItemCrafterArm extends Item -{ - - protected ItemCrafterArm(int par1) - { - super(par1); - this.setHasSubtypes(true); - } - -} diff --git a/src/common/assemblyline/machines/crafter/TaskArmCollect.java b/src/common/assemblyline/machines/crafter/TaskArmCollect.java deleted file mode 100644 index 83fdd22f2..000000000 --- a/src/common/assemblyline/machines/crafter/TaskArmCollect.java +++ /dev/null @@ -1,38 +0,0 @@ -package assemblyline.machines.crafter; - -import net.minecraft.src.EntityItem; -import assemblyline.ai.Task; - -/** - * Used by arms to collect items in a specific region. - * - * @author Calclavia - */ -public class TaskArmCollect extends Task -{ - - /** - * The item to be collected. - */ - private EntityItem entityItem; - - public TaskArmCollect(TileEntityCraftingArm arm, EntityItem entityItem) - { - super(arm); - this.entityItem = entityItem; - } - - @Override - protected boolean doTask() - { - super.doTask(); - - if (entityItem == null) { return false; } - - /** - * Slowly stretch down the arm's model and grab the item - */ - - return true; - } -} diff --git a/src/common/assemblyline/machines/crafter/TaskArmSearch.java b/src/common/assemblyline/machines/crafter/TaskArmSearch.java deleted file mode 100644 index 11c303eb0..000000000 --- a/src/common/assemblyline/machines/crafter/TaskArmSearch.java +++ /dev/null @@ -1,53 +0,0 @@ -package assemblyline.machines.crafter; - -import net.minecraft.src.AxisAlignedBB; -import net.minecraft.src.Entity; -import assemblyline.ai.Task; - -/** - * Used by arms to search for entities in a region - * - * @author Calclavia - */ -public class TaskArmSearch extends Task -{ - - /** - * The item to be collected. - */ - private Class entityToInclude; - - private float searchSpeed; - - private double radius; - - private Entity foundEntity; - - public TaskArmSearch(TileEntityCraftingArm arm, Class entityToInclude, double radius, float searchSpeed) - { - super(arm); - this.entityToInclude = entityToInclude; - this.radius = radius; - this.searchSpeed = searchSpeed; - } - - @Override - public void onTaskStart() - { - this.foundEntity = (Entity) this.tileEntity.worldObj.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox(this.tileEntity.xCoord - this.radius, this.tileEntity.yCoord - this.radius, this.tileEntity.zCoord - this.radius, this.tileEntity.xCoord + this.radius, this.tileEntity.yCoord + this.radius, this.tileEntity.zCoord + this.radius)).get(0); - } - - @Override - protected boolean doTask() - { - super.doTask(); - - if (this.entityToInclude == null || this.foundEntity == null) { return false; } - - /** - * Move the robotic arm around and emulate an item search. Then initiate a collect task. - */ - - return true; - } -} diff --git a/src/common/assemblyline/machines/crafter/TileEntityAutoCrafter.java b/src/common/assemblyline/machines/crafter/TileEntityAutoCrafter.java deleted file mode 100644 index fcdd2c8ca..000000000 --- a/src/common/assemblyline/machines/crafter/TileEntityAutoCrafter.java +++ /dev/null @@ -1,27 +0,0 @@ -package assemblyline.machines.crafter; - -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.INetworkManager; -import net.minecraft.src.Packet250CustomPayload; -import universalelectricity.prefab.tile.TileEntityAdvanced; - -import com.google.common.io.ByteArrayDataInput; - -public class TileEntityAutoCrafter extends TileEntityAdvanced -{ - public String getInvName() - { - return "Auto Crafter"; - } - - public int getSizeInventory() - { - return 10; - } - - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - - } - -} diff --git a/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java b/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java deleted file mode 100644 index 46a7ad266..000000000 --- a/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java +++ /dev/null @@ -1,282 +0,0 @@ -package assemblyline.machines.crafter; - -import java.util.EnumSet; - -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.IInventory; -import net.minecraft.src.INetworkManager; -import net.minecraft.src.ItemStack; -import net.minecraft.src.NBTTagCompound; -import net.minecraft.src.NBTTagList; -import net.minecraft.src.Packet250CustomPayload; -import net.minecraft.src.TileEntity; -import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.electricity.ElectricityConnections; -import universalelectricity.core.implement.IConductor; -import universalelectricity.core.implement.IJouleStorage; -import universalelectricity.core.vector.Vector3; -import universalelectricity.prefab.network.IPacketReceiver; -import universalelectricity.prefab.tile.TileEntityElectricityReceiver; -import assemblyline.ai.TaskManager; - -import com.google.common.io.ByteArrayDataInput; - -public class TileEntityCraftingArm extends TileEntityElectricityReceiver implements IInventory, IPacketReceiver, IJouleStorage -{ - /** - * The items this container contains. - */ - protected ItemStack[] containingItems = new ItemStack[this.getSizeInventory()]; - - private TaskManager taskManager = new TaskManager(); - - /** - * Entity robotic arm to be used with this tileEntity - */ - public EntityCraftingArm EntityArm = null; - - public final double WATT_REQUEST = 20; - - public double wattsReceived = 0; - - private int playerUsing = 0; - - @Override - public void initiate() - { - ElectricityConnections.registerConnector(this, EnumSet.of(ForgeDirection.DOWN, ForgeDirection.SOUTH, ForgeDirection.NORTH, ForgeDirection.EAST, ForgeDirection.WEST)); - } - - public void updateEntity() - { - super.updateEntity(); - - if (!this.worldObj.isRemote) - { - for (int i = 0; i < 6; i++) - { - ForgeDirection inputDirection = ForgeDirection.getOrientation(i); - - if (inputDirection != ForgeDirection.UP) - { - TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, Vector3.get(this), inputDirection); - - if (inputTile != null) - { - if (inputTile instanceof IConductor) - { - if (this.getJoules() >= this.getMaxJoules()) - { - ((IConductor) inputTile).getNetwork().stopRequesting(this); - } - else - { - ((IConductor) inputTile).getNetwork().startRequesting(this, this.WATT_REQUEST / this.getVoltage(), this.getVoltage()); - this.setJoules(this.getJoules() + ((IConductor) inputTile).getNetwork().consumeElectricity(this).getWatts()); - } - } - } - } - } - } - - taskManager.onUpdate(); - - if (this.ticks % 5 == 0 && !this.isDisabled() && this.taskManager.hasTask() && EntityArm != null) - { - this.wattsReceived -= this.WATT_REQUEST; - this.doWork(); - } - } - - /** - * controls the robotic arm into doing a set task - */ - public void doWork() - { - - } - - @Override - public double getVoltage() - { - return 120; - } - - /** - * Data - */ - @Override - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - - } - - /** - * inventory - */ - @Override - public int getSizeInventory() - { - return 1; - } - - @Override - public String getInvName() - { - return "RoboticArm"; - } - - /** - * 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 int getInventoryStackLimit() - { - return 64; - } - - @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); - - 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); - } - } - } - - /** - * Writes a tile entity to NBT. - */ - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - 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 double getJoules(Object... data) - { - return this.wattsReceived; - } - - @Override - public void setJoules(double joules, Object... data) - { - this.wattsReceived = joules; - } - - @Override - public double getMaxJoules(Object... data) - { - return 1000; - } - -}