mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 23:48:00 +01:00
Rewrite the plane renderer/horn glow renderer to be more sensible
This commit is contained in:
parent
d6c5e2bd0b
commit
75cb0eb6fc
5 changed files with 186 additions and 73 deletions
|
@ -1,16 +1,19 @@
|
||||||
package com.minelittlepony.render;
|
package com.minelittlepony.render;
|
||||||
|
|
||||||
import net.minecraft.client.model.ModelBase;
|
import net.minecraft.client.model.ModelBase;
|
||||||
|
import net.minecraft.client.model.ModelBox;
|
||||||
import net.minecraft.client.model.ModelRenderer;
|
import net.minecraft.client.model.ModelRenderer;
|
||||||
import net.minecraft.client.model.TextureOffset;
|
import net.minecraft.client.model.TextureOffset;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class BasePonyRenderer<T extends BasePonyRenderer<T>> extends ModelRenderer {
|
public abstract class BasePonyRenderer<T extends BasePonyRenderer<T>> extends ModelRenderer {
|
||||||
|
|
||||||
protected final ModelBase baseModel;
|
protected final ModelBase baseModel;
|
||||||
|
|
||||||
protected int textureOffsetX, textureOffsetY;
|
protected int textureOffsetX, textureOffsetY;
|
||||||
|
|
||||||
|
protected float modelOffsetX, modelOffsetY, modelOffsetZ;
|
||||||
|
|
||||||
public BasePonyRenderer(ModelBase model) {
|
public BasePonyRenderer(ModelBase model) {
|
||||||
super(model);
|
super(model);
|
||||||
baseModel = model;
|
baseModel = model;
|
||||||
|
@ -20,6 +23,11 @@ public class BasePonyRenderer<T extends BasePonyRenderer<T>> extends ModelRender
|
||||||
super(model, x, y);
|
super(model, x, y);
|
||||||
baseModel = model;
|
baseModel = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called to create a new instance of this renderer (used for child renderers)
|
||||||
|
*/
|
||||||
|
protected abstract T copySelf();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T setTextureOffset(int x, int y) {
|
public T setTextureOffset(int x, int y) {
|
||||||
|
@ -29,23 +37,87 @@ public class BasePonyRenderer<T extends BasePonyRenderer<T>> extends ModelRender
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T at(float x, float y, float z) {
|
/**
|
||||||
offsetX = x;
|
* Flips the mirror flag. All faces are mirrored until this is called again.
|
||||||
offsetY = y;
|
*/
|
||||||
offsetZ = z;
|
public T mirror() {
|
||||||
|
return mirror(!mirror);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T mirror(boolean m) {
|
||||||
|
mirror = m;
|
||||||
return (T) this;
|
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 extends ModelRenderer> 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) {
|
public T around(float x, float y, float z) {
|
||||||
setRotationPoint(x, y, z);
|
setRotationPoint(x, y, z);
|
||||||
return (T) this;
|
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
|
@Override
|
||||||
public T addBox(String partName, float offX, float offY, float offZ, int width, int height, int depth) {
|
public T addBox(String partName, float offX, float offY, float offZ, int width, int height, int depth) {
|
||||||
partName = boxName + "." + partName;
|
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);
|
setTextureOffset(tex.textureOffsetX, tex.textureOffsetY).addBox(offX, offY, offZ, width, height, depth);
|
||||||
cubeList.get(cubeList.size() - 1).setBoxName(partName);
|
cubeList.get(cubeList.size() - 1).setBoxName(partName);
|
||||||
|
@ -58,4 +130,29 @@ public class BasePonyRenderer<T extends BasePonyRenderer<T>> extends ModelRender
|
||||||
addBox(offX, offY, offZ, width, height, depth, 0);
|
addBox(offX, offY, offZ, width, height, depth, 0);
|
||||||
return (T) this;
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
20
src/main/java/com/minelittlepony/render/PonyRenderer.java
Normal file
20
src/main/java/com/minelittlepony/render/PonyRenderer.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package com.minelittlepony.render;
|
||||||
|
|
||||||
|
import net.minecraft.client.model.ModelBase;
|
||||||
|
|
||||||
|
public class PonyRenderer extends BasePonyRenderer<PonyRenderer> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package com.minelittlepony.render.plane;
|
package com.minelittlepony.render.plane;
|
||||||
|
|
||||||
enum Face {
|
enum Face {
|
||||||
WEST, EAST,
|
NORTH, SOUTH,
|
||||||
UP, DOWN,
|
UP, DOWN,
|
||||||
NORTH, SOUTH
|
EAST, WEST;
|
||||||
}
|
}
|
|
@ -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) {
|
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);
|
super(renderer, textureX, textureY, x, y, z, w, h, d, scale, false);
|
||||||
|
|
||||||
float x2 = x + w;
|
float x2 = x + w + scale;
|
||||||
float y2 = y + h;
|
float y2 = y + h + scale;
|
||||||
float z2 = z + d;
|
float z2 = z + d + scale;
|
||||||
|
|
||||||
x -= scale;
|
x -= scale;
|
||||||
y -= scale;
|
y -= scale;
|
||||||
z -= scale;
|
z -= scale;
|
||||||
x2 += scale;
|
|
||||||
y2 += scale;
|
|
||||||
z2 += scale;
|
|
||||||
|
|
||||||
if (renderer.mirror) {
|
if (renderer.mirror) {
|
||||||
float v = x2;
|
float v = x2;
|
||||||
x2 = x;
|
x2 = x;
|
||||||
|
@ -47,56 +44,32 @@ public class ModelPlane extends ModelBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
// w:west e:east d:down u:up s:south n:north
|
// w:west e:east d:down u:up s:south n:north
|
||||||
PositionTextureVertex wds = new PositionTextureVertex(x, y, z, 0.0F, 0.0F);
|
PositionTextureVertex wds = new PositionTextureVertex(x , y , z , 0, 0);
|
||||||
PositionTextureVertex eds = new PositionTextureVertex(x2, y, z, 0.0F, 8.0F);
|
PositionTextureVertex eds = new PositionTextureVertex(x2, y , z , 0, 8);
|
||||||
PositionTextureVertex eus = new PositionTextureVertex(x2, y2, z, 8.0F, 8.0F);
|
PositionTextureVertex eus = new PositionTextureVertex(x2, y2, z , 8, 8);
|
||||||
PositionTextureVertex wus = new PositionTextureVertex(x, y2, z, 8.0F, 0.0F);
|
PositionTextureVertex wus = new PositionTextureVertex(x , y2, z , 8, 0);
|
||||||
PositionTextureVertex wdn = new PositionTextureVertex(x, y, z2, 0.0F, 0.0F);
|
PositionTextureVertex wdn = new PositionTextureVertex(x , y , z2, 0, 0);
|
||||||
PositionTextureVertex edn = new PositionTextureVertex(x2, y, z2, 0.0F, 8.0F);
|
PositionTextureVertex edn = new PositionTextureVertex(x2, y , z2, 0, 8);
|
||||||
PositionTextureVertex eun = new PositionTextureVertex(x2, y2, z2, 8.0F, 8.0F);
|
PositionTextureVertex eun = new PositionTextureVertex(x2, y2, z2, 8, 8);
|
||||||
PositionTextureVertex wun = new PositionTextureVertex(x, y2, z2, 8.0F, 0.0F);
|
PositionTextureVertex wun = new PositionTextureVertex(x , y2, z2, 8, 0);
|
||||||
|
|
||||||
if (face == Face.EAST) {
|
if (face == Face.EAST) { // North/Front (was East)
|
||||||
quad = new TexturedQuad(
|
quad = new TexturedQuad(new PositionTextureVertex[]{edn, eds, eus, eun}, textureX, textureY, textureX + d, textureY + h, renderer.textureWidth, renderer.textureHeight);
|
||||||
new PositionTextureVertex[]{edn, eds, eus, eun},
|
|
||||||
textureX, textureY,
|
|
||||||
textureX + d, textureY + h,
|
|
||||||
renderer.textureWidth, renderer.textureHeight);
|
|
||||||
}
|
}
|
||||||
if (face == Face.WEST) {
|
if (face == Face.WEST) { // South/Back (was West)
|
||||||
quad = new TexturedQuad(
|
quad = new TexturedQuad(new PositionTextureVertex[]{wds, wdn, wun, wus}, textureX, textureY, textureX + d, textureY + h, renderer.textureWidth, renderer.textureHeight);
|
||||||
new PositionTextureVertex[]{wds, wdn, wun, wus},
|
|
||||||
textureX, textureY,
|
|
||||||
textureX + d, textureY + h,
|
|
||||||
renderer.textureWidth, renderer.textureHeight);
|
|
||||||
}
|
}
|
||||||
if (face == Face.UP) {
|
if (face == Face.UP) { // Up
|
||||||
quad = new TexturedQuad(
|
quad = new TexturedQuad(new PositionTextureVertex[]{edn, wdn, wds, eds}, textureX, textureY, textureX + w, textureY + d, renderer.textureWidth, renderer.textureHeight);
|
||||||
new PositionTextureVertex[]{edn, wdn, wds, eds},
|
|
||||||
textureX, textureY,
|
|
||||||
textureX + w, textureY + d,
|
|
||||||
renderer.textureWidth, renderer.textureHeight);
|
|
||||||
}
|
}
|
||||||
if (face == Face.DOWN) {
|
if (face == Face.DOWN) { // Down
|
||||||
quad = new TexturedQuad(
|
quad = new TexturedQuad(new PositionTextureVertex[]{eus, wus, wun, eun}, textureX, textureY, textureX + w, textureY + d, renderer.textureWidth, renderer.textureHeight);
|
||||||
new PositionTextureVertex[]{eus, wus, wun, eun},
|
|
||||||
textureX, textureY,
|
|
||||||
textureX + w, textureY + d,
|
|
||||||
renderer.textureWidth, renderer.textureHeight);
|
|
||||||
}
|
}
|
||||||
if (face == Face.SOUTH) {
|
if (face == Face.SOUTH) { // East/Left (was South)
|
||||||
quad = new TexturedQuad(
|
quad = new TexturedQuad(new PositionTextureVertex[]{eds, wds, wus, eus}, textureX, textureY, textureX + w, textureY + h, renderer.textureWidth, renderer.textureHeight);
|
||||||
new PositionTextureVertex[]{eds, wds, wus, eus},
|
|
||||||
textureX, textureY,
|
|
||||||
textureX + w, textureY + h,
|
|
||||||
renderer.textureWidth, renderer.textureHeight);
|
|
||||||
}
|
}
|
||||||
if (face == Face.NORTH) {
|
if (face == Face.NORTH) { // West/Right (was North)
|
||||||
quad = new TexturedQuad(
|
quad = new TexturedQuad(new PositionTextureVertex[]{wdn, edn, eun, wun}, textureX, textureY, textureX + w, textureY + h, renderer.textureWidth, renderer.textureHeight);
|
||||||
new PositionTextureVertex[]{wdn, edn, eun, wun},
|
|
||||||
textureX, textureY,
|
|
||||||
textureX + w, textureY + h,
|
|
||||||
renderer.textureWidth, renderer.textureHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderer.mirror || renderer.mirrory || renderer.mirrorz) {
|
if (renderer.mirror || renderer.mirrory || renderer.mirrorz) {
|
||||||
|
|
|
@ -16,31 +16,54 @@ public class PlaneRenderer extends BasePonyRenderer<PlaneRenderer> {
|
||||||
super(model, x, y);
|
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) {
|
@Override
|
||||||
this.addPlane(offX, offY, offZ, width, 0, depth, scale, Face.DOWN);
|
protected PlaneRenderer copySelf() {
|
||||||
|
return new PlaneRenderer(baseModel, textureOffsetX, textureOffsetY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWestPlane(float offX, float offY, float offZ, int height, int depth, float scale) {
|
private PlaneRenderer addPlane(float offX, float offY, float offZ, int width, int height, int depth, float scale, Face face) {
|
||||||
this.addPlane(offX, offY, offZ, 0, height, depth, scale, Face.WEST);
|
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) {
|
public PlaneRenderer addTopPlane(float offX, float offY, float offZ, int width, int depth, float scale) {
|
||||||
this.addPlane(offX, offY, offZ, 0, height, depth, scale, Face.EAST);
|
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) {
|
public PlaneRenderer addBottomPlane(float offX, float offY, float offZ, int width, int depth, float scale) {
|
||||||
this.addPlane(offX, offY, offZ, width, height, 0, scale, Face.NORTH);
|
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) {
|
public PlaneRenderer addWestPlane(float offX, float offY, float offZ, int height, int depth, float scale) {
|
||||||
this.addPlane(offX, offY, offZ, width, height, 0, scale, Face.SOUTH);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue