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

Commit cb8be5d

Browse files
committed
yes
1 parent 7c489fe commit cb8be5d

12 files changed

Lines changed: 64 additions & 139 deletions

File tree

patchwork-level-generators/src/main/java/net/patchworkmc/api/levelgenerators/PatchworkGeneratorType.java renamed to patchwork-level-generators/src/main/java/net/patchworkmc/api/levelgenerators/PatchworkLevelGeneratorType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
/**
2525
* Used by Patchwork to mark forge level generator types. Added in the patching phase by patcher.
2626
*/
27-
public interface PatchworkGeneratorType extends IForgeWorldType {
27+
public interface PatchworkLevelGeneratorType extends IForgeWorldType {
2828
}

patchwork-level-generators/src/main/java/net/patchworkmc/impl/levelgenerators/PatchworkLevelGeneratorTypes.java

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,25 @@
1919

2020
package net.patchworkmc.impl.levelgenerators;
2121

22-
import java.lang.reflect.Field;
23-
import java.lang.reflect.Modifier;
2422
import java.util.Arrays;
2523

2624
import net.minecraft.world.level.LevelGeneratorType;
2725

28-
import net.fabricmc.loader.api.FabricLoader;
26+
import net.patchworkmc.mixin.levelgenerators.AccessorLevelGeneratorType;
2927

3028
public class PatchworkLevelGeneratorTypes {
31-
private static final Field TYPES;
32-
3329
public static int getNextID() {
3430
LevelGeneratorType[] types = LevelGeneratorType.TYPES;
3531

36-
try {
37-
for (int x = 0; x < types.length; x++) {
38-
if (types[x] == null) {
39-
return x;
40-
}
32+
for (int x = 0; x < types.length; x++) {
33+
if (types[x] == null) {
34+
return x;
4135
}
42-
43-
int old = types.length;
44-
TYPES.set(null, Arrays.copyOf(types, old + 16));
45-
return old;
46-
} catch (IllegalArgumentException | IllegalAccessException e) {
47-
throw new RuntimeException(e);
4836
}
49-
}
5037

51-
static {
52-
try {
53-
TYPES = LevelGeneratorType.class.getDeclaredField(FabricLoader.getInstance().isDevelopmentEnvironment() ? "TYPES" : "field_9279");
54-
// make accessible
55-
TYPES.setAccessible(true);
56-
// make non final
57-
Field modifiers = Field.class.getDeclaredField("modifiers");
58-
modifiers.setAccessible(true);
59-
modifiers.setInt(TYPES, TYPES.getModifiers() & ~Modifier.FINAL);
60-
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
61-
throw new RuntimeException(e);
62-
}
38+
int old = types.length;
39+
AccessorLevelGeneratorType.patchwork$setTypes(Arrays.copyOf(types, old + 16));
40+
return old;
6341
}
6442
}
6543

patchwork-level-generators/src/main/java/net/patchworkmc/impl/levelgenerators/ChunkManagerValues.java renamed to patchwork-level-generators/src/main/java/net/patchworkmc/mixin/levelgenerators/AccessorLevelGeneratorType.java

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

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

22-
import java.io.File;
23-
import java.util.concurrent.Executor;
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.gen.Accessor;
2424

25-
import com.mojang.datafixers.DataFixer;
25+
import net.minecraft.world.level.LevelGeneratorType;
2626

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;
27+
@Mixin(LevelGeneratorType.class)
28+
public interface AccessorLevelGeneratorType {
29+
@Accessor("TYPES")
30+
static void patchwork$setTypes(LevelGeneratorType[] types) {
31+
throw new RuntimeException("Failed to create accessor: LevelGeneratorType#TYPES!");
32+
}
3933
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import net.minecraft.world.gen.chunk.OverworldChunkGeneratorConfig;
5656
import net.minecraft.world.level.LevelGeneratorType;
5757

58-
import net.patchworkmc.api.levelgenerators.PatchworkGeneratorType;
58+
import net.patchworkmc.api.levelgenerators.PatchworkLevelGeneratorType;
5959

6060
@Mixin(BiomeLayers.class)
6161
public class MixinBiomeLayers {
@@ -66,7 +66,7 @@ private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFa
6666

6767
@Inject(at = @At("HEAD"), method = "build", cancellable = true)
6868
private static <T extends LayerSampler, C extends LayerSampleContext<T>> void build(LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider, CallbackInfoReturnable<ImmutableList<LayerFactory<T>>> info) {
69-
if (generatorType instanceof PatchworkGeneratorType) {
69+
if (generatorType instanceof PatchworkLevelGeneratorType) {
7070
LayerFactory<T> continentLayer = ContinentLayer.INSTANCE.create(contextProvider.apply(1L));
7171
continentLayer = ScaleLayer.FUZZY.create(contextProvider.apply(2000L), continentLayer);
7272

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@
2626
import org.spongepowered.asm.mixin.injection.Inject;
2727
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2828

29-
import net.minecraft.client.MinecraftClient;
3029
import net.minecraft.client.gui.screen.Screen;
3130
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
3231
import net.minecraft.client.gui.widget.ButtonWidget;
3332
import net.minecraft.text.Text;
3433
import net.minecraft.world.level.LevelGeneratorType;
3534

36-
import net.patchworkmc.api.levelgenerators.PatchworkGeneratorType;
35+
import net.patchworkmc.api.levelgenerators.PatchworkLevelGeneratorType;
3736

3837
@Mixin(CreateWorldScreen.class)
3938
public abstract class MixinCreateWorldScreen extends Screen {
@@ -43,14 +42,12 @@ protected MixinCreateWorldScreen(Text title) {
4342

4443
@Shadow
4544
private int generatorType;
46-
@Shadow
47-
private MinecraftClient minecraft;
4845

4946
@Inject(at = @At("RETURN"), method = "method_19926")
5047
private void onCustomizeButton(ButtonWidget widget, CallbackInfo info) {
5148
LevelGeneratorType generatorType = LevelGeneratorType.TYPES[this.generatorType];
5249

53-
if (generatorType instanceof PatchworkGeneratorType) {
50+
if (generatorType instanceof PatchworkLevelGeneratorType) {
5451
((IForgeWorldType) generatorType).onCustomizeButton(this.minecraft, (CreateWorldScreen) (Object) this);
5552
}
5653
}
@@ -59,7 +56,7 @@ private void onCustomizeButton(ButtonWidget widget, CallbackInfo info) {
5956
private void onGUICreateWorldPress(CallbackInfo info) {
6057
LevelGeneratorType generatorType = LevelGeneratorType.TYPES[this.generatorType];
6158

62-
if (generatorType instanceof PatchworkGeneratorType) {
59+
if (generatorType instanceof PatchworkLevelGeneratorType) {
6360
((IForgeWorldType) generatorType).onGUICreateWorldPress();
6461
}
6562
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import net.minecraft.world.dimension.Dimension;
3232
import net.minecraft.world.level.LevelGeneratorType;
3333

34-
import net.patchworkmc.api.levelgenerators.PatchworkGeneratorType;
34+
import net.patchworkmc.api.levelgenerators.PatchworkLevelGeneratorType;
3535

3636
@Mixin(Dimension.class)
3737
public class MixinDimension {
@@ -43,7 +43,7 @@ public class MixinDimension {
4343
private void getCloudHeight(CallbackInfoReturnable<Float> info) {
4444
LevelGeneratorType generatorType = this.world.getLevelProperties().getGeneratorType();
4545

46-
if (generatorType instanceof PatchworkGeneratorType) {
46+
if (generatorType instanceof PatchworkLevelGeneratorType) {
4747
info.setReturnValue(((IForgeWorldType) generatorType).getCloudHeight());
4848
}
4949
}
@@ -52,7 +52,7 @@ private void getCloudHeight(CallbackInfoReturnable<Float> info) {
5252
private void getHorizonShadingRatio(CallbackInfoReturnable<Double> info) {
5353
LevelGeneratorType generatorType = this.world.getLevelProperties().getGeneratorType();
5454

55-
if (generatorType instanceof PatchworkGeneratorType) {
55+
if (generatorType instanceof PatchworkLevelGeneratorType) {
5656
info.setReturnValue(((IForgeWorldType) generatorType).voidFadeMagnitude());
5757
}
5858
}

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

Lines changed: 0 additions & 55 deletions
This file was deleted.

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,34 @@
1919

2020
package net.patchworkmc.mixin.levelgenerators;
2121

22+
import java.util.concurrent.Executor;
23+
2224
import net.minecraftforge.common.extensions.IForgeWorldType;
2325
import org.spongepowered.asm.mixin.Mixin;
2426
import org.spongepowered.asm.mixin.injection.At;
25-
import org.spongepowered.asm.mixin.injection.Inject;
26-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
27+
import org.spongepowered.asm.mixin.injection.Redirect;
2728

28-
import net.minecraft.server.world.ServerChunkManager;
29+
import net.minecraft.server.MinecraftServer;
30+
import net.minecraft.server.WorldGenerationProgressListener;
2931
import net.minecraft.server.world.ServerWorld;
3032
import net.minecraft.world.World;
31-
import net.minecraft.world.chunk.ChunkManager;
33+
import net.minecraft.world.WorldSaveHandler;
3234
import net.minecraft.world.dimension.Dimension;
33-
import net.minecraft.world.dimension.DimensionType;
35+
import net.minecraft.world.gen.chunk.ChunkGenerator;
3436
import net.minecraft.world.level.LevelGeneratorType;
3537

36-
import net.patchworkmc.api.levelgenerators.PatchworkGeneratorType;
37-
import net.patchworkmc.impl.levelgenerators.ChunkManagerValues;
38+
import net.patchworkmc.api.levelgenerators.PatchworkLevelGeneratorType;
3839

3940
@Mixin(ServerWorld.class)
4041
public abstract class MixinServerWorld {
41-
@Inject(method = "method_14168", at = @At("HEAD"), cancellable = true)
42-
private static void createChunkGenerator(World world, Dimension dimension, CallbackInfoReturnable<ChunkManager> info) {
42+
@Redirect(method = "method_14168", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;createChunkGenerator()Lnet/minecraft/world/gen/chunk/ChunkGenerator;"))
43+
private static ChunkGenerator<?> createChunkGenerator(Dimension dimension, WorldSaveHandler saveHandler, Executor executor, MinecraftServer minecraftServer, WorldGenerationProgressListener progressListener, World world, Dimension dimensionArg) {
4344
LevelGeneratorType generatorType = world.getLevelProperties().getGeneratorType();
4445

45-
if (generatorType instanceof PatchworkGeneratorType) {
46-
info.setReturnValue(new ServerChunkManager((ServerWorld) world,
47-
ChunkManagerValues.file,
48-
ChunkManagerValues.dataFixer,
49-
ChunkManagerValues.structureManager,
50-
ChunkManagerValues.workerExecutor,
51-
((IForgeWorldType) generatorType).createChunkGenerator(world),
52-
ChunkManagerValues.viewDistance,
53-
ChunkManagerValues.progressListener,
54-
() -> {
55-
return ChunkManagerValues.server.getWorld(DimensionType.OVERWORLD).getPersistentStateManager();
56-
}));
46+
if (generatorType instanceof PatchworkLevelGeneratorType) {
47+
return ((IForgeWorldType) generatorType).createChunkGenerator(world);
48+
} else {
49+
return dimension.createChunkGenerator();
5750
}
5851
}
5952
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
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+
120
package net.patchworkmc.mixin.levelgenerators;
221

322
import net.minecraftforge.common.extensions.IForgeWorldType;
@@ -12,7 +31,7 @@
1231
import net.minecraft.world.level.LevelGeneratorType;
1332
import net.minecraft.world.level.LevelProperties;
1433

15-
import net.patchworkmc.api.levelgenerators.PatchworkGeneratorType;
34+
import net.patchworkmc.api.levelgenerators.PatchworkLevelGeneratorType;
1635

1736
@Mixin(World.class)
1837
public class MixinWorld {
@@ -24,7 +43,7 @@ public class MixinWorld {
2443
private void getHorizonHeight(CallbackInfoReturnable<Double> info) { // TODO: use IForgeDimension
2544
LevelGeneratorType generatorType = this.properties.getGeneratorType();
2645

27-
if (generatorType instanceof PatchworkGeneratorType) {
46+
if (generatorType instanceof PatchworkLevelGeneratorType) {
2847
info.setReturnValue(((IForgeWorldType) generatorType).getHorizon((World) (Object) this));
2948
}
3049
}

patchwork-level-generators/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"PatchworkMC"
1414
],
1515
"depends": {
16-
"fabricloader": ">=0.6.2",
17-
"patchwork-fml": "*"
16+
"fabricloader": ">=0.6.2"
1817
},
1918
"description": "Implementation of the Forge World Type API.",
2019
"mixins": [

0 commit comments

Comments
 (0)