Skip to content

Commit 5eacd29

Browse files
committed
Toolbelt capability passthrough
1 parent c214f00 commit 5eacd29

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager
141141
(newItem, onlyAmountChanged, client, init) -> handler
142142
.onContentsChanged(index)))
143143
.background(GTGuiTextures.SLOT, GTGuiTextures.TOOL_SLOT_OVERLAY)
144-
.debugName("slot_" + index))
145-
.debugName("toolbelt_inventory"))
144+
.name("slot_" + index))
145+
.name("toolbelt_inventory"))
146146
.bindPlayerInventory();
147147
}
148148

@@ -265,7 +265,7 @@ public boolean shouldCauseReequipAnimation(@NotNull ItemStack oldStack, @NotNull
265265
}
266266

267267
@Override
268-
public int getMetadata(ItemStack stack) {
268+
public int getMetadata(@NotNull ItemStack stack) {
269269
ItemStack selected = getHandler(stack).getSelectedStack();
270270
if (!selected.isEmpty()) {
271271
return selected.getItem().getMetadata(selected);
@@ -420,7 +420,8 @@ public boolean supportsTool(ItemStack stack, ItemStack tool) {
420420
}
421421

422422
private ToolStackHandler getHandler(ItemStack stack) {
423-
IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
423+
// use the very rarely used sidedness of item capabilities to signal that we want to ignore passthrough
424+
IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
424425
if (handler instanceof ToolStackHandler h) return h;
425426
else return FALLBACK;
426427
}
@@ -441,8 +442,7 @@ public void changeSelectedToolMousewheel(int direction, ItemStack stack) {
441442
@SideOnly(Side.CLIENT)
442443
public void changeSelectedToolHotkey(int slot, ItemStack stack) {
443444
ToolStackHandler handler = getHandler(stack);
444-
if (slot < 0 || slot >= handler.getSlots()) handler.selectedSlot = -1;
445-
else handler.selectedSlot = slot;
445+
handler.setSelectedSlot(slot);
446446
PacketToolbeltSelectionChange.toServer(handler.selectedSlot);
447447
}
448448

@@ -569,12 +569,18 @@ public ToolbeltCapabilityProvider(ItemStack stack) {
569569

570570
@Override
571571
public boolean hasCapability(@NotNull Capability<?> capability, EnumFacing facing) {
572-
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
572+
ItemStack selected = getHandler().getSelectedStack();
573+
if (!selected.isEmpty() && facing != EnumFacing.UP) {
574+
return selected.hasCapability(capability, facing);
575+
} else return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
573576
}
574577

575578
@Override
576579
public <T> T getCapability(@NotNull Capability<T> capability, EnumFacing facing) {
577-
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
580+
ItemStack selected = getHandler().getSelectedStack();
581+
if (!selected.isEmpty() && facing != EnumFacing.UP) {
582+
return selected.getCapability(capability, facing);
583+
} else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
578584
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.getHandler());
579585
else return null;
580586
}
@@ -646,7 +652,8 @@ public int getSelectedSlot() {
646652
}
647653

648654
public void setSelectedSlot(int selectedSlot) {
649-
this.selectedSlot = Math.min(getSlots() - 1, Math.max(selectedSlot, -1));
655+
if (selectedSlot >= getSlots() || selectedSlot < 0) this.selectedSlot = -1;
656+
else this.selectedSlot = selectedSlot;
650657
}
651658

652659
public void enablePassthrough() {

0 commit comments

Comments
 (0)