From f4d009db041d9db3aa17f34fa9bdf11a01606268 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:09:26 -0700 Subject: [PATCH] Add back getAffectedBlocks to explosion events --- .../world/level/ServerExplosion.java.patch | 22 +++++++++++++++++-- .../neoforged/neoforge/event/EventHooks.java | 8 +++---- .../neoforge/event/level/ExplosionEvent.java | 12 +++++----- .../event/level/ExplosionKnockbackEvent.java | 13 ++++++----- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/patches/net/minecraft/world/level/ServerExplosion.java.patch b/patches/net/minecraft/world/level/ServerExplosion.java.patch index de66d59d95..210b558757 100644 --- a/patches/net/minecraft/world/level/ServerExplosion.java.patch +++ b/patches/net/minecraft/world/level/ServerExplosion.java.patch @@ -1,12 +1,21 @@ --- a/net/minecraft/world/level/ServerExplosion.java +++ b/net/minecraft/world/level/ServerExplosion.java +@@ -165,7 +_,7 @@ + return new ObjectArrayList<>(set); + } + +- private void hurtEntities() { ++ private void hurtEntities(List blocks) { + float f = this.radius * 2.0F; + int i = Mth.floor(this.center.x - (double)f - 1.0); + int j = Mth.floor(this.center.x + (double)f + 1.0); @@ -174,7 +_,9 @@ int i1 = Mth.floor(this.center.z - (double)f - 1.0); int j1 = Mth.floor(this.center.z + (double)f + 1.0); - for (Entity entity : this.level.getEntities(this.source, new AABB((double)i, (double)k, (double)i1, (double)j, (double)l, (double)j1))) { + List list = this.level.getEntities(this.source, new AABB((double)i, (double)k, (double)i1, (double)j, (double)l, (double)j1)); -+ net.neoforged.neoforge.event.EventHooks.onExplosionDetonate(this.level, this, list, f); ++ net.neoforged.neoforge.event.EventHooks.onExplosionDetonate(this.level, this, list, blocks); + for (Entity entity : list) { if (!entity.ignoreExplosion(this)) { double d0 = Math.sqrt(entity.distanceToSqr(this.center)) / (double)f; @@ -15,7 +24,16 @@ d2 *= d6; d3 *= d6; Vec3 vec3 = new Vec3(d1, d2, d3); -+ vec3 = net.neoforged.neoforge.event.EventHooks.getExplosionKnockback(this.level, this, entity, vec3); ++ vec3 = net.neoforged.neoforge.event.EventHooks.getExplosionKnockback(this.level, this, entity, vec3, blocks); entity.setDeltaMovement(entity.getDeltaMovement().add(vec3)); if (entity instanceof Player) { Player player = (Player)entity; +@@ -246,7 +_,7 @@ + public void explode() { + this.level.gameEvent(this.source, GameEvent.EXPLODE, this.center); + List list = this.calculateExplodedPositions(); +- this.hurtEntities(); ++ this.hurtEntities(list); + if (this.interactsWithBlocks()) { + ProfilerFiller profilerfiller = Profiler.get(); + profilerfiller.push("explosion_blocks"); diff --git a/src/main/java/net/neoforged/neoforge/event/EventHooks.java b/src/main/java/net/neoforged/neoforge/event/EventHooks.java index cca9ed385c..c5109000f3 100644 --- a/src/main/java/net/neoforged/neoforge/event/EventHooks.java +++ b/src/main/java/net/neoforged/neoforge/event/EventHooks.java @@ -588,7 +588,7 @@ public static boolean onExplosionStart(Level level, ServerExplosion explosion) { return NeoForge.EVENT_BUS.post(new ExplosionEvent.Start(level, explosion)).isCanceled(); } - public static void onExplosionDetonate(Level level, ServerExplosion explosion, List list, double diameter) { + public static void onExplosionDetonate(Level level, ServerExplosion explosion, List entities, List blocks) { //Filter entities to only those who are effected, to prevent modders from seeing more then will be hurt. /* Enable this if we get issues with modders looping to much. Iterator itr = list.iterator(); @@ -600,7 +600,7 @@ public static void onExplosionDetonate(Level level, ServerExplosion explosion, L if (e.isImmuneToExplosions() || dist > 1.0F) itr.remove(); } */ - NeoForge.EVENT_BUS.post(new ExplosionEvent.Detonate(level, explosion, list)); + NeoForge.EVENT_BUS.post(new ExplosionEvent.Detonate(level, explosion, entities, blocks)); } /** @@ -613,8 +613,8 @@ public static void onExplosionDetonate(Level level, ServerExplosion explosion, L * @param initialVelocity The explosion calculated velocity for the entity * @return The new explosion velocity to add to the entity's existing velocity */ - public static Vec3 getExplosionKnockback(Level level, ServerExplosion explosion, Entity entity, Vec3 initialVelocity) { - ExplosionKnockbackEvent event = new ExplosionKnockbackEvent(level, explosion, entity, initialVelocity); + public static Vec3 getExplosionKnockback(Level level, ServerExplosion explosion, Entity entity, Vec3 initialVelocity, List blocks) { + ExplosionKnockbackEvent event = new ExplosionKnockbackEvent(level, explosion, entity, initialVelocity, blocks); NeoForge.EVENT_BUS.post(event); return event.getKnockbackVelocity(); } diff --git a/src/main/java/net/neoforged/neoforge/event/level/ExplosionEvent.java b/src/main/java/net/neoforged/neoforge/event/level/ExplosionEvent.java index b6d1d38e2d..34118e3790 100644 --- a/src/main/java/net/neoforged/neoforge/event/level/ExplosionEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/level/ExplosionEvent.java @@ -6,6 +6,7 @@ package net.neoforged.neoforge.event.level; import java.util.List; +import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.level.ServerExplosion; @@ -63,17 +64,18 @@ public Start(Level level, ServerExplosion explosion) { */ public static class Detonate extends ExplosionEvent { private final List entityList; + private final List blockList; - public Detonate(Level level, ServerExplosion explosion, List entityList) { + public Detonate(Level level, ServerExplosion explosion, List entityList, List blockList) { super(level, explosion); this.entityList = entityList; + this.blockList = blockList; } /** return the list of blocks affected by the explosion. */ - // FIXME porting: explosions changed a bit - /*public List getAffectedBlocks() { - return getExplosion().getToBlow(); - }*/ + public List getAffectedBlocks() { + return this.blockList; + } /** return the list of entities affected by the explosion. */ public List getAffectedEntities() { diff --git a/src/main/java/net/neoforged/neoforge/event/level/ExplosionKnockbackEvent.java b/src/main/java/net/neoforged/neoforge/event/level/ExplosionKnockbackEvent.java index d07fee5f06..321e30f49e 100644 --- a/src/main/java/net/neoforged/neoforge/event/level/ExplosionKnockbackEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/level/ExplosionKnockbackEvent.java @@ -5,6 +5,8 @@ package net.neoforged.neoforge.event.level; +import java.util.List; +import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.level.ServerExplosion; @@ -21,19 +23,20 @@ */ public class ExplosionKnockbackEvent extends ExplosionEvent { private final Entity entity; + private final List blockList; private Vec3 knockbackVelocity; - public ExplosionKnockbackEvent(Level level, ServerExplosion explosion, Entity entity, Vec3 knockbackVelocity) { + public ExplosionKnockbackEvent(Level level, ServerExplosion explosion, Entity entity, Vec3 knockbackVelocity, List blockList) { super(level, explosion); this.entity = entity; + this.blockList = blockList; this.knockbackVelocity = knockbackVelocity; } /** return the list of blocks affected by the explosion. */ - // FIXME porting: explosions changed a bit - /*public List getAffectedBlocks() { - return getExplosion().getToBlow(); - }*/ + public List getAffectedBlocks() { + return this.blockList; + } /** return the entity affected by the explosion knockback. */ public Entity getAffectedEntity() {