This commit is contained in:
paulevsGitch 2020-10-24 16:47:30 +03:00
parent f7b1f6baff
commit 20f93cc9a4
7 changed files with 69 additions and 68 deletions

View file

@ -23,7 +23,6 @@ import ru.betterend.registry.SoundRegistry;
import ru.betterend.registry.StructureRegistry; import ru.betterend.registry.StructureRegistry;
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.surface.DoubleBlockSurfaceBuilder;
public class BetterEnd implements ModInitializer { public class BetterEnd implements ModInitializer {
public static final String MOD_ID = "betterend"; public static final String MOD_ID = "betterend";
@ -33,7 +32,6 @@ public class BetterEnd implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
SoundRegistry.register(); SoundRegistry.register();
DoubleBlockSurfaceBuilder.register();
ItemRegistry.register(); ItemRegistry.register();
BlockRegistry.register(); BlockRegistry.register();
BlockEntityRegistry.register(); BlockEntityRegistry.register();

View file

@ -32,12 +32,16 @@ public class BiomeRegistry {
private static Registry<Biome> biomeRegistry; private static Registry<Biome> biomeRegistry;
public static final EndBiome END = registerBiome(BiomeKeys.THE_END, BiomeType.LAND, true); // Vanilla Land
public static final EndBiome END_BARRENS = registerBiome(BiomeKeys.END_BARRENS, BiomeType.VOID, true); public static final EndBiome END = registerBiome(BiomeKeys.THE_END, BiomeType.LAND, 1F);
public static final EndBiome END_HIGHLANDS = registerBiome(BiomeKeys.END_HIGHLANDS, BiomeType.LAND, false); public static final EndBiome END_MIDLANDS = registerSubBiome(BiomeKeys.END_MIDLANDS, END, 0.5F);
public static final EndBiome END_MIDLANDS = registerBiome(BiomeKeys.END_MIDLANDS, BiomeType.LAND, false); public static final EndBiome END_HIGHLANDS = registerSubBiome(BiomeKeys.END_HIGHLANDS, END, 0.5F);
public static final EndBiome SMALL_END_ISLANDS = registerBiome(BiomeKeys.SMALL_END_ISLANDS, BiomeType.VOID, true);
// Vanilla Void
public static final EndBiome END_BARRENS = registerBiome(BiomeKeys.END_BARRENS, BiomeType.VOID, 1F);
public static final EndBiome SMALL_END_ISLANDS = registerBiome(BiomeKeys.SMALL_END_ISLANDS, BiomeType.VOID, 1);
// Better End Land
public static final EndBiome FOGGY_MUSHROOMLAND = registerBiome(new BiomeFoggyMushroomland(), BiomeType.LAND); public static final EndBiome FOGGY_MUSHROOMLAND = registerBiome(new BiomeFoggyMushroomland(), BiomeType.LAND);
public static final EndBiome CHORUS_FOREST = registerBiome(new BiomeChorusForest(), BiomeType.LAND); public static final EndBiome CHORUS_FOREST = registerBiome(new BiomeChorusForest(), BiomeType.LAND);
public static final EndBiome DUST_WASTELANDS = registerBiome(new BiomeDustWastelands(), BiomeType.LAND); public static final EndBiome DUST_WASTELANDS = registerBiome(new BiomeDustWastelands(), BiomeType.LAND);
@ -60,7 +64,7 @@ public class BiomeRegistry {
biomeRegistry.forEach((biome) -> { biomeRegistry.forEach((biome) -> {
if (biome.getCategory() == Category.THEEND) { if (biome.getCategory() == Category.THEEND) {
if (!MUTABLE.containsKey(biome) && !biomeRegistry.getId(biome).getNamespace().equals("minecraft")) { if (!MUTABLE.containsKey(biome) && !biomeRegistry.getId(biome).getNamespace().equals("minecraft")) {
EndBiome endBiome = new EndBiome(biome); EndBiome endBiome = new EndBiome(biome, 1);
LAND_BIOMES.addBiomeMutable(endBiome); LAND_BIOMES.addBiomeMutable(endBiome);
KEYS.put(endBiome, biomeRegistry.getKey(biome).get()); KEYS.put(endBiome, biomeRegistry.getKey(biome).get());
} }
@ -68,16 +72,24 @@ public class BiomeRegistry {
}); });
} }
public static EndBiome registerBiome(RegistryKey<Biome> key, BiomeType type, boolean addToGen) { public static EndBiome registerBiome(RegistryKey<Biome> key, BiomeType type, float genChance) {
EndBiome endBiome = new EndBiome(BuiltinRegistries.BIOME.get(key)); return registerBiome(BuiltinRegistries.BIOME.get(key), type, genChance);
if (addToGen) addToPicker(endBiome, type); }
public static EndBiome registerBiome(Biome biome, BiomeType type, float genChance) {
EndBiome endBiome = new EndBiome(biome, genChance);
addToPicker(endBiome, type);
makeLink(endBiome); makeLink(endBiome);
return endBiome; return endBiome;
} }
public static EndBiome registerBiome(Biome biome, BiomeType type) { public static EndBiome registerSubBiome(RegistryKey<Biome> key, EndBiome parent, float genChance) {
EndBiome endBiome = new EndBiome(biome); return registerSubBiome(BuiltinRegistries.BIOME.get(key), parent, genChance);
addToPicker(endBiome, type); }
public static EndBiome registerSubBiome(Biome biome, EndBiome parent, float genChance) {
EndBiome endBiome = new EndBiome(biome, genChance);
parent.addSubBiome(endBiome);
makeLink(endBiome); makeLink(endBiome);
return endBiome; return endBiome;
} }

View file

@ -71,7 +71,10 @@ public class FeatureRegistry {
if (id.getNamespace().equals("minecraft")) { if (id.getNamespace().equals("minecraft")) {
String path = id.getPath(); String path = id.getPath();
if (path.equals("end_highlands") || path.equals("end_midlands") || path.equals("small_end_islands")) { if (path.equals("end_highlands") || path.equals("end_midlands") || path.equals("small_end_islands")) {
features.get(GenerationStep.Feature.VEGETAL_DECORATION.ordinal()).clear(); int pos = GenerationStep.Feature.VEGETAL_DECORATION.ordinal();
if (pos < features.size()) {
features.get(pos).clear();
}
} }
} }

View file

@ -61,27 +61,22 @@ public class BiomeDefinition {
this.id = BetterEnd.makeID(name); this.id = BetterEnd.makeID(name);
} }
public BiomeDefinition setSurface(Block surfaceBlock) { public BiomeDefinition setSurface(Block block) {
this.surface = SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig( setSurface(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(
surfaceBlock.getDefaultState(), block.getDefaultState(),
Blocks.END_STONE.getDefaultState(), Blocks.END_STONE.getDefaultState(),
Blocks.END_STONE.getDefaultState() Blocks.END_STONE.getDefaultState()
)); )));
return this; return this;
} }
public BiomeDefinition setSurface(Block surfaceBlock1, Block surfaceBlock2) { public BiomeDefinition setSurface(Block block1, Block block2) {
this.surface = DoubleBlockSurfaceBuilder.INSTANCE.setConfigUpper(new TernarySurfaceConfig( setSurface(DoubleBlockSurfaceBuilder.register("be_" + id.getPath() + "_surface").setBlock1(block1).setBlock2(block2).configured());
surfaceBlock1.getDefaultState(), return this;
Blocks.END_STONE.getDefaultState(), }
Blocks.END_STONE.getDefaultState()
)).setConfigLower(new TernarySurfaceConfig( public BiomeDefinition setSurface(ConfiguredSurfaceBuilder<?> builder) {
surfaceBlock2.getDefaultState(), this.surface = builder;
Blocks.END_STONE.getDefaultState(),
Blocks.END_STONE.getDefaultState()
)).withConfig(new TernarySurfaceConfig(surfaceBlock1.getDefaultState(),
Blocks.END_STONE.getDefaultState(),
Blocks.END_STONE.getDefaultState()));
return this; return this;
} }

View file

@ -12,7 +12,7 @@ import net.minecraft.world.WorldAccess;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
public class EndBiome { public class EndBiome {
protected List<Subbiome> subbiomes = Lists.newArrayList(); protected List<EndBiome> subbiomes = Lists.newArrayList();
protected final Biome biome; protected final Biome biome;
protected final Identifier mcID; protected final Identifier mcID;
@ -33,11 +33,11 @@ public class EndBiome {
genChanceUnmutable = definition.getGenChance(); genChanceUnmutable = definition.getGenChance();
} }
public EndBiome(Biome biome) { public EndBiome(Biome biome, float genChance) {
this.biome = biome; this.biome = biome;
mcID = BuiltinRegistries.BIOME.getId(biome); mcID = BuiltinRegistries.BIOME.getId(biome);
fogDensity = 1; fogDensity = 1;
genChanceUnmutable = 1; genChanceUnmutable = genChance;
} }
public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) { public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) {
@ -60,17 +60,17 @@ public class EndBiome {
edgeSize = size; edgeSize = size;
} }
public void addSubBiome(EndBiome biome, float chance) { public void addSubBiome(EndBiome biome) {
maxSubBiomeChance += chance; maxSubBiomeChance += biome.mutateGenChance(maxSubBiomeChance);
biome.biomeParent = this; biome.biomeParent = this;
subbiomes.add(new Subbiome(biome, maxSubBiomeChance)); subbiomes.add(biome);
} }
public EndBiome getSubBiome(Random random) { public EndBiome getSubBiome(Random random) {
float chance = random.nextFloat() * maxSubBiomeChance; float chance = random.nextFloat() * maxSubBiomeChance;
for (Subbiome biome : subbiomes) for (EndBiome biome : subbiomes)
if (biome.canGenerate(chance)) if (biome.canGenerate(chance))
return biome.biome; return biome;
return this; return this;
} }
@ -90,25 +90,11 @@ public class EndBiome {
return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this); return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this);
} }
protected final class Subbiome {
EndBiome biome;
float chance;
Subbiome(EndBiome biome, float chance) {
this.biome = biome;
this.chance = chance;
}
public boolean canGenerate(float chance) {
return chance < this.chance;
}
}
public boolean canGenerate(float chance) { public boolean canGenerate(float chance) {
return chance <= this.genChance; return chance <= this.genChance;
} }
public float setGenChance(float chance) { public float mutateGenChance(float chance) {
genChance = genChanceUnmutable; genChance = genChanceUnmutable;
genChance += chance; genChance += chance;
return genChance; return genChance;

View file

@ -16,14 +16,14 @@ public class BiomePicker {
public void addBiome(EndBiome biome) { public void addBiome(EndBiome biome) {
biomes.add(biome); biomes.add(biome);
maxChance = biome.setGenChance(maxChance); maxChance = biome.mutateGenChance(maxChance);
biomeCount ++; biomeCount ++;
maxChanceUnmutable = maxChance; maxChanceUnmutable = maxChance;
} }
public void addBiomeMutable(EndBiome biome) { public void addBiomeMutable(EndBiome biome) {
biomes.add(biome); biomes.add(biome);
maxChance = biome.setGenChance(maxChance); maxChance = biome.mutateGenChance(maxChance);
} }
public void clearMutables() { public void clearMutables() {

View file

@ -2,34 +2,36 @@ package ru.betterend.world.surface;
import java.util.Random; import java.util.Random;
import com.mojang.serialization.Codec; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilder;
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder; import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;
import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig; import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig;
import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class DoubleBlockSurfaceBuilder extends SurfaceBuilder<TernarySurfaceConfig> { public class DoubleBlockSurfaceBuilder extends SurfaceBuilder<TernarySurfaceConfig> {
public static final DoubleBlockSurfaceBuilder INSTANCE = new DoubleBlockSurfaceBuilder(TernarySurfaceConfig.CODEC);
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(4141); private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(4141);
private TernarySurfaceConfig config1; private TernarySurfaceConfig config1;
private TernarySurfaceConfig config2; private TernarySurfaceConfig config2;
public DoubleBlockSurfaceBuilder(Codec<TernarySurfaceConfig> codec) { private DoubleBlockSurfaceBuilder() {
super(codec); super(TernarySurfaceConfig.CODEC);
} }
public DoubleBlockSurfaceBuilder setConfigUpper(TernarySurfaceConfig config) { public DoubleBlockSurfaceBuilder setBlock1(Block block) {
config1 = config; BlockState stone = Blocks.END_STONE.getDefaultState();
config1 = new TernarySurfaceConfig(block.getDefaultState(), stone, stone);
return this; return this;
} }
public DoubleBlockSurfaceBuilder setConfigLower(TernarySurfaceConfig config) { public DoubleBlockSurfaceBuilder setBlock2(Block block) {
config2 = config; BlockState stone = Blocks.END_STONE.getDefaultState();
config2 = new TernarySurfaceConfig(block.getDefaultState(), stone, stone);
return this; return this;
} }
@ -39,7 +41,12 @@ public class DoubleBlockSurfaceBuilder extends SurfaceBuilder<TernarySurfaceConf
SurfaceBuilder.DEFAULT.generate(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, seaLevel, seed, noise > 0 ? config1 : config2); SurfaceBuilder.DEFAULT.generate(random, chunk, biome, x, z, height, noise, defaultBlock, defaultFluid, seaLevel, seed, noise > 0 ? config1 : config2);
} }
public static void register() { public static DoubleBlockSurfaceBuilder register(String name) {
Registry.register(Registry.SURFACE_BUILDER, "double_block_surface_builder", INSTANCE); return Registry.register(Registry.SURFACE_BUILDER, name, new DoubleBlockSurfaceBuilder());
}
public ConfiguredSurfaceBuilder<TernarySurfaceConfig> configured() {
BlockState stone = Blocks.END_STONE.getDefaultState();
return this.withConfig(new TernarySurfaceConfig(config1.getTopMaterial(), stone, stone));
} }
} }