1
0
Fork 0

fix large item explosions

This commit is contained in:
Sen 2025-09-05 14:41:52 +02:00
parent f93075f211
commit b09f8e422b
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
10 changed files with 27 additions and 53 deletions

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}