clean up ChunkGenerator

This commit is contained in:
dfsek
2021-11-27 08:55:40 -07:00
parent 7a3597a722
commit 50da6d9d9b
7 changed files with 21 additions and 15 deletions

View File

@@ -26,7 +26,7 @@ import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.biome.GenerationSettings;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.api.world.generator.ProtoChunk;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.api.world.generator.GenerationStage;
import com.dfsek.terra.api.world.generator.Palette;
@@ -48,7 +48,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
@Override
@SuppressWarnings("try")
public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) {
public void generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ProtoChunk chunk) {
try(ProfileFrame ignore = platform.getProfiler().profile("chunk_base_3d")) {
BiomeProvider grid = world.getBiomeProvider();
@@ -92,7 +92,6 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
}
}
}
return chunk;
}
}

View File

@@ -7,6 +7,8 @@
package com.dfsek.terra.api.world.generator;
import com.dfsek.terra.api.util.vector.integer.Vector3Int;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -22,7 +24,7 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
public interface ChunkGenerator {
ChunkData generateChunkData(@NotNull World world, Random random, int x, int z, ChunkData original);
void generateChunkData(@NotNull World world, Random random, int x, int z, ProtoChunk original);
Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth);
ConfigPack getConfigPack();
@@ -36,4 +38,8 @@ public interface ChunkGenerator {
default BlockState getBlock(World world, Vector3 vector3) {
return getBlock(world, vector3.getBlockX(), vector3.getBlockY(), vector3.getBlockZ());
}
default BlockState getBlock(World world, Vector3Int vector3) {
return getBlock(world, vector3.getX(), vector3.getY(), vector3.getZ());
}
}

View File

@@ -10,7 +10,7 @@ package com.dfsek.terra.api.world.generator;
import com.dfsek.terra.api.world.ChunkAccess;
public interface ChunkData extends ChunkAccess {
public interface ProtoChunk extends ChunkAccess {
/**
* Get the maximum height for the chunk.
* <p>

View File

@@ -93,7 +93,9 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
}
com.dfsek.terra.api.world.World bukkitWorld = BukkitAdapter.adapt(world);
if(needsLoad) load(bukkitWorld); // Load population data for world.
return (ChunkData) delegate.generateChunkData(bukkitWorld, random, x, z, new BukkitChunkData(createChunkData(world))).getHandle();
ChunkData data = createChunkData(world);
delegate.generateChunkData(bukkitWorld, random, x, z, new BukkitProtoChunk(data));
return data;
}
@Override

View File

@@ -21,15 +21,15 @@ import org.bukkit.generator.ChunkGenerator;
import org.jetbrains.annotations.NotNull;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.api.world.generator.ProtoChunk;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
public class BukkitChunkData implements ChunkData {
public class BukkitProtoChunk implements ProtoChunk {
private final ChunkGenerator.ChunkData delegate;
public BukkitChunkData(ChunkGenerator.ChunkData delegate) {
public BukkitProtoChunk(ChunkGenerator.ChunkData delegate) {
this.delegate = delegate;
}

View File

@@ -55,7 +55,7 @@ import java.util.concurrent.Executor;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.api.world.generator.ProtoChunk;
import com.dfsek.terra.api.world.generator.ChunkGenerator;
import com.dfsek.terra.api.world.generator.Chunkified;
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
@@ -193,7 +193,7 @@ public class FabricChunkGeneratorWrapper extends net.minecraft.world.gen.chunk.C
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender arg, StructureAccessor structureAccessor, Chunk chunk) {
return CompletableFuture.supplyAsync(() -> {
World world = (World) ((StructureAccessorAccessor) structureAccessor).getWorld();
delegate.generateChunkData(world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
delegate.generateChunkData(world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ProtoChunk) chunk);
delegate.getGenerationStages().forEach(populator -> {
if(populator instanceof Chunkified) {
populator.populate(world, (com.dfsek.terra.api.world.Chunk) world);

View File

@@ -18,7 +18,6 @@
package com.dfsek.terra.fabric.mixin.implementations.chunk.data;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.chunk.ProtoChunk;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Interface;
@@ -27,12 +26,12 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.api.world.generator.ProtoChunk;
import com.dfsek.terra.fabric.block.FabricBlockState;
@Mixin(ProtoChunk.class)
@Implements(@Interface(iface = ChunkData.class, prefix = "terra$", remap = Interface.Remap.NONE))
@Mixin(net.minecraft.world.chunk.ProtoChunk.class)
@Implements(@Interface(iface = ProtoChunk.class, prefix = "terra$", remap = Interface.Remap.NONE))
public abstract class ProtoChunkMixin {
@Shadow
public abstract net.minecraft.block.BlockState getBlockState(BlockPos pos);