Skip to content

Commit 835d87e

Browse files
authored
Attempt to fix out of bounds crash with modern blockpick (#875)
1 parent 9e8c9db commit 835d87e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/main/java/com/mitchej123/hodgepodge/mixins/early/forge/MixinForgeHooks_ModernPickBlock.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1515

1616
import com.llamalad7.mixinextras.sugar.Local;
17+
import com.mitchej123.hodgepodge.Common;
1718

1819
@Mixin(value = ForgeHooks.class, remap = false)
1920
public class MixinForgeHooks_ModernPickBlock {
@@ -23,6 +24,15 @@ public class MixinForgeHooks_ModernPickBlock {
2324
private static void hodgepodge$onPickBlock(MovingObjectPosition target, EntityPlayer player, World world,
2425
CallbackInfoReturnable<Boolean> cir, @Local(name = "result") ItemStack result) {
2526
Minecraft clientObject = Minecraft.getMinecraft();
27+
// Pick-block fires only with no GUI shown, so openContainer should already be inventoryContainer.
28+
// If it isn't, some mod leaked a container reference and we should fix the state.
29+
if (player.openContainer != player.inventoryContainer) {
30+
Common.log.warn(
31+
"ModernPickBlock: leaked openContainer {} (size={}); resetting to inventoryContainer",
32+
player.openContainer.getClass().getName(),
33+
player.openContainer.inventorySlots.size());
34+
player.closeScreen();
35+
}
2636
for (int x = 9; x < 36; x++) {
2737
ItemStack stack = player.inventory.getStackInSlot(x);
2838
if (stack != null && stack.isItemEqual(result) && ItemStack.areItemStackTagsEqual(stack, result)) {

0 commit comments

Comments
 (0)