From ce71badc7adf6978dc1438976d356915f793b5b1 Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Tue, 3 May 2016 21:24:07 -0400 Subject: [PATCH] Fix held item glow --- .../renderer/layer/LayerHeldPonyItem.java | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerHeldPonyItem.java b/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerHeldPonyItem.java index ce006cd7..55d6237c 100644 --- a/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerHeldPonyItem.java +++ b/src/main/java/com/brohoof/minelittlepony/renderer/layer/LayerHeldPonyItem.java @@ -7,8 +7,11 @@ import org.lwjgl.opengl.GL14; import com.brohoof.minelittlepony.PonyData; import com.brohoof.minelittlepony.ducks.IRenderPony; +import com.brohoof.minelittlepony.model.AbstractPonyModel; +import com.brohoof.minelittlepony.model.BodyPart; import com.brohoof.minelittlepony.model.PlayerModel; import com.brohoof.minelittlepony.model.pony.ModelHumanPlayer; +import com.brohoof.minelittlepony.model.pony.ModelPlayerPony; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBiped; @@ -50,6 +53,7 @@ public class LayerHeldPonyItem implements LayerRenderer { if (left != null || right != null) { pushMatrix(); + pony.getModel().transform(BodyPart.LEGS); if (this.livingPonyEntity.getMainModel().isChild) { translate(0, 0.625, 0); rotate(-20, -1, 0, 0); @@ -66,8 +70,15 @@ public class LayerHeldPonyItem implements LayerRenderer { private void renderHeldItem(EntityLivingBase entity, ItemStack drop, ItemCameraTransforms.TransformType transform, EnumHandSide hand) { if (drop != null) { GlStateManager.pushMatrix(); - ((ModelBiped) this.livingPonyEntity.getMainModel()).postRenderArm(0.0625F, hand); - + AbstractPonyModel thePony = ((IRenderPony) this.livingPonyEntity).getPony().getModel(); + PonyData metadata = thePony.metadata; + boolean isUnicorn = metadata.getRace().hasHorn(); + if (isUnicorn) { + ModelPlayerPony playerModel = (ModelPlayerPony) thePony; + playerModel.unicornarm.postRender(0.0625F); + } else { + ((ModelBiped) this.livingPonyEntity.getMainModel()).postRenderArm(0.0625F, hand); + } if (entity.isSneaking()) { GlStateManager.translate(0.0F, 0.2F, 0.0F); } @@ -75,18 +86,26 @@ public class LayerHeldPonyItem implements LayerRenderer { GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F); GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); boolean isLeft = hand == EnumHandSide.LEFT; - GlStateManager.translate(isLeft ? -0.0625F : 0.0625F, 0.125F, -0.625F); - Minecraft.getMinecraft().getItemRenderer().renderItemSide(entity, drop, transform, isLeft); - GlStateManager.popMatrix(); - - PonyData metadata = ((IRenderPony) this.livingPonyEntity).getPony().getModel().metadata; - if (metadata.getRace().hasHorn() && metadata.getGlowColor() != 0) { - this.renderItemGlow(entity, drop, transform, hand, metadata.getGlowColor()); + if (isUnicorn) { + GlStateManager.translate(isLeft ? -0.1F : 0.1F, 1, -.5); + } else { + GlStateManager.translate(isLeft ? -0.0625F : 0.0625F, 0.125F, -1.00F); } + Minecraft.getMinecraft().getItemRenderer().renderItemSide(entity, drop, transform, isLeft); + + if (isUnicorn && metadata.getGlowColor() != 0) { + this.renderItemGlow(entity, drop.copy(), transform, hand, metadata.getGlowColor()); + } + GlStateManager.popMatrix(); } } public void renderItemGlow(EntityLivingBase entity, ItemStack drop, ItemCameraTransforms.TransformType transform, EnumHandSide hand, int glowColor) { + + // enchantments mess up the rendering + if (drop.hasEffect()) + drop.setTagInfo("ench", null); + GL11.glPushAttrib(GL11.GL_CURRENT_BIT | GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT); float red = (glowColor >> 16 & 255) / 255.0F; @@ -99,9 +118,9 @@ public class LayerHeldPonyItem implements LayerRenderer { GL14.glBlendColor(red, green, blue, alpha); IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(drop, null, null); - scale(2, 2, 2); + ItemCameraTransforms itemcameratransforms = model.getItemCameraTransforms(); + ItemCameraTransforms.applyTransformSide(itemcameratransforms.getTransform(transform), hand == EnumHandSide.LEFT); - model.getItemCameraTransforms().applyTransform(transform); RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); scale(1.1, 1.1, 1.1);