Created
January 10, 2015 09:37
-
-
Save marchermans/7de0188a03c4fc175971 to your computer and use it in GitHub Desktop.
FirePit TESR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.Orion.Armory.Client.Renderer.TileEntities; | |
/* | |
* FirePitTEST | |
* Created by: Orion | |
* Created on: 10-10-2014 | |
*/ | |
import com.Orion.Armory.Client.Models.ModelFirePit; | |
import com.Orion.Armory.Common.TileEntity.TileEntityFirePit; | |
import com.Orion.Armory.Util.References; | |
import cpw.mods.fml.common.registry.GameData; | |
import net.minecraft.client.renderer.Tessellator; | |
import net.minecraft.client.renderer.entity.RenderItem; | |
import net.minecraft.client.renderer.entity.RenderManager; | |
import net.minecraft.client.renderer.texture.TextureMap; | |
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; | |
import net.minecraft.entity.item.EntityItem; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.IIcon; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraftforge.common.util.ForgeDirection; | |
import org.lwjgl.opengl.GL11; | |
public class FirePitTESR extends TileEntitySpecialRenderer | |
{ | |
protected final ResourceLocation iOffTexture = new ResourceLocation(References.General.MOD_ID + ":" + "textures/blocks/FirePitTextureOff.png"); | |
protected final ResourceLocation iBurningTexture = new ResourceLocation(References.General.MOD_ID + ":" + "texture/blocks/FirePitTextureOn.png"); | |
protected final ResourceLocation iCoalSurfaceTexture = new ResourceLocation(References.General.MOD_ID + ":" + "textures/blocks/CoalField.png"); | |
public final ModelFirePit iModel = new ModelFirePit(); | |
public final RenderItem iItemRenderer; | |
public FirePitTESR() | |
{ | |
iItemRenderer = new RenderItem() | |
{ | |
@Override | |
public boolean shouldBob() | |
{ | |
return false; | |
} | |
}; | |
iItemRenderer.setRenderManager(RenderManager.instance); | |
} | |
@Override | |
public void renderTileEntityAt(TileEntity pEntity, double pX, double pY, double pZ, float pPartialTickTime) { | |
if (!(pEntity instanceof TileEntityFirePit)) | |
{ | |
return; | |
} | |
TileEntityFirePit tTEFirePit = (TileEntityFirePit) pEntity; | |
boolean tIsBurning = tTEFirePit.isBurning(); | |
GL11.glEnable(GL11.GL_DEPTH_TEST); | |
GL11.glPushMatrix(); | |
GL11.glEnable(GL11.GL_DEPTH_TEST); | |
scaleTranslateRotateAnd(pX, pY, pZ, tTEFirePit.getDirection()); | |
if(!tIsBurning) | |
{ | |
this.bindTexture(iOffTexture); | |
iModel.renderPart("Furnace_Cube"); | |
this.bindTexture(iCoalSurfaceTexture); | |
iModel.renderPart("CoalSurface_Plane"); | |
} | |
else | |
{ | |
this.bindTexture(iOffTexture); | |
iModel.renderPart("Furnace_Cube"); | |
} | |
GL11.glPopMatrix(); | |
GL11.glPushMatrix(); | |
GL11.glDisable(GL11.GL_BLEND); | |
GL11.glEnable(GL11.GL_DEPTH_TEST); | |
//TODO: Render the front tools. | |
EntityItem gostItem = new EntityItem(tTEFirePit.getWorldObj()); | |
gostItem.hoverStart = 0.0F; | |
gostItem.setEntityItemStack(new ItemStack(GameData.getItemRegistry().getObject("iron_pickaxe"))); | |
translateGhostItemByOrientation(gostItem.getEntityItem(), pX, pY, pZ, tTEFirePit.getDirection()); | |
GL11.glEnable(GL11.GL_DEPTH_TEST); | |
RenderItem(gostItem, pX, pY, pZ); | |
GL11.glPopMatrix(); | |
} | |
private void scaleTranslateRotateAnd(double x, double y, double z, ForgeDirection orientation) | |
{ | |
if (orientation == ForgeDirection.NORTH) | |
{ | |
GL11.glTranslated(x+1, y, z+1); | |
GL11.glRotatef(180F, 0F, 1F, 0F); | |
} | |
else if (orientation == ForgeDirection.EAST) | |
{ | |
GL11.glTranslated(x, y, z + 1); | |
GL11.glRotatef(90F, 0F, 1F, 0F); | |
} | |
else if (orientation == ForgeDirection.SOUTH) | |
{ | |
GL11.glTranslated(x, y, z); | |
} | |
else if (orientation == ForgeDirection.WEST) | |
{ | |
GL11.glTranslated(x +1, y, z); | |
GL11.glRotatef(-90F, 0F, 1F, 0F); | |
} | |
} | |
private void translateGhostItemByOrientation(ItemStack ghostItemStack, double x, double y, double z, ForgeDirection forgeDirection) | |
{ | |
if (ghostItemStack != null) | |
{ | |
if (forgeDirection == ForgeDirection.NORTH) | |
{ | |
GL11.glTranslatef((float) x + 0.35F, (float) y + 0.7F, (float) z - 0.015625F); | |
GL11.glScalef(0.32F, 0.32F, 0.5F); | |
return; | |
} | |
else if(forgeDirection == ForgeDirection.SOUTH) | |
{ | |
GL11.glTranslatef((float) x + 0.44F, (float) y + 0.55F, (float) z + 1.015625F); | |
GL11.glRotatef(180F, 0F, 1F, 0F); | |
GL11.glScalef(0.32F, 0.32F, 0.5F); | |
return; | |
} | |
else if(forgeDirection == ForgeDirection.EAST) | |
{ | |
GL11.glTranslatef((float) x + 0.3F, (float) y + 0.4F, (float) z + 0.5F); | |
GL11.glRotatef(90F, 0F, 1F, 0F); | |
GL11.glScalef(0.32F, 0.32F, 0.5F); | |
return; | |
} | |
else if (forgeDirection == ForgeDirection.WEST) | |
{ | |
GL11.glTranslatef((float) x + 0.70F, (float) y + 0.4F, (float) z + 0.5F); | |
GL11.glRotatef(-90F, 0F, 1F, 0F); | |
GL11.glScalef(0.32F, 0.32F, 0.5F); | |
return; | |
} | |
} | |
} | |
private void RenderItem(EntityItem pGostEntity, double pX, double pY, double pZ) | |
{ | |
this.bindTexture(TextureMap.locationItemsTexture); | |
Tessellator tTessallator = Tessellator.instance; | |
IIcon icIcon = pGostEntity.getEntityItem().getIconIndex(); | |
double iMaxU = icIcon.getMaxU(); | |
double iMaxV = icIcon.getMaxV(); | |
double iMinU = icIcon.getMinU(); | |
double iMinV = icIcon.getMinV(); | |
double iIconHeight = icIcon.getIconHeight(); | |
double iIconWidth = icIcon.getIconWidth(); | |
double iThickness = 0.0625F; | |
tTessallator.startDrawingQuads(); | |
tTessallator.setNormal(0.0F, 0.0F, 1.0F); | |
tTessallator.addVertexWithUV(0.0D, 0.0D, 0.0D, (double)iMaxU, (double)iMaxV); | |
tTessallator.addVertexWithUV(1.0D, 0.0D, 0.0D, (double)iMinU, (double)iMaxV); | |
tTessallator.addVertexWithUV(1.0D, 1.0D, 0.0D, (double) iMinU, (double) iMinV); | |
tTessallator.addVertexWithUV(0.0D, 1.0D, 0.0D, (double) iMaxU, (double) iMinV); | |
tTessallator.draw(); | |
tTessallator.startDrawingQuads(); | |
tTessallator.setNormal(0.0F, 0.0F, -1.0F); | |
tTessallator.addVertexWithUV(0.0D, 1.0D, (double)(0.0F - iThickness), (double)iMaxU, (double)iMinV); | |
tTessallator.addVertexWithUV(1.0D, 1.0D, (double)(0.0F - iThickness), (double)iMinU, (double)iMinV); | |
tTessallator.addVertexWithUV(1.0D, 0.0D, (double)(0.0F - iThickness), (double)iMinU, (double)iMaxV); | |
tTessallator.addVertexWithUV(0.0D, 0.0D, (double)(0.0F - iThickness), (double)iMaxU, (double)iMaxV); | |
tTessallator.draw(); | |
float f5 = (float) (0.5F * (iMaxU - iMinU) / (float)iIconHeight); | |
float f6 = (float) (0.5F * (iMaxV - iMinV) / (float)iIconWidth); | |
tTessallator.startDrawingQuads(); | |
tTessallator.setNormal(-1.0F, 0.0F, 0.0F); | |
int k; | |
float f7; | |
float f8; | |
for (k = 0; k < iIconHeight; ++k) | |
{ | |
f7 = (float)k / (float)iIconHeight; | |
f8 = (float) (iMaxU + (iMinU - iMaxU) * f7 - f5); | |
tTessallator.addVertexWithUV((double)f7, 0.0D, (double)(0.0F - iThickness), (double)f8, (double)iMaxV); | |
tTessallator.addVertexWithUV((double)f7, 0.0D, 0.0D, (double)f8, (double)iMaxV); | |
tTessallator.addVertexWithUV((double)f7, 1.0D, 0.0D, (double)f8, (double)iMinV); | |
tTessallator.addVertexWithUV((double)f7, 1.0D, (double)(0.0F - iThickness), (double)f8, (double)iMinV); | |
} | |
tTessallator.draw(); | |
tTessallator.startDrawingQuads(); | |
tTessallator.setNormal(1.0F, 0.0F, 0.0F); | |
float f9; | |
for (k = 0; k < iIconHeight; ++k) | |
{ | |
f7 = (float)k / (float)iIconHeight; | |
f8 = (float) (iMaxU + (iMinU - iMaxU) * f7 - f5); | |
f9 = f7 + 1.0F / (float)iIconHeight; | |
tTessallator.addVertexWithUV((double)f9, 1.0D, (double)(0.0F - iThickness), (double)f8, (double)iMinV); | |
tTessallator.addVertexWithUV((double)f9, 1.0D, 0.0D, (double)f8, (double)iMinV); | |
tTessallator.addVertexWithUV((double)f9, 0.0D, 0.0D, (double)f8, (double)iMaxV); | |
tTessallator.addVertexWithUV((double)f9, 0.0D, (double)(0.0F - iThickness), (double)f8, (double)iMaxV); | |
} | |
tTessallator.draw(); | |
tTessallator.startDrawingQuads(); | |
tTessallator.setNormal(0.0F, 1.0F, 0.0F); | |
for (k = 0; k < iIconWidth; ++k) | |
{ | |
f7 = (float)k / (float)iIconWidth; | |
f8 = (float) (iMaxV + (iMinV - iMaxV) * f7 - f6); | |
f9 = f7 + 1.0F / (float)iIconWidth; | |
tTessallator.addVertexWithUV(0.0D, (double)f9, 0.0D, (double)iMaxU, (double)f8); | |
tTessallator.addVertexWithUV(1.0D, (double)f9, 0.0D, (double)iMinU, (double)f8); | |
tTessallator.addVertexWithUV(1.0D, (double)f9, (double)(0.0F - iThickness), (double)iMinU, (double)f8); | |
tTessallator.addVertexWithUV(0.0D, (double)f9, (double)(0.0F - iThickness), (double)iMaxU, (double)f8); | |
} | |
tTessallator.draw(); | |
tTessallator.startDrawingQuads(); | |
tTessallator.setNormal(0.0F, -1.0F, 0.0F); | |
for (k = 0; k < iIconWidth; ++k) | |
{ | |
f7 = (float)k / (float)iIconWidth; | |
f8 = (float) (iMaxV + (iMinV - iMaxV) * f7 - f6); | |
tTessallator.addVertexWithUV(1.0D, (double)f7, 0.0D, (double)iMinU, (double)f8); | |
tTessallator.addVertexWithUV(0.0D, (double)f7, 0.0D, (double)iMaxU, (double)f8); | |
tTessallator.addVertexWithUV(0.0D, (double)f7, (double)(0.0F - iThickness), (double)iMaxU, (double)f8); | |
tTessallator.addVertexWithUV(1.0D, (double)f7, (double)(0.0F - iThickness), (double)iMinU, (double)f8); | |
} | |
tTessallator.draw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment