From df6ee38f9cae6f426e70f3396d82e576ced7bab8 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 12 Dec 2024 19:24:32 +0100 Subject: [PATCH] 1.21.3 -> 1.21.4 --- gradle.properties | 12 ++++---- .../mson/api/export/ModelSerializer.java | 3 +- .../api/export/VanillaModelSerializer.java | 9 ++---- .../minelittlepony/mson/impl/MsonImpl.java | 14 ++++----- .../impl/mixin/MixinBakedModelManager.java | 20 +++++++++++++ .../MixinBlockEntityRenderDispatcher.java | 26 +++++++++------- .../impl/mixin/MixinEntityModelLoader.java | 30 ------------------- .../mixin/MixinEntityRenderDispatcher.java | 18 ++++++----- .../mson/impl/mixin/ModelListAccessor.java | 16 ++++++++++ src/main/resources/mson.mixin.json | 5 ++-- .../models/entity/mson/enderman.json | 4 +-- 11 files changed, 85 insertions(+), 72 deletions(-) create mode 100644 src/main/java/com/minelittlepony/mson/impl/mixin/MixinBakedModelManager.java delete mode 100644 src/main/java/com/minelittlepony/mson/impl/mixin/MixinEntityModelLoader.java create mode 100644 src/main/java/com/minelittlepony/mson/impl/mixin/ModelListAccessor.java diff --git a/gradle.properties b/gradle.properties index c0282c8..1a74ae6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.daemon=false # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.21.3 - yarn_mappings=1.21.3+build.2 - loader_version=0.16.7 - fabric_version=0.106.1+1.21.3 + minecraft_version=1.21.4 + yarn_mappings=1.21.4+build.2 + loader_version=0.16.9 + fabric_version=0.111.0+1.21.4 # Mod Properties group=com.minelittlepony @@ -15,9 +15,9 @@ org.gradle.daemon=false description=Json-based entity models. Mson. # Publishing - minecraft_version_range=>=1.21.2 + minecraft_version_range=>=1.21.4 modrinth_loader_type=fabric modrinth_project_id=POWgsZW2 # Dependencies - modmenu_version=12.0.0-beta.1 + modmenu_version=13.0.0-beta.1 diff --git a/src/main/java/com/minelittlepony/mson/api/export/ModelSerializer.java b/src/main/java/com/minelittlepony/mson/api/export/ModelSerializer.java index b9c01e3..d6fc608 100644 --- a/src/main/java/com/minelittlepony/mson/api/export/ModelSerializer.java +++ b/src/main/java/com/minelittlepony/mson/api/export/ModelSerializer.java @@ -3,6 +3,7 @@ import org.jetbrains.annotations.Nullable; import com.google.gson.JsonElement; +import com.google.gson.Strictness; import com.google.gson.internal.Streams; import com.google.gson.stream.JsonWriter; @@ -47,7 +48,7 @@ private static class JsWriter extends JsonWriter { public JsWriter(Writer out) { super(out); - setLenient(true); + setStrictness(Strictness.LENIENT); setIndent(currentIndent); } diff --git a/src/main/java/com/minelittlepony/mson/api/export/VanillaModelSerializer.java b/src/main/java/com/minelittlepony/mson/api/export/VanillaModelSerializer.java index f24f9b6..0e135f7 100644 --- a/src/main/java/com/minelittlepony/mson/api/export/VanillaModelSerializer.java +++ b/src/main/java/com/minelittlepony/mson/api/export/VanillaModelSerializer.java @@ -2,18 +2,17 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.model.TexturedModelData; -import net.minecraft.client.render.entity.model.EntityModelLayer; import org.jetbrains.annotations.Nullable; import com.google.gson.JsonElement; import com.minelittlepony.mson.api.parser.ModelLoader; +import com.minelittlepony.mson.impl.mixin.ModelListAccessor; import com.minelittlepony.mson.impl.model.bbmodel.BBModelFormat; import com.minelittlepony.mson.impl.model.json.MsonModelFormat; import java.io.IOException; import java.nio.file.Path; -import java.util.Map; public class VanillaModelSerializer extends ModelSerializer { @@ -29,7 +28,7 @@ public VanillaModelSerializer() { } public void exportAll(Path root) { - ((ModelList)MinecraftClient.getInstance().getEntityModelLoader()).getModelParts().forEach((id, model) -> { + ((ModelListAccessor)MinecraftClient.getInstance().getLoadedEntityModels()).getModelParts().forEach((id, model) -> { try { Path path = root.resolve(id.id().getNamespace()).resolve(id.id().getPath() + ".json"); writeToFile(path, model); @@ -59,10 +58,6 @@ public JsonElement writeToJsonElement(TexturedModelData content) { return JsonBuffer.INSTANCE.write(content); } - public interface ModelList { - Map getModelParts(); - } - @Override public void close() throws Exception { } diff --git a/src/main/java/com/minelittlepony/mson/impl/MsonImpl.java b/src/main/java/com/minelittlepony/mson/impl/MsonImpl.java index 1d6040d..91d7f08 100644 --- a/src/main/java/com/minelittlepony/mson/impl/MsonImpl.java +++ b/src/main/java/com/minelittlepony/mson/impl/MsonImpl.java @@ -4,8 +4,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.model.Model; import net.minecraft.client.model.ModelPart; -import net.minecraft.client.model.TexturedModelData; -import net.minecraft.client.render.entity.model.EntityModelLayer; import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; @@ -24,6 +22,7 @@ import com.minelittlepony.mson.api.parser.FileContent; import com.minelittlepony.mson.api.Mson; import com.minelittlepony.mson.impl.key.AbstractModelKeyImpl; +import com.minelittlepony.mson.impl.mixin.ModelListAccessor; import com.minelittlepony.mson.impl.model.RootContext; import com.minelittlepony.mson.impl.model.bbmodel.BBModelFormat; import com.minelittlepony.mson.impl.model.json.MsonModelFormat; @@ -70,10 +69,10 @@ public Stream> getHandlers(String extension) { return handlersByExtension.getOrDefault(extension, Set.of()).stream(); } - public void registerVanillaModels(Map modelParts) { + public void registerVanillaModels() { synchronized (vanillaModels) { vanillaModels.clear(); - modelParts.forEach((layer, vanilla) -> { + ((ModelListAccessor)MinecraftClient.getInstance().getLoadedEntityModels()).getModelParts().forEach((layer, vanilla) -> { Identifier id = layer.id().withPath(p -> String.format("mson/%s", p)); ((MsonImpl.KeyHolder)vanilla).setKey(registeredModels.computeIfAbsent(id, VanillaKey::new)); vanillaModels.add(id); @@ -85,13 +84,14 @@ public void registerVanillaModels(Map model } } - private CompletableFuture requireVanillaModels(ResourceManager sender, Executor prepareExecutor) { + private CompletableFuture requireVanillaModels(Synchronizer sync, ResourceManager sender, Executor prepareExecutor, Executor applyExecutor) { boolean hasVanillaModels; synchronized (vanillaModels) { hasVanillaModels = !vanillaModels.isEmpty(); } if (!hasVanillaModels) { - return CompletableFuture.runAsync(() -> MinecraftClient.getInstance().getEntityModelLoader().reload(sender), prepareExecutor); + LOGGER.info("Vanilla models are not ready, preparing them ourselves..."); + return CompletableFuture.runAsync(() -> MinecraftClient.getInstance().getBakedModelManager().reload(sync, sender, prepareExecutor, applyExecutor), prepareExecutor); } return CompletableFuture.completedFuture(null); } @@ -100,7 +100,7 @@ private CompletableFuture requireVanillaModels(ResourceManager sender, Exe public CompletableFuture reload(Synchronizer sync, ResourceManager sender, Executor prepareExecutor, Executor applyExecutor) { ModelFoundry loadingFoundry = new ModelFoundry(this).setWorker(LoadWorker.async(prepareExecutor)); - return requireVanillaModels(sender, prepareExecutor) + return requireVanillaModels(sync, sender, prepareExecutor, applyExecutor) .thenComposeAsync(v -> loadingFoundry.load(), prepareExecutor) .thenCompose(sync::whenPrepared) .thenRunAsync(() -> { diff --git a/src/main/java/com/minelittlepony/mson/impl/mixin/MixinBakedModelManager.java b/src/main/java/com/minelittlepony/mson/impl/mixin/MixinBakedModelManager.java new file mode 100644 index 0000000..c780b19 --- /dev/null +++ b/src/main/java/com/minelittlepony/mson/impl/mixin/MixinBakedModelManager.java @@ -0,0 +1,20 @@ +package com.minelittlepony.mson.impl.mixin; + +import net.minecraft.client.render.model.BakedModelManager; +import net.minecraft.util.profiler.Profiler; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Coerce; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.minelittlepony.mson.impl.MsonImpl; + +@Mixin(BakedModelManager.class) +abstract class MixinBakedModelManager { + @Inject(method = "upload(Lnet/minecraft/client/render/model/BakedModelManager$BakingResult;Lnet/minecraft/util/profiler/Profiler;)V", at = @At("TAIL")) + private void upload(@Coerce Object bakingResult, Profiler profiler, CallbackInfo info) { + MsonImpl.INSTANCE.registerVanillaModels(); + } +} diff --git a/src/main/java/com/minelittlepony/mson/impl/mixin/MixinBlockEntityRenderDispatcher.java b/src/main/java/com/minelittlepony/mson/impl/mixin/MixinBlockEntityRenderDispatcher.java index ca1840c..73db785 100644 --- a/src/main/java/com/minelittlepony/mson/impl/mixin/MixinBlockEntityRenderDispatcher.java +++ b/src/main/java/com/minelittlepony/mson/impl/mixin/MixinBlockEntityRenderDispatcher.java @@ -3,12 +3,13 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.item.ItemModelManager; import net.minecraft.client.render.block.BlockRenderManager; import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; import net.minecraft.client.render.block.entity.BlockEntityRenderer; import net.minecraft.client.render.block.entity.BlockEntityRendererFactory; import net.minecraft.client.render.entity.EntityRenderDispatcher; -import net.minecraft.client.render.entity.model.EntityModelLoader; +import net.minecraft.client.render.entity.model.LoadedEntityModels; import net.minecraft.client.render.item.ItemRenderer; import org.spongepowered.asm.mixin.Final; @@ -34,13 +35,15 @@ abstract class MixinBlockEntityRenderDispatcher implements EntityRendererRegistr @Shadow private @Final TextRenderer textRenderer; @Shadow - private @Final EntityModelLoader entityModelLoader; + private @Final Supplier entityModelsGetter; @Shadow - private @Final Supplier blockRenderManager; + private @Final BlockRenderManager blockRenderManager; @Shadow - private @Final Supplier itemRenderer; + private @Final ItemModelManager itemModelManager; @Shadow - private @Final Supplier entityRenderDispatcher; + private @Final ItemRenderer itemRenderer; + @Shadow + private @Final EntityRenderDispatcher entityRenderDispatcher; @Inject(method = "reload(Lnet/minecraft/resource/ResourceManager;)V", at = @At("RETURN")) private void onInit(CallbackInfo info) { @@ -50,11 +53,14 @@ private void onInit(CallbackInfo info) { @Override public

> void registerBlockRenderer(BlockEntityType

type, Function constructor) { try { - BlockEntityRendererFactory.Context context = new BlockEntityRendererFactory.Context((BlockEntityRenderDispatcher)(Object)this, - blockRenderManager.get(), - itemRenderer.get(), - entityRenderDispatcher.get(), - entityModelLoader, textRenderer); + BlockEntityRendererFactory.Context context = new BlockEntityRendererFactory.Context( + (BlockEntityRenderDispatcher)(Object)this, + blockRenderManager, + itemModelManager, + itemRenderer, + entityRenderDispatcher, + entityModelsGetter.get(), + textRenderer); if (renderers instanceof ImmutableMap) { renderers = new HashMap<>(renderers); } diff --git a/src/main/java/com/minelittlepony/mson/impl/mixin/MixinEntityModelLoader.java b/src/main/java/com/minelittlepony/mson/impl/mixin/MixinEntityModelLoader.java deleted file mode 100644 index 0b32e6a..0000000 --- a/src/main/java/com/minelittlepony/mson/impl/mixin/MixinEntityModelLoader.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.minelittlepony.mson.impl.mixin; - -import net.minecraft.client.model.TexturedModelData; -import net.minecraft.client.render.entity.model.EntityModelLayer; -import net.minecraft.client.render.entity.model.EntityModelLoader; -import net.minecraft.resource.ResourceManager; -import net.minecraft.resource.SynchronousResourceReloader; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import com.minelittlepony.mson.api.export.VanillaModelSerializer; -import com.minelittlepony.mson.impl.MsonImpl; - -import java.util.Map; - -@Mixin(EntityModelLoader.class) -abstract class MixinEntityModelLoader implements SynchronousResourceReloader, VanillaModelSerializer.ModelList { - @Override - @Accessor("modelParts") - public abstract Map getModelParts(); - - @Inject(method = "reload(Lnet/minecraft/resource/ResourceManager;)V", at = @At("RETURN")) - public void onReload(ResourceManager resourceManager, CallbackInfo info) { - MsonImpl.INSTANCE.registerVanillaModels(getModelParts()); - } -} diff --git a/src/main/java/com/minelittlepony/mson/impl/mixin/MixinEntityRenderDispatcher.java b/src/main/java/com/minelittlepony/mson/impl/mixin/MixinEntityRenderDispatcher.java index e456071..1f9e336 100644 --- a/src/main/java/com/minelittlepony/mson/impl/mixin/MixinEntityRenderDispatcher.java +++ b/src/main/java/com/minelittlepony/mson/impl/mixin/MixinEntityRenderDispatcher.java @@ -7,7 +7,8 @@ import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.PlayerEntityRenderer; import net.minecraft.client.render.entity.EntityRendererFactory.Context; -import net.minecraft.client.render.entity.model.EntityModelLoader; +import net.minecraft.client.render.entity.equipment.EquipmentModelLoader; +import net.minecraft.client.render.entity.model.LoadedEntityModels; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.resource.ResourceManager; @@ -29,6 +30,7 @@ import java.util.Map; import java.util.function.Function; import java.util.function.Predicate; +import java.util.function.Supplier; @Mixin(EntityRenderDispatcher.class) abstract class MixinEntityRenderDispatcher implements EntityRendererRegistry { @@ -37,7 +39,9 @@ abstract class MixinEntityRenderDispatcher implements EntityRendererRegistry { private Map, Map, EntityRenderer>> customEntityRenderers; private Map, PlayerEntityRenderer>> customModelRenderers; @Shadow - private @Final EntityModelLoader modelLoader; + private @Final Supplier entityModelsGetter; + @Shadow + private @Final EquipmentModelLoader equipmentModelLoader; @Inject(method = "reload(Lnet/minecraft/resource/ResourceManager;)V", at = @At("RETURN")) private void onRegisterRenderers(ResourceManager manager, CallbackInfo info) { @@ -49,14 +53,14 @@ private void onRegisterRenderers(ResourceManager manager, CallbackInfo info) { private EntityRendererFactory.Context createContext() { MinecraftClient mc = MinecraftClient.getInstance(); - EntityRenderDispatcher self = (EntityRenderDispatcher)(Object)this; - return new EntityRendererFactory.Context(self, - mc.getItemRenderer(), + return new EntityRendererFactory.Context( + (EntityRenderDispatcher)(Object)this, + mc.getItemModelManager(), mc.getMapRenderer(), mc.getBlockRenderManager(), mc.getResourceManager(), - modelLoader, - mc.getEquipmentModelLoader(), + entityModelsGetter.get(), + equipmentModelLoader, mc.textRenderer ); } diff --git a/src/main/java/com/minelittlepony/mson/impl/mixin/ModelListAccessor.java b/src/main/java/com/minelittlepony/mson/impl/mixin/ModelListAccessor.java new file mode 100644 index 0000000..b5864cb --- /dev/null +++ b/src/main/java/com/minelittlepony/mson/impl/mixin/ModelListAccessor.java @@ -0,0 +1,16 @@ +package com.minelittlepony.mson.impl.mixin; + +import net.minecraft.client.model.TexturedModelData; +import net.minecraft.client.render.entity.model.EntityModelLayer; +import net.minecraft.client.render.entity.model.LoadedEntityModels; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(LoadedEntityModels.class) +public interface ModelListAccessor { + @Accessor("modelParts") + Map getModelParts(); +} diff --git a/src/main/resources/mson.mixin.json b/src/main/resources/mson.mixin.json index 3a67f62..bc80f30 100644 --- a/src/main/resources/mson.mixin.json +++ b/src/main/resources/mson.mixin.json @@ -5,9 +5,9 @@ "refmap": "mson.mixin.refmap.json", "compatibilityLevel": "JAVA_17", "client": [ + "MixinBakedModelManager", "MixinBlockEntityRenderDispatcher", "MixinDilation", - "MixinEntityModelLoader", "MixinEntityRenderDispatcher", "MixinModel", "MixinModelPart", @@ -17,6 +17,7 @@ "MixinTextureDimensions", "MixinTexturedModelData", "MixinModelPartData", - "MixinModelCuboidData" + "MixinModelCuboidData", + "ModelListAccessor" ] } diff --git a/src/test/resources/assets/minecraft/models/entity/mson/enderman.json b/src/test/resources/assets/minecraft/models/entity/mson/enderman.json index 4e5ec17..ded90f1 100644 --- a/src/test/resources/assets/minecraft/models/entity/mson/enderman.json +++ b/src/test/resources/assets/minecraft/models/entity/mson/enderman.json @@ -2,13 +2,13 @@ "parent": "mson:biped", "data": { "head": { + "pivot": [0, -6, -6], "cubes": [ { "from": [-4, -8, -4], "size": [ 8, 8, 8] } ], "children": { "hat": { "texture": { "u": 0, "v": 16 }, - "pivot": [0, -14, 0], "cubes": [ { "from": [-4, -8, -4], "size": [ 8, 8, 8], "dilate": [-0.5, -0.5, -0.5] } ] @@ -24,7 +24,7 @@ }, "right_arm": { "texture": { "u": 56, "v": 0 }, - "pivot": [-3, -12, 0], + "pivot": [-5, -12, 0], "cubes": [ { "from": [-1, -2, -1], "size": [ 2, 30, 2] } ]