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.

This commit is contained in:
pahimar 2012-12-11 13:06:51 -05:00
parent b0fc220cef
commit 6ff25b24e4
2 changed files with 54 additions and 2 deletions

View file

@ -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;
}
}

View file

@ -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);
}
}
}