Fixed Mixin and Frozen Registry Errors

This commit is contained in:
Frank 2022-10-25 17:46:08 +02:00
parent 8edddec2b6
commit 73687e3401
10 changed files with 89 additions and 110 deletions

View file

@ -10,7 +10,6 @@ import net.minecraft.core.Holder;
import net.minecraft.core.MappedRegistry; import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.KeyDispatchDataCodec; import net.minecraft.util.KeyDispatchDataCodec;
@ -88,37 +87,40 @@ public class BCLBiomeRegistry {
@ApiStatus.Internal @ApiStatus.Internal
public static Holder<BCLBiome> bootstrap(Registry<BCLBiome> registry) { public static Holder<BCLBiome> bootstrap(Registry<BCLBiome> registry) {
BuiltinRegistries.register(registry, BiomeAPI.SMALL_END_ISLANDS.getBCLBiomeKey(), BiomeAPI.SMALL_END_ISLANDS); //TODO:1.19.3 Registry is frozen at this point
BuiltinRegistries.register(registry, BiomeAPI.END_BARRENS.getBCLBiomeKey(), BiomeAPI.END_BARRENS); // BuiltinRegistries.register(registry, BiomeAPI.SMALL_END_ISLANDS.getBCLBiomeKey(), BiomeAPI.SMALL_END_ISLANDS);
BuiltinRegistries.register(registry, BiomeAPI.END_HIGHLANDS.getBCLBiomeKey(), BiomeAPI.END_HIGHLANDS); // BuiltinRegistries.register(registry, BiomeAPI.END_BARRENS.getBCLBiomeKey(), BiomeAPI.END_BARRENS);
BuiltinRegistries.register(registry, BiomeAPI.END_MIDLANDS.getBCLBiomeKey(), BiomeAPI.END_MIDLANDS); // BuiltinRegistries.register(registry, BiomeAPI.END_HIGHLANDS.getBCLBiomeKey(), BiomeAPI.END_HIGHLANDS);
BuiltinRegistries.register(registry, BiomeAPI.THE_END.getBCLBiomeKey(), BiomeAPI.THE_END); // BuiltinRegistries.register(registry, BiomeAPI.END_MIDLANDS.getBCLBiomeKey(), BiomeAPI.END_MIDLANDS);
BuiltinRegistries.register( // BuiltinRegistries.register(registry, BiomeAPI.THE_END.getBCLBiomeKey(), BiomeAPI.THE_END);
registry, // BuiltinRegistries.register(
BiomeAPI.BASALT_DELTAS_BIOME.getBCLBiomeKey(), // registry,
BiomeAPI.BASALT_DELTAS_BIOME // BiomeAPI.BASALT_DELTAS_BIOME.getBCLBiomeKey(),
); // BiomeAPI.BASALT_DELTAS_BIOME
BuiltinRegistries.register( // );
registry, // BuiltinRegistries.register(
BiomeAPI.SOUL_SAND_VALLEY_BIOME.getBCLBiomeKey(), // registry,
BiomeAPI.SOUL_SAND_VALLEY_BIOME // BiomeAPI.SOUL_SAND_VALLEY_BIOME.getBCLBiomeKey(),
); // BiomeAPI.SOUL_SAND_VALLEY_BIOME
BuiltinRegistries.register( // );
registry, // BuiltinRegistries.register(
BiomeAPI.WARPED_FOREST_BIOME.getBCLBiomeKey(), // registry,
BiomeAPI.WARPED_FOREST_BIOME // BiomeAPI.WARPED_FOREST_BIOME.getBCLBiomeKey(),
); // BiomeAPI.WARPED_FOREST_BIOME
BuiltinRegistries.register( // );
registry, // BuiltinRegistries.register(
BiomeAPI.CRIMSON_FOREST_BIOME.getBCLBiomeKey(), // registry,
BiomeAPI.CRIMSON_FOREST_BIOME // BiomeAPI.CRIMSON_FOREST_BIOME.getBCLBiomeKey(),
); // BiomeAPI.CRIMSON_FOREST_BIOME
BuiltinRegistries.register( // );
registry, // BuiltinRegistries.register(
BiomeAPI.NETHER_WASTES_BIOME.getBCLBiomeKey(), // registry,
BiomeAPI.NETHER_WASTES_BIOME // BiomeAPI.NETHER_WASTES_BIOME.getBCLBiomeKey(),
); // BiomeAPI.NETHER_WASTES_BIOME
return BuiltinRegistries.register(registry, EMPTY_BIOME.getBCLBiomeKey(), EMPTY_BIOME); // );
// return BuiltinRegistries.register(registry, EMPTY_BIOME.getBCLBiomeKey(), EMPTY_BIOME);
return Holder.direct(EMPTY_BIOME);
} }
public static BCLBiome get(ResourceLocation loc) { public static BCLBiome get(ResourceLocation loc) {

View file

@ -6,7 +6,6 @@ import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.util.profiling.ProfilerFiller;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@ -26,11 +25,7 @@ public abstract class ModelBakeryMixin {
@Inject(method = "<init>*", at = @At("TAIL")) @Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_findEmissiveModels( private void bclib_findEmissiveModels(
ResourceManager resourceManager, BlockColors blockColors, ProfilerFiller profilerFiller, Map map, Map map2, CallbackInfo ci
BlockColors blockColors,
ProfilerFiller profiler,
int mipmap,
CallbackInfo info
) { ) {
//CustomModelBakery.setModelsLoaded(false); //CustomModelBakery.setModelsLoaded(false);
if (ModIntegrationAPI.hasCanvas()) { if (ModIntegrationAPI.hasCanvas()) {

View file

@ -1,25 +1,18 @@
package org.betterx.bclib.mixin.client; package org.betterx.bclib.mixin.client;
import org.betterx.bclib.client.BCLibClient;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelManager; import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ModelManager.class) @Mixin(ModelManager.class)
public class ModelManagerMixin { public class ModelManagerMixin {
@Inject(method = "prepare", at = @At("HEAD")) //TODO: 1.19.3 Disabled for now
private void bclib_loadCustomModels( // @Inject(method = "prepare", at = @At("HEAD"))
ResourceManager resourceManager, // private void bclib_loadCustomModels(
ProfilerFiller profilerFiller, // ResourceManager resourceManager,
CallbackInfoReturnable<ModelBakery> info // ProfilerFiller profilerFiller,
) { // CallbackInfoReturnable<ModelBakery> info
BCLibClient.modelBakery.loadCustomModels(resourceManager); // ) {
} // BCLibClient.modelBakery.loadCustomModels(resourceManager);
// }
} }

View file

@ -1,9 +1,6 @@
package org.betterx.bclib.mixin.common; package org.betterx.bclib.mixin.common;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import com.mojang.serialization.Lifecycle; import com.mojang.serialization.Lifecycle;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.WritableRegistry; import net.minecraft.core.WritableRegistry;
import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.BuiltinRegistries;
@ -30,11 +27,12 @@ public abstract class BuiltinRegistriesMixin {
//this needs to be added BEFORE the WORLD_PRESET-Registry. Otherwise decoding will fail! //this needs to be added BEFORE the WORLD_PRESET-Registry. Otherwise decoding will fail!
@Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/data/BuiltinRegistries;registerSimple(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/data/BuiltinRegistries$RegistryBootstrap;)Lnet/minecraft/core/Registry;", ordinal = 0)) @Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/data/BuiltinRegistries;registerSimple(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/data/BuiltinRegistries$RegistryBootstrap;)Lnet/minecraft/core/Registry;", ordinal = 0))
private static void bcl_registerBuiltin(CallbackInfo ci) { private static void bcl_registerBuiltin(CallbackInfo ci) {
BCLBiomeRegistry.BUILTIN_BCL_BIOMES = internalRegister( //TODO: 1.19.3 reenable
BCLBiomeRegistry.BCL_BIOMES_REGISTRY, // BCLBiomeRegistry.BUILTIN_BCL_BIOMES = internalRegister(
(MappedRegistry) BCLBiomeRegistry.BUILTIN_BCL_BIOMES, // BCLBiomeRegistry.BCL_BIOMES_REGISTRY,
BCLBiomeRegistry::bootstrap, // (MappedRegistry) BCLBiomeRegistry.BUILTIN_BCL_BIOMES,
Lifecycle.stable() // BCLBiomeRegistry::bootstrap,
); // Lifecycle.stable()
// );
} }
} }

View file

@ -1,16 +1,14 @@
package org.betterx.bclib.registry; package org.betterx.bclib.registry;
import org.betterx.bclib.client.gui.screens.WorldSetupScreen;
import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class PresetsRegistryClient { public class PresetsRegistryClient {
public static void onLoad() { public static void onLoad() {
WorldPresetsClient.registerCustomizeUI(PresetsRegistry.BCL_WORLD, (createWorldScreen, worldCreationContext) -> { //TODO:1.19.3 Disabled for now
return new WorldSetupScreen(createWorldScreen, worldCreationContext); // WorldPresetsClient.registerCustomizeUI(PresetsRegistry.BCL_WORLD, (createWorldScreen, worldCreationContext) -> {
}); // return new WorldSetupScreen(createWorldScreen, worldCreationContext);
// });
} }
} }

View file

@ -8,7 +8,7 @@ import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent; import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.WorldLoader; import net.minecraft.server.WorldLoader;
import net.minecraft.world.level.DataPackConfig; import net.minecraft.world.level.WorldDataConfiguration;
import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset; import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource;
@ -34,7 +34,7 @@ public class CreateWorldScreenMixin {
@Inject(method = "<init>", at = @At("TAIL")) @Inject(method = "<init>", at = @At("TAIL"))
private void wt_init( private void wt_init(
Screen screen, Screen screen,
DataPackConfig dataPackConfig, WorldDataConfiguration worldDataConfiguration,
WorldGenSettingsComponent worldGenSettingsComponent, WorldGenSettingsComponent worldGenSettingsComponent,
CallbackInfo ci CallbackInfo ci
) { ) {

View file

@ -1,13 +1,9 @@
package org.betterx.worlds.together.mixin.common; package org.betterx.worlds.together.mixin.common;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.progress.ChunkProgressListener; import net.minecraft.server.level.progress.ChunkProgressListener;
import net.minecraft.world.level.storage.WorldData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@ -18,12 +14,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
*/ */
@Mixin(value = MinecraftServer.class, priority = 2000) @Mixin(value = MinecraftServer.class, priority = 2000)
public class MinecraftServerMixin { public class MinecraftServerMixin {
@Shadow // @Shadow
@Final // @Final
private RegistryAccess.Frozen registryHolder; // private RegistryAccess.Frozen registryHolder;
@Shadow // @Shadow
@Final // @Final
protected WorldData worldData; // protected WorldData worldData;
@Inject(method = "createLevels", at = @At(value = "HEAD")) @Inject(method = "createLevels", at = @At(value = "HEAD"))
private void together_addSurfaceRules(ChunkProgressListener worldGenerationProgressListener, CallbackInfo ci) { private void together_addSurfaceRules(ChunkProgressListener worldGenerationProgressListener, CallbackInfo ci) {

View file

@ -14,7 +14,8 @@ public class WorldLoaderMixin {
//this is the place a new Registry access gets first istantiated //this is the place a new Registry access gets first istantiated
//either when a new Datapack was added to a world on the create-screen //either when a new Datapack was added to a world on the create-screen
//or because we did start world loading //or because we did start world loading
@ModifyArg(method = "load", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/ReloadableServerResources;loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/RegistryAccess$Frozen;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;")) //TODO: 1.19.3 This might get replaced by the data Providers...
@ModifyArg(method = "load", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/ReloadableServerResources;loadResources(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/core/RegistryAccess$Frozen;Lnet/minecraft/world/flag/FeatureFlagSet;Lnet/minecraft/commands/Commands$CommandSelection;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
private static RegistryAccess.Frozen wt_newRegistry(RegistryAccess.Frozen frozen) { private static RegistryAccess.Frozen wt_newRegistry(RegistryAccess.Frozen frozen) {
WorldBootstrap.InGUI.registryReady(frozen); WorldBootstrap.InGUI.registryReady(frozen);
return frozen; return frozen;

View file

@ -1,13 +1,9 @@
package org.betterx.worlds.together.mixin.common; package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.levelgen.WorldGenUtil;
import org.betterx.worlds.together.worldPreset.WorldPresets;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset; import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.levelgen.structure.StructureSet; import net.minecraft.world.level.levelgen.structure.StructureSet;
@ -16,8 +12,6 @@ import net.minecraft.world.level.levelgen.synth.NormalNoise;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(net.minecraft.world.level.levelgen.presets.WorldPresets.Bootstrap.class) @Mixin(net.minecraft.world.level.levelgen.presets.WorldPresets.Bootstrap.class)
public abstract class WorldPresetsBootstrapMixin { public abstract class WorldPresetsBootstrapMixin {
@ -48,26 +42,27 @@ public abstract class WorldPresetsBootstrapMixin {
//see WorldPresets.register //see WorldPresets.register
@ModifyArg(method = "run", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap;registerCustomOverworldPreset(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/LevelStem;)Lnet/minecraft/core/Holder;")) //TODO: 1.19.3
private LevelStem bcl_getOverworldStem(LevelStem overworldStem) { // @ModifyArg(method = "run", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap;registerCustomOverworldPreset(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/LevelStem;)Lnet/minecraft/core/Holder;"))
WorldGenUtil.Context netherContext = new WorldGenUtil.Context( // private LevelStem bcl_getOverworldStem(LevelStem overworldStem) {
this.biomes, // WorldGenUtil.Context netherContext = new WorldGenUtil.Context(
this.netherDimensionType, // this.biomes,
this.structureSets, // this.netherDimensionType,
this.noises, // this.structureSets,
this.netherNoiseSettings // this.noises,
); // this.netherNoiseSettings
WorldGenUtil.Context endContext = new WorldGenUtil.Context( // );
this.biomes, // WorldGenUtil.Context endContext = new WorldGenUtil.Context(
this.endDimensionType, // this.biomes,
this.structureSets, // this.endDimensionType,
this.noises, // this.structureSets,
this.endNoiseSettings // this.noises,
); // this.endNoiseSettings
// );
WorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext); //
// WorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext);
return overworldStem; //
} // return overworldStem;
// }
} }

View file

@ -90,7 +90,8 @@ public class WorldPresets {
for (Map.Entry<ResourceKey<WorldPreset>, PresetBuilder> e : BUILDERS.entrySet()) { for (Map.Entry<ResourceKey<WorldPreset>, PresetBuilder> e : BUILDERS.entrySet()) {
TogetherWorldPreset preset = e.getValue().create(overworldStem, netherContext, endContext); TogetherWorldPreset preset = e.getValue().create(overworldStem, netherContext, endContext);
BuiltinRegistries.register(presets, e.getKey(), preset); //TODO: 1.19.3 already frozen
//BuiltinRegistries.register(presets, e.getKey(), preset);
} }
BUILDERS = null; BUILDERS = null;
} }