From 1c64e4986268564d52c14b9fce69fa6bd0886fea Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 27 Jun 2019 12:37:08 +0200 Subject: [PATCH] Backport: Fix compatibility with CCL and any other mods that use the old proxy object pattern --- .../com/minelittlepony/ducks/IRenderItem.java | 9 ---- .../mixin/MixinGlStateManager.java | 4 +- .../minelittlepony/mixin/MixinRenderItem.java | 18 ++------ .../render/LevitatingItemRenderer.java | 44 ++++++++++--------- .../render/skull/PonySkullRenderer.java | 17 ++----- .../transform/PostureElytra.java | 1 - 6 files changed, 32 insertions(+), 61 deletions(-) delete mode 100644 src/main/java/com/minelittlepony/ducks/IRenderItem.java diff --git a/src/main/java/com/minelittlepony/ducks/IRenderItem.java b/src/main/java/com/minelittlepony/ducks/IRenderItem.java deleted file mode 100644 index ebd69469..00000000 --- a/src/main/java/com/minelittlepony/ducks/IRenderItem.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.minelittlepony.ducks; - -public interface IRenderItem { - - /** - * Sets whether items should be rendered with transparency support. - */ - void useTransparency(boolean use); -} diff --git a/src/main/java/com/minelittlepony/mixin/MixinGlStateManager.java b/src/main/java/com/minelittlepony/mixin/MixinGlStateManager.java index d0c42fe8..72589b4d 100644 --- a/src/main/java/com/minelittlepony/mixin/MixinGlStateManager.java +++ b/src/main/java/com/minelittlepony/mixin/MixinGlStateManager.java @@ -6,7 +6,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.minelittlepony.render.LevitatingItemRenderer; -import com.minelittlepony.render.skull.PonySkullRenderer; import net.minecraft.client.renderer.GlStateManager; @@ -15,8 +14,7 @@ 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()) { - LevitatingItemRenderer.enableItemGlowRenderProfile(); + if (profile == GlStateManager.Profile.PLAYER_SKIN && LevitatingItemRenderer.enableItemGlowRenderProfile()) { info.cancel(); } } diff --git a/src/main/java/com/minelittlepony/mixin/MixinRenderItem.java b/src/main/java/com/minelittlepony/mixin/MixinRenderItem.java index cb0c810d..1ce4ba35 100644 --- a/src/main/java/com/minelittlepony/mixin/MixinRenderItem.java +++ b/src/main/java/com/minelittlepony/mixin/MixinRenderItem.java @@ -1,6 +1,5 @@ package com.minelittlepony.mixin; -import com.minelittlepony.ducks.IRenderItem; import com.minelittlepony.render.LevitatingItemRenderer; import net.minecraft.client.renderer.RenderItem; @@ -15,20 +14,11 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(RenderItem.class) -public abstract class MixinRenderItem implements IResourceManagerReloadListener, IRenderItem { - - private boolean transparency; - - @Override - public void useTransparency(boolean transparency) { - this.transparency = transparency; - } +public abstract class MixinRenderItem implements IResourceManagerReloadListener { @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/block/model/IBakedModel;)V", at = @At("HEAD")) private void onRenderItem(ItemStack stack, IBakedModel model, CallbackInfo info) { - if (transparency) { - LevitatingItemRenderer.enableItemGlowRenderProfile(); - } + LevitatingItemRenderer.enableItemGlowRenderProfile(); } @ModifyArg(method = "renderQuads(Lnet/minecraft/client/renderer/BufferBuilder;Ljava/util/List;ILnet/minecraft/item/ItemStack;)V", @@ -36,12 +26,12 @@ public abstract class MixinRenderItem implements IResourceManagerReloadListener, target = "Lnet/minecraft/client/renderer/RenderItem;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; + return LevitatingItemRenderer.usesTransparency() ? -1 : color; } @Inject(method = "renderEffect(Lnet/minecraft/client/renderer/block/model/IBakedModel;)V", at = @At("HEAD"), cancellable = true) private void renderEffect(IBakedModel model, CallbackInfo info) { - if (transparency) { + if (LevitatingItemRenderer.usesTransparency()) { info.cancel(); } } diff --git a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java index 4cd291f4..1dd3edb2 100644 --- a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java +++ b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java @@ -3,9 +3,7 @@ package com.minelittlepony.render; import org.lwjgl.opengl.GL14; import com.minelittlepony.MineLittlePony; -import com.minelittlepony.ducks.IRenderItem; import com.minelittlepony.pony.data.IPony; -import com.minelittlepony.render.skull.PonySkullRenderer; import com.minelittlepony.util.render.Color; import com.mumfrey.liteloader.client.overlays.IMinecraft; @@ -25,10 +23,20 @@ import static net.minecraft.client.renderer.GlStateManager.*; public class LevitatingItemRenderer { - public static void enableItemGlowRenderProfile() { - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO); - Minecraft.getMinecraft().entityRenderer.disableLightmap(); + private static boolean usingTransparency; + + public static boolean enableItemGlowRenderProfile() { + if (usesTransparency()) { + GlStateManager.enableBlend(); + GlStateManager.tryBlendFuncSeparate(SourceFactor.CONSTANT_COLOR, DestFactor.ONE, SourceFactor.ONE, DestFactor.ZERO); + Minecraft.getMinecraft().entityRenderer.disableLightmap(); + } + + return usesTransparency(); + } + + public static boolean usesTransparency() { + return usingTransparency; } /** @@ -40,18 +48,17 @@ public class LevitatingItemRenderer { setColor(glowColor); RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); - ((IRenderItem) renderItem).useTransparency(true); - PonySkullRenderer.ponyInstance.useTransparency(true); - scale(1.1, 1.1, 1.1); + usingTransparency = true; - translate(0, 0.01F, 0.01F); + scale(1.1F, 1.1F, 1.1F); + + translate(0.1F, 0.01F, 0.01F); renderItem.renderItem(drop, entity, transform, hand == EnumHandSide.LEFT); - translate(0.01F, -0.01F, -0.02F); + translate(-0.02F, -0.02F, -0.02F); renderItem.renderItem(drop, entity, transform, hand == EnumHandSide.LEFT); - ((IRenderItem) renderItem).useTransparency(false); - PonySkullRenderer.ponyInstance.useTransparency(false); + usingTransparency = false; unsetColor(); enableLighting(); popMatrix(); @@ -86,21 +93,18 @@ public class LevitatingItemRenderer { if (doMagic) { disableLighting(); - IRenderItem renderItem = (IRenderItem)Minecraft.getMinecraft().getRenderItem(); - renderItem.useTransparency(true); - PonySkullRenderer.ponyInstance.useTransparency(true); + usingTransparency = true; setColor(pony.getMetadata().getGlowColor()); scale(1.1, 1.1, 1.1); - translate(-0.015F, 0.01F, 0.01F); + translate(0.01F, 0.01F, 0.01F); renderer.renderItemSide(entity, stack, transform, left); - translate(0.03F, -0.01F, -0.02F); + translate(-0.02F, -0.02F, -0.02F); renderer.renderItemSide(entity, stack, transform, left); - renderItem.useTransparency(false); - PonySkullRenderer.ponyInstance.useTransparency(false); + usingTransparency = false; unsetColor(); enableLighting(); diff --git a/src/main/java/com/minelittlepony/render/skull/PonySkullRenderer.java b/src/main/java/com/minelittlepony/render/skull/PonySkullRenderer.java index 08d8dfd9..27af4a0b 100644 --- a/src/main/java/com/minelittlepony/render/skull/PonySkullRenderer.java +++ b/src/main/java/com/minelittlepony/render/skull/PonySkullRenderer.java @@ -2,8 +2,8 @@ package com.minelittlepony.render.skull; import com.minelittlepony.MineLittlePony; import com.minelittlepony.PonyConfig; -import com.minelittlepony.ducks.IRenderItem; import com.minelittlepony.pony.data.IPony; +import com.minelittlepony.render.LevitatingItemRenderer; import com.mojang.authlib.GameProfile; import com.mumfrey.liteloader.util.ModUtilities; import net.minecraft.client.renderer.GlStateManager; @@ -20,7 +20,7 @@ import javax.annotation.Nullable; /** * PonySkullRenderer! It renders ponies as skulls, or something... */ -public class PonySkullRenderer extends TileEntitySkullRenderer implements IRenderItem { +public class PonySkullRenderer extends TileEntitySkullRenderer { public static final int SKELETON = 0; public static final int WITHER = 1; @@ -68,8 +68,6 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende return instance; } - protected boolean transparency = false; - @Override public void renderSkull(float x, float y, float z, EnumFacing facing, float rotation, int skullType, @Nullable GameProfile profile, int destroyStage, float animateTicks) { @@ -111,7 +109,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende GlStateManager.scale(-1, -1, 1); GlStateManager.enableAlpha(); - skull.preRender(transparency); + skull.preRender(LevitatingItemRenderer.usesTransparency()); skull.render(animateTicks, rotation, scale); GlStateManager.popMatrix(); @@ -146,15 +144,6 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende return rotation; } - @Override - public void useTransparency(boolean use) { - transparency = use; - } - - public boolean usesTransparency() { - return transparency; - } - /** * A skull, just a skull. * diff --git a/src/main/java/com/minelittlepony/transform/PostureElytra.java b/src/main/java/com/minelittlepony/transform/PostureElytra.java index 7314c582..68769224 100644 --- a/src/main/java/com/minelittlepony/transform/PostureElytra.java +++ b/src/main/java/com/minelittlepony/transform/PostureElytra.java @@ -1,6 +1,5 @@ package com.minelittlepony.transform; -import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.capabilities.IModel; import net.minecraft.client.renderer.GlStateManager;