From 2d9ea3d654340b44851f4b5923d7d86c4b60d862 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 4 Sep 2025 18:37:02 +0200 Subject: [PATCH] change inventory system --- .../client/gui/container/GuiContainer.java | 13 +- .../client/gui/element/InventoryButton.java | 33 ++++- .../java/common/inventory/ContainerChest.java | 9 +- .../inventory/ContainerEnchantment.java | 4 +- .../inventory/ContainerEntityInventory.java | 11 +- .../common/inventory/ContainerMerchant.java | 124 +++++++++++++++++- .../common/inventory/ContainerPlayer.java | 11 +- .../common/inventory/ContainerRepair.java | 77 ++++++++++- .../java/common/inventory/ContainerTile.java | 6 +- .../common/inventory/ContainerWorkbench.java | 7 +- .../inventory/InventoryCraftResult.java | 75 ----------- .../src/main/java/common/inventory/Slot.java | 34 +++-- .../java/common/inventory/SlotCommon.java | 51 +++++++ .../common/inventory/SlotMerchantResult.java | 122 ----------------- .../java/common/inventory/SlotOutput.java | 17 --- 15 files changed, 349 insertions(+), 245 deletions(-) delete mode 100755 common/src/main/java/common/inventory/InventoryCraftResult.java create mode 100644 common/src/main/java/common/inventory/SlotCommon.java delete mode 100755 common/src/main/java/common/inventory/SlotMerchantResult.java delete mode 100755 common/src/main/java/common/inventory/SlotOutput.java diff --git a/client/src/main/java/client/gui/container/GuiContainer.java b/client/src/main/java/client/gui/container/GuiContainer.java index 4d9557d9..29a4e441 100755 --- a/client/src/main/java/client/gui/container/GuiContainer.java +++ b/client/src/main/java/client/gui/container/GuiContainer.java @@ -188,6 +188,15 @@ public abstract class GuiContainer extends Gui return list; } + + public int getScale() { + return this.container_scale; + } + + public ItemStack getHoverItem(Slot slot) { + return this.gm.player != null && this.gm.player.getMouseItem() != null ? this.gm.player.getMouseItem() : (this.gm.itemCheat && this.cheatStack != null ? this.cheatStack : (Bind.CRAFT.isDown() + && slot.canCheatItem() && slot.getHasStack() ? this.gm.player.inventoryContainer.getSingleRecipe(slot.getStack()) : null)); + } public Label label(String text, int x, int y) { x = x * this.container_scale + this.container_x; @@ -292,7 +301,7 @@ public abstract class GuiContainer extends Gui if(this.inventorySlots != null) { for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) { Slot slot = this.inventorySlots.inventorySlots.get(i1); - if(slot.getTexture() == null || !slot.getTexture().isEmpty()) + if(slot.canDraw()) this.slot(slot.xDisplayPosition - 1, slot.yDisplayPosition - 1, 18, 18, slot); } } @@ -316,7 +325,7 @@ public abstract class GuiContainer extends Gui Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1); this.drawSlot(slot); - if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canBeHovered()) + if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canHover()) { this.theSlot = slot; } diff --git a/client/src/main/java/client/gui/element/InventoryButton.java b/client/src/main/java/client/gui/element/InventoryButton.java index 42e83241..aa1a0070 100644 --- a/client/src/main/java/client/gui/element/InventoryButton.java +++ b/client/src/main/java/client/gui/element/InventoryButton.java @@ -1,23 +1,34 @@ package client.gui.element; import client.Client; +import client.gui.Gui; +import client.gui.container.GuiContainer; import client.renderer.Drawing; import common.inventory.Slot; +import common.item.ItemStack; public class InventoryButton extends Element { private final boolean bordered; private final Slot slot; private final String texture; + private final boolean background; + private final int bgW; + private final int bgH; public InventoryButton(int x, int y, int w, int h, boolean bordered, Slot slot) { super(x, y, w, h, null); this.bordered = bordered; - this.texture = slot == null || slot.getTexture() == null ? null : "textures/items/icon_" + slot.getTexture() + ".png"; - this.slot = this.texture == null ? null : slot; + this.texture = slot == null || slot.getTexture() == null || slot.getTexture().isEmpty() ? null : "textures/items/icon_" + slot.getTexture() + ".png"; + this.background = slot == null || slot.getTexture() != null; + this.slot = slot; + int scale = this.bordered ? 2 : 1; + this.bgW = slot == null ? w : slot.getBackgroundWidth() * 18 * scale; + this.bgH = slot == null ? h : slot.getBackgroundHeight() * 18 * scale; } protected void drawBackground() { - drawButton(this.gm, this.pos_x, this.pos_y, this.size_x, this.size_y, this.bordered); + if(this.background) + drawButton(this.gm, this.pos_x, this.pos_y, this.bgW, this.bgH, this.bordered); if(this.texture != null && !this.slot.getHasStack()) { int scale = this.bordered ? 2 : 1; Drawing.drawTexturedRect(this.gm, this.texture, 16 * scale, 16 * scale, this.pos_x + scale, this.pos_y + scale, 0, 0, this.size_x - scale * 2, this.size_y - scale * 2); @@ -33,4 +44,20 @@ public class InventoryButton extends Element { else Drawing.drawGradient(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, gm.style.brdr_top, gm.style.brdr_btm); } + + public boolean canHover() { + if(this.slot == null) + return true; + ItemStack hover = ((GuiContainer)this.gui).getHoverItem(this.slot); + return hover == null ? this.slot.getHasStack() : this.slot.isItemValid(hover); + } + + public void drawHover() { + int scale = this.bordered ? 2 : 1; + Drawing.drawRect(this.pos_x + scale, this.pos_y + scale, 16 * scale, 16 * scale, Gui.HOVER_COLOR); + } + + public boolean canClick() { + return false; + } } diff --git a/common/src/main/java/common/inventory/ContainerChest.java b/common/src/main/java/common/inventory/ContainerChest.java index 724d3dd2..7ab70ac3 100755 --- a/common/src/main/java/common/inventory/ContainerChest.java +++ b/common/src/main/java/common/inventory/ContainerChest.java @@ -1,6 +1,9 @@ package common.inventory; +import java.util.List; + import common.block.tech.BlockChest; +import common.collect.Lists; import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.tileentity.TileEntityChest; @@ -22,17 +25,19 @@ public class ContainerChest extends Container int xOffset = this.width < 12 ? 0 : (this.width - 12) * 18 / 2; int yOffset = (this.height - 3) * 18; + List list1 = Lists.newArrayList(); for (int j = 0; j < this.height; ++j) { for (int k = 0; k < this.width; ++k) { - this.addSlotToContainer(new Slot(chest, k + j * this.width, 8 + k * 18, 18 + j * 18)); + this.addSlotToContainer(new SlotCommon(list1, chest, k + j * this.width, 8 + k * 18, 18 + j * 18)); } } + List list2 = Lists.newArrayList(); for (int l = 0; l < player.getInventoryCapacity(); ++l) { - this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18 + xOffset, 85 + (l / 12) * 18 + yOffset)); + this.addSlotToContainer(new SlotCommon(list2, player, l, 8 + (l % 12) * 18 + xOffset, 85 + (l / 12) * 18 + yOffset)); } } diff --git a/common/src/main/java/common/inventory/ContainerEnchantment.java b/common/src/main/java/common/inventory/ContainerEnchantment.java index c299527c..01aacd72 100755 --- a/common/src/main/java/common/inventory/ContainerEnchantment.java +++ b/common/src/main/java/common/inventory/ContainerEnchantment.java @@ -2,6 +2,7 @@ package common.inventory; import java.util.List; +import common.collect.Lists; import common.enchantment.Enchantment; import common.enchantment.EnchantmentHelper; import common.enchantment.RngEnchantment; @@ -63,9 +64,10 @@ public class ContainerEnchantment extends Container } }); + List list = Lists.newArrayList(); for (int l = 0; l < playerInv.getInventoryCapacity(); ++l) { - this.addSlotToContainer(new Slot(playerInv, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); + this.addSlotToContainer(new SlotCommon(list, playerInv, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); } } diff --git a/common/src/main/java/common/inventory/ContainerEntityInventory.java b/common/src/main/java/common/inventory/ContainerEntityInventory.java index 81106ff5..a640dcb1 100755 --- a/common/src/main/java/common/inventory/ContainerEntityInventory.java +++ b/common/src/main/java/common/inventory/ContainerEntityInventory.java @@ -1,5 +1,8 @@ package common.inventory; +import java.util.List; + +import common.collect.Lists; import common.entity.Entity; import common.entity.animal.EntityHorse; import common.entity.npc.EntityNPC; @@ -32,26 +35,28 @@ public class ContainerEntityInventory extends Container { return super.isItemValid(stack) && horse.canWearArmor() && EntityHorse.isArmorItem(stack.getItem()); } - public boolean canBeHovered() + public boolean canDraw() { return horse.canWearArmor(); } }); if (horse.isChested()) { + List list = Lists.newArrayList(); for (int k = 0; k < i; ++k) { for (int l = 0; l < 5; ++l) { - this.addSlotToContainer(new Slot(entityInv, 2 + l + k * 5, 80 + l * 18, 18 + k * 18)); + this.addSlotToContainer(new SlotCommon(list, entityInv, 2 + l + k * 5, 80 + l * 18, 18 + k * 18)); } } } } + List list = Lists.newArrayList(); for (int l = 0; l < player.getInventoryCapacity(); ++l) { - this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); + this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); } } diff --git a/common/src/main/java/common/inventory/ContainerMerchant.java b/common/src/main/java/common/inventory/ContainerMerchant.java index 77cb4079..b8fbff24 100755 --- a/common/src/main/java/common/inventory/ContainerMerchant.java +++ b/common/src/main/java/common/inventory/ContainerMerchant.java @@ -1,12 +1,133 @@ package common.inventory; +import java.util.List; + +import common.collect.Lists; import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.network.IPlayer; +import common.village.MerchantRecipe; import common.world.World; public class ContainerMerchant extends Container { + private class SlotMerchantResult extends Slot + { + private final InventoryMerchant theMerchantInventory; + private EntityNPC thePlayer; + private int traded; +// private final EntityVillager theMerchant; + + public SlotMerchantResult(EntityNPC player, InventoryMerchant merchantInventory, int slotIndex, int xPosition, int yPosition) + { + super(merchantInventory, slotIndex, xPosition, yPosition); + this.thePlayer = player; +// this.theMerchant = merchant; + this.theMerchantInventory = merchantInventory; + } + + /** + * Check if the stack is a valid item for this slot. Always true beside for the armor slots. + */ + public boolean isItemValid(ItemStack stack) + { + return false; + } + + /** + * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new + * stack. + */ + public ItemStack decrStackSize(int amount) + { + if (this.getHasStack()) + { + this.traded += Math.min(amount, this.getStack().getSize()); + } + + return super.decrStackSize(amount); + } + + /** + * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an + * internal count then calls onCrafting(item). + */ + protected void onCrafting(ItemStack stack, int amount) + { + this.traded += amount; + this.onCrafting(stack); + } + + /** + * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. + */ + protected void onCrafting(ItemStack stack) + { +// stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.traded); + this.traded = 0; + } + + public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack) + { + this.onCrafting(stack); + MerchantRecipe merchantrecipe = this.theMerchantInventory.getCurrentRecipe(); + + if (merchantrecipe != null) + { + ItemStack itemstack = this.theMerchantInventory.getStackInSlot(0); + ItemStack itemstack1 = this.theMerchantInventory.getStackInSlot(1); + + if (this.doTrade(merchantrecipe, itemstack, itemstack1) || this.doTrade(merchantrecipe, itemstack1, itemstack)) + { +// if(this.theMerchant != null) +// this.theMerchant.useRecipe(merchantrecipe); +// playerIn.triggerAchievement(StatRegistry.timesTradedWithNpcStat); + + if (itemstack != null && itemstack.isEmpty()) + { + itemstack = null; + } + + if (itemstack1 != null && itemstack1.isEmpty()) + { + itemstack1 = null; + } + + this.theMerchantInventory.setInventorySlotContents(0, itemstack); + this.theMerchantInventory.setInventorySlotContents(1, itemstack1); + } + } + } + + private boolean doTrade(MerchantRecipe trade, ItemStack firstItem, ItemStack secondItem) + { + ItemStack itemstack = trade.first(); + ItemStack itemstack1 = trade.second(); + + if (firstItem != null && firstItem.getItem() == itemstack.getItem()) + { + if (itemstack1 != null && secondItem != null && itemstack1.getItem() == secondItem.getItem()) + { + firstItem.decrSize(itemstack.getSize()); + secondItem.decrSize(itemstack1.getSize()); + return true; + } + + if (itemstack1 == null && secondItem == null) + { + firstItem.decrSize(itemstack.getSize()); + return true; + } + } + + return false; + } + + public boolean canCheatItem() { + return false; + } + } + private EntityNPC theMerchant; private InventoryMerchant merchantInventory; private final World theWorld; @@ -28,9 +149,10 @@ public class ContainerMerchant extends Container }); this.addSlotToContainer(new SlotMerchantResult(playerInventory, this.merchantInventory, 2, 120, 53)); + List list = Lists.newArrayList(); for (int l = 0; l < playerInventory.getInventoryCapacity(); ++l) { - this.addSlotToContainer(new Slot(playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); + this.addSlotToContainer(new SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); } } diff --git a/common/src/main/java/common/inventory/ContainerPlayer.java b/common/src/main/java/common/inventory/ContainerPlayer.java index 20432fe7..4a312827 100755 --- a/common/src/main/java/common/inventory/ContainerPlayer.java +++ b/common/src/main/java/common/inventory/ContainerPlayer.java @@ -1,5 +1,8 @@ package common.inventory; +import java.util.List; + +import common.collect.Lists; import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.item.material.ItemArmor; @@ -26,14 +29,18 @@ public class ContainerPlayer extends Container { return stack != null && stack.getItem() instanceof ItemArmor armor && armor.getArmorType().canUseInSlot(ContainerPlayer.this.thePlayer, type); } public String getTexture() { - return ContainerPlayer.this.thePlayer.hasArmorSlot(type) ? (type.isRing() ? "ring" : type.getName()) : ""; + return type.isRing() ? "ring" : type.getName(); + } + public boolean canDraw() { + return ContainerPlayer.this.thePlayer.hasArmorSlot(type); } }); } + List list = Lists.newArrayList(); for (int l = 0; l < player.getInventoryCapacity(); ++l) { - this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); + this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); } } diff --git a/common/src/main/java/common/inventory/ContainerRepair.java b/common/src/main/java/common/inventory/ContainerRepair.java index c6fae1cd..3660afe0 100755 --- a/common/src/main/java/common/inventory/ContainerRepair.java +++ b/common/src/main/java/common/inventory/ContainerRepair.java @@ -1,9 +1,11 @@ package common.inventory; import java.util.Iterator; +import java.util.List; import java.util.Map; import common.block.tech.BlockAnvil; +import common.collect.Lists; import common.enchantment.Enchantment; import common.enchantment.EnchantmentHelper; import common.entity.npc.EntityNPC; @@ -17,6 +19,78 @@ import common.world.World; public class ContainerRepair extends Container { + private class InventoryCraftResult implements IInventory + { + /** A list of one item containing the result of the crafting formula */ + private ItemStack[] stackResult = new ItemStack[1]; + + /** + * Returns the number of slots in the inventory. + */ + public int getSizeInventory() + { + return 1; + } + + /** + * Returns the stack in the given slot. + */ + public ItemStack getStackInSlot(int index) + { + return this.stackResult[0]; + } + + /** + * Removes up to a specified number of items from an inventory slot and returns them in a new stack. + */ + public ItemStack decrStackSize(int index, int count) + { + if (this.stackResult[0] != null) + { + ItemStack itemstack = this.stackResult[0]; + this.stackResult[0] = null; + return itemstack; + } + else + { + return null; + } + } + + /** + * Removes a stack from the given slot and returns it. + */ + public ItemStack removeStackFromSlot(int index) + { + if (this.stackResult[0] != null) + { + ItemStack itemstack = this.stackResult[0]; + this.stackResult[0] = null; + return itemstack; + } + else + { + return null; + } + } + + /** + * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). + */ + public void setInventorySlotContents(int index, ItemStack stack) + { + this.stackResult[0] = stack; + } + + public void clear() + { + for (int i = 0; i < this.stackResult.length; ++i) + { + this.stackResult[i] = null; + } + } + } + private IInventory outputSlot; private IInventory inputSlots; private World theWorld; @@ -121,9 +195,10 @@ public class ContainerRepair extends Container } }); + List list = Lists.newArrayList(); for (int l = 0; l < playerInventory.getInventoryCapacity(); ++l) { - this.addSlotToContainer(new Slot(playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); + this.addSlotToContainer(new SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); } } diff --git a/common/src/main/java/common/inventory/ContainerTile.java b/common/src/main/java/common/inventory/ContainerTile.java index 12d26832..01b4fa6f 100755 --- a/common/src/main/java/common/inventory/ContainerTile.java +++ b/common/src/main/java/common/inventory/ContainerTile.java @@ -1,5 +1,8 @@ package common.inventory; +import java.util.List; + +import common.collect.Lists; import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.network.IPlayer; @@ -51,9 +54,10 @@ public class ContainerTile extends Container ++output; } + List list = Lists.newArrayList(); for (int l = 0; l < player.getInventoryCapacity(); ++l) { - this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18, 112 + (l / 12) * 18)); + this.addSlotToContainer(new SlotCommon(list, player, l, 8 + (l % 12) * 18, 112 + (l / 12) * 18)); } } diff --git a/common/src/main/java/common/inventory/ContainerWorkbench.java b/common/src/main/java/common/inventory/ContainerWorkbench.java index 9de48361..ee0be5dc 100755 --- a/common/src/main/java/common/inventory/ContainerWorkbench.java +++ b/common/src/main/java/common/inventory/ContainerWorkbench.java @@ -1,6 +1,9 @@ package common.inventory; +import java.util.List; + import common.block.tech.BlockWorkbench; +import common.collect.Lists; import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.util.LocalPos; @@ -15,8 +18,10 @@ public class ContainerWorkbench extends Container { this.block = block; this.worldObj = worldIn; this.pos = posIn; + + List list = Lists.newArrayList(); for(int l = 0; l < playerInventory.getInventoryCapacity(); ++l) { - this.addSlotToContainer(new Slot(playerInventory, l, 8 + (l % 12) * 18, 30 + 3 * 18 + (l / 12) * 18)); + this.addSlotToContainer(new SlotCommon(list, playerInventory, l, 8 + (l % 12) * 18, 30 + 3 * 18 + (l / 12) * 18)); } } diff --git a/common/src/main/java/common/inventory/InventoryCraftResult.java b/common/src/main/java/common/inventory/InventoryCraftResult.java deleted file mode 100755 index cbea0775..00000000 --- a/common/src/main/java/common/inventory/InventoryCraftResult.java +++ /dev/null @@ -1,75 +0,0 @@ -package common.inventory; - -import common.item.ItemStack; - -public class InventoryCraftResult implements IInventory -{ - /** A list of one item containing the result of the crafting formula */ - private ItemStack[] stackResult = new ItemStack[1]; - - /** - * Returns the number of slots in the inventory. - */ - public int getSizeInventory() - { - return 1; - } - - /** - * Returns the stack in the given slot. - */ - public ItemStack getStackInSlot(int index) - { - return this.stackResult[0]; - } - - /** - * Removes up to a specified number of items from an inventory slot and returns them in a new stack. - */ - public ItemStack decrStackSize(int index, int count) - { - if (this.stackResult[0] != null) - { - ItemStack itemstack = this.stackResult[0]; - this.stackResult[0] = null; - return itemstack; - } - else - { - return null; - } - } - - /** - * Removes a stack from the given slot and returns it. - */ - public ItemStack removeStackFromSlot(int index) - { - if (this.stackResult[0] != null) - { - ItemStack itemstack = this.stackResult[0]; - this.stackResult[0] = null; - return itemstack; - } - else - { - return null; - } - } - - /** - * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). - */ - public void setInventorySlotContents(int index, ItemStack stack) - { - this.stackResult[0] = stack; - } - - public void clear() - { - for (int i = 0; i < this.stackResult.length; ++i) - { - this.stackResult[i] = null; - } - } -} diff --git a/common/src/main/java/common/inventory/Slot.java b/common/src/main/java/common/inventory/Slot.java index d180a948..1d2697df 100755 --- a/common/src/main/java/common/inventory/Slot.java +++ b/common/src/main/java/common/inventory/Slot.java @@ -118,11 +118,6 @@ public class Slot return this.canStackItems() ? 1000000000 : 1; } - public String getTexture() - { - return null; - } - /** * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new * stack. @@ -147,15 +142,6 @@ public class Slot { return true; } - - /** - * Actualy only call when we want to render the white square effect over the slots. Return always True, except for - * the armor slot of the Donkey/Mule (we can't interact with the Undead and Skeleton horses) - */ - public boolean canBeHovered() - { - return true; - } public int getIndex() { return this.slotIndex; @@ -168,4 +154,24 @@ public class Slot public boolean canEditItem() { return this.canCheatItem(); } + + public int getBackgroundWidth() { + return 1; + } + + public int getBackgroundHeight() { + return 1; + } + + public String getTexture() { + return ""; + } + + public boolean canDraw() { + return true; + } + + public boolean canHover() { + return this.canDraw(); + } } diff --git a/common/src/main/java/common/inventory/SlotCommon.java b/common/src/main/java/common/inventory/SlotCommon.java new file mode 100644 index 00000000..3d0d6112 --- /dev/null +++ b/common/src/main/java/common/inventory/SlotCommon.java @@ -0,0 +1,51 @@ +package common.inventory; + +import java.util.List; + +public class SlotCommon extends Slot { + private final List list; + private final SlotCommon draw; + + private int w; + private int h; + + public SlotCommon(List list, IInventory inventoryIn, int index, int xPosition, int yPosition) { + super(inventoryIn, index, xPosition, yPosition); + this.list = list; + this.draw = list.isEmpty() ? null : list.getFirst(); + list.add(this); + } + + public String getTexture() { + return this.draw == null ? super.getTexture() : null; + } + + private void init() { + int x1 = Integer.MAX_VALUE; + int y1 = Integer.MAX_VALUE; + int x2 = Integer.MIN_VALUE; + int y2 = Integer.MIN_VALUE; + for(SlotCommon slot : this.list) { + x1 = Math.min(x1, slot.xDisplayPosition); + y1 = Math.min(y1, slot.yDisplayPosition); + x2 = Math.max(x2, slot.xDisplayPosition + 18); + y2 = Math.max(y2, slot.yDisplayPosition + 18); + } + this.w = (x2 - x1) / 18; + this.h = (y2 - y1) / 18; + } + + public int getBackgroundWidth() { + if(this.draw != null) + return this.draw.getBackgroundWidth(); + this.init(); + return this.w; + } + + public int getBackgroundHeight() { + if(this.draw != null) + return this.draw.getBackgroundHeight(); + this.init(); + return this.h; + } +} diff --git a/common/src/main/java/common/inventory/SlotMerchantResult.java b/common/src/main/java/common/inventory/SlotMerchantResult.java deleted file mode 100755 index edba8158..00000000 --- a/common/src/main/java/common/inventory/SlotMerchantResult.java +++ /dev/null @@ -1,122 +0,0 @@ -package common.inventory; - -import common.entity.npc.EntityNPC; -import common.item.ItemStack; -import common.village.MerchantRecipe; - -public class SlotMerchantResult extends Slot -{ - private final InventoryMerchant theMerchantInventory; - private EntityNPC thePlayer; - private int traded; -// private final EntityVillager theMerchant; - - public SlotMerchantResult(EntityNPC player, InventoryMerchant merchantInventory, int slotIndex, int xPosition, int yPosition) - { - super(merchantInventory, slotIndex, xPosition, yPosition); - this.thePlayer = player; -// this.theMerchant = merchant; - this.theMerchantInventory = merchantInventory; - } - - /** - * Check if the stack is a valid item for this slot. Always true beside for the armor slots. - */ - public boolean isItemValid(ItemStack stack) - { - return false; - } - - /** - * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new - * stack. - */ - public ItemStack decrStackSize(int amount) - { - if (this.getHasStack()) - { - this.traded += Math.min(amount, this.getStack().getSize()); - } - - return super.decrStackSize(amount); - } - - /** - * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an - * internal count then calls onCrafting(item). - */ - protected void onCrafting(ItemStack stack, int amount) - { - this.traded += amount; - this.onCrafting(stack); - } - - /** - * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. - */ - protected void onCrafting(ItemStack stack) - { -// stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.traded); - this.traded = 0; - } - - public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack) - { - this.onCrafting(stack); - MerchantRecipe merchantrecipe = this.theMerchantInventory.getCurrentRecipe(); - - if (merchantrecipe != null) - { - ItemStack itemstack = this.theMerchantInventory.getStackInSlot(0); - ItemStack itemstack1 = this.theMerchantInventory.getStackInSlot(1); - - if (this.doTrade(merchantrecipe, itemstack, itemstack1) || this.doTrade(merchantrecipe, itemstack1, itemstack)) - { -// if(this.theMerchant != null) -// this.theMerchant.useRecipe(merchantrecipe); -// playerIn.triggerAchievement(StatRegistry.timesTradedWithNpcStat); - - if (itemstack != null && itemstack.isEmpty()) - { - itemstack = null; - } - - if (itemstack1 != null && itemstack1.isEmpty()) - { - itemstack1 = null; - } - - this.theMerchantInventory.setInventorySlotContents(0, itemstack); - this.theMerchantInventory.setInventorySlotContents(1, itemstack1); - } - } - } - - private boolean doTrade(MerchantRecipe trade, ItemStack firstItem, ItemStack secondItem) - { - ItemStack itemstack = trade.first(); - ItemStack itemstack1 = trade.second(); - - if (firstItem != null && firstItem.getItem() == itemstack.getItem()) - { - if (itemstack1 != null && secondItem != null && itemstack1.getItem() == secondItem.getItem()) - { - firstItem.decrSize(itemstack.getSize()); - secondItem.decrSize(itemstack1.getSize()); - return true; - } - - if (itemstack1 == null && secondItem == null) - { - firstItem.decrSize(itemstack.getSize()); - return true; - } - } - - return false; - } - - public boolean canCheatItem() { - return false; - } -} diff --git a/common/src/main/java/common/inventory/SlotOutput.java b/common/src/main/java/common/inventory/SlotOutput.java deleted file mode 100755 index 6c585436..00000000 --- a/common/src/main/java/common/inventory/SlotOutput.java +++ /dev/null @@ -1,17 +0,0 @@ -package common.inventory; - -import common.item.ItemStack; - -public class SlotOutput extends Slot { - public SlotOutput(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) { - super(inventoryIn, slotIndex, xPosition, yPosition); - } - - public boolean isItemValid(ItemStack stack) { - return false; - } - - public boolean canCheatItem() { - return false; - } -}