Generator config

This commit is contained in:
paulevsGitch 2020-12-28 17:59:00 +03:00
parent 9a41dc8670
commit 078139a26f
5 changed files with 44 additions and 22 deletions

View file

@ -27,6 +27,7 @@ import ru.betterend.registry.EndTags;
import ru.betterend.util.BonemealUtil; import ru.betterend.util.BonemealUtil;
import ru.betterend.util.Logger; import ru.betterend.util.Logger;
import ru.betterend.world.generator.BetterEndBiomeSource; import ru.betterend.world.generator.BetterEndBiomeSource;
import ru.betterend.world.generator.TerrainGenerator;
import ru.betterend.world.surface.SurfaceBuilders; import ru.betterend.world.surface.SurfaceBuilders;
public class BetterEnd implements ModInitializer { public class BetterEnd implements ModInitializer {
@ -54,6 +55,7 @@ public class BetterEnd implements ModInitializer {
EndStructures.register(); EndStructures.register();
Integrations.register(); Integrations.register();
BonemealUtil.init(); BonemealUtil.init();
TerrainGenerator.init();
if (hasGuideBook()) { if (hasGuideBook()) {
GuideBook.register(); GuideBook.register();

View file

@ -13,11 +13,15 @@ public class Configs {
public static final IdConfig ENTITY_CONFIG = new IdConfig("entities", (entityId, category) -> { public static final IdConfig ENTITY_CONFIG = new IdConfig("entities", (entityId, category) -> {
return new ConfigKey(entityId.getNamespace(), category, entityId.getPath()); return new ConfigKey(entityId.getNamespace(), category, entityId.getPath());
}); });
public static final IdConfig GENERATOR_CONFIG = new IdConfig("generator", (entityId, category) -> {
return new ConfigKey(entityId.getNamespace(), category, entityId.getPath());
});
public static void saveConfigs() { public static void saveConfigs() {
ITEM_CONFIG.saveChanges(); ITEM_CONFIG.saveChanges();
BLOCK_CONFIG.saveChanges(); BLOCK_CONFIG.saveChanges();
BIOME_CONFIG.saveChanges(); BIOME_CONFIG.saveChanges();
ENTITY_CONFIG.saveChanges(); ENTITY_CONFIG.saveChanges();
GENERATOR_CONFIG.saveChanges();
} }
} }

View file

@ -27,7 +27,7 @@ public abstract class NoiseChunkGeneratorMixin {
@Inject(method = "sampleNoiseColumn([DII)V", at = @At("HEAD"), cancellable = true, allow = 2) @Inject(method = "sampleNoiseColumn([DII)V", at = @At("HEAD"), cancellable = true, allow = 2)
private void beSampleNoiseColumn(double[] buffer, int x, int z, CallbackInfo info) { private void beSampleNoiseColumn(double[] buffer, int x, int z, CallbackInfo info) {
if (settings.get().equals(ChunkGeneratorSettings.END)) { if (TerrainGenerator.useNewGenerator() && settings.get().equals(ChunkGeneratorSettings.END)) {
if (TerrainGenerator.canGenerate(x, z)) { if (TerrainGenerator.canGenerate(x, z)) {
TerrainGenerator.fillTerrainDensity(buffer, x, z); TerrainGenerator.fillTerrainDensity(buffer, x, z);
info.cancel(); info.cancel();

View file

@ -13,12 +13,14 @@ import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Category; import net.minecraft.world.biome.Biome.Category;
import net.minecraft.world.biome.BiomeKeys; import net.minecraft.world.biome.BiomeKeys;
import net.minecraft.world.biome.source.BiomeSource; import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.TheEndBiomeSource;
import net.minecraft.world.gen.ChunkRandom; import net.minecraft.world.gen.ChunkRandom;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.EndBiomes; import ru.betterend.registry.EndBiomes;
import ru.betterend.registry.EndTags; import ru.betterend.registry.EndTags;
import ru.betterend.util.FeaturesHelper; import ru.betterend.util.FeaturesHelper;
import ru.betterend.world.biome.EndBiome;
public class BetterEndBiomeSource extends BiomeSource { public class BetterEndBiomeSource extends BiomeSource {
public static final Codec<BetterEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> { public static final Codec<BetterEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> {
@ -36,8 +38,6 @@ public class BetterEndBiomeSource extends BiomeSource {
private BiomeMap mapLand; private BiomeMap mapLand;
private BiomeMap mapVoid; private BiomeMap mapVoid;
private final long seed; private final long seed;
private int preY = -1;
boolean preLand = false;
public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) { public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(getBiomes(biomeRegistry)); super(getBiomes(biomeRegistry));
@ -70,23 +70,25 @@ public class BetterEndBiomeSource extends BiomeSource {
@Override @Override
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
boolean hasVoid = !TerrainGenerator.useNewGenerator() || !TerrainGenerator.noRingVoid();
long i = (long) biomeX * (long) biomeX; long i = (long) biomeX * (long) biomeX;
long j = (long) biomeZ * (long) biomeZ; long j = (long) biomeZ * (long) biomeZ;
if (i + j <= 65536L) return this.centerBiome; if (hasVoid && i + j <= 65536L) return this.centerBiome;
if (biomeX == 0 && biomeZ == 0) { if (biomeX == 0 && biomeZ == 0) {
mapLand.clearCache(); mapLand.clearCache();
mapVoid.clearCache(); mapVoid.clearCache();
} }
if (TerrainGenerator.useNewGenerator()) {
if (TerrainGenerator.isLand(biomeX, biomeZ)) { if (TerrainGenerator.isLand(biomeX, biomeZ)) {
return mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); return mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
} }
else { else {
return mapVoid.getBiome(biomeX << 2, biomeZ << 2).getActualBiome(); return mapVoid.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
} }
}
/* else {
float height = TheEndBiomeSource.getNoiseAt(noise, (biomeX >> 1) + 1, (biomeZ >> 1) + 1) + (float) SMALL_NOISE.eval(biomeX, biomeZ) * 5; float height = TheEndBiomeSource.getNoiseAt(noise, (biomeX >> 1) + 1, (biomeZ >> 1) + 1) + (float) SMALL_NOISE.eval(biomeX, biomeZ) * 5;
if (height > -20F && height < -5F) { if (height > -20F && height < -5F) {
@ -94,11 +96,8 @@ public class BetterEndBiomeSource extends BiomeSource {
} }
EndBiome endBiome = height < -10F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) : mapLand.getBiome(biomeX << 2, biomeZ << 2); EndBiome endBiome = height < -10F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) : mapLand.getBiome(biomeX << 2, biomeZ << 2);
if (biomeX == 0 && biomeZ == 0) { return endBiome.getActualBiome();
mapLand.clearCache();
mapVoid.clearCache();
} }
return endBiome.getActualBiome();*/
} }
@Override @Override

View file

@ -3,6 +3,8 @@ package ru.betterend.world.generator;
import java.util.Random; import java.util.Random;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import net.minecraft.util.Identifier;
import ru.betterend.config.Configs;
import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
@ -17,6 +19,13 @@ public class TerrainGenerator {
private static IslandLayer smallIslands; private static IslandLayer smallIslands;
private static OpenSimplexNoise noise1; private static OpenSimplexNoise noise1;
private static OpenSimplexNoise noise2; private static OpenSimplexNoise noise2;
private static boolean newGenerator;
private static boolean noRingVoid;
public static void init() {
newGenerator = Configs.GENERATOR_CONFIG.getBoolean(new Identifier("generator", "enabled"), "useNewGenerator", true);
noRingVoid = Configs.GENERATOR_CONFIG.getBoolean(new Identifier("generator", "enabled"), "noRingVoid", false);
}
public static void initNoise(long seed) { public static void initNoise(long seed) {
Random random = new Random(seed); Random random = new Random(seed);
@ -28,7 +37,15 @@ public class TerrainGenerator {
} }
public static boolean canGenerate(int x, int z) { public static boolean canGenerate(int x, int z) {
return (long) x + (long) z > CENTER; return noRingVoid || (long) x + (long) z > CENTER;
}
public static boolean noRingVoid() {
return noRingVoid;
}
public static boolean useNewGenerator() {
return newGenerator;
} }
public static void fillTerrainDensity(double[] buffer, int x, int z) { public static void fillTerrainDensity(double[] buffer, int x, int z) {