Finished mechanical piston render and model

This commit is contained in:
Calclavia 2014-04-18 18:14:40 +08:00
parent 2be853c78c
commit e34ef8e294
8 changed files with 39 additions and 29 deletions

View file

@ -1,23 +1,23 @@
package resonantinduction.mechanical.process.crusher; package resonantinduction.mechanical.process.crusher;
import calclavia.lib.render.RenderUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom; import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.common.ForgeDirection;
import org.apache.commons.lang3.ArrayUtils;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference; import resonantinduction.core.Reference;
import calclavia.lib.render.RenderUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class RenderMechanicalPiston extends TileEntitySpecialRenderer public class RenderMechanicalPiston extends TileEntitySpecialRenderer
{ {
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(Reference.MODEL_DIRECTORY + "rejector.tcn"); public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(Reference.MODEL_DIRECTORY + "piston/mechanicalPiston.tcn");
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "rejector.png"); public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "piston/mechanicalPiston_iron.png");
@Override @Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)
@ -25,43 +25,53 @@ public class RenderMechanicalPiston extends TileEntitySpecialRenderer
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5); GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
TileMechanicalPiston tile = (TileMechanicalPiston) tileEntity; TileMechanicalPiston tile = (TileMechanicalPiston) tileEntity;
GL11.glRotated(-90, 0, 1, 0); GL11.glRotated(-90, 0, 1, 0);
GL11.glRotated(180, 0, 0, 1);
if (tile.worldObj != null) if (tile.worldObj != null)
{
RenderUtility.rotateBlockBasedOnDirection(tile.getDirection()); RenderUtility.rotateBlockBasedOnDirection(tile.getDirection());
}
RenderUtility.bind(TEXTURE); RenderUtility.bind(TEXTURE);
// Angle in radians of the rotor. // Angle in radians of the rotor.
float angle = (float) tile.mechanicalNode.angle; double angle = tile.mechanicalNode.angle;
float radius = 0.5f; final String[] staticParts = { "baseRing", "leg1", "leg2", "leg3", "leg4", "connector", "basePlate", "basePlateTop", "connectorBar", "centerPiston" };
// Length of piston arm final String[] shaftParts = { "topPlate", "outerPiston" };
float length = 0.8f;
double beta = Math.asin((radius * Math.sin(angle)) / (length / 2));
/**
* Render Piston Rod
*/
GL11.glPushMatrix();
double pistonTranslateX = 2 * length * Math.cos(beta);
double pistonTranslateY = 2 * length * Math.sin(beta);
GL11.glTranslated(0, pistonTranslateY, pistonTranslateX);
GL11.glRotated(-Math.toDegrees(beta), 1, 0, 0);
// MODEL.renderOnly("PistonShaft", "PistonFace", "PistonFace2");
GL11.glPopMatrix();
/** /**
* Render Piston Rotor * Render Piston Rotor
*/ */
GL11.glPushMatrix(); GL11.glPushMatrix();
// TODO: Temporary, unless new models come out. GL11.glRotated(-Math.toDegrees(angle), 0, 0, 1);
GL11.glTranslated(0, 0, (0.06 * Math.sin(angle)) - 0.01); MODEL.renderAllExcept(ArrayUtils.addAll(shaftParts, staticParts));
MODEL.renderOnly("PistonShaft", "PistonFace", "PistonFace2");
GL11.glPopMatrix(); GL11.glPopMatrix();
MODEL.renderAllExcept("PistonShaft", "PistonFace", "PistonFace2"); /**
* Render Piston Shaft
*/
GL11.glPushMatrix();
if (tile.worldObj != null)
{
ForgeDirection dir = tile.getDirection();
if (tile.world().isAirBlock(tile.x() + dir.offsetX, tile.y() + dir.offsetY, tile.z() + dir.offsetZ))
{
GL11.glTranslated(0, 0, (0.4 * Math.sin(angle)) - 0.5);
}
else
{
GL11.glTranslated(0, 0, (0.06 * Math.sin(angle)) - 0.03);
}
}
MODEL.renderOnly(shaftParts);
GL11.glPopMatrix();
MODEL.renderOnly(staticParts);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB