From 3e65a04f1e5aa64281846703bfb5de4d745411e6 Mon Sep 17 00:00:00 2001 From: pahimar Date: Tue, 14 May 2013 21:07:52 -0400 Subject: [PATCH] Shift clicking work for all existing and implemented container inventories --- .../com/pahimar/ee3/block/BlockGlassBell.java | 8 +- .../tileentity/TileEntityAludelRenderer.java | 2 +- .../TileEntityCalcinatorRenderer.java | 2 +- .../ee3/inventory/ContainerAlchemicalBag.java | 42 ++++++++- .../inventory/ContainerAlchemicalChest.java | 2 +- .../ee3/inventory/ContainerAludel.java | 41 +++++++-- .../ee3/inventory/ContainerCalcinator.java | 92 ++++++++++--------- .../ee3/inventory/ContainerGlassBell.java | 2 +- .../pahimar/ee3/tileentity/TileAludel.java | 6 +- .../ee3/tileentity/TileCalcinator.java | 2 +- 10 files changed, 131 insertions(+), 68 deletions(-) diff --git a/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java b/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java index f6e64a43..a0cbdd90 100644 --- a/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java +++ b/ee3_common/com/pahimar/ee3/block/BlockGlassBell.java @@ -79,15 +79,15 @@ public class BlockGlassBell extends BlockEE { return false; else { if (!world.isRemote) { - TileGlassBell tileGlassBell = (TileGlassBell) world.getBlockTileEntity(x, y, z); - TileAludel tileAludel = (TileAludel) world.getBlockTileEntity(x, y - 1, z); + TileEntity tileEntityGlassBell = world.getBlockTileEntity(x, y, z); + TileEntity tileEntityAludel = world.getBlockTileEntity(x, y - 1, z); - if (tileAludel != null && tileGlassBell != null) { + if (tileEntityAludel instanceof TileAludel && tileEntityGlassBell instanceof TileGlassBell) { player.openGui(EquivalentExchange3.instance, GuiIds.ALUDEL, world, x, y - 1, z); return true; } - if (tileGlassBell != null) { + if (tileEntityGlassBell != null) { player.openGui(EquivalentExchange3.instance, GuiIds.GLASS_BELL, world, x, y, z); } } diff --git a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java index f9d5e0d8..ed28fc1b 100644 --- a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java +++ b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityAludelRenderer.java @@ -77,7 +77,7 @@ public class TileEntityAludelRenderer extends TileEntitySpecialRenderer { TileEntity tileGlassBell = tileAludel.worldObj.getBlockTileEntity(tileAludel.xCoord, tileAludel.yCoord + 1, tileAludel.zCoord); - if (tileGlassBell != null && tileGlassBell instanceof TileGlassBell) { + if (tileGlassBell instanceof TileGlassBell) { if (tileAludel.getStackInSlot(TileAludel.INPUT_INVENTORY_INDEX) != null) { float scaleFactor = getGhostItemScaleFactor(tileAludel.getStackInSlot(TileAludel.INPUT_INVENTORY_INDEX)); diff --git a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityCalcinatorRenderer.java b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityCalcinatorRenderer.java index f8770e88..6963c83d 100644 --- a/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityCalcinatorRenderer.java +++ b/ee3_common/com/pahimar/ee3/client/renderer/tileentity/TileEntityCalcinatorRenderer.java @@ -48,7 +48,7 @@ public class TileEntityCalcinatorRenderer extends TileEntitySpecialRenderer { // Render modelCalcinator.renderPart("Calcinator"); - if (tileCalcinator.getStackInSlot(TileCalcinator.DUST_INVENTORY_INDEX) != null) { + if (tileCalcinator.getStackInSlot(TileCalcinator.OUTPUT_INVENTORY_INDEX) != null) { modelCalcinator.renderPart("Dust"); } diff --git a/ee3_common/com/pahimar/ee3/inventory/ContainerAlchemicalBag.java b/ee3_common/com/pahimar/ee3/inventory/ContainerAlchemicalBag.java index bf67f9ab..353ad889 100644 --- a/ee3_common/com/pahimar/ee3/inventory/ContainerAlchemicalBag.java +++ b/ee3_common/com/pahimar/ee3/inventory/ContainerAlchemicalBag.java @@ -19,18 +19,24 @@ import com.pahimar.ee3.lib.Strings; * */ public class ContainerAlchemicalBag extends Container { + + private final int BAG_INVENTORY_ROWS = 4; + private final int BAG_INVENTORY_COLUMNS = 13; + + private final int PLAYER_INVENTORY_ROWS = 3; + private final int PLAYER_INVENTORY_COLUMNS = 9; public ContainerAlchemicalBag(InventoryPlayer inventoryPlayer) { // Add the player's inventory slots to the container - for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) { - for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex) { - this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 44 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18)); + for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex) { + for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex) { + this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * PLAYER_INVENTORY_COLUMNS + PLAYER_INVENTORY_COLUMNS, 44 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18)); } } // Add the player's action bar slots to the container - for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex) { + for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex) { this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 162)); } } @@ -57,4 +63,32 @@ public class ContainerAlchemicalBag extends Container { } } } + + @Override + public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) { + + ItemStack newItemStack = null; + Slot slot = (Slot) inventorySlots.get(slotIndex); + + if (slot != null && slot.getHasStack()) { + ItemStack itemStack = slot.getStack(); + newItemStack = itemStack.copy(); + + if (slotIndex < BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS) { + if (!this.mergeItemStack(itemStack, BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS, inventorySlots.size(), false)) + return null; + } + else if (!this.mergeItemStack(itemStack, 0, BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS, false)) + return null; + + if (itemStack.stackSize == 0) { + slot.putStack((ItemStack) null); + } + else { + slot.onSlotChanged(); + } + } + + return newItemStack; + } } diff --git a/ee3_common/com/pahimar/ee3/inventory/ContainerAlchemicalChest.java b/ee3_common/com/pahimar/ee3/inventory/ContainerAlchemicalChest.java index 75758c6c..fa2222c8 100644 --- a/ee3_common/com/pahimar/ee3/inventory/ContainerAlchemicalChest.java +++ b/ee3_common/com/pahimar/ee3/inventory/ContainerAlchemicalChest.java @@ -80,7 +80,7 @@ public class ContainerAlchemicalChest extends Container { newItemStack = itemStack.copy(); if (slotIndex < CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS) { - if (!this.mergeItemStack(itemStack, CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS, inventorySlots.size(), true)) + if (!this.mergeItemStack(itemStack, CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS, inventorySlots.size(), false)) return null; } else if (!this.mergeItemStack(itemStack, 0, CHEST_INVENTORY_ROWS * CHEST_INVENTORY_COLUMNS, false)) diff --git a/ee3_common/com/pahimar/ee3/inventory/ContainerAludel.java b/ee3_common/com/pahimar/ee3/inventory/ContainerAludel.java index c19d3dff..923b56b9 100644 --- a/ee3_common/com/pahimar/ee3/inventory/ContainerAludel.java +++ b/ee3_common/com/pahimar/ee3/inventory/ContainerAludel.java @@ -5,7 +5,9 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityFurnace; +import com.pahimar.ee3.item.ItemAlchemicalDust; import com.pahimar.ee3.tileentity.TileAludel; /** @@ -24,9 +26,9 @@ public class ContainerAludel extends Container { public ContainerAludel(InventoryPlayer inventoryPlayer, TileAludel tileAludel) { + this.addSlotToContainer(new Slot(tileAludel, TileAludel.FUEL_INVENTORY_INDEX, 44, 74)); this.addSlotToContainer(new Slot(tileAludel, TileAludel.INPUT_INVENTORY_INDEX, 44, 18)); this.addSlotToContainer(new Slot(tileAludel, TileAludel.DUST_INVENTORY_INDEX, 44, 39)); - this.addSlotToContainer(new Slot(tileAludel, TileAludel.FUEL_INVENTORY_INDEX, 44, 74)); this.addSlotToContainer(new Slot(tileAludel, TileAludel.OUTPUT_INVENTORY_INDEX, 120, 39)); // Add the player's inventory slots to the container @@ -54,22 +56,47 @@ public class ContainerAludel extends Container { ItemStack itemStack = null; Slot slot = (Slot) inventorySlots.get(slotIndex); - if (slot != null && slot.getHasStack()) - { + if (slot != null && slot.getHasStack()) { + ItemStack slotItemStack = slot.getStack(); itemStack = slotItemStack.copy(); + /** + * If we are shift-clicking an item out of the Aludel's container, attempt to put it in the first available slot in the + * player's inventory + */ if (slotIndex < TileAludel.INVENTORY_SIZE) { - if (!this.mergeItemStack(slotItemStack, TileAludel.INVENTORY_SIZE + 1, inventorySlots.size(), true)) { + if (!this.mergeItemStack(slotItemStack, TileAludel.INVENTORY_SIZE, inventorySlots.size(), false)) { return null; } } else { - /* - * TODO: Depending on the slowItemStack, attempt to merge it into acceptable slots + + /** + * If the stack being shift-clicked into the Aludel's container is a fuel, first try to put it in the fuel slot. + * If it cannot be merged into the fuel slot, try to put it in the input slot. */ - if (!this.mergeItemStack(slotItemStack, 0, TileAludel.INVENTORY_SIZE - 1, false)) { + if (TileEntityFurnace.isItemFuel(slotItemStack)) { + if (!this.mergeItemStack(slotItemStack, TileAludel.FUEL_INVENTORY_INDEX, TileAludel.INPUT_INVENTORY_INDEX, false)) { + return null; + } + } + + /** + * If the stack being shift-clicked into the Aludel's container is a dust, first try to put it in the dust slot. + * If it cannot be merged into the dust slot, try to put it in the input slot. + */ + else if (slotItemStack.getItem() instanceof ItemAlchemicalDust) { + if (!this.mergeItemStack(slotItemStack, TileAludel.DUST_INVENTORY_INDEX, TileAludel.OUTPUT_INVENTORY_INDEX, false)) { + return null; + } + } + + /** + * Finally, attempt to put stack into the input slot + */ + else if (!this.mergeItemStack(slotItemStack, TileAludel.INPUT_INVENTORY_INDEX, TileAludel.DUST_INVENTORY_INDEX, false)) { return null; } } diff --git a/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java b/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java index 6ec364fd..d0b879bd 100644 --- a/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java +++ b/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java @@ -8,6 +8,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.tileentity.TileEntityFurnace; +import com.pahimar.ee3.item.ItemAlchemicalDust; +import com.pahimar.ee3.tileentity.TileAludel; import com.pahimar.ee3.tileentity.TileCalcinator; /** @@ -23,14 +25,14 @@ public class ContainerCalcinator extends Container { public ContainerCalcinator(InventoryPlayer inventoryPlayer, TileCalcinator calcinator) { - // Add the calcinator "to be calcined" slot to the container - this.addSlotToContainer(new Slot(calcinator, 0, 56, 17)); + // Add the fuel slot to the container + this.addSlotToContainer(new Slot(calcinator, TileCalcinator.FUEL_INVENTORY_INDEX, 56, 62)); + + // Add the input slot to the container + this.addSlotToContainer(new Slot(calcinator, TileCalcinator.INPUT_INVENTORY_INDEX, 56, 17)); - // Add the calcinator fuel slot to the container - this.addSlotToContainer(new Slot(calcinator, 1, 56, 62)); - - // Add the calcined results slot to the container - this.addSlotToContainer(new SlotCalcinator(calcinator, 2, 116, 35)); + // Add the output results slot to the container + this.addSlotToContainer(new SlotCalcinator(calcinator, TileCalcinator.OUTPUT_INVENTORY_INDEX, 116, 35)); // Add the player's inventory slots to the container for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) { @@ -51,56 +53,56 @@ public class ContainerCalcinator extends Container { return true; } - // TODO Write our own version - this is taken from ContainerFurnace @Override - public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { + public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) { - ItemStack var3 = null; - Slot var4 = (Slot) inventorySlots.get(par2); + ItemStack itemStack = null; + Slot slot = (Slot) inventorySlots.get(slotIndex); - if (var4 != null && var4.getHasStack()) { - ItemStack var5 = var4.getStack(); - var3 = var5.copy(); + if (slot != null && slot.getHasStack()) { + + ItemStack slotItemStack = slot.getStack(); + itemStack = slotItemStack.copy(); - if (par2 == 2) { - if (!this.mergeItemStack(var5, 3, 39, true)) + /** + * If we are shift-clicking an item out of the Aludel's container, attempt to put it in the first available slot in the + * player's inventory + */ + if (slotIndex < TileCalcinator.INVENTORY_SIZE) { + + if (!this.mergeItemStack(slotItemStack, TileCalcinator.INVENTORY_SIZE, inventorySlots.size(), false)) { return null; - - var4.onSlotChange(var5, var3); - } - else if (par2 != 1 && par2 != 0) { - if (FurnaceRecipes.smelting().getSmeltingResult(var5) != null) { - if (!this.mergeItemStack(var5, 0, 1, false)) - return null; } - else if (TileEntityFurnace.isItemFuel(var5)) { - if (!this.mergeItemStack(var5, 1, 2, false)) - return null; - } - else if (par2 >= 3 && par2 < 30) { - if (!this.mergeItemStack(var5, 30, 39, false)) - return null; - } - else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false)) - return null; - } - else if (!this.mergeItemStack(var5, 3, 39, false)) - return null; - - if (var5.stackSize == 0) { - var4.putStack((ItemStack) null); } else { - var4.onSlotChanged(); + + /** + * If the stack being shift-clicked into the Aludel's container is a fuel, first try to put it in the fuel slot. + * If it cannot be merged into the fuel slot, try to put it in the input slot. + */ + if (TileEntityFurnace.isItemFuel(slotItemStack)) { + if (!this.mergeItemStack(slotItemStack, TileCalcinator.FUEL_INVENTORY_INDEX, TileCalcinator.OUTPUT_INVENTORY_INDEX, false)) { + return null; + } + } + + /** + * Finally, attempt to put stack into the input slot + */ + else if (!this.mergeItemStack(slotItemStack, TileCalcinator.INPUT_INVENTORY_INDEX, TileCalcinator.OUTPUT_INVENTORY_INDEX, false)) { + return null; + } } - if (var5.stackSize == var3.stackSize) - return null; - - var4.onPickupFromSlot(par1EntityPlayer, var5); + if (slotItemStack.stackSize == 0) { + slot.putStack((ItemStack) null); + } + else { + slot.onSlotChanged(); + } } - return var3; + return itemStack; } } diff --git a/ee3_common/com/pahimar/ee3/inventory/ContainerGlassBell.java b/ee3_common/com/pahimar/ee3/inventory/ContainerGlassBell.java index 7f9d119a..21e3597a 100644 --- a/ee3_common/com/pahimar/ee3/inventory/ContainerGlassBell.java +++ b/ee3_common/com/pahimar/ee3/inventory/ContainerGlassBell.java @@ -25,7 +25,7 @@ public class ContainerGlassBell extends Container { public ContainerGlassBell(InventoryPlayer inventoryPlayer, TileGlassBell tileGlassBell) { - this.addSlotToContainer(new Slot(tileGlassBell, TileAludel.INPUT_INVENTORY_INDEX, 80, 22)); + this.addSlotToContainer(new Slot(tileGlassBell, TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX, 80, 22)); // Add the player's inventory slots to the container for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex) { diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java b/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java index ae2646c9..e5c2f93c 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileAludel.java @@ -29,9 +29,9 @@ public class TileAludel extends TileEE implements IInventory { public static final int INVENTORY_SIZE = 4; - public static final int INPUT_INVENTORY_INDEX = 0; - public static final int DUST_INVENTORY_INDEX = 1; - public static final int FUEL_INVENTORY_INDEX = 2; + public static final int FUEL_INVENTORY_INDEX = 0; + public static final int INPUT_INVENTORY_INDEX = 1; + public static final int DUST_INVENTORY_INDEX = 2; public static final int OUTPUT_INVENTORY_INDEX = 3; public TileAludel() { diff --git a/ee3_common/com/pahimar/ee3/tileentity/TileCalcinator.java b/ee3_common/com/pahimar/ee3/tileentity/TileCalcinator.java index 60d9dac2..fe49f3c5 100644 --- a/ee3_common/com/pahimar/ee3/tileentity/TileCalcinator.java +++ b/ee3_common/com/pahimar/ee3/tileentity/TileCalcinator.java @@ -27,7 +27,7 @@ public class TileCalcinator extends TileEE implements IInventory { public static final int FUEL_INVENTORY_INDEX = 0; public static final int INPUT_INVENTORY_INDEX = 1; - public static final int DUST_INVENTORY_INDEX = 2; + public static final int OUTPUT_INVENTORY_INDEX = 2; public TileCalcinator() {