Skip to content

Commit

Permalink
Add spawner argument to EntityEvents.CHECK_SPAWN (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxNeedsSnacks committed Jan 15, 2024
1 parent 131bb0a commit 118a57d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.Level;

@Info("""
Expand All @@ -18,14 +19,16 @@ public class CheckLivingEntitySpawnEventJS extends LivingEntityEventJS {

public final double x, y, z;
public final MobSpawnType type;
public final BaseSpawner spawner;

public CheckLivingEntitySpawnEventJS(LivingEntity entity, Level level, double x, double y, double z, MobSpawnType type) {
public CheckLivingEntitySpawnEventJS(LivingEntity entity, Level level, double x, double y, double z, MobSpawnType type, BaseSpawner spawner) {
this.entity = entity;
this.level = level;
this.x = x;
this.y = y;
this.z = z;
this.type = type;
this.spawner = spawner;
}

@Override
Expand All @@ -49,4 +52,9 @@ public BlockContainerJS getBlock() {
public MobSpawnType getType() {
return type;
}

@Info("The spawner that spawned the entity.")
public BaseSpawner getSpawner() {
return spawner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void init() {

private static EventResult checkSpawn(LivingEntity entity, LevelAccessor la, double x, double y, double z, MobSpawnType type, BaseSpawner spawner) {
if (la instanceof Level level && (la.isClientSide() || UtilsJS.staticServer != null) && EntityEvents.CHECK_SPAWN.hasListeners()) {
return EntityEvents.CHECK_SPAWN.post(level, entity.getType(), new CheckLivingEntitySpawnEventJS(entity, level, x, y, z, type)).arch();
return EntityEvents.CHECK_SPAWN.post(level, entity.getType(), new CheckLivingEntitySpawnEventJS(entity, level, x, y, z, type, spawner)).arch();
}

return EventResult.pass();
Expand Down

0 comments on commit 118a57d

Please sign in to comment.