Fix worldgen and rubber trees. For now datapack driven worldgen isnt working.

This commit is contained in:
modmuss50 2021-05-29 19:09:28 +01:00
parent 22a50d2ecd
commit e7ab7e26d3
3 changed files with 15 additions and 13 deletions

View file

@ -35,6 +35,7 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import net.minecraft.util.collection.DataPool;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.intprovider.ConstantIntProvider;
import net.minecraft.util.math.intprovider.UniformIntProvider;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
@ -62,7 +63,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class DefaultWorldGen {
@ -88,7 +88,7 @@ public class DefaultWorldGen {
new StraightTrunkPlacer(6, 3, 0),
new SimpleBlockStateProvider(TRContent.RUBBER_LEAVES.getDefaultState()),
new SimpleBlockStateProvider(TRContent.RUBBER_SAPLING.getDefaultState()),
new RubberTreeFeature.FoliagePlacer(UniformIntProvider.create(2, 0), UniformIntProvider.create(0, 0), 3, 3, TRContent.RUBBER_LEAVES.getDefaultState()),
new RubberTreeFeature.FoliagePlacer(ConstantIntProvider.create(2), ConstantIntProvider.create(0), 3, 3, TRContent.RUBBER_LEAVES.getDefaultState()),
new TwoLayersFeatureSize(1, 0, 1)
).build();
@ -123,7 +123,7 @@ public class DefaultWorldGen {
features.add(new DataDrivenFeature(
new Identifier("techreborn", "rubber_tree"),
RubberSaplingGenerator.IDENTIFIER,
BiomeSelectors.categories(Biome.Category.FOREST, Biome.Category.TAIGA, Biome.Category.SWAMP),
getRubberTree(),
GenerationStep.Feature.VEGETAL_DECORATION

View file

@ -35,17 +35,17 @@ import org.jetbrains.annotations.Nullable;
import java.util.Random;
public class RubberSaplingGenerator extends SaplingGenerator {
private final Identifier identifier = new Identifier("techreborn", "techreborn/features/rubber_tree.json");
public static final Identifier IDENTIFIER = new Identifier("techreborn", "techreborn/features/rubber_tree.json");
@Nullable
@Override
protected ConfiguredFeature<TreeFeatureConfig, ?> createTreeFeature(Random random, boolean bl) {
MutableRegistry<ConfiguredFeature<?, ?>> registry = WorldGenerator.worldGenObseravable.getA();
if (!registry.getIds().contains(identifier)) {
if (!registry.getIds().contains(IDENTIFIER)) {
throw new RuntimeException("Could not find registered rubber tree feature!");
}
DecoratedFeatureConfig decoratedFeatureConfig = (DecoratedFeatureConfig) registry.get(identifier).getConfig();
DecoratedFeatureConfig decoratedFeatureConfig = (DecoratedFeatureConfig) registry.get(IDENTIFIER).getConfig();
//noinspection unchecked
return (ConfiguredFeature<TreeFeatureConfig, ?>) decoratedFeatureConfig.feature.get();
}

View file

@ -67,17 +67,19 @@ public class WorldGenerator {
// DefaultWorldGen.export();
worldGenObseravable.listen(WorldGenerator::applyToActiveRegistry);
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new WorldGenConfigReloader());
// FIXME 1.17 datadriven worldgen, for now we just use the default
//ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new WorldGenConfigReloader());
worldGenObseravable.pushB(DefaultWorldGen.getDefaultFeatures());
DynamicRegistrySetupCallback.EVENT.register(registryManager -> {
worldGenObseravable.pushA(registryManager.getMutable(BuiltinRegistries.CONFIGURED_FEATURE.getKey()));
});
BiomeModifications.create(new Identifier("techreborn", "features")).add(ModificationPhase.ADDITIONS, BiomeSelectors.all(), (biomeSelectionContext, biomeModificationContext) -> {
if (!worldGenObseravable.hasBoth()) {
LOGGER.warn("TR world gen not ready for biome modification");
return;
}
BiomeModifications.create(new Identifier("techreborn", "features")).add(ModificationPhase.ADDITIONS, BiomeSelectors.all(),
(biomeSelectionContext, biomeModificationContext) -> {
for (DataDrivenFeature feature : worldGenObseravable.getB()) {
if (feature.getBiomeSelector().test(biomeSelectionContext)) {
biomeModificationContext.getGenerationSettings().addFeature(feature.getGenerationStep(), feature.getRegistryKey());