From b09f8e422b970ca2572c688b09f0370c0aeaeeae Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 5 Sep 2025 14:41:52 +0200 Subject: [PATCH] fix large item explosions --- .../java/common/entity/item/EntityItem.java | 2 +- .../main/java/common/inventory/Container.java | 38 +++---------------- .../java/common/inventory/ContainerChest.java | 4 +- .../inventory/ContainerEnchantment.java | 2 +- .../inventory/ContainerEntityInventory.java | 8 ++-- .../common/inventory/ContainerMerchant.java | 8 ++-- .../common/inventory/ContainerPlayer.java | 6 +-- .../common/inventory/ContainerRepair.java | 6 +-- .../java/common/inventory/ContainerTile.java | 4 +- .../java/common/tileentity/DeviceFurnace.java | 2 +- 10 files changed, 27 insertions(+), 53 deletions(-) diff --git a/common/src/main/java/common/entity/item/EntityItem.java b/common/src/main/java/common/entity/item/EntityItem.java index 221e4b23..b6215236 100755 --- a/common/src/main/java/common/entity/item/EntityItem.java +++ b/common/src/main/java/common/entity/item/EntityItem.java @@ -72,7 +72,7 @@ public class EntityItem extends Entity } this.worldObj.playEffect(1023, this.getPosition(), 0); if(Vars.itemExplosion && distance >= 2.0f && this.getEntityItem().getItem().getExplosive() > 0 && !this.getEntityItem().isEmpty()) - this.worldObj.explode(null, this, this.posX, this.posY, this.posZ, (float)this.getEntityItem().getItem().getExplosive() * (1.0f + (float)(this.getEntityItem().getSize() - 1) / 24.0f), true, true, true); + this.worldObj.explode(null, this, this.posX, this.posY, this.posZ, (float)this.getEntityItem().getItem().getExplosive() * (1.0f + (float)(Math.min(this.getEntityItem().getSize(), 20) - 1) / 24.0f), true, true, true); this.setDead(); } } diff --git a/common/src/main/java/common/inventory/Container.java b/common/src/main/java/common/inventory/Container.java index 06ce250f..02ced52b 100755 --- a/common/src/main/java/common/inventory/Container.java +++ b/common/src/main/java/common/inventory/Container.java @@ -491,19 +491,14 @@ public abstract class Container * (included) and maxIndex (excluded). Args : stack, minIndex, maxIndex, negativDirection. /!\ the Container * implementation do not check if the item is valid for the slot */ - protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection) + protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex) { boolean flag = false; int i = startIndex; - if (reverseDirection) - { - i = endIndex - 1; - } - if (stack.isStackable()) { - while (!stack.isEmpty() && (!reverseDirection && i < endIndex || reverseDirection && i >= startIndex)) + while (!stack.isEmpty() && i < endIndex) { Slot slot = (Slot)this.inventorySlots.get(i); ItemStack itemstack = slot.getStack(); @@ -528,29 +523,15 @@ public abstract class Container } } - if (reverseDirection) - { - --i; - } - else - { - ++i; - } + ++i; } } if (!stack.isEmpty()) { - if (reverseDirection) - { - i = endIndex - 1; - } - else - { - i = startIndex; - } + i = startIndex; - while (!reverseDirection && i < endIndex || reverseDirection && i >= startIndex) + while (i < endIndex) { Slot slot1 = (Slot)this.inventorySlots.get(i); ItemStack itemstack1 = slot1.getStack(); @@ -564,14 +545,7 @@ public abstract class Container break; } - if (reverseDirection) - { - --i; - } - else - { - ++i; - } + ++i; } } diff --git a/common/src/main/java/common/inventory/ContainerChest.java b/common/src/main/java/common/inventory/ContainerChest.java index dfd6d82e..212b61ba 100755 --- a/common/src/main/java/common/inventory/ContainerChest.java +++ b/common/src/main/java/common/inventory/ContainerChest.java @@ -58,12 +58,12 @@ public class ContainerChest extends Container if (index < this.chestSize) { - if (!this.mergeItemStack(itemstack1, this.chestSize, this.inventorySlots.size(), false)) + if (!this.mergeItemStack(itemstack1, this.chestSize, this.inventorySlots.size())) { return null; } } - else if (!this.mergeItemStack(itemstack1, 0, this.chestSize, false)) + else if (!this.mergeItemStack(itemstack1, 0, this.chestSize)) { return null; } diff --git a/common/src/main/java/common/inventory/ContainerEnchantment.java b/common/src/main/java/common/inventory/ContainerEnchantment.java index 01aacd72..f2026028 100755 --- a/common/src/main/java/common/inventory/ContainerEnchantment.java +++ b/common/src/main/java/common/inventory/ContainerEnchantment.java @@ -309,7 +309,7 @@ public class ContainerEnchantment extends Container if (index == 0) { - if (!this.mergeItemStack(itemstack1, 1, 37, true)) + if (!this.mergeItemStack(itemstack1, 1, 37)) { return null; } diff --git a/common/src/main/java/common/inventory/ContainerEntityInventory.java b/common/src/main/java/common/inventory/ContainerEntityInventory.java index 9a5c5b42..a79ef053 100755 --- a/common/src/main/java/common/inventory/ContainerEntityInventory.java +++ b/common/src/main/java/common/inventory/ContainerEntityInventory.java @@ -82,26 +82,26 @@ public class ContainerEntityInventory extends Container if (index < this.entityInventory.getSizeInventory()) { - if (!this.mergeItemStack(itemstack1, this.entityInventory.getSizeInventory(), this.inventorySlots.size(), false)) + if (!this.mergeItemStack(itemstack1, this.entityInventory.getSizeInventory(), this.inventorySlots.size())) { return null; } } else if (this.entity instanceof EntityHorse && this.getSlot(1).isItemValid(itemstack1) && !this.getSlot(1).getHasStack()) { - if (!this.mergeItemStack(itemstack1, 1, 2, false)) + if (!this.mergeItemStack(itemstack1, 1, 2)) { return null; } } else if (this.entity instanceof EntityHorse && this.getSlot(0).isItemValid(itemstack1)) { - if (!this.mergeItemStack(itemstack1, 0, 1, false)) + if (!this.mergeItemStack(itemstack1, 0, 1)) { return null; } } - else if (this.entity instanceof EntityHorse && (this.entityInventory.getSizeInventory() <= 2 || !this.mergeItemStack(itemstack1, 2, this.entityInventory.getSizeInventory(), false))) + else if (this.entity instanceof EntityHorse && (this.entityInventory.getSizeInventory() <= 2 || !this.mergeItemStack(itemstack1, 2, this.entityInventory.getSizeInventory()))) { return null; } diff --git a/common/src/main/java/common/inventory/ContainerMerchant.java b/common/src/main/java/common/inventory/ContainerMerchant.java index 79fa25a0..c8a650a8 100755 --- a/common/src/main/java/common/inventory/ContainerMerchant.java +++ b/common/src/main/java/common/inventory/ContainerMerchant.java @@ -203,7 +203,7 @@ public class ContainerMerchant extends Container if (index == 2) { - if (!this.mergeItemStack(itemstack1, 3, 39, false)) + if (!this.mergeItemStack(itemstack1, 3, 39)) { return null; } @@ -214,17 +214,17 @@ public class ContainerMerchant extends Container { if (index >= 3 && index < 30) { - if (!this.mergeItemStack(itemstack1, 30, 39, false)) + if (!this.mergeItemStack(itemstack1, 30, 39)) { return null; } } - else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) + else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30)) { return null; } } - else if (!this.mergeItemStack(itemstack1, 3, 39, false)) + else if (!this.mergeItemStack(itemstack1, 3, 39)) { return null; } diff --git a/common/src/main/java/common/inventory/ContainerPlayer.java b/common/src/main/java/common/inventory/ContainerPlayer.java index 4a312827..0df1145b 100755 --- a/common/src/main/java/common/inventory/ContainerPlayer.java +++ b/common/src/main/java/common/inventory/ContainerPlayer.java @@ -86,14 +86,14 @@ public class ContainerPlayer extends Container { if (index >= 0 && index < Equipment.ARMOR_SLOTS) { - if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity(), false)) + if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity())) { return null; } } else if (itemstack.getItem() instanceof ItemArmor armor && (idx = this.getFreeSlotFor(armor.getArmorType())) >= 0) { - if (!this.mergeItemStack(itemstack1, idx, idx + 1, false)) + if (!this.mergeItemStack(itemstack1, idx, idx + 1)) { return null; } @@ -102,7 +102,7 @@ public class ContainerPlayer extends Container { { return null; } - else if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity(), false)) + else if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity())) { return null; } diff --git a/common/src/main/java/common/inventory/ContainerRepair.java b/common/src/main/java/common/inventory/ContainerRepair.java index d936cefc..37c9e09b 100755 --- a/common/src/main/java/common/inventory/ContainerRepair.java +++ b/common/src/main/java/common/inventory/ContainerRepair.java @@ -497,7 +497,7 @@ public class ContainerRepair extends Container if (index == 2) { - if (!this.mergeItemStack(itemstack1, 3, 39, false)) + if (!this.mergeItemStack(itemstack1, 3, 39)) { return null; } @@ -506,12 +506,12 @@ public class ContainerRepair extends Container } else if (index != 0 && index != 1) { - if (index >= 3 && index < 39 && !this.mergeItemStack(itemstack1, 0, 2, false)) + if (index >= 3 && index < 39 && !this.mergeItemStack(itemstack1, 0, 2)) { return null; } } - else if (!this.mergeItemStack(itemstack1, 3, 39, false)) + else if (!this.mergeItemStack(itemstack1, 3, 39)) { return null; } diff --git a/common/src/main/java/common/inventory/ContainerTile.java b/common/src/main/java/common/inventory/ContainerTile.java index 991cd423..5e6461ea 100755 --- a/common/src/main/java/common/inventory/ContainerTile.java +++ b/common/src/main/java/common/inventory/ContainerTile.java @@ -82,12 +82,12 @@ public class ContainerTile extends Container if (index < this.tileInv.getSizeInventory()) { - if (!this.mergeItemStack(itemstack1, this.tileInv.getSizeInventory(), this.inventorySlots.size(), false)) + if (!this.mergeItemStack(itemstack1, this.tileInv.getSizeInventory(), this.inventorySlots.size())) { return null; } } - else if (!this.mergeItemStack(itemstack1, 0, this.tileInv.getSizeInventory(), false)) + else if (!this.mergeItemStack(itemstack1, 0, this.tileInv.getSizeInventory())) { return null; } diff --git a/common/src/main/java/common/tileentity/DeviceFurnace.java b/common/src/main/java/common/tileentity/DeviceFurnace.java index 063174dc..3d22cf3e 100755 --- a/common/src/main/java/common/tileentity/DeviceFurnace.java +++ b/common/src/main/java/common/tileentity/DeviceFurnace.java @@ -77,7 +77,7 @@ public class DeviceFurnace extends Device { if(Vars.itemExplosion && this.getStackInSlot(1).getItem().getExplosive() > 0 && !this.getStackInSlot(1).isEmpty()) { this.world.setBlockToAir(getPos()); - this.world.explode(null, null, this.getXPos(), this.getYPos(), this.getZPos(), (float)this.getStackInSlot(1).getItem().getExplosive() * (1.0f + (float)(this.getStackInSlot(1).getSize() - 1) / 24.0f), true, true, true); + this.world.explode(null, null, this.getXPos(), this.getYPos(), this.getZPos(), (float)this.getStackInSlot(1).getItem().getExplosive() * (1.0f + (float)(Math.min(this.getStackInSlot(1).getSize(), 20) - 1) / 24.0f), true, true, true); this.setInventorySlotContents(1, null); return false; }