equivalent-exchange-3/ee3_common/com/pahimar/ee3/client/model/ModelAludel.java

119 lines
4.1 KiB
Java
Raw Normal View History

2013-02-18 03:30:11 +01:00
package com.pahimar.ee3.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.Tessellator;
import net.minecraftforge.common.ForgeDirection;
2013-02-18 03:30:11 +01:00
2013-02-19 02:13:24 +01:00
import org.lwjgl.opengl.GL11;
import com.obj.Face;
import com.obj.Group;
import com.obj.WavefrontObject;
import com.pahimar.ee3.lib.Models;
import com.pahimar.ee3.lib.Reference;
2013-02-19 02:13:24 +01:00
import com.pahimar.ee3.lib.Sprites;
import com.pahimar.ee3.tileentity.TileAludel;
2013-02-18 03:30:11 +01:00
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Equivalent-Exchange-3
*
* ModelAludel
*
* @author pahimar
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*
*/
@SideOnly(Side.CLIENT)
2013-02-18 03:30:11 +01:00
public class ModelAludel extends ModelBase {
2013-02-19 02:13:24 +01:00
2013-02-18 03:30:11 +01:00
private float scale;
2013-03-12 04:24:05 +01:00
private WavefrontObject modelAludelOBJ;
2013-02-19 02:13:24 +01:00
public ModelAludel() {
2013-03-12 04:24:05 +01:00
scale = 1F;
modelAludelOBJ = new WavefrontObject(this.getClass().getResource("/" + Models.ALUDEL).getFile());
}
2013-03-12 04:24:05 +01:00
2013-02-18 03:30:11 +01:00
public ModelAludel(float scale) {
2013-03-12 04:24:05 +01:00
2013-02-18 03:30:11 +01:00
this.scale = scale;
2013-03-12 04:24:05 +01:00
modelAludelOBJ = new WavefrontObject(this.getClass().getResource("/" + Models.ALUDEL).getFile());
2013-02-18 03:30:11 +01:00
}
2013-03-12 04:24:05 +01:00
public void render(Tessellator tessellator, float scale) {
2013-03-12 04:24:05 +01:00
if (modelAludelOBJ.getGroups().size() != 0) {
for (Group group : modelAludelOBJ.getGroups()) {
if (group.getFaces().size() != 0) {
for (Face face : group.getFaces()) {
tessellator.startDrawing(GL11.GL_TRIANGLES);
2013-03-12 04:24:05 +01:00
float sumU = 0F;
float sumV = 0F;
2013-03-12 04:24:05 +01:00
for (int i = 0; i < face.getTextures().length; ++i) {
sumU += face.getTextures()[i].getU();
sumV += face.getTextures()[i].getV();
}
2013-03-12 04:24:05 +01:00
for (int i = 0; i < 3; ++i) {
float offsetU = Reference.MODEL_TEXTURE_OFFSET;
float offsetV = Reference.MODEL_TEXTURE_OFFSET;
2013-03-12 04:24:05 +01:00
if (face.getTextures()[i].getU() > sumU / face.getTextures().length) {
offsetU = -offsetU;
}
2013-03-12 04:24:05 +01:00
if (face.getTextures()[i].getV() > sumV / face.getTextures().length) {
offsetV = -offsetV;
}
tessellator.addVertexWithUV(face.getVertices()[i].getX() * scale, face.getVertices()[i].getY() * scale, face.getVertices()[i].getZ() * scale, face.getTextures()[i].getU() + offsetU, face.getTextures()[i].getV() + offsetV);
}
2013-03-12 04:24:05 +01:00
tessellator.draw();
}
}
}
}
}
2013-02-19 02:13:24 +01:00
public void render(TileAludel aludel, double x, double y, double z) {
2013-02-19 02:13:24 +01:00
GL11.glPushMatrix();
2013-02-19 02:13:24 +01:00
GL11.glDisable(GL11.GL_LIGHTING);
correctRotation(x, y, z, aludel.getOrientation());
FMLClientHandler.instance().getClient().renderEngine.func_98187_b(Sprites.MODEL_ALUDEL);
2013-03-12 04:24:05 +01:00
this.render(Tessellator.instance, scale);
2013-02-19 02:13:24 +01:00
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
2013-02-18 03:30:11 +01:00
}
2013-03-12 04:24:05 +01:00
private void correctRotation(double x, double y, double z, ForgeDirection orientation) {
if (orientation == ForgeDirection.NORTH) {
GL11.glTranslated(x + 1, y, z);
GL11.glRotatef(180F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
}
else if (orientation == ForgeDirection.EAST) {
GL11.glTranslated(x + 1, y, z + 1);
GL11.glRotatef(90F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
}
else if (orientation == ForgeDirection.SOUTH) {
GL11.glTranslated(x, y, z + 1);
GL11.glRotatef(0F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
}
else if (orientation == ForgeDirection.WEST) {
GL11.glTranslated(x, y, z);
GL11.glRotatef(-90F, 0F, 1F, 0F);
GL11.glRotatef(-90F, 1F, 0F, 0F);
}
}
2013-02-18 03:30:11 +01:00
}