Use biome modification api

This commit is contained in:
SD 2021-09-27 11:04:11 +05:30
parent 3692b634bf
commit 8cffb5829c
4 changed files with 27 additions and 31 deletions

View file

@ -149,7 +149,7 @@ public final class ModConfig implements ConfigData {
@RequiresRestart
@Tooltip public double clusterGenChance = 20000;
@RequiresRestart
@Tooltip public int gatewayGenChance = 200;
@Tooltip public int gatewayGenChance = 100;
@RequiresRestart
@Tooltip public List<String> clusterDimBlacklist = new LinkedList<>();
@RequiresRestart

View file

@ -10,6 +10,7 @@ import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.feature.DefaultBiomeFeatures;
// TODO
@Mixin(DefaultBiomeFeatures.class)
public class DefaultBiomeFeaturesMixin {
@Inject(method = "addDesertLakes", at = @At("RETURN"))

View file

@ -1,26 +1,26 @@
package org.dimdev.dimdoors.world.feature;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.mixin.accessor.GenerationSettingsAccessor;
import org.dimdev.dimdoors.world.feature.decorator.EternalFluidLakeDecorator;
import org.dimdev.dimdoors.world.feature.gateway.LimboGatewayFeature;
import org.dimdev.dimdoors.world.feature.gateway.schematic.*;
import org.dimdev.dimdoors.world.feature.gateway.schematic.SandstonePillarsGateway;
import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicGateway;
import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicGatewayFeature;
import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicGatewayFeatureConfig;
import org.dimdev.dimdoors.world.feature.gateway.schematic.TwoPillarsGateway;
import net.minecraft.structure.rule.BlockMatchRuleTest;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biome.Category;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.YOffset;
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
import net.minecraft.world.gen.decorator.Decoratable;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.RangeDecoratorConfig;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.ConfiguredFeatures;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
@ -28,6 +28,7 @@ import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.feature.SingleStateFeatureConfig;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.loader.api.FabricLoader;
// IMPORTANT NOTE
@ -44,6 +45,8 @@ public final class ModFeatures {
public static final ConfiguredFeature<?, ?> LIMBO_GATEWAY_CONFIGURED_FEATURE;
public static final ConfiguredFeature<?, ?> SOLID_STATIC_ORE;
public static final ConfiguredFeature<?, ?> DECAYED_BLOCK_ORE;
public static final RegistryKey<ConfiguredFeature<?, ?>> SANDSTONE_PILLARS_KEY = RegistryKey.of(Registry.CONFIGURED_FEATURE_KEY, new Identifier("dimdoors", "sandstone_pillars"));
public static final RegistryKey<ConfiguredFeature<?, ?>> TWO_PILLARS_KEY = RegistryKey.of(Registry.CONFIGURED_FEATURE_KEY, new Identifier("dimdoors", "two_pillars"));
@Deprecated public static final ConfiguredFeature<?, ?> ETERNAL_FLUID_LAKE = Feature.LAKE.configure(new SingleStateFeatureConfig(ModBlocks.ETERNAL_FLUID.getDefaultState())).decorate(ETERNAL_FLUID_LAKE_DECORATOR.configure(new ChanceDecoratorConfig(20)));
@ -51,37 +54,30 @@ public final class ModFeatures {
SANDSTONE_PILLARS_GATEWAY.init();
TWO_PILLARS_GATEWAY.init();
Registry.register(Registry.FEATURE, new Identifier("dimdoors", "schematic_gateway"), SCHEMATIC_GATEWAY_FEATURE);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "sandstone_pillars"), SANDSTONE_PILLARS_FEATURE);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, SANDSTONE_PILLARS_KEY.getValue(), SANDSTONE_PILLARS_FEATURE);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, TWO_PILLARS_KEY.getValue(), TWO_PILLARS_FEATURE);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "limbo_gateway"), LIMBO_GATEWAY_CONFIGURED_FEATURE);
Registry.register(Registry.DECORATOR, new Identifier("dimdoors", "eternal_fluid_lake"), ETERNAL_FLUID_LAKE_DECORATOR);
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "eternal_fluid_lake"), ETERNAL_FLUID_LAKE);
synchronized (BuiltinRegistries.BIOME) {
BuiltinRegistries.BIOME.stream()
.filter(biome ->
biome.getCategory() != Biome.Category.NONE &&
biome.getCategory() != Biome.Category.THEEND &&
biome.getCategory() != Biome.Category.NETHER &&
biome.getCategory() != Biome.Category.OCEAN &&
biome.getCategory() != Biome.Category.MUSHROOM
)
.forEach(biome -> {
int index = GenerationStep.Feature.SURFACE_STRUCTURES.ordinal();
List<List<Supplier<ConfiguredFeature<?, ?>>>> features = new ArrayList<>(biome.getGenerationSettings().getFeatures());
List<Supplier<ConfiguredFeature<?, ?>>> surfaceStructures = new ArrayList<>(features.get(index));
surfaceStructures.add(() -> TWO_PILLARS_FEATURE);
features.set(index, surfaceStructures);
((GenerationSettingsAccessor) biome.getGenerationSettings()).setFeatures(features);
});
}
BiomeModifications.addFeature(ctx -> {
Biome biome = ctx.getBiome();
return biome.getCategory() != Category.NONE &&
biome.getCategory() != Category.THEEND &&
biome.getCategory() != Category.NETHER &&
biome.getCategory() != Category.OCEAN &&
biome.getCategory() != Category.MUSHROOM &&
biome.getCategory() != Category.DESERT;
}, GenerationStep.Feature.SURFACE_STRUCTURES, TWO_PILLARS_KEY);
BiomeModifications.addFeature(ctx -> ctx.getBiome().getCategory() == Category.DESERT, GenerationStep.Feature.SURFACE_STRUCTURES, SANDSTONE_PILLARS_KEY);
}
static {
int gatewayChance = FabricLoader.getInstance().isDevelopmentEnvironment() ? 20 : DimensionalDoorsInitializer.getConfig().getWorldConfig().gatewayGenChance;
int gatewayChance = /*FabricLoader.getInstance().isDevelopmentEnvironment() ? 20 : */DimensionalDoorsInitializer.getConfig().getWorldConfig().gatewayGenChance;
SANDSTONE_PILLARS_FEATURE = SCHEMATIC_GATEWAY_FEATURE.configure(new SchematicGatewayFeatureConfig(SchematicGateway.ID_SCHEMATIC_MAP.inverse().get(SANDSTONE_PILLARS_GATEWAY))).decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP.applyChance(gatewayChance));
TWO_PILLARS_FEATURE = SCHEMATIC_GATEWAY_FEATURE.configure(new SchematicGatewayFeatureConfig(SchematicGateway.ID_SCHEMATIC_MAP.inverse().get(TWO_PILLARS_GATEWAY))).decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP.applyChance(gatewayChance));
LIMBO_GATEWAY_CONFIGURED_FEATURE = LIMBO_GATEWAY_FEATURE.configure(DefaultFeatureConfig.INSTANCE).decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP.applyChance(gatewayChance));
SOLID_STATIC_ORE = Feature.ORE.configure(new OreFeatureConfig(new BlockMatchRuleTest(ModBlocks.UNRAVELLED_FABRIC), ModBlocks.SOLID_STATIC.getDefaultState(), 4)).uniformRange(YOffset.getBottom(), YOffset.getTop()).repeat(3);
DECAYED_BLOCK_ORE = Feature.ORE.configure(new OreFeatureConfig(new BlockMatchRuleTest(ModBlocks.UNRAVELLED_FABRIC), ModBlocks.DECAYED_BLOCK.getDefaultState(), 64)).uniformRange(YOffset.fixed(0), YOffset.fixed(79)).repeat(2);
}
}

View file

@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_16",
"mixins": [
"BlockMixin",
"DefaultBiomeFeaturesMixin",
"ExplosionMixin",
"ExtendedServerPlayNetworkhandlerMixin",
"ItemMixin",