From 9839107c4e04e69d94cd4f07f58e64674af2c96f Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+ballofenergy1@users.noreply.github.com> Date: Sat, 22 Mar 2025 13:05:45 -0500 Subject: [PATCH] New GUI, also some index fixes. --- .../inventory/container/ContainerToolBox.java | 11 ++++--- .../com/hbm/inventory/gui/GUIToolBox.java | 10 +++--- .../java/com/hbm/items/tool/ItemToolBox.java | 31 +++++++++++++----- .../assets/hbm/textures/gui/gui_toolbox.png | Bin 1399 -> 2012 bytes 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/hbm/inventory/container/ContainerToolBox.java b/src/main/java/com/hbm/inventory/container/ContainerToolBox.java index 9e9de5aa9..512e75283 100644 --- a/src/main/java/com/hbm/inventory/container/ContainerToolBox.java +++ b/src/main/java/com/hbm/inventory/container/ContainerToolBox.java @@ -1,5 +1,6 @@ package com.hbm.inventory.container; +import com.hbm.inventory.SlotNonRetarded; import com.hbm.util.InventoryUtil; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -11,7 +12,7 @@ import static com.hbm.items.tool.ItemToolBox.*; public class ContainerToolBox extends Container { - private InventoryToolBox box; + private final InventoryToolBox box; public ContainerToolBox(InventoryPlayer invPlayer, InventoryToolBox box) { this.box = box; @@ -19,18 +20,18 @@ public class ContainerToolBox extends Container { for(int i = 0; i < 3; i++) { for(int j = 0; j < 8; j++) { - this.addSlotToContainer(new Slot(box, j + i * 8, 17 + j * 18, 18 + i * 18)); + this.addSlotToContainer(new SlotNonRetarded(box, j + i * 8, 17 + j * 18, 49 + i * 18)); } } for(int i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { - this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 98 + i * 18)); + this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 129 + i * 18)); } } for(int i = 0; i < 9; i++) { - this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 156)); + this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 187)); } } @@ -52,7 +53,7 @@ public class ContainerToolBox extends Container { } if(var5.stackSize == 0) { - var4.putStack((ItemStack) null); + var4.putStack(null); } else { var4.onSlotChanged(); } diff --git a/src/main/java/com/hbm/inventory/gui/GUIToolBox.java b/src/main/java/com/hbm/inventory/gui/GUIToolBox.java index 1aedd6395..d00282f56 100644 --- a/src/main/java/com/hbm/inventory/gui/GUIToolBox.java +++ b/src/main/java/com/hbm/inventory/gui/GUIToolBox.java @@ -1,8 +1,6 @@ package com.hbm.inventory.gui; -import com.hbm.inventory.container.ContainerLeadBox; import com.hbm.inventory.container.ContainerToolBox; -import com.hbm.items.tool.ItemLeadBox.InventoryLeadBox; import com.hbm.lib.RefStrings; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; @@ -16,7 +14,7 @@ import static com.hbm.items.tool.ItemToolBox.*; public class GUIToolBox extends GuiContainer { - private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_toolbox.png"); + private final static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_toolbox.png"); private final InventoryToolBox inventory; private ItemStack firstHeld; @@ -25,7 +23,7 @@ public class GUIToolBox extends GuiContainer { this.inventory = box; this.xSize = 176; - this.ySize = 186; + this.ySize = 211; } @Override @@ -52,8 +50,8 @@ public class GUIToolBox extends GuiContainer { name = inventory.target.getDisplayName(); } - this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752); - this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 102 + 2, 4210752); + this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 37, 4210752); + this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); } @Override diff --git a/src/main/java/com/hbm/items/tool/ItemToolBox.java b/src/main/java/com/hbm/items/tool/ItemToolBox.java index a378c6cd8..e44cb5810 100644 --- a/src/main/java/com/hbm/items/tool/ItemToolBox.java +++ b/src/main/java/com/hbm/items/tool/ItemToolBox.java @@ -7,12 +7,10 @@ import com.hbm.items.ModItems; import com.hbm.lib.RefStrings; import com.hbm.main.MainRegistry; import com.hbm.tileentity.IGUIProvider; -import com.hbm.util.ChatBuilder; import com.hbm.util.ItemStackUtil; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.Item; @@ -23,7 +21,6 @@ import net.minecraft.world.World; import java.util.ArrayList; import java.util.List; -import java.util.Random; public class ItemToolBox extends Item implements IGUIProvider { @@ -56,6 +53,7 @@ public class ItemToolBox extends Item implements IGUIProvider { return renderPass == 1 ? this.iconClosed : getIconFromDamageForRenderPass(stack.getItemDamage(), renderPass); } + // Finds active rows in the toolbox (rows with items inside them). public List getActiveRows(ItemStack box) { ItemStack[] stacks = ItemStackUtil.readStacksFromNBT(box, 24); if(stacks == null) @@ -110,14 +108,24 @@ public class ItemToolBox extends Item implements IGUIProvider { ItemStack[] stacks = ItemStackUtil.readStacksFromNBT(box, 24); ItemStack[] endingStacks = new ItemStack[24]; + int lowestActiveIndex = Integer.MAX_VALUE; // Lowest active index to find which row to move *to* the hotbar. + int lowestInactiveIndex = Integer.MAX_VALUE; // Lowest *inactive* index to find which row to move the hotbar to. + if(stacks != null) { List activeRows = getActiveRows(box); - int lowestIndex = Integer.MAX_VALUE; - { // Finding the lowest active row to decide what row to move to the hotbar. - for (Integer activeRowIndex : activeRows) { - lowestIndex = Math.min(activeRowIndex, lowestIndex); + { // despair + for (int i = 0; i < 3; i++) { + if(activeRows.contains(i)) + lowestActiveIndex = Math.min(i, lowestActiveIndex); + else + lowestInactiveIndex = Math.min(i, lowestInactiveIndex); } + + if(lowestInactiveIndex > 2) // No inactive rows... + lowestInactiveIndex = 2; // Set to the last possible row; the items will be moved out of the way in time. + else + lowestInactiveIndex = Math.max(0, lowestInactiveIndex - 1); // A little shittery to make items pop into the row that's *going* to be empty. } // This entire section sucks, but honestly it's not actually that bad; it works so.... @@ -125,7 +133,7 @@ public class ItemToolBox extends Item implements IGUIProvider { int activeIndex = 8 * activeRowIndex; - if (activeRowIndex == lowestIndex) { // Items to "flow" to the hotbar. + if (activeRowIndex == lowestActiveIndex) { // Items to "flow" to the hotbar. hasToolbox = false; for (int i = 0; i < 9; i++) { if(i == player.inventory.currentItem) { @@ -144,7 +152,7 @@ public class ItemToolBox extends Item implements IGUIProvider { } // Finally, move all temporary arrays into their respective locations. - System.arraycopy(stacksToTransferToBox, 0, endingStacks, 16, 8); + System.arraycopy(stacksToTransferToBox, 0, endingStacks, lowestInactiveIndex * 8, 8); for (int i = 0; i < endingHotBar.length; i++) { player.inventory.setInventorySlotContents(i, endingHotBar[i]); @@ -223,5 +231,10 @@ public class ItemToolBox extends Item implements IGUIProvider { this.player.inventory.setInventorySlotContents(this.player.inventory.currentItem, this.target); super.closeInventory(); } + + @Override + public boolean isItemValidForSlot(int slot, ItemStack stack) { + return stack.getItem() != ModItems.toolbox; + } } } diff --git a/src/main/resources/assets/hbm/textures/gui/gui_toolbox.png b/src/main/resources/assets/hbm/textures/gui/gui_toolbox.png index 285c78101cec9bd2c09640359806b7f0e9b5c317..c73cc5b014cbf33f267183752cf59a0bb0339b6a 100644 GIT binary patch delta 1598 zcmV-E2EqCF3fvEnNq@os01m% zaFxO!P-WZ+)TvROR3RV)Y7)}hpi0C9HLl$VyD+G7Fr<*cDU!ygUm;PwS)p#DfxIE~0${K6HquvM(M2K^I4Nk?b1uLl5}b*;#$m&FSfBeRLSR z0wD}swAhQ`5QE-#h^I0p9>Tyyi#h4dfgdvHOBwL7h6JJ+20_R$>yvzO==%(O%Aohv zCkz*ZAO^>4R(~h9@4NgQ2K~j07xmFF*RNl%kEXLP4DJq&*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