From 6ff25b24e43f4d3bc04fadd8a288f742ccfebb31 Mon Sep 17 00:00:00 2001 From: pahimar Date: Tue, 11 Dec 2012 13:06:51 -0500 Subject: [PATCH] Missed the case where an item could be used up when it reaches its max durability. Also made it throw a PlayerDestroyItemEvent with the Buildcraft user when a damageable item is used up in autocrafting. --- common/buildcraft/core/proxy/CoreProxy.java | 42 +++++++++++++++++++ .../buildcraft/factory/TileAutoWorkbench.java | 14 ++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/common/buildcraft/core/proxy/CoreProxy.java b/common/buildcraft/core/proxy/CoreProxy.java index a85cf663..26fbe456 100644 --- a/common/buildcraft/core/proxy/CoreProxy.java +++ b/common/buildcraft/core/proxy/CoreProxy.java @@ -159,13 +159,55 @@ public class CoreProxy { player.username = "[BuildCraft]"; return player; } + + private EntityPlayer createNewPlayer(World world, int x, int y, int z) { + EntityPlayer player = new EntityPlayer(world) { + + @Override + public void sendChatToPlayer(String var1) { + } + + @Override + public boolean canCommandSenderUseCommand(int var1, String var2) { + return false; + } + + @Override + public ChunkCoordinates getPlayerCoordinates() { + return null; + } + + }; + player.username = "[BuildCraft]"; + player.posX = (int) x; + player.posY = (int) y; + player.posZ = (int) z; + return player; + } public EntityPlayer getBuildCraftPlayer(World world) { if (CoreProxy.buildCraftPlayer == null) { CoreProxy.buildCraftPlayer = createNewPlayer(world); } + else { + CoreProxy.buildCraftPlayer.worldObj = world; + } return CoreProxy.buildCraftPlayer; } + + public EntityPlayer getBuildCraftPlayer(World world, int x, int y, int z) { + if (CoreProxy.buildCraftPlayer == null) { + CoreProxy.buildCraftPlayer = createNewPlayer(world, x, y, z); + } + else { + CoreProxy.buildCraftPlayer.worldObj = world; + CoreProxy.buildCraftPlayer.posX = (int) x; + CoreProxy.buildCraftPlayer.posY = (int) y; + CoreProxy.buildCraftPlayer.posZ = (int) z; + } + + return CoreProxy.buildCraftPlayer; + } } diff --git a/common/buildcraft/factory/TileAutoWorkbench.java b/common/buildcraft/factory/TileAutoWorkbench.java index 83d36528..9b261e5a 100644 --- a/common/buildcraft/factory/TileAutoWorkbench.java +++ b/common/buildcraft/factory/TileAutoWorkbench.java @@ -12,9 +12,12 @@ package buildcraft.factory; import java.util.LinkedList; 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.TransactorRoundRobin; +import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; import net.minecraft.src.Container; @@ -185,8 +188,15 @@ public class TileAutoWorkbench extends TileEntity implements ISpecialInventory { if (p.item.getItem().getContainerItem() != null) { ItemStack newStack = p.item.getItem().getContainerItemStack(p.item); - - p.inventory.setInventorySlotContents(p.index, newStack); + + if (p.item.isItemStackDamageable()) { + if (newStack.getItemDamage() >= p.item.getMaxDamage()) { + MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(CoreProxy.proxy.getBuildCraftPlayer(worldObj, xCoord, yCoord, zCoord), newStack)); + newStack = null; + } + } + + p.inventory.setInventorySlotContents(p.index, newStack); } } }