diff --git a/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/ChunkGeneratorSettingsAccessor.java b/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/ChunkGeneratorSettingsAccessor.java deleted file mode 100644 index 5736610e..00000000 --- a/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/ChunkGeneratorSettingsAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.terraformersmc.cinderscapes.mixin; - -import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; -import net.minecraft.world.gen.surfacebuilder.MaterialRules; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(ChunkGeneratorSettings.class) -public interface ChunkGeneratorSettingsAccessor { - @Accessor("surfaceRule") @Mutable - void cinderscapes$setSurfaceRule(MaterialRules.MaterialRule ruleSource); -} diff --git a/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/MaterialRuleContextAccessor.java b/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/MaterialRuleContextAccessor.java deleted file mode 100644 index 013331b4..00000000 --- a/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/MaterialRuleContextAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.terraformersmc.cinderscapes.mixin; - -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.surfacebuilder.MaterialRules; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(MaterialRules.MaterialRuleContext.class) -public interface MaterialRuleContextAccessor { - @Accessor("chunk") - Chunk cinderscapes$getChunk(); -} diff --git a/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/MixinMinecraftServer.java b/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/MixinMinecraftServer.java deleted file mode 100644 index d91657fc..00000000 --- a/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/MixinMinecraftServer.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.terraformersmc.cinderscapes.mixin; - -import com.terraformersmc.cinderscapes.surfacerules.CinderscapesSurfaceRules; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.WorldGenerationProgressListener; -import net.minecraft.util.registry.RegistryKey; -import net.minecraft.world.SaveProperties; -import net.minecraft.world.dimension.DimensionOptions; -import net.minecraft.world.gen.chunk.ChunkGenerator; -import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; -import net.minecraft.world.gen.chunk.NoiseChunkGenerator; -import net.minecraft.world.gen.surfacebuilder.MaterialRules; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MinecraftServer.class) -public abstract class MixinMinecraftServer { - @Shadow public abstract SaveProperties getSaveProperties(); - - @Inject(method = "createWorlds", at = @At("RETURN")) - private void cinderscapes$hackyAddSurfaceRules(WorldGenerationProgressListener worldGenerationProgressListener, CallbackInfo ci) { - cinderscapes$appendSurfaceRule(this.getSaveProperties(), DimensionOptions.NETHER, CinderscapesSurfaceRules.createRules()); - } - - private static void cinderscapes$appendSurfaceRule(SaveProperties worldData, RegistryKey optionsRegistryKey, MaterialRules.MaterialRule materialRule) { - if (worldData == null) { - // For some reason mods can make world data null as seen in some user crash logs; this makes that issue clearer for us. - throw new NullPointerException("Minecraft server's world data is null, this should be impossible..."); - } - DimensionOptions dimensionOptions = worldData.getGeneratorOptions().getDimensions().get(optionsRegistryKey); - if (dimensionOptions == null) { - throw new NullPointerException(String.format("\"%s\" is not a valid level stem key as it doesn't exist in this world's settings. This is more than likely the result of a broken level.dat and most often occurs when moving a world between MC versions.", optionsRegistryKey.getValue())); - } - ChunkGenerator chunkGenerator = dimensionOptions.getChunkGenerator(); - if (chunkGenerator instanceof NoiseChunkGenerator) { - Object noiseGeneratorSettings = ((NoiseChunkGeneratorAccessor) chunkGenerator).cinderscapes$getSettings().value(); - ((ChunkGeneratorSettingsAccessor) noiseGeneratorSettings).cinderscapes$setSurfaceRule(MaterialRules.sequence(materialRule, ((ChunkGeneratorSettings) noiseGeneratorSettings).surfaceRule())); - } - } -} diff --git a/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/NoiseChunkGeneratorAccessor.java b/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/NoiseChunkGeneratorAccessor.java deleted file mode 100644 index ad8f485a..00000000 --- a/worldgen/src/main/java/com/terraformersmc/cinderscapes/mixin/NoiseChunkGeneratorAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.terraformersmc.cinderscapes.mixin; - -import net.minecraft.util.registry.RegistryEntry; -import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; -import net.minecraft.world.gen.chunk.NoiseChunkGenerator; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(NoiseChunkGenerator.class) -public interface NoiseChunkGeneratorAccessor { - @Accessor("settings") - RegistryEntry cinderscapes$getSettings(); -} diff --git a/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacebuilders/CinderscapesSurfaceBuilders.java b/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacebuilders/CinderscapesSurfaceBuilders.java index c4c35ee3..5bd931e1 100644 --- a/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacebuilders/CinderscapesSurfaceBuilders.java +++ b/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacebuilders/CinderscapesSurfaceBuilders.java @@ -16,6 +16,12 @@ public static void init() { Blocks.MAGMA_BLOCK.getDefaultState(), Blocks.LAVA.getDefaultState() ).setBiomeKey(CinderscapesBiomes.ASHY_SHOALS)); + + builders.add(new LuminousGroveSurfaceBuilder( + CinderscapesBlocks.UMBRAL_NYLIUM.getDefaultState(), + CinderscapesBlocks.UMBRAL_WART_BLOCK.getDefaultState(), + Blocks.NETHERRACK.getDefaultState() + ).setBiomeKey(CinderscapesBiomes.LUMINOUS_GROVE)); } public static ArrayList getBuilders() { diff --git a/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacebuilders/LuminousGroveSurfaceBuilder.java b/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacebuilders/LuminousGroveSurfaceBuilder.java new file mode 100644 index 00000000..df019a8c --- /dev/null +++ b/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacebuilders/LuminousGroveSurfaceBuilder.java @@ -0,0 +1,47 @@ +package com.terraformersmc.cinderscapes.surfacebuilders; + +import net.minecraft.block.BlockState; +import net.minecraft.tag.BiomeTags; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.RegistryEntry; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.source.BiomeAccess; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.gen.chunk.BlockColumn; +import net.minecraft.world.gen.random.AbstractRandom; + +public class LuminousGroveSurfaceBuilder extends CinderscapesSurfaceBuilder { + private final BlockState topMaterial; + private final BlockState midMaterial; + private final BlockState lowMaterial; + + public LuminousGroveSurfaceBuilder(BlockState topMaterial, BlockState midMaterial, BlockState lowMaterial) { + this.topMaterial = topMaterial; + this.midMaterial = midMaterial; + this.lowMaterial = lowMaterial; + } + + @Override + public void generate(BiomeAccess biomeAccess, BlockColumn column, AbstractRandom rand, Chunk chunk, Biome biome, int x, int z, int vHeight, int seaLevel) { + BlockPos pos = new BlockPos(x, -128, z); + boolean inAir = false; + + // Set in-biome netherrack + for (int y = chunk.getTopY() - 6; y >= seaLevel - 1; --y) { + BlockState state = column.getState(y); + if (state.isAir()) { + inAir = true; + } else { + if (inAir && state.isOf(lowMaterial.getBlock()) && biomeAccess.getBiome(pos.withY(y)).matchesKey(biomeKey)) { + column.setState(y, rand.nextFloat() < 0.99f ? topMaterial : midMaterial); + } + inAir = false; + } + } + } + + @Override + public boolean filterBiome(RegistryEntry biome) { + return biome.isIn(BiomeTags.IS_NETHER); + } +} diff --git a/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacerules/CinderscapesSurfaceRules.java b/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacerules/CinderscapesSurfaceRules.java index c91747b3..917ab3c0 100644 --- a/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacerules/CinderscapesSurfaceRules.java +++ b/worldgen/src/main/java/com/terraformersmc/cinderscapes/surfacerules/CinderscapesSurfaceRules.java @@ -22,6 +22,8 @@ public class CinderscapesSurfaceRules { MaterialRules.block(CinderscapesBlocks.UMBRAL_WART_BLOCK.getDefaultState())), MaterialRules.block(CinderscapesBlocks.UMBRAL_NYLIUM.getDefaultState()))))))); + // TODO: Actually ATM there are no active Cinderscapes surface rules. TerraBlender when present overwrites them. + // When we migrate to TerraBlender, consider whether to migrate back from surface builders to surface rules... // At the moment, there's just Luminous Grove. To add another, wrap them in MaterialRules.sequence() public static final MaterialRules.MaterialRule CINDERSCAPES_NETHER_RULES = LUMINOUS_GROVE; diff --git a/worldgen/src/main/resources/cinderscapes-worldgen.accesswidener b/worldgen/src/main/resources/cinderscapes-worldgen.accesswidener index c2cfd8e9..f21ecb88 100644 --- a/worldgen/src/main/resources/cinderscapes-worldgen.accesswidener +++ b/worldgen/src/main/resources/cinderscapes-worldgen.accesswidener @@ -2,8 +2,5 @@ accessWidener v1 named accessible class net/minecraft/world/gen/surfacebuilder/MaterialRules$BlockStateRule accessible class net/minecraft/world/gen/surfacebuilder/MaterialRules$MaterialRuleContext -accessible class net/minecraft/world/gen/surfacebuilder/MaterialRules$BooleanSupplier -accessible method net/minecraft/world/gen/surfacebuilder/MaterialRules$MaterialRuleContext initVerticalContext (IIIIII)V -accessible field net/minecraft/world/gen/surfacebuilder/MaterialRules$MaterialRuleContext surfaceBuilder Lnet/minecraft/world/gen/surfacebuilder/SurfaceBuilder; accessible method net/minecraft/world/gen/surfacebuilder/MaterialRules$MaterialRuleContext method_39551 ()I accessible method net/minecraft/world/gen/surfacebuilder/SurfaceBuilder getNoiseSampler (Lnet/minecraft/util/registry/RegistryKey;)Lnet/minecraft/util/math/noise/DoublePerlinNoiseSampler; diff --git a/worldgen/src/main/resources/mixins.cinderscapes-worldgen.json b/worldgen/src/main/resources/mixins.cinderscapes-worldgen.json index f75d17d0..dc4ccb12 100644 --- a/worldgen/src/main/resources/mixins.cinderscapes-worldgen.json +++ b/worldgen/src/main/resources/mixins.cinderscapes-worldgen.json @@ -3,12 +3,8 @@ "package": "com.terraformersmc.cinderscapes.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ - "ChunkGeneratorSettingsAccessor", - "MaterialRuleContextAccessor", - "MixinMinecraftServer", "MixinNetherCaveCarver", - "MixinSurfaceBuilder", - "NoiseChunkGeneratorAccessor" + "MixinSurfaceBuilder" ], "client": [ ],