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

Commit a05b2f5

Browse files
committed
coderbot's requested changes
1 parent 3fb5f90 commit a05b2f5

18 files changed

Lines changed: 376 additions & 69 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
archivesBaseName = "patchwork-world-types"
1+
archivesBaseName = "patchwork-level-generators"
22
version = getSubprojectVersion(project, "0.1.0")

patchwork-world-types/src/main/java/net/minecraftforge/common/extensions/IForgeWorldType.java renamed to patchwork-level-generators/src/main/java/net/minecraftforge/common/extensions/IForgeWorldType.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package net.minecraftforge.common.extensions;
2121

22+
import java.util.Random;
2223
import java.util.function.LongFunction;
2324

2425
import net.minecraft.client.MinecraftClient;
@@ -41,7 +42,7 @@
4142
import net.fabricmc.api.EnvType;
4243
import net.fabricmc.api.Environment;
4344

44-
import net.patchworkmc.mixin.worldtypes.AccessorBiomeLayers;
45+
import net.patchworkmc.mixin.levelgenerators.AccessorBiomeLayers;
4546

4647
public interface IForgeWorldType {
4748
default LevelGeneratorType getWorldType() {
@@ -56,20 +57,17 @@ default void onGUICreateWorldPress() {
5657

5758
/**
5859
* Called when the 'Customize' button is pressed on world creation GUI.
59-
*
60-
* @param mc The Minecraft instance
61-
* @param gui the createworld GUI
6260
*/
6361
@Environment(EnvType.CLIENT)
64-
default void onCustomizeButton(MinecraftClient mc, CreateWorldScreen gui) {
62+
default void onCustomizeButton(MinecraftClient client, CreateWorldScreen screen) {
6563
if (this == LevelGeneratorType.FLAT) {
66-
mc.openScreen(new CustomizeFlatLevelScreen(gui, gui.generatorOptionsTag));
64+
client.openScreen(new CustomizeFlatLevelScreen(screen, screen.generatorOptionsTag));
6765
} else if (this == LevelGeneratorType.BUFFET) {
68-
mc.openScreen(new CustomizeBuffetLevelScreen(gui, gui.generatorOptionsTag));
66+
client.openScreen(new CustomizeBuffetLevelScreen(screen, screen.generatorOptionsTag));
6967
}
7068
}
7169

72-
default boolean handleSlimeSpawnReduction(java.util.Random random, IWorld world) {
70+
default boolean handleSlimeSpawnReduction(Random random, IWorld world) {
7371
return this == LevelGeneratorType.FLAT && random.nextInt(4) != 1;
7472
}
7573

@@ -83,8 +81,6 @@ default double voidFadeMagnitude() {
8381

8482
/**
8583
* Get the height to render the clouds for this world type.
86-
*
87-
* @return The height to render clouds at
8884
*/
8985
default float getCloudHeight() {
9086
return 128.0F;
@@ -95,21 +91,21 @@ default ChunkGenerator<?> createChunkGenerator(World world) {
9591
}
9692

9793
/**
98-
* Allows modifying the {@link IAreaFactory} used for this type's biome
94+
* Allows modifying the {@link LayerFactory} used for this type's biome
9995
* generation.
10096
*
101-
* @param <T> The type of {@link IArea}.
102-
* @param <C> The type of {@link IContextExtended}.
97+
* @param <T> The type of {@link LayerSampler}.
98+
* @param <C> The type of {@link LayerSampleContext}.
10399
* @param parentLayer The parent layer to feed into any layer you return
104-
* @param chunkSettings The {@link OverworldGenSettings} used to create the
105-
* {@link GenLayerBiome}.
100+
* @param settings The {@link OverworldChunkGeneratorConfig} used to create the
101+
* {@link SetBaseBiomesLayer}.
106102
* @param contextFactory A {@link LongFunction} factory to create contexts of
107103
* the supplied size.
108-
* @return An {@link IAreaFactory} that representing the Biomes to be generated.
104+
* @return A {@link LayerFactory} that representing the Biomes to be generated.
109105
* @see SetBaseBiomesLayer
110106
*/
111-
default <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> getBiomeLayer(LayerFactory<T> parentLayer, OverworldChunkGeneratorConfig chunkSettings, LongFunction<C> contextFactory) {
112-
parentLayer = (new SetBaseBiomesLayer(getWorldType(), chunkSettings)).create(contextFactory.apply(200L), parentLayer);
107+
default <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> getBiomeLayer(LayerFactory<T> parentLayer, OverworldChunkGeneratorConfig settings, LongFunction<C> contextFactory) {
108+
parentLayer = (new SetBaseBiomesLayer(getWorldType(), settings)).create(contextFactory.apply(200L), parentLayer);
113109
parentLayer = AddBambooJungleLayer.INSTANCE.create(contextFactory.apply(1001L), parentLayer);
114110
parentLayer = AccessorBiomeLayers.stack(1000L, ScaleLayer.NORMAL, parentLayer, 2, contextFactory);
115111
parentLayer = EaseBiomeEdgeLayer.INSTANCE.create(contextFactory.apply(1000L), parentLayer);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.impl.levelgenerators;
21+
22+
import java.io.File;
23+
import java.util.concurrent.Executor;
24+
25+
import com.mojang.datafixers.DataFixer;
26+
27+
import net.minecraft.server.MinecraftServer;
28+
import net.minecraft.server.WorldGenerationProgressListener;
29+
import net.minecraft.structure.StructureManager;
30+
31+
public class ChunkManagerValues {
32+
public static File file;
33+
public static DataFixer dataFixer;
34+
public static StructureManager structureManager;
35+
public static Executor workerExecutor;
36+
public static int viewDistance;
37+
public static WorldGenerationProgressListener progressListener;
38+
public static MinecraftServer server;
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package net.patchworkmc.impl.levelgenerators;
2+
3+
import net.minecraftforge.common.extensions.IForgeWorldType;
4+
5+
public interface PatchworkGeneratorType extends IForgeWorldType {
6+
}

patchwork-world-types/src/main/java/net/patchworkmc/impl/worldtypes/PatchworkLevelGeneratorTypes.java renamed to patchwork-level-generators/src/main/java/net/patchworkmc/impl/levelgenerators/PatchworkLevelGeneratorTypes.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
package net.patchworkmc.impl.worldtypes;
20+
package net.patchworkmc.impl.levelgenerators;
2121

2222
import java.lang.reflect.Field;
2323
import java.lang.reflect.Modifier;
@@ -31,11 +31,9 @@ public class PatchworkLevelGeneratorTypes {
3131
private static final Field TYPES;
3232

3333
public static int getNextID() {
34-
LevelGeneratorType[] types;
34+
LevelGeneratorType[] types = LevelGeneratorType.TYPES;
3535

3636
try {
37-
types = (LevelGeneratorType[]) TYPES.get(null);
38-
3937
for (int x = 0; x < types.length; x++) {
4038
if (types[x] == null) {
4139
return x;

patchwork-world-types/src/main/java/net/patchworkmc/mixin/worldtypes/AccessorBiomeLayers.java renamed to patchwork-level-generators/src/main/java/net/patchworkmc/mixin/levelgenerators/AccessorBiomeLayers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
package net.patchworkmc.mixin.worldtypes;
20+
package net.patchworkmc.mixin.levelgenerators;
2121

2222
import java.util.function.LongFunction;
2323

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.mixin.levelgenerators;
21+
22+
import net.minecraftforge.common.extensions.IForgeWorldType;
23+
import org.spongepowered.asm.mixin.Mixin;
24+
import org.spongepowered.asm.mixin.Shadow;
25+
import org.spongepowered.asm.mixin.injection.At;
26+
import org.spongepowered.asm.mixin.injection.Inject;
27+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
28+
29+
import net.minecraft.client.MinecraftClient;
30+
import net.minecraft.client.gui.screen.Screen;
31+
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
32+
import net.minecraft.client.gui.widget.ButtonWidget;
33+
import net.minecraft.text.Text;
34+
import net.minecraft.world.level.LevelGeneratorType;
35+
36+
import net.patchworkmc.impl.levelgenerators.PatchworkGeneratorType;
37+
38+
@Mixin(CreateWorldScreen.class)
39+
public abstract class MixinCreateWorldScreen extends Screen {
40+
protected MixinCreateWorldScreen(Text title) {
41+
super(title);
42+
}
43+
44+
@Shadow
45+
private int generatorType;
46+
private MinecraftClient minecraft;
47+
48+
@Inject(at = @At("RETURN"), method = "method_19926")
49+
private void onCustomizeButton(ButtonWidget widget, CallbackInfo info) {
50+
LevelGeneratorType generatorType = LevelGeneratorType.TYPES[this.generatorType];
51+
52+
if (generatorType instanceof PatchworkGeneratorType) {
53+
((IForgeWorldType) generatorType).onCustomizeButton(this.minecraft, (CreateWorldScreen) (Object) this);
54+
}
55+
}
56+
57+
@Inject(at = @At(value = "INVOKE", target = "org/apache/commons/lang3/StringUtils.isEmpty(Ljava/lang/CharSequence;)Z"), method = "createLevel")
58+
private void onGUICreateWorldPress(CallbackInfo info) {
59+
LevelGeneratorType generatorType = LevelGeneratorType.TYPES[this.generatorType];
60+
61+
if (generatorType instanceof PatchworkGeneratorType) {
62+
((IForgeWorldType) generatorType).onGUICreateWorldPress();
63+
}
64+
}
65+
}

patchwork-world-types/src/main/java/net/patchworkmc/mixin/worldtypes/MixinDimension.java renamed to patchwork-level-generators/src/main/java/net/patchworkmc/mixin/levelgenerators/MixinDimension.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
package net.patchworkmc.mixin.worldtypes;
20+
package net.patchworkmc.mixin.levelgenerators;
2121

2222
import net.minecraftforge.common.extensions.IForgeWorldType;
2323
import org.spongepowered.asm.mixin.Final;
@@ -31,6 +31,8 @@
3131
import net.minecraft.world.dimension.Dimension;
3232
import net.minecraft.world.level.LevelGeneratorType;
3333

34+
import net.patchworkmc.impl.levelgenerators.PatchworkGeneratorType;
35+
3436
@Mixin(Dimension.class)
3537
public class MixinDimension {
3638
@Shadow
@@ -41,7 +43,7 @@ public class MixinDimension {
4143
private void getCloudHeight(CallbackInfoReturnable<Float> info) {
4244
LevelGeneratorType generatorType = this.world.getLevelProperties().getGeneratorType();
4345

44-
if (generatorType instanceof IForgeWorldType) {
46+
if (generatorType instanceof PatchworkGeneratorType) {
4547
info.setReturnValue(((IForgeWorldType) generatorType).getCloudHeight());
4648
}
4749
}
@@ -50,7 +52,7 @@ private void getCloudHeight(CallbackInfoReturnable<Float> info) {
5052
private void getHorizonShadingRatio(CallbackInfoReturnable<Double> info) {
5153
LevelGeneratorType generatorType = this.world.getLevelProperties().getGeneratorType();
5254

53-
if (generatorType instanceof IForgeWorldType) {
55+
if (generatorType instanceof PatchworkGeneratorType) {
5456
info.setReturnValue(((IForgeWorldType) generatorType).voidFadeMagnitude());
5557
}
5658
}

0 commit comments

Comments
 (0)