From 4996c3e901d590dcd70337c29c33fbba4fba566c Mon Sep 17 00:00:00 2001 From: Samsuik Date: Sat, 20 Jul 2024 00:08:08 +0100 Subject: [PATCH] Fix falling tnt not swinging inside blocks --- .../server/0021-Specialised-Explosions.patch | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/patches/server/0021-Specialised-Explosions.patch b/patches/server/0021-Specialised-Explosions.patch index fcb1edc..29d2851 100644 --- a/patches/server/0021-Specialised-Explosions.patch +++ b/patches/server/0021-Specialised-Explosions.patch @@ -228,10 +228,10 @@ index 0000000000000000000000000000000000000000..0611555b4afb461e2045585e3d816014 +} diff --git a/src/main/java/me/samsuik/sakura/explosion/special/TntExplosion.java b/src/main/java/me/samsuik/sakura/explosion/special/TntExplosion.java new file mode 100644 -index 0000000000000000000000000000000000000000..5a1a576625b265c9b6d2d0968efedebf4be79166 +index 0000000000000000000000000000000000000000..580fa77e60fd9c5b47b3499d86f13c36ad73d89b --- /dev/null +++ b/src/main/java/me/samsuik/sakura/explosion/special/TntExplosion.java -@@ -0,0 +1,191 @@ +@@ -0,0 +1,200 @@ +package me.samsuik.sakura.explosion.special; + +import io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet; @@ -263,7 +263,7 @@ index 0000000000000000000000000000000000000000..5a1a576625b265c9b6d2d0968efedebf + private final List explosions = new ObjectArrayList<>(); + private AABB bounds; + private int wrapped = 0; -+ private int movement = 0; ++ private boolean moved = false; + + public TntExplosion(Level world, PrimedTnt tnt, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, BlockInteraction destructionType, ParticleOptions particle, ParticleOptions emitterParticle, SoundEvent soundEvent) { + super(world, tnt, damageSource, behavior, x, y, z, power, createFire, destructionType, particle, emitterParticle, soundEvent); @@ -306,7 +306,7 @@ index 0000000000000000000000000000000000000000..5a1a576625b265c9b6d2d0968efedebf + if (this.wrapped < ALL_DIRECTIONS) { + Vec3 momentum = this.cause.entityState().momentum(); + for (Direction.Axis axis : Direction.Axis.VALUES) { -+ double current = momentum.get(axis); ++ double current = momentum.get(axis); + double previous = previousMomentum.get(axis); + if (current == previous || current * previous < 0) { + this.wrapped |= 1 << axis.ordinal(); @@ -352,7 +352,16 @@ index 0000000000000000000000000000000000000000..5a1a576625b265c9b6d2d0968efedebf + + private void updateExplosionPosition(EntityState entityState, boolean destroyedBlocks) { + // Before setting entity state, otherwise we might cause issues. -+ final boolean hasMoved = !this.position.equals(this.cause.position()) && (this.movement != 1 || !this.originalPosition.equals(this.position)); ++ final boolean hasMoved; ++ if (this.moved) { ++ hasMoved = true; ++ } else if (this.position.equals(this.cause.position())) { ++ hasMoved = false; ++ } else { ++ double newMomentum = entityState.momentum().lengthSqr(); ++ double oldMomentum = this.cause.entityState().momentum().lengthSqr(); ++ hasMoved = oldMomentum <= Math.pow(this.radius() * 2.0 + 1.0, 2.0) || newMomentum <= oldMomentum; ++ } + + // Keep track of entity state + entityState.apply(this.cause); @@ -362,7 +371,7 @@ index 0000000000000000000000000000000000000000..5a1a576625b265c9b6d2d0968efedebf + if (destroyedBlocks || hasMoved) { + this.cause.setFuse(100); + this.cause.tick(); -+ this.movement++; ++ this.moved |= !this.position.equals(this.originalPosition); + this.recalculateExplosionPosition(); + } + }