Skip to content

Commit eab8b28

Browse files
committed
Extra row working EVEN MORE THAN BEFORE
1 parent c169355 commit eab8b28

16 files changed

Lines changed: 532 additions & 21 deletions

src/main/java/net/gompk/pockets/Pockets.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class Pockets implements ModInitializer {
88
public static final String MOD_ID = "pockets";
9-
9+
public static int extraInventoryRows = 0; // Set this when adding rows
1010
// This logger is used to write text to the console and the log file.
1111
// It is considered best practice to use your mod id as the logger's name.
1212
// That way, it's clear which mod wrote info, warnings, and errors.
@@ -21,3 +21,4 @@ public void onInitialize() {
2121
LOGGER.info("You feel your pants get slightly heavier...");
2222
}
2323
}
24+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.gompk.pockets.mixin;
2+
3+
import net.gompk.pockets.Pockets;
4+
import net.minecraft.entity.player.PlayerInventory;
5+
import net.minecraft.item.ItemStack;
6+
import net.minecraft.screen.slot.Slot;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
11+
12+
@Mixin(Slot.class)
13+
public class ArmorSlotProtectionMixin {
14+
15+
@Inject(method = "canInsert", at = @At("HEAD"), cancellable = true)
16+
private void preventArmorSlotInsertion(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
17+
Slot slot = (Slot)(Object)this;
18+
19+
if (slot.inventory instanceof PlayerInventory) {
20+
int index = slot.getIndex();
21+
22+
// Block insertion into armor slots (36-39)
23+
if (index >= 36 && index <= 39) {
24+
Pockets.LOGGER.info("POCKETS DEBUG: Blocked manual insertion of {} into armor slot {}",
25+
stack.getItem().getName().getString(), index);
26+
cir.setReturnValue(false);
27+
return;
28+
}
29+
}
30+
}
31+
32+
// Allow removal from armor slots - we only want to prevent automatic insertion
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package net.gompk.pockets.mixin;
2+
3+
import net.gompk.pockets.Pockets;
4+
import net.minecraft.entity.player.PlayerInventory;
5+
import net.minecraft.item.ItemStack;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
10+
11+
@Mixin(PlayerInventory.class)
12+
public class ArmorVisualFixMixin {
13+
14+
@Inject(method = "setStack", at = @At("TAIL"))
15+
private void onArmorEquipped(int slot, ItemStack stack, CallbackInfo ci) {
16+
// When armor is equipped in slots 36-39, force a visual update
17+
if (slot >= 36 && slot <= 39) {
18+
Pockets.LOGGER.info("POCKETS DEBUG: Armor equipped in slot {}: {}",
19+
slot, stack.isEmpty() ? "empty" : stack.getItem().getName().getString());
20+
21+
PlayerInventory inventory = (PlayerInventory)(Object)this;
22+
// The visual update will happen automatically through the setStack method
23+
// No additional action needed - just log for debugging
24+
if (inventory.player != null) {
25+
Pockets.LOGGER.info("POCKETS DEBUG: Player equipment updated for {}",
26+
inventory.player.getName().getString());
27+
}
28+
}
29+
}
30+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package net.gompk.pockets.mixin;
2+
3+
import net.gompk.pockets.Pockets;
4+
import net.minecraft.entity.player.PlayerInventory;
5+
import net.minecraft.item.ItemStack;
6+
import net.minecraft.item.ShieldItem;
7+
import net.minecraft.item.Items;
8+
import net.minecraft.entity.EquipmentSlot;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
13+
14+
@Mixin(PlayerInventory.class)
15+
public class EnhancedSlotProtectionMixin {
16+
17+
// Block insertStack method from putting items in protected slots
18+
@Inject(method = "insertStack(Lnet/minecraft/item/ItemStack;)Z", at = @At("HEAD"), cancellable = true)
19+
private void blockInsertStack(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
20+
PlayerInventory inventory = (PlayerInventory)(Object)this;
21+
22+
// Try to insert into allowed slots only
23+
if (insertIntoAllowedSlots(inventory, stack)) {
24+
cir.setReturnValue(true);
25+
} else {
26+
Pockets.LOGGER.info("POCKETS DEBUG: Failed to insert {} - no valid slots available",
27+
stack.getItem().getName().getString());
28+
cir.setReturnValue(false);
29+
}
30+
cir.cancel();
31+
}
32+
33+
// Override getEmptySlot to never return armor/offhand slots for regular items
34+
@Inject(method = "getEmptySlot()I", at = @At("HEAD"), cancellable = true)
35+
private void getEmptySlotProtected(CallbackInfoReturnable<Integer> cir) {
36+
PlayerInventory inventory = (PlayerInventory)(Object)this;
37+
38+
// Check hotbar first (0-8)
39+
for (int i = 0; i <= 8; i++) {
40+
if (inventory.getStack(i).isEmpty()) {
41+
cir.setReturnValue(i);
42+
return;
43+
}
44+
}
45+
46+
// Check main inventory (9-35)
47+
for (int i = 9; i <= 35; i++) {
48+
if (inventory.getStack(i).isEmpty()) {
49+
cir.setReturnValue(i);
50+
return;
51+
}
52+
}
53+
54+
// Check extra slots (45-53) if they exist
55+
for (int i = 45; i <= 53; i++) {
56+
if (i < inventory.size() && inventory.getStack(i).isEmpty()) {
57+
cir.setReturnValue(i);
58+
return;
59+
}
60+
}
61+
62+
// No empty slots found - never return armor/offhand slots (36-40)
63+
cir.setReturnValue(-1);
64+
}
65+
66+
private boolean insertIntoAllowedSlots(PlayerInventory inventory, ItemStack stack) {
67+
// Try to add to existing stacks first
68+
if (addToExistingStacks(inventory, stack)) {
69+
return true;
70+
}
71+
72+
// Find empty slot in allowed areas
73+
int emptySlot = getProtectedEmptySlot(inventory);
74+
if (emptySlot != -1) {
75+
inventory.getMainStacks().set(emptySlot, stack.copy());
76+
stack.setCount(0);
77+
return true;
78+
}
79+
80+
return false;
81+
}
82+
83+
private boolean addToExistingStacks(PlayerInventory inventory, ItemStack stack) {
84+
// Check hotbar (0-8)
85+
for (int i = 0; i <= 8; i++) {
86+
ItemStack existing = inventory.getStack(i);
87+
if (canStackWith(existing, stack)) {
88+
int transferred = Math.min(stack.getCount(), existing.getMaxCount() - existing.getCount());
89+
existing.increment(transferred);
90+
stack.decrement(transferred);
91+
if (stack.isEmpty()) return true;
92+
}
93+
}
94+
95+
// Check main inventory (9-35)
96+
for (int i = 9; i <= 35; i++) {
97+
ItemStack existing = inventory.getStack(i);
98+
if (canStackWith(existing, stack)) {
99+
int transferred = Math.min(stack.getCount(), existing.getMaxCount() - existing.getCount());
100+
existing.increment(transferred);
101+
stack.decrement(transferred);
102+
if (stack.isEmpty()) return true;
103+
}
104+
}
105+
106+
// Check extra slots (45-53)
107+
for (int i = 45; i <= 53; i++) {
108+
if (i < inventory.size()) {
109+
ItemStack existing = inventory.getStack(i);
110+
if (canStackWith(existing, stack)) {
111+
int transferred = Math.min(stack.getCount(), existing.getMaxCount() - existing.getCount());
112+
existing.increment(transferred);
113+
stack.decrement(transferred);
114+
if (stack.isEmpty()) return true;
115+
}
116+
}
117+
}
118+
119+
return false;
120+
}
121+
122+
private boolean canStackWith(ItemStack existing, ItemStack stack) {
123+
return !existing.isEmpty() &&
124+
existing.getItem() == stack.getItem() &&
125+
existing.getCount() < existing.getMaxCount() &&
126+
ItemStack.areEqual(existing, stack);
127+
}
128+
129+
private int getProtectedEmptySlot(PlayerInventory inventory) {
130+
// Check hotbar first (0-8)
131+
for (int i = 0; i <= 8; i++) {
132+
if (inventory.getStack(i).isEmpty()) {
133+
return i;
134+
}
135+
}
136+
137+
// Check main inventory (9-35)
138+
for (int i = 9; i <= 35; i++) {
139+
if (inventory.getStack(i).isEmpty()) {
140+
return i;
141+
}
142+
}
143+
144+
// Check extra slots (45-53)
145+
for (int i = 45; i <= 53; i++) {
146+
if (i < inventory.size() && inventory.getStack(i).isEmpty()) {
147+
return i;
148+
}
149+
}
150+
151+
return -1;
152+
}
153+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.gompk.pockets.mixin;
2+
3+
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
4+
import net.minecraft.client.gui.ScreenPos;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
9+
10+
@Mixin(InventoryScreen.class)
11+
public abstract class FixRecipeBookMixin {
12+
13+
@Inject(method = "getRecipeBookButtonPos", at = @At("HEAD"), cancellable = true)
14+
private void fixRecipeBookButtonPos(CallbackInfoReturnable<ScreenPos> cir) {
15+
// Cast this InventoryScreen to the accessor to get x/y
16+
HandledScreenAccessor accessor = (HandledScreenAccessor) (Object) this;
17+
18+
int offsetX = 104; // horizontal offset from background
19+
int offsetY = 60; // vertical offset from top of background
20+
21+
int stableX = accessor.getGuiX() + offsetX;
22+
int stableY = accessor.getGuiY() + offsetY;
23+
24+
cir.setReturnValue(new ScreenPos(stableX, stableY));
25+
}
26+
}
27+
28+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.gompk.pockets.mixin;
2+
3+
import net.minecraft.client.gui.screen.ingame.HandledScreen;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Accessor;
6+
7+
@Mixin(HandledScreen.class)
8+
public interface HandledScreenAccessor {
9+
@Accessor("x")
10+
int getGuiX();
11+
12+
@Accessor("y")
13+
int getGuiY();
14+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package net.gompk.pockets.mixin;
2+
3+
import net.gompk.pockets.Pockets;
4+
import net.minecraft.entity.player.PlayerEntity;
5+
import net.minecraft.entity.player.PlayerInventory;
6+
import net.minecraft.screen.PlayerScreenHandler;
7+
import net.minecraft.screen.slot.Slot;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.ModifyArg;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(PlayerScreenHandler.class)
15+
public class HotbarPositionFixMixin {
16+
17+
// Intercept hotbar slot creation and adjust Y position
18+
@ModifyArg(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;<init>(Lnet/minecraft/inventory/Inventory;III)V"), index = 3)
19+
private int adjustHotbarY(int y) {
20+
// If this is a hotbar slot (Y position around 142), move it down by 18 pixels
21+
if (y == 142) {
22+
Pockets.LOGGER.info("POCKETS DEBUG: Adjusting hotbar Y from {} to {}", y, y + 18);
23+
return y + 18;
24+
}
25+
return y;
26+
}
27+
28+
@Inject(method = "<init>", at = @At("TAIL"))
29+
private void addExtraInventoryRows(PlayerInventory inventory, boolean onServer, PlayerEntity owner, CallbackInfo ci) {
30+
Pockets.LOGGER.info("POCKETS DEBUG: Adding extra inventory row...");
31+
32+
Pockets.extraInventoryRows = 1;
33+
34+
// Add extra slots between main inventory (Y: 84) and hotbar (now at Y: 160)
35+
// Position them at Y: 102 to be visually between the main inventory and hotbar
36+
int startIndex = 45; // Use indices 45-53 to avoid conflicts with armor/offhand slots
37+
int y = 102; // Position between main inventory and moved hotbar
38+
39+
for (int x = 0; x < 9; x++) {
40+
Slot newSlot = new Slot(inventory, startIndex + x, 8 + x * 18, y);
41+
((ScreenHandlerAccessor)this).invokeAddSlot(newSlot);
42+
Pockets.LOGGER.info("POCKETS DEBUG: Added slot {} at ({}, {})", startIndex + x, 8 + x * 18, y);
43+
}
44+
45+
Pockets.LOGGER.info("POCKETS DEBUG: Extra row added successfully");
46+
}
47+
}

0 commit comments

Comments
 (0)