From b6b428995db8ac394a05c23097d36db4ddda6a09 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Wed, 4 Dec 2024 01:13:42 +0100 Subject: [PATCH] Update petrified oak slab fix - finished port --- .../minecraft/item/MixinItemRenderer.java | 32 +++++++++---------- src/main/resources/viafabricplus.mixins.json | 4 +-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItemRenderer.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItemRenderer.java index d793c548..16adb267 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItemRenderer.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinItemRenderer.java @@ -20,31 +20,29 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; import de.florianmichael.viafabricplus.settings.impl.VisualSettings; -import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.BakedModelManager; -import net.minecraft.entity.LivingEntity; +import net.minecraft.client.item.ItemModelManager; +import net.minecraft.component.ComponentType; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; +import net.minecraft.util.Identifier; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(ItemRenderer.class) +@Mixin(ItemModelManager.class) public abstract class MixinItemRenderer { - @Shadow - @Final - private BakedModelManager bakedModelManager; + @Unique + private static final Identifier viaFabricPlus$missingIdentifier = Identifier.of(String.valueOf(System.currentTimeMillis())); - @Inject(method = "getModel(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)Lnet/minecraft/client/render/model/BakedModel;", at = @At("HEAD"), cancellable = true) - private void removeModel(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable cir) { - if (VisualSettings.global().replacePetrifiedOakSlab.isEnabled() && world != null /* world is null in gui rendering */ && stack.isOf(Items.PETRIFIED_OAK_SLAB)) { - cir.setReturnValue(this.bakedModelManager.getMissingModel()); + @Redirect(method = "update(Lnet/minecraft/client/render/item/ItemRenderState;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;get(Lnet/minecraft/component/ComponentType;)Ljava/lang/Object;")) + public Object removeModel(ItemStack instance, ComponentType componentType) { + if (VisualSettings.global().replacePetrifiedOakSlab.isEnabled() && instance.isOf(Items.PETRIFIED_OAK_SLAB)) { + return viaFabricPlus$missingIdentifier; + } else { + return instance.get(componentType); } } diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index bf412a6b..54b66d02 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -129,6 +129,7 @@ "fixes.minecraft.item.MixinBrushItem", "fixes.minecraft.item.MixinBucketItem", "fixes.minecraft.item.MixinDrawContext", + "fixes.minecraft.item.MixinEnderEyeItem", "fixes.minecraft.item.MixinEnderPearlItem", "fixes.minecraft.item.MixinEquippableComponent", "fixes.minecraft.item.MixinFireChargeItem", @@ -216,8 +217,7 @@ "fixes.viaversion.MixinWorldPacketRewriter1_19", "viabedrock.MixinJoinPackets", "vialegacy.MixinExtensionProtocolMetadataStorage", - "vialegacy.MixinViaLegacyConfig", - "fixes.minecraft.item.MixinEnderEyeItem" + "vialegacy.MixinViaLegacyConfig" ], "injectors": { "defaultRequire": 1