diff --git a/Allay-API/src/main/java/org/allaymc/api/blockentity/BlockEntityHelper.java b/Allay-API/src/main/java/org/allaymc/api/blockentity/BlockEntityHelper.java index 191fa90e3..ab24053e1 100644 --- a/Allay-API/src/main/java/org/allaymc/api/blockentity/BlockEntityHelper.java +++ b/Allay-API/src/main/java/org/allaymc/api/blockentity/BlockEntityHelper.java @@ -1,5 +1,6 @@ package org.allaymc.api.blockentity; +import lombok.extern.slf4j.Slf4j; import org.allaymc.api.blockentity.init.SimpleBlockEntityInitInfo; import org.allaymc.api.blockentity.registry.BlockEntityTypeRegistry; import org.allaymc.api.world.Dimension; @@ -12,11 +13,15 @@ * * @author daoge_cmd */ +@Slf4j public final class BlockEntityHelper { public static BlockEntity fromNBT(Dimension dimension, NbtMap nbt) { var id = nbt.getString("id"); var blockEntityType = BlockEntityTypeRegistry.getRegistry().get(id); - Objects.requireNonNull(blockEntityType, "Unknown block entity type: " + id); + if (blockEntityType == null) { + log.warn("Unknown block entity type: " + id); + return null; + } return blockEntityType.createBlockEntity(SimpleBlockEntityInitInfo.builder().dimension(dimension).nbt(nbt).build()); } } diff --git a/Allay-API/src/main/java/org/allaymc/api/entity/EntityHelper.java b/Allay-API/src/main/java/org/allaymc/api/entity/EntityHelper.java index 82082dad5..85a337686 100644 --- a/Allay-API/src/main/java/org/allaymc/api/entity/EntityHelper.java +++ b/Allay-API/src/main/java/org/allaymc/api/entity/EntityHelper.java @@ -1,5 +1,6 @@ package org.allaymc.api.entity; +import lombok.extern.slf4j.Slf4j; import org.allaymc.api.utils.Identifier; import org.allaymc.api.entity.init.SimpleEntityInitInfo; import org.allaymc.api.entity.registry.EntityTypeRegistry; @@ -13,10 +14,15 @@ * * @author daoge_cmd */ +@Slf4j public final class EntityHelper { public static Entity fromNBT(Dimension dimension, NbtMap nbt) { var identifier = new Identifier(nbt.getString("identifier")); - var entityType = Objects.requireNonNull(EntityTypeRegistry.getRegistry().get(identifier), "Unknown entity type " + identifier); + var entityType = EntityTypeRegistry.getRegistry().get(identifier); + if (entityType == null) { + log.warn("Unknown entity type " + identifier); + return null; + } return entityType.createEntity(SimpleEntityInitInfo.builder().dimension(dimension).nbt(nbt).build()); } } diff --git a/Allay-Server/src/main/java/org/allaymc/server/world/chunk/AllayUnsafeChunk.java b/Allay-Server/src/main/java/org/allaymc/server/world/chunk/AllayUnsafeChunk.java index b0c8b43e7..ef31e2516 100644 --- a/Allay-Server/src/main/java/org/allaymc/server/world/chunk/AllayUnsafeChunk.java +++ b/Allay-Server/src/main/java/org/allaymc/server/world/chunk/AllayUnsafeChunk.java @@ -71,6 +71,7 @@ public void beforeSetChunk(Dimension dimension) { if (blockEntityNbtList != null && !blockEntityNbtList.isEmpty()) { for (var n : blockEntityNbtList) { BlockEntity entity = BlockEntityHelper.fromNBT(dimension, n); + if (entity == null) continue; Position3ic position = entity.getPosition(); var key = HashUtils.hashChunkXYZ(position.x() & 15, position.y(), position.z() & 15); this.blockEntities.put(key, entity); @@ -84,6 +85,7 @@ public void afterSetChunk(Dimension dimension) { if (entityNbtList != null && !entityNbtList.isEmpty()) { for (var n : entityNbtList) { Entity entity = EntityHelper.fromNBT(dimension, n); + if (entity == null) continue; dimension.getEntityService().addEntity(entity); } entityNbtList = null;