Use our getRegistryAccess to null check against world
This commit is contained in:
Owen
2025-06-24 15:26:37 -04:00
committed by GitHub
parent aa6ee44a7a
commit d7510efc16
4 changed files with 11 additions and 3 deletions

View File

@@ -74,7 +74,7 @@ public abstract class CraftBlockEntityState<T extends BlockEntity> extends Craft
this.loadData(state.getSnapshotNBT()); this.loadData(state.getSnapshotNBT());
} }
private RegistryAccess getRegistryAccess() { public RegistryAccess getRegistryAccess() {
LevelAccessor worldHandle = this.getWorldHandle(); LevelAccessor worldHandle = this.getWorldHandle();
return (worldHandle != null) ? worldHandle.registryAccess() : CraftRegistry.getMinecraftRegistry(); return (worldHandle != null) ? worldHandle.registryAccess() : CraftRegistry.getMinecraftRegistry();
} }

View File

@@ -50,7 +50,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
} }
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(() -> "spawner@" + getLocation(), LOGGER)) { try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(() -> "spawner@" + getLocation(), LOGGER)) {
ValueInput valueInput = TagValueInput.create(scopedCollector, this.getInternalWorld().registryAccess(), spawnData.entityToSpawn()); ValueInput valueInput = TagValueInput.create(scopedCollector, this.getRegistryAccess(), spawnData.entityToSpawn());
Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(valueInput); Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(valueInput);
return type.map(CraftEntityType::minecraftToBukkit).orElse(null); return type.map(CraftEntityType::minecraftToBukkit).orElse(null);
} }
@@ -182,7 +182,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<SpawnerBlockEnti
return null; return null;
} }
try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(() -> "spawner@" + getLocation(), LOGGER)) { try (ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(() -> "spawner@" + getLocation(), LOGGER)) {
ValueInput valueInput = TagValueInput.create(scopedCollector, this.getInternalWorld().registryAccess(), spawnData.getEntityToSpawn()); ValueInput valueInput = TagValueInput.create(scopedCollector, this.getRegistryAccess(), spawnData.getEntityToSpawn());
Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(valueInput); Optional<net.minecraft.world.entity.EntityType<?>> type = net.minecraft.world.entity.EntityType.by(valueInput);
return type.map(CraftEntityType::minecraftToBukkit).map(CraftEntityType::bukkitToString).orElse(null); return type.map(CraftEntityType::minecraftToBukkit).map(CraftEntityType::bukkitToString).orElse(null);

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import net.minecraft.core.RegistryAccess;
import net.minecraft.util.ProblemReporter; import net.minecraft.util.ProblemReporter;
import net.minecraft.util.RandomSource; import net.minecraft.util.RandomSource;
import net.minecraft.util.random.WeightedList; import net.minecraft.util.random.WeightedList;
@@ -186,6 +187,11 @@ public class CraftMinecartMobSpawner extends CraftMinecart implements SpawnerMin
return this.getHandle().level(); return this.getHandle().level();
} }
@Override
public RegistryAccess getRegistryAccess() {
return this.getHandle().registryAccess();
}
@Override @Override
public net.minecraft.core.BlockPos getInternalPosition() { public net.minecraft.core.BlockPos getInternalPosition() {
return this.getHandle().blockPosition(); return this.getHandle().blockPosition();

View File

@@ -34,6 +34,8 @@ public interface PaperSharedSpawnerLogic extends Spawner {
Level getInternalWorld(); Level getInternalWorld();
RegistryAccess getRegistryAccess();
BlockPos getInternalPosition(); BlockPos getInternalPosition();
default boolean isActivated() { default boolean isActivated() {
return this.getSpawner().isNearPlayer(this.getInternalWorld(), this.getInternalPosition()); return this.getSpawner().isNearPlayer(this.getInternalWorld(), this.getInternalPosition());