diff --git a/src/main/java/com/minelittlepony/render/BasePonyRenderer.java b/src/main/java/com/minelittlepony/render/BasePonyRenderer.java index 787d51ff..05305dbe 100644 --- a/src/main/java/com/minelittlepony/render/BasePonyRenderer.java +++ b/src/main/java/com/minelittlepony/render/BasePonyRenderer.java @@ -1,16 +1,19 @@ package com.minelittlepony.render; import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelBox; import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.model.TextureOffset; @SuppressWarnings("unchecked") -public class BasePonyRenderer> extends ModelRenderer { +public abstract class BasePonyRenderer> extends ModelRenderer { protected final ModelBase baseModel; protected int textureOffsetX, textureOffsetY; + protected float modelOffsetX, modelOffsetY, modelOffsetZ; + public BasePonyRenderer(ModelBase model) { super(model); baseModel = model; @@ -20,6 +23,11 @@ public class BasePonyRenderer> extends ModelRender super(model, x, y); baseModel = model; } + + /** + * Called to create a new instance of this renderer (used for child renderers) + */ + protected abstract T copySelf(); @Override public T setTextureOffset(int x, int y) { @@ -29,23 +37,87 @@ public class BasePonyRenderer> extends ModelRender return (T) this; } - public T at(float x, float y, float z) { - offsetX = x; - offsetY = y; - offsetZ = z; + /** + * Flips the mirror flag. All faces are mirrored until this is called again. + */ + public T mirror() { + return mirror(!mirror); + } + + public T mirror(boolean m) { + mirror = m; return (T) this; } + + /** + * Sets the texture offset + */ + public T tex(int x, int y) { + return setTextureOffset(x, y); + } + + public T size(int x, int y) { + return (T) setTextureSize(x, y); + } + + /** + * Positions this model in space. + */ + public T at(float x, float y, float z) { + return (T)at(this, x, y, z); + } + + /** + * Sets an offset to be used on all shapes and children created through this renderer. + */ + public T offset(float x, float y, float z) { + modelOffsetX = x; + modelOffsetY = y; + modelOffsetZ = z; + return (T) this; + } + + public static T at(T renderer, float x, float y, float z) { + renderer.offsetX = x / 16; + renderer.offsetY = y / 16; + renderer.offsetZ = z / 16; + return renderer; + } + + public void rotateTo(ModelRenderer other) { + rotateAngleX = other.rotateAngleX; + rotateAngleY = other.rotateAngleY; + rotateAngleZ = other.rotateAngleZ; + } + + public T rotateAt(ModelRenderer other) { + return at(other.rotationPointX, other.rotationPointY, other.rotationPointZ); + } + /** + * Sets the rotation point. + */ public T around(float x, float y, float z) { setRotationPoint(x, y, z); return (T) this; } + /** + * Gets or creates a new child model based on its unique index. + * New children will be of the same type and inherit the same textures and offsets of the original. + */ + public T child(int index) { + if (childModels == null || index >= childModels.size()) { + addChild(copySelf().offset(modelOffsetX, modelOffsetY, modelOffsetZ)); + } + return (T)childModels.get(index); + } + @Override public T addBox(String partName, float offX, float offY, float offZ, int width, int height, int depth) { partName = boxName + "." + partName; - TextureOffset tex = this.baseModel.getTextureOffset(partName); + TextureOffset tex = baseModel.getTextureOffset(partName); setTextureOffset(tex.textureOffsetX, tex.textureOffsetY).addBox(offX, offY, offZ, width, height, depth); cubeList.get(cubeList.size() - 1).setBoxName(partName); @@ -58,4 +130,29 @@ public class BasePonyRenderer> extends ModelRender addBox(offX, offY, offZ, width, height, depth, 0); return (T) this; } + + public T addBox(float offX, float offY, float offZ, int width, int height, int depth, boolean mirrored) { + addBox(offX, offY, offZ, width, height, depth, 0, mirrored); + return (T)this; + } + + public void addBox(float offX, float offY, float offZ, int width, int height, int depth, float scaleFactor) { + addBox(offX, offY, offZ, width, height, depth, scaleFactor, mirror); + } + + /** + * Creates a textured box. + */ + public T box(float offX, float offY, float offZ, int width, int height, int depth, float scaleFactor) { + return addBox(offX, offY, offZ, width, height, depth, scaleFactor, mirror); + } + + private T addBox(float offX, float offY, float offZ, int width, int height, int depth, float scaleFactor, boolean mirrored) { + createBox(modelOffsetX + offX, modelOffsetY + offY, modelOffsetZ + offZ, width, height, depth, scaleFactor, mirrored); + return (T)this; + } + + protected void createBox(float offX, float offY, float offZ, int width, int height, int depth, float scaleFactor, boolean mirrored) { + cubeList.add(new ModelBox(this, textureOffsetX, textureOffsetY, offX, offY, offZ, width, height, depth, scaleFactor, mirrored)); + } } diff --git a/src/main/java/com/minelittlepony/render/PonyRenderer.java b/src/main/java/com/minelittlepony/render/PonyRenderer.java new file mode 100644 index 00000000..102dc0ff --- /dev/null +++ b/src/main/java/com/minelittlepony/render/PonyRenderer.java @@ -0,0 +1,20 @@ +package com.minelittlepony.render; + +import net.minecraft.client.model.ModelBase; + +public class PonyRenderer extends BasePonyRenderer { + + public PonyRenderer(ModelBase model) { + super(model); + } + + public PonyRenderer(ModelBase model, int x, int y) { + super(model, x, y); + } + + @Override + protected PonyRenderer copySelf() { + return new PonyRenderer(baseModel, textureOffsetX, textureOffsetY); + } + +} diff --git a/src/main/java/com/minelittlepony/render/plane/Face.java b/src/main/java/com/minelittlepony/render/plane/Face.java index 86149e82..1c466452 100644 --- a/src/main/java/com/minelittlepony/render/plane/Face.java +++ b/src/main/java/com/minelittlepony/render/plane/Face.java @@ -1,7 +1,7 @@ package com.minelittlepony.render.plane; enum Face { - WEST, EAST, + NORTH, SOUTH, UP, DOWN, - NORTH, SOUTH + EAST, WEST; } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/render/plane/ModelPlane.java b/src/main/java/com/minelittlepony/render/plane/ModelPlane.java index 33695541..bd575aa1 100644 --- a/src/main/java/com/minelittlepony/render/plane/ModelPlane.java +++ b/src/main/java/com/minelittlepony/render/plane/ModelPlane.java @@ -16,17 +16,14 @@ public class ModelPlane extends ModelBox { public ModelPlane(PlaneRenderer renderer, int textureX, int textureY, float x, float y, float z, int w, int h, int d, float scale, Face face) { super(renderer, textureX, textureY, x, y, z, w, h, d, scale, false); - float x2 = x + w; - float y2 = y + h; - float z2 = z + d; + float x2 = x + w + scale; + float y2 = y + h + scale; + float z2 = z + d + scale; x -= scale; y -= scale; z -= scale; - x2 += scale; - y2 += scale; - z2 += scale; - + if (renderer.mirror) { float v = x2; x2 = x; @@ -47,56 +44,32 @@ public class ModelPlane extends ModelBox { } // w:west e:east d:down u:up s:south n:north - PositionTextureVertex wds = new PositionTextureVertex(x, y, z, 0.0F, 0.0F); - PositionTextureVertex eds = new PositionTextureVertex(x2, y, z, 0.0F, 8.0F); - PositionTextureVertex eus = new PositionTextureVertex(x2, y2, z, 8.0F, 8.0F); - PositionTextureVertex wus = new PositionTextureVertex(x, y2, z, 8.0F, 0.0F); - PositionTextureVertex wdn = new PositionTextureVertex(x, y, z2, 0.0F, 0.0F); - PositionTextureVertex edn = new PositionTextureVertex(x2, y, z2, 0.0F, 8.0F); - PositionTextureVertex eun = new PositionTextureVertex(x2, y2, z2, 8.0F, 8.0F); - PositionTextureVertex wun = new PositionTextureVertex(x, y2, z2, 8.0F, 0.0F); + PositionTextureVertex wds = new PositionTextureVertex(x , y , z , 0, 0); + PositionTextureVertex eds = new PositionTextureVertex(x2, y , z , 0, 8); + PositionTextureVertex eus = new PositionTextureVertex(x2, y2, z , 8, 8); + PositionTextureVertex wus = new PositionTextureVertex(x , y2, z , 8, 0); + PositionTextureVertex wdn = new PositionTextureVertex(x , y , z2, 0, 0); + PositionTextureVertex edn = new PositionTextureVertex(x2, y , z2, 0, 8); + PositionTextureVertex eun = new PositionTextureVertex(x2, y2, z2, 8, 8); + PositionTextureVertex wun = new PositionTextureVertex(x , y2, z2, 8, 0); - if (face == Face.EAST) { - quad = new TexturedQuad( - new PositionTextureVertex[]{edn, eds, eus, eun}, - textureX, textureY, - textureX + d, textureY + h, - renderer.textureWidth, renderer.textureHeight); + if (face == Face.EAST) { // North/Front (was East) + quad = new TexturedQuad(new PositionTextureVertex[]{edn, eds, eus, eun}, textureX, textureY, textureX + d, textureY + h, renderer.textureWidth, renderer.textureHeight); } - if (face == Face.WEST) { - quad = new TexturedQuad( - new PositionTextureVertex[]{wds, wdn, wun, wus}, - textureX, textureY, - textureX + d, textureY + h, - renderer.textureWidth, renderer.textureHeight); + if (face == Face.WEST) { // South/Back (was West) + quad = new TexturedQuad(new PositionTextureVertex[]{wds, wdn, wun, wus}, textureX, textureY, textureX + d, textureY + h, renderer.textureWidth, renderer.textureHeight); } - if (face == Face.UP) { - quad = new TexturedQuad( - new PositionTextureVertex[]{edn, wdn, wds, eds}, - textureX, textureY, - textureX + w, textureY + d, - renderer.textureWidth, renderer.textureHeight); + if (face == Face.UP) { // Up + quad = new TexturedQuad(new PositionTextureVertex[]{edn, wdn, wds, eds}, textureX, textureY, textureX + w, textureY + d, renderer.textureWidth, renderer.textureHeight); } - if (face == Face.DOWN) { - quad = new TexturedQuad( - new PositionTextureVertex[]{eus, wus, wun, eun}, - textureX, textureY, - textureX + w, textureY + d, - renderer.textureWidth, renderer.textureHeight); + if (face == Face.DOWN) { // Down + quad = new TexturedQuad(new PositionTextureVertex[]{eus, wus, wun, eun}, textureX, textureY, textureX + w, textureY + d, renderer.textureWidth, renderer.textureHeight); } - if (face == Face.SOUTH) { - quad = new TexturedQuad( - new PositionTextureVertex[]{eds, wds, wus, eus}, - textureX, textureY, - textureX + w, textureY + h, - renderer.textureWidth, renderer.textureHeight); + if (face == Face.SOUTH) { // East/Left (was South) + quad = new TexturedQuad(new PositionTextureVertex[]{eds, wds, wus, eus}, textureX, textureY, textureX + w, textureY + h, renderer.textureWidth, renderer.textureHeight); } - if (face == Face.NORTH) { - quad = new TexturedQuad( - new PositionTextureVertex[]{wdn, edn, eun, wun}, - textureX, textureY, - textureX + w, textureY + h, - renderer.textureWidth, renderer.textureHeight); + if (face == Face.NORTH) { // West/Right (was North) + quad = new TexturedQuad(new PositionTextureVertex[]{wdn, edn, eun, wun}, textureX, textureY, textureX + w, textureY + h, renderer.textureWidth, renderer.textureHeight); } if (renderer.mirror || renderer.mirrory || renderer.mirrorz) { diff --git a/src/main/java/com/minelittlepony/render/plane/PlaneRenderer.java b/src/main/java/com/minelittlepony/render/plane/PlaneRenderer.java index cb5e54f9..c5560169 100644 --- a/src/main/java/com/minelittlepony/render/plane/PlaneRenderer.java +++ b/src/main/java/com/minelittlepony/render/plane/PlaneRenderer.java @@ -16,31 +16,54 @@ public class PlaneRenderer extends BasePonyRenderer { super(model, x, y); } - private void addPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale, Face face) { - this.cubeList.add(new ModelPlane(this, textureOffsetX, textureOffsetY, offX, offY, offZ, width, height, depth, scale, face)); + /** + * Flips the Z bit. Any calls to add a plane will be mirrored until this is called again. + */ + public PlaneRenderer flipZ() { + mirrorz = !mirrorz; + return this; } - public void addTopPlane(float offX, float offY, float offZ, int width, int depth, float scale) { - this.addPlane(offX, offY, offZ, width, 0, depth, scale, Face.UP); + + /** + * Flips the Y bit. Any calls to add a plane will be mirrored until this is called again. + */ + public PlaneRenderer flipY() { + mirrory = !mirrory; + return this; } - public void addBottomPlane(float offX, float offY, float offZ, int width, int depth, float scale) { - this.addPlane(offX, offY, offZ, width, 0, depth, scale, Face.DOWN); + @Override + protected PlaneRenderer copySelf() { + return new PlaneRenderer(baseModel, textureOffsetX, textureOffsetY); } - public void addWestPlane(float offX, float offY, float offZ, int height, int depth, float scale) { - this.addPlane(offX, offY, offZ, 0, height, depth, scale, Face.WEST); + private PlaneRenderer addPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale, Face face) { + cubeList.add(new ModelPlane(this, textureOffsetX, textureOffsetY, modelOffsetX + offX, modelOffsetY + offY, modelOffsetZ + offZ, width, height, depth, scale, face)); + return this; } - public void addEastPlane(float offX, float offY, float offZ, int height, int depth, float scale) { - this.addPlane(offX, offY, offZ, 0, height, depth, scale, Face.EAST); + public PlaneRenderer addTopPlane(float offX, float offY, float offZ, int width, int depth, float scale) { + return addPlane(offX, offY, offZ, width, 0, depth, scale, Face.UP); } - public void addFrontPlane(float offX, float offY, float offZ, int width, int height, float scale) { - this.addPlane(offX, offY, offZ, width, height, 0, scale, Face.NORTH); + public PlaneRenderer addBottomPlane(float offX, float offY, float offZ, int width, int depth, float scale) { + return addPlane(offX, offY, offZ, width, 0, depth, scale, Face.DOWN); } - public void addBackPlane(float offX, float offY, float offZ, int width, int height, float scale) { - this.addPlane(offX, offY, offZ, width, height, 0, scale, Face.SOUTH); + public PlaneRenderer addWestPlane(float offX, float offY, float offZ, int height, int depth, float scale) { + return addPlane(offX, offY, offZ, 0, height, depth, scale, Face.WEST); + } + + public PlaneRenderer addEastPlane(float offX, float offY, float offZ, int height, int depth, float scale) { + return addPlane(offX, offY, offZ, 0, height, depth, scale, Face.EAST); + } + + public PlaneRenderer addFrontPlane(float offX, float offY, float offZ, int width, int height, float scale) { + return addPlane(offX, offY, offZ, width, height, 0, scale, Face.NORTH); + } + + public PlaneRenderer addBackPlane(float offX, float offY, float offZ, int width, int height, float scale) { + return addPlane(offX, offY, offZ, width, height, 0, scale, Face.SOUTH); } }