Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 7d1aec9

Browse files
committed
switch to four redirects
1 parent cb8be5d commit 7d1aec9

2 files changed

Lines changed: 46 additions & 92 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
## Reasoning
2+
3+
* Minecraft forge patches the LevelGeneratorType to be extensible through providing IForgeWorldType and making a public constrcutor
4+
* Numerous mods for forge use this LevelGeneratorType API
5+
16
## TODO
27
* Use IForgeDimension for the getHorizonHeight client mixin to World

patchwork-level-generators/src/main/java/net/patchworkmc/mixin/levelgenerators/MixinBiomeLayers.java

Lines changed: 41 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,16 @@
2121

2222
import java.util.function.LongFunction;
2323

24-
import com.google.common.collect.ImmutableList;
2524
import net.minecraftforge.common.extensions.IForgeWorldType;
2625
import org.spongepowered.asm.mixin.Mixin;
2726
import org.spongepowered.asm.mixin.Shadow;
2827
import org.spongepowered.asm.mixin.injection.At;
29-
import org.spongepowered.asm.mixin.injection.Inject;
30-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
28+
import org.spongepowered.asm.mixin.injection.Redirect;
3129

32-
import net.minecraft.world.biome.layer.AddClimateLayers;
33-
import net.minecraft.world.biome.layer.AddColdClimatesLayer;
34-
import net.minecraft.world.biome.layer.AddDeepOceanLayer;
35-
import net.minecraft.world.biome.layer.AddEdgeBiomesLayer;
36-
import net.minecraft.world.biome.layer.AddHillsLayer;
37-
import net.minecraft.world.biome.layer.AddIslandLayer;
38-
import net.minecraft.world.biome.layer.AddMushroomIslandLayer;
39-
import net.minecraft.world.biome.layer.AddRiversLayer;
40-
import net.minecraft.world.biome.layer.AddSunflowerPlainsLayer;
41-
import net.minecraft.world.biome.layer.ApplyOceanTemperatureLayer;
30+
import net.minecraft.world.biome.layer.AddBambooJungleLayer;
4231
import net.minecraft.world.biome.layer.BiomeLayers;
43-
import net.minecraft.world.biome.layer.CellScaleLayer;
44-
import net.minecraft.world.biome.layer.ContinentLayer;
45-
import net.minecraft.world.biome.layer.IncreaseEdgeCurvatureLayer;
46-
import net.minecraft.world.biome.layer.NoiseToRiverLayer;
47-
import net.minecraft.world.biome.layer.OceanTemperatureLayer;
48-
import net.minecraft.world.biome.layer.ScaleLayer;
49-
import net.minecraft.world.biome.layer.SimpleLandNoiseLayer;
50-
import net.minecraft.world.biome.layer.SmoothenShorelineLayer;
32+
import net.minecraft.world.biome.layer.EaseBiomeEdgeLayer;
33+
import net.minecraft.world.biome.layer.SetBaseBiomesLayer;
5134
import net.minecraft.world.biome.layer.type.ParentedLayer;
5235
import net.minecraft.world.biome.layer.util.LayerFactory;
5336
import net.minecraft.world.biome.layer.util.LayerSampleContext;
@@ -64,81 +47,47 @@ private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFa
6447
throw new RuntimeException("Failed to shadow BiomeLayers#stack!");
6548
}
6649

67-
@Inject(at = @At("HEAD"), method = "build", cancellable = true)
68-
private static <T extends LayerSampler, C extends LayerSampleContext<T>> void build(LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider, CallbackInfoReturnable<ImmutableList<LayerFactory<T>>> info) {
50+
@Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;",
51+
at = @At(value = "INVOKE", target = "net/minecraft/world/biome/layer/SetBaseBiomesLayer.create(Lnet/minecraft/world/biome/layer/util/LayerSampleContext;Lnet/minecraft/world/biome/layer/util/LayerFactory;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 0))
52+
private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> addForgeBiomeLayers(SetBaseBiomesLayer instance, C contextParam, LayerFactory<T> parentLayer, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider) {
6953
if (generatorType instanceof PatchworkLevelGeneratorType) {
70-
LayerFactory<T> continentLayer = ContinentLayer.INSTANCE.create(contextProvider.apply(1L));
71-
continentLayer = ScaleLayer.FUZZY.create(contextProvider.apply(2000L), continentLayer);
72-
73-
continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(1L), continentLayer);
74-
continentLayer = ScaleLayer.NORMAL.create(contextProvider.apply(2001L), continentLayer);
75-
76-
continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer);
77-
continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(50L), continentLayer);
78-
continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(70L), continentLayer);
79-
continentLayer = AddIslandLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer);
80-
81-
LayerFactory<T> layerFactory2 = OceanTemperatureLayer.INSTANCE.create(contextProvider.apply(2L));
82-
layerFactory2 = stack(2001L, ScaleLayer.NORMAL, layerFactory2, 6, contextProvider);
83-
84-
continentLayer = AddColdClimatesLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer);
85-
continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(3L), continentLayer);
86-
continentLayer = AddClimateLayers.AddTemperateBiomesLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer);
87-
continentLayer = AddClimateLayers.AddCoolBiomesLayer.INSTANCE.create(contextProvider.apply(2L), continentLayer);
88-
continentLayer = AddClimateLayers.AddSpecialBiomesLayer.INSTANCE.create(contextProvider.apply(3L), continentLayer);
89-
continentLayer = ScaleLayer.NORMAL.create(contextProvider.apply(2002L), continentLayer);
90-
continentLayer = ScaleLayer.NORMAL.create(contextProvider.apply(2003L), continentLayer);
91-
92-
continentLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(4L), continentLayer);
93-
continentLayer = AddMushroomIslandLayer.INSTANCE.create(contextProvider.apply(5L), continentLayer);
94-
continentLayer = AddDeepOceanLayer.INSTANCE.create(contextProvider.apply(4L), continentLayer);
95-
continentLayer = stack(1000L, ScaleLayer.NORMAL, continentLayer, 0, contextProvider);
96-
97-
int biomeSize = 4;
98-
int riverSize = biomeSize;
99-
100-
if (settings != null) {
101-
biomeSize = settings.getBiomeSize();
102-
riverSize = settings.getRiverSize();
103-
}
104-
105-
if (generatorType == LevelGeneratorType.LARGE_BIOMES) {
106-
biomeSize = 6;
107-
}
108-
109-
LayerFactory<T> riverLayer = stack(1000L, ScaleLayer.NORMAL, continentLayer, 0, contextProvider);
110-
riverLayer = SimpleLandNoiseLayer.INSTANCE.create(contextProvider.apply(100L), riverLayer);
111-
112-
LayerFactory<T> noiseLayer = ((IForgeWorldType) generatorType).getBiomeLayer(continentLayer, settings, contextProvider);
113-
LayerFactory<T> layerFactory5 = stack(1000L, ScaleLayer.NORMAL, riverLayer, 2, contextProvider);
114-
115-
noiseLayer = AddHillsLayer.INSTANCE.create(contextProvider.apply(1000L), noiseLayer, layerFactory5);
116-
117-
riverLayer = stack(1000L, ScaleLayer.NORMAL, riverLayer, 2, contextProvider);
118-
riverLayer = stack(1000L, ScaleLayer.NORMAL, riverLayer, riverSize, contextProvider);
119-
riverLayer = NoiseToRiverLayer.INSTANCE.create(contextProvider.apply(1L), riverLayer);
120-
riverLayer = SmoothenShorelineLayer.INSTANCE.create(contextProvider.apply(1000L), riverLayer);
121-
122-
noiseLayer = AddSunflowerPlainsLayer.INSTANCE.create(contextProvider.apply(1001L), noiseLayer);
123-
124-
for (int k = 0; k < biomeSize; ++k) {
125-
noiseLayer = ScaleLayer.NORMAL.create(contextProvider.apply((long) (1000 + k)), noiseLayer);
126-
127-
if (k == 0) {
128-
noiseLayer = IncreaseEdgeCurvatureLayer.INSTANCE.create(contextProvider.apply(3L), noiseLayer);
129-
}
54+
return ((IForgeWorldType) generatorType).getBiomeLayer(parentLayer, settings, contextProvider);
55+
} else {
56+
// vanilla behaviour
57+
return instance.create(contextParam, parentLayer);
58+
}
59+
}
13060

131-
if (k == 1 || biomeSize == 1) {
132-
noiseLayer = AddEdgeBiomesLayer.INSTANCE.create(contextProvider.apply(1000L), noiseLayer);
133-
}
134-
}
61+
@Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;",
62+
at = @At(value = "INVOKE", target = "net/minecraft/world/biome/layer/AddBambooJungleLayer.create(Lnet/minecraft/world/biome/layer/util/LayerSampleContext;Lnet/minecraft/world/biome/layer/util/LayerFactory;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 0))
63+
private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> redirectBambooJungle(AddBambooJungleLayer instance, C contextParam, LayerFactory<T> parentLayer, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider) {
64+
if (generatorType instanceof PatchworkLevelGeneratorType) {
65+
return parentLayer;
66+
} else {
67+
// vanilla behaviour
68+
return instance.create(contextParam, parentLayer);
69+
}
70+
}
13571

136-
noiseLayer = SmoothenShorelineLayer.INSTANCE.create(contextProvider.apply(1000L), noiseLayer);
137-
noiseLayer = AddRiversLayer.INSTANCE.create(contextProvider.apply(100L), noiseLayer, riverLayer);
138-
noiseLayer = ApplyOceanTemperatureLayer.INSTANCE.create(contextProvider.apply(100L), noiseLayer, layerFactory2);
72+
@Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;",
73+
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/biome/layer/BiomeLayers;stack(JLnet/minecraft/world/biome/layer/type/ParentedLayer;Lnet/minecraft/world/biome/layer/util/LayerFactory;ILjava/util/function/LongFunction;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 3))
74+
private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> redirectStack(long seed, ParentedLayer layer, LayerFactory<T> parentLayer, int count, LongFunction<C> contextProvider, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProviderParam) {
75+
if (generatorType instanceof PatchworkLevelGeneratorType) {
76+
return parentLayer;
77+
} else {
78+
// vanilla behaviour
79+
return stack(seed, layer, parentLayer, count, contextProvider);
80+
}
81+
}
13982

140-
LayerFactory<T> biomeLayer = CellScaleLayer.INSTANCE.create(contextProvider.apply(10L), noiseLayer);
141-
info.setReturnValue(ImmutableList.of(noiseLayer, biomeLayer, noiseLayer));
83+
@Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;",
84+
at = @At(value = "INVOKE", target = "net/minecraft/world/biome/layer/EaseBiomeEdgeLayer.create(Lnet/minecraft/world/biome/layer/util/LayerSampleContext;Lnet/minecraft/world/biome/layer/util/LayerFactory;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 0))
85+
private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> redirectEaseBiomeEdge(EaseBiomeEdgeLayer instance, C contextParam, LayerFactory<T> parentLayer, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider) {
86+
if (generatorType instanceof PatchworkLevelGeneratorType) {
87+
return parentLayer;
88+
} else {
89+
// vanilla behaviour
90+
return instance.create(contextParam, parentLayer);
14291
}
14392
}
14493
}

0 commit comments

Comments
 (0)