From ab262c9b54a5b487db3c5adbbbabb195e7ed0e34 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Mon, 5 Aug 2013 02:45:44 -0400 Subject: [PATCH] Fixed crash when shift-clicking items --- .../battery/ContainerBattery.java | 79 ++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/src/resonantinduction/battery/ContainerBattery.java b/src/resonantinduction/battery/ContainerBattery.java index 1db9612b7..e415ae218 100644 --- a/src/resonantinduction/battery/ContainerBattery.java +++ b/src/resonantinduction/battery/ContainerBattery.java @@ -6,6 +6,7 @@ import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import resonantinduction.api.IBattery; import resonantinduction.battery.BatteryManager.SlotBattery; import resonantinduction.battery.BatteryManager.SlotOut; @@ -51,9 +52,9 @@ public class ContainerBattery extends Container ItemStack itemstack1 = itemstack == null ? null : itemstack.copy(); inventoryItemStacks.set(slotID, itemstack1); - for (int j = 0; j < this.crafters.size(); ++j) + for (int j = 0; j < crafters.size(); ++j) { - ((ICrafting)this.crafters.get(j)).sendSlotContents(this, slotID, itemstack1); + ((ICrafting)crafters.get(j)).sendSlotContents(this, slotID, itemstack1); } } @@ -73,4 +74,78 @@ public class ContainerBattery extends Container { return tileEntity.isUseableByPlayer(entityplayer); } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotID) + { + ItemStack stack = null; + Slot currentSlot = (Slot)inventorySlots.get(slotID); + + if(currentSlot != null && currentSlot.getHasStack()) + { + ItemStack slotStack = currentSlot.getStack(); + stack = slotStack.copy(); + + if(slotID == 0 || slotID == 1) + { + if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true)) + { + return null; + } + } + else if(slotID == 2 || slotID == 3) + { + if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true)) + { + return null; + } + } + else if(slotStack.getItem() instanceof IBattery) + { + if(!mergeItemStack(slotStack, 0, 1, false)) + { + return null; + } + } + else { + if(slotID >= 4 && slotID <= 30) + { + if(!mergeItemStack(slotStack, 31, inventorySlots.size(), false)) + { + return null; + } + } + else if(slotID > 30) + { + if(!mergeItemStack(slotStack, 4, 30, false)) + { + return null; + } + } + else { + if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true)) + { + return null; + } + } + } + + if(slotStack.stackSize == 0) + { + currentSlot.putStack((ItemStack)null); + } + else { + currentSlot.onSlotChanged(); + } + + if(slotStack.stackSize == stack.stackSize) + { + return null; + } + + currentSlot.onPickupFromSlot(player, slotStack); + } + + return stack; + } }