From 7e1ccf548d2a7a7bb4eafac58a521b3663a76fa0 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Sat, 24 Aug 2024 20:29:25 +0200 Subject: [PATCH] Simplify book model --- .../client/FabricClientInitializer.java | 4 +- .../client/NeoForgeClientInitializer.java | 5 +- .../patchouli/client/base/BookModel.java | 72 +++++++++---------- .../mixin/client/AccessorModelBakery.java | 14 ---- .../resources/patchouli_xplat.mixins.json | 1 - 5 files changed, 38 insertions(+), 58 deletions(-) delete mode 100644 Xplat/src/main/java/vazkii/patchouli/mixin/client/AccessorModelBakery.java diff --git a/Fabric/src/main/java/vazkii/patchouli/fabric/client/FabricClientInitializer.java b/Fabric/src/main/java/vazkii/patchouli/fabric/client/FabricClientInitializer.java index 9942c7bf..bc01af95 100644 --- a/Fabric/src/main/java/vazkii/patchouli/fabric/client/FabricClientInitializer.java +++ b/Fabric/src/main/java/vazkii/patchouli/fabric/client/FabricClientInitializer.java @@ -62,9 +62,7 @@ public void onInitializeClient() { PatchouliItems.BOOK_ID.equals(ctx.topLevelId().id()) // checks namespace and path && ctx.topLevelId().getVariant().equals("inventory") && oldModel != null) { - return new BookModel(oldModel, ctx.loader(), (model) -> { - return Minecraft.getInstance().getModelManager().getModel(model); - }); + return new BookModel(oldModel, (model) -> Minecraft.getInstance().getModelManager().getModel(model)); } return oldModel; } diff --git a/NeoForge/src/main/java/vazkii/patchouli/neoforge/client/NeoForgeClientInitializer.java b/NeoForge/src/main/java/vazkii/patchouli/neoforge/client/NeoForgeClientInitializer.java index 9f8a9007..d28f53e0 100644 --- a/NeoForge/src/main/java/vazkii/patchouli/neoforge/client/NeoForgeClientInitializer.java +++ b/NeoForge/src/main/java/vazkii/patchouli/neoforge/client/NeoForgeClientInitializer.java @@ -151,9 +151,6 @@ public static void onInitializeClient(FMLClientSetupEvent evt) { @SubscribeEvent public static void replaceBookModel(ModelEvent.ModifyBakingResult evt) { ModelResourceLocation key = ModelResourceLocation.inventory(PatchouliItems.BOOK_ID); - evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, evt.getModelBakery(), (model) -> { - ModelResourceLocation modelPath = ModelResourceLocation.standalone(model); - return Minecraft.getInstance().getModelManager().getModel(modelPath); - })); + evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, (model) -> Minecraft.getInstance().getModelManager().getModel(ModelResourceLocation.standalone(model)))); } } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java b/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java index 78956972..9b7361eb 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java @@ -2,7 +2,6 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -16,7 +15,6 @@ import vazkii.patchouli.common.book.Book; import vazkii.patchouli.common.item.ItemModBook; -import vazkii.patchouli.mixin.client.AccessorModelBakery; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,42 +27,10 @@ public class BookModel implements BakedModel { private final BakedModel original; private final ItemOverrides itemHandler; - public BookModel(BakedModel original, ModelBakery loader, Function modelGetter) { + public BookModel(BakedModel original, Function modelGetter) { this.original = original; - BlockModel missing = (BlockModel) ((AccessorModelBakery) loader).invokeGetModel(ModelBakery.MISSING_MODEL_LOCATION); - - this.itemHandler = new ItemOverrides(new ModelBaker() { - // soft implement IModelBakerExtension - public Function getModelTextureGetter() { - return null; - } - - // soft implement IModelBakerExtension - public BakedModel bake(ResourceLocation location, ModelState state, Function sprites) { - return null; - } - - // soft implement IModelBakerExtension - public BakedModel bakeUncached(UnbakedModel model, ModelState state, Function sprites) { - return null; - } - - // soft implement IModelBakerExtension - public UnbakedModel getTopLevelModel(ModelResourceLocation location) { - return null; - } - @Override - public UnbakedModel getModel(ResourceLocation resourceLocation) { - return null; - } - - @Nullable - @Override - public BakedModel bake(ResourceLocation resourceLocation, ModelState modelState) { - return null; - } - }, missing, Collections.emptyList()) { + this.itemHandler = new ItemOverrides(DummyModelBaker.INSTANCE, null, Collections.emptyList()) { @Override public BakedModel resolve(@NotNull BakedModel original, @NotNull ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int seed) { @@ -119,4 +85,38 @@ public TextureAtlasSprite getParticleIcon() { public ItemTransforms getTransforms() { return original.getTransforms(); } + + private static class DummyModelBaker implements ModelBaker { + static ModelBaker INSTANCE = new DummyModelBaker(); + // soft implement IModelBakerExtension + public Function getModelTextureGetter() { + return null; + } + + // soft implement IModelBakerExtension + public BakedModel bake(ResourceLocation location, ModelState state, Function sprites) { + return null; + } + + // soft implement IModelBakerExtension + public BakedModel bakeUncached(UnbakedModel model, ModelState state, Function sprites) { + return null; + } + + // soft implement IModelBakerExtension + public UnbakedModel getTopLevelModel(ModelResourceLocation location) { + return null; + } + + @Override + public UnbakedModel getModel(ResourceLocation resourceLocation) { + return null; + } + + @Nullable + @Override + public BakedModel bake(ResourceLocation resourceLocation, ModelState modelState) { + return null; + } + } } diff --git a/Xplat/src/main/java/vazkii/patchouli/mixin/client/AccessorModelBakery.java b/Xplat/src/main/java/vazkii/patchouli/mixin/client/AccessorModelBakery.java deleted file mode 100644 index 6a1eb110..00000000 --- a/Xplat/src/main/java/vazkii/patchouli/mixin/client/AccessorModelBakery.java +++ /dev/null @@ -1,14 +0,0 @@ -package vazkii.patchouli.mixin.client; - -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.UnbakedModel; -import net.minecraft.resources.ResourceLocation; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(ModelBakery.class) -public interface AccessorModelBakery { - @Invoker("getModel") - UnbakedModel invokeGetModel(ResourceLocation location); -} diff --git a/Xplat/src/main/resources/patchouli_xplat.mixins.json b/Xplat/src/main/resources/patchouli_xplat.mixins.json index 0ebe4417..869b4465 100644 --- a/Xplat/src/main/resources/patchouli_xplat.mixins.json +++ b/Xplat/src/main/resources/patchouli_xplat.mixins.json @@ -10,7 +10,6 @@ "client": [ "client.AccessorClientAdvancements", "client.AccessorKeyMapping", - "client.AccessorModelBakery", "client.AccessorMultiBufferSource", "client.AccessorScreen", "client.MixinClientAdvancements",