Skip to content

Instantly share code, notes, and snippets.

@killjoy1221
Created August 22, 2016 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killjoy1221/49e1a04a5eb0a170d0c2b2ed044bddc7 to your computer and use it in GitHub Desktop.
Save killjoy1221/49e1a04a5eb0a170d0c2b2ed044bddc7 to your computer and use it in GitHub Desktop.
package com.brohoof.minelittlepony.model;
import com.brohoof.minelittlepony.renderer.PlaneRenderer;
import net.minecraft.client.model.ModelBox;
import net.minecraft.client.model.PositionTextureVertex;
import net.minecraft.client.model.TexturedQuad;
import net.minecraft.client.renderer.VertexBuffer;
public class ModelPlane extends ModelBox {
private TexturedQuad[] quadList;
private final Face face;
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);
this.face = face;
this.quadList = new TexturedQuad[6];
float x2 = x + w;
float y2 = y + h;
float z2 = z + d;
x -= scale;
y -= scale;
z -= scale;
x2 += scale;
y2 += scale;
z2 += scale;
if (renderer.mirror) {
float vert = x2;
x2 = x;
x = vert;
}
if (renderer.mirrory) {
float v = y2;
y2 = y;
y = v;
}
if (renderer.mirrorz) {
float v = z2;
z2 = z;
z = v;
}
// 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);
// east
this.quadList[0] = new TexturedQuad(
new PositionTextureVertex[] { edn, eds, eus, eun },
textureX, textureY,
textureX + d, textureY + h,
renderer.textureWidth, renderer.textureHeight);
// west
this.quadList[1] = new TexturedQuad(
new PositionTextureVertex[] { wds, wdn, wun, wus },
textureX, textureY,
textureX + d, textureY + h,
renderer.textureWidth, renderer.textureHeight);
// down
this.quadList[3] = new TexturedQuad(
new PositionTextureVertex[] { edn, wdn, wds, eds },
textureX, textureY,
textureX + w, textureY + d,
renderer.textureWidth, renderer.textureHeight);
// up
this.quadList[2] = new TexturedQuad(
new PositionTextureVertex[] { eus, wus, wun, eun },
textureX, textureY,
textureX + w, textureY + d,
renderer.textureWidth, renderer.textureHeight);
// south
this.quadList[4] = new TexturedQuad(
new PositionTextureVertex[] { eds, wds, wus, eus },
textureX, textureY,
textureX + w, textureY + h,
renderer.textureWidth, renderer.textureHeight);
// north
this.quadList[5] = 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) {
for (TexturedQuad texturedquad : this.quadList) {
texturedquad.flipFace();
}
}
}
@Override
public void render(VertexBuffer renderer, float scale) {
this.quadList[this.face.ordinal()].draw(renderer, scale);
}
public static enum Face {
EAST,
WEST,
DOWN,
UP,
SOUTH,
NORTH;
}
}
package com.brohoof.minelittlepony.renderer;
import com.brohoof.minelittlepony.model.ModelPlane;
import com.brohoof.minelittlepony.model.ModelPlane.Face;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
public class PlaneRenderer extends ModelRenderer {
public boolean mirrory;
public boolean mirrorz;
private int textureOffsetX;
private int textureOffsetY;
public PlaneRenderer(ModelBase model, int x, int y) {
super(model, x, y);
}
@Override
public ModelRenderer setTextureOffset(int x, int y) {
this.textureOffsetX = x;
this.textureOffsetY = y;
return super.setTextureOffset(x, y);
}
public void addPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale, Face face) {
this.cubeList.add(new ModelPlane(this, this.textureOffsetX, this.textureOffsetY, offX, offY, offZ, width, height, depth, scale, face));
}
public void addTopPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale) {
this.addPlane(offX, offY, offZ, width, height, depth, scale, Face.UP);
}
public void addBottomPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale) {
this.addPlane(offX, offY, offZ, width, height, depth, scale, Face.DOWN);
}
public void addWestPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale) {
this.addPlane(offX, offY, offZ, width, height, depth, scale, Face.WEST);
}
public void addEastPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale) {
this.addPlane(offX, offY, offZ, width, height, depth, scale, Face.EAST);
}
public void addFrontPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale) {
this.addPlane(offX, offY, offZ, width, height, depth, scale, Face.NORTH);
}
public void addBackPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale) {
this.addPlane(offX, offY, offZ, width, height, depth, scale, Face.SOUTH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment