Mekanism-tilera-Edition/common/mekanism/client/ModelRendererSelectiveFace.java

169 lines
4.9 KiB
Java
Raw Normal View History

package mekanism.client;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.TextureOffset;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.Tessellator;
import org.bouncycastle.util.Arrays;
import org.lwjgl.opengl.GL11;
public class ModelRendererSelectiveFace
{
public float textureWidth;
public float textureHeight;
public float offsetX;
public float offsetY;
public float offsetZ;
2013-08-01 05:54:08 +02:00
public float rotationPointX;
public float rotationPointY;
public float rotationPointZ;
2013-08-01 05:54:08 +02:00
public float rotateAngleX;
public float rotateAngleY;
public float rotateAngleZ;
2013-08-01 05:54:08 +02:00
public boolean[] connectedFaces;
2013-08-01 05:54:08 +02:00
public boolean mirror;
public boolean showModel;
public boolean isHidden;
2013-08-01 05:54:08 +02:00
public List cubeList;
2013-08-01 05:54:08 +02:00
private int textureOffsetX;
private int textureOffsetY;
2013-08-01 05:54:08 +02:00
private int displayList;
2013-08-01 05:54:08 +02:00
private boolean compiled;
private ModelBase baseModel;
2013-08-01 05:54:08 +02:00
public ModelRendererSelectiveFace(ModelBase modelBase)
{
textureWidth = 64.0F;
textureHeight = 32.0F;
showModel = true;
cubeList = new ArrayList();
2013-08-01 05:54:08 +02:00
baseModel = modelBase;
setTextureSize(modelBase.textureWidth, modelBase.textureHeight);
}
2013-08-01 05:54:08 +02:00
public ModelRendererSelectiveFace(ModelBase modelBase, int par2, int par3)
{
2013-08-01 05:54:08 +02:00
this(modelBase);
setTextureOffset(par2, par3);
}
public ModelRendererSelectiveFace setTextureOffset(int par1, int par2)
{
textureOffsetX = par1;
textureOffsetY = par2;
2013-08-01 05:54:08 +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)
public void render(boolean[] connected, float par1)
{
2013-08-01 05:54:08 +02:00
if(!isHidden)
{
2013-08-01 05:54:08 +02:00
if(showModel)
{
2013-08-01 05:54:08 +02:00
if(!(compiled && Arrays.areEqual(connected, connectedFaces)))
{
connectedFaces = connected;
compileDisplayList(par1);
}
GL11.glTranslatef(offsetX, offsetY, offsetZ);
int i;
2013-08-01 05:54:08 +02:00
if(rotateAngleX == 0.0F && rotateAngleY == 0.0F && rotateAngleZ == 0.0F)
{
2013-08-01 05:54:08 +02:00
if(rotationPointX == 0.0F && rotationPointY == 0.0F && rotationPointZ == 0.0F)
{
GL11.glCallList(displayList);
}
else
{
GL11.glTranslatef(rotationPointX * par1, rotationPointY * par1, rotationPointZ * par1);
GL11.glCallList(displayList);
GL11.glTranslatef(-rotationPointX * par1, -rotationPointY * par1, -rotationPointZ * par1);
}
}
else
{
GL11.glPushMatrix();
GL11.glTranslatef(rotationPointX * par1, rotationPointY * par1, rotationPointZ * par1);
2013-08-01 05:54:08 +02:00
if(rotateAngleZ != 0.0F)
{
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)
{
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)
{
GL11.glRotatef(rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F);
}
GL11.glCallList(displayList);
GL11.glPopMatrix();
}
GL11.glTranslatef(-offsetX, -offsetY, -offsetZ);
}
}
}
@SideOnly(Side.CLIENT)
2013-08-01 05:54:08 +02:00
private void compileDisplayList(float size)
{
displayList = GLAllocation.generateDisplayLists(1);
GL11.glNewList(displayList, GL11.GL_COMPILE);
Tessellator tessellator = Tessellator.instance;
2013-08-01 05:54:08 +02:00
for(int i = 0; i < cubeList.size(); i++)
{
2013-08-01 05:54:08 +02:00
((ModelBoxSelectiveFace)cubeList.get(i)).render(tessellator, connectedFaces, size);
}
GL11.glEndList();
compiled = true;
}
2013-08-01 05:54:08 +02:00
public ModelRendererSelectiveFace setTextureSize(int width, int height)
{
2013-08-01 05:54:08 +02:00
textureWidth = width;
textureHeight = height;
return this;
}
}