2014-02-27 12:11:24 +01:00
|
|
|
package resonantinduction.mechanical.energy.turbine;
|
2014-02-02 13:22:04 +01:00
|
|
|
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
2014-02-21 12:48:28 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-02 13:22:04 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-02-21 12:48:28 +01:00
|
|
|
import net.minecraftforge.client.model.AdvancedModelLoader;
|
|
|
|
import net.minecraftforge.client.model.IModelCustom;
|
2014-02-02 13:22:04 +01:00
|
|
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2014-05-14 07:32:00 +02:00
|
|
|
import resonant.api.items.ISimpleItemRenderer;
|
|
|
|
import resonant.lib.render.RenderUtility;
|
2014-02-02 13:22:04 +01:00
|
|
|
import resonantinduction.core.Reference;
|
2014-06-12 11:45:54 +02:00
|
|
|
import resonantinduction.core.ResonantInduction;
|
2014-02-02 13:22:04 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2014-02-21 12:48:28 +01:00
|
|
|
public class RenderWaterTurbine extends TileEntitySpecialRenderer implements ISimpleItemRenderer
|
2014-02-02 13:22:04 +01:00
|
|
|
{
|
2014-02-21 12:48:28 +01:00
|
|
|
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(Reference.MODEL_DIRECTORY + "waterTurbines.obj");
|
|
|
|
|
2014-02-02 13:22:04 +01:00
|
|
|
@Override
|
|
|
|
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
|
|
|
|
{
|
2014-06-07 13:27:35 +02:00
|
|
|
TileTurbine tile = (TileTurbine) t;
|
2014-02-02 13:22:04 +01:00
|
|
|
|
|
|
|
if (tile.getMultiBlock().isPrimary())
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
|
2014-06-12 11:45:54 +02:00
|
|
|
// Determine if the turbine is facing horizontally or vertical.
|
2014-02-21 12:48:28 +01:00
|
|
|
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection());
|
2014-06-12 11:45:54 +02:00
|
|
|
|
|
|
|
// Get the rotation directly from the mechanical node running client side.
|
|
|
|
double mechanicalNodeRenderAngle = tile.mechanicalNode.renderAngle;
|
|
|
|
|
|
|
|
// We need to convert this value into something the model renderer can understand.
|
|
|
|
// Note: Check for NaN and if so then just defaults to zero.
|
|
|
|
float renderAngleInDegrees = 0;
|
|
|
|
if (!Double.isNaN(mechanicalNodeRenderAngle))
|
|
|
|
{
|
|
|
|
renderAngleInDegrees = (float) Math.toDegrees(mechanicalNodeRenderAngle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call to actually rotate the gear model to the specified degree.
|
|
|
|
GL11.glRotatef(renderAngleInDegrees, 0, 1, 0);
|
2014-06-12 11:49:03 +02:00
|
|
|
//ResonantInduction.LOGGER.info("[RenderWaterTurbine] Render Angle: " + renderAngleInDegrees);
|
2014-02-02 13:22:04 +01:00
|
|
|
|
2014-06-12 11:45:54 +02:00
|
|
|
// Determine what type of water turbine model we need to use based on orientation.
|
2014-02-21 12:48:28 +01:00
|
|
|
if (tile.getDirection().offsetY != 0)
|
2014-06-12 11:45:54 +02:00
|
|
|
{
|
2014-03-06 05:13:31 +01:00
|
|
|
renderWaterTurbine(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());
|
2014-06-12 11:45:54 +02:00
|
|
|
}
|
2014-02-02 13:22:04 +01:00
|
|
|
else
|
2014-06-12 11:45:54 +02:00
|
|
|
{
|
2014-03-06 05:13:31 +01:00
|
|
|
renderWaterWheel(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());
|
2014-06-12 11:45:54 +02:00
|
|
|
}
|
2014-02-21 12:48:28 +01:00
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
2014-02-02 13:22:04 +01:00
|
|
|
|
2014-02-28 04:25:51 +01:00
|
|
|
@Override
|
|
|
|
public void renderInventoryItem(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
GL11.glPushMatrix();
|
2014-03-12 11:22:31 +01:00
|
|
|
GL11.glTranslatef(0.5f, 0.5f, 0.5f);
|
2014-03-06 05:13:31 +01:00
|
|
|
renderWaterTurbine(itemStack.getItemDamage(), 1, false);
|
2014-02-28 04:25:51 +01:00
|
|
|
GL11.glPopMatrix();
|
|
|
|
}
|
|
|
|
|
2014-03-06 05:13:31 +01:00
|
|
|
public void renderWaterWheel(int tier, int size, boolean isLarge)
|
2014-02-21 12:48:28 +01:00
|
|
|
{
|
|
|
|
if (isLarge)
|
|
|
|
{
|
2014-03-06 05:13:31 +01:00
|
|
|
GL11.glScalef(0.3f, 1, 0.3f);
|
|
|
|
GL11.glScalef(size * 2 + 1, Math.min(size, 2), size * 2 + 1);
|
|
|
|
|
2014-02-21 12:48:28 +01:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glScalef(1, 1.6f, 1);
|
|
|
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "cobblestone.png");
|
2014-02-23 14:35:29 +01:00
|
|
|
MODEL.renderOnly("bigwheel_endknot", "horizontal_centre_shaft");
|
2014-02-02 13:22:04 +01:00
|
|
|
GL11.glPopMatrix();
|
2014-02-21 12:48:28 +01:00
|
|
|
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glScalef(1, 1.4f, 1);
|
|
|
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "planks_spruce.png");
|
2014-02-23 14:35:29 +01:00
|
|
|
MODEL.renderOnly("bigwheel_supporters");
|
2014-02-28 04:25:51 +01:00
|
|
|
bindTexture(tier);
|
2014-02-23 14:35:29 +01:00
|
|
|
MODEL.renderOnly("bigwheel_scoops", "bigwheel_supportercircle");
|
2014-02-02 13:22:04 +01:00
|
|
|
GL11.glPopMatrix();
|
2014-02-21 12:48:28 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-23 14:35:29 +01:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glScalef(0.7f, 1, 0.7f);
|
2014-02-21 12:48:28 +01:00
|
|
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "cobblestone.png");
|
2014-02-23 14:35:29 +01:00
|
|
|
MODEL.renderOnly("small_waterwheel_endknot");
|
2014-02-28 04:25:51 +01:00
|
|
|
bindTexture(tier);
|
2014-02-23 14:35:29 +01:00
|
|
|
MODEL.renderOnly("small_waterwheel", "small_waterwheel_supporters", "horizontal_centre_shaft");
|
|
|
|
GL11.glPopMatrix();
|
2014-02-21 12:48:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 05:13:31 +01:00
|
|
|
public void renderWaterTurbine(int tier, int size, boolean isLarge)
|
2014-02-21 12:48:28 +01:00
|
|
|
{
|
|
|
|
if (isLarge)
|
|
|
|
{
|
2014-03-06 05:13:31 +01:00
|
|
|
GL11.glScalef(0.3f, 1, 0.3f);
|
|
|
|
GL11.glScalef(size * 2 + 1, Math.min(size, 2), size * 2 + 1);
|
2014-02-28 04:25:51 +01:00
|
|
|
bindTexture(tier);
|
2014-02-21 12:48:28 +01:00
|
|
|
MODEL.renderOnly("turbine_centre");
|
|
|
|
MODEL.renderOnly("turbine_blades");
|
2014-02-02 13:22:04 +01:00
|
|
|
}
|
2014-02-21 12:48:28 +01:00
|
|
|
else
|
|
|
|
{
|
2014-02-23 14:35:29 +01:00
|
|
|
GL11.glPushMatrix();
|
|
|
|
GL11.glScalef(0.9f, 1f, 0.9f);
|
2014-02-28 04:25:51 +01:00
|
|
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "log_oak.png");
|
2014-02-23 14:35:29 +01:00
|
|
|
MODEL.renderOnly("small_waterwheel_endknot");
|
2014-02-28 04:25:51 +01:00
|
|
|
bindTexture(tier);
|
2014-02-23 14:35:29 +01:00
|
|
|
MODEL.renderOnly("small_turbine_blades");
|
|
|
|
GL11.glPopMatrix();
|
2014-02-21 12:48:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:25:51 +01:00
|
|
|
public void bindTexture(int tier)
|
2014-02-21 12:48:28 +01:00
|
|
|
{
|
2014-02-28 04:25:51 +01:00
|
|
|
switch (tier)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "planks_oak.png");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "cobblestone.png");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
RenderUtility.bind(Reference.BLOCK_TEXTURE_DIRECTORY + "iron_block.png");
|
|
|
|
break;
|
|
|
|
}
|
2014-02-02 13:22:04 +01:00
|
|
|
}
|
|
|
|
}
|