Skip to content

Commit ab568fb

Browse files
committed
block slot with current item from interaction in test item
1 parent 9d6f77d commit ab568fb

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/main/java/com/cleanroommc/modularui/test/TestItem.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.cleanroommc.modularui.api.IGuiHolder;
66
import com.cleanroommc.modularui.factory.GuiFactories;
77
import com.cleanroommc.modularui.factory.PlayerInventoryGuiData;
8+
import com.cleanroommc.modularui.factory.inventory.InventoryTypes;
89
import com.cleanroommc.modularui.screen.ModularPanel;
910
import com.cleanroommc.modularui.screen.UISettings;
1011
import com.cleanroommc.modularui.utils.Alignment;
@@ -17,6 +18,7 @@
1718
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
1819
import com.cleanroommc.modularui.widgets.layout.Column;
1920
import com.cleanroommc.modularui.widgets.slot.ItemSlot;
21+
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
2022

2123
import net.minecraft.client.util.ITooltipFlag;
2224
import net.minecraft.entity.player.EntityPlayer;
@@ -52,6 +54,14 @@ public ModularPanel buildUI(PlayerInventoryGuiData guiData, PanelSyncManager gui
5254
IItemHandlerModifiable itemHandler = (IItemHandlerModifiable) guiData.getUsedItemStack().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
5355
guiSyncManager.registerSlotGroup("mixer_items", 2);
5456

57+
// if the player slot is the slot with this item, then disallow any interaction
58+
// if the item is not in the player inventory (bauble for example), then this items slot is not on the screen, and we don't need to
59+
// accessibility
60+
if (guiData.getInventoryType() == InventoryTypes.PLAYER) {
61+
guiSyncManager.bindPlayerInventory(guiData.getPlayer(), (inv, index) -> index == guiData.getSlotIndex() ?
62+
new ModularSlot(inv, index).accessibility(false, false) :
63+
new ModularSlot(inv, index));
64+
}
5565
ModularPanel panel = ModularPanel.defaultPanel("knapping_gui").resizeableOnDrag(true);
5666
panel.child(new Column().margin(7)
5767
.child(new ParentWidget<>().widthRel(1f).expanded()
@@ -61,6 +71,8 @@ public ModularPanel buildUI(PlayerInventoryGuiData guiData, PanelSyncManager gui
6171
.key('I', index -> new ItemSlot().slot(SyncHandlers.itemSlot(itemHandler, index)
6272
.ignoreMaxStackSize(true)
6373
.slotGroup("mixer_items")
74+
// do not allow putting items which can hold other items into the item
75+
// some mods don't do this on their backpacks, so it won't catch those cases
6476
.filter(stack -> !stack.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))))
6577
.build()
6678
.align(Alignment.Center)))

src/main/java/com/cleanroommc/modularui/widgets/SlotGroupWidget.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.cleanroommc.modularui.api.widget.ISynced;
44
import com.cleanroommc.modularui.api.widget.IWidget;
55
import com.cleanroommc.modularui.widget.ParentWidget;
6-
76
import com.cleanroommc.modularui.widgets.slot.ItemSlot;
87

98
import it.unimi.dsi.fastutil.chars.Char2IntMap;
@@ -33,11 +32,11 @@ public static SlotGroupWidget playerInventory(int bottom, boolean horizontalCent
3332
return widget;
3433
}
3534

36-
/**
37-
* Automatically creates and places the player inventory.
38-
*
39-
* @return player inventory group
40-
*/
35+
/**
36+
* Automatically creates and places the player inventory.
37+
*
38+
* @return player inventory group
39+
*/
4140
public static SlotGroupWidget playerInventory(SlotConsumer slotConsumer) {
4241
SlotGroupWidget slotGroupWidget = new SlotGroupWidget();
4342
slotGroupWidget.coverChildren();
@@ -59,7 +58,8 @@ public static SlotGroupWidget playerInventory(SlotConsumer slotConsumer) {
5958
}
6059

6160
public interface SlotConsumer {
62-
ItemSlot apply(int index, ItemSlot slot);
61+
62+
ItemSlot apply(int index, ItemSlot widgetSlot);
6363
}
6464

6565
private String slotsKeyName;

0 commit comments

Comments
 (0)