From 77dc998673ed79e01c0f82c1f6bf219f58429a9e Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Wed, 19 Jun 2024 18:37:17 +0800 Subject: [PATCH] fix: avoid unnecessary exception during world generating --- .../block/component/common/BlockEntityHolderComponent.java | 2 +- .../allaymc/server/world/generator/AllayWorldGenerator.java | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Allay-API/src/main/java/org/allaymc/api/block/component/common/BlockEntityHolderComponent.java b/Allay-API/src/main/java/org/allaymc/api/block/component/common/BlockEntityHolderComponent.java index 819ea8f58..a3bfa4912 100644 --- a/Allay-API/src/main/java/org/allaymc/api/block/component/common/BlockEntityHolderComponent.java +++ b/Allay-API/src/main/java/org/allaymc/api/block/component/common/BlockEntityHolderComponent.java @@ -44,7 +44,7 @@ default void createBlockEntityAt(int x, int y, int z, Dimension dimension) { } var presentBlockEntity = chunk.getBlockEntity(x & 15, y, z & 15); if (presentBlockEntity != null) { - throw new IllegalStateException("Trying to create a block entity in Dimension: " + dimension + " at pos " + x + ", " + y + ", " + z + "!"); + throw new IllegalStateException("Trying to create a block entity where block entity already exists! Dimension: " + dimension + " at pos " + x + ", " + y + ", " + z + "!"); } var blockEntity = getBlockEntityType().createBlockEntity(SimpleBlockEntityInitInfo.builder().pos(x, y, z).dimension(dimension).build()); chunk.addBlockEntity(blockEntity); diff --git a/Allay-Server/src/main/java/org/allaymc/server/world/generator/AllayWorldGenerator.java b/Allay-Server/src/main/java/org/allaymc/server/world/generator/AllayWorldGenerator.java index ed1605f44..2f1b959d1 100644 --- a/Allay-Server/src/main/java/org/allaymc/server/world/generator/AllayWorldGenerator.java +++ b/Allay-Server/src/main/java/org/allaymc/server/world/generator/AllayWorldGenerator.java @@ -111,10 +111,6 @@ public Chunk generateChunk(int x, int z) { } private Chunk getOrGenerateProtoChunk(int x, int z) { - if (protoChunkBeingSet(x, z)) { - log.error("Trying to access a proto chunk which is being set: x: " + x + ", z: " + z); - return AllayUnsafeChunk.builder().emptyChunk(x, z, dimension.getDimensionInfo()).toSafeChunk(); - } CompletableFuture future = new CompletableFuture<>(); // 这里的putIfAbsent()保证了只有一个线程可以写入future,其他线程只能获取这一个线程写入的future var presentFuture = protoChunks.putIfAbsent(HashUtils.hashXZ(x, z), future); @@ -207,7 +203,7 @@ public Chunk getChunk(int x, int z) { // 先获取future,避免在此过程中区块完成加载导致future被删除 CompletableFuture future = chunkService.getChunkLoadingFuture(x, z); - if (protoChunkBeingSet(x, z)) { + if (future != null && protoChunkBeingSet(x, z)) { // 即使在此过程中future被删除(区块完成加载),此代码依然可以工作因为 // 区块完成加载后,future.join()等效于chunkService.getChunk(x, z) return future.join();