mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
register features
This commit is contained in:
@@ -20,6 +20,7 @@ import com.dfsek.terra.fabric.world.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.world.generator.TerraChunkGeneratorCodec;
|
||||
import com.dfsek.terra.registry.ConfigRegistry;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
@@ -29,28 +30,14 @@ import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.chunk.FlatChunkGeneratorConfig;
|
||||
import net.minecraft.world.gen.chunk.StructuresConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
private static TerraFabricPlugin instance;
|
||||
private final GeneratorType TERRA = new GeneratorType("terra") {
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
FlatChunkGeneratorConfig config = new FlatChunkGeneratorConfig(
|
||||
new StructuresConfig(Optional.empty(), Collections.emptyMap()), biomeRegistry);
|
||||
config.updateLayerBlocks();
|
||||
|
||||
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed), seed);
|
||||
}
|
||||
};
|
||||
private final TerraChunkGeneratorCodec chunkGeneratorCodec = new TerraChunkGeneratorCodec(this);
|
||||
|
||||
public static TerraFabricPlugin getInstance() {
|
||||
@@ -64,6 +51,10 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private File config;
|
||||
|
||||
{
|
||||
logger.setLevel(Level.INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldHandle getWorldHandle() {
|
||||
return worldHandle;
|
||||
@@ -133,9 +124,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
String id = (String) o;
|
||||
if(!id.contains(":")) id = "minecraft:" + id.toLowerCase();
|
||||
Identifier identifier = new Identifier(id);
|
||||
logger.info("Registering Vanilla biome: " + o.toString() + " with ID " + identifier + "/" + id);
|
||||
Biome biome = BuiltinRegistries.BIOME.get(identifier);
|
||||
logger.info("Found " + biome + " in registry.");
|
||||
return new FabricBiome(biome);
|
||||
});
|
||||
}
|
||||
@@ -146,8 +135,18 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
config = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra");
|
||||
LangUtil.load("en_us", this);
|
||||
logger.info("Initializing Terra...");
|
||||
GeneratorTypeAccessor.getValues().add(TERRA);
|
||||
registry.loadAll(this);
|
||||
|
||||
if(FabricLoader.getInstance().getEnvironmentType().equals(EnvType.CLIENT)) {
|
||||
GeneratorTypeAccessor.getValues().add(new GeneratorType("terra") {
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed), seed);
|
||||
}
|
||||
});
|
||||
}
|
||||
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
|
||||
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
||||
}
|
||||
|
||||
public TerraChunkGeneratorCodec getChunkGeneratorCodec() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.fabric.world.generator;
|
||||
|
||||
import com.dfsek.terra.api.gaea.util.FastRandom;
|
||||
import com.dfsek.terra.api.generic.Handle;
|
||||
import com.dfsek.terra.api.generic.generator.TerraBlockPopulator;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.world.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.world.handles.FabricSeededWorldAccess;
|
||||
@@ -10,11 +11,16 @@ import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.structure.StructureManager;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.Heightmap;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.gen.GenerationStep;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.StructuresConfig;
|
||||
@@ -24,7 +30,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
private final long seed;
|
||||
private final TerraChunkGenerator delegate;
|
||||
private final TerraBiomeSource biomeSource;
|
||||
private final Codec<FabricChunkGeneratorWrapper> codec = RecordCodecBuilder.create(instance -> instance.group(
|
||||
public static final Codec<FabricChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
TerraBiomeSource.CODEC.fieldOf("biome_source").forGetter(generator -> generator.biomeSource),
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(generator -> generator.seed))
|
||||
.apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)));
|
||||
@@ -46,7 +52,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
|
||||
@Override
|
||||
protected Codec<? extends ChunkGenerator> getCodec() {
|
||||
return codec;
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,6 +71,29 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
delegate.generateChunkData(worldAccess, new FastRandom(), chunk.getPos().x, chunk.getPos().z, new FabricChunkData(chunk));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
|
||||
// No caves
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
|
||||
for(TerraBlockPopulator populator : delegate.getPopulators()) {
|
||||
//populator.populate();
|
||||
}
|
||||
// Nope
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStructureStarts(DynamicRegistryManager dynamicRegistryManager, StructureAccessor structureAccessor, Chunk chunk, StructureManager structureManager, long worldSeed) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
|
||||
return 0;
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.dfsek.terra.api.generic.world.Chunk;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.api.generic.world.block.Block;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
|
||||
import java.io.File;
|
||||
@@ -14,40 +15,40 @@ import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FabricWorldChunkRegion implements World {
|
||||
private final ChunkRegion delegate;
|
||||
private final Handle delegate;
|
||||
|
||||
public FabricWorldChunkRegion(ChunkRegion delegate) {
|
||||
this.delegate = delegate;
|
||||
public FabricWorldChunkRegion(ChunkRegion delegate, net.minecraft.world.gen.chunk.ChunkGenerator generator) {
|
||||
this.delegate = new Handle(delegate, generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return delegate.getSeed();
|
||||
return delegate.getChunk().getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return delegate.getHeight();
|
||||
return delegate.getChunk().getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return null;
|
||||
return new FabricChunkGenerator(delegate.getGenerator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
return getWorldFolder().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUID() {
|
||||
return null;
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChunkGenerated(int x, int z) {
|
||||
return false;
|
||||
return delegate.chunk.isChunkLoaded(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,4 +85,22 @@ public class FabricWorldChunkRegion implements World {
|
||||
public Object getHandle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Handle {
|
||||
private final ChunkRegion chunk;
|
||||
private final net.minecraft.world.gen.chunk.ChunkGenerator generator;
|
||||
|
||||
public Handle(ChunkRegion chunk, net.minecraft.world.gen.chunk.ChunkGenerator generator) {
|
||||
this.chunk = chunk;
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
public net.minecraft.world.gen.chunk.ChunkGenerator getGenerator() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
public ChunkRegion getChunk() {
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user