Fix major worldgen issues

This commit is contained in:
modmuss50 2020-08-08 17:01:48 +01:00
parent 6e001dd9cc
commit 0b3cb646ce
6 changed files with 49 additions and 30 deletions

View file

@ -592,7 +592,4 @@ public class TechRebornConfig {
@Config(config = "world", category = "loot", key = "enableEndLoot", comment = "When true TechReborn will add ingots, machine frames and circuits to The End loot chests.") @Config(config = "world", category = "loot", key = "enableEndLoot", comment = "When true TechReborn will add ingots, machine frames and circuits to The End loot chests.")
public static boolean enableEndLoot = true; public static boolean enableEndLoot = true;
@Config(config = "world", category = "rubber_tree", key = "rubberTreeChance", comment = "Chance to spawn rubber tree")
public static int rubberTreeChance = 50;
} }

View file

@ -4,7 +4,10 @@ import net.minecraft.block.Blocks;
import net.minecraft.structure.rule.BlockStateMatchRuleTest; import net.minecraft.structure.rule.BlockStateMatchRuleTest;
import net.minecraft.structure.rule.RuleTest; import net.minecraft.structure.rule.RuleTest;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.UniformIntDistribution; import net.minecraft.world.gen.UniformIntDistribution;
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.OreFeatureConfig; import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.feature.TreeFeatureConfig; import net.minecraft.world.gen.feature.TreeFeatureConfig;
import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize; import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize;
@ -13,6 +16,7 @@ import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider;
import net.minecraft.world.gen.trunk.StraightTrunkPlacer; import net.minecraft.world.gen.trunk.StraightTrunkPlacer;
import org.apache.logging.log4j.util.TriConsumer; import org.apache.logging.log4j.util.TriConsumer;
import techreborn.blocks.misc.BlockRubberLog; import techreborn.blocks.misc.BlockRubberLog;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent; import techreborn.init.TRContent;
import java.util.ArrayList; import java.util.ArrayList;
@ -28,7 +32,7 @@ public class DefaultWorldGen {
return new WorldGenConfig(getOres(), getRubberTree()); return new WorldGenConfig(getOres(), getRubberTree());
} }
private static TreeFeatureConfig getRubberTree() { private static ConfiguredFeature<?, ?> getRubberTree() {
WeightedBlockStateProvider logProvider = new WeightedBlockStateProvider(); WeightedBlockStateProvider logProvider = new WeightedBlockStateProvider();
logProvider.addState(TRContent.RUBBER_LOG.getDefaultState(), 10); logProvider.addState(TRContent.RUBBER_LOG.getDefaultState(), 10);
@ -40,13 +44,19 @@ public class DefaultWorldGen {
) )
.forEach(state -> logProvider.addState(state, 1)); .forEach(state -> logProvider.addState(state, 1));
return new TreeFeatureConfig.Builder( TreeFeatureConfig treeFeatureConfig = new TreeFeatureConfig.Builder(
logProvider, logProvider,
new SimpleBlockStateProvider(TRContent.RUBBER_LEAVES.getDefaultState()), new SimpleBlockStateProvider(TRContent.RUBBER_LEAVES.getDefaultState()),
new RubberTreeFeature.FoliagePlacer(UniformIntDistribution.of(2, 0), UniformIntDistribution.of(0, 0), 3, 3, TRContent.RUBBER_LEAVES.getDefaultState()), new RubberTreeFeature.FoliagePlacer(UniformIntDistribution.of(2, 0), UniformIntDistribution.of(0, 0), 3, 3, TRContent.RUBBER_LEAVES.getDefaultState()),
new StraightTrunkPlacer(6, 3, 0), new StraightTrunkPlacer(6, 3, 0),
new TwoLayersFeatureSize(1, 0, 1) new TwoLayersFeatureSize(1, 0, 1)
).build(); ).build();
return WorldGenerator.RUBBER_TREE_FEATURE.configure(treeFeatureConfig)
.decorate(WorldGenerator.RUBBER_TREE_DECORATOR
.configure(new ChanceDecoratorConfig(50)
));
} }
private static List<TechRebornOre> getOres() { private static List<TechRebornOre> getOres() {

View file

@ -35,7 +35,7 @@ public class RubberSaplingGenerator extends SaplingGenerator {
@Nullable @Nullable
@Override @Override
protected ConfiguredFeature<TreeFeatureConfig, ?> createTreeFeature(Random random, boolean bl) { protected ConfiguredFeature<TreeFeatureConfig, ?> createTreeFeature(Random random, boolean bl) {
return WorldGenerator.RUBBER_TREE_FEATURE.configure(WorldGenerator.activeConfig.getRubberTree()); return WorldGenerator.RUBBER_TREE_FEATURE.configure((TreeFeatureConfig) WorldGenerator.activeConfig.getRubberTree().config);
} }
} }

View file

@ -4,6 +4,8 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.structure.rule.RuleTest; import net.minecraft.structure.rule.RuleTest;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig; import net.minecraft.world.gen.feature.OreFeatureConfig;
@ -26,6 +28,7 @@ public class TechRebornOre {
private final int maxY; private final int maxY;
private final int veinSize; private final int veinSize;
private final int veinCount; private final int veinCount;
private final ConfiguredFeature<?, ?> configuredFeature;
public TechRebornOre(WorldTargetType targetType, RuleTest ruleTest, BlockState blockState, int maxY, int veinSize, int veinCount) { public TechRebornOre(WorldTargetType targetType, RuleTest ruleTest, BlockState blockState, int maxY, int veinSize, int veinCount) {
this.targetType = targetType; this.targetType = targetType;
@ -34,15 +37,20 @@ public class TechRebornOre {
this.maxY = maxY; this.maxY = maxY;
this.veinSize = veinSize; this.veinSize = veinSize;
this.veinCount = veinCount; this.veinCount = veinCount;
this.configuredFeature = Feature.ORE.configure(
new OreFeatureConfig(ruleTest, blockState, veinSize)
)
.method_30377(maxY)
.spreadHorizontally()
.repeat(veinCount);
} }
public ConfiguredFeature<?, ?> getConfiguredFeature() { public ConfiguredFeature<?, ?> getConfiguredFeature() {
return Feature.ORE.configure( return configuredFeature;
new OreFeatureConfig(ruleTest, blockState, veinSize) }
)
.method_30377(maxY) public Identifier getIdentifier() {
.spreadHorizontally() return new Identifier("techreborn", "ore_" + Registry.BLOCK.getId(blockState.getBlock()).toString().replace(":", "_"));
.repeat(veinCount);
} }
public WorldTargetType getTargetType() { public WorldTargetType getTargetType() {

View file

@ -2,6 +2,7 @@ package techreborn.world;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.TreeFeatureConfig; import net.minecraft.world.gen.feature.TreeFeatureConfig;
import java.util.List; import java.util.List;
@ -10,20 +11,20 @@ public class WorldGenConfig {
public static final Codec<WorldGenConfig> CODEC = RecordCodecBuilder.create(instance -> public static final Codec<WorldGenConfig> CODEC = RecordCodecBuilder.create(instance ->
instance.group( instance.group(
Codec.list(TechRebornOre.CODEC).fieldOf("ores").forGetter(WorldGenConfig::getOres), Codec.list(TechRebornOre.CODEC).fieldOf("ores").forGetter(WorldGenConfig::getOres),
TreeFeatureConfig.CODEC.fieldOf("rubberTree").forGetter(WorldGenConfig::getRubberTree) ConfiguredFeature.field_25833.fieldOf("rubberTree").forGetter(WorldGenConfig::getRubberTree)
) )
.apply(instance, WorldGenConfig::new) .apply(instance, WorldGenConfig::new)
); );
private final List<TechRebornOre> ores; private final List<TechRebornOre> ores;
private final TreeFeatureConfig rubberTree; private final ConfiguredFeature<?, ?> rubberTree;
public WorldGenConfig(List<TechRebornOre> ores, TreeFeatureConfig rubberTree) { public WorldGenConfig(List<TechRebornOre> ores, ConfiguredFeature<?, ?> rubberTree) {
this.ores = ores; this.ores = ores;
this.rubberTree = rubberTree; this.rubberTree = rubberTree;
} }
public TreeFeatureConfig getRubberTree() { public ConfiguredFeature<?, ?> getRubberTree() {
return rubberTree; return rubberTree;
} }

View file

@ -94,21 +94,16 @@ public class WorldGenerator {
for (TechRebornOre ore : config.getOres()) { for (TechRebornOre ore : config.getOres()) {
if (ore.getTargetType().isApplicable(biome.getCategory())) { if (ore.getTargetType().isApplicable(biome.getCategory())) {
addFeature(biome, GenerationStep.Feature.UNDERGROUND_ORES, ore.getConfiguredFeature()); addFeature(biome, ore.getIdentifier(), GenerationStep.Feature.UNDERGROUND_ORES, ore.getConfiguredFeature());
} }
} }
if (biome.getCategory() == Category.FOREST || biome.getCategory() == Category.TAIGA || biome.getCategory() == Category.SWAMP) { if (biome.getCategory() == Category.FOREST || biome.getCategory() == Category.TAIGA || biome.getCategory() == Category.SWAMP) {
addFeature(biome, GenerationStep.Feature.VEGETAL_DECORATION, addFeature(biome, new Identifier("techreborn:rubber_tree"), GenerationStep.Feature.VEGETAL_DECORATION, config.getRubberTree());
RUBBER_TREE_FEATURE.configure(config.getRubberTree())
.decorate(RUBBER_TREE_DECORATOR
.configure(new ChanceDecoratorConfig(biome.getCategory() == Category.SWAMP ? TechRebornConfig.rubberTreeChance / 3 : TechRebornConfig.rubberTreeChance))
)
);
} }
} }
private static void addFeature(Biome biome, GenerationStep.Feature feature, ConfiguredFeature<?, ?> configuredFeature) { private static void addFeature(Biome biome, Identifier identifier, GenerationStep.Feature feature, ConfiguredFeature<?, ?> configuredFeature) {
List<List<Supplier<ConfiguredFeature<?, ?>>>> features = biome.getGenerationSettings().getFeatures(); List<List<Supplier<ConfiguredFeature<?, ?>>>> features = biome.getGenerationSettings().getFeatures();
int stepIndex = feature.ordinal(); int stepIndex = feature.ordinal();
@ -122,6 +117,14 @@ public class WorldGenerator {
features.set(feature.ordinal(), stepList = new ArrayList<>(stepList)); features.set(feature.ordinal(), stepList = new ArrayList<>(stepList));
} }
if (!BuiltinRegistries.CONFIGURED_FEATURE.getKey(configuredFeature).isPresent()) {
if (BuiltinRegistries.CONFIGURED_FEATURE.getOrEmpty(identifier).isPresent()) {
throw new RuntimeException("Duplicate feature: " + identifier.toString());
}
BuiltinRegistries.add(BuiltinRegistries.CONFIGURED_FEATURE, identifier, configuredFeature);
}
stepList.add(() -> configuredFeature); stepList.add(() -> configuredFeature);
} }
} }