Fix crash when repairing or upgrading tools (#297)

This commit is contained in:
Algent authored and GitHub committed 2026-06-15 21:19:20 +02:00
1 parent ec8d5201a4
commit 20fc4245ee
7 files changed
+14 -7

No files matched your search

@@ -20,6 +20,9 @@ public class ModifyBuilder {
if (copy.getItem() instanceof IModifyable) {
IModifyable item = (IModifyable) copy.getItem();
// Strip stale ToRemove tags that can cause extra amount of items being used or OOB crash
copy.getTagCompound().getCompoundTag(item.getBaseTagName()).removeTag("ToRemove");
boolean built = false;
for (ItemModifier mod : itemModifiers) {
if (mod.matches(modifiers, input) && mod.validType(item)) {
@@ -317,7 +317,11 @@ public class CraftingStationContainer extends Container {
copyStack = otherInventorySlot.getStack();
if (copyStack == null && otherInventorySlot.isItemValid(stack)) {
otherInventorySlot.putStack(stack.copy());
ItemStack placed = stack.copy();
if (placed.hasTagCompound() && placed.getItem() instanceof IModifyable modifyable) {
placed.getTagCompound().getCompoundTag(modifyable.getBaseTagName()).removeTag("ToRemove");
}
otherInventorySlot.putStack(placed);
otherInventorySlot.onSlotChanged();
stack.stackSize = 0;
failedToMerge = true;
@@ -31,13 +31,13 @@ public class SlotCraftingStation extends SlotCrafting {
int toRemoveIndex = 0;
IInventory inventory = this.matrix;
for (int i = 0; i <= inventory.getSizeInventory(); i++) {
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (i == 4) continue;
ItemStack item = inventory.getStackInSlot(i);
if (item == null) {
continue;
}
if (toRemoveArray == null) {
if (toRemoveArray == null || toRemoveIndex >= toRemoveArray.length) {
inventory.decrStackSize(i, 1);
} else {
inventory.decrStackSize(i, toRemoveArray[toRemoveIndex]);
@@ -64,7 +64,7 @@ public class SlotTool extends Slot {
if (item == null) {
continue;
}
if (toRemoveArray == null) {
if (toRemoveArray == null || toRemoveIndex >= toRemoveArray.length) {
inventory.decrStackSize(i, 1);
} else {
inventory.decrStackSize(i, toRemoveArray[toRemoveIndex]);
@@ -35,7 +35,7 @@ public class SlotToolForge extends SlotTool {
if (item == null) {
continue;
}
if (toRemoveArray == null) {
if (toRemoveArray == null || toRemoveIndex >= toRemoveArray.length) {
inventory.decrStackSize(i, 1);
} else {
inventory.decrStackSize(i, toRemoveArray[toRemoveIndex]);
@@ -84,7 +84,7 @@ public class ToolForgeContainer extends ToolStationContainer {
if (item == null) {
continue;
}
if (toRemoveArray == null) {
if (toRemoveArray == null || toRemoveIndex >= toRemoveArray.length) {
logic.decrStackSize(i, 1);
} else {
logic.decrStackSize(i, toRemoveArray[toRemoveIndex]);
@@ -133,7 +133,7 @@ public class ToolStationContainer extends ActiveContainer {
if (item == null) {
continue;
}
if (toRemoveArray == null) {
if (toRemoveArray == null || toRemoveIndex >= toRemoveArray.length) {
logic.decrStackSize(i, 1);
} else {
logic.decrStackSize(i, toRemoveArray[toRemoveIndex]);