Skip to content

Commit

Permalink
Make sure to mention spawner in CHECK_SPAWN is nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxNeedsSnacks committed Jan 26, 2024
1 parent df234fa commit 546bcdb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

@Info("""
Invoked before an entity is spawned into the world.
Expand All @@ -19,9 +20,11 @@ public class CheckLivingEntitySpawnEventJS extends LivingEntityEventJS {

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

@Nullable
public final BaseSpawner spawner;

public CheckLivingEntitySpawnEventJS(LivingEntity entity, Level level, double x, double y, double z, MobSpawnType type, BaseSpawner spawner) {
public CheckLivingEntitySpawnEventJS(LivingEntity entity, Level level, double x, double y, double z, MobSpawnType type, @Nullable BaseSpawner spawner) {
this.entity = entity;
this.level = level;
this.x = x;
Expand Down Expand Up @@ -53,7 +56,8 @@ public MobSpawnType getType() {
return type;
}

@Info("The spawner that spawned the entity.")
@Info("The spawner that spawned the entity. Can be null if the entity was spawned by worldgen.")
@Nullable
public BaseSpawner getSpawner() {
return spawner;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import org.jetbrains.annotations.Nullable;

public class KubeJSEntityEventHandler {
public static void init() {
Expand All @@ -20,7 +21,7 @@ public static void init() {
EntityEvent.ADD.register(KubeJSEntityEventHandler::entitySpawned);
}

private static EventResult checkSpawn(LivingEntity entity, LevelAccessor la, double x, double y, double z, MobSpawnType type, BaseSpawner spawner) {
private static EventResult checkSpawn(LivingEntity entity, LevelAccessor la, double x, double y, double z, MobSpawnType type, @Nullable 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, spawner)).arch();
}
Expand Down

0 comments on commit 546bcdb

Please sign in to comment.