Rewrite world gen, in preperation for json based config files

This commit is contained in:
modmuss50 2020-08-02 15:41:28 +01:00
parent 46fe49ebe5
commit cfd9c7f10c
11 changed files with 312 additions and 283 deletions

View file

@ -91,7 +91,7 @@ public class TechReborn implements ModInitializer {
RecipeCrafter.soundHanlder = new ModSounds.SoundHandler();
}
ModLoot.init();
WorldGenerator.initBiomeFeatures();
WorldGenerator.initWorldGen();
FluidGeneratorRecipes.init();
//Force loads the block entities at the right time
TRBlockEntities.THERMAL_GEN.toString();

View file

@ -593,156 +593,6 @@ 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.")
public static boolean enableEndLoot = true;
@Config(config = "world", category = "ore", key = "enableBauxiteOre", comment = "Generate Bauxite Ore in The Overworld.")
public static boolean enableBauxiteOre = true;
@Config(config = "world", category = "ore", key = "bauxiteVeinCount", comment = "Count of Bauxite Ore veins per chunk.")
public static int bauxiteVeinCount = 10;
@Config(config = "world", category = "ore", key = "bauxiteVeinSize", comment = "Amount of Bauxite Ores per vein.")
public static int bauxiteVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableCopperOre", comment = "Generate Copper Ore in The Overworld.")
public static boolean enableCopperOre = true;
@Config(config = "world", category = "ore", key = "copperVeinCount", comment = "Count of Copper Ore veins per chunk.")
public static int copperVeinCount = 16;
@Config(config = "world", category = "ore", key = "copperVeinSize", comment = "Amount of Copper Ores per vein.")
public static int copperVeinSize = 8;
@Config(config = "world", category = "ore", key = "enableGalenaOre", comment = "Generate Galena Ore in The Overworld.")
public static boolean enableGalenaOre = true;
@Config(config = "world", category = "ore", key = "galenaVeinCount", comment = "Count of Galena Ore veins per chunk.")
public static int galenaVeinCount = 16;
@Config(config = "world", category = "ore", key = "galenaVeinSize", comment = "Amount of Galena Ores per vein.")
public static int galenaVeinSize = 8;
@Config(config = "world", category = "ore", key = "enableIridiumOre", comment = "Generate Iridium Ore in The Overworld.")
public static boolean enableIridiumOre = true;
@Config(config = "world", category = "ore", key = "iridiumVeinCount", comment = "Count of Iridium Ore veins per chunk.")
public static int iridiumVeinCount = 3;
@Config(config = "world", category = "ore", key = "iridiumVeinSize", comment = "Amount of Iridium Ores per vein.")
public static int iridiumVeinSize = 3;
@Config(config = "world", category = "ore", key = "enableLeadOre", comment = "Generate Lead Ore in The Overworld.")
public static boolean enableLeadOre = true;
@Config(config = "world", category = "ore", key = "leadVeinCount", comment = "Count of Lead Ore veins per chunk.")
public static int leadVeinCount = 16;
@Config(config = "world", category = "ore", key = "leadVeinSize", comment = "Amount of Lead Ores per vein.")
public static int leadVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableRubyOre", comment = "Generate Ruby Ore in The Overworld.")
public static boolean enableRubyOre = true;
@Config(config = "world", category = "ore", key = "rubyVeinCount", comment = "Count of Ruby Ore veins per chunk.")
public static int rubyVeinCount = 3;
@Config(config = "world", category = "ore", key = "rubyVeinSize", comment = "Amount of Ruby Ores per vein.")
public static int rubyVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableSapphireOre", comment = "Generate Sapphire Ore in The Overworld.")
public static boolean enableSapphireOre = true;
@Config(config = "world", category = "ore", key = "sapphireVeinCount", comment = "Count of Sapphire Ore veins per chunk.")
public static int sapphireVeinCount = 3;
@Config(config = "world", category = "ore", key = "sapphireVeinSize", comment = "Amount of Sapphire Ores per vein.")
public static int sapphireVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableSilverOre", comment = "Generate Silver Ore in The Overworld.")
public static boolean enableSilverOre = true;
@Config(config = "world", category = "ore", key = "silverVeinCount", comment = "Count of Silver Ore veins per chunk.")
public static int silverVeinCount = 16;
@Config(config = "world", category = "ore", key = "silverVeinSize", comment = "Amount of Silver Ores per vein.")
public static int silverVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableTinOre", comment = "Generate Tin Ore in The Overworld.")
public static boolean enableTinOre = true;
@Config(config = "world", category = "ore", key = "tinVeinCount", comment = "Count of Tin Ore veins per chunk.")
public static int tinVeinCount = 16;
@Config(config = "world", category = "ore", key = "tinVeinSize", comment = "Amount of Tin Ores per vein.")
public static int tinVeinSize = 8;
@Config(config = "world", category = "ore", key = "enableCinnabarOre", comment = "Generate Cinnabar Ore in The Nether.")
public static boolean enableCinnabarOre = true;
@Config(config = "world", category = "ore", key = "cinnabarVeinCount", comment = "Count of Cinnabar Ore veins per chunk.")
public static int cinnabarVeinCount = 3;
@Config(config = "world", category = "ore", key = "cinnabarVeinSize", comment = "Amount of Cinnabar Ores per vein.")
public static int cinnabarVeinSize = 6;
@Config(config = "world", category = "ore", key = "enablePyriteOre", comment = "Generate Pyrite Ore in The Nether.")
public static boolean enablePyriteOre = true;
@Config(config = "world", category = "ore", key = "pyriteVeinCount", comment = "Count of Pyrite Ore veins per chunk.")
public static int pyriteVeinCount = 3;
@Config(config = "world", category = "ore", key = "pyriteVeinSize", comment = "Amount of Pyrite Ores per vein.")
public static int pyriteVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableSphaleriteOre", comment = "Generate Sphalerite Ore in The Nether.")
public static boolean enableSphaleriteOre = true;
@Config(config = "world", category = "ore", key = "sphaleriteVeinCount", comment = "Count of Sphalerite Ore veins per chunk.")
public static int sphaleriteVeinCount = 3;
@Config(config = "world", category = "ore", key = "sphaleriteVeinSize", comment = "Amount of Sphalerite Ores per vein.")
public static int sphaleriteVeinSize = 6;
@Config(config = "world", category = "ore", key = "enablePeridotOre", comment = "Generate Peridot Ore in The End.")
public static boolean enablePeridotOre = true;
@Config(config = "world", category = "ore", key = "peridotVeinCount", comment = "Count of Peridot Ore veins per chunk.")
public static int peridotVeinCount = 3;
@Config(config = "world", category = "ore", key = "peridotVeinSize", comment = "Amount of Peridot Ores per vein.")
public static int peridotVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableSheldoniteOre", comment = "Generate Sheldonite Ore in The End.")
public static boolean enableSheldoniteOre = true;
@Config(config = "world", category = "ore", key = "sheldoniteVeinCount", comment = "Count of Sheldonite Ore veins per chunk.")
public static int sheldoniteVeinCount = 3;
@Config(config = "world", category = "ore", key = "sheldoniteVeinSize", comment = "Amount of Sheldonite Ores per vein.")
public static int sheldoniteVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableSodaliteOre", comment = "Generate Sodalite Ore in The End.")
public static boolean enableSodaliteOre = true;
@Config(config = "world", category = "ore", key = "sodaliteVeinCount", comment = "Count of Sodalite Ore veins per chunk.")
public static int sodaliteVeinCount = 3;
@Config(config = "world", category = "ore", key = "sodaliteVeinSize", comment = "Amount of Sodalite Ores per vein.")
public static int sodaliteVeinSize = 6;
@Config(config = "world", category = "ore", key = "enableTungstenOre", comment = "Generate Tungsten Ore in The End.")
public static boolean enableTungstenOre = true;
@Config(config = "world", category = "ore", key = "tungstenVeinCount", comment = "Count of Tungsten Ore veins per chunk.")
public static int tungstenVeinCount = 3;
@Config(config = "world", category = "ore", key = "tungstenVeinSize", comment = "Amount of Tungsten Ores per vein.")
public static int tungstenVeinSize = 6;
@Config(config = "world", category = "rubber_tree", key = "rubberTreeChance", comment = "Chance to spawn rubber tree")
public static int rubberTreeChance = 50;
@Config(config = "world", category = "rubber_tree", key = "rubberTreeBaseHeight", comment = "Basic height for not-spire part of rubber tree")
public static int rubberTreeBaseHeight = 6;
@Config(config = "world", category = "rubber_tree", key = "rubberTreeSpireHeight", comment = "Height of spire of rubber tree")
public static int rubberTreeSpireHeight = 3;
}

View file

@ -32,6 +32,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.structure.rule.RuleTest;
import reborncore.api.blockentity.IUpgrade;
import reborncore.common.fluid.FluidValue;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
@ -82,6 +83,9 @@ import techreborn.items.tool.MiningLevel;
import techreborn.utils.InitUtils;
import org.jetbrains.annotations.Nullable;
import techreborn.world.TechRebornOre;
import techreborn.world.WorldTargetType;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Stream;
@ -370,22 +374,22 @@ public class TRContent {
}
public enum Ores implements ItemConvertible {
BAUXITE(TechRebornConfig.bauxiteVeinSize, TechRebornConfig.bauxiteVeinCount, 10, 60, MiningLevel.STONE),
CINNABAR(TechRebornConfig.cinnabarVeinSize, TechRebornConfig.cinnabarVeinCount, 10, 126, MiningLevel.IRON),
COPPER(TechRebornConfig.copperVeinSize, TechRebornConfig.copperVeinCount, 20, 60, MiningLevel.STONE),
GALENA(TechRebornConfig.galenaVeinSize, TechRebornConfig.galenaVeinCount, 10, 60, MiningLevel.IRON),
IRIDIUM(TechRebornConfig.iridiumVeinSize, TechRebornConfig.iridiumVeinCount, 5, 60, MiningLevel.DIAMOND),
LEAD(TechRebornConfig.leadVeinSize, TechRebornConfig.leadVeinCount, 20, 60, MiningLevel.IRON),
PERIDOT(TechRebornConfig.peridotVeinSize, TechRebornConfig.peridotVeinCount, 10, 250, MiningLevel.DIAMOND),
PYRITE(TechRebornConfig.pyriteVeinSize, TechRebornConfig.pyriteVeinCount, 10, 126, MiningLevel.DIAMOND),
RUBY(TechRebornConfig.rubyVeinSize, TechRebornConfig.rubyVeinCount, 10, 60, MiningLevel.IRON),
SAPPHIRE(TechRebornConfig.sapphireVeinSize, TechRebornConfig.sapphireVeinCount, 10, 60, MiningLevel.IRON),
SHELDONITE(TechRebornConfig.sheldoniteVeinSize, TechRebornConfig.sheldoniteVeinCount, 10, 250, MiningLevel.DIAMOND),
SILVER(TechRebornConfig.silverVeinSize, TechRebornConfig.silverVeinCount, 20, 60, MiningLevel.IRON),
SODALITE(TechRebornConfig.sodaliteVeinSize, TechRebornConfig.sodaliteVeinCount, 10, 250, MiningLevel.DIAMOND),
SPHALERITE(TechRebornConfig.sphaleriteVeinSize, TechRebornConfig.sphaleriteVeinCount, 10, 126, MiningLevel.IRON),
TIN(TechRebornConfig.tinVeinSize, TechRebornConfig.tinVeinCount, 20, 60, MiningLevel.STONE),
TUNGSTEN(TechRebornConfig.tungstenVeinSize, TechRebornConfig.tungstenVeinCount, 10, 250, MiningLevel.DIAMOND);
BAUXITE(6, 10, 10, 60, MiningLevel.STONE),
CINNABAR(6, 3, 10, 126, MiningLevel.IRON),
COPPER(8, 16, 20, 60, MiningLevel.STONE),
GALENA(8, 16, 10, 60, MiningLevel.IRON),
IRIDIUM(3, 3, 5, 60, MiningLevel.DIAMOND),
LEAD(6, 16, 20, 60, MiningLevel.IRON),
PERIDOT(6, 3, 10, 250, MiningLevel.DIAMOND),
PYRITE(6, 3, 10, 126, MiningLevel.DIAMOND),
RUBY(6, 3, 10, 60, MiningLevel.IRON),
SAPPHIRE(6, 3, 10, 60, MiningLevel.IRON),
SHELDONITE(6, 3, 10, 250, MiningLevel.DIAMOND),
SILVER(6, 16, 20, 60, MiningLevel.IRON),
SODALITE(6, 3, 10, 250, MiningLevel.DIAMOND),
SPHALERITE(6, 3, 10, 126, MiningLevel.IRON),
TIN(8, 16, 20, 60, MiningLevel.STONE),
TUNGSTEN(6, 3, 10, 250, MiningLevel.DIAMOND);
public final String name;
public final Block block;
@ -414,6 +418,10 @@ public class TRContent {
return block.asItem();
}
public TechRebornOre asNewOres(WorldTargetType targetType, RuleTest ruleTest) {
return new TechRebornOre(targetType, ruleTest, block.getDefaultState(), maxY, veinSize, veinsPerChunk);
}
}
public enum StorageBlocks implements ItemConvertible {

View file

@ -0,0 +1,78 @@
package techreborn.world;
import net.minecraft.block.Blocks;
import net.minecraft.structure.rule.BlockStateMatchRuleTest;
import net.minecraft.structure.rule.RuleTest;
import net.minecraft.util.math.Direction;
import net.minecraft.world.gen.UniformIntDistribution;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize;
import net.minecraft.world.gen.stateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider;
import net.minecraft.world.gen.trunk.StraightTrunkPlacer;
import org.apache.logging.log4j.util.TriConsumer;
import techreborn.blocks.misc.BlockRubberLog;
import techreborn.init.TRContent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class DefaultWorldGen {
private static final RuleTest END_STONE = new BlockStateMatchRuleTest(Blocks.END_STONE.getDefaultState());
public static WorldGenConfig getDefaultWorldGen() {
return new WorldGenConfig(getOres(), getRubberTree());
}
private static TreeFeatureConfig getRubberTree() {
WeightedBlockStateProvider logProvider = new WeightedBlockStateProvider();
logProvider.addState(TRContent.RUBBER_LOG.getDefaultState(), 10);
Arrays.stream(Direction.values())
.filter(direction -> direction.getAxis().isHorizontal())
.map(direction -> TRContent.RUBBER_LOG.getDefaultState()
.with(BlockRubberLog.HAS_SAP, true)
.with(BlockRubberLog.SAP_SIDE, direction)
)
.forEach(state -> logProvider.addState(state, 1));
return new TreeFeatureConfig.Builder(
logProvider,
new SimpleBlockStateProvider(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 TwoLayersFeatureSize(1, 0, 1)
).build();
}
private static List<TechRebornOre> getOres() {
List<TechRebornOre> ores = new ArrayList<>();
TriConsumer<WorldTargetType, RuleTest, TRContent.Ores> addOre = (worldTargetType, ruleTest, ore) -> ores.add(ore.asNewOres(worldTargetType, ruleTest));
addOre.accept(WorldTargetType.NETHER, OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.CINNABAR);
addOre.accept(WorldTargetType.NETHER, OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.PYRITE);
addOre.accept(WorldTargetType.NETHER, OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.SPHALERITE);
addOre.accept(WorldTargetType.END, END_STONE, TRContent.Ores.PERIDOT);
addOre.accept(WorldTargetType.END, END_STONE, TRContent.Ores.SHELDONITE);
addOre.accept(WorldTargetType.END, END_STONE, TRContent.Ores.SODALITE);
addOre.accept(WorldTargetType.END, END_STONE, TRContent.Ores.TUNGSTEN);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.BAUXITE);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.COPPER);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.GALENA);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.IRIDIUM);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.LEAD);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.RUBY);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.SAPPHIRE);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.SILVER);
addOre.accept(WorldTargetType.DEFAULT, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.TIN);
return Collections.unmodifiableList(ores);
}
}

View file

@ -27,15 +27,15 @@ package techreborn.world;
import net.minecraft.block.sapling.SaplingGenerator;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import org.jetbrains.annotations.Nullable;
import java.util.Random;
public class RubberSaplingGenerator extends SaplingGenerator {
@Nullable
@Override
protected ConfiguredFeature<TreeFeatureConfig, ?> createTreeFeature(Random random, boolean bl) {
return WorldGenerator.RUBBER_TREE_FEATURE.configure(WorldGenerator.RUBBER_TREE_CONFIG);
return WorldGenerator.RUBBER_TREE_FEATURE.configure(WorldGenerator.activeConfig.getRubberTree());
}
}

View file

@ -3,8 +3,6 @@ package techreborn.world;
import com.mojang.serialization.Codec;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.DecoratorContext;

View file

@ -25,6 +25,7 @@
package techreborn.world;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
@ -33,8 +34,7 @@ import net.minecraft.world.gen.UniformIntDistribution;
import net.minecraft.world.gen.feature.TreeFeature;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import net.minecraft.world.gen.foliage.BlobFoliagePlacer;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
import net.minecraft.world.gen.foliage.FoliagePlacerType;
import java.util.Random;
import java.util.Set;
@ -49,9 +49,22 @@ public class RubberTreeFeature extends TreeFeature {
}
public static class FoliagePlacer extends BlobFoliagePlacer {
public static final Codec<FoliagePlacer> CODEC = RecordCodecBuilder.create((instance) -> method_28838(instance)
.and(
Codec.INT.fieldOf("spireHeight").forGetter(FoliagePlacer::getSpireHeight)
)
.and(
BlockState.CODEC.fieldOf("spireBlockState").forGetter(FoliagePlacer::getSpireBlockState)
)
.apply(instance, FoliagePlacer::new));
public FoliagePlacer(UniformIntDistribution uniformIntDistribution, UniformIntDistribution uniformIntDistribution2, int height) {
super(uniformIntDistribution, uniformIntDistribution2, height);
private final int spireHeight;
private final BlockState spireBlockState;
public FoliagePlacer(UniformIntDistribution radius, UniformIntDistribution offset, int height, int spireHeight, BlockState spireBlockState) {
super(radius, offset, height);
this.spireHeight = spireHeight;
this.spireBlockState = spireBlockState;
}
@Override
@ -75,10 +88,23 @@ public class RubberTreeFeature extends TreeFeature {
if (topPos == null) return;
for (int i = 0; i < TechRebornConfig.rubberTreeSpireHeight; i++) {
world.setBlockState(pos.up(i), TRContent.RUBBER_LEAVES.getDefaultState(), 19);
for (int i = 0; i < spireHeight; i++) {
world.setBlockState(pos.up(i), spireBlockState, 19);
}
}
@Override
protected FoliagePlacerType<?> getType() {
return WorldGenerator.RUBBER_TREE_FOLIAGE_PLACER_TYPE;
}
public int getSpireHeight() {
return spireHeight;
}
public BlockState getSpireBlockState() {
return spireBlockState;
}
}

View file

@ -0,0 +1,71 @@
package techreborn.world;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.structure.rule.RuleTest;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
public class TechRebornOre {
public static final Codec<TechRebornOre> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
WorldTargetType.CODEC.fieldOf("target").forGetter(TechRebornOre::getTargetType),
RuleTest.field_25012.fieldOf("rule").forGetter(TechRebornOre::getRuleTest),
BlockState.CODEC.fieldOf("blockState").forGetter(TechRebornOre::getBlockState),
Codec.INT.fieldOf("maxY").forGetter(TechRebornOre::getMaxY),
Codec.INT.fieldOf("veinSize").forGetter(TechRebornOre::getVeinCount),
Codec.INT.fieldOf("veinCount").forGetter(TechRebornOre::getVeinCount)
).apply(instance, TechRebornOre::new)
);
private final WorldTargetType targetType;
private final RuleTest ruleTest;
private final BlockState blockState;
private final int maxY;
private final int veinSize;
private final int veinCount;
public TechRebornOre(WorldTargetType targetType, RuleTest ruleTest, BlockState blockState, int maxY, int veinSize, int veinCount) {
this.targetType = targetType;
this.ruleTest = ruleTest;
this.blockState = blockState;
this.maxY = maxY;
this.veinSize = veinSize;
this.veinCount = veinCount;
}
public ConfiguredFeature<?, ?> getConfiguredFeature() {
return Feature.ORE.configure(
new OreFeatureConfig(ruleTest, blockState, veinSize)
)
.method_30377(maxY)
.spreadHorizontally()
.repeat(veinCount);
}
public WorldTargetType getTargetType() {
return targetType;
}
public RuleTest getRuleTest() {
return ruleTest;
}
public BlockState getBlockState() {
return blockState;
}
public int getMaxY() {
return maxY;
}
public int getVeinSize() {
return veinSize;
}
public int getVeinCount() {
return veinCount;
}
}

View file

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

View file

@ -26,33 +26,26 @@ package techreborn.world;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.gson.JsonElement;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.minecraft.block.Blocks;
import net.minecraft.structure.rule.BlockStateMatchRuleTest;
import net.minecraft.structure.rule.RuleTest;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Category;
import net.minecraft.world.gen.GenerationStep;
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.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize;
import net.minecraft.world.gen.stateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider;
import net.minecraft.world.gen.trunk.StraightTrunkPlacer;
import techreborn.blocks.misc.BlockRubberLog;
import net.minecraft.world.gen.foliage.FoliagePlacerType;
import org.jetbrains.annotations.Nullable;
import reborncore.mixin.common.AccessorFoliagePlacerType;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
@ -63,123 +56,56 @@ public class WorldGenerator {
public static Feature<TreeFeatureConfig> RUBBER_TREE_FEATURE;
public static RubberTreeDecorator RUBBER_TREE_DECORATOR;
public static TreeFeatureConfig RUBBER_TREE_CONFIG;
private static final RuleTest END_STONE = new BlockStateMatchRuleTest(Blocks.END_STONE.getDefaultState());
public static FoliagePlacerType<RubberTreeFeature.FoliagePlacer> RUBBER_TREE_FOLIAGE_PLACER_TYPE;
@Nullable
public static WorldGenConfig activeConfig;
private static final List<Biome> checkedBiomes = new ArrayList<>();
public static void initBiomeFeatures() {
public static void initWorldGen() {
setupTrees();
activeConfig = DefaultWorldGen.getDefaultWorldGen();
DataResult<JsonElement> result = WorldGenConfig.CODEC.encodeStart(JsonOps.INSTANCE, activeConfig);
JsonElement jsonElement = result.getOrThrow(true, System.out::println);
String json = jsonElement.toString();
for (Biome biome : BuiltinRegistries.BIOME) {
addToBiome(biome);
populateBiome(biome, activeConfig);
}
//Handles modded biomes
RegistryEntryAddedCallback.event(BuiltinRegistries.BIOME).register((i, identifier, biome) -> addToBiome(biome));
RegistryEntryAddedCallback.event(BuiltinRegistries.BIOME).register((i, identifier, biome) -> populateBiome(biome, activeConfig));
}
private static void setupTrees() {
RUBBER_TREE_FEATURE = Registry.register(Registry.FEATURE, new Identifier("techreborn:rubber_tree"), new RubberTreeFeature(TreeFeatureConfig.CODEC));
RUBBER_TREE_DECORATOR = Registry.register(Registry.DECORATOR, new Identifier("techreborn:rubber_tree"), new RubberTreeDecorator(ChanceDecoratorConfig.CODEC));
WeightedBlockStateProvider logProvider = new WeightedBlockStateProvider();
logProvider.addState(TRContent.RUBBER_LOG.getDefaultState(), 10);
Arrays.stream(Direction.values())
.filter(direction -> direction.getAxis().isHorizontal())
.map(direction -> TRContent.RUBBER_LOG.getDefaultState()
.with(BlockRubberLog.HAS_SAP, true)
.with(BlockRubberLog.SAP_SIDE, direction)
)
.forEach(state -> logProvider.addState(state, 1));
RUBBER_TREE_CONFIG = new TreeFeatureConfig.Builder(
logProvider,
new SimpleBlockStateProvider(TRContent.RUBBER_LEAVES.getDefaultState()),
new RubberTreeFeature.FoliagePlacer(UniformIntDistribution.of(2, 0), UniformIntDistribution.of(0, 0), 3),
new StraightTrunkPlacer(TechRebornConfig.rubberTreeBaseHeight, 3, 0),
new TwoLayersFeatureSize(1, 0, 1)
).build();
RUBBER_TREE_FOLIAGE_PLACER_TYPE = AccessorFoliagePlacerType.register("techreborn:rubber_tree", RubberTreeFeature.FoliagePlacer.CODEC);
}
private static void addToBiome(Biome biome) {
private static void populateBiome(Biome biome, WorldGenConfig config) {
if (checkedBiomes.contains(biome)) {
//Just to be sure we dont add the stuff twice to the same biome
return;
}
checkedBiomes.add(biome);
if (biome.getCategory() == Category.NETHER) {
if (TechRebornConfig.enableCinnabarOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.CINNABAR);
}
if (TechRebornConfig.enablePyriteOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.PYRITE);
}
if (TechRebornConfig.enableSphaleriteOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.SPHALERITE);
}
} else if (biome.getCategory() == Category.THEEND) {
if (TechRebornConfig.enablePeridotOre) {
addOre(biome, END_STONE, TRContent.Ores.PERIDOT);
}
if (TechRebornConfig.enableSheldoniteOre) {
addOre(biome, END_STONE, TRContent.Ores.SHELDONITE);
}
if (TechRebornConfig.enableSodaliteOre) {
addOre(biome, END_STONE, TRContent.Ores.SODALITE);
}
if (TechRebornConfig.enableTungstenOre) {
addOre(biome, END_STONE, TRContent.Ores.TUNGSTEN);
}
} else {
if (TechRebornConfig.enableBauxiteOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.BAUXITE);
}
if (TechRebornConfig.enableCopperOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.COPPER);
}
if (TechRebornConfig.enableGalenaOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.GALENA);
}
if (TechRebornConfig.enableIridiumOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.IRIDIUM);
}
if (TechRebornConfig.enableLeadOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.LEAD);
}
if (TechRebornConfig.enableRubyOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.RUBY);
}
if (TechRebornConfig.enableSapphireOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.SAPPHIRE);
}
if (TechRebornConfig.enableSilverOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.SILVER);
}
if (TechRebornConfig.enableTinOre) {
addOre(biome, OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.TIN);
}
if (biome.getCategory() == Category.FOREST || biome.getCategory() == Category.TAIGA || biome.getCategory() == Category.SWAMP) {
addFeature(biome, GenerationStep.Feature.VEGETAL_DECORATION,
RUBBER_TREE_FEATURE.configure(RUBBER_TREE_CONFIG)
.decorate(RUBBER_TREE_DECORATOR
.configure(new ChanceDecoratorConfig(biome.getCategory() == Category.SWAMP ? TechRebornConfig.rubberTreeChance / 3 : TechRebornConfig.rubberTreeChance))
)
);
for (TechRebornOre ore : config.getOres()) {
if (ore.getTargetType().isApplicable(biome.getCategory())) {
addFeature(biome, GenerationStep.Feature.UNDERGROUND_ORES, ore.getConfiguredFeature());
}
}
}
private static void addOre(Biome biome, RuleTest ruleTest, TRContent.Ores ore) {
addFeature(biome,
GenerationStep.Feature.UNDERGROUND_ORES,
Feature.ORE.configure(
new OreFeatureConfig(ruleTest, ore.block.getDefaultState(), ore.veinSize)
).method_30377(ore.maxY).spreadHorizontally().repeat(ore.veinsPerChunk)
);
if (biome.getCategory() == Category.FOREST || biome.getCategory() == Category.TAIGA || biome.getCategory() == Category.SWAMP) {
addFeature(biome, GenerationStep.Feature.VEGETAL_DECORATION,
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) {
@ -187,7 +113,7 @@ public class WorldGenerator {
int stepIndex = feature.ordinal();
while(features.size() <= stepIndex) {
while (features.size() <= stepIndex) {
features.add(Lists.newArrayList());
}

View file

@ -0,0 +1,39 @@
package techreborn.world;
import com.mojang.serialization.Codec;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.world.biome.Biome;
import java.util.function.Predicate;
public enum WorldTargetType implements StringIdentifiable {
DEFAULT("default", category -> category != Biome.Category.NETHER && category != Biome.Category.THEEND),
NETHER("nether", category -> category == Biome.Category.NETHER),
END("end", category -> category == Biome.Category.THEEND);
private final String name;
private final Predicate<Biome.Category> biomeCategoryPredicate;
public static final Codec<WorldTargetType> CODEC = StringIdentifiable.createCodec(WorldTargetType::values, WorldTargetType::getByName);
WorldTargetType(String name, Predicate<Biome.Category> biomeCategoryPredicate) {
this.name = name;
this.biomeCategoryPredicate = biomeCategoryPredicate;
}
public String getName() {
return name;
}
public boolean isApplicable(Biome.Category biomeCategory) {
return biomeCategoryPredicate.test(biomeCategory);
}
public static WorldTargetType getByName(String name) {
return null;
}
@Override
public String asString() {
return name;
}
}