diff --git a/src/main/java/com/minelittlepony/MineLittlePony.java b/src/main/java/com/minelittlepony/MineLittlePony.java index a031beff..f1987c04 100644 --- a/src/main/java/com/minelittlepony/MineLittlePony.java +++ b/src/main/java/com/minelittlepony/MineLittlePony.java @@ -4,6 +4,7 @@ import com.minelittlepony.gui.GuiPonySettings; import com.minelittlepony.hdskins.gui.GuiSkinsMineLP; import com.minelittlepony.pony.data.IPonyData; import com.minelittlepony.pony.data.PonyDataSerialzier; +import com.minelittlepony.render.PonySkullRenderer; import com.mumfrey.liteloader.core.LiteLoader; import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.skins.SkinServer; @@ -76,6 +77,8 @@ public class MineLittlePony { RenderManager rm = minecraft.getRenderManager(); renderManager.initialisePlayerRenderers(rm); renderManager.initializeMobRenderers(rm, config); + + PonySkullRenderer.apply(); } void onTick(Minecraft minecraft, boolean inGame) { diff --git a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java index f54c0af1..9e54a84f 100644 --- a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java @@ -538,10 +538,8 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { ((PonyRenderer)bipedHead).offset(HEAD_CENTRE_X, HEAD_CENTRE_Y, HEAD_CENTRE_Z) .around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z - 2) .box(-4, -4, -4, 8, 8, 8, stretch) - .tex(12, 16) - .box(-4, -6, 1, 2, 2, 2, stretch) - .flip() - .box(2, -6, 1, 2, 2, 2, stretch); + .tex(12, 16).box(-4, -6, 1, 2, 2, 2, stretch) + .flip().box( 2, -6, 1, 2, 2, 2, stretch); ((PonyRenderer)bipedHeadwear).offset(HEAD_CENTRE_X, HEAD_CENTRE_Y, HEAD_CENTRE_Z) .around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z - 2) diff --git a/src/main/java/com/minelittlepony/model/components/ModelPonyHead.java b/src/main/java/com/minelittlepony/model/components/ModelPonyHead.java index 99958ea0..480b1505 100644 --- a/src/main/java/com/minelittlepony/model/components/ModelPonyHead.java +++ b/src/main/java/com/minelittlepony/model/components/ModelPonyHead.java @@ -3,6 +3,7 @@ package com.minelittlepony.model.components; import com.minelittlepony.model.capabilities.ICapitated; import com.minelittlepony.pony.data.IPonyData; import com.minelittlepony.pony.data.PonyData; +import com.minelittlepony.render.PonyRenderer; import net.minecraft.client.model.ModelHumanoidHead; import net.minecraft.client.model.ModelRenderer; @@ -10,17 +11,27 @@ import net.minecraft.entity.Entity; public class ModelPonyHead extends ModelHumanoidHead implements ICapitated { - private final PonySnout snout; + private PonySnout snout; private final UnicornHorn horn; + private final PonyRenderer ears; + public IPonyData metadata = new PonyData(); public ModelPonyHead() { super(); - snout = new PonySnout(this); - horn = new UnicornHorn(this, 0, 0); + snout = new PonySnout(this, 0, -3, 2); + horn = new UnicornHorn(this, 0, 0, 0, -1, 4); + + snout.init(0, 0); + + ears = new PonyRenderer(this, 0, 0).offset(0, -3, 2).around(0, 0, -2) + .tex(12, 16).box(-4, -6, 1, 2, 2, 2, 0) + .flip().box( 2, -6, 1, 2, 2, 2, 0); + + skeletonHead.addChild(ears); } @Override @@ -30,12 +41,15 @@ public class ModelPonyHead extends ModelHumanoidHead implements ICapitated { @Override public void render(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) { + snout.isHidden = metadata.getRace().isHuman(); + ears.isHidden = snout.isHidden; snout.setGender(metadata.getGender()); super.render(entity, move, swing, ticks, headYaw, headPitch, scale); if (metadata.hasMagic()) { + skeletonHead.postRender(scale); horn.render(scale); } } diff --git a/src/main/java/com/minelittlepony/model/components/PonySnout.java b/src/main/java/com/minelittlepony/model/components/PonySnout.java index e77110f0..9bdb1da3 100644 --- a/src/main/java/com/minelittlepony/model/components/PonySnout.java +++ b/src/main/java/com/minelittlepony/model/components/PonySnout.java @@ -18,8 +18,12 @@ public class PonySnout { private PlaneRenderer stallion; public PonySnout(T pony) { - mare = new PlaneRenderer(pony); - stallion = new PlaneRenderer(pony); + this(pony, 0, 0, 0); + } + + public PonySnout(T pony, int x, int y, int z) { + mare = new PlaneRenderer(pony).offset(HEAD_CENTRE_X + x, HEAD_CENTRE_Y + y, HEAD_CENTRE_Z + z); + stallion = new PlaneRenderer(pony).offset(HEAD_CENTRE_X + x, HEAD_CENTRE_Y + y, HEAD_CENTRE_Z + z); pony.getHead().addChild(stallion); pony.getHead().addChild(mare); @@ -31,8 +35,7 @@ public class PonySnout { } public void init(float yOffset, float stretch) { - mare.offset(HEAD_CENTRE_X, HEAD_CENTRE_Y, HEAD_CENTRE_Z) - .around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) + mare.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) .tex(10, 14) .addBackPlane(-2, 2, -5, 4, 2, stretch) .tex(11, 13) .addBackPlane(-1, 1, -5, 2, 1, stretch) .tex(9, 14) .addTopPlane(-2, 2, -5, 1, 1, stretch) @@ -43,8 +46,7 @@ public class PonySnout { .tex(14, 14) .addEastPlane( 2, 2, -5, 2, 1, stretch) .tex(11, 12) .addWestPlane(-1, 1, -5, 1, 1, stretch) .tex(12, 12) .addEastPlane( 1, 1, -5, 1, 1, stretch); - stallion.offset(HEAD_CENTRE_X, HEAD_CENTRE_Y, HEAD_CENTRE_Z) - .around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) + stallion.around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) .tex(10, 13) .addBackPlane(-2, 1, -5, 4, 3, stretch) .tex(10, 13) .addTopPlane(-2, 1, -5, 4, 1, stretch) .tex(18, 7).addBottomPlane(-2, 4, -5, 4, 1, stretch) diff --git a/src/main/java/com/minelittlepony/model/components/UnicornHorn.java b/src/main/java/com/minelittlepony/model/components/UnicornHorn.java index 9d105800..81903de6 100644 --- a/src/main/java/com/minelittlepony/model/components/UnicornHorn.java +++ b/src/main/java/com/minelittlepony/model/components/UnicornHorn.java @@ -16,15 +16,19 @@ public class UnicornHorn { private HornGlowRenderer glow; public UnicornHorn(T pony, float yOffset, float stretch) { + this(pony, yOffset, stretch, 0, 0, 0); + } + + public UnicornHorn(T pony, float yOffset, float stretch, int x, int y, int z) { horn = new PonyRenderer(pony, 0, 3); glow = new HornGlowRenderer(pony, 0, 3); - horn.offset(HORN_X, HORN_Y, HORN_Z) + horn.offset(HORN_X + x, HORN_Y + y, HORN_Z + z) .around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) .box(0, 0, 0, 1, 4, 1, stretch) .rotateAngleX = 0.5F; - glow.offset(HORN_X, HORN_Y, HORN_Z) + glow.offset(HORN_X + x, HORN_Y + y, HORN_Z + z) .around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) .setAlpha(0.4f).box(0, 0, 0, 1, 4, 1, stretch + 0.5F) .setAlpha(0.2f).box(0, 0, 0, 1, 3, 1, stretch + 0.8F); diff --git a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java index 0f6ea67d..646d3cf6 100644 --- a/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java +++ b/src/main/java/com/minelittlepony/render/LevitatingItemRenderer.java @@ -82,6 +82,7 @@ public class LevitatingItemRenderer { IRenderItem renderItem = (IRenderItem)Minecraft.getMinecraft().getRenderItem(); renderItem.useTransparency(true); + ((IRenderItem)PonySkullRenderer.instance).useTransparency(true); setColor(pony.getMetadata().getGlowColor()); @@ -93,6 +94,7 @@ public class LevitatingItemRenderer { renderer.renderItemSide(entity, stack, transform, left); renderItem.useTransparency(false); + ((IRenderItem)PonySkullRenderer.instance).useTransparency(false); unsetColor(); enableLighting(); } diff --git a/src/main/java/com/minelittlepony/render/PonySkullRenderer.java b/src/main/java/com/minelittlepony/render/PonySkullRenderer.java index 625e96cc..4d42fd8f 100644 --- a/src/main/java/com/minelittlepony/render/PonySkullRenderer.java +++ b/src/main/java/com/minelittlepony/render/PonySkullRenderer.java @@ -1,13 +1,10 @@ package com.minelittlepony.render; import java.util.Map; +import java.util.Optional; import javax.annotation.Nullable; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - import com.minelittlepony.MineLittlePony; import com.minelittlepony.PonyConfig; import com.minelittlepony.ducks.IRenderItem; @@ -18,9 +15,10 @@ import com.minelittlepony.render.ponies.RenderPonyZombie; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; +import com.mumfrey.liteloader.util.ModUtilities; +import com.voxelmodpack.hdskins.HDSkinManager; import net.minecraft.client.Minecraft; -import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager.DestFactor; import net.minecraft.client.renderer.GlStateManager.SourceFactor; @@ -28,18 +26,43 @@ import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer; import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntitySkull; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; public class PonySkullRenderer extends TileEntitySkullRenderer implements IRenderItem { - private final ModelPonyHead ponyHead = new ModelPonyHead(); + private ModelPonyHead ponyHead = new ModelPonyHead(); private boolean renderAsPony = false; protected boolean transparency = false; - public void renderSkull(float x, float y, float z, EnumFacing facing, float rotationIn, int skullType, @Nullable GameProfile profile, int destroyStage, float animateTicks, CallbackInfo info) { + private static final PonySkullRenderer ponyInstance = new PonySkullRenderer(); + private static TileEntitySkullRenderer backup = null; + + public static TileEntitySkullRenderer apply() { + if (instance != ponyInstance) { + backup = instance; + ModUtilities.addRenderer(TileEntitySkull.class, ponyInstance); + instance = ponyInstance; + } + return instance; + } + + public static TileEntitySkullRenderer unapply() { + if (instance == ponyInstance && backup != null) { + ModUtilities.addRenderer(TileEntitySkull.class, backup); + instance = backup; + } + return instance; + } + + private PonySkullRenderer() { + + } + + public void renderSkull(float x, float y, float z, EnumFacing facing, float rotationIn, int skullType, @Nullable GameProfile profile, int destroyStage, float animateTicks) { PonyConfig config = MineLittlePony.getConfig(); switch (skullType) @@ -73,11 +96,17 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende return RenderPonySkeleton.WITHER; } if (skullType == 2) { - return RenderPonySkeleton.SKELETON; + return RenderPonyZombie.ZOMBIE; } + if (skullType == 3) { if (profile != null) { + Optional skin = HDSkinManager.INSTANCE.getSkinLocation(profile, Type.SKIN, true); + if (skin.isPresent()) { + return skin.get(); + } + Minecraft minecraft = Minecraft.getMinecraft(); Map map = minecraft.getSkinManager().loadSkinFromCache(profile); @@ -91,7 +120,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende return DefaultPlayerSkin.getDefaultSkinLegacy(); } - return RenderPonyZombie.ZOMBIE; + return RenderPonySkeleton.SKELETON; } public void renderPonySkull(float x, float y, float z, EnumFacing facing, float rotationIn, int skullType, @Nullable GameProfile profile, int destroyStage, float animateTicks) { @@ -152,18 +181,8 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende } } - @Redirect(method = "renderSkull(FFFLnet/minecraft/util/EnumFacing;FILcom/mojang/authlib/GameProfile;IF)V", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/model/ModelBase;render(Let/minecraft/entity/Entity;FFFFFFF)V")) - private void redirectRender(ModelBase self, Entity entity, float ticks, float swing, float swingAmount, float age, float headYaw, float headPitch, float scale) { - if (renderAsPony) { - self = ponyHead; - } - - self.render(entity, swing, swingAmount, age, headYaw, headPitch, scale); - } - - protected void bindTexture(ResourceLocation location, CallbackInfo info) { + @Override + protected void bindTexture(ResourceLocation location) { Pony pony = MineLittlePony.getInstance().getManager().getPony(location, false); ponyHead.metadata = pony.getMetadata(); super.bindTexture(location);