Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,6 +23,9 @@ public class GregtechCapabilities {
@CapabilityInject(IElectricItem.class)
public static Capability<IElectricItem> CAPABILITY_ELECTRIC_ITEM = null;

@CapabilityInject(ItemGTToolbelt.ToolStackHandler.class)
public static Capability<ItemGTToolbelt.ToolStackHandler> CAPABILITY_TOOLBELT_HANDLER = null;

@CapabilityInject(IMultiblockController.class)
public static Capability<IMultiblockController> CAPABILITY_MULTIBLOCK_CONTROLLER = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,6 +38,7 @@ public void readNBT(Capability<T> 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);
Expand Down
34 changes: 23 additions & 11 deletions src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -141,8 +142,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();
}

Expand Down Expand Up @@ -265,7 +266,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);
Expand Down Expand Up @@ -420,7 +421,7 @@ public boolean supportsTool(ItemStack stack, ItemStack tool) {
}

private ToolStackHandler getHandler(ItemStack stack) {
IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
IItemHandler handler = stack.getCapability(GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER, null);
if (handler instanceof ToolStackHandler h) return h;
else return FALLBACK;
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -569,14 +569,25 @@ public ToolbeltCapabilityProvider(ItemStack stack) {

@Override
public boolean hasCapability(@NotNull Capability<?> capability, EnumFacing facing) {
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
if (capability == GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER)
return true;
ItemStack selected = getHandler().getSelectedStack();
if (!selected.isEmpty()) {
return selected.hasCapability(capability, facing);
} else return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;
}

@Override
public <T> T getCapability(@NotNull Capability<T> capability, EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
if (capability == GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER)
return GregtechCapabilities.CAPABILITY_TOOLBELT_HANDLER.cast(this.getHandler());
ItemStack selected = getHandler().getSelectedStack();
if (!selected.isEmpty()) {
return selected.getCapability(capability, facing);
} 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
Expand Down Expand Up @@ -616,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<String> EMPTY = ImmutableSet.of();

Expand Down Expand Up @@ -646,7 +657,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() {
Expand Down
Loading