diff --git a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java index da19d70b..c1b65f88 100644 --- a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java @@ -60,11 +60,6 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { initPositions(yOffset, stretch); } - /** - * Returns a new pony armour to go with this model. Called on startup by a model wrapper. - */ - public abstract PonyArmor createArmour(); - /** * Loads texture values. */ @@ -141,11 +136,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { arm.rotateAngleX += MathHelper.sin(tick * 0.067F) * 0.1F; } - /** - * Applies a transform particular to a certain body part. - * - * FIXME: Too long! Is there a better way to do this? - */ + @Override public void transform(BodyPart part) { if (isRiding) translate(0, -0.6F, -0.2F); diff --git a/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java b/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java index 3fac3c32..d2d0d5d2 100644 --- a/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java +++ b/src/main/java/com/minelittlepony/model/armour/ModelZombiePonyArmor.java @@ -1,5 +1,7 @@ package com.minelittlepony.model.armour; +import com.minelittlepony.render.AbstractPonyRenderer; + public class ModelZombiePonyArmor extends ModelPonyArmor { // Copied from ModelZombiePony @@ -24,9 +26,9 @@ public class ModelZombiePonyArmor extends ModelPonyArmor { if (rightArmPose != ArmPose.EMPTY) return; if (islookAngleRight(move)) { - shiftRotationPoint(bipedRightArm, 0.5F, 1.5F, 3); + AbstractPonyRenderer.shiftRotationPoint(bipedRightArm, 0.5F, 1.5F, 3); } else { - shiftRotationPoint(bipedLeftArm, -0.5F, 1.5F, 3); + AbstractPonyRenderer.shiftRotationPoint(bipedLeftArm, -0.5F, 1.5F, 3); } } } diff --git a/src/main/java/com/minelittlepony/model/capabilities/IModel.java b/src/main/java/com/minelittlepony/model/capabilities/IModel.java index f1bfe006..99003a50 100644 --- a/src/main/java/com/minelittlepony/model/capabilities/IModel.java +++ b/src/main/java/com/minelittlepony/model/capabilities/IModel.java @@ -1,9 +1,31 @@ package com.minelittlepony.model.capabilities; +import com.minelittlepony.model.BodyPart; +import com.minelittlepony.model.armour.PonyArmor; + import net.minecraft.entity.Entity; public interface IModel { + + /** + * Sets up this model's initial values, like a constructor... + * @param yOffset YPosition for this model. Always 0. + * @param stretch Scaling factor for this model. Ranges above or below 0 (no change). + */ + void init(float yOffset, float stretch); + + /** + * Applies a transform particular to a certain body part. + */ + void transform(BodyPart part); + + + /** + * Returns a new pony armour to go with this model. Called on startup by a model wrapper. + */ + PonyArmor createArmour(); + /** * Returns true if this model is on the ground and crouching. */ diff --git a/src/main/java/com/minelittlepony/model/capabilities/IModelUnicorn.java b/src/main/java/com/minelittlepony/model/capabilities/IModelUnicorn.java index 234003b9..9381169e 100644 --- a/src/main/java/com/minelittlepony/model/capabilities/IModelUnicorn.java +++ b/src/main/java/com/minelittlepony/model/capabilities/IModelUnicorn.java @@ -17,4 +17,9 @@ public interface IModelUnicorn extends IModel { * @return */ boolean isCasting(); + + /** + * Gets the preferred magic color for this mode. + */ + int getMagicColor(); } diff --git a/src/main/java/com/minelittlepony/model/components/PonySnout.java b/src/main/java/com/minelittlepony/model/components/PonySnout.java index f4f33ac8..6d467296 100644 --- a/src/main/java/com/minelittlepony/model/components/PonySnout.java +++ b/src/main/java/com/minelittlepony/model/components/PonySnout.java @@ -12,8 +12,13 @@ public class PonySnout { private PlaneRenderer mare; private PlaneRenderer stallion; - public PonySnout(AbstractPonyModel pony, float yOffset, float stretch) { + public PonySnout(AbstractPonyModel pony) { mare = new PlaneRenderer(pony); + stallion = new PlaneRenderer(pony); + pony.bipedHead.addChild(stallion); + } + + 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) .tex(10, 14) .addBackPlane(-2, 2, -5, 4, 2, stretch) @@ -26,9 +31,6 @@ 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); - pony.bipedHead.addChild(mare); - - stallion = new PlaneRenderer(pony); stallion.offset(HEAD_CENTRE_X, HEAD_CENTRE_Y, HEAD_CENTRE_Z) .around(HEAD_RP_X, HEAD_RP_Y + yOffset, HEAD_RP_Z) .tex(10, 13) .addBackPlane(-2, 1, -5, 4, 3, stretch) @@ -36,7 +38,6 @@ public class PonySnout { .tex(18, 7).addBottomPlane(-2, 4, -5, 4, 1, stretch) .tex(10, 13) .addWestPlane(-2, 1, -5, 3, 1, stretch) .tex(13, 13) .addEastPlane( 2, 1, -5, 3, 1, stretch); - pony.bipedHead.addChild(stallion); } public void setGender(PonyGender gender) { diff --git a/src/main/java/com/minelittlepony/model/player/ModelAlicorn.java b/src/main/java/com/minelittlepony/model/player/ModelAlicorn.java index f6fbceb4..47bf83f8 100644 --- a/src/main/java/com/minelittlepony/model/player/ModelAlicorn.java +++ b/src/main/java/com/minelittlepony/model/player/ModelAlicorn.java @@ -112,6 +112,11 @@ public class ModelAlicorn extends ModelPegasus implements IModelUnicorn { return rightArmPose != ArmPose.EMPTY || leftArmPose != ArmPose.EMPTY; } + @Override + public int getMagicColor() { + return metadata.getGlowColor(); + } + @Override protected void sneakLegs() { super.sneakLegs(); @@ -136,7 +141,7 @@ public class ModelAlicorn extends ModelPegasus implements IModelUnicorn { if (canCast()) { horn.render(scale); if (isCasting()) { - horn.renderMagic(metadata.getGlowColor(), scale); + horn.renderMagic(getMagicColor(), scale); } } } @@ -146,7 +151,6 @@ public class ModelAlicorn extends ModelPegasus implements IModelUnicorn { super.initLegTextures(); unicornArmLeft = new PonyRenderer(this, 40, 32).size(64, 64); unicornArmRight = new PonyRenderer(this, 40, 32).size(64, 64); - boxList.remove(unicornArmRight); } @Override @@ -155,7 +159,7 @@ public class ModelAlicorn extends ModelPegasus implements IModelUnicorn { float armY = THIRDP_ARM_CENTRE_Y - 6; float armZ = THIRDP_ARM_CENTRE_Z - 2; - unicornArmLeft .box(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25f).around(5, yOffset + 2, 0); - unicornArmRight.box(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25f).around(-5, yOffset + 2, 0); + unicornArmLeft .box(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25F).around(5, yOffset + 2, 0); + unicornArmRight.box(FIRSTP_ARM_CENTRE_X - 2, armY, armZ, 4, 12, 4, stretch + .25F).around(-5, yOffset + 2, 0); } } diff --git a/src/main/java/com/minelittlepony/model/player/ModelEarthPony.java b/src/main/java/com/minelittlepony/model/player/ModelEarthPony.java index 69e2eaef..693a10a7 100644 --- a/src/main/java/com/minelittlepony/model/player/ModelEarthPony.java +++ b/src/main/java/com/minelittlepony/model/player/ModelEarthPony.java @@ -6,6 +6,7 @@ import com.minelittlepony.model.armour.ModelPonyArmor; import com.minelittlepony.model.armour.PonyArmor; import com.minelittlepony.model.components.PonySnout; import com.minelittlepony.model.components.PonyTail; +import com.minelittlepony.render.AbstractPonyRenderer; import com.minelittlepony.render.PonyRenderer; import com.minelittlepony.render.plane.PlaneRenderer; @@ -23,7 +24,7 @@ public class ModelEarthPony extends AbstractPonyModel { private final boolean smallArms; - public ModelRenderer bipedCape; + public PonyRenderer bipedCape; public PlaneRenderer upperTorso; public PlaneRenderer neck; @@ -41,12 +42,6 @@ public class ModelEarthPony extends AbstractPonyModel { return new PonyArmor(new ModelPonyArmor(), new ModelPonyArmor()); } - @Override - public void init(float yOffset, float stretch) { - super.init(yOffset, stretch); - snout = new PonySnout(this, yOffset, stretch); - } - @Override public void setRotationAngles(float move, float swing, float age, float headYaw, float headPitch, float scale, Entity entity) { super.setRotationAngles(move, swing, age, headYaw, headPitch, scale, entity); @@ -366,10 +361,10 @@ public class ModelEarthPony extends AbstractPonyModel { setHead(1, 2, isSneak ? -1 : 1); - shiftRotationPoint(bipedRightArm, 0, 2, 6); - shiftRotationPoint(bipedLeftArm, 0, 2, 6); - shiftRotationPoint(bipedRightLeg, 0, 2, -8); - shiftRotationPoint(bipedLeftLeg, 0, 2, -8); + AbstractPonyRenderer.shiftRotationPoint(bipedRightArm, 0, 2, 6); + AbstractPonyRenderer.shiftRotationPoint(bipedLeftArm, 0, 2, 6); + AbstractPonyRenderer.shiftRotationPoint(bipedRightLeg, 0, 2, -8); + AbstractPonyRenderer.shiftRotationPoint(bipedLeftLeg, 0, 2, -8); } protected void aimBow(ArmPose leftArm, ArmPose rightArm, float tick) { @@ -383,7 +378,7 @@ public class ModelEarthPony extends AbstractPonyModel { arm.rotateAngleX = ROTATE_270 + bipedHead.rotateAngleX; arm.rotateAngleZ += MathHelper.cos(tick * 0.09F) * 0.05F + 0.05F; arm.rotateAngleX += MathHelper.sin(tick * 0.067F) * 0.05F; - if (shift) shiftRotationPoint(arm, 0, 0, 1); + if (shift) AbstractPonyRenderer.shiftRotationPoint(arm, 0, 0, 1); } protected void fixSpecialRotationPoints(float move) { @@ -467,6 +462,7 @@ public class ModelEarthPony extends AbstractPonyModel { bipedCape = new PonyRenderer(this, 0, 0).size(64, 32); bipedHead = new PonyRenderer(this, 0, 0); bipedHeadwear = new PonyRenderer(this, 32, 0); + snout = new PonySnout(this); } protected void initBodyTextures() { @@ -507,6 +503,8 @@ public class ModelEarthPony extends AbstractPonyModel { } protected void initHeadPositions(float yOffset, float stretch) { + snout.init(yOffset, stretch); + bipedCape.addBox(-5.0F, 0.0F, -1.0F, 10, 16, 1, stretch); ((PonyRenderer)bipedHead).offset(HEAD_CENTRE_X, HEAD_CENTRE_Y, HEAD_CENTRE_Z) diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java b/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java index e71c2bfe..94e80d1e 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java @@ -3,6 +3,7 @@ package com.minelittlepony.model.ponies; import com.minelittlepony.model.ModelMobPony; import com.minelittlepony.model.armour.ModelZombiePonyArmor; import com.minelittlepony.model.armour.PonyArmor; +import com.minelittlepony.render.AbstractPonyRenderer; public class ModelZombiePony extends ModelMobPony { @@ -32,9 +33,9 @@ public class ModelZombiePony extends ModelMobPony { if (rightArmPose != ArmPose.EMPTY) return; if (islookAngleRight(move)) { - shiftRotationPoint(bipedRightArm, 0.5F, 1.5F, 3); + AbstractPonyRenderer.shiftRotationPoint(bipedRightArm, 0.5F, 1.5F, 3); } else { - shiftRotationPoint(bipedLeftArm, -0.5F, 1.5F, 3); + AbstractPonyRenderer.shiftRotationPoint(bipedLeftArm, -0.5F, 1.5F, 3); } } } diff --git a/src/main/java/com/minelittlepony/render/AbstractPonyRenderer.java b/src/main/java/com/minelittlepony/render/AbstractPonyRenderer.java index 77e9d76b..88a0a715 100644 --- a/src/main/java/com/minelittlepony/render/AbstractPonyRenderer.java +++ b/src/main/java/com/minelittlepony/render/AbstractPonyRenderer.java @@ -80,6 +80,15 @@ public abstract class AbstractPonyRenderer> ex return (T) this; } + /** + * Adjusts the rotation center of the given renderer by the given amounts in each direction. + */ + public static void shiftRotationPoint(ModelRenderer renderer, float x, float y, float z) { + renderer.rotationPointX += x; + renderer.rotationPointY += y; + renderer.rotationPointZ += z; + } + /** * Sets this renderer's rotation angles. */ diff --git a/src/main/java/com/minelittlepony/render/HornGlowRenderer.java b/src/main/java/com/minelittlepony/render/HornGlowRenderer.java index e767cf10..d7a03c04 100644 --- a/src/main/java/com/minelittlepony/render/HornGlowRenderer.java +++ b/src/main/java/com/minelittlepony/render/HornGlowRenderer.java @@ -2,13 +2,13 @@ package com.minelittlepony.render; import static net.minecraft.client.renderer.GlStateManager.color; +import com.minelittlepony.util.coordinates.Color; + import net.minecraft.client.model.ModelBase; public class HornGlowRenderer extends AbstractPonyRenderer { - float red; - float green; - float blue; + int tint; float alpha = 1; public HornGlowRenderer(ModelBase model, int x, int y) { @@ -22,15 +22,13 @@ public class HornGlowRenderer extends AbstractPonyRenderer { } public HornGlowRenderer setTint(int tint) { - red = (tint >> 16 & 255) / 255.0F; - green = (tint >> 8 & 255) / 255.0F; - blue = (tint & 255) / 255.0F; + this.tint = tint; return this; } public void applyTint(float alpha) { - color(red, green, blue, alpha); + Color.glColor(tint, alpha); } @Override diff --git a/src/main/java/com/minelittlepony/render/layer/AbstractPonyLayer.java b/src/main/java/com/minelittlepony/render/layer/AbstractPonyLayer.java index 96ad02f2..4e394568 100644 --- a/src/main/java/com/minelittlepony/render/layer/AbstractPonyLayer.java +++ b/src/main/java/com/minelittlepony/render/layer/AbstractPonyLayer.java @@ -2,6 +2,7 @@ package com.minelittlepony.render.layer; import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.model.capabilities.IModel; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.entity.RenderLivingBase; @@ -33,8 +34,9 @@ public abstract class AbstractPonyLayer implements L return ((IRenderPony) getRenderer()).getPlayerModel().getModel(); } - public AbstractPonyModel getPonyModel() { - return getMainModel(); + @SuppressWarnings("unchecked") + public M getPonyModel() { + return (M)getMainModel(); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/minelittlepony/render/layer/LayerHeldPonyItemMagical.java b/src/main/java/com/minelittlepony/render/layer/LayerHeldPonyItemMagical.java index 3e371e39..c4f66f87 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerHeldPonyItemMagical.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerHeldPonyItemMagical.java @@ -7,13 +7,11 @@ import static net.minecraft.client.renderer.GlStateManager.pushMatrix; import static net.minecraft.client.renderer.GlStateManager.scale; import static net.minecraft.client.renderer.GlStateManager.translate; -import org.lwjgl.opengl.GL14; - import com.minelittlepony.ducks.IRenderItem; import com.minelittlepony.model.capabilities.IModelUnicorn; +import com.minelittlepony.util.coordinates.Color; import net.minecraft.client.Minecraft; -import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; @@ -29,10 +27,10 @@ public class LayerHeldPonyItemMagical extends LayerH } protected boolean isUnicorn() { - ModelBase model = getMainModel(); - return model instanceof IModelUnicorn && ((IModelUnicorn) model).canCast(); + return getMainModel() instanceof IModelUnicorn && this.getPonyModel().canCast(); } + @Override protected void preItemRender(T entity, ItemStack drop, TransformType transform, EnumHandSide hand) { if (isUnicorn()) { GlStateManager.translate(hand == EnumHandSide.LEFT ? -0.6F : 0.1F, 1, -0.5F); @@ -41,18 +39,17 @@ public class LayerHeldPonyItemMagical extends LayerH } } + @Override protected void postItemRender(T entity, ItemStack drop, TransformType transform, EnumHandSide hand) { if (isUnicorn()) { - renderItemGlow(entity, drop, transform, hand, getPonyModel().metadata.getGlowColor()); + renderItemGlow(entity, drop, transform, hand, this.getPonyModel().getMagicColor()); } } - /** - * Renders the main arm - */ + @Override protected void renderArm(EnumHandSide side) { if (isUnicorn()) { - ((IModelUnicorn)getMainModel()).getUnicornArmForSide(side).postRender(0.0625F); + this.getPonyModel().getUnicornArmForSide(side).postRender(0.0625F); } else { super.renderArm(side); } @@ -63,15 +60,10 @@ public class LayerHeldPonyItemMagical extends LayerH // enchantments mess up the rendering drop = stackWithoutEnchantment(drop); - float red = (glowColor >> 16 & 255) / 255.0F; - float green = (glowColor >> 8 & 255) / 255.0F; - float blue = (glowColor & 255) / 255.0F; - float alpha = 0.2F; - pushMatrix(); disableLighting(); - GL14.glBlendColor(red, green, blue, alpha); + Color.glColor(glowColor, 0.2F); RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); ((IRenderItem) renderItem).useTransparency(true); diff --git a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java index af314204..dc4c52e7 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerPonyArmor.java @@ -6,6 +6,7 @@ import com.minelittlepony.ducks.IRenderPony; import com.minelittlepony.model.AbstractPonyModel; import com.minelittlepony.model.ModelWrapper; import com.minelittlepony.model.armour.ModelPonyArmor; +import com.minelittlepony.util.coordinates.Color; import net.minecraft.client.Minecraft; import net.minecraft.client.model.ModelBase; @@ -69,11 +70,7 @@ public class LayerPonyArmor extends AbstractPonyLaye getRenderer().bindTexture(armors.getFirst()); if (itemarmor.getArmorMaterial() == ArmorMaterial.LEATHER) { - int color = itemarmor.getColor(itemstack); - float r = (color >> 16 & 255) / 255.0F; - float g = (color >> 8 & 255) / 255.0F; - float b = (color & 255) / 255.0F; - GlStateManager.color(r, g, b, 1); + Color.glColor(itemarmor.getColor(itemstack), 1); modelbase.render(entity, move, swing, age, headYaw, headPitch, scale); armors = getArmorTexture(entity, itemstack, armorSlot, "overlay"); getRenderer().bindTexture(armors.getFirst()); diff --git a/src/main/java/com/minelittlepony/render/plane/ModelPlane.java b/src/main/java/com/minelittlepony/render/plane/ModelPlane.java index a1cedd46..0d713740 100644 --- a/src/main/java/com/minelittlepony/render/plane/ModelPlane.java +++ b/src/main/java/com/minelittlepony/render/plane/ModelPlane.java @@ -63,10 +63,10 @@ public class ModelPlane extends Box { if (face == Face.DOWN) { quad = quad(textureX, w, textureY, d, eus, wus, wun, eun); } - if (face == Face.SOUTH) { // East/Left (was South) + if (face == Face.SOUTH) { quad = quad(textureX, w, textureY, h, eds, wds, wus, eus); } - if (face == Face.NORTH) { // West/Right (was North) + if (face == Face.NORTH) { quad = quad(textureX, w, textureY, h, wdn, edn, eun, wun); } diff --git a/src/main/java/com/minelittlepony/util/coordinates/Color.java b/src/main/java/com/minelittlepony/util/coordinates/Color.java new file mode 100644 index 00000000..915b910b --- /dev/null +++ b/src/main/java/com/minelittlepony/util/coordinates/Color.java @@ -0,0 +1,21 @@ +package com.minelittlepony.util.coordinates; + +import net.minecraft.client.renderer.GlStateManager; + +public interface Color { + public static float r(int color) { + return (color >> 16 & 255) / 255F; + } + + public static float g(int color) { + return (color >> 8 & 255) / 255F; + } + + public static float b(int color) { + return (color & 255) / 255F; + } + + public static void glColor(int color, float alpha) { + GlStateManager.color(Color.r(color), Color.g(color), Color.b(color), alpha); + } +}