feat: start generating features

This commit is contained in:
Christian Bergschneider
2024-12-28 20:05:50 +01:00
parent 7288373dbc
commit f953c5085d
2 changed files with 57 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.minestom.world;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
import com.dfsek.terra.minestom.chunk.CachedChunk;
import com.dfsek.terra.minestom.chunk.GeneratedChunkCache;
@@ -14,9 +15,11 @@ import org.jetbrains.annotations.NotNull;
public class MinestomChunkGeneratorWrapper implements Generator {
private final GeneratedChunkCache cache;
private final ChunkGenerator generator;
private final TerraMinestomWorld world;
public MinestomChunkGeneratorWrapper(ChunkGenerator generator, TerraMinestomWorld world) {
this.generator = generator;
this.world = world;
this.cache = new GeneratedChunkCache(world.getDimensionType(), generator, world);
}
@@ -29,6 +32,20 @@ public class MinestomChunkGeneratorWrapper implements Generator {
Point start = unit.absoluteStart();
CachedChunk chunk = cache.at(start.chunkX(), start.chunkZ());
chunk.writeRelative(unit.modifier());
//chunk.writeRelative(unit.modifier());
unit.fork(setter -> {
MinestomProtoWorld protoWorld = new MinestomProtoWorld(
cache,
start.chunkX(),
start.chunkZ(),
world,
setter
);
for(GenerationStage stage : world.getPack().getStages()) {
stage.populate(protoWorld);
}
});
}
}

View File

@@ -9,27 +9,51 @@ import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
import com.dfsek.terra.minestom.chunk.GeneratedChunkCache;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.Block.Setter;
public class MinestomProtoWorld implements ProtoWorld {
private final GeneratedChunkCache cache;
private final int x;
private final int z;
private final ServerWorld world;
private final Setter modifier;
public MinestomProtoWorld(
GeneratedChunkCache cache,
int x,
int z,
ServerWorld world,
Setter modifier
) {
this.cache = cache;
this.x = x;
this.z = z;
this.world = world;
this.modifier = modifier;
}
@Override
public int centerChunkX() {
return 0;
return x;
}
@Override
public int centerChunkZ() {
return 0;
return z;
}
@Override
public ServerWorld getWorld() {
return null;
return world;
}
@Override
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
modifier.setBlock(this.x * 16 + x, y, this.z * 16 + z, (Block) data.getHandle());
}
@Override
@@ -39,7 +63,10 @@ public class MinestomProtoWorld implements ProtoWorld {
@Override
public BlockState getBlockState(int x, int y, int z) {
return null;
int chunkX = x >> 4;
int chunkZ = z >> 4;
return cache.at(chunkX + this.x, chunkZ + this.z)
.getBlock(x & 15, y, z & 15);
}
@Override
@@ -49,36 +76,36 @@ public class MinestomProtoWorld implements ProtoWorld {
@Override
public ChunkGenerator getGenerator() {
return null;
return world.getGenerator();
}
@Override
public BiomeProvider getBiomeProvider() {
return null;
return world.getBiomeProvider();
}
@Override
public ConfigPack getPack() {
return null;
return world.getPack();
}
@Override
public long getSeed() {
return 0;
return world.getSeed();
}
@Override
public int getMaxHeight() {
return 0;
return world.getMaxHeight();
}
@Override
public int getMinHeight() {
return 0;
return world.getMinHeight();
}
@Override
public Object getHandle() {
return null;
return world;
}
}