mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
BiomeGrid no longer needs World object.
This commit is contained in:
@@ -35,7 +35,7 @@ public class TerraWorld {
|
||||
String partName = template.getGrids().get(i);
|
||||
try {
|
||||
BiomeGridBuilder g = config.getBiomeGrid(partName);
|
||||
BiomeGrid b = g.build(w, c);
|
||||
BiomeGrid b = g.build(w.getSeed(), c);
|
||||
definedGrids[i] = b;
|
||||
} catch(NullPointerException e) {
|
||||
safe = false;
|
||||
@@ -46,12 +46,12 @@ public class TerraWorld {
|
||||
main.getLogger().severe("Terrain will NOT generate properly at this point. Correct your config before using your server!");
|
||||
}
|
||||
}
|
||||
zone = new BiomeZone(w, c, definedGrids);
|
||||
zone = new BiomeZone(w.getSeed(), c, definedGrids);
|
||||
|
||||
if(template.getGridType().equals(TerraBiomeGrid.Type.RADIAL)) {
|
||||
BiomeGrid internal = config.getBiomeGrid(template.getRadialInternalGrid()).build(w, c);
|
||||
grid = new TerraRadialBiomeGrid(w, template.getGridFreqX(), template.getGridFreqZ(), zone, config, template.getRadialGridRadius(), internal);
|
||||
} else grid = new TerraStandardBiomeGrid(w, template.getGridFreqX(), template.getGridFreqZ(), zone, config);
|
||||
BiomeGrid internal = config.getBiomeGrid(template.getRadialInternalGrid()).build(w.getSeed(), c);
|
||||
grid = new TerraRadialBiomeGrid(w.getSeed(), template.getGridFreqX(), template.getGridFreqZ(), zone, config, template.getRadialGridRadius(), internal);
|
||||
} else grid = new TerraStandardBiomeGrid(w.getSeed(), template.getGridFreqX(), template.getGridFreqZ(), zone, config);
|
||||
}
|
||||
|
||||
public static boolean isTerraWorld(World w) {
|
||||
|
||||
@@ -2,24 +2,21 @@ package com.dfsek.terra.api.gaea.biome;
|
||||
|
||||
import com.dfsek.terra.api.gaea.generation.GenerationPhase;
|
||||
import com.dfsek.terra.api.gaea.math.FastNoiseLite;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
|
||||
public abstract class BiomeGrid {
|
||||
private final FastNoiseLite noiseX;
|
||||
private final FastNoiseLite noiseZ;
|
||||
private final World world;
|
||||
private final int sizeX;
|
||||
private final int sizeZ;
|
||||
private Biome[][] grid;
|
||||
|
||||
|
||||
public BiomeGrid(World w, double freq1, double freq2, int sizeX, int sizeZ) {
|
||||
public BiomeGrid(long seed, double freq1, double freq2, int sizeX, int sizeZ) {
|
||||
this.sizeX = sizeX;
|
||||
this.sizeZ = sizeZ;
|
||||
this.world = w;
|
||||
this.noiseX = new FastNoiseLite((int) w.getSeed());
|
||||
this.noiseZ = new FastNoiseLite((int) w.getSeed() + 1);
|
||||
this.noiseX = new FastNoiseLite((int) seed);
|
||||
this.noiseZ = new FastNoiseLite((int) seed + 1);
|
||||
this.noiseX.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
this.noiseX.setFractalType(FastNoiseLite.FractalType.FBm);
|
||||
this.noiseX.setFractalOctaves(4);
|
||||
@@ -96,10 +93,6 @@ public abstract class BiomeGrid {
|
||||
return grid[normalize(biomeNoise, sizeX)][normalize(climateNoise, sizeZ)];
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public int getSizeX() {
|
||||
return sizeX;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.biome;
|
||||
import com.dfsek.terra.api.gaea.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.gaea.biome.NormalizationUtil;
|
||||
import com.dfsek.terra.api.gaea.math.FastNoiseLite;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
@@ -22,8 +21,8 @@ public class BiomeZone {
|
||||
private final boolean useImage;
|
||||
private final ImageLoader.Channel channel;
|
||||
|
||||
public BiomeZone(World w, ConfigPack wc, BiomeGrid[] grids) {
|
||||
this.noise = new FastNoiseLite((int) w.getSeed() + 2);
|
||||
public BiomeZone(long seed, ConfigPack wc, BiomeGrid[] grids) {
|
||||
this.noise = new FastNoiseLite((int) seed + 2);
|
||||
this.noise.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
this.noise.setFractalType(FastNoiseLite.FractalType.FBm);
|
||||
this.noise.setFractalOctaves(4);
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.biome.grid;
|
||||
import com.dfsek.terra.api.gaea.biome.Biome;
|
||||
import com.dfsek.terra.api.gaea.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.gaea.generation.GenerationPhase;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
|
||||
/**
|
||||
@@ -12,8 +11,8 @@ import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
public class SingleBiomeGrid extends BiomeGrid {
|
||||
private final Biome biome;
|
||||
|
||||
public SingleBiomeGrid(World w, Biome biome) {
|
||||
super(w, 0, 0, 1, 1);
|
||||
public SingleBiomeGrid(long seed, Biome biome) {
|
||||
super(seed, 0, 0, 1, 1);
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.gaea.biome.Biome;
|
||||
import com.dfsek.terra.api.gaea.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.gaea.biome.NormalizationUtil;
|
||||
import com.dfsek.terra.api.gaea.generation.GenerationPhase;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.base.ConfigPackTemplate;
|
||||
@@ -16,8 +15,8 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
private final ImageLoader.Channel channelX;
|
||||
private final ImageLoader.Channel channelZ;
|
||||
|
||||
public UserDefinedGrid(World w, double freq1, double freq2, Biome[][] b, ConfigPack c) {
|
||||
super(w, freq1, freq2, b.length, b[0].length);
|
||||
public UserDefinedGrid(long seed, double freq1, double freq2, Biome[][] b, ConfigPack c) {
|
||||
super(seed, freq1, freq2, b.length, b[0].length);
|
||||
super.setGrid(b);
|
||||
ConfigPackTemplate t = c.getTemplate();
|
||||
imageLoader = t.getImageLoader();
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.dfsek.terra.biome.grid.master;
|
||||
|
||||
import com.dfsek.terra.api.gaea.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.biome.grid.UserDefinedGrid;
|
||||
|
||||
public abstract class TerraBiomeGrid extends BiomeGrid {
|
||||
public TerraBiomeGrid(World w, double freq1, double freq2, int sizeX, int sizeZ) {
|
||||
super(w, freq1, freq2, sizeX, sizeZ);
|
||||
public TerraBiomeGrid(long seed, double freq1, double freq2, int sizeX, int sizeZ) {
|
||||
super(seed, freq1, freq2, sizeX, sizeZ);
|
||||
}
|
||||
|
||||
public abstract UserDefinedGrid getGrid(int x, int z);
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.biome.grid.master;
|
||||
import com.dfsek.terra.api.gaea.biome.Biome;
|
||||
import com.dfsek.terra.api.gaea.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.gaea.generation.GenerationPhase;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
import com.dfsek.terra.api.generic.world.vector.Vector2;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
@@ -23,15 +22,15 @@ public class TerraRadialBiomeGrid extends TerraBiomeGrid {
|
||||
private CoordinatePerturb perturb;
|
||||
private ErosionNoise erode;
|
||||
|
||||
public TerraRadialBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c, double radius, BiomeGrid internal) {
|
||||
super(w, freq1, freq2, 0, 0);
|
||||
public TerraRadialBiomeGrid(long seed, double freq1, double freq2, BiomeZone zone, ConfigPack c, double radius, BiomeGrid internal) {
|
||||
super(seed, freq1, freq2, 0, 0);
|
||||
ConfigPackTemplate t = c.getTemplate();
|
||||
if(c.getTemplate().isBlend()) {
|
||||
perturb = new CoordinatePerturb(t.getBlendFreq(), t.getBlendAmp(), w.getSeed());
|
||||
perturb = new CoordinatePerturb(t.getBlendFreq(), t.getBlendAmp(), seed);
|
||||
}
|
||||
this.zone = zone;
|
||||
if(c.getTemplate().isErode()) {
|
||||
erode = new ErosionNoise(t.getErodeFreq(), t.getErodeThresh(), t.getErodeOctaves(), w.getSeed());
|
||||
erode = new ErosionNoise(t.getErodeFreq(), t.getErodeThresh(), t.getErodeOctaves(), seed);
|
||||
}
|
||||
this.radiusSq = FastMath.pow2(radius);
|
||||
this.internal = internal;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.biome.grid.master;
|
||||
|
||||
import com.dfsek.terra.api.gaea.biome.Biome;
|
||||
import com.dfsek.terra.api.gaea.generation.GenerationPhase;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
import com.dfsek.terra.api.generic.world.vector.Vector2;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
@@ -19,15 +18,15 @@ public class TerraStandardBiomeGrid extends TerraBiomeGrid {
|
||||
private CoordinatePerturb perturb;
|
||||
private ErosionNoise erode;
|
||||
|
||||
public TerraStandardBiomeGrid(World w, double freq1, double freq2, BiomeZone zone, ConfigPack c) {
|
||||
super(w, freq1, freq2, 0, 0);
|
||||
public TerraStandardBiomeGrid(long seed, double freq1, double freq2, BiomeZone zone, ConfigPack c) {
|
||||
super(seed, freq1, freq2, 0, 0);
|
||||
ConfigPackTemplate t = c.getTemplate();
|
||||
if(c.getTemplate().isBlend()) {
|
||||
perturb = new CoordinatePerturb(t.getBlendFreq(), t.getBlendAmp(), w.getSeed());
|
||||
perturb = new CoordinatePerturb(t.getBlendFreq(), t.getBlendAmp(), seed);
|
||||
}
|
||||
this.zone = zone;
|
||||
if(c.getTemplate().isErode()) {
|
||||
erode = new ErosionNoise(t.getErodeFreq(), t.getErodeThresh(), t.getErodeOctaves(), w.getSeed());
|
||||
erode = new ErosionNoise(t.getErodeFreq(), t.getErodeThresh(), t.getErodeOctaves(), seed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.api.gaea.biome.BiomeGrid;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
|
||||
public interface BiomeGridBuilder {
|
||||
BiomeGrid build(World world, ConfigPack config);
|
||||
BiomeGrid build(long seed, ConfigPack config);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.api.gaea.biome.Biome;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.biome.grid.SingleBiomeGrid;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
|
||||
@@ -13,7 +12,7 @@ public class SingleGridBuilder implements BiomeGridBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingleBiomeGrid build(World world, ConfigPack config) {
|
||||
return new SingleBiomeGrid(world, biome);
|
||||
public SingleBiomeGrid build(long seed, ConfigPack config) {
|
||||
return new SingleBiomeGrid(seed, biome);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.config.builder.biomegrid;
|
||||
|
||||
import com.dfsek.terra.api.gaea.biome.Biome;
|
||||
import com.dfsek.terra.api.generic.world.World;
|
||||
import com.dfsek.terra.biome.grid.UserDefinedGrid;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
|
||||
@@ -12,8 +11,8 @@ public class UserDefinedGridBuilder implements BiomeGridBuilder {
|
||||
private Biome[][] biomes;
|
||||
|
||||
@Override
|
||||
public UserDefinedGrid build(World world, ConfigPack config) {
|
||||
return new UserDefinedGrid(world, 1D / xFreq, 1D / zFreq, biomes, config);
|
||||
public UserDefinedGrid build(long seed, ConfigPack config) {
|
||||
return new UserDefinedGrid(seed, 1D / xFreq, 1D / zFreq, biomes, config);
|
||||
}
|
||||
|
||||
public double getXFreq() {
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.dfsek.terra.fabric.inventory.FabricItemHandle;
|
||||
import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor;
|
||||
import com.dfsek.terra.fabric.world.FabricBiome;
|
||||
import com.dfsek.terra.fabric.world.FabricWorldHandle;
|
||||
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;
|
||||
@@ -24,7 +25,6 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.world.GeneratorType;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.VanillaLayeredBiomeSource;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.chunk.FlatChunkGeneratorConfig;
|
||||
@@ -45,7 +45,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
new StructuresConfig(Optional.empty(), Collections.emptyMap()), biomeRegistry);
|
||||
config.updateLayerBlocks();
|
||||
|
||||
return new FabricChunkGeneratorWrapper(new VanillaLayeredBiomeSource(seed, false, false, biomeRegistry), seed);
|
||||
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed), seed);
|
||||
}
|
||||
};
|
||||
private final TerraChunkGeneratorCodec chunkGeneratorCodec = new TerraChunkGeneratorCodec(this);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.fabric.codec;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
|
||||
public class ConfigPackCodec implements Codec<ConfigPack> {
|
||||
@Override
|
||||
public <T> DataResult<Pair<ConfigPack, T>> decode(DynamicOps<T> ops, T input) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DataResult<T> encode(ConfigPack input, DynamicOps<T> ops, T prefix) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.dfsek.terra.fabric.world;
|
||||
|
||||
import com.dfsek.terra.registry.TerraRegistry;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class FabricBiomeRegistry extends TerraRegistry<Biome> {
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.dfsek.terra.fabric.world;
|
||||
|
||||
import com.dfsek.terra.api.generic.TerraPlugin;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryLookupCodec;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TerraBiomeSource extends BiomeSource {
|
||||
public static final Codec<TerraBiomeSource> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter(source -> source.biomeRegistry),
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(source -> source.seed))
|
||||
.apply(instance, instance.stable(TerraBiomeSource::new)));
|
||||
|
||||
private final Registry<Biome> biomeRegistry;
|
||||
private final long seed;
|
||||
private final TerraPlugin main;
|
||||
|
||||
public TerraBiomeSource(Registry<Biome> biomes, long seed) {
|
||||
super(biomes.stream().collect(Collectors.toList()));
|
||||
this.biomeRegistry = biomes;
|
||||
this.seed = seed;
|
||||
this.main = TerraFabricPlugin.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Codec<? extends BiomeSource> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeSource withSeed(long seed) {
|
||||
return new TerraBiomeSource(this.biomeRegistry, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user