diff --git a/fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/api/structure/v1/FabricStructureBuilder.java b/fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/api/structure/v1/FabricStructureBuilder.java index 445042427..40d7a3a38 100644 --- a/fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/api/structure/v1/FabricStructureBuilder.java +++ b/fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/api/structure/v1/FabricStructureBuilder.java @@ -20,16 +20,14 @@ import java.util.Objects; import com.google.common.collect.ImmutableList; -import net.minecraft.world.gen.GenerationStep; import net.minecraft.util.Identifier; +import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.chunk.StructureConfig; import net.minecraft.world.gen.chunk.StructuresConfig; -import net.minecraft.world.gen.feature.ConfiguredStructureFeature; import net.minecraft.world.gen.feature.FeatureConfig; import net.minecraft.world.gen.feature.StructureFeature; import net.fabricmc.fabric.impl.structure.FabricStructureImpl; -import net.fabricmc.fabric.mixin.structure.FlatChunkGeneratorConfigAccessor; import net.fabricmc.fabric.mixin.structure.StructureFeatureAccessor; /** @@ -55,7 +53,7 @@ public final class FabricStructureBuilder> superflatFeature; + private boolean generateInSuperflat = false; private boolean adjustsSurface = false; private FabricStructureBuilder(Identifier id, S structure) { @@ -66,7 +64,7 @@ public final class FabricStructureBuilder> FabricStructureBuilder create(Identifier id, S structure) { @@ -113,11 +111,10 @@ public final class FabricStructureBuilderThis is a required option. Vanilla needs it to function.

* - * @param spacing The average distance between 2 structures of this type along the X and Z axes. + * @param spacing The average distance between 2 structures of this type along the X and Z axes. * @param separation The minimum distance between 2 structures of this type. - * @param salt The random salt of the structure. This does not affect how common the structure is, but every - * structure must have an unique {@code salt} in order to spawn in different places. - * + * @param salt The random salt of the structure. This does not affect how common the structure is, but every + * structure must have an unique {@code salt} in order to spawn in different places. * @see #defaultConfig(StructureConfig) */ public FabricStructureBuilder defaultConfig(int spacing, int separation, int salt) { @@ -125,27 +122,14 @@ public final class FabricStructureBuilder superflatFeature(ConfiguredStructureFeature> superflatFeature) { - Objects.requireNonNull(superflatFeature, "superflatFeature must not be null"); - this.superflatFeature = superflatFeature; + public FabricStructureBuilder enableSuperflat() { + this.generateInSuperflat = true; return this; } - /** - * Sets the structure configuration which spawns in superflat worlds. If unset, this structure will not spawn in - * superflat worlds. - * - * @see #superflatFeature(ConfiguredStructureFeature) - */ - public FabricStructureBuilder superflatFeature(FC config) { - return superflatFeature(structure.configure(config)); - } - /** * Causes structure pieces of this structure to adjust the surface of the world to fit them, so that they don't * stick out of or into the ground. @@ -174,8 +158,8 @@ public final class FabricStructureBuilder, StructureConfig> FLAT_STRUCTURE_TO_CONFIG_MAP = new HashMap<>(); + //Keeps a map of structures to structure configs. public static final Map, StructureConfig> STRUCTURE_TO_CONFIG_MAP = new HashMap<>(); diff --git a/fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/mixin/structure/FlatChunkGeneratorConfigAccessor.java b/fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/mixin/structure/FlatChunkGeneratorConfigMixin.java similarity index 54% rename from fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/mixin/structure/FlatChunkGeneratorConfigAccessor.java rename to fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/mixin/structure/FlatChunkGeneratorConfigMixin.java index 162717921..e122e987a 100644 --- a/fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/mixin/structure/FlatChunkGeneratorConfigAccessor.java +++ b/fabric-structure-api-v1/src/main/java/net/fabricmc/fabric/mixin/structure/FlatChunkGeneratorConfigMixin.java @@ -16,19 +16,21 @@ package net.fabricmc.fabric.mixin.structure; -import java.util.Map; - import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import net.minecraft.world.gen.chunk.FlatChunkGeneratorConfig; -import net.minecraft.world.gen.feature.ConfiguredStructureFeature; -import net.minecraft.world.gen.feature.StructureFeature; +import net.minecraft.world.gen.chunk.StructuresConfig; + +import net.fabricmc.fabric.impl.structure.FabricStructureImpl; @Mixin(FlatChunkGeneratorConfig.class) -public interface FlatChunkGeneratorConfigAccessor { - @Accessor("STRUCTURE_TO_FEATURES") - static Map, ConfiguredStructureFeature> getStructureToFeatures() { - throw new AssertionError("Untransformed accessor"); +public class FlatChunkGeneratorConfigMixin { + @Inject(method = "getDefaultConfig", at = @At(value = "RETURN")) + private static void createDefaultConfig(CallbackInfoReturnable cir) { + StructuresConfig structuresConfig = cir.getReturnValue().getStructuresConfig(); + structuresConfig.getStructures().putAll(FabricStructureImpl.FLAT_STRUCTURE_TO_CONFIG_MAP); } } diff --git a/fabric-structure-api-v1/src/main/resources/fabric-structure-api-v1.mixins.json b/fabric-structure-api-v1/src/main/resources/fabric-structure-api-v1.mixins.json index 501a06c9e..7d78107fc 100644 --- a/fabric-structure-api-v1/src/main/resources/fabric-structure-api-v1.mixins.json +++ b/fabric-structure-api-v1/src/main/resources/fabric-structure-api-v1.mixins.json @@ -4,7 +4,7 @@ "compatibilityLevel": "JAVA_16", "mixins": [ "ChunkSerializerMixin", - "FlatChunkGeneratorConfigAccessor", + "FlatChunkGeneratorConfigMixin", "StructureFeatureAccessor", "StructuresConfigAccessor" ], diff --git a/fabric-structure-api-v1/src/testmod/java/net/fabricmc/fabric/test/structure/StructureTest.java b/fabric-structure-api-v1/src/testmod/java/net/fabricmc/fabric/test/structure/StructureTest.java index 385e68765..695570a5b 100644 --- a/fabric-structure-api-v1/src/testmod/java/net/fabricmc/fabric/test/structure/StructureTest.java +++ b/fabric-structure-api-v1/src/testmod/java/net/fabricmc/fabric/test/structure/StructureTest.java @@ -61,7 +61,7 @@ public class StructureTest { FabricStructureBuilder.create(new Identifier("fabric", "test_structure"), STRUCTURE) .step(GenerationStep.Feature.SURFACE_STRUCTURES) .defaultConfig(32, 8, 12345) - .superflatFeature(CONFIGURED_STRUCTURE) + .enableSuperflat() .adjustsSurface() .register(); Registry.register(Registry.STRUCTURE_PIECE, new Identifier("fabric", "test_structure_piece"), PIECE); diff --git a/fabric-structure-api-v1/src/testmod/java/net/fabricmc/fabric/test/structure/mixin/MixinConfiguredStructureFeatures.java b/fabric-structure-api-v1/src/testmod/java/net/fabricmc/fabric/test/structure/mixin/MixinConfiguredStructureFeatures.java index f1675f6ce..54a7b8f6b 100644 --- a/fabric-structure-api-v1/src/testmod/java/net/fabricmc/fabric/test/structure/mixin/MixinConfiguredStructureFeatures.java +++ b/fabric-structure-api-v1/src/testmod/java/net/fabricmc/fabric/test/structure/mixin/MixinConfiguredStructureFeatures.java @@ -33,7 +33,7 @@ import net.fabricmc.fabric.test.structure.StructureTest; @Mixin(ConfiguredStructureFeatures.class) public class MixinConfiguredStructureFeatures { - @Inject(method = "method_38571", at = @At("TAIL")) + @Inject(method = "method_38570", at = @At("TAIL")) private static void addStructuresToBiomes(BiConsumer, RegistryKey> consumer, CallbackInfo ci) { consumer.accept(StructureTest.CONFIGURED_STRUCTURE, BiomeKeys.PLAINS); }