diff --git a/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalBag.java b/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalBag.java index 0c0bca4c..fa42e9f1 100644 --- a/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalBag.java +++ b/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalBag.java @@ -2,6 +2,7 @@ package com.pahimar.ee3.inventory; import com.pahimar.ee3.item.ItemAlchemicalBag; import com.pahimar.ee3.reference.Names; +import com.pahimar.ee3.util.ItemHelper; import com.pahimar.ee3.util.NBTHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -21,7 +22,7 @@ public class ContainerAlchemicalBag extends ContainerEE public static final int LARGE_BAG_INVENTORY_ROWS = 9; public static final int LARGE_BAG_INVENTORY_COLUMNS = 13; private final EntityPlayer entityPlayer; - private final InventoryAlchemicalBag inventoryAlchemicalBag; + protected final InventoryAlchemicalBag inventoryAlchemicalBag; private int bagInventoryRows; private int bagInventoryColumns; @@ -74,15 +75,15 @@ public class ContainerAlchemicalBag extends ContainerEE { if (inventoryAlchemicalBag.parentItemStack.getItemDamage() == 0) { - this.addSlotToContainer(new Slot(entityPlayer.inventory, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 35 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18)); + this.addSlotToContainer(new SlotPlayerInventory(this, entityPlayer.inventory, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 35 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18)); } else if (inventoryAlchemicalBag.parentItemStack.getItemDamage() == 1) { - this.addSlotToContainer(new Slot(entityPlayer.inventory, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 35 + inventoryColumnIndex * 18, 158 + inventoryRowIndex * 18)); + this.addSlotToContainer(new SlotPlayerInventory(this, entityPlayer.inventory, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 35 + inventoryColumnIndex * 18, 158 + inventoryRowIndex * 18)); } else if (inventoryAlchemicalBag.parentItemStack.getItemDamage() == 2) { - this.addSlotToContainer(new Slot(entityPlayer.inventory, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 44 + inventoryColumnIndex * 18, 174 + inventoryRowIndex * 18)); + this.addSlotToContainer(new SlotPlayerInventory(this, entityPlayer.inventory, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 44 + inventoryColumnIndex * 18, 174 + inventoryRowIndex * 18)); } } } @@ -92,15 +93,15 @@ public class ContainerAlchemicalBag extends ContainerEE { if (inventoryAlchemicalBag.parentItemStack.getItemDamage() == 0) { - this.addSlotToContainer(new Slot(entityPlayer.inventory, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 162)); + this.addSlotToContainer(new SlotPlayerInventory(this, entityPlayer.inventory, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 162)); } else if (inventoryAlchemicalBag.parentItemStack.getItemDamage() == 1) { - this.addSlotToContainer(new Slot(entityPlayer.inventory, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 216)); + this.addSlotToContainer(new SlotPlayerInventory(this, entityPlayer.inventory, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 216)); } else if (inventoryAlchemicalBag.parentItemStack.getItemDamage() == 2) { - this.addSlotToContainer(new Slot(entityPlayer.inventory, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 232)); + this.addSlotToContainer(new SlotPlayerInventory(this, entityPlayer.inventory, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 232)); } } } @@ -203,9 +204,16 @@ public class ContainerAlchemicalBag extends ContainerEE } @Override - public void onSlotChange(ItemStack itemStack1, ItemStack itemStack2) + public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) { - super.onSlotChange(itemStack1, itemStack2); + super.onPickupFromSlot(entityPlayer, itemStack); + containerAlchemicalBag.saveInventory(entityPlayer); + } + + @Override + public void putStack(ItemStack itemStack) + { + super.putStack(itemStack); containerAlchemicalBag.saveInventory(entityPlayer); } @@ -218,4 +226,21 @@ public class ContainerAlchemicalBag extends ContainerEE return !(itemStack.getItem() instanceof ItemAlchemicalBag); } } + + private class SlotPlayerInventory extends Slot + { + private ContainerAlchemicalBag containerAlchemicalBag; + + public SlotPlayerInventory(ContainerAlchemicalBag containerAlchemicalBag, IInventory inventory, int slotIndex, int x, int y) + { + super(inventory, slotIndex, x, y); + this.containerAlchemicalBag = containerAlchemicalBag; + } + + @Override + public boolean canTakeStack(EntityPlayer entityPlayer) + { + return !ItemHelper.equals(this.getStack(), containerAlchemicalBag.inventoryAlchemicalBag.parentItemStack); + } + } }