mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 23:06:05 +00:00
feat: use OtherChunkAccessibleContext directly
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user