diff --git a/buildcraft_resources/gfx/buildcraft/gui/autobench.png b/buildcraft_resources/gfx/buildcraft/gui/autobench.png new file mode 100644 index 00000000..fef821de Binary files /dev/null and b/buildcraft_resources/gfx/buildcraft/gui/autobench.png differ diff --git a/buildcraft_resources/lang/buildcraft/en_US.properties b/buildcraft_resources/lang/buildcraft/en_US.properties index 63fe6fc7..4eab9980 100644 --- a/buildcraft_resources/lang/buildcraft/en_US.properties +++ b/buildcraft_resources/lang/buildcraft/en_US.properties @@ -13,6 +13,7 @@ gui.stored=Stored gui.heat=Heat gui.assemblyRate=Energy Rate gui.assemblyCurrentRequired=Energy Required +gui.clickcraft=-Click to Craft- item.bucketFuel=Fuel Bucket item.bucketOil=Oil Bucket item.woodenGearItem=Wood Gear @@ -75,7 +76,7 @@ item.Facade=Facade item.PipePlug=Pipe Plug tile.miningWellBlock=Mining Well tile.plainPipeBlock=Mining Pipe -tile.autoWorkbenchBlock=Autocrafting Table +tile.autoWorkbenchBlock=Auto Workbench tile.machineBlock=Quarry tile.markerBlock=Land Mark tile.fillerBlock=Filler diff --git a/common/buildcraft/core/gui/slots/SlotOutput.java b/common/buildcraft/core/gui/slots/SlotOutput.java new file mode 100644 index 00000000..590c82b7 --- /dev/null +++ b/common/buildcraft/core/gui/slots/SlotOutput.java @@ -0,0 +1,16 @@ +package buildcraft.core.gui.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public class SlotOutput extends SlotBase { + + public SlotOutput(IInventory iinventory, int slotIndex, int posX, int posY) { + super(iinventory, slotIndex, posX, posY); + } + + @Override + public boolean isItemValid(ItemStack itemstack) { + return false; + } +} diff --git a/common/buildcraft/core/gui/slots/SlotWorkbench.java b/common/buildcraft/core/gui/slots/SlotWorkbench.java new file mode 100644 index 00000000..23f93422 --- /dev/null +++ b/common/buildcraft/core/gui/slots/SlotWorkbench.java @@ -0,0 +1,16 @@ +package buildcraft.core.gui.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public class SlotWorkbench extends SlotBase { + + public SlotWorkbench(IInventory iinventory, int slotIndex, int posX, int posY) { + super(iinventory, slotIndex, posX, posY); + } + + @Override + public boolean isItemValid(ItemStack stack) { + return stack != null && stack.isStackable() && !stack.getItem().hasContainerItem(); + } +} diff --git a/common/buildcraft/core/inventory/InventoryIterator.java b/common/buildcraft/core/inventory/InventoryIterator.java index 1475da4e..d0ff6935 100644 --- a/common/buildcraft/core/inventory/InventoryIterator.java +++ b/common/buildcraft/core/inventory/InventoryIterator.java @@ -29,6 +29,8 @@ public class InventoryIterator { } public interface IInvSlot { + + int getIndex(); boolean canPutStackInSlot(ItemStack stack); diff --git a/common/buildcraft/core/inventory/InventoryIteratorSided.java b/common/buildcraft/core/inventory/InventoryIteratorSided.java index c62ab21e..02db8127 100644 --- a/common/buildcraft/core/inventory/InventoryIteratorSided.java +++ b/common/buildcraft/core/inventory/InventoryIteratorSided.java @@ -76,5 +76,10 @@ class InventoryIteratorSided implements Iterable { return inv.decrStackSize(slot, 1); } + @Override + public int getIndex() { + return slot; + } + } } diff --git a/common/buildcraft/core/inventory/InventoryIteratorSimple.java b/common/buildcraft/core/inventory/InventoryIteratorSimple.java index f8ba1eb3..96e0f940 100644 --- a/common/buildcraft/core/inventory/InventoryIteratorSimple.java +++ b/common/buildcraft/core/inventory/InventoryIteratorSimple.java @@ -70,5 +70,10 @@ class InventoryIteratorSimple implements Iterable { public ItemStack decreaseStackInSlot() { return inv.decrStackSize(slot, 1); } + + @Override + public int getIndex() { + return slot; + } } } diff --git a/common/buildcraft/core/inventory/InventoryMapper.java b/common/buildcraft/core/inventory/InventoryMapper.java new file mode 100644 index 00000000..eaf2f9ee --- /dev/null +++ b/common/buildcraft/core/inventory/InventoryMapper.java @@ -0,0 +1,116 @@ +package buildcraft.core.inventory; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +/** + * Wrapper class used to specify part of an existing inventory to be treated as + * a complete inventory. Used primarily to map a side of an ISidedInventory, but + * it is also helpful for complex inventories such as the Tunnel Bore. + * + * @author CovertJaguar + */ +public class InventoryMapper implements IInventory { + + private final IInventory inv; + private final int start; + private final int size; + private int stackSizeLimit = -1; + private boolean checkItems = true; + + /** + * Creates a new InventoryMapper + * + * @param inv The backing inventory + * @param start The starting index + * @param size The size of the new inventory, take care not to exceed the + * end of the backing inventory + */ + public InventoryMapper(IInventory inv, int start, int size) { + this(inv, start, size, true); + } + + public InventoryMapper(IInventory inv, int start, int size, boolean checkItems) { + this.inv = inv; + this.start = start; + this.size = size; + this.checkItems = checkItems; + } + + public IInventory getBaseInventory() { + return inv; + } + + @Override + public int getSizeInventory() { + return size; + } + + @Override + public ItemStack getStackInSlot(int slot) { + return inv.getStackInSlot(start + slot); + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + return inv.decrStackSize(start + slot, amount); + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemstack) { + inv.setInventorySlotContents(start + slot, itemstack); + } + + @Override + public String getInvName() { + return inv.getInvName(); + } + + public void setStackSizeLimit(int limit) { + stackSizeLimit = limit; + } + + @Override + public int getInventoryStackLimit() { + return stackSizeLimit > 0 ? stackSizeLimit : inv.getInventoryStackLimit(); + } + + @Override + public void onInventoryChanged() { + inv.onInventoryChanged(); + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) { + return inv.isUseableByPlayer(entityplayer); + } + + @Override + public void openChest() { + inv.openChest(); + } + + @Override + public void closeChest() { + inv.closeChest(); + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return inv.getStackInSlotOnClosing(start + slot); + } + + @Override + public boolean isInvNameLocalized() { + return inv.isInvNameLocalized(); + } + + @Override + public boolean isStackValidForSlot(int slot, ItemStack stack) { + if (checkItems) { + return inv.isStackValidForSlot(start + slot, stack); + } + return true; + } +} diff --git a/common/buildcraft/core/utils/SimpleInventory.java b/common/buildcraft/core/inventory/SimpleInventory.java similarity index 76% rename from common/buildcraft/core/utils/SimpleInventory.java rename to common/buildcraft/core/inventory/SimpleInventory.java index c154ac24..9482e0bf 100644 --- a/common/buildcraft/core/utils/SimpleInventory.java +++ b/common/buildcraft/core/inventory/SimpleInventory.java @@ -5,23 +5,23 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.core.inventory; -package buildcraft.core.utils; - +import buildcraft.core.utils.INBTTagable; +import java.util.LinkedList; 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.tileentity.TileEntity; public class SimpleInventory implements IInventory, INBTTagable { private final ItemStack[] _contents; private final String _name; private final int _stackLimit; - - // private final LinkedList _listener = new - // LinkedList(); + private final LinkedList _listener = new LinkedList(); public SimpleInventory(int size, String name, int stackLimit) { _contents = new ItemStack[size]; @@ -41,19 +41,24 @@ public class SimpleInventory implements IInventory, INBTTagable { @Override public ItemStack decrStackSize(int slotId, int count) { - if (_contents[slotId] == null) + if (_contents[slotId] == null) { return null; - if (_contents[slotId].stackSize > count) - return _contents[slotId].splitStack(count); + } + if (_contents[slotId].stackSize > count) { + ItemStack result = _contents[slotId].splitStack(count); + onInventoryChanged(); + return result; + } ItemStack stack = _contents[slotId]; _contents[slotId] = null; + onInventoryChanged(); return stack; } @Override public void setInventorySlotContents(int slotId, ItemStack itemstack) { _contents[slotId] = itemstack; - + onInventoryChanged(); } @Override @@ -68,9 +73,9 @@ public class SimpleInventory implements IInventory, INBTTagable { @Override public void onInventoryChanged() { - // for (ISimpleInventoryEventHandler handler : _listener){ - // handler.InventoryChanged(this); - // } + for (TileEntity handler : _listener) { + handler.onInventoryChanged(); + } } @Override @@ -111,42 +116,32 @@ public class SimpleInventory implements IInventory, INBTTagable { nbttagcompound.setTag("items", nbttaglist); } - // public void addListener(ISimpleInventoryEventHandler listner){ - // if (!_listener.contains(listner)){ - // _listener.add(listner); - // } - // } - // - // public void removeListener(ISimpleInventoryEventHandler listner){ - // if (_listener.contains(listner)){ - // _listener.remove(listner); - // } - // } + public void addListener(TileEntity listner) { + _listener.add(listner); + } @Override public ItemStack getStackInSlotOnClosing(int i) { - if (this._contents[i] == null) + if (this._contents[i] == null) { return null; + } ItemStack stackToTake = this._contents[i]; this._contents[i] = null; return stackToTake; } - public ItemStack[] getItemStacks() - { - return _contents; + public ItemStack[] getItemStacks() { + return _contents; } @Override public boolean isInvNameLocalized() { - // TODO Auto-generated method stub return false; } @Override public boolean isStackValidForSlot(int i, ItemStack itemstack) { - // TODO Auto-generated method stub - return false; + return true; } } diff --git a/common/buildcraft/core/utils/Utils.java b/common/buildcraft/core/utils/Utils.java index 791575cb..8acb9ccf 100644 --- a/common/buildcraft/core/utils/Utils.java +++ b/common/buildcraft/core/utils/Utils.java @@ -1,12 +1,10 @@ /** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package buildcraft.core.utils; import java.util.Arrays; @@ -49,9 +47,12 @@ import buildcraft.energy.TileEngine; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Random; +import net.minecraft.nbt.NBTTagString; public class Utils { + public static final Random RANDOM = new Random(); public static final float pipeMinPos = 0.25F; public static final float pipeMaxPos = 0.75F; public static float pipeNormalSpeed = 0.01F; @@ -88,7 +89,8 @@ public class Utils { } /** - * Depending on the kind of item in the pipe, set the floor at a different level to optimize graphical aspect. + * Depending on the kind of item in the pipe, set the floor at a different + * level to optimize graphical aspect. */ public static float getPipeFloorOf(ItemStack item) { return pipeMinPos; @@ -99,14 +101,15 @@ public class Utils { double Dz = pos1.z - pos2.z; double angle = Math.atan2(Dz, Dx) / Math.PI * 180 + 180; - if (angle < 45 || angle > 315) + if (angle < 45 || angle > 315) { return ForgeDirection.EAST; - else if (angle < 135) + } else if (angle < 135) { return ForgeDirection.SOUTH; - else if (angle < 225) + } else if (angle < 225) { return ForgeDirection.WEST; - else + } else { return ForgeDirection.NORTH; + } } public static ForgeDirection get3dOrientation(Position pos1, Position pos2) { @@ -114,18 +117,21 @@ public class Utils { double Dy = pos1.y - pos2.y; double angle = Math.atan2(Dy, Dx) / Math.PI * 180 + 180; - if (angle > 45 && angle < 135) + if (angle > 45 && angle < 135) { return ForgeDirection.UP; - else if (angle > 225 && angle < 315) + } else if (angle > 225 && angle < 315) { return ForgeDirection.DOWN; - else + } else { return get2dOrientation(pos1, pos2); + } } /** - * Look around the tile given in parameter in all 6 position, tries to add the items to a random pipe entry around. Will make sure that the location from - * which the items are coming from (identified by the from parameter) isn't used again so that entities doesn't go backwards. Returns true if successful, - * false otherwise. + * Look around the tile given in parameter in all 6 position, tries to add + * the items to a random pipe entry around. Will make sure that the location + * from which the items are coming from (identified by the from parameter) + * isn't used again so that entities doesn't go backwards. Returns true if + * successful, false otherwise. */ public static boolean addToRandomPipeEntry(TileEntity tile, ForgeDirection from, ItemStack items) { World w = tile.worldObj; @@ -145,10 +151,11 @@ public class Utils { TileEntity pipeEntry = w.getBlockTileEntity((int) pos.x, (int) pos.y, (int) pos.z); if (pipeEntry instanceof IPipeEntry && ((IPipeEntry) pipeEntry).acceptItems()) { - if (pipeEntry instanceof IPipeConnection) + if (pipeEntry instanceof IPipeConnection) { if (!((IPipeConnection) pipeEntry).isPipeConnected(o.getOpposite())) { continue; } + } possiblePipes.add(o); } } @@ -174,13 +181,15 @@ public class Utils { pipeEntry.entityEntering(entity, entityPos.orientation); items.stackSize = 0; return true; - } else + } else { return false; + } } public static void dropItems(World world, ItemStack stack, int i, int j, int k) { - if (stack.stackSize <= 0) + if (stack.stackSize <= 0) { return; + } float f1 = 0.7F; double d = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D; @@ -211,8 +220,9 @@ public class Utils { } /** - * Ensures that the given inventory is the full inventory, i.e. takes double chests into account. - * + * Ensures that the given inventory is the full inventory, i.e. takes double + * chests into account. + * * @param inv * @return Modified inventory if double chest, unmodified otherwise. */ @@ -238,8 +248,9 @@ public class Utils { if (tile instanceof TileEntityChest) { chest2 = (IInventory) tile; } - if (chest2 != null) + if (chest2 != null) { return new InventoryLargeChest("", inv, chest2); + } } return inv; } @@ -252,30 +263,37 @@ public class Utils { TileEntity a5 = world.getBlockTileEntity(i, j + 1, k); TileEntity a6 = world.getBlockTileEntity(i, j - 1, k); - if (a1 instanceof IAreaProvider) + if (a1 instanceof IAreaProvider) { return (IAreaProvider) a1; + } - if (a2 instanceof IAreaProvider) + if (a2 instanceof IAreaProvider) { return (IAreaProvider) a2; + } - if (a3 instanceof IAreaProvider) + if (a3 instanceof IAreaProvider) { return (IAreaProvider) a3; + } - if (a4 instanceof IAreaProvider) + if (a4 instanceof IAreaProvider) { return (IAreaProvider) a4; + } - if (a5 instanceof IAreaProvider) + if (a5 instanceof IAreaProvider) { return (IAreaProvider) a5; + } - if (a6 instanceof IAreaProvider) + if (a6 instanceof IAreaProvider) { return (IAreaProvider) a6; + } return null; } public static EntityBlock createLaser(World world, Position p1, Position p2, LaserKind kind) { - if (p1.equals(p2)) + if (p1.equals(p2)) { return null; + } double iSize = p2.x - p1.x; double jSize = p2.y - p1.y; @@ -359,38 +377,42 @@ public class Utils { } public static int liquidId(int blockId) { - if (blockId == Block.waterStill.blockID || blockId == Block.waterMoving.blockID) + if (blockId == Block.waterStill.blockID || blockId == Block.waterMoving.blockID) { return Block.waterStill.blockID; - else if (blockId == Block.lavaStill.blockID || blockId == Block.lavaMoving.blockID) + } else if (blockId == Block.lavaStill.blockID || blockId == Block.lavaMoving.blockID) { return Block.lavaStill.blockID; - else if (Block.blocksList[blockId] instanceof ILiquid) + } else if (Block.blocksList[blockId] instanceof ILiquid) { return ((ILiquid) Block.blocksList[blockId]).stillLiquidId(); - else + } else { return 0; + } } public static LiquidStack liquidFromBlockId(int blockId) { - if (blockId == Block.waterStill.blockID || blockId == Block.waterMoving.blockID) + if (blockId == Block.waterStill.blockID || blockId == Block.waterMoving.blockID) { return new LiquidStack(Block.waterStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME, 0); - else if (blockId == Block.lavaStill.blockID || blockId == Block.lavaMoving.blockID) + } else if (blockId == Block.lavaStill.blockID || blockId == Block.lavaMoving.blockID) { return new LiquidStack(Block.lavaStill.blockID, LiquidContainerRegistry.BUCKET_VOLUME, 0); - else if (Block.blocksList[blockId] instanceof ILiquid) { + } else if (Block.blocksList[blockId] instanceof ILiquid) { ILiquid liquid = (ILiquid) Block.blocksList[blockId]; - if (liquid.isMetaSensitive()) + if (liquid.isMetaSensitive()) { return new LiquidStack(liquid.stillLiquidId(), LiquidContainerRegistry.BUCKET_VOLUME, liquid.stillLiquidMeta()); - else + } else { return new LiquidStack(liquid.stillLiquidId(), LiquidContainerRegistry.BUCKET_VOLUME, 0); - } else + } + } else { return null; + } } public static void preDestroyBlock(World world, int i, int j, int k) { TileEntity tile = world.getBlockTileEntity(i, j, k); - if (tile instanceof IInventory && !CoreProxy.proxy.isRenderWorld(world)) + if (tile instanceof IInventory && !CoreProxy.proxy.isRenderWorld(world)) { if (!(tile instanceof IDropControlInventory) || ((IDropControlInventory) tile).doDrop()) { dropItems(world, (IInventory) tile, i, j, k); } + } if (tile instanceof TileBuildCraft) { ((TileBuildCraft) tile).destroy(); @@ -398,11 +420,13 @@ public class Utils { } public static boolean checkPipesConnections(TileEntity tile1, TileEntity tile2) { - if (tile1 == null || tile2 == null) + if (tile1 == null || tile2 == null) { return false; + } - if (!(tile1 instanceof IPipeConnection) && !(tile2 instanceof IPipeConnection)) + if (!(tile1 instanceof IPipeConnection) && !(tile2 instanceof IPipeConnection)) { return false; + } ForgeDirection o = ForgeDirection.UNKNOWN; @@ -420,11 +444,13 @@ public class Utils { o = ForgeDirection.SOUTH; } - if (tile1 instanceof IPipeConnection && !((IPipeConnection) tile1).isPipeConnected(o)) + if (tile1 instanceof IPipeConnection && !((IPipeConnection) tile1).isPipeConnected(o)) { return false; + } - if (tile2 instanceof IPipeConnection && !((IPipeConnection) tile2).isPipeConnected(o.getOpposite())) + if (tile2 instanceof IPipeConnection && !((IPipeConnection) tile2).isPipeConnected(o.getOpposite())) { return false; + } return true; } @@ -440,23 +466,70 @@ public class Utils { Block b1 = Block.blocksList[blockAccess.getBlockId(x1, y1, z1)]; Block b2 = Block.blocksList[blockAccess.getBlockId(x2, y2, z2)]; - if (!(b1 instanceof IFramePipeConnection) && !(b2 instanceof IFramePipeConnection)) + if (!(b1 instanceof IFramePipeConnection) && !(b2 instanceof IFramePipeConnection)) { return false; + } - if (b1 instanceof IFramePipeConnection && !((IFramePipeConnection) b1).isPipeConnected(blockAccess, x1, y1, z1, x2, y2, z2)) + if (b1 instanceof IFramePipeConnection && !((IFramePipeConnection) b1).isPipeConnected(blockAccess, x1, y1, z1, x2, y2, z2)) { return false; + } - if (b2 instanceof IFramePipeConnection && !((IFramePipeConnection) b2).isPipeConnected(blockAccess, x2, y2, z2, x1, y1, z1)) + if (b2 instanceof IFramePipeConnection && !((IFramePipeConnection) b2).isPipeConnected(blockAccess, x2, y2, z2, x1, y1, z1)) { return false; + } return true; } + public static NBTTagCompound getItemData(ItemStack stack) { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + nbt = new NBTTagCompound("tag"); + stack.setTagCompound(nbt); + } + return nbt; + } + + public static void addItemToolTip(ItemStack stack, String tag, String msg) { + NBTTagCompound nbt = getItemData(stack); + NBTTagCompound display = nbt.getCompoundTag("display"); + nbt.setCompoundTag("display", display); + NBTTagList lore = display.getTagList("Lore"); + display.setTag("Lore", lore); + lore.appendTag(new NBTTagString(tag, msg)); + } + + public static void writeInvToNBT(IInventory inv, String tag, NBTTagCompound data) { + NBTTagList list = new NBTTagList(); + for (byte slot = 0; slot < inv.getSizeInventory(); slot++) { + ItemStack stack = inv.getStackInSlot(slot); + if (stack != null) { + NBTTagCompound itemTag = new NBTTagCompound(); + itemTag.setByte("Slot", slot); + stack.writeToNBT(itemTag); + list.appendTag(itemTag); + } + } + data.setTag(tag, list); + } + + public static void readInvFromNBT(IInventory inv, String tag, NBTTagCompound data) { + NBTTagList list = data.getTagList(tag); + for (byte entry = 0; entry < list.tagCount(); entry++) { + NBTTagCompound itemTag = (NBTTagCompound) list.tagAt(entry); + int slot = itemTag.getByte("Slot"); + if (slot >= 0 && slot < inv.getSizeInventory()) { + ItemStack stack = ItemStack.loadItemStackFromNBT(itemTag); + inv.setInventorySlotContents(slot, stack); + } + } + } + public static void readStacksFromNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) { NBTTagList nbttaglist = nbt.getTagList(name); - for (int i = 0; i < stacks.length; ++i) + for (int i = 0; i < stacks.length; ++i) { if (i < nbttaglist.tagCount()) { NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist.tagAt(i); @@ -464,6 +537,7 @@ public class Utils { } else { stacks[i] = null; } + } } public static void writeStacksToNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) { @@ -483,10 +557,11 @@ public class Utils { public static ItemStack consumeItem(ItemStack stack) { if (stack.stackSize == 1) { - if (stack.getItem().hasContainerItem()) + if (stack.getItem().hasContainerItem()) { return stack.getItem().getContainerItemStack(stack); - else + } else { return null; + } } else { stack.splitStack(1); @@ -514,9 +589,9 @@ public class Utils { public static int[] createSlotArray(int first, int count) { int[] slots = new int[count]; - for (int k = first; k < first + count; k++) + for (int k = first; k < first + count; k++) { slots[k - first] = k; + } return slots; } - } diff --git a/common/buildcraft/factory/TileAutoWorkbench.java b/common/buildcraft/factory/TileAutoWorkbench.java index f35af3b8..3033147a 100644 --- a/common/buildcraft/factory/TileAutoWorkbench.java +++ b/common/buildcraft/factory/TileAutoWorkbench.java @@ -1,102 +1,117 @@ /** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package buildcraft.factory; -import java.util.LinkedList; +import buildcraft.core.inventory.InventoryIterator; +import buildcraft.core.inventory.InventoryIterator.IInvSlot; +import buildcraft.core.inventory.InventoryMapper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; -import buildcraft.api.core.Position; -import buildcraft.api.inventory.ISpecialInventory; -import buildcraft.core.inventory.InventoryWrapper; -import buildcraft.core.inventory.TransactorRoundRobin; +import buildcraft.core.inventory.StackMergeHelper; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.CraftingHelper; +import buildcraft.core.inventory.SimpleInventory; +import buildcraft.core.inventory.TransactorRoundRobin; import buildcraft.core.utils.Utils; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCraftResult; +import net.minecraft.inventory.SlotCrafting; +import net.minecraft.util.ChunkCoordinates; +import net.minecraftforge.common.ForgeDirection; -public class TileAutoWorkbench extends TileEntity implements ISpecialInventory { +public class TileAutoWorkbench extends TileEntity implements ISidedInventory { - private ItemStack stackList[] = new ItemStack[9]; - private IRecipe currentRecipe = null; + private static final StackMergeHelper MERGE_HELPER = new StackMergeHelper(); + public static final int SLOT_RESULT = 0; + public static final int CRAFT_TIME = 256; + public static final int UPDATE_TIME = 16; + private static final int[] SLOTS = Utils.createSlotArray(0, 5); + private SimpleInventory inv = new SimpleInventory(5, "Auto Workbench", 64); + private IInventory invBuffer = new InventoryMapper(inv, 1, 4); + public InventoryCrafting craftMatrix = new LocalInventoryCrafting(); + public boolean useLast; + private final TransactorRoundRobin transactor = new TransactorRoundRobin(craftMatrix); + private EntityPlayer internalPlayer; + private SlotCrafting craftSlot; + private InventoryCraftResult craftResult = new InventoryCraftResult(); + public int progress; + private int update = Utils.RANDOM.nextInt(); - class LocalInventoryCrafting extends InventoryCrafting { + private class LocalInventoryCrafting extends InventoryCrafting { public LocalInventoryCrafting() { super(new Container() { - - @SuppressWarnings("all") - public boolean isUsableByPlayer(EntityPlayer entityplayer) { - return false; - } - - @SuppressWarnings("all") + @Override public boolean canInteractWith(EntityPlayer entityplayer) { - // TODO Auto-generated method stub return false; } }, 3, 3); - // TODO Auto-generated constructor stub } - } - public IRecipe getCurrentRecipe() { + private final class InternalPlayer extends EntityPlayer { - return currentRecipe ; + public InternalPlayer() { + super(TileAutoWorkbench.this.worldObj); + posX = TileAutoWorkbench.this.xCoord; + posY = TileAutoWorkbench.this.yCoord + 1; + posZ = TileAutoWorkbench.this.zCoord; + } + + @Override + public void sendChatToPlayer(String var1) { + } + + @Override + public boolean canCommandSenderUseCommand(int var1, String var2) { + return false; + } + + @Override + public ChunkCoordinates getPlayerCoordinates() { + return null; + } + } + + public TileAutoWorkbench() { + inv.addListener(this); } @Override public int getSizeInventory() { - - return stackList.length; + return inv.getSizeInventory(); } @Override - public ItemStack getStackInSlot(int i) { - return stackList[i]; + public ItemStack getStackInSlot(int slot) { + return inv.getStackInSlot(slot); } @Override - public ItemStack decrStackSize(int slotId, int count) { - if (stackList[slotId] == null) - return null; - if (stackList[slotId].stackSize > count) - return stackList[slotId].splitStack(count); - ItemStack stack = stackList[slotId]; - stackList[slotId] = null; - return stack; + public ItemStack decrStackSize(int slot, int count) { + return inv.decrStackSize(slot, count); } @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - stackList[i] = itemstack; + public void setInventorySlotContents(int slot, ItemStack stack) { + inv.setInventorySlotContents(slot, stack); } @Override public ItemStack getStackInSlotOnClosing(int slot) { - if (this.stackList[slot] == null) - return null; - - ItemStack stackToTake = this.stackList[slot]; - this.stackList[slot] = null; - return stackToTake; + return inv.getStackInSlotOnClosing(slot); } @Override @@ -112,276 +127,122 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory { } @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this; + public boolean isUseableByPlayer(EntityPlayer player) { + return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64.0D; } @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); - - Utils.readStacksFromNBT(nbttagcompound, "stackList", stackList); + public void readFromNBT(NBTTagCompound data) { + super.readFromNBT(data); + inv.readFromNBT(data); + Utils.readInvFromNBT(craftMatrix, "matrix", data); } @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); - - Utils.writeStacksToNBT(nbttagcompound, "stackList", stackList); + public void writeToNBT(NBTTagCompound data) { + super.writeToNBT(data); + inv.writeToNBT(data); + Utils.writeInvToNBT(craftMatrix, "matrix", data); } - class StackPointer { - - IInventory inventory; - int index; - ItemStack item; - } - - public ItemStack findRecipe() { - InventoryCrafting craftMatrix = new LocalInventoryCrafting(); - - for (int i = 0; i < getSizeInventory(); ++i) { - ItemStack stack = getStackInSlot(i); - - craftMatrix.setInventorySlotContents(i, stack); + public ItemStack findRecipeOutput() { + IRecipe recipe = findRecipe(); + if (recipe != null) { + ItemStack result = recipe.getCraftingResult(craftMatrix); + if (result != null) { + result = result.copy(); + } + return result; } - - if(this.currentRecipe == null || !this.currentRecipe.matches(craftMatrix, worldObj)) - currentRecipe = CraftingHelper.findMatchingRecipe(craftMatrix, worldObj); - - if(currentRecipe!=null) - return currentRecipe.getCraftingResult(craftMatrix); return null; } - public ItemStack extractItem(boolean doRemove, boolean removeRecipe) { - InventoryCrafting craftMatrix = new LocalInventoryCrafting(); - - LinkedList pointerList = new LinkedList(); - - int itemsToLeave = (removeRecipe ? 0 : 1); - - for (int i = 0; i < getSizeInventory(); ++i) { - ItemStack stack = getStackInSlot(i); - + public IRecipe findRecipe() { + for (IInvSlot slot : InventoryIterator.getIterable(craftMatrix, ForgeDirection.UP)) { + ItemStack stack = slot.getStackInSlot(); if (stack != null) { - if (stack.stackSize <= itemsToLeave) { - StackPointer pointer = getNearbyItem(stack); + if (!stack.isStackable()) { + return null; + } + if (stack.getItem().hasContainerItem()) { + return null; + } + } + } - if (pointer == null) { - resetPointers(pointerList); + return CraftingHelper.findMatchingRecipe(craftMatrix, worldObj); + } - return null; - } else { - pointerList.add(pointer); + @Override + public boolean canUpdate() { + return true; + } + + @Override + public void updateEntity() { + super.updateEntity(); + if (CoreProxy.proxy.isRenderWorld(worldObj)) { + return; + } + for (IInvSlot slot : InventoryIterator.getIterable(invBuffer, ForgeDirection.UP)) { + ItemStack stack = slot.getStackInSlot(); + if (stack != null) { + if (gridHasItem(stack)) { + stack.stackSize -= transactor.add(stack, ForgeDirection.DOWN, true).stackSize; + if (stack.stackSize <= 0) { + slot.setStackInSlot(null); } } else { - StackPointer pointer = new StackPointer(); - pointer.inventory = this; - pointer.item = this.decrStackSize(i, 1); - pointer.index = i; - stack = pointer.item; - - pointerList.add(pointer); + Utils.dropItems(worldObj, stack, xCoord, yCoord + 1, zCoord); } } - - craftMatrix.setInventorySlotContents(i, stack); } - - if(this.currentRecipe == null || !this.currentRecipe.matches(craftMatrix, worldObj)) - currentRecipe = buildcraft.core.utils.CraftingHelper.findMatchingRecipe(craftMatrix, worldObj); - - - ItemStack resultStack = null; - if(currentRecipe != null) { - resultStack = currentRecipe.getCraftingResult(craftMatrix); + if (craftSlot == null) { + internalPlayer = new InternalPlayer(); + craftSlot = new SlotCrafting(internalPlayer, craftMatrix, craftResult, 0, 0, 0); } + if (inv.getStackInSlot(SLOT_RESULT) != null) { + return; + } + update++; + if (update % UPDATE_TIME == 0) { + updateCrafting(); + } + } - if (resultStack == null || !doRemove) { - resetPointers(pointerList); - } else { - for (StackPointer p : pointerList) { - // replace with the container where appropriate + public int getProgressScaled(int i) { + return (progress * i) / CRAFT_TIME; + } - if (p.item.getItem().getContainerItem() != null) { - ItemStack newStack = p.item.getItem().getContainerItemStack(p.item); - - if (p.item.isItemStackDamageable()) { - if (newStack.getItemDamage() >= p.item.getMaxDamage()) { - MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(CoreProxy.proxy.getBuildCraftPlayer(worldObj, xCoord, yCoord, zCoord), - newStack)); - this.worldObj.playSoundAtEntity(CoreProxy.proxy.getBuildCraftPlayer(worldObj, xCoord, yCoord, zCoord), "random.break", 0.8F, - 0.8F + this.worldObj.rand.nextFloat() * 0.4F); - newStack = null; - } + private void updateCrafting() { + IRecipe recipe = findRecipe(); + if (recipe == null) { + progress = 0; + return; + } + if (useLast || !isLast()) { + progress += UPDATE_TIME; + if (progress < CRAFT_TIME) { + return; + } + progress = 0; + useLast = false; + ItemStack result = recipe.getCraftingResult(craftMatrix); + if (result != null) { + result = result.copy(); + craftSlot.onPickupFromSlot(internalPlayer, result); + inv.setInventorySlotContents(SLOT_RESULT, result); + for (IInvSlot slot : InventoryIterator.getIterable(internalPlayer.inventory, ForgeDirection.DOWN)) { + ItemStack stack = slot.getStackInSlot(); + if (stack != null) { + slot.setStackInSlot(null); + Utils.dropItems(worldObj, stack, xCoord, yCoord + 1, zCoord); } - - p.inventory.setInventorySlotContents(p.index, newStack); } } + } else { + progress = 0; } - - return resultStack; - } - - public void resetPointers(LinkedList pointers) { - for (StackPointer p : pointers) { - ItemStack item = p.inventory.getStackInSlot(p.index); - - if (item == null) { - p.inventory.setInventorySlotContents(p.index, p.item); - } else { - p.inventory.getStackInSlot(p.index).stackSize++; - } - } - } - - public StackPointer getNearbyItem(ItemStack stack) { - StackPointer pointer = null; - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(stack, ForgeDirection.WEST); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(stack, ForgeDirection.EAST); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(stack, ForgeDirection.DOWN); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(stack, ForgeDirection.UP); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(stack, ForgeDirection.NORTH); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(stack, ForgeDirection.SOUTH); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(stack, ForgeDirection.UNKNOWN); - } - - return pointer; - } - - public StackPointer getNearbyItemFromOrientation(ItemStack itemStack, ForgeDirection direction) { - TileEntity tile = worldObj.getBlockTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ); - - if (tile instanceof ISpecialInventory) { - // Don't get stuff out of ISpecialInventory for now / we wouldn't - // know how to put it back... And it's not clear if we want to - // have workbenches automatically getting things from one another. - return null; - } - - ISidedInventory inventory = InventoryWrapper.getWrappedInventory(tile); - if (inventory == null) - return null; - - for (int j : inventory.getAccessibleSlotsFromSide(direction.ordinal())) { - ItemStack stack = inventory.getStackInSlot(j); - if(stack == null) - continue; - if(stack.stackSize <= 0) - continue; - if(!inventory.canExtractItem(j, stack, direction.ordinal())) - continue; - if(stack.itemID != itemStack.itemID) - continue; - - if (!stack.isItemStackDamageable()) { - if (stack.itemID == itemStack.itemID && stack.getItemDamage() == itemStack.getItemDamage()) { - inventory.decrStackSize(j, 1); - - StackPointer result = new StackPointer(); - result.inventory = inventory; - result.index = j; - result.item = stack; - - return result; - } - } else { - if (stack.itemID == itemStack.itemID) { - inventory.decrStackSize(j, 1); - - StackPointer result = new StackPointer(); - result.inventory = inventory; - result.index = j; - result.item = stack; - - return result; - } - } - } - - return null; - } - - public StackPointer getNearbyItem(int itemId, int damage) { - StackPointer pointer = null; - - pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.WEST); - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.EAST); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.DOWN); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.UP); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.NORTH); - } - - if (pointer == null) { - pointer = getNearbyItemFromOrientation(itemId, damage, ForgeDirection.SOUTH); - } - - return pointer; - } - - public StackPointer getNearbyItemFromOrientation(int itemId, int damage, ForgeDirection orientation) { - Position p = new Position(xCoord, yCoord, zCoord, orientation); - p.moveForwards(1.0); - - TileEntity tile = worldObj.getBlockTileEntity((int) p.x, (int) p.y, (int) p.z); - - if (tile instanceof ISpecialInventory) { - // Don't get stuff out of ISpecialInventory for now / we wouldn't - // know how to put it back... And it's not clear if we want to - // have workbenches automatically getting things from one another. - } else if (tile instanceof IInventory) { - IInventory inventory = Utils.getInventory((IInventory) tile); - - for (int j = 0; j < inventory.getSizeInventory(); ++j) { - ItemStack stack = inventory.getStackInSlot(j); - - if (stack != null && stack.stackSize > 0 && stack.itemID == itemId && stack.getItemDamage() == damage) { - inventory.decrStackSize(j, 1); - - StackPointer result = new StackPointer(); - result.inventory = inventory; - result.index = j; - result.item = stack; - - return result; - } - } - } - - return null; } @Override @@ -392,29 +253,49 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory { public void closeChest() { } - /* ISPECIALINVENTORY */ @Override - public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) { - return new TransactorRoundRobin(this).add(stack, from, doAdd).stackSize; + public boolean isInvNameLocalized() { + return false; } @Override - public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) { - return new ItemStack[] { extractItem(doRemove, false) }; + public boolean isStackValidForSlot(int slot, ItemStack stack) { + return slot != SLOT_RESULT && stack != null && stack.isStackable() && !stack.getItem().hasContainerItem() && gridHasItem(stack); } - @Override - public boolean isInvNameLocalized() - { - // TODO Auto-generated method stub - return false; - } + @Override + public int[] getAccessibleSlotsFromSide(int var1) { + return SLOTS; + } - @Override - public boolean isStackValidForSlot(int i, ItemStack itemstack) - { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean canInsertItem(int slot, ItemStack stack, int side) { + return isStackValidForSlot(slot, stack); + } + @Override + public boolean canExtractItem(int slot, ItemStack stack, int side) { + return slot == SLOT_RESULT && !isLast(); + } + + private boolean gridHasItem(ItemStack input) { + for (IInvSlot slot : InventoryIterator.getIterable(craftMatrix, ForgeDirection.UP)) { + ItemStack stack = slot.getStackInSlot(); + if (stack != null && MERGE_HELPER.canStacksMerge(stack, input)) { + return true; + } + } + return false; + } + + public boolean isLast() { + int minStackSize = 64; + for (IInvSlot slot : InventoryIterator.getIterable(craftMatrix, ForgeDirection.UP)) { + ItemStack stack = slot.getStackInSlot(); + if (stack != null && stack.stackSize < minStackSize) { + minStackSize = stack.stackSize; + } + } + return minStackSize <= 1; + } } \ No newline at end of file diff --git a/common/buildcraft/factory/TileHopper.java b/common/buildcraft/factory/TileHopper.java index 15d9ad06..74aad440 100644 --- a/common/buildcraft/factory/TileHopper.java +++ b/common/buildcraft/factory/TileHopper.java @@ -10,7 +10,7 @@ import buildcraft.core.TileBuildCraft; import buildcraft.core.inventory.ITransactor; import buildcraft.core.inventory.Transactor; import buildcraft.core.proxy.CoreProxy; -import buildcraft.core.utils.SimpleInventory; +import buildcraft.core.inventory.SimpleInventory; public class TileHopper extends TileBuildCraft implements IInventory { diff --git a/common/buildcraft/factory/gui/ContainerAutoWorkbench.java b/common/buildcraft/factory/gui/ContainerAutoWorkbench.java index 0946b844..3b7dbe6b 100644 --- a/common/buildcraft/factory/gui/ContainerAutoWorkbench.java +++ b/common/buildcraft/factory/gui/ContainerAutoWorkbench.java @@ -1,161 +1,155 @@ /** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package buildcraft.factory.gui; -import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.Slot; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.stats.AchievementList; import buildcraft.core.gui.BuildCraftContainer; -import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.gui.slots.SlotOutput; +import buildcraft.core.gui.slots.SlotUntouchable; +import buildcraft.core.gui.slots.SlotWorkbench; +import buildcraft.core.utils.StringUtils; +import buildcraft.core.utils.Utils; import buildcraft.factory.TileAutoWorkbench; +import net.minecraft.inventory.ICrafting; +import net.minecraft.util.EnumChatFormatting; public class ContainerAutoWorkbench extends BuildCraftContainer { - TileAutoWorkbench tile; - - // public InventoryCrafting craftMatrix; + private final TileAutoWorkbench tile; public IInventory craftResult; + private int lastProgress; + private ItemStack prevOutput; - public class SlotAutoCrafting extends Slot { - - private final IInventory craftMatrix; - private EntityPlayer thePlayer; - - public SlotAutoCrafting(EntityPlayer entityplayer, IInventory iinventory, IInventory iinventory1, int i, int j, int k) { - super(iinventory1, i, j, k); - thePlayer = entityplayer; - craftMatrix = iinventory; - } - - @Override - public boolean isItemValid(ItemStack itemstack) { - return false; - } - - @Override - public void onPickupFromSlot(EntityPlayer pl, ItemStack itemstack) { - CoreProxy.proxy.onCraftingPickup(thePlayer.worldObj, thePlayer, itemstack); - if (itemstack.itemID == Block.workbench.blockID) { - thePlayer.addStat(AchievementList.buildWorkBench, 1); - } else if (itemstack.itemID == Item.pickaxeWood.itemID) { - thePlayer.addStat(AchievementList.buildPickaxe, 1); - } else if (itemstack.itemID == Block.furnaceIdle.blockID) { - thePlayer.addStat(AchievementList.buildFurnace, 1); - } else if (itemstack.itemID == Item.hoeWood.itemID) { - thePlayer.addStat(AchievementList.buildHoe, 1); - } else if (itemstack.itemID == Item.bread.itemID) { - thePlayer.addStat(AchievementList.makeBread, 1); - } else if (itemstack.itemID == Item.cake.itemID) { - thePlayer.addStat(AchievementList.bakeCake, 1); - } else if (itemstack.itemID == Item.pickaxeStone.itemID) { - thePlayer.addStat(AchievementList.buildBetterPickaxe, 1); - } else if (itemstack.itemID == Item.swordWood.itemID) { - thePlayer.addStat(AchievementList.buildSword, 1); - } else if (itemstack.itemID == Block.enchantmentTable.blockID) { - thePlayer.addStat(AchievementList.enchantments, 1); - } else if (itemstack.itemID == Block.bookShelf.blockID) { - thePlayer.addStat(AchievementList.bookcase, 1); - } - CoreProxy.proxy.TakenFromCrafting(thePlayer, itemstack, craftMatrix); - // FIXME: Autocrafting table should post a forge event. - // ForgeHooks.onTakenFromCrafting(thePlayer, itemstack, craftMatrix); - - tile.extractItem(true, true); - } - - } - - public ContainerAutoWorkbench(InventoryPlayer inventoryplayer, TileAutoWorkbench tile) { - super(tile.getSizeInventory()); + public ContainerAutoWorkbench(InventoryPlayer inventoryplayer, TileAutoWorkbench t) { + super(t.getSizeInventory()); craftResult = new InventoryCraftResult(); - this.tile = tile; - addSlotToContainer(new SlotAutoCrafting(inventoryplayer.player, tile, craftResult, 0, 124, 35)); - for (int l = 0; l < 3; l++) { - for (int k1 = 0; k1 < 3; k1++) { - addSlotToContainer(new Slot(tile, k1 + l * 3, 30 + k1 * 18, 17 + l * 18)); + this.tile = t; + addSlotToContainer(new SlotUntouchable(craftResult, 0, 93, 27) { + @Override + public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) { + tile.useLast = true; + } + }); + addSlotToContainer(new SlotOutput(tile, TileAutoWorkbench.SLOT_RESULT, 124, 35)); + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 3; x++) { + addSlotToContainer(new SlotWorkbench(tile.craftMatrix, x + y * 3, 30 + x * 18, 17 + y * 18)); } - } - for (int i1 = 0; i1 < 3; i1++) { - for (int l1 = 0; l1 < 9; l1++) { - addSlotToContainer(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 84 + i1 * 18)); + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 9; x++) { + addSlotToContainer(new Slot(inventoryplayer, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } - } - for (int j1 = 0; j1 < 9; j1++) { - addSlotToContainer(new Slot(inventoryplayer, j1, 8 + j1 * 18, 142)); + for (int x = 0; x < 9; x++) { + addSlotToContainer(new Slot(inventoryplayer, x, 8 + x * 18, 142)); } onCraftMatrixChanged(tile); } + @Override + public void addCraftingToCrafters(ICrafting icrafting) { + super.addCraftingToCrafters(icrafting); + icrafting.sendProgressBarUpdate(this, 0, tile.progress); + } + @Override public void detectAndSendChanges() { super.detectAndSendChanges(); - craftResult.setInventorySlotContents(0, tile.findRecipe()); + for (int i = 0; i < crafters.size(); i++) { + ICrafting icrafting = (ICrafting) crafters.get(i); + + if (lastProgress != tile.progress) { + icrafting.sendProgressBarUpdate(this, 0, tile.progress); + } + } + + ItemStack output = craftResult.getStackInSlot(0); + if (output != prevOutput) { + prevOutput = output; + onCraftMatrixChanged(tile.craftMatrix); + } + + lastProgress = tile.progress; } @Override - public ItemStack slotClick(int i, int j, int flag, EntityPlayer entityplayer) { - // This call ensures that the ouptut is correctly computed - craftResult.setInventorySlotContents(0, tile.findRecipe()); + public void updateProgressBar(int id, int data) { + switch (id) { + case 0: + tile.progress = data; + break; + } + } - ItemStack ret = super.slotClick(i, j, flag, entityplayer); - onCraftMatrixChanged(tile); + @Override + public final void onCraftMatrixChanged(IInventory inv) { + super.onCraftMatrixChanged(inv); + ItemStack output = tile.findRecipeOutput(); + if (output != null && tile.isLast()) { + Utils.addItemToolTip(output, "tip", EnumChatFormatting.YELLOW + StringUtils.localize("gui.clickcraft")); + } + craftResult.setInventorySlotContents(0, output); + } - return ret; + @Override + public ItemStack slotClick(int i, int j, int modifier, EntityPlayer entityplayer) { + ItemStack stack = super.slotClick(i, j, modifier, entityplayer); + onCraftMatrixChanged(tile.craftMatrix); + return stack; } @Override public boolean canInteractWith(EntityPlayer entityplayer) { return tile.isUseableByPlayer(entityplayer); } - - @Override - public ItemStack transferStackInSlot(EntityPlayer pl, int i) { - ItemStack itemstack = null; - Slot slot = (Slot) inventorySlots.get(i); - if (slot != null && slot.getHasStack()) { - ItemStack itemstack1 = slot.getStack(); - itemstack = itemstack1.copy(); - if (i == 0) { - if (!mergeItemStack(itemstack1, 10, 46, true)) - return null; - } else if (i >= 10 && i < 37) { - if (!mergeItemStack(itemstack1, 37, 46, false)) - return null; - } else if (i >= 37 && i < 46) { - if (!mergeItemStack(itemstack1, 10, 37, false)) - return null; - } else if (!mergeItemStack(itemstack1, 10, 46, false)) - return null; - if (itemstack1.stackSize == 0) { - slot.putStack(null); - } else { - slot.onSlotChanged(); - } - if (itemstack1.stackSize != itemstack.stackSize) { - slot.onPickupFromSlot(pl, itemstack1); - } else - return null; - } - return itemstack; - } - +// @Override +// public ItemStack transferStackInSlot(EntityPlayer pl, int i) { +// ItemStack itemstack = null; +// Slot slot = (Slot) inventorySlots.get(i); +// if (slot != null && slot.getHasStack()) { +// ItemStack itemstack1 = slot.getStack(); +// itemstack = itemstack1.copy(); +// if (i == 0) { +// if (!mergeItemStack(itemstack1, 10, 46, true)) { +// return null; +// } +// } else if (i >= 10 && i < 37) { +// if (!mergeItemStack(itemstack1, 37, 46, false)) { +// return null; +// } +// } else if (i >= 37 && i < 46) { +// if (!mergeItemStack(itemstack1, 10, 37, false)) { +// return null; +// } +// } else if (!mergeItemStack(itemstack1, 10, 46, false)) { +// return null; +// } +// if (itemstack1.stackSize == 0) { +// slot.putStack(null); +// } else { +// slot.onSlotChanged(); +// } +// if (itemstack1.stackSize != itemstack.stackSize) { +// slot.onPickupFromSlot(pl, itemstack1); +// } else { +// return null; +// } +// } +// return itemstack; +// } } diff --git a/common/buildcraft/factory/gui/GuiAutoCrafting.java b/common/buildcraft/factory/gui/GuiAutoCrafting.java index 94f5dad3..9a33fe23 100644 --- a/common/buildcraft/factory/gui/GuiAutoCrafting.java +++ b/common/buildcraft/factory/gui/GuiAutoCrafting.java @@ -1,14 +1,13 @@ /** - * Copyright (c) SpaceToad, 2011 - * http://www.mod-buildcraft.com + * Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in + * BuildCraft is distributed under the terms of the Minecraft Mod Public License + * 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ - package buildcraft.factory.gui; +import buildcraft.core.DefaultProps; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.world.World; @@ -20,8 +19,11 @@ import buildcraft.factory.TileAutoWorkbench; public class GuiAutoCrafting extends GuiBuildCraft { + private TileAutoWorkbench bench; + public GuiAutoCrafting(InventoryPlayer inventoryplayer, World world, TileAutoWorkbench tile) { super(new ContainerAutoWorkbench(inventoryplayer, tile), tile); + this.bench = tile; } @Override @@ -40,12 +42,15 @@ public class GuiAutoCrafting extends GuiBuildCraft { } @Override - protected void drawGuiContainerBackgroundLayer(float f, int x, int y) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.renderEngine.bindTexture("/gui/crafting.png"); - int j = (width - xSize) / 2; - int k = (height - ySize) / 2; - drawTexturedModalRect(j, k, 0, 0, xSize, ySize); + protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + mc.renderEngine.bindTexture(DefaultProps.TEXTURE_PATH_GUI + "/autobench.png"); + int x = (width - xSize) / 2; + int y = (height - ySize) / 2; + drawTexturedModalRect(x, y, 0, 0, xSize, ySize); + if (bench.progress > 0) { + int progress = bench.getProgressScaled(23); + drawTexturedModalRect(x + 89, y + 45, 176, 0, progress + 1, 12); + } } - } diff --git a/common/buildcraft/silicon/TileAdvancedCraftingTable.java b/common/buildcraft/silicon/TileAdvancedCraftingTable.java index 8f998d32..39bc5d8c 100644 --- a/common/buildcraft/silicon/TileAdvancedCraftingTable.java +++ b/common/buildcraft/silicon/TileAdvancedCraftingTable.java @@ -22,8 +22,9 @@ import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketSlotChange; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.CraftingHelper; -import buildcraft.core.utils.SimpleInventory; +import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.utils.Utils; +import buildcraft.factory.TileAutoWorkbench; import com.google.common.collect.Lists; import net.minecraftforge.common.ForgeDirection; @@ -95,6 +96,9 @@ public class TileAdvancedCraftingTable extends TileEntity implements IInventory, public InternalPlayer() { super(TileAdvancedCraftingTable.this.worldObj); + posX = TileAdvancedCraftingTable.this.xCoord; + posY = TileAdvancedCraftingTable.this.yCoord + 1; + posZ = TileAdvancedCraftingTable.this.zCoord; } @Override @@ -339,7 +343,7 @@ public class TileAdvancedCraftingTable extends TileEntity implements IInventory, output.stackSize -= Utils.addToRandomInventory(output, worldObj, xCoord, yCoord, zCoord).stackSize; } if (output.stackSize > 0) { - Utils.dropItems(worldObj, output, xCoord, yCoord, zCoord); + Utils.dropItems(worldObj, output, xCoord, yCoord + 1, zCoord); } } } diff --git a/common/buildcraft/transport/pipes/PipeItemsEmerald.java b/common/buildcraft/transport/pipes/PipeItemsEmerald.java index 21d5199d..44ffb90d 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmerald.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmerald.java @@ -26,7 +26,7 @@ import buildcraft.api.inventory.ISpecialInventory; import buildcraft.core.GuiIds; import buildcraft.core.network.IClientState; import buildcraft.core.proxy.CoreProxy; -import buildcraft.core.utils.SimpleInventory; +import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.utils.Utils; import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.PipeIconProvider; diff --git a/common/buildcraft/transport/pipes/PipeLogicDiamond.java b/common/buildcraft/transport/pipes/PipeLogicDiamond.java index 765519ad..65edfe13 100644 --- a/common/buildcraft/transport/pipes/PipeLogicDiamond.java +++ b/common/buildcraft/transport/pipes/PipeLogicDiamond.java @@ -18,7 +18,7 @@ import buildcraft.BuildCraftTransport; import buildcraft.api.inventory.ISpecialInventory; import buildcraft.core.GuiIds; import buildcraft.core.proxy.CoreProxy; -import buildcraft.core.utils.SimpleInventory; +import buildcraft.core.inventory.SimpleInventory; import buildcraft.transport.BlockGenericPipe; public class PipeLogicDiamond extends PipeLogic implements ISpecialInventory {