From 5eacd29b71c750f08f07eac64b27f7ab1f737fb2 Mon Sep 17 00:00:00 2001 From: M-W-K <31022105+M-W-K@users.noreply.github.com> Date: Tue, 9 Dec 2025 08:59:52 -0700 Subject: [PATCH 1/3] Toolbelt capability passthrough --- .../api/items/toolitem/ItemGTToolbelt.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java b/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java index b8fd6434292..a06c0bbba82 100644 --- a/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java +++ b/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java @@ -141,8 +141,8 @@ public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager (newItem, onlyAmountChanged, client, init) -> handler .onContentsChanged(index))) .background(GTGuiTextures.SLOT, GTGuiTextures.TOOL_SLOT_OVERLAY) - .debugName("slot_" + index)) - .debugName("toolbelt_inventory")) + .name("slot_" + index)) + .name("toolbelt_inventory")) .bindPlayerInventory(); } @@ -265,7 +265,7 @@ public boolean shouldCauseReequipAnimation(@NotNull ItemStack oldStack, @NotNull } @Override - public int getMetadata(ItemStack stack) { + public int getMetadata(@NotNull ItemStack stack) { ItemStack selected = getHandler(stack).getSelectedStack(); if (!selected.isEmpty()) { return selected.getItem().getMetadata(selected); @@ -420,7 +420,8 @@ public boolean supportsTool(ItemStack stack, ItemStack tool) { } private ToolStackHandler getHandler(ItemStack stack) { - IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); + // use the very rarely used sidedness of item capabilities to signal that we want to ignore passthrough + IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); if (handler instanceof ToolStackHandler h) return h; else return FALLBACK; } @@ -441,8 +442,7 @@ public void changeSelectedToolMousewheel(int direction, ItemStack stack) { @SideOnly(Side.CLIENT) public void changeSelectedToolHotkey(int slot, ItemStack stack) { ToolStackHandler handler = getHandler(stack); - if (slot < 0 || slot >= handler.getSlots()) handler.selectedSlot = -1; - else handler.selectedSlot = slot; + handler.setSelectedSlot(slot); PacketToolbeltSelectionChange.toServer(handler.selectedSlot); } @@ -569,12 +569,18 @@ public ToolbeltCapabilityProvider(ItemStack stack) { @Override public boolean hasCapability(@NotNull Capability capability, EnumFacing facing) { - return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY; + ItemStack selected = getHandler().getSelectedStack(); + if (!selected.isEmpty() && facing != EnumFacing.UP) { + return selected.hasCapability(capability, facing); + } else return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY; } @Override public T getCapability(@NotNull Capability capability, EnumFacing facing) { - if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) + ItemStack selected = getHandler().getSelectedStack(); + if (!selected.isEmpty() && facing != EnumFacing.UP) { + return selected.getCapability(capability, facing); + } else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.getHandler()); else return null; } @@ -646,7 +652,8 @@ public int getSelectedSlot() { } public void setSelectedSlot(int selectedSlot) { - this.selectedSlot = Math.min(getSlots() - 1, Math.max(selectedSlot, -1)); + if (selectedSlot >= getSlots() || selectedSlot < 0) this.selectedSlot = -1; + else this.selectedSlot = selectedSlot; } public void enablePassthrough() { From b458724cddd55fa948334591b3b9bbd02177021f Mon Sep 17 00:00:00 2001 From: M-W-K <31022105+M-W-K@users.noreply.github.com> Date: Thu, 11 Dec 2025 00:12:35 -0700 Subject: [PATCH 2/3] Move toolbelt container to unique capability --- .../api/capability/GregtechCapabilities.java | 4 ++++ .../api/capability/SimpleCapabilityManager.java | 2 ++ .../api/items/toolitem/ItemGTToolbelt.java | 17 +++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/api/capability/GregtechCapabilities.java b/src/main/java/gregtech/api/capability/GregtechCapabilities.java index df163402aeb..8d6bc2c799f 100644 --- a/src/main/java/gregtech/api/capability/GregtechCapabilities.java +++ b/src/main/java/gregtech/api/capability/GregtechCapabilities.java @@ -2,6 +2,7 @@ import gregtech.api.GTValues; import gregtech.api.capability.impl.EUToFEProvider; +import gregtech.api.items.toolitem.ItemGTToolbelt; import gregtech.api.util.GTUtility; import gregtech.common.metatileentities.converter.ConverterTrait; @@ -22,6 +23,9 @@ public class GregtechCapabilities { @CapabilityInject(IElectricItem.class) public static Capability CAPABILITY_ELECTRIC_ITEM = null; + @CapabilityInject(ItemGTToolbelt.ToolStackHandler.class) + public static Capability CAPABILITY_TOOLBELT_HANDLER = null; + @CapabilityInject(IMultiblockController.class) public static Capability CAPABILITY_MULTIBLOCK_CONTROLLER = null; diff --git a/src/main/java/gregtech/api/capability/SimpleCapabilityManager.java b/src/main/java/gregtech/api/capability/SimpleCapabilityManager.java index f517b473bab..9532b4e361c 100644 --- a/src/main/java/gregtech/api/capability/SimpleCapabilityManager.java +++ b/src/main/java/gregtech/api/capability/SimpleCapabilityManager.java @@ -2,6 +2,7 @@ import gregtech.api.capability.impl.AbstractRecipeLogic; import gregtech.api.cover.CoverHolder; +import gregtech.api.items.toolitem.ItemGTToolbelt; import gregtech.api.metatileentity.multiblock.IMaintenance; import gregtech.api.worldgen.generator.GTWorldGenCapability; import gregtech.common.metatileentities.converter.ConverterTrait; @@ -37,6 +38,7 @@ public void readNBT(Capability capability, T instance, EnumFacing side, NBTBa public static void init() { registerCapabilityWithNoDefault(IEnergyContainer.class); registerCapabilityWithNoDefault(IElectricItem.class); + registerCapabilityWithNoDefault(ItemGTToolbelt.ToolStackHandler.class); registerCapabilityWithNoDefault(IWorkable.class); registerCapabilityWithNoDefault(CoverHolder.class); registerCapabilityWithNoDefault(IControllable.class); diff --git a/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java b/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java index a06c0bbba82..b7b278aebc7 100644 --- a/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java +++ b/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java @@ -1,6 +1,7 @@ package gregtech.api.items.toolitem; import gregtech.api.GregTechAPI; +import gregtech.api.capability.GregtechCapabilities; import gregtech.api.items.IDyeableItem; import gregtech.api.items.gui.ItemUIFactory; import gregtech.api.items.toolitem.behavior.IToolBehavior; @@ -420,8 +421,7 @@ public boolean supportsTool(ItemStack stack, ItemStack tool) { } private ToolStackHandler getHandler(ItemStack stack) { - // use the very rarely used sidedness of item capabilities to signal that we want to ignore passthrough - IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); + IItemHandler handler = stack.getCapability(GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER, null); if (handler instanceof ToolStackHandler h) return h; else return FALLBACK; } @@ -569,6 +569,8 @@ public ToolbeltCapabilityProvider(ItemStack stack) { @Override public boolean hasCapability(@NotNull Capability capability, EnumFacing facing) { + if (capability == GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER) + return true; ItemStack selected = getHandler().getSelectedStack(); if (!selected.isEmpty() && facing != EnumFacing.UP) { return selected.hasCapability(capability, facing); @@ -577,12 +579,15 @@ public boolean hasCapability(@NotNull Capability capability, EnumFacing facin @Override public T getCapability(@NotNull Capability capability, EnumFacing facing) { + if (capability == GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER) + return GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER.cast(this.getHandler()); ItemStack selected = getHandler().getSelectedStack(); - if (!selected.isEmpty() && facing != EnumFacing.UP) { + if (!selected.isEmpty()) { return selected.getCapability(capability, facing); - } else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) + } else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { + // if nothing is selected, expose the handler under the item handler capability return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.getHandler()); - else return null; + } else return null; } @Override @@ -622,7 +627,7 @@ public void readNBTShareTag(ItemStack stack, NBTTagCompound nbt) { protected static final ToolStackHandler FALLBACK = new ToolStackHandler(0); - protected static class ToolStackHandler extends ItemStackHandler { + public static class ToolStackHandler extends ItemStackHandler { private static final Set EMPTY = ImmutableSet.of(); From 43297d7a263342352451e3ac3c772b8c504d0ab9 Mon Sep 17 00:00:00 2001 From: M-W-K <31022105+M-W-K@users.noreply.github.com> Date: Thu, 11 Dec 2025 09:43:12 -0700 Subject: [PATCH 3/3] sadness --- src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java b/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java index b7b278aebc7..ca4fb88843c 100644 --- a/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java +++ b/src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java @@ -572,7 +572,7 @@ public boolean hasCapability(@NotNull Capability capability, EnumFacing facin if (capability == GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER) return true; ItemStack selected = getHandler().getSelectedStack(); - if (!selected.isEmpty() && facing != EnumFacing.UP) { + if (!selected.isEmpty()) { return selected.hasCapability(capability, facing); } else return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY; }