diff --git a/src/main/java/com/zerofall/ezstorage/gui/server/ContainerStorageCore.java b/src/main/java/com/zerofall/ezstorage/gui/server/ContainerStorageCore.java index e67d318..4627e48 100644 --- a/src/main/java/com/zerofall/ezstorage/gui/server/ContainerStorageCore.java +++ b/src/main/java/com/zerofall/ezstorage/gui/server/ContainerStorageCore.java @@ -63,7 +63,7 @@ public boolean enchantItem(EntityPlayer player, int action) { return true; case 1: // clear the crafting grid if it exists if (this instanceof ContainerStorageCoreCrafting) { - ((ContainerStorageCoreCrafting) this).clearGrid(player); + ((ContainerStorageCoreCrafting) this).clearCraftingGrid(player); tileEntity.sortInventory(); return true; } @@ -97,35 +97,27 @@ public boolean enchantItem(EntityPlayer player, int action) { } /** Click a custom slot to take or insert items */ - public @Nonnull ItemStack customSlotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { - int itemIndex = slotId; + public @Nonnull ItemStack customSlotClick(int slotId, int clickedButton, int shiftPressed, EntityPlayer playerIn) { ItemStack heldStack = playerIn.inventory.getItemStack(); - // grab a stack from the inventory if (heldStack.isEmpty()) { - int type = 0; - if (clickedButton == 1) { - type = 1; - } - ItemStack stack = this.tileEntity.inventory.getItemsAt(itemIndex, type); - if (stack.isEmpty()) { - return ItemStack.EMPTY; - } - // player -> inventory - if (clickedButton == 0 && mode == 1) { - if (!this.mergeItemStack(stack, this.rowCount() * 9, this.rowCount() * 9 + 36, true)) { - this.tileEntity.inventory.input(stack); - } - // inventory -> player - } else { - playerIn.inventory.setItemStack(stack); - } - return stack; + ItemStack retrievedStack = this.tileEntity.inventory.getItemsAt(slotId, clickedButton); + + // take item from system if the user inventory is not full + if (playerIn.inventory.getFirstEmptyStack() != -1) { + if (retrievedStack.isEmpty()) return ItemStack.EMPTY; + + // check for shift clicking + if (clickedButton == 0 && shiftPressed == 1) { + if (!this.mergeItemStack(retrievedStack, this.rowCount() * 9, this.rowCount() * 9 + 36, true)) { + this.tileEntity.inventory.input(retrievedStack); + } + } else playerIn.inventory.setItemStack(retrievedStack); + return retrievedStack; + + } else playerIn.inventory.setItemStack(retrievedStack); + } else playerIn.inventory.setItemStack(this.tileEntity.inventory.input(heldStack)); - // place a stack into the inventory - } else { - playerIn.inventory.setItemStack(this.tileEntity.inventory.input(heldStack)); - } return ItemStack.EMPTY; } diff --git a/src/main/java/com/zerofall/ezstorage/gui/server/ContainerStorageCoreCrafting.java b/src/main/java/com/zerofall/ezstorage/gui/server/ContainerStorageCoreCrafting.java index b196d0b..fa3d7ff 100644 --- a/src/main/java/com/zerofall/ezstorage/gui/server/ContainerStorageCoreCrafting.java +++ b/src/main/java/com/zerofall/ezstorage/gui/server/ContainerStorageCoreCrafting.java @@ -69,7 +69,7 @@ public void onCraftMatrixChanged(IInventory inventoryIn) { if (slotObject instanceof SlotCrafting) { ItemStack[] recipe = new ItemStack[9]; for (int i = 0; i < 9; i++) { - recipe[i] = this.craftMatrix.getStackInSlot(i); + recipe[i] = this.craftMatrix.getStackInSlot(i).copy(); } ItemStack itemstack1 = slotObject.getStack(); @@ -80,15 +80,15 @@ public void onCraftMatrixChanged(IInventory inventoryIn) { int crafting = itemstack1.getCount(); for (int i = 0; i < itemstack1.getMaxStackSize(); i++) { - if (slotObject.getHasStack() && slotObject.getStack().isItemEqual(itemstack1)) { + if (slotObject.getHasStack()) { if (crafting > maxStackSize) { return ItemStack.EMPTY; } itemstack1 = slotObject.getStack(); itemstack = itemstack1.copy(); if (crafted + itemstack1.getCount() > itemstack1.getMaxStackSize()) { - return ItemStack.EMPTY; - } + return ItemStack.EMPTY; + } boolean merged = this.mergeItemStack(itemstack1, this.rowCount() * 9, this.rowCount() * 9 + 36, true); if (!merged) { return ItemStack.EMPTY; @@ -102,9 +102,10 @@ public void onCraftMatrixChanged(IInventory inventoryIn) { if (original.isItemEqual(slotObject.getStack())) { continue; } - - tryToPopulateCraftingGrid(recipe, playerIn); } + + tryToPopulateCraftingGrid(recipe, playerIn); + } else { break; } @@ -144,19 +145,20 @@ public void onCraftMatrixChanged(IInventory inventoryIn) { } private void tryToPopulateCraftingGrid(ItemStack[] recipe, EntityPlayer playerIn) { - clearGrid(playerIn); + clearCraftingGrid(playerIn); for (int j = 0; j < recipe.length; j++) { if (!recipe[j].isEmpty()) { - if (recipe[j].getCount() > 1) { - continue; - } else { - recipe[j].setCount(1); - } + + // if the item count is higher than 1, we take 1 item away. + if(recipe[j].getCount() != 1) { + recipe[j].setCount(recipe[j].getCount() - 1); + } + Slot slot = getSlotFromInventory(this.craftMatrix, j); if (slot != null) { - ItemStack retreived = tileEntity.inventory.getItems(new ItemStack[] { recipe[j] }); - if (!retreived.isEmpty()) { - slot.putStack(retreived); + ItemStack retrieved = tileEntity.inventory.getItems(new ItemStack[] { recipe[j] }); + if (!retrieved.isEmpty()) { + slot.putStack(retrieved); } } } @@ -175,16 +177,18 @@ protected int rowCount() { @Override public void onContainerClosed(EntityPlayer playerIn) { - clearGrid(playerIn); + clearCraftingGrid(playerIn); super.onContainerClosed(playerIn); } - public void clearGrid(EntityPlayer playerIn) { + public void clearCraftingGrid(EntityPlayer playerIn) { for (int i = 0; i < 9; i++) { ItemStack stack = this.craftMatrix.getStackInSlot(i); if (!stack.isEmpty()) { ItemStack result = this.tileEntity.input(stack); this.craftMatrix.setInventorySlotContents(i, ItemStack.EMPTY); + + // drop items on the ground if the grid is unable to be cleared if (!result.isEmpty()) { playerIn.dropItem(result, false); } diff --git a/src/main/java/com/zerofall/ezstorage/network/MessageRecipeSync.java b/src/main/java/com/zerofall/ezstorage/network/MessageRecipeSync.java index 4e8b2f3..d81cd21 100644 --- a/src/main/java/com/zerofall/ezstorage/network/MessageRecipeSync.java +++ b/src/main/java/com/zerofall/ezstorage/network/MessageRecipeSync.java @@ -62,7 +62,7 @@ public void handle(EntityPlayerMP player, MessageRecipeSync message) { TileEntityStorageCore tileEntity = con.tileEntity; // Empty grid into inventory - con.clearGrid(player); + con.clearCraftingGrid(player); this.recipe = new ItemStack[9][]; for (int x = 0; x < this.recipe.length; x++) {