11package gregtech .api .items .toolitem ;
22
33import gregtech .api .GregTechAPI ;
4+ import gregtech .api .capability .GregtechCapabilities ;
45import gregtech .api .items .IDyeableItem ;
56import gregtech .api .items .gui .ItemUIFactory ;
67import gregtech .api .items .toolitem .behavior .IToolBehavior ;
@@ -420,8 +421,7 @@ public boolean supportsTool(ItemStack stack, ItemStack tool) {
420421 }
421422
422423 private ToolStackHandler getHandler (ItemStack stack ) {
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 );
424+ IItemHandler handler = stack .getCapability (GregtechCapabilities .CAPABILITY_TOOLBELT_HANDLER , null );
425425 if (handler instanceof ToolStackHandler h ) return h ;
426426 else return FALLBACK ;
427427 }
@@ -569,6 +569,8 @@ public ToolbeltCapabilityProvider(ItemStack stack) {
569569
570570 @ Override
571571 public boolean hasCapability (@ NotNull Capability <?> capability , EnumFacing facing ) {
572+ if (capability == GregtechCapabilities .CAPABILITY_TOOLBELT_HANDLER )
573+ return true ;
572574 ItemStack selected = getHandler ().getSelectedStack ();
573575 if (!selected .isEmpty () && facing != EnumFacing .UP ) {
574576 return selected .hasCapability (capability , facing );
@@ -577,12 +579,15 @@ public boolean hasCapability(@NotNull Capability<?> capability, EnumFacing facin
577579
578580 @ Override
579581 public <T > T getCapability (@ NotNull Capability <T > capability , EnumFacing facing ) {
582+ if (capability == GregtechCapabilities .CAPABILITY_TOOLBELT_HANDLER )
583+ return GregtechCapabilities .CAPABILITY_TOOLBELT_HANDLER .cast (this .getHandler ());
580584 ItemStack selected = getHandler ().getSelectedStack ();
581- if (!selected .isEmpty () && facing != EnumFacing . UP ) {
585+ if (!selected .isEmpty ()) {
582586 return selected .getCapability (capability , facing );
583- } else if (capability == CapabilityItemHandler .ITEM_HANDLER_CAPABILITY )
587+ } else if (capability == CapabilityItemHandler .ITEM_HANDLER_CAPABILITY ) {
588+ // if nothing is selected, expose the handler under the item handler capability
584589 return CapabilityItemHandler .ITEM_HANDLER_CAPABILITY .cast (this .getHandler ());
585- else return null ;
590+ } else return null ;
586591 }
587592
588593 @ Override
@@ -622,7 +627,7 @@ public void readNBTShareTag(ItemStack stack, NBTTagCompound nbt) {
622627
623628 protected static final ToolStackHandler FALLBACK = new ToolStackHandler (0 );
624629
625- protected static class ToolStackHandler extends ItemStackHandler {
630+ public static class ToolStackHandler extends ItemStackHandler {
626631
627632 private static final Set <String > EMPTY = ImmutableSet .of ();
628633
0 commit comments