From a0d3dfaf284c2ec138d48e37aa4592bf1e96e9ae Mon Sep 17 00:00:00 2001 From: Jacob Martin Date: Thu, 29 Dec 2022 14:06:51 +1100 Subject: [PATCH] #1129: Fix state corruption while handling explosion damage on EntityComplexPart An IllegalStateException may occur when an entity is damaged by fire or a potion effect immediately after an EntityComplexPart is damaged by an explosion. This is fixed by performing the instanceof EntityComplexPart check prior to setting CraftEventFactory.entityDamage. --- .../net/minecraft/world/level/Explosion.patch | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/nms-patches/net/minecraft/world/level/Explosion.patch b/nms-patches/net/minecraft/world/level/Explosion.patch index 201b83c38..236663e05 100644 --- a/nms-patches/net/minecraft/world/level/Explosion.patch +++ b/nms-patches/net/minecraft/world/level/Explosion.patch @@ -45,14 +45,12 @@ this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3D(this.x, this.y, this.z)); Set set = Sets.newHashSet(); boolean flag = true; -@@ -211,7 +226,35 @@ +@@ -211,7 +226,36 @@ double d12 = (double) getSeenPercent(vec3d, entity); double d13 = (1.0D - d7) * d12; - entity.hurt(this.getDamageSource(), (float) ((int) ((d13 * d13 + d13) / 2.0D * 7.0D * (double) f2 + 1.0D))); + // CraftBukkit start -+ CraftEventFactory.entityDamage = source; -+ entity.lastDamageCancelled = false; + + // Special case ender dragon only give knockback if no damage is cancelled + // Thinks to note: @@ -64,6 +62,9 @@ + continue; + } + ++ CraftEventFactory.entityDamage = source; ++ entity.lastDamageCancelled = false; ++ + if (entity instanceof EntityEnderDragon) { + for (EntityComplexPart entityComplexPart : ((EntityEnderDragon) entity).subEntities) { + if (list.contains(entityComplexPart)) { @@ -82,7 +83,7 @@ double d14 = d13; if (entity instanceof EntityLiving) { -@@ -254,6 +297,51 @@ +@@ -254,6 +298,51 @@ SystemUtils.shuffle(this.toBlow, this.level.random); ObjectListIterator objectlistiterator = this.toBlow.iterator(); @@ -134,7 +135,7 @@ while (objectlistiterator.hasNext()) { BlockPosition blockposition = (BlockPosition) objectlistiterator.next(); -@@ -272,8 +360,8 @@ +@@ -272,8 +361,8 @@ TileEntity tileentity = iblockdata.hasBlockEntity() ? this.level.getBlockEntity(blockposition) : null; LootTableInfo.Builder loottableinfo_builder = (new LootTableInfo.Builder(worldserver)).withRandom(this.level.random).withParameter(LootContextParameters.ORIGIN, Vec3D.atCenterOf(blockposition)).withParameter(LootContextParameters.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParameters.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParameters.THIS_ENTITY, this.source); @@ -145,7 +146,7 @@ } iblockdata.spawnAfterBreak(worldserver, blockposition, ItemStack.EMPTY, flag2); -@@ -305,7 +393,11 @@ +@@ -305,7 +394,11 @@ BlockPosition blockposition2 = (BlockPosition) objectlistiterator1.next(); if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockposition2).isAir() && this.level.getBlockState(blockposition2.below()).isSolidRender(this.level, blockposition2.below())) { @@ -158,7 +159,7 @@ } } } -@@ -317,6 +409,7 @@ +@@ -317,6 +410,7 @@ } private static void addBlockDrops(ObjectArrayList> objectarraylist, ItemStack itemstack, BlockPosition blockposition) {