fix OOB crash

This commit is contained in:
PrototypeTrousers
2023-02-13 01:02:59 -03:00
parent e09ec8c420
commit ede2b4ce25
2 changed files with 36 additions and 32 deletions
@@ -115,23 +115,25 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable implements I
@Override @Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
if (clickTypeIn == ClickType.PICKUP && dragType == 1) { if (slotId >= 0 && slotId < this.inventorySlots.size()) {
if (this.inventorySlots.get(slotId) == magnetSlot) { if (clickTypeIn == ClickType.PICKUP && dragType == 1) {
ItemStack itemStack = magnetSlot.getStack(); if (this.inventorySlots.get(slotId) == magnetSlot) {
if (!magnetSlot.getStack().isEmpty()) { ItemStack itemStack = magnetSlot.getStack();
NBTTagCompound tag = itemStack.getTagCompound(); if (!magnetSlot.getStack().isEmpty()) {
if (tag == null) { NBTTagCompound tag = itemStack.getTagCompound();
tag = new NBTTagCompound(); 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;
} }
} }
} }
@@ -164,23 +164,25 @@ public class ContainerWirelessPatternTerminal extends ContainerPatternEncoder im
@Override @Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
if (clickTypeIn == ClickType.PICKUP && dragType == 1) { if (slotId >= 0 && slotId < this.inventorySlots.size()) {
if (this.inventorySlots.get(slotId) == magnetSlot) { if (clickTypeIn == ClickType.PICKUP && dragType == 1) {
ItemStack itemStack = magnetSlot.getStack(); if (this.inventorySlots.get(slotId) == magnetSlot) {
if (!magnetSlot.getStack().isEmpty()) { ItemStack itemStack = magnetSlot.getStack();
NBTTagCompound tag = itemStack.getTagCompound(); if (!magnetSlot.getStack().isEmpty()) {
if (tag == null) { NBTTagCompound tag = itemStack.getTagCompound();
tag = new NBTTagCompound(); 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;
} }
} }
} }