Skip to content

Commit a7cd76b

Browse files
committed
feat: custom button definitions for vanilla containers
1 parent 34bd84e commit a7cd76b

9 files changed

Lines changed: 82 additions & 30 deletions

File tree

common/src/client/java/io/github/jamalam360/sort_it_out/client/SortItOutClient.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.minecraft.client.multiplayer.ClientLevel;
2828
import net.minecraft.core.registries.BuiltInRegistries;
2929
import net.minecraft.network.chat.Component;
30+
import net.minecraft.resources.ResourceLocation;
3031
import net.minecraft.server.packs.PackType;
3132
import net.minecraft.world.inventory.AbstractContainerMenu;
3233
import net.minecraft.world.inventory.Slot;
@@ -114,7 +115,16 @@ private static void renderContainerForeground(AbstractContainerScreen<?> screen,
114115
}
115116

116117
if (isSlotIndexOverlayEnabled) {
117-
graphics.drawCenteredString(Minecraft.getInstance().font, "" + BuiltInRegistries.MENU.getKey(screen.getMenu().getType()), Minecraft.getInstance().getWindow().getGuiScaledWidth() / 2, 5, 0xFFFFFF);
118+
ResourceLocation type;
119+
120+
try {
121+
type = BuiltInRegistries.MENU.getKey(screen.getMenu().getType());
122+
} catch (UnsupportedOperationException e) {
123+
type = null;
124+
}
125+
126+
graphics.drawCenteredString(Minecraft.getInstance().font, "" + type, ((AbstractContainerScreenAccessor) screen).getImageWidth() / 2, -50, 0xFFFFFF);
127+
graphics.drawCenteredString(Minecraft.getInstance().font, screen.getClass().getName(), ((AbstractContainerScreenAccessor) screen).getImageWidth() / 2, -40, 0xFFFFFF);
118128

119129
for (Slot slot : screen.getMenu().slots) {
120130
graphics.drawString(Minecraft.getInstance().font, "" + slot.index, slot.x, slot.y, 0xFFFFFF);

common/src/client/java/io/github/jamalam360/sort_it_out/client/gui/SortButton.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
import io.github.jamalam360.sort_it_out.SortItOut;
44
import io.github.jamalam360.sort_it_out.client.ClientPacketWorkQueue;
5-
import io.github.jamalam360.sort_it_out.client.ClientSortableContainer;
65
import io.github.jamalam360.sort_it_out.client.SortItOutClient;
76
import io.github.jamalam360.sort_it_out.client.mixinsupport.MutableSpriteSpriteIconButton;
8-
import io.github.jamalam360.sort_it_out.sort.ContainerSorterUtil;
97
import net.minecraft.client.gui.GuiGraphics;
108
import net.minecraft.client.gui.components.Button;
119
import net.minecraft.client.gui.components.SpriteIconButton;
1210
import net.minecraft.network.chat.Component;
1311
import net.minecraft.resources.ResourceLocation;
14-
import net.minecraft.world.Container;
1512
import net.minecraft.world.inventory.AbstractContainerMenu;
1613
import net.minecraft.world.inventory.Slot;
1714

common/src/client/java/io/github/jamalam360/sort_it_out/client/mixin/AbstractContainerScreenMixin.java

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
1212
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
1313
import net.minecraft.network.chat.Component;
14+
import net.minecraft.world.entity.player.Inventory;
1415
import net.minecraft.world.inventory.AbstractContainerMenu;
1516
import net.minecraft.world.inventory.ClickType;
1617
import net.minecraft.world.inventory.Slot;
@@ -55,32 +56,21 @@ protected AbstractContainerScreenMixin(Component title) {
5556
for (ScreenSortButton button : customButtons) {
5657
this.addRenderableWidget(new SortButton(this.leftPos + button.xOffset(), this.topPos + button.yOffset(), this.menu, this.menu.slots.get(button.slotStartIndex())));
5758
}
58-
}
59+
} else {
60+
// If custom sort buttons defs. are not present, at least guess where the player inventory sort button should be
61+
Slot invSlot = null;
62+
63+
for (Slot slot : this.menu.slots) {
64+
if (slot.container instanceof Inventory) {
65+
invSlot = slot;
66+
break;
67+
}
68+
}
5969

60-
// Slot mainContainer = null;
61-
// Slot invContainer = null;
62-
//
63-
// for (Slot slot : this.menu.slots) {
64-
// if (slot.container instanceof Inventory) {
65-
// invContainer = slot;
66-
// } else if (mainContainer == null) {
67-
// mainContainer = slot;
68-
// }
69-
//
70-
// if (mainContainer != null && invContainer != null) {
71-
// break;
72-
// }
73-
// }
74-
//
75-
// int x = (this.leftPos + this.imageWidth) - 19;
76-
//
77-
// if (mainContainer != null) {
78-
// this.addRenderableWidget(new SortButton(x, this.topPos + 5, this.menu, mainContainer));
79-
// }
80-
//
81-
// if (invContainer != null) {
82-
// this.addRenderableWidget(new SortButton(x, this.topPos + 72, this.menu, invContainer));
83-
// }
70+
if (invSlot != null) {
71+
this.addRenderableWidget(new SortButton(this.leftPos + 158, this.topPos + 71, this.menu, invSlot));
72+
}
73+
}
8474
}
8575

8676
@Inject(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "minecraft:generic_3x3",
3+
"sortButtons": [
4+
{
5+
"xOffset": 116,
6+
"yOffset": 16,
7+
"slotStartIndex": 0
8+
},
9+
{
10+
"xOffset": 158,
11+
"yOffset": 71,
12+
"slotStartIndex": 9
13+
}
14+
]
15+
}

common/src/main/resources/assets/sort_it_out/sort_buttons/generic_9x3.json renamed to common/src/main/resources/assets/sort_it_out/sort_buttons/minecraft/generic_9x3.json

File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "minecraft:hopper",
3+
"sortButtons": [
4+
{
5+
"xOffset": 134,
6+
"yOffset": 19,
7+
"slotStartIndex": 0
8+
},
9+
{
10+
"xOffset": 158,
11+
"yOffset": 38,
12+
"slotStartIndex": 5
13+
}
14+
]
15+
}

common/src/main/resources/assets/sort_it_out/sort_buttons/inventory_screen.json renamed to common/src/main/resources/assets/sort_it_out/sort_buttons/minecraft/inventory.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"xOffset": 158,
66
"yOffset": 68,
7-
"slotStartIndex": 27
7+
"slotStartIndex": 9
88
}
99
]
1010
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "minecraft:loom",
3+
"sortButtons": [
4+
{
5+
"xOffset": 121,
6+
"yOffset": 71,
7+
"slotStartIndex": 4
8+
}
9+
]
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "minecraft:shulker_box",
3+
"sortButtons": [
4+
{
5+
"xOffset": 158,
6+
"yOffset": 5,
7+
"slotStartIndex": 0
8+
},
9+
{
10+
"xOffset": 158,
11+
"yOffset": 71,
12+
"slotStartIndex": 27
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)