From e68f928e3845eb425b2c4b0e10a1bbb186ab041b Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Tue, 18 Jun 2024 14:59:42 +0800 Subject: [PATCH] feat: use OtherChunkAccessibleContext directly --- .../terra/allay/delegate/AllayProtoWorld.java | 41 ++++--------------- .../generator/AllayGeneratorWrapper.java | 3 +- 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/platforms/allay/src/main/java/org/allaymc/terra/allay/delegate/AllayProtoWorld.java b/platforms/allay/src/main/java/org/allaymc/terra/allay/delegate/AllayProtoWorld.java index a0e93b972..d7a8b2b7b 100644 --- a/platforms/allay/src/main/java/org/allaymc/terra/allay/delegate/AllayProtoWorld.java +++ b/platforms/allay/src/main/java/org/allaymc/terra/allay/delegate/AllayProtoWorld.java @@ -4,6 +4,7 @@ import com.dfsek.terra.api.util.vector.Vector3; import org.allaymc.api.world.chunk.ChunkAccessible; import org.allaymc.api.world.chunk.UnsafeChunk; +import org.allaymc.api.world.generator.context.OtherChunkAccessibleContext; import org.allaymc.terra.allay.Mapping; import com.dfsek.terra.api.block.entity.BlockEntity; @@ -21,16 +22,16 @@ import com.dfsek.terra.api.world.chunk.generation.ProtoWorld; * * @author daoge_cmd */ -public record AllayProtoWorld(AllayServerWorld allayServerWorld, UnsafeChunk centerChunk, ChunkAccessible chunkAccessor) implements ProtoWorld { +public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAccessibleContext context) implements ProtoWorld { @Override public int centerChunkX() { - return centerChunk.getX(); + return context.getCurrentChunk().getX(); } @Override public int centerChunkZ() { - return centerChunk.getZ(); + return context.getCurrentChunk().getZ(); } @Override @@ -40,16 +41,13 @@ public record AllayProtoWorld(AllayServerWorld allayServerWorld, UnsafeChunk cen @Override public void setBlockState(int x, int y, int z, BlockState data, boolean physics) { - if(isInCurrentChunk(x, y, z)) { - centerChunk.setBlockState(x & 15, y, z & 15, ((AllayBlockState)data).allayBlockState()); - } else { - setBlockStateInOtherChunk(x, y, z, data, physics); - } + context.setBlockState(x & 15, y, z & 15, ((AllayBlockState)data).allayBlockState()); } - private void setBlockStateInOtherChunk(int x, int y, int z, BlockState data, boolean physics) { - var chunk = chunkAccessor.getChunk(x >> 4, z >> 4); - chunk.setBlockState(x & 15, y, z & 15, ((AllayBlockState)data).allayBlockState()); + @Override + public BlockState getBlockState(int x, int y, int z) { + var blockState = context.getBlockState(x & 15, y, z & 15); + return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState)); } @Override @@ -57,20 +55,6 @@ public record AllayProtoWorld(AllayServerWorld allayServerWorld, UnsafeChunk cen return new AllayFakeEntity(Vector3.of(x, y, z), allayServerWorld); } - @Override - public BlockState getBlockState(int x, int y, int z) { - if(isInCurrentChunk(x, y, z)) { - var blockState = centerChunk.getBlockState(x & 15, y, z & 15); - return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState)); - } - return getBlockStateInOtherChunk(x, y, z); - } - - private BlockState getBlockStateInOtherChunk(int x, int y, int z) { - var chunk = chunkAccessor.getChunk(x >> 4, z >> 4); - return new AllayBlockState(chunk.getBlockState(x & 15, y, z & 15), Mapping.blockStateBeToJe(chunk.getBlockState(x & 15, y, z & 15))); - } - @Override public BlockEntity getBlockEntity(int x, int y, int z) { // TODO @@ -111,11 +95,4 @@ public record AllayProtoWorld(AllayServerWorld allayServerWorld, UnsafeChunk cen public AllayServerWorld getHandle() { return allayServerWorld; } - - private boolean isInCurrentChunk(int x, int y, int z) { - return - x >= centerChunkX() * 16 && x < centerChunkX() * 16 + 16 && - z >= centerChunkZ() * 16 && z < centerChunkZ() * 16 + 16 && - y >= getMinHeight() && y <= getMaxHeight(); - } } \ No newline at end of file diff --git a/platforms/allay/src/main/java/org/allaymc/terra/allay/generator/AllayGeneratorWrapper.java b/platforms/allay/src/main/java/org/allaymc/terra/allay/generator/AllayGeneratorWrapper.java index 56d273f50..a9c979658 100644 --- a/platforms/allay/src/main/java/org/allaymc/terra/allay/generator/AllayGeneratorWrapper.java +++ b/platforms/allay/src/main/java/org/allaymc/terra/allay/generator/AllayGeneratorWrapper.java @@ -125,8 +125,7 @@ public class AllayGeneratorWrapper implements GeneratorWrapper { @Override public Boolean apply(PopulateContext context) { - var chunk = context.getCurrentChunk(); - var tmp = new AllayProtoWorld(allayServerWorld, chunk, context.getChunkAccessor()); + var tmp = new AllayProtoWorld(allayServerWorld, context); try { for (var generationStage : configPack.getStages()) { generationStage.populate(tmp);