From d08c43ffbaf6a7587a233266aced6bcfd2822136 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 20 Jun 2018 23:54:41 +0200 Subject: [PATCH] Fixed skulls not always rendering with magic effects --- .../mixin/MixinGlStateManager.java | 25 +++++++++++++++++++ .../render/LevitatingItemRenderer.java | 2 ++ .../render/PonySkullRenderer.java | 4 +++ .../render/player/RenderPonyPlayer.java | 8 +----- src/main/resources/minelp.mixin.json | 3 ++- 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/minelittlepony/mixin/MixinGlStateManager.java diff --git a/src/main/java/com/minelittlepony/mixin/MixinGlStateManager.java b/src/main/java/com/minelittlepony/mixin/MixinGlStateManager.java new file mode 100644 index 00000000..aaec35d9 --- /dev/null +++ b/src/main/java/com/minelittlepony/mixin/MixinGlStateManager.java @@ -0,0 +1,25 @@ +package com.minelittlepony.mixin; + +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.callback.CallbackInfo; + +import com.minelittlepony.render.PonySkullRenderer; + +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.GlStateManager.DestFactor; +import net.minecraft.client.renderer.GlStateManager.SourceFactor; + +@Mixin(GlStateManager.class) +public abstract class MixinGlStateManager { + + @Inject(method = "enableBlendProfile(Lnet/minecraft/client/renderer/GlStateManager$Profile;)V", at = @At("HEAD"), cancellable = true) + private static void enableBlendProfile(GlStateManager.Profile profile, CallbackInfo info) { + if (profile == GlStateManager.Profile.PLAYER_SKIN && PonySkullRenderer.ponyInstance.usesTransparency()) { + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO); + info.cancel(); + } + } +} diff --git a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java index 05892f23..5613dd4c 100644 --- a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java +++ b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java @@ -35,6 +35,7 @@ public class LevitatingItemRenderer { RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); ((IRenderItem) renderItem).useTransparency(true); + PonySkullRenderer.ponyInstance.useTransparency(true); scale(1.1, 1.1, 1.1); @@ -44,6 +45,7 @@ public class LevitatingItemRenderer { renderItem.renderItem(drop, entity, transform, hand == EnumHandSide.LEFT); ((IRenderItem) renderItem).useTransparency(false); + PonySkullRenderer.ponyInstance.useTransparency(false); unsetColor(); enableLighting(); popMatrix(); diff --git a/src/main/java/com/minelittlepony/render/PonySkullRenderer.java b/src/main/java/com/minelittlepony/render/PonySkullRenderer.java index e558abcc..3f5a8a26 100644 --- a/src/main/java/com/minelittlepony/render/PonySkullRenderer.java +++ b/src/main/java/com/minelittlepony/render/PonySkullRenderer.java @@ -139,6 +139,10 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende transparency = use; } + public boolean usesTransparency() { + return transparency; + } + /** * A skull, just a skull. * diff --git a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java index ef6ffad6..7f4b03ac 100644 --- a/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java +++ b/src/main/java/com/minelittlepony/render/player/RenderPonyPlayer.java @@ -18,8 +18,6 @@ import com.voxelmodpack.hdskins.HDSkinManager; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.GlStateManager.DestFactor; -import net.minecraft.client.renderer.GlStateManager.SourceFactor; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.entity.player.EntityPlayer; @@ -39,11 +37,7 @@ public class RenderPonyPlayer extends RenderPonyBase { @Override public void preRender(boolean transparency) { - if (transparency) { - GlStateManager.tryBlendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO); - } else { - GlStateManager.enableBlendProfile(GlStateManager.Profile.PLAYER_SKIN); - } + GlStateManager.enableBlendProfile(GlStateManager.Profile.PLAYER_SKIN); } @Override diff --git a/src/main/resources/minelp.mixin.json b/src/main/resources/minelp.mixin.json index 50d02026..a7c3f82d 100644 --- a/src/main/resources/minelp.mixin.json +++ b/src/main/resources/minelp.mixin.json @@ -9,6 +9,7 @@ "MixinNetworkPlayerInfo", "MixinRenderItem", "MixinItemRenderer", - "MixinRenderManager" + "MixinRenderManager", + "MixinGlStateManager" ] }