1- package net .gompk .pockets .mixin ;
1+ /* package net.gompk.pockets.mixin;
22
33import net.gompk.pockets.Pockets;
4+ import net.gompk.pockets.mixin.accessor.ScreenHandlerAccessor;
45import net.minecraft.entity.player.PlayerEntity;
56import net.minecraft.entity.player.PlayerInventory;
67import net.minecraft.screen.PlayerScreenHandler;
@@ -42,7 +43,7 @@ private void addExtraInventoryRows(PlayerInventory inventory, boolean onServer,
4243
4344 // Add extra slots between main inventory (Y: 54) and hotbar (now at Y: 94)
4445 // Position them at Y: 72 to be visually between the main inventory and hotbar
45- int startIndex = 45 ; // Use indices 45-53 to avoid conflicts with armor/offhand slots
46+ int startIndex = 36 ; // Use indices 45-53 to avoid conflicts with armor/offhand slots
4647 int y = 72;
4748
4849 for (int x = 0; x < 9; x++) {
@@ -54,4 +55,135 @@ private void addExtraInventoryRows(PlayerInventory inventory, boolean onServer,
5455 addingExtraSlots = false;
5556 Pockets.LOGGER.info("POCKETS DEBUG: Extra row added successfully");
5657 }
58+
59+
60+ }
61+
62+ package net.gompk.pockets.mixin;
63+
64+ import net.gompk.pockets.Pockets;
65+ import net.gompk.pockets.mixin.accessor.ScreenHandlerAccessor;
66+ import net.minecraft.entity.player.PlayerEntity;
67+ import net.minecraft.entity.player.PlayerInventory;
68+ import net.minecraft.screen.PlayerScreenHandler;
69+ import net.minecraft.screen.slot.Slot;
70+ import net.minecraft.item.ItemStack;
71+ import org.spongepowered.asm.mixin.Mixin;
72+ import org.spongepowered.asm.mixin.injection.At;
73+ import org.spongepowered.asm.mixin.injection.Inject;
74+ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
75+
76+ @Mixin(PlayerScreenHandler.class)
77+ public abstract class PlayerScreenHandlerMixin {
78+
79+ @Inject(method = "<init>", at = @At("TAIL"))
80+ private void addExtraSlots(PlayerInventory inventory, boolean onServer, PlayerEntity owner, CallbackInfo ci) {
81+ addExtraInventoryRows(inventory, Pockets.extraInventoryRows);
82+ }
83+
84+ private void addExtraInventoryRows(PlayerInventory inventory, int rowCount) {
85+ if (rowCount <= 0) return;
86+
87+ // Standard vanilla slot positions
88+ int mainInvStartY = 54;
89+ int slotWidth = 18;
90+ int invStartX = 8;
91+
92+ int startY = mainInvStartY + (3 * slotWidth); // Start after main inventory
93+ int nextAvailableIndex = 41; // Start at 41 to avoid vanilla conflicts
94+
95+ for (int row = 0; row < rowCount; row++) {
96+ int y = startY + (row * slotWidth);
97+ addSingleRow(inventory, nextAvailableIndex + (row * 9), y, invStartX, slotWidth);
98+ }
99+
100+ Pockets.LOGGER.info("Added {} extra inventory rows", rowCount);
101+ }
102+
103+ private void addSingleRow(PlayerInventory inventory, int startIndex, int y, int startX, int slotWidth) {
104+ for (int col = 0; col < 9; col++) {
105+ int x = startX + (col * slotWidth);
106+ int slotIndex = startIndex + col;
107+
108+ Slot slot = createExtraSlot(inventory, slotIndex, x, y);
109+ ((ScreenHandlerAccessor)this).invokeAddSlot(slot);
110+ }
111+ }
112+
113+ private Slot createExtraSlot(PlayerInventory inventory, int index, int x, int y) {
114+ return new Slot(inventory, index, x, y) {
115+ @Override
116+ public boolean canInsert(ItemStack stack) {
117+ return true; // Allow all items in extra slots
118+ }
119+
120+ @Override
121+ public boolean canTakeItems(PlayerEntity player) {
122+ return true;
123+ }
124+ };
125+ }
126+ }
127+
128+ */
129+
130+ package net .gompk .pockets .mixin ;
131+
132+ import net .gompk .pockets .Pockets ;
133+ import net .gompk .pockets .mixin .accessor .ScreenHandlerAccessor ;
134+ import net .minecraft .entity .player .PlayerEntity ;
135+ import net .minecraft .entity .player .PlayerInventory ;
136+ import net .minecraft .screen .PlayerScreenHandler ;
137+ import net .minecraft .screen .slot .Slot ;
138+ import net .minecraft .item .ItemStack ;
139+ import org .spongepowered .asm .mixin .Mixin ;
140+ import org .spongepowered .asm .mixin .injection .At ;
141+ import org .spongepowered .asm .mixin .injection .Inject ;
142+ import org .spongepowered .asm .mixin .injection .Redirect ;
143+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
144+
145+ @ Mixin (PlayerScreenHandler .class )
146+ public abstract class PlayerScreenHandlerMixin {
147+
148+ // Redirect addSlot to move hotbar down when adding it
149+ @ Redirect (method = "<init>" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/screen/PlayerScreenHandler;addSlot(Lnet/minecraft/screen/slot/Slot;)Lnet/minecraft/screen/slot/Slot;" ))
150+ private Slot moveHotbarSlots (PlayerScreenHandler instance , Slot slot ) {
151+ if (slot .inventory instanceof PlayerInventory ) {
152+ int index = slot .getIndex ();
153+ // Move hotbar slots (0-8) down by 18px per extra row
154+ if (index >= 0 && index <= 8 ) {
155+ int yOffset = Pockets .extraInventoryRows * 18 ;
156+ slot = new Slot (slot .inventory , index , slot .x , slot .y + yOffset );
157+ }
158+ }
159+ return ((ScreenHandlerAccessor )instance ).invokeAddSlot (slot );
160+ }
161+
162+ @ Inject (method = "<init>" , at = @ At ("TAIL" ))
163+ private void addExtraSlots (PlayerInventory inventory , boolean onServer , PlayerEntity owner , CallbackInfo ci ) {
164+ if (Pockets .extraInventoryRows <= 0 ) return ;
165+
166+ int startY = 54 + (3 * 18 ); // After main inventory
167+ int startIndex = 36 ; // Start after main inventory (0-35)
168+
169+ for (int row = 0 ; row < Pockets .extraInventoryRows ; row ++) {
170+ for (int col = 0 ; col < 9 ; col ++) {
171+ int x = 8 + (col * 18 );
172+ int y = startY + (row * 18 );
173+ int index = startIndex + (row * 9 ) + col ;
174+
175+ Slot extraSlot = new Slot (inventory , index , x , y ) {
176+ @ Override
177+ public boolean canInsert (ItemStack stack ) {
178+ return true ;
179+ }
180+ };
181+
182+ ((ScreenHandlerAccessor )this ).invokeAddSlot (extraSlot );
183+ }
184+ }
185+
186+ Pockets .LOGGER .info ("POCKETS: Added {} extra rows with {} total slots" ,
187+ Pockets .extraInventoryRows , Pockets .extraInventoryRows * 9 );
188+ }
57189}
0 commit comments