From dca3cad2cd239d6e8f00536a3e7e5fe6f3715535 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 18 Aug 2018 14:15:05 +0200 Subject: [PATCH] Fixed magic rendering of items that have permanent enchantment effects AND items with a dark tint --- .../minelittlepony/mixin/MixinRenderItem.java | 17 +++++++++++++++++ .../render/LevitatingItemRenderer.java | 19 ++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/minelittlepony/mixin/MixinRenderItem.java b/src/main/java/com/minelittlepony/mixin/MixinRenderItem.java index b1989d98..99d1590f 100644 --- a/src/main/java/com/minelittlepony/mixin/MixinRenderItem.java +++ b/src/main/java/com/minelittlepony/mixin/MixinRenderItem.java @@ -1,6 +1,7 @@ package com.minelittlepony.mixin; import com.minelittlepony.ducks.IRenderItem; + import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager.DestFactor; import net.minecraft.client.renderer.GlStateManager.SourceFactor; @@ -12,6 +13,7 @@ import net.minecraft.item.ItemStack; 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.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(RenderItem.class) @@ -30,4 +32,19 @@ public abstract class MixinRenderItem implements IResourceManagerReloadListener, GlStateManager.tryBlendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO); } } + + @ModifyArg(method = "renderQuads(Lnet/minecraft/client/renderer/BufferBuilder;ILjava/util/List;Lnet/minecraft/item/Itemstack;)V", + at = @At(value = "INVOKE", + target = "renderQuad(Lnet/minecraft/client/renderer/BufferBuilder;Lnet/minecraft/client/renderer/block/model/BakedQuad;I)V"), + index = 2) + private int modifyItemRenderTint(int color) { + return transparency ? -1 : color; + } + + @Inject(method = "renderEffect(Lnet/minecraft/client/renderer/block/model/IBakedQuad;)V", at = @At("HEAD"), cancellable = true) + private void renderEffect(IBakedModel model, CallbackInfo info) { + if (transparency) { + info.cancel(); + } + } } diff --git a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java index 977b8da8..d3982208 100644 --- a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java +++ b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java @@ -25,10 +25,6 @@ public class LevitatingItemRenderer { * Renders a magical overlay over an item in third person. */ public void renderItemGlow(EntityLivingBase entity, ItemStack drop, TransformType transform, EnumHandSide hand, int glowColor) { - - // enchantments mess up the rendering - drop = stackWithoutEnchantment(drop); - pushMatrix(); disableLighting(); setColor(glowColor); @@ -65,7 +61,6 @@ public class LevitatingItemRenderer { * Renders an item in first person optionally with a magical overlay. */ public void renderItemInFirstPerson(ItemRenderer renderer, AbstractClientPlayer entity, ItemStack stack, TransformType transform, boolean left) { - Pony pony = MineLittlePony.getInstance().getManager().getPony(entity); pushMatrix(); @@ -79,7 +74,6 @@ public class LevitatingItemRenderer { renderer.renderItemSide(entity, stack, transform, left); if (doMagic) { - disableLighting(); IRenderItem renderItem = (IRenderItem)Minecraft.getMinecraft().getRenderItem(); @@ -90,9 +84,9 @@ public class LevitatingItemRenderer { scale(1.1, 1.1, 1.1); - translate(0, 0.01F, 0.01F); + translate(-0.015F, 0.01F, 0.01F); renderer.renderItemSide(entity, stack, transform, left); - translate(0.01F, -0.01F, -0.02F); + translate(0.03F, -0.01F, -0.02F); renderer.renderItemSide(entity, stack, transform, left); renderItem.useTransparency(false); @@ -135,13 +129,4 @@ public class LevitatingItemRenderer { } } } - - private ItemStack stackWithoutEnchantment(ItemStack original) { - if (original.isItemEnchanted()) { - original = original.copy(); - original.getTagCompound().removeTag("ench"); - } - - return original; - } }