|
| 1 | +package net.patchworkmc.mixin.levelgenerators; |
| 2 | + |
| 3 | +import java.util.function.LongFunction; |
| 4 | + |
| 5 | +import com.google.common.collect.ImmutableList; |
| 6 | +import net.minecraftforge.common.extensions.IForgeWorldType; |
| 7 | +import org.spongepowered.asm.mixin.Mixin; |
| 8 | +import org.spongepowered.asm.mixin.Shadow; |
| 9 | +import org.spongepowered.asm.mixin.injection.At; |
| 10 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 11 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 12 | + |
| 13 | +import net.minecraft.world.biome.layer.AddClimateLayers; |
| 14 | +import net.minecraft.world.biome.layer.AddColdClimatesLayer; |
| 15 | +import net.minecraft.world.biome.layer.AddDeepOceanLayer; |
| 16 | +import net.minecraft.world.biome.layer.AddEdgeBiomesLayer; |
| 17 | +import net.minecraft.world.biome.layer.AddHillsLayer; |
| 18 | +import net.minecraft.world.biome.layer.AddIslandLayer; |
| 19 | +import net.minecraft.world.biome.layer.AddMushroomIslandLayer; |
| 20 | +import net.minecraft.world.biome.layer.AddRiversLayer; |
| 21 | +import net.minecraft.world.biome.layer.AddSunflowerPlainsLayer; |
| 22 | +import net.minecraft.world.biome.layer.ApplyOceanTemperatureLayer; |
| 23 | +import net.minecraft.world.biome.layer.BiomeLayers; |
| 24 | +import net.minecraft.world.biome.layer.CellScaleLayer; |
| 25 | +import net.minecraft.world.biome.layer.ContinentLayer; |
| 26 | +import net.minecraft.world.biome.layer.IncreaseEdgeCurvatureLayer; |
| 27 | +import net.minecraft.world.biome.layer.NoiseToRiverLayer; |
| 28 | +import net.minecraft.world.biome.layer.OceanTemperatureLayer; |
| 29 | +import net.minecraft.world.biome.layer.ScaleLayer; |
| 30 | +import net.minecraft.world.biome.layer.SimpleLandNoiseLayer; |
| 31 | +import net.minecraft.world.biome.layer.SmoothenShorelineLayer; |
| 32 | +import net.minecraft.world.biome.layer.type.ParentedLayer; |
| 33 | +import net.minecraft.world.biome.layer.util.LayerFactory; |
| 34 | +import net.minecraft.world.biome.layer.util.LayerSampleContext; |
| 35 | +import net.minecraft.world.biome.layer.util.LayerSampler; |
| 36 | +import net.minecraft.world.gen.chunk.OverworldChunkGeneratorConfig; |
| 37 | +import net.minecraft.world.level.LevelGeneratorType; |
| 38 | + |
| 39 | +import net.patchworkmc.impl.levelgenerators.PatchworkGeneratorType; |
| 40 | + |
| 41 | +@Mixin(BiomeLayers.class) |
| 42 | +public class MixinBiomeLayers { |
| 43 | + @Shadow |
| 44 | + private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> stack(long seed, ParentedLayer layer, LayerFactory<T> parent, int count, LongFunction<C> contextProvider) { |
| 45 | + throw new RuntimeException("Failed to shadow BiomeLayers#stack!"); |
| 46 | + } |
| 47 | + |
| 48 | + @Inject(at = @At("HEAD"), method = "build", cancellable = true) |
| 49 | + private static <T extends LayerSampler, C extends LayerSampleContext<T>> void build(LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider, CallbackInfoReturnable<ImmutableList<LayerFactory<T>>> info) { |
| 50 | + if (generatorType instanceof PatchworkGeneratorType) { |
| 51 | + LayerFactory<T> continentLayer = ContinentLayer.INSTANCE.create(contextProvider.apply(1L)); |
| 52 | + continentLayer = ScaleLayer.FUZZY.create(contextProvider.apply(2000L), continentLayer); |
| 53 | + continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(1L), continentLayer); |
| 54 | + continentLayer = ScaleLayer.NORMAL.create(contextProvider.apply(2001L), continentLayer); |
| 55 | + continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer); |
| 56 | + continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(50L), continentLayer); |
| 57 | + continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(70L), continentLayer); |
| 58 | + continentLayer = AddIslandLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer); |
| 59 | + LayerFactory<T> layerFactory2 = OceanTemperatureLayer.INSTANCE.create(contextProvider.apply(2L)); |
| 60 | + layerFactory2 = stack(2001L, ScaleLayer.NORMAL, layerFactory2, 6, contextProvider); |
| 61 | + continentLayer = AddColdClimatesLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer); |
| 62 | + continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(3L), continentLayer); |
| 63 | + continentLayer = AddClimateLayers.AddTemperateBiomesLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer); |
| 64 | + continentLayer = AddClimateLayers.AddCoolBiomesLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer); |
| 65 | + continentLayer = AddClimateLayers.AddSpecialBiomesLayer.INSTANCE.create(contextProvider.apply(3L), continentLayer); |
| 66 | + continentLayer = ScaleLayer.NORMAL.create(contextProvider.apply(2002L), continentLayer); |
| 67 | + continentLayer = ScaleLayer.NORMAL.create(contextProvider.apply(2003L), continentLayer); |
| 68 | + continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(4L), continentLayer); |
| 69 | + continentLayer = AddMushroomIslandLayer.INSTANCE.create(contextProvider.apply(5L), continentLayer); |
| 70 | + continentLayer = AddDeepOceanLayer.INSTANCE.create(contextProvider.apply(4L), continentLayer); |
| 71 | + continentLayer = stack(1000L, ScaleLayer.NORMAL, continentLayer, 0, contextProvider); |
| 72 | + int biomeSize = 4; |
| 73 | + int riverSize = biomeSize; |
| 74 | + |
| 75 | + if (settings != null) { |
| 76 | + biomeSize = settings.getBiomeSize(); |
| 77 | + riverSize = settings.getRiverSize(); |
| 78 | + } |
| 79 | + |
| 80 | + if (generatorType == LevelGeneratorType.LARGE_BIOMES) { |
| 81 | + biomeSize = 6; |
| 82 | + } |
| 83 | + |
| 84 | + LayerFactory<T> riverLayer = stack(1000L, ScaleLayer.NORMAL, continentLayer, 0, contextProvider); |
| 85 | + riverLayer = SimpleLandNoiseLayer.INSTANCE.create(contextProvider.apply(100L), riverLayer); |
| 86 | + LayerFactory<T> noiseLayer = ((IForgeWorldType) generatorType).getBiomeLayer(continentLayer, settings, contextProvider); |
| 87 | + LayerFactory<T> layerFactory5 = stack(1000L, ScaleLayer.NORMAL, riverLayer, 2, contextProvider); |
| 88 | + noiseLayer = AddHillsLayer.INSTANCE.create(contextProvider.apply(1000L), noiseLayer, layerFactory5); |
| 89 | + riverLayer = stack(1000L, ScaleLayer.NORMAL, riverLayer, 2, contextProvider); |
| 90 | + riverLayer = stack(1000L, ScaleLayer.NORMAL, riverLayer, riverSize, contextProvider); |
| 91 | + riverLayer = NoiseToRiverLayer.INSTANCE.create(contextProvider.apply(1L), riverLayer); |
| 92 | + riverLayer = SmoothenShorelineLayer.INSTANCE.create(contextProvider.apply(1000L), riverLayer); |
| 93 | + noiseLayer = AddSunflowerPlainsLayer.INSTANCE.create(contextProvider.apply(1001L), noiseLayer); |
| 94 | + |
| 95 | + for (int k = 0; k < biomeSize; ++k) { |
| 96 | + noiseLayer = ScaleLayer.NORMAL.create(contextProvider.apply((long) (1000 + k)), noiseLayer); |
| 97 | + |
| 98 | + if (k == 0) { |
| 99 | + noiseLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(3L), noiseLayer); |
| 100 | + } |
| 101 | + |
| 102 | + if (k == 1 || biomeSize == 1) { |
| 103 | + noiseLayer = AddEdgeBiomesLayer.INSTANCE.create(contextProvider.apply(1000L), noiseLayer); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + noiseLayer = SmoothenShorelineLayer.INSTANCE.create(contextProvider.apply(1000L), noiseLayer); |
| 108 | + noiseLayer = AddRiversLayer.INSTANCE.create(contextProvider.apply(100L), noiseLayer, riverLayer); |
| 109 | + noiseLayer = ApplyOceanTemperatureLayer.INSTANCE.create(contextProvider.apply(100L), noiseLayer, layerFactory2); |
| 110 | + LayerFactory<T> biomeLayer = CellScaleLayer.INSTANCE.create(contextProvider.apply(10L), noiseLayer); |
| 111 | + info.setReturnValue(ImmutableList.of(noiseLayer, biomeLayer, noiseLayer)); |
| 112 | + } |
| 113 | + } |
| 114 | +} |
0 commit comments