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.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.KeyDispatchDataCodec;
@ -88,37 +87,40 @@ public class BCLBiomeRegistry {
@ApiStatus.Internal
public static Holder<BCLBiome> bootstrap(Registry<BCLBiome> registry) {
BuiltinRegistries.register(registry, BiomeAPI.SMALL_END_ISLANDS.getBCLBiomeKey(), BiomeAPI.SMALL_END_ISLANDS);
BuiltinRegistries.register(registry, BiomeAPI.END_BARRENS.getBCLBiomeKey(), BiomeAPI.END_BARRENS);
BuiltinRegistries.register(registry, BiomeAPI.END_HIGHLANDS.getBCLBiomeKey(), BiomeAPI.END_HIGHLANDS);
BuiltinRegistries.register(registry, BiomeAPI.END_MIDLANDS.getBCLBiomeKey(), BiomeAPI.END_MIDLANDS);
BuiltinRegistries.register(registry, BiomeAPI.THE_END.getBCLBiomeKey(), BiomeAPI.THE_END);
BuiltinRegistries.register(
registry,
BiomeAPI.BASALT_DELTAS_BIOME.getBCLBiomeKey(),
BiomeAPI.BASALT_DELTAS_BIOME
);
BuiltinRegistries.register(
registry,
BiomeAPI.SOUL_SAND_VALLEY_BIOME.getBCLBiomeKey(),
BiomeAPI.SOUL_SAND_VALLEY_BIOME
);
BuiltinRegistries.register(
registry,
BiomeAPI.WARPED_FOREST_BIOME.getBCLBiomeKey(),
BiomeAPI.WARPED_FOREST_BIOME
);
BuiltinRegistries.register(
registry,
BiomeAPI.CRIMSON_FOREST_BIOME.getBCLBiomeKey(),
BiomeAPI.CRIMSON_FOREST_BIOME
);
BuiltinRegistries.register(
registry,
BiomeAPI.NETHER_WASTES_BIOME.getBCLBiomeKey(),
BiomeAPI.NETHER_WASTES_BIOME
);
return BuiltinRegistries.register(registry, EMPTY_BIOME.getBCLBiomeKey(), EMPTY_BIOME);
//TODO:1.19.3 Registry is frozen at this point
// BuiltinRegistries.register(registry, BiomeAPI.SMALL_END_ISLANDS.getBCLBiomeKey(), BiomeAPI.SMALL_END_ISLANDS);
// BuiltinRegistries.register(registry, BiomeAPI.END_BARRENS.getBCLBiomeKey(), BiomeAPI.END_BARRENS);
// BuiltinRegistries.register(registry, BiomeAPI.END_HIGHLANDS.getBCLBiomeKey(), BiomeAPI.END_HIGHLANDS);
// BuiltinRegistries.register(registry, BiomeAPI.END_MIDLANDS.getBCLBiomeKey(), BiomeAPI.END_MIDLANDS);
// BuiltinRegistries.register(registry, BiomeAPI.THE_END.getBCLBiomeKey(), BiomeAPI.THE_END);
// BuiltinRegistries.register(
// registry,
// BiomeAPI.BASALT_DELTAS_BIOME.getBCLBiomeKey(),
// BiomeAPI.BASALT_DELTAS_BIOME
// );
// BuiltinRegistries.register(
// registry,
// BiomeAPI.SOUL_SAND_VALLEY_BIOME.getBCLBiomeKey(),
// BiomeAPI.SOUL_SAND_VALLEY_BIOME
// );
// BuiltinRegistries.register(
// registry,
// BiomeAPI.WARPED_FOREST_BIOME.getBCLBiomeKey(),
// BiomeAPI.WARPED_FOREST_BIOME
// );
// BuiltinRegistries.register(
// registry,
// BiomeAPI.CRIMSON_FOREST_BIOME.getBCLBiomeKey(),
// BiomeAPI.CRIMSON_FOREST_BIOME
// );
// BuiltinRegistries.register(
// registry,
// BiomeAPI.NETHER_WASTES_BIOME.getBCLBiomeKey(),
// BiomeAPI.NETHER_WASTES_BIOME
// );
// return BuiltinRegistries.register(registry, EMPTY_BIOME.getBCLBiomeKey(), EMPTY_BIOME);
return Holder.direct(EMPTY_BIOME);
}
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.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import org.spongepowered.asm.mixin.Final;
@ -26,11 +25,7 @@ public abstract class ModelBakeryMixin {
@Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_findEmissiveModels(
ResourceManager resourceManager,
BlockColors blockColors,
ProfilerFiller profiler,
int mipmap,
CallbackInfo info
BlockColors blockColors, ProfilerFiller profilerFiller, Map map, Map map2, CallbackInfo ci
) {
//CustomModelBakery.setModelsLoaded(false);
if (ModIntegrationAPI.hasCanvas()) {

View file

@ -1,25 +1,18 @@
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.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
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)
public class ModelManagerMixin {
@Inject(method = "prepare", at = @At("HEAD"))
private void bclib_loadCustomModels(
ResourceManager resourceManager,
ProfilerFiller profilerFiller,
CallbackInfoReturnable<ModelBakery> info
) {
BCLibClient.modelBakery.loadCustomModels(resourceManager);
}
//TODO: 1.19.3 Disabled for now
// @Inject(method = "prepare", at = @At("HEAD"))
// private void bclib_loadCustomModels(
// ResourceManager resourceManager,
// ProfilerFiller profilerFiller,
// CallbackInfoReturnable<ModelBakery> info
// ) {
// BCLibClient.modelBakery.loadCustomModels(resourceManager);
// }
}

View file

@ -1,9 +1,6 @@
package org.betterx.bclib.mixin.common;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import com.mojang.serialization.Lifecycle;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.WritableRegistry;
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!
@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) {
BCLBiomeRegistry.BUILTIN_BCL_BIOMES = internalRegister(
BCLBiomeRegistry.BCL_BIOMES_REGISTRY,
(MappedRegistry) BCLBiomeRegistry.BUILTIN_BCL_BIOMES,
BCLBiomeRegistry::bootstrap,
Lifecycle.stable()
);
//TODO: 1.19.3 reenable
// BCLBiomeRegistry.BUILTIN_BCL_BIOMES = internalRegister(
// BCLBiomeRegistry.BCL_BIOMES_REGISTRY,
// (MappedRegistry) BCLBiomeRegistry.BUILTIN_BCL_BIOMES,
// BCLBiomeRegistry::bootstrap,
// Lifecycle.stable()
// );
}
}

View file

@ -1,16 +1,14 @@
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.Environment;
@Environment(EnvType.CLIENT)
public class PresetsRegistryClient {
public static void onLoad() {
WorldPresetsClient.registerCustomizeUI(PresetsRegistry.BCL_WORLD, (createWorldScreen, worldCreationContext) -> {
return new WorldSetupScreen(createWorldScreen, worldCreationContext);
});
//TODO:1.19.3 Disabled for now
// 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.resources.ResourceKey;
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.presets.WorldPreset;
import net.minecraft.world.level.storage.LevelStorageSource;
@ -34,7 +34,7 @@ public class CreateWorldScreenMixin {
@Inject(method = "<init>", at = @At("TAIL"))
private void wt_init(
Screen screen,
DataPackConfig dataPackConfig,
WorldDataConfiguration worldDataConfiguration,
WorldGenSettingsComponent worldGenSettingsComponent,
CallbackInfo ci
) {

View file

@ -1,13 +1,9 @@
package org.betterx.worlds.together.mixin.common;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer;
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.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
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)
public class MinecraftServerMixin {
@Shadow
@Final
private RegistryAccess.Frozen registryHolder;
@Shadow
@Final
protected WorldData worldData;
// @Shadow
// @Final
// private RegistryAccess.Frozen registryHolder;
// @Shadow
// @Final
// protected WorldData worldData;
@Inject(method = "createLevels", at = @At(value = "HEAD"))
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
//either when a new Datapack was added to a world on the create-screen
//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) {
WorldBootstrap.InGUI.registryReady(frozen);
return frozen;

View file

@ -1,13 +1,9 @@
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.Registry;
import net.minecraft.world.level.biome.Biome;
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.presets.WorldPreset;
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.Mixin;
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)
public abstract class WorldPresetsBootstrapMixin {
@ -48,26 +42,27 @@ public abstract class WorldPresetsBootstrapMixin {
//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;"))
private LevelStem bcl_getOverworldStem(LevelStem overworldStem) {
WorldGenUtil.Context netherContext = new WorldGenUtil.Context(
this.biomes,
this.netherDimensionType,
this.structureSets,
this.noises,
this.netherNoiseSettings
);
WorldGenUtil.Context endContext = new WorldGenUtil.Context(
this.biomes,
this.endDimensionType,
this.structureSets,
this.noises,
this.endNoiseSettings
);
WorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext);
return overworldStem;
}
//TODO: 1.19.3
// @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;"))
// private LevelStem bcl_getOverworldStem(LevelStem overworldStem) {
// WorldGenUtil.Context netherContext = new WorldGenUtil.Context(
// this.biomes,
// this.netherDimensionType,
// this.structureSets,
// this.noises,
// this.netherNoiseSettings
// );
// WorldGenUtil.Context endContext = new WorldGenUtil.Context(
// this.biomes,
// this.endDimensionType,
// this.structureSets,
// this.noises,
// this.endNoiseSettings
// );
//
// WorldPresets.bootstrapPresets(presets, overworldStem, netherContext, endContext);
//
// return overworldStem;
// }
}

View file

@ -90,7 +90,8 @@ public class WorldPresets {
for (Map.Entry<ResourceKey<WorldPreset>, PresetBuilder> e : BUILDERS.entrySet()) {
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;
}