mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-23 04:57:58 +01:00
When you're sick and tired of staring at this unreadable code
This commit is contained in:
parent
de88e95ffe
commit
7237480d04
8 changed files with 118 additions and 47 deletions
|
@ -126,8 +126,8 @@ public class ModelPonyArmor extends ModelMobPony {
|
|||
bipedRightArm = new PonyRenderer(this, 0, 16);
|
||||
bipedRightLeg = new PonyRenderer(this, 0, 16);
|
||||
|
||||
bipedLeftArm = new PonyRenderer(this, 0, 16).mirror();
|
||||
bipedLeftLeg = new PonyRenderer(this, 0, 16).mirror();
|
||||
bipedLeftArm = new PonyRenderer(this, 0, 16).flipX();
|
||||
bipedLeftLeg = new PonyRenderer(this, 0, 16).flipX();
|
||||
|
||||
unicornArmRight = new PonyRenderer(this, 0, 16);
|
||||
unicornArmLeft = new PonyRenderer(this, 0, 16);
|
||||
|
@ -175,7 +175,7 @@ public class ModelPonyArmor extends ModelMobPony {
|
|||
.box(-2, -6, -2, 4, 12, 4, stretch);
|
||||
rightLegging.offset(THIRDP_ARM_CENTRE_X, THIRDP_ARM_CENTRE_Y, THIRDP_ARM_CENTRE_Z)
|
||||
.around(-3, yOffset, 0)
|
||||
.mirror().box(-2, -6, -2, 4, 12, 4, stretch);
|
||||
.flipX().box(-2, -6, -2, 4, 12, 4, stretch);
|
||||
}
|
||||
|
||||
protected void syncLegs() {
|
||||
|
|
|
@ -20,7 +20,7 @@ public class PonyElytra extends ModelBase {
|
|||
|
||||
public PonyElytra() {
|
||||
leftWing .box(-10, 0, 0, 10, 20, 2, 1);
|
||||
rightWing.mirror().box( 0, 0, 0, 10, 20, 2, 1);
|
||||
rightWing.flipX().box( 0, 0, 0, 10, 20, 2, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -514,7 +514,7 @@ public class ModelEarthPony extends AbstractPonyModel {
|
|||
.box(-4, -4, -4, 8, 8, 8, stretch)
|
||||
.tex(12, 16)
|
||||
.box(-4, -6, 1, 2, 2, 2, stretch)
|
||||
.mirror()
|
||||
.flipX()
|
||||
.box(2, -6, 1, 2, 2, 2, stretch);
|
||||
|
||||
((PonyRenderer)bipedHeadwear).offset(HEAD_CENTRE_X, HEAD_CENTRE_Y, HEAD_CENTRE_Z)
|
||||
|
|
|
@ -43,7 +43,7 @@ public abstract class AbstractPonyRenderer<T extends AbstractPonyRenderer<T>> ex
|
|||
/**
|
||||
* Flips the mirror flag. All faces are mirrored until this is called again.
|
||||
*/
|
||||
public T mirror() {
|
||||
public T flipX() {
|
||||
return mirror(!mirror);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,75 +1,73 @@
|
|||
package com.minelittlepony.render.plane;
|
||||
|
||||
import net.minecraft.client.model.ModelBox;
|
||||
import net.minecraft.client.model.PositionTextureVertex;
|
||||
import net.minecraft.client.model.TexturedQuad;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ModelPlane extends ModelBox {
|
||||
import com.minelittlepony.util.coordinates.*;
|
||||
|
||||
private TexturedQuad quad;
|
||||
public class ModelPlane extends Box<PlaneRenderer> {
|
||||
|
||||
private Quad quad;
|
||||
|
||||
public boolean hidden = false;
|
||||
|
||||
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);
|
||||
public ModelPlane(PlaneRenderer renderer, int textureX, int textureY, float xMin, float yMin, float zMin, int w, int h, int d, float scale, Face face) {
|
||||
super(renderer, textureX, textureY, xMin, yMin, zMin, w, h, d, scale, false);
|
||||
|
||||
float x2 = x + w + scale;
|
||||
float y2 = y + h + scale;
|
||||
float z2 = z + d + scale;
|
||||
float xMax = xMin + w + scale;
|
||||
float yMax = yMin + h + scale;
|
||||
float zMax = zMin + d + scale;
|
||||
|
||||
x -= scale;
|
||||
y -= scale;
|
||||
z -= scale;
|
||||
xMin -= scale;
|
||||
yMin -= scale;
|
||||
zMin -= scale;
|
||||
|
||||
if (renderer.mirror) {
|
||||
float v = x2;
|
||||
x2 = x;
|
||||
x = v;
|
||||
float v = xMax;
|
||||
xMax = xMin;
|
||||
xMin = v;
|
||||
}
|
||||
|
||||
if (renderer.mirrory) {
|
||||
float v = y2;
|
||||
y2 = y;
|
||||
y = v;
|
||||
float v = yMax;
|
||||
yMax = yMin;
|
||||
yMin = v;
|
||||
}
|
||||
|
||||
if (renderer.mirrorz) {
|
||||
float v = z2;
|
||||
z2 = z;
|
||||
z = v;
|
||||
|
||||
float v = zMax;
|
||||
zMax = zMin;
|
||||
zMin = v;
|
||||
}
|
||||
|
||||
// w:west e:east d:down u:up s:south n:north
|
||||
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);
|
||||
Vertex wds = vert(xMin , yMin , zMin , 0, 0);
|
||||
Vertex eds = vert(xMax, yMin , zMin , 0, 8);
|
||||
Vertex eus = vert(xMax, yMax, zMin , 8, 8);
|
||||
Vertex wus = vert(xMin , yMax, zMin , 8, 0);
|
||||
Vertex wdn = vert(xMin , yMin , zMax, 0, 0);
|
||||
Vertex edn = vert(xMax, yMin , zMax, 0, 8);
|
||||
Vertex eun = vert(xMax, yMax, zMax, 8, 8);
|
||||
Vertex wun = vert(xMin , yMax, zMax, 8, 0);
|
||||
|
||||
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.EAST) {
|
||||
quad = quad(textureX, d, textureY, h, edn, eds, eus, eun);
|
||||
}
|
||||
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.WEST) {
|
||||
quad = quad(textureX, d, textureY, h, wds, wdn, wun, wus);
|
||||
}
|
||||
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.UP) {
|
||||
quad = quad(textureX, w, textureY, h, edn, wdn, wds, eds);
|
||||
}
|
||||
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.DOWN) {
|
||||
quad = quad(textureX, w, textureY, d, eus, wus, wun, eun);
|
||||
}
|
||||
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);
|
||||
quad = quad(textureX, w, textureY, h, eds, wds, wus, eus);
|
||||
}
|
||||
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);
|
||||
quad = quad(textureX, w, textureY, h, wdn, edn, eun, wun);
|
||||
}
|
||||
|
||||
if (renderer.mirror || renderer.mirrory || renderer.mirrorz) {
|
||||
|
|
36
src/main/java/com/minelittlepony/util/coordinates/Box.java
Normal file
36
src/main/java/com/minelittlepony/util/coordinates/Box.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package com.minelittlepony.util.coordinates;
|
||||
|
||||
import net.minecraft.client.model.ModelBox;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
|
||||
public abstract class Box<T extends ModelRenderer> extends ModelBox {
|
||||
|
||||
protected final T parent;
|
||||
|
||||
public Box(T renderer, int texU, int texV, float x, float y, float z, int dx, int dy, int dz, float delta) {
|
||||
super(renderer, texU, texV, x, y, z, dx, dy, dz, delta);
|
||||
parent = renderer;
|
||||
}
|
||||
|
||||
public Box(T renderer, int texU, int texV, float x, float y, float z, int dx, int dy, int dz, float delta, boolean mirror) {
|
||||
super(renderer, texU, texV, x, y, z, dx, dy, dz, delta, mirror);
|
||||
parent = renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new vertex mapping the given (x, y, z) coordinates to a texture offset.
|
||||
*/
|
||||
protected Vertex vert(float x, float y, float z, int texX, int texY) {
|
||||
return new Vertex(x, y, z, texX, texY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new quad with the given spacial vertices.
|
||||
*/
|
||||
protected Quad quad(int startX, int width, int startY, int height, Vertex ...verts) {
|
||||
return new Quad(verts,
|
||||
startX, startY,
|
||||
startX + width, startY + height,
|
||||
parent.textureWidth, parent.textureHeight);
|
||||
}
|
||||
}
|
10
src/main/java/com/minelittlepony/util/coordinates/Quad.java
Normal file
10
src/main/java/com/minelittlepony/util/coordinates/Quad.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package com.minelittlepony.util.coordinates;
|
||||
|
||||
import net.minecraft.client.model.TexturedQuad;
|
||||
|
||||
public class Quad extends TexturedQuad {
|
||||
|
||||
public Quad(Vertex[] vertices, int texcoordU1, int texcoordV1, int texcoordU2, int texcoordV2, float textureWidth, float textureHeight) {
|
||||
super(vertices, texcoordU1, texcoordV1, texcoordU2, texcoordV2, textureWidth, textureHeight);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.minelittlepony.util.coordinates;
|
||||
|
||||
import net.minecraft.client.model.PositionTextureVertex;
|
||||
|
||||
public class Vertex extends PositionTextureVertex {
|
||||
|
||||
public Vertex(float x, float y, float z, int texX, int texY) {
|
||||
super(x, y, z, texX, texY);
|
||||
}
|
||||
|
||||
public Vertex(Vertex old, float texX, float texY) {
|
||||
super(old, texX, texY);
|
||||
}
|
||||
|
||||
public Vertex setTexturePosition(float texX, float texY) {
|
||||
texturePositionX = texX;
|
||||
texturePositionY = texY;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new vertex mapping the given (x, y, z) coordinates to a texture offset.
|
||||
*/
|
||||
public static Vertex vert(float x, float y, float z, int texX, int texY) {
|
||||
return new Vertex(x, y, z, texX, texY);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue