From b73b7272a4ee21ac44e54d9506a21b6ba6c03a18 Mon Sep 17 00:00:00 2001 From: SD Date: Tue, 6 Oct 2020 17:18:01 +0530 Subject: [PATCH] List hacks Changes to be committed: modified: src/main/java/org/dimdev/dimdoors/ModConfig.java new file: src/main/java/org/dimdev/dimdoors/mixin/GenerationSettingsAccessor.java modified: src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java modified: src/main/java/org/dimdev/dimdoors/world/feature/gateway/schematic/SchematicV2Gateway.java modified: src/main/resources/dimdoors.mixins.json --- .../java/org/dimdev/dimdoors/ModConfig.java | 2 +- .../mixin/GenerationSettingsAccessor.java | 18 ++++++++++ .../dimdoors/world/feature/ModFeatures.java | 34 +++++++++++++++++-- .../gateway/schematic/SchematicV2Gateway.java | 2 -- src/main/resources/dimdoors.mixins.json | 1 + 5 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/dimdev/dimdoors/mixin/GenerationSettingsAccessor.java diff --git a/src/main/java/org/dimdev/dimdoors/ModConfig.java b/src/main/java/org/dimdev/dimdoors/ModConfig.java index ba3ceeca..f58e1126 100644 --- a/src/main/java/org/dimdev/dimdoors/ModConfig.java +++ b/src/main/java/org/dimdev/dimdoors/ModConfig.java @@ -149,7 +149,7 @@ public final class ModConfig { Codecs.INT_SET.fieldOf("gatewayDimBlacklist").forGetter((world) -> world.gatewayDimBlacklist) ).apply(instance, World::create)); public double clusterGenChance = 0.0002; - public int gatewayGenChance = 80; + public int gatewayGenChance = 200; public Set clusterDimBlacklist = new LinkedHashSet<>(); public Set gatewayDimBlacklist = new LinkedHashSet<>(); diff --git a/src/main/java/org/dimdev/dimdoors/mixin/GenerationSettingsAccessor.java b/src/main/java/org/dimdev/dimdoors/mixin/GenerationSettingsAccessor.java new file mode 100644 index 00000000..71b6135e --- /dev/null +++ b/src/main/java/org/dimdev/dimdoors/mixin/GenerationSettingsAccessor.java @@ -0,0 +1,18 @@ +package org.dimdev.dimdoors.mixin; + +import java.util.List; +import java.util.function.Supplier; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.world.biome.GenerationSettings; +import net.minecraft.world.gen.feature.ConfiguredFeature; + +@Mixin(GenerationSettings.class) +public interface GenerationSettingsAccessor { + @Mutable + @Accessor + void setFeatures(List>>> features); +} diff --git a/src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java b/src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java index f734cbd8..5c7e6b1e 100644 --- a/src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java +++ b/src/main/java/org/dimdev/dimdoors/world/feature/ModFeatures.java @@ -1,16 +1,24 @@ package org.dimdev.dimdoors.world.feature; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + import org.dimdev.dimdoors.ModConfig; import org.dimdev.dimdoors.block.ModBlocks; +import org.dimdev.dimdoors.mixin.GenerationSettingsAccessor; import org.dimdev.dimdoors.world.feature.gateway.LimboGatewayFeature; import org.dimdev.dimdoors.world.feature.gateway.schematic.SandstonePillarsV2Gateway; import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicV2Gateway; import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicV2GatewayFeature; import org.dimdev.dimdoors.world.feature.gateway.schematic.SchematicV2GatewayFeatureConfig; +import org.dimdev.dimdoors.world.feature.gateway.schematic.TwoPillarsV2Gateway; import net.minecraft.util.Identifier; import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.Registry; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.decorator.Decorator; import net.minecraft.world.gen.decorator.RangeDecoratorConfig; import net.minecraft.world.gen.feature.ConfiguredFeature; @@ -25,22 +33,42 @@ public final class ModFeatures { public static final Feature SCHEMATIC_GATEWAY_FEATURE = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "schematic_gateway"), new SchematicV2GatewayFeature(SchematicV2GatewayFeatureConfig.CODEC)); public static final Feature LIMBO_GATEWAY_FEATURE = Registry.register(Registry.FEATURE, new Identifier("dimdoors", "limbo_gateway"), new LimboGatewayFeature()); public static final SchematicV2Gateway SANDSTONE_PILLARS_GATEWAY = new SandstonePillarsV2Gateway(); + public static final SchematicV2Gateway TWO_PILLARS_GATEWAY = new TwoPillarsV2Gateway(); public static final ConfiguredFeature SANDSTONE_PILLARS_FEATURE; + public static final ConfiguredFeature TWO_PILLARS_FEATURE; public static final ConfiguredFeature LIMBO_GATEWAY_CONFIGURED_FEATURE; public static ConfiguredFeature ETERNAL_FLUID_LAKE; public static void init() { SANDSTONE_PILLARS_GATEWAY.init(); + TWO_PILLARS_GATEWAY.init(); Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "sandstone_pillars"), SANDSTONE_PILLARS_FEATURE); Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "limbo_gateway"), LIMBO_GATEWAY_CONFIGURED_FEATURE); ETERNAL_FLUID_LAKE = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier("dimdoors", "eternal_fluid_lake"), Feature.LAKE.configure(new SingleStateFeatureConfig(ModBlocks.ETERNAL_FLUID.getDefaultState())).decorate(Decorator.RANGE.configure(new RangeDecoratorConfig(5, 70, 128)).applyChance(20))); + 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>>> features = new ArrayList<>(biome.getGenerationSettings().getFeatures()); + List>> surfaceStructures = new ArrayList<>(features.get(index)); + surfaceStructures.add(() -> TWO_PILLARS_FEATURE); + features.set(index, surfaceStructures); + ((GenerationSettingsAccessor) biome.getGenerationSettings()).setFeatures(features); + }); + } } static { int gatewayChance = FabricLoader.getInstance().isDevelopmentEnvironment() ? 20 : ModConfig.INSTANCE.getWorldConfig().gatewayGenChance; - SANDSTONE_PILLARS_FEATURE = SCHEMATIC_GATEWAY_FEATURE.configure(new SchematicV2GatewayFeatureConfig(SchematicV2Gateway.SCHEMATIC_ID_MAP.get(SANDSTONE_PILLARS_GATEWAY))) - .decorate(ConfiguredFeatures.Decorators.SQUARE_TOP_SOLID_HEIGHTMAP - .applyChance(gatewayChance)); + SANDSTONE_PILLARS_FEATURE = SCHEMATIC_GATEWAY_FEATURE.configure(new SchematicV2GatewayFeatureConfig(SchematicV2Gateway.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 SchematicV2GatewayFeatureConfig(SchematicV2Gateway.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)); } } diff --git a/src/main/java/org/dimdev/dimdoors/world/feature/gateway/schematic/SchematicV2Gateway.java b/src/main/java/org/dimdev/dimdoors/world/feature/gateway/schematic/SchematicV2Gateway.java index ac91457b..d046261b 100644 --- a/src/main/java/org/dimdev/dimdoors/world/feature/gateway/schematic/SchematicV2Gateway.java +++ b/src/main/java/org/dimdev/dimdoors/world/feature/gateway/schematic/SchematicV2Gateway.java @@ -22,11 +22,9 @@ public abstract class SchematicV2Gateway implements Gateway { private static final Logger LOGGER = LogManager.getLogger(); private Schematic schematic; private final String id; - public static final BiMap SCHEMATIC_ID_MAP = HashBiMap.create(); public static final BiMap ID_SCHEMATIC_MAP = HashBiMap.create(); public SchematicV2Gateway(String id) { - SCHEMATIC_ID_MAP.putIfAbsent(this, id); ID_SCHEMATIC_MAP.putIfAbsent(id, this); this.id = id; } diff --git a/src/main/resources/dimdoors.mixins.json b/src/main/resources/dimdoors.mixins.json index 3af8b0f0..b648a3af 100644 --- a/src/main/resources/dimdoors.mixins.json +++ b/src/main/resources/dimdoors.mixins.json @@ -10,6 +10,7 @@ "DimensionTypeAccessor", "DirectionAccessor", "EntityMixin", + "GenerationSettingsAccessor", "ListTagAccessor", "PlayerEntityMixin", "RedstoneWireBlockAccessor"