2013-08-27 00:49:32 +02:00
|
|
|
package mekanism.client.model;
|
2013-08-01 00:22:48 +02:00
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-08-27 00:49:32 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
import java.util.ArrayList;
|
2013-08-01 03:16:34 +02:00
|
|
|
import java.util.HashMap;
|
2013-08-01 00:22:48 +02:00
|
|
|
import java.util.List;
|
2013-08-01 03:16:34 +02:00
|
|
|
import java.util.Map;
|
2013-08-01 00:22:48 +02:00
|
|
|
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.client.render.MekanismRenderer.BooleanArray;
|
|
|
|
import mekanism.client.render.MekanismRenderer.DisplayInteger;
|
2013-08-01 00:22:48 +02:00
|
|
|
import net.minecraft.client.model.ModelBase;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
public class ModelRendererSelectiveFace
|
|
|
|
{
|
|
|
|
public float textureWidth;
|
|
|
|
public float textureHeight;
|
2013-08-01 06:08:45 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
public float offsetX;
|
|
|
|
public float offsetY;
|
|
|
|
public float offsetZ;
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
public float rotationPointX;
|
|
|
|
public float rotationPointY;
|
|
|
|
public float rotationPointZ;
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
public float rotateAngleX;
|
|
|
|
public float rotateAngleY;
|
|
|
|
public float rotateAngleZ;
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
public boolean mirror;
|
|
|
|
public boolean showModel;
|
|
|
|
public boolean isHidden;
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 03:16:34 +02:00
|
|
|
public List<ModelBoxSelectiveFace> cubeList = new ArrayList<ModelBoxSelectiveFace>();
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
private int textureOffsetX;
|
|
|
|
private int textureOffsetY;
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
private ModelBase baseModel;
|
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
private Map<BooleanArray, DisplayInteger> displayLists = new HashMap<BooleanArray, DisplayInteger>();
|
2013-08-01 00:22:48 +02:00
|
|
|
|
|
|
|
|
2013-08-01 03:16:34 +02:00
|
|
|
public ModelRendererSelectiveFace(ModelBase modelBase)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
|
|
|
textureWidth = 64.0F;
|
|
|
|
textureHeight = 32.0F;
|
|
|
|
showModel = true;
|
2013-08-01 03:16:34 +02:00
|
|
|
baseModel = modelBase;
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 03:16:34 +02:00
|
|
|
setTextureSize(modelBase.textureWidth, modelBase.textureHeight);
|
2013-08-01 00:22:48 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 03:16:34 +02:00
|
|
|
public ModelRendererSelectiveFace(ModelBase modelBase, int offsetX, int offsetY)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-01 03:16:34 +02:00
|
|
|
this(modelBase);
|
|
|
|
setTextureOffset(offsetX, offsetY);
|
2013-08-01 00:22:48 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 03:16:34 +02:00
|
|
|
public ModelRendererSelectiveFace setTextureOffset(int offsetX, int offsetY)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-01 03:16:34 +02:00
|
|
|
textureOffsetX = offsetX;
|
|
|
|
textureOffsetY = offsetY;
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ModelRendererSelectiveFace addBox(float minX, float minY, float minZ, int sizeX, int sizeY, int sizeZ)
|
|
|
|
{
|
|
|
|
cubeList.add(new ModelBoxSelectiveFace(this, textureOffsetX, textureOffsetY, minX, minY, minZ, sizeX, sizeY, sizeZ, 0.0F));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRotationPoint(float pointX, float pointY, float pointZ)
|
|
|
|
{
|
|
|
|
rotationPointX = pointX;
|
|
|
|
rotationPointY = pointY;
|
|
|
|
rotationPointZ = pointZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-08-01 03:16:34 +02:00
|
|
|
public void render(boolean[] dontRender, float scaleFactor)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-01 05:54:08 +02:00
|
|
|
if(!isHidden)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-01 05:54:08 +02:00
|
|
|
if(showModel)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
DisplayInteger currentDisplayList = displayLists.get(new BooleanArray(dontRender));
|
2013-08-01 06:08:45 +02:00
|
|
|
|
|
|
|
if(currentDisplayList == null)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-01 03:16:34 +02:00
|
|
|
currentDisplayList = compileDisplayList(dontRender, scaleFactor);
|
2013-08-01 00:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glTranslatef(offsetX, offsetY, offsetZ);
|
2013-08-01 06:08:45 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
int i;
|
|
|
|
|
2013-08-01 05:54:08 +02:00
|
|
|
if(rotateAngleX == 0.0F && rotateAngleY == 0.0F && rotateAngleZ == 0.0F)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-01 05:54:08 +02:00
|
|
|
if(rotationPointX == 0.0F && rotationPointY == 0.0F && rotationPointZ == 0.0F)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
currentDisplayList.render();
|
2013-08-01 00:22:48 +02:00
|
|
|
}
|
2013-08-01 06:08:45 +02:00
|
|
|
else {
|
2013-08-01 03:16:34 +02:00
|
|
|
GL11.glTranslatef(rotationPointX * scaleFactor, rotationPointY * scaleFactor, rotationPointZ * scaleFactor);
|
2013-08-02 00:14:26 +02:00
|
|
|
currentDisplayList.render();
|
2013-08-01 03:16:34 +02:00
|
|
|
GL11.glTranslatef(-rotationPointX * scaleFactor, -rotationPointY * scaleFactor, -rotationPointZ * scaleFactor);
|
2013-08-01 00:22:48 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-23 03:13:23 +02:00
|
|
|
else {
|
2013-08-01 00:22:48 +02:00
|
|
|
GL11.glPushMatrix();
|
2013-08-01 03:16:34 +02:00
|
|
|
GL11.glTranslatef(rotationPointX * scaleFactor, rotationPointY * scaleFactor, rotationPointZ * scaleFactor);
|
2013-08-01 00:22:48 +02:00
|
|
|
|
2013-08-01 05:54:08 +02:00
|
|
|
if(rotateAngleZ != 0.0F)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
|
|
|
GL11.glRotatef(rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F);
|
|
|
|
}
|
|
|
|
|
2013-08-01 05:54:08 +02:00
|
|
|
if(rotateAngleY != 0.0F)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
|
|
|
GL11.glRotatef(rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F);
|
|
|
|
}
|
|
|
|
|
2013-08-01 05:54:08 +02:00
|
|
|
if(rotateAngleX != 0.0F)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
|
|
|
GL11.glRotatef(rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
currentDisplayList.render();
|
2013-08-01 00:22:48 +02:00
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
GL11.glTranslatef(-offsetX, -offsetY, -offsetZ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-08-02 00:14:26 +02:00
|
|
|
private DisplayInteger compileDisplayList(boolean[] dontRender, float scaleFactor)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-02 00:14:26 +02:00
|
|
|
DisplayInteger displayList = DisplayInteger.createAndStart();
|
2013-08-01 00:22:48 +02:00
|
|
|
Tessellator tessellator = Tessellator.instance;
|
|
|
|
|
2013-08-01 06:08:45 +02:00
|
|
|
for(int i = 0; i < cubeList.size(); ++i)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-01 03:16:34 +02:00
|
|
|
cubeList.get(i).render(tessellator, dontRender, scaleFactor);
|
2013-08-01 00:22:48 +02:00
|
|
|
}
|
|
|
|
|
2013-08-02 00:14:26 +02:00
|
|
|
displayList.endList();
|
2013-08-01 03:16:34 +02:00
|
|
|
displayLists.put(new BooleanArray(dontRender), displayList);
|
2013-08-01 06:08:45 +02:00
|
|
|
|
2013-08-01 03:16:34 +02:00
|
|
|
return displayList;
|
2013-08-01 00:22:48 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 03:16:34 +02:00
|
|
|
public ModelRendererSelectiveFace setTextureSize(int sizeX, int sizeY)
|
2013-08-01 00:22:48 +02:00
|
|
|
{
|
2013-08-01 06:08:45 +02:00
|
|
|
textureWidth = sizeX;
|
|
|
|
textureHeight = sizeY;
|
2013-08-01 05:54:08 +02:00
|
|
|
|
2013-08-01 00:22:48 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|