fix: ignore the block when out of bounds

This commit is contained in:
daoge_cmd
2025-10-10 10:03:01 +08:00
parent 0144200ec9
commit 8c532ede8e
5 changed files with 25 additions and 1 deletions

View File

@@ -21,6 +21,13 @@ public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfs
@Override
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
var dimensionInfo = allayChunk.getDimensionInfo();
if (x < 0 || x > 15 ||
z < 0 || z > 15 ||
y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
return;
}
AllayBlockState allayBlockState = (AllayBlockState) data;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {

View File

@@ -7,7 +7,7 @@ import com.dfsek.terra.api.world.ServerWorld;
/**
* NOTICE: Entity is not supported currently, and this is a fake implementation.
* TODO: Entity is not supported currently, and this is a fake implementation.
*
* @author daoge_cmd
*/

View File

@@ -26,6 +26,13 @@ public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk {
@Override
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
var dimensionInfo = allayChunk.getDimensionInfo();
if (x < 0 || x > 15 ||
z < 0 || z > 15 ||
y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
return;
}
AllayBlockState allayBlockState = (AllayBlockState) blockState;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {

View File

@@ -43,6 +43,11 @@ public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAcces
@Override
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
var dimensionInfo = allayServerWorld.allayDimension().getDimensionInfo();
if (y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
return;
}
AllayBlockState allayBlockState = (AllayBlockState) data;
context.setBlockState(x, y, z, allayBlockState.allayBlockState());
if(allayBlockState.containsWater() || context.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {

View File

@@ -27,6 +27,11 @@ public record AllayServerWorld(AllayGeneratorWrapper allayGeneratorWrapper, Dime
@Override
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
var dimensionInfo = allayDimension.getDimensionInfo();
if (y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
return;
}
// In dimension#setBlockState() method, Water will be moved to layer 1 if it is placed at layer 0
allayDimension.setBlockState(x, y, z, ((AllayBlockState) data).allayBlockState());
}