Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back getAffectedBlocks to explosion events #1647

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions patches/net/minecraft/world/level/ServerExplosion.java.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
--- a/net/minecraft/world/level/ServerExplosion.java
+++ b/net/minecraft/world/level/ServerExplosion.java
@@ -165,7 +_,12 @@
return new ObjectArrayList<>(set);
}

+ @Deprecated
private void hurtEntities() {
+ this.hurtEntities(List.of());
+ }
+
+ private void hurtEntities(List<BlockPos> blocks) {
jpenilla marked this conversation as resolved.
Show resolved Hide resolved
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<Entity> 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;
Expand All @@ -15,7 +28,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<BlockPos> list = this.calculateExplodedPositions();
- this.hurtEntities();
+ this.hurtEntities(list);
if (this.interactsWithBlocks()) {
ProfilerFiller profilerfiller = Profiler.get();
profilerfiller.push("explosion_blocks");
8 changes: 4 additions & 4 deletions src/main/java/net/neoforged/neoforge/event/EventHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity> list, double diameter) {
public static void onExplosionDetonate(Level level, ServerExplosion explosion, List<Entity> entities, List<BlockPos> 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<Entity> itr = list.iterator();
Expand All @@ -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));
}

/**
Expand All @@ -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<BlockPos> blocks) {
ExplosionKnockbackEvent event = new ExplosionKnockbackEvent(level, explosion, entity, initialVelocity, blocks);
NeoForge.EVENT_BUS.post(event);
return event.getKnockbackVelocity();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,17 +64,18 @@ public Start(Level level, ServerExplosion explosion) {
*/
public static class Detonate extends ExplosionEvent {
private final List<Entity> entityList;
private final List<BlockPos> blockList;

public Detonate(Level level, ServerExplosion explosion, List<Entity> entityList) {
public Detonate(Level level, ServerExplosion explosion, List<Entity> entityList, List<BlockPos> 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<BlockPos> getAffectedBlocks() {
return getExplosion().getToBlow();
}*/
public List<BlockPos> getAffectedBlocks() {
return this.blockList;
}

/** return the list of entities affected by the explosion. */
public List<Entity> getAffectedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,19 +23,20 @@
*/
public class ExplosionKnockbackEvent extends ExplosionEvent {
private final Entity entity;
private final List<BlockPos> 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<BlockPos> 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<BlockPos> getAffectedBlocks() {
return getExplosion().getToBlow();
}*/
public List<BlockPos> getAffectedBlocks() {
return this.blockList;
}

/** return the entity affected by the explosion knockback. */
public Entity getAffectedEntity() {
Expand Down