From 7df0f117ffacf5c751db2e161a859ab258b15e38 Mon Sep 17 00:00:00 2001 From: Gu_ZT Date: Wed, 18 Oct 2023 01:18:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86ItemModelShaperMixin=E6=94=BE=E7=BD=AE?= =?UTF-8?q?=E5=9C=A8fabric=E7=AB=AF=EF=BC=8C=E5=AF=B9forge=E7=AB=AF?= =?UTF-8?q?=E5=8F=A6=E4=BD=9C=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chinesefestivals-common.mixins.json | 1 - .../fabric}/mixins/ItemModelShaperMixin.java | 2 +- .../resources/chinesefestivals.mixins.json | 3 +- forge/build.gradle | 2 +- .../mixins/ForgeItemModelShaperMixin.java | 46 +++++++++++++++++++ .../resources/chinesefestivals.mixins.json | 13 ++++++ 6 files changed, 63 insertions(+), 4 deletions(-) rename {common/src/main/java/dev/dubhe/chinesefestivals => fabric/src/main/java/dev/dubhe/chinesefestivals/fabric}/mixins/ItemModelShaperMixin.java (96%) create mode 100644 forge/src/main/java/dev/dubhe/chinesefestivals/forge/mixins/ForgeItemModelShaperMixin.java create mode 100644 forge/src/main/resources/chinesefestivals.mixins.json diff --git a/common/src/main/resources/chinesefestivals-common.mixins.json b/common/src/main/resources/chinesefestivals-common.mixins.json index b9b1b90..2a91df8 100644 --- a/common/src/main/resources/chinesefestivals-common.mixins.json +++ b/common/src/main/resources/chinesefestivals-common.mixins.json @@ -6,7 +6,6 @@ "mixins": [], "client": [ "BlockModelShaperMixin", - "ItemModelShaperMixin", "LanguageMixin", "LevelRendererMixin" ], diff --git a/common/src/main/java/dev/dubhe/chinesefestivals/mixins/ItemModelShaperMixin.java b/fabric/src/main/java/dev/dubhe/chinesefestivals/fabric/mixins/ItemModelShaperMixin.java similarity index 96% rename from common/src/main/java/dev/dubhe/chinesefestivals/mixins/ItemModelShaperMixin.java rename to fabric/src/main/java/dev/dubhe/chinesefestivals/fabric/mixins/ItemModelShaperMixin.java index 085d8c8..edb406c 100644 --- a/common/src/main/java/dev/dubhe/chinesefestivals/mixins/ItemModelShaperMixin.java +++ b/fabric/src/main/java/dev/dubhe/chinesefestivals/fabric/mixins/ItemModelShaperMixin.java @@ -1,4 +1,4 @@ -package dev.dubhe.chinesefestivals.mixins; +package dev.dubhe.chinesefestivals.fabric.mixins; import dev.dubhe.chinesefestivals.ChineseFestivals; import dev.dubhe.chinesefestivals.festivals.Festivals; diff --git a/fabric/src/main/resources/chinesefestivals.mixins.json b/fabric/src/main/resources/chinesefestivals.mixins.json index 24f52fb..cfdd555 100644 --- a/fabric/src/main/resources/chinesefestivals.mixins.json +++ b/fabric/src/main/resources/chinesefestivals.mixins.json @@ -6,7 +6,8 @@ "mixins": [ ], "client": [ - "CommandsMixin" + "CommandsMixin", + "ItemModelShaperMixin" ], "injectors": { "defaultRequire": 1 diff --git a/forge/build.gradle b/forge/build.gradle index 751f650..ec946ef 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -9,7 +9,7 @@ architectury { loom { forge { - mixinConfig "chinesefestivals-common.mixins.json" + mixinConfig "chinesefestivals.mixins.json,chinesefestivals-common.mixins.json" } } diff --git a/forge/src/main/java/dev/dubhe/chinesefestivals/forge/mixins/ForgeItemModelShaperMixin.java b/forge/src/main/java/dev/dubhe/chinesefestivals/forge/mixins/ForgeItemModelShaperMixin.java new file mode 100644 index 0000000..a6b95fc --- /dev/null +++ b/forge/src/main/java/dev/dubhe/chinesefestivals/forge/mixins/ForgeItemModelShaperMixin.java @@ -0,0 +1,46 @@ +package dev.dubhe.chinesefestivals.forge.mixins; + +import dev.dubhe.chinesefestivals.ChineseFestivals; +import dev.dubhe.chinesefestivals.festivals.Festivals; +import dev.dubhe.chinesefestivals.festivals.IFestival; +import net.minecraft.client.renderer.ItemModelShaper; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.ModelManager; +import net.minecraft.core.Holder; +import net.minecraft.world.item.Item; +import net.minecraftforge.client.model.ForgeItemModelShaper; +import net.minecraftforge.registries.ForgeRegistries; +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.CallbackInfoReturnable; + +import java.util.Map; +import java.util.function.Supplier; + +@Mixin(ForgeItemModelShaper.class) +public abstract class ForgeItemModelShaperMixin extends ItemModelShaper { + @Shadow(remap = false) + @Final + private Map, BakedModel> models; + + public ForgeItemModelShaperMixin(ModelManager arg) { + super(arg); + } + + @Inject(method = "getItemModel", remap = false, at = @At("HEAD"), cancellable = true) + private void getItemModel(Item item, CallbackInfoReturnable cir) { + ChineseFestivals.LOGGER.info("test"); + for (IFestival festival : Festivals.FESTIVALS) { + if (festival.isNow()) { + Supplier item1 = festival.getItemReplace().getOrDefault(item, null); + if (item1 != null) { + cir.setReturnValue(this.models.get(ForgeRegistries.ITEMS.getDelegateOrThrow(item1.get()))); + return; + } + } + } + } +} diff --git a/forge/src/main/resources/chinesefestivals.mixins.json b/forge/src/main/resources/chinesefestivals.mixins.json new file mode 100644 index 0000000..88bb41a --- /dev/null +++ b/forge/src/main/resources/chinesefestivals.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "dev.dubhe.chinesefestivals.forge.mixins", + "compatibilityLevel": "JAVA_17", + "mixins": [], + "client": [ + "ForgeItemModelShaperMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}