Biome size config value

This commit is contained in:
paulevsGitch 2020-12-31 08:05:18 +03:00
parent 1d95a4c771
commit b76b122784
5 changed files with 50 additions and 26 deletions

View file

@ -1,11 +1,17 @@
package ru.betterend.config; package ru.betterend.config;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import ru.betterend.BetterEnd;
public class Configs { public class Configs {
public static final PathConfig ENTITY_CONFIG = new PathConfig("entities"); public static final PathConfig ENTITY_CONFIG = new PathConfig("entities");
public static final PathConfig BLOCK_CONFIG = new PathConfig("blocks"); public static final PathConfig BLOCK_CONFIG = new PathConfig("blocks");
public static final PathConfig ITEM_CONFIG = new PathConfig("items"); public static final PathConfig ITEM_CONFIG = new PathConfig("items");
public static final IdConfig BIOME_CONFIG = new EntryConfig("biomes"); public static final IdConfig BIOME_CONFIG = new EntryConfig("biomes");
public static final PathConfig GENERATOR_CONFIG = new PathConfig("generator"); public static final PathConfig GENERATOR_CONFIG = new PathConfig("generator");
@Environment(value = EnvType.CLIENT)
public static final PathConfig CLENT_CONFIG = new PathConfig("client"); public static final PathConfig CLENT_CONFIG = new PathConfig("client");
public static void saveConfigs() { public static void saveConfigs() {
@ -14,6 +20,9 @@ public class Configs {
BIOME_CONFIG.saveChanges(); BIOME_CONFIG.saveChanges();
ITEM_CONFIG.saveChanges(); ITEM_CONFIG.saveChanges();
GENERATOR_CONFIG.saveChanges(); GENERATOR_CONFIG.saveChanges();
CLENT_CONFIG.saveChanges();
if (BetterEnd.isClient()) {
CLENT_CONFIG.saveChanges();
}
} }
} }

View file

@ -42,8 +42,8 @@ public class BetterEndBiomeSource extends BiomeSource {
public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) { public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(getBiomes(biomeRegistry)); super(getBiomes(biomeRegistry));
this.mapLand = new BiomeMap(seed, 256, EndBiomes.LAND_BIOMES); this.mapLand = new BiomeMap(seed, GeneratorOptions.getBiomeSizeLand(), EndBiomes.LAND_BIOMES);
this.mapVoid = new BiomeMap(seed, 256, EndBiomes.VOID_BIOMES); this.mapVoid = new BiomeMap(seed, GeneratorOptions.getBiomeSizeVoid(), EndBiomes.VOID_BIOMES);
this.centerBiome = biomeRegistry.getOrThrow(BiomeKeys.THE_END); this.centerBiome = biomeRegistry.getOrThrow(BiomeKeys.THE_END);
this.barrens = biomeRegistry.getOrThrow(BiomeKeys.END_BARRENS); this.barrens = biomeRegistry.getOrThrow(BiomeKeys.END_BARRENS);
this.biomeRegistry = biomeRegistry; this.biomeRegistry = biomeRegistry;

View file

@ -1,6 +1,8 @@
package ru.betterend.world.generator; package ru.betterend.world.generator;
import java.util.HashMap; import java.util.Map;
import com.google.common.collect.Maps;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.gen.ChunkRandom; import net.minecraft.world.gen.ChunkRandom;
@ -8,11 +10,10 @@ import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
import ru.betterend.world.biome.EndBiome; import ru.betterend.world.biome.EndBiome;
public class BiomeMap public class BiomeMap {
{
private static final ChunkRandom RANDOM = new ChunkRandom(); private static final ChunkRandom RANDOM = new ChunkRandom();
private final HashMap<ChunkPos, BiomeChunk> maps = new HashMap<ChunkPos, BiomeChunk>(); private final Map<ChunkPos, BiomeChunk> maps = Maps.newHashMap();
private final int size; private final int size;
private final int sizeXZ; private final int sizeXZ;
private final int depth; private final int depth;
@ -20,8 +21,7 @@ public class BiomeMap
private final OpenSimplexNoise noiseZ; private final OpenSimplexNoise noiseZ;
private final BiomePicker picker; private final BiomePicker picker;
public BiomeMap(long seed, int size, BiomePicker picker) public BiomeMap(long seed, int size, BiomePicker picker) {
{
maps.clear(); maps.clear();
RANDOM.setSeed(seed); RANDOM.setSeed(seed);
noiseX = new OpenSimplexNoise(RANDOM.nextLong()); noiseX = new OpenSimplexNoise(RANDOM.nextLong());
@ -32,15 +32,13 @@ public class BiomeMap
this.picker = picker; this.picker = picker;
} }
public void clearCache() public void clearCache() {
{
if (maps.size() > 32) { if (maps.size() > 32) {
maps.clear(); maps.clear();
} }
} }
private EndBiome getRawBiome(int bx, int bz) private EndBiome getRawBiome(int bx, int bz) {
{
double x = (double) bx * size / sizeXZ; double x = (double) bx * size / sizeXZ;
double z = (double) bz * size / sizeXZ; double z = (double) bz * size / sizeXZ;
double nx = x; double nx = x;
@ -49,8 +47,7 @@ public class BiomeMap
double px = bx * 0.2; double px = bx * 0.2;
double pz = bz * 0.2; double pz = bz * 0.2;
for (int i = 0; i < depth; i++) for (int i = 0; i < depth; i++) {
{
nx = (x + noiseX.eval(px, pz)) / 2F; nx = (x + noiseX.eval(px, pz)) / 2F;
nz = (z + noiseZ.eval(px, pz)) / 2F; nz = (z + noiseZ.eval(px, pz)) / 2F;
@ -72,8 +69,7 @@ public class BiomeMap
ChunkPos cpos = new ChunkPos(MHelper.floor(x / BiomeChunk.WIDTH), MHelper.floor(z / BiomeChunk.WIDTH)); ChunkPos cpos = new ChunkPos(MHelper.floor(x / BiomeChunk.WIDTH), MHelper.floor(z / BiomeChunk.WIDTH));
BiomeChunk chunk = maps.get(cpos); BiomeChunk chunk = maps.get(cpos);
if (chunk == null) if (chunk == null) {
{
RANDOM.setTerrainSeed(cpos.x, cpos.z); RANDOM.setTerrainSeed(cpos.x, cpos.z);
chunk = new BiomeChunk(this, RANDOM, picker); chunk = new BiomeChunk(this, RANDOM, picker);
maps.put(cpos, chunk); maps.put(cpos, chunk);
@ -82,15 +78,14 @@ public class BiomeMap
return chunk.getBiome(MHelper.floor(x), MHelper.floor(z)); return chunk.getBiome(MHelper.floor(x), MHelper.floor(z));
} }
public EndBiome getBiome(int x, int z) public EndBiome getBiome(int x, int z) {
{
EndBiome biome = getRawBiome(x, z); EndBiome biome = getRawBiome(x, z);
if (biome.hasEdge() || (biome.hasParentBiome() && biome.getParentBiome().hasEdge())) if (biome.hasEdge() || (biome.hasParentBiome() && biome.getParentBiome().hasEdge())) {
{
EndBiome search = biome; EndBiome search = biome;
if (biome.hasParentBiome()) if (biome.hasParentBiome()) {
search = biome.getParentBiome(); search = biome.getParentBiome();
}
int d = (int) Math.ceil(search.getEdgeSize() / 4F) << 2; int d = (int) Math.ceil(search.getEdgeSize() / 4F) << 2;
boolean edge = !search.isSame(getRawBiome(x + d, z)); boolean edge = !search.isSame(getRawBiome(x + d, z));
@ -102,8 +97,7 @@ public class BiomeMap
edge = edge || !search.isSame(getRawBiome(x + 1, z - 1)); edge = edge || !search.isSame(getRawBiome(x + 1, z - 1));
edge = edge || !search.isSame(getRawBiome(x + 1, z + 1)); edge = edge || !search.isSame(getRawBiome(x + 1, z + 1));
if (edge) if (edge) {
{
biome = search.getEdge(); biome = search.getEdge();
} }
} }

View file

@ -0,0 +1,21 @@
package ru.betterend.world.generator;
import ru.betterend.config.Configs;
public class GeneratorOptions {
private static int biomeSizeLand;
private static int biomeSizeVoid;
public static void init() {
biomeSizeLand = Configs.GENERATOR_CONFIG.getIntRoot("biomeSizeLand", 256);
biomeSizeVoid = Configs.GENERATOR_CONFIG.getIntRoot("biomeSizeVoid", 256);
}
public static int getBiomeSizeLand() {
return biomeSizeLand;
}
public static int getBiomeSizeVoid() {
return biomeSizeVoid;
}
}

View file

@ -22,8 +22,8 @@ public class TerrainGenerator {
private static boolean noRingVoid; private static boolean noRingVoid;
public static void init() { public static void init() {
newGenerator = Configs.GENERATOR_CONFIG.getBoolean("generator", "useNewGenerator", false); newGenerator = Configs.GENERATOR_CONFIG.getBooleanRoot("useNewGenerator", false);
noRingVoid = Configs.GENERATOR_CONFIG.getBoolean("generator", "noRingVoid", false); noRingVoid = Configs.GENERATOR_CONFIG.getBooleanRoot("noRingVoid", false);
} }
public static void initNoise(long seed) { public static void initNoise(long seed) {