From ede2b4ce253d1a71ff5c437c6fde1952bffd512a Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Mon, 13 Feb 2023 01:02:59 -0300 Subject: [PATCH] fix OOB crash --- .../ContainerMEPortableCell.java | 34 ++++++++++--------- .../ContainerWirelessPatternTerminal.java | 34 ++++++++++--------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java index 9fd890175..836881a8a 100644 --- a/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java +++ b/src/main/java/appeng/container/implementations/ContainerMEPortableCell.java @@ -115,23 +115,25 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { - if (clickTypeIn == ClickType.PICKUP && dragType == 1) { - if (this.inventorySlots.get(slotId) == magnetSlot) { - ItemStack itemStack = magnetSlot.getStack(); - if (!magnetSlot.getStack().isEmpty()) { - NBTTagCompound tag = itemStack.getTagCompound(); - if (tag == null) { - tag = new NBTTagCompound(); + if (slotId >= 0 && slotId < this.inventorySlots.size()) { + if (clickTypeIn == ClickType.PICKUP && dragType == 1) { + if (this.inventorySlots.get(slotId) == magnetSlot) { + ItemStack itemStack = magnetSlot.getStack(); + if (!magnetSlot.getStack().isEmpty()) { + NBTTagCompound tag = itemStack.getTagCompound(); + if (tag == null) { + tag = new NBTTagCompound(); + } + if (tag.hasKey("enabled")) { + boolean e = tag.getBoolean("enabled"); + tag.setBoolean("enabled", !e); + } else { + tag.setBoolean("enabled", false); + } + magnetSlot.getStack().setTagCompound(tag); + magnetSlot.onSlotChanged(); + return ItemStack.EMPTY; } - if (tag.hasKey("enabled")) { - boolean e = tag.getBoolean("enabled"); - tag.setBoolean("enabled", !e); - } else { - tag.setBoolean("enabled", false); - } - magnetSlot.getStack().setTagCompound(tag); - magnetSlot.onSlotChanged(); - return ItemStack.EMPTY; } } } diff --git a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java index 8b760b636..e363f3ec8 100644 --- a/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerWirelessPatternTerminal.java @@ -164,23 +164,25 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { - if (clickTypeIn == ClickType.PICKUP && dragType == 1) { - if (this.inventorySlots.get(slotId) == magnetSlot) { - ItemStack itemStack = magnetSlot.getStack(); - if (!magnetSlot.getStack().isEmpty()) { - NBTTagCompound tag = itemStack.getTagCompound(); - if (tag == null) { - tag = new NBTTagCompound(); + if (slotId >= 0 && slotId < this.inventorySlots.size()) { + if (clickTypeIn == ClickType.PICKUP && dragType == 1) { + if (this.inventorySlots.get(slotId) == magnetSlot) { + ItemStack itemStack = magnetSlot.getStack(); + if (!magnetSlot.getStack().isEmpty()) { + NBTTagCompound tag = itemStack.getTagCompound(); + if (tag == null) { + tag = new NBTTagCompound(); + } + if (tag.hasKey("enabled")) { + boolean e = tag.getBoolean("enabled"); + tag.setBoolean("enabled", !e); + } else { + tag.setBoolean("enabled", false); + } + magnetSlot.getStack().setTagCompound(tag); + magnetSlot.onSlotChanged(); + return ItemStack.EMPTY; } - if (tag.hasKey("enabled")) { - boolean e = tag.getBoolean("enabled"); - tag.setBoolean("enabled", !e); - } else { - tag.setBoolean("enabled", false); - } - magnetSlot.getStack().setTagCompound(tag); - magnetSlot.onSlotChanged(); - return ItemStack.EMPTY; } } }