2012-04-25 03:17:23 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2012 cpw.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the GNU Public License v3.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.gnu.org/licenses/gpl.html
|
2012-07-08 20:28:25 +02:00
|
|
|
*
|
2012-04-25 03:17:23 +02:00
|
|
|
* Contributors:
|
2012-07-08 08:24:48 +02:00
|
|
|
* cpw - initial API and implementation
|
2012-04-25 03:17:23 +02:00
|
|
|
******************************************************************************/
|
|
|
|
package cpw.mods.ironchest.client;
|
|
|
|
|
2012-07-08 08:24:48 +02:00
|
|
|
import static org.lwjgl.opengl.GL11.GL_COMPILE_AND_EXECUTE;
|
2012-04-25 03:17:23 +02:00
|
|
|
import static org.lwjgl.opengl.GL11.glColor4f;
|
|
|
|
import static org.lwjgl.opengl.GL11.glDisable;
|
|
|
|
import static org.lwjgl.opengl.GL11.glEnable;
|
2012-06-25 21:11:13 +02:00
|
|
|
import static org.lwjgl.opengl.GL11.glEndList;
|
|
|
|
import static org.lwjgl.opengl.GL11.glGenLists;
|
|
|
|
import static org.lwjgl.opengl.GL11.glCallList;
|
|
|
|
import static org.lwjgl.opengl.GL11.glNewList;
|
2012-04-25 03:17:23 +02:00
|
|
|
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
|
|
|
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
|
|
|
import static org.lwjgl.opengl.GL11.glRotatef;
|
|
|
|
import static org.lwjgl.opengl.GL11.glScalef;
|
|
|
|
import static org.lwjgl.opengl.GL11.glTranslatef;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2012-06-25 21:11:13 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
2012-04-25 03:17:23 +02:00
|
|
|
|
|
|
|
import net.minecraft.src.Block;
|
|
|
|
import net.minecraft.src.EntityItem;
|
|
|
|
import net.minecraft.src.Item;
|
|
|
|
import net.minecraft.src.ItemStack;
|
|
|
|
import net.minecraft.src.ModelChest;
|
|
|
|
import net.minecraft.src.RenderBlocks;
|
|
|
|
import net.minecraft.src.Tessellator;
|
|
|
|
import net.minecraft.src.TileEntity;
|
|
|
|
import net.minecraft.src.TileEntitySpecialRenderer;
|
|
|
|
import net.minecraft.src.forge.ForgeHooksClient;
|
|
|
|
import net.minecraft.src.forge.IItemRenderer;
|
|
|
|
import net.minecraft.src.forge.MinecraftForgeClient;
|
|
|
|
import cpw.mods.ironchest.IronChestType;
|
2012-07-08 20:28:25 +02:00
|
|
|
import cpw.mods.ironchest.MappableItemStackWrapper;
|
2012-04-25 03:17:23 +02:00
|
|
|
import cpw.mods.ironchest.TileEntityIronChest;
|
2012-07-08 20:28:25 +02:00
|
|
|
import cpw.mods.ironchest.mod_IronChest;
|
2012-04-25 03:17:23 +02:00
|
|
|
|
|
|
|
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
|
2012-07-08 20:28:25 +02:00
|
|
|
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
|
2012-07-08 08:24:48 +02:00
|
|
|
|
2012-04-25 03:17:23 +02:00
|
|
|
private Random random;
|
2012-07-08 08:24:48 +02:00
|
|
|
|
2012-04-25 03:17:23 +02:00
|
|
|
private RenderBlocks renderBlocks;
|
|
|
|
|
2012-07-08 20:28:25 +02:00
|
|
|
private static float[][] shifts = {
|
|
|
|
{ 0.3F, 0.45F, 0.3F },
|
|
|
|
{ 0.7F, 0.45F, 0.3F },
|
|
|
|
{ 0.3F, 0.45F, 0.7F },
|
|
|
|
{ 0.7F, 0.45F, 0.7F },
|
|
|
|
{ 0.3F, 0.1F, 0.3F },
|
|
|
|
{ 0.7F, 0.1F, 0.3F },
|
|
|
|
{ 0.3F, 0.1F, 0.7F },
|
|
|
|
{ 0.7F, 0.1F, 0.7F },
|
|
|
|
{ 0.5F, 0.32F, 0.5F },
|
|
|
|
};
|
2012-04-25 03:17:23 +02:00
|
|
|
|
|
|
|
public TileEntityIronChestRenderer() {
|
|
|
|
model = new ModelChest();
|
|
|
|
random = new Random();
|
|
|
|
renderBlocks = new RenderBlocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
|
2012-07-08 08:24:48 +02:00
|
|
|
if (tile == null) {
|
2012-04-25 03:17:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int facing = 3;
|
2012-07-08 08:24:48 +02:00
|
|
|
IronChestType type = tile.getType();
|
2012-04-25 03:17:23 +02:00
|
|
|
if (tile != null && tile.worldObj != null) {
|
|
|
|
facing = tile.getFacing();
|
2012-07-08 08:24:48 +02:00
|
|
|
type = tile.getType();
|
|
|
|
int typ = tile.worldObj.getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
|
|
|
|
type = IronChestType.values()[typ];
|
2012-04-25 03:17:23 +02:00
|
|
|
}
|
|
|
|
bindTextureByName(type.getModelTexture());
|
|
|
|
glPushMatrix();
|
|
|
|
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
|
|
|
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
|
|
|
|
glScalef(1.0F, -1F, -1F);
|
|
|
|
glTranslatef(0.5F, 0.5F, 0.5F);
|
|
|
|
int k = 0;
|
|
|
|
if (facing == 2) {
|
|
|
|
k = 180;
|
|
|
|
}
|
|
|
|
if (facing == 3) {
|
|
|
|
k = 0;
|
|
|
|
}
|
|
|
|
if (facing == 4) {
|
|
|
|
k = 90;
|
|
|
|
}
|
|
|
|
if (facing == 5) {
|
|
|
|
k = -90;
|
|
|
|
}
|
|
|
|
glRotatef(k, 0.0F, 1.0F, 0.0F);
|
|
|
|
glTranslatef(-0.5F, -0.5F, -0.5F);
|
|
|
|
float lidangle = tile.prevLidAngle + (tile.lidAngle - tile.prevLidAngle) * partialTick;
|
|
|
|
lidangle = 1.0F - lidangle;
|
|
|
|
lidangle = 1.0F - lidangle * lidangle * lidangle;
|
|
|
|
model.chestLid.rotateAngleX = -((lidangle * 3.141593F) / 2.0F);
|
|
|
|
// Render the chest itself
|
|
|
|
model.renderAll();
|
|
|
|
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
|
|
|
glPopMatrix();
|
|
|
|
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
if (type.isTransparent()) {
|
|
|
|
random.setSeed(254L);
|
|
|
|
float shiftX;
|
|
|
|
float shiftY;
|
|
|
|
float shiftZ;
|
|
|
|
int shift = 0;
|
|
|
|
float spread = 0.1F;
|
|
|
|
float blockScale = 0.15F;
|
|
|
|
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
|
|
|
|
if (tile.getTopItemStacks()[1] == null) {
|
|
|
|
shift = 8;
|
|
|
|
blockScale = 0.2F;
|
|
|
|
spread = 0.22F;
|
|
|
|
}
|
|
|
|
glPushMatrix();
|
|
|
|
glDisable(2896 /* GL_LIGHTING */);
|
|
|
|
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
|
|
|
glTranslatef((float) x, (float) y, (float) z);
|
2012-07-08 08:24:48 +02:00
|
|
|
EntityItem customitem = new EntityItem(tileEntityRenderer.worldObj);
|
2012-04-25 03:17:23 +02:00
|
|
|
for (ItemStack item : tile.getTopItemStacks()) {
|
|
|
|
if (shift > shifts.length) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (item == null) {
|
|
|
|
shift++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
shiftX = shifts[shift][0];
|
|
|
|
shiftY = shifts[shift][1];
|
|
|
|
shiftZ = shifts[shift][2];
|
|
|
|
shift++;
|
|
|
|
float localScale = blockScale;
|
2012-07-08 08:24:48 +02:00
|
|
|
if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null) {
|
2012-04-25 03:17:23 +02:00
|
|
|
int j = Block.blocksList[item.itemID].getRenderType();
|
|
|
|
if (j == 1 || j == 19 || j == 12 || j == 2) {
|
|
|
|
localScale = 2 * blockScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(shiftX, shiftY, shiftZ);
|
|
|
|
glScalef(localScale, localScale, localScale);
|
|
|
|
for (int miniBlocks = 0; miniBlocks < (item.stackSize / 32) + 1; miniBlocks++) {
|
|
|
|
glPushMatrix();
|
|
|
|
glRotatef(timeD, 0.0F, 1.0F, 0.0F);
|
|
|
|
if (miniBlocks > 0) {
|
|
|
|
float minishiftX = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
|
|
|
|
float minishiftY = ((random.nextFloat() * 2.0F - 1.0F) * spread * 0.9F) / localScale;
|
|
|
|
float minishiftZ = ((random.nextFloat() * 2.0F - 1.0F) * spread) / localScale;
|
|
|
|
glTranslatef(minishiftX, minishiftY, minishiftZ);
|
|
|
|
}
|
2012-07-08 20:28:25 +02:00
|
|
|
MappableItemStackWrapper mis = new MappableItemStackWrapper(item);
|
|
|
|
if (!mod_IronChest.CACHE_RENDER || !renderList.containsKey(mis)) { // Added support for using only old system.
|
|
|
|
if (mod_IronChest.CACHE_RENDER) {
|
2012-07-08 08:24:48 +02:00
|
|
|
int render = glGenLists(1);
|
2012-07-08 20:28:25 +02:00
|
|
|
renderList.put(mis, render);
|
2012-07-08 08:24:48 +02:00
|
|
|
glNewList(render, GL_COMPILE_AND_EXECUTE);
|
|
|
|
}
|
2012-07-08 20:28:25 +02:00
|
|
|
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, IItemRenderer.ItemRenderType.ENTITY);
|
2012-06-25 21:11:13 +02:00
|
|
|
if (customRenderer != null) {
|
2012-07-08 08:24:48 +02:00
|
|
|
customitem.item = item;
|
2012-06-25 21:11:13 +02:00
|
|
|
bindTextureByName("/terrain.png");
|
|
|
|
ForgeHooksClient.overrideTexture(item.getItem());
|
|
|
|
customRenderer.renderItem(IItemRenderer.ItemRenderType.ENTITY, item, renderBlocks, customitem);
|
2012-07-08 08:24:48 +02:00
|
|
|
} else if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) {
|
2012-04-25 03:17:23 +02:00
|
|
|
bindTextureByName("/terrain.png");
|
|
|
|
ForgeHooksClient.overrideTexture(Block.blocksList[item.itemID]);
|
2012-06-25 21:11:13 +02:00
|
|
|
renderBlocks.renderBlockAsItem(Block.blocksList[item.itemID], item.getItemDamage(), 1.0F);
|
|
|
|
} else {
|
|
|
|
int i = item.getIconIndex();
|
2012-07-08 08:24:48 +02:00
|
|
|
if (item.itemID >= Block.blocksList.length || Block.blocksList[item.itemID] == null) {
|
2012-06-25 21:11:13 +02:00
|
|
|
bindTextureByName("/gui/items.png");
|
|
|
|
ForgeHooksClient.overrideTexture(Item.itemsList[item.itemID]);
|
|
|
|
} else {
|
|
|
|
bindTextureByName("/terrain.png");
|
|
|
|
ForgeHooksClient.overrideTexture(Block.blocksList[item.itemID]);
|
|
|
|
}
|
|
|
|
Tessellator tessellator = Tessellator.instance;
|
|
|
|
float f5 = (float) ((i % 16) * 16 + 0) / 256F;
|
|
|
|
float f8 = (float) ((i % 16) * 16 + 16) / 256F;
|
|
|
|
float f10 = (float) ((i / 16) * 16 + 0) / 256F;
|
|
|
|
float f12 = (float) ((i / 16) * 16 + 16) / 256F;
|
|
|
|
float f13 = 1.0F;
|
|
|
|
float f14 = 0.5F;
|
|
|
|
float f15 = 0.25F;
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.setNormal(0.0F, 1.0F, 0.0F);
|
|
|
|
tessellator.addVertexWithUV(0.0F - f14, 0.0F - f15, 0.0D, f5, f12);
|
|
|
|
tessellator.addVertexWithUV(f13 - f14, 0.0F - f15, 0.0D, f8, f12);
|
|
|
|
tessellator.addVertexWithUV(f13 - f14, 1.0F - f15, 0.0D, f8, f10);
|
|
|
|
tessellator.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10);
|
|
|
|
tessellator.draw();
|
|
|
|
glScalef(-1.0F, 1.0F, 1.0F);
|
|
|
|
tessellator.startDrawingQuads();
|
|
|
|
tessellator.setNormal(0.0F, 1.0F, 0.0F);
|
|
|
|
tessellator.addVertexWithUV(0.0F - f14, 0.0F - f15, 0.0D, f5, f12);
|
|
|
|
tessellator.addVertexWithUV(f13 - f14, 0.0F - f15, 0.0D, f8, f12);
|
|
|
|
tessellator.addVertexWithUV(f13 - f14, 1.0F - f15, 0.0D, f8, f10);
|
|
|
|
tessellator.addVertexWithUV(0.0F - f14, 1.0F - f15, 0.0D, f5, f10);
|
|
|
|
tessellator.draw();
|
2012-04-25 03:17:23 +02:00
|
|
|
}
|
2012-07-08 20:28:25 +02:00
|
|
|
if (mod_IronChest.CACHE_RENDER) {
|
|
|
|
glEndList();
|
|
|
|
}
|
2012-06-25 21:11:13 +02:00
|
|
|
} else {
|
2012-07-08 20:28:25 +02:00
|
|
|
Integer integer = renderList.get(mis);
|
|
|
|
if (integer != null) { // Added null check for auto-unboxing JUST in case.
|
2012-07-08 08:24:48 +02:00
|
|
|
glCallList(integer.intValue());
|
2012-07-08 20:28:25 +02:00
|
|
|
}
|
2012-04-25 03:17:23 +02:00
|
|
|
}
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
|
|
|
glEnable(2896 /* GL_LIGHTING */);
|
|
|
|
glPopMatrix();
|
|
|
|
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick) {
|
|
|
|
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ModelChest model;
|
|
|
|
}
|