2014-09-24 14:32:58 +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
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* cpw - initial API and implementation
|
|
|
|
******************************************************************************/
|
|
|
|
package cpw.mods.ironchest.client;
|
|
|
|
|
|
|
|
import static org.lwjgl.opengl.GL11.glColor4f;
|
|
|
|
import static org.lwjgl.opengl.GL11.glDisable;
|
|
|
|
import static org.lwjgl.opengl.GL11.glEnable;
|
|
|
|
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.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2014-09-26 04:45:55 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2014-09-24 14:32:58 +02:00
|
|
|
import net.minecraft.client.model.ModelChest;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderItem;
|
|
|
|
import net.minecraft.client.renderer.entity.RenderManager;
|
|
|
|
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.ResourceLocation;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
import com.google.common.collect.ImmutableMap.Builder;
|
|
|
|
|
2014-09-26 04:45:55 +02:00
|
|
|
import cpw.mods.ironchest.BlockIronChest;
|
2014-09-26 13:42:37 +02:00
|
|
|
import cpw.mods.ironchest.IronChest;
|
2014-09-24 14:32:58 +02:00
|
|
|
import cpw.mods.ironchest.IronChestType;
|
|
|
|
import cpw.mods.ironchest.MappableItemStackWrapper;
|
|
|
|
import cpw.mods.ironchest.TileEntityIronChest;
|
|
|
|
|
2014-09-26 04:45:55 +02:00
|
|
|
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer
|
|
|
|
{
|
2014-09-24 14:32:58 +02:00
|
|
|
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
|
|
|
|
|
|
|
|
private static Map<IronChestType, ResourceLocation> locations;
|
2014-09-26 04:45:55 +02:00
|
|
|
|
2014-09-24 14:32:58 +02:00
|
|
|
static {
|
|
|
|
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType,ResourceLocation>builder();
|
|
|
|
for (IronChestType typ : IronChestType.values()) {
|
|
|
|
builder.put(typ, new ResourceLocation("ironchest","textures/model/"+typ.getModelTexture()));
|
|
|
|
}
|
|
|
|
locations = builder.build();
|
|
|
|
}
|
2014-09-26 04:45:55 +02:00
|
|
|
|
2014-09-24 14:32:58 +02:00
|
|
|
private Random random;
|
|
|
|
private RenderItem itemRenderer;
|
2014-09-26 04:45:55 +02:00
|
|
|
private ModelChest model;
|
2014-09-24 14:32:58 +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 }, };
|
2014-09-26 04:45:55 +02:00
|
|
|
|
2014-09-24 14:32:58 +02:00
|
|
|
public TileEntityIronChestRenderer()
|
|
|
|
{
|
|
|
|
model = new ModelChest();
|
|
|
|
random = new Random();
|
2014-09-26 04:45:55 +02:00
|
|
|
/*itemRenderer = new RenderItem(null, null) {
|
2014-09-24 14:32:58 +02:00
|
|
|
@Override
|
|
|
|
public byte getMiniBlockCount(ItemStack stack, byte original) {
|
|
|
|
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public byte getMiniItemCount(ItemStack stack, byte original) {
|
|
|
|
return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 7) + 1);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public boolean shouldBob() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public boolean shouldSpreadItems() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2014-09-26 04:45:55 +02:00
|
|
|
itemRenderer.setRenderManager(RenderManager.instance);*/
|
2014-09-24 14:32:58 +02:00
|
|
|
}
|
|
|
|
|
2014-09-26 04:45:55 +02:00
|
|
|
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick)
|
|
|
|
{
|
2014-09-24 14:32:58 +02:00
|
|
|
if (tile == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int facing = 3;
|
|
|
|
IronChestType type = tile.getType();
|
2014-09-26 13:42:37 +02:00
|
|
|
|
|
|
|
if (tile != null && tile.hasWorldObj() && tile.getWorld().getBlockState(tile.getPos()).getBlock() == IronChest.ironChestBlock) {
|
2014-09-24 14:32:58 +02:00
|
|
|
facing = tile.getFacing();
|
|
|
|
type = tile.getType();
|
2014-09-26 04:45:55 +02:00
|
|
|
IBlockState state = tile.getWorld().getBlockState(tile.getPos());
|
|
|
|
type = (IronChestType)state.getValue(BlockIronChest.VARIANT_PROP);
|
2014-09-24 14:32:58 +02:00
|
|
|
}
|
2014-09-26 13:42:37 +02:00
|
|
|
|
2014-09-24 14:32:58 +02:00
|
|
|
bindTexture(locations.get(type));
|
|
|
|
glPushMatrix();
|
2014-09-26 04:45:55 +02:00
|
|
|
glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
|
|
|
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2014-09-24 14:32:58 +02:00
|
|
|
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();
|
2014-09-26 04:45:55 +02:00
|
|
|
glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
|
|
|
|
glPopMatrix();
|
2014-09-24 14:32:58 +02:00
|
|
|
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2014-09-26 04:45:55 +02:00
|
|
|
if (type.isTransparent() && tile.getDistanceSq(this.rendererDispatcher.field_147560_j, this.rendererDispatcher.field_147561_k, this.rendererDispatcher.field_147558_l) < 128d) {
|
2014-09-24 14:32:58 +02:00
|
|
|
random.setSeed(254L);
|
|
|
|
float shiftX;
|
|
|
|
float shiftY;
|
|
|
|
float shiftZ;
|
|
|
|
int shift = 0;
|
|
|
|
float blockScale = 0.70F;
|
|
|
|
float timeD = (float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL);
|
|
|
|
if (tile.getTopItemStacks()[1] == null) {
|
|
|
|
shift = 8;
|
|
|
|
blockScale = 0.85F;
|
|
|
|
}
|
|
|
|
glPushMatrix();
|
2014-09-26 04:45:55 +02:00
|
|
|
glDisable(2896 /* GL_LIGHTING */);
|
|
|
|
glTranslatef((float) x, (float) y, (float) z);
|
|
|
|
EntityItem customitem = new EntityItem(this.getWorld());
|
2014-09-24 14:32:58 +02:00
|
|
|
customitem.hoverStart = 0f;
|
|
|
|
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++;
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef(shiftX, shiftY, shiftZ);
|
|
|
|
glRotatef(timeD, 0.0F, 1.0F, 0.0F);
|
|
|
|
glScalef(blockScale, blockScale, blockScale);
|
|
|
|
customitem.setEntityItemStack(item);
|
2014-09-26 04:45:55 +02:00
|
|
|
//itemRenderer.doRender(customitem, 0, 0, 0, 0, 0);
|
2014-09-24 14:32:58 +02:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
2014-09-26 04:45:55 +02:00
|
|
|
glEnable(2896 /* GL_LIGHTING */);
|
|
|
|
glPopMatrix();
|
2014-09-24 14:32:58 +02:00
|
|
|
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
|
|
|
}
|
|
|
|
}
|
2014-09-26 04:45:55 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick, int p_180535_9_)
|
2014-09-24 14:32:58 +02:00
|
|
|
{
|
|
|
|
render((TileEntityIronChest) tileentity, x, y, z, partialTick);
|
|
|
|
}
|
|
|
|
|
2014-09-26 04:45:55 +02:00
|
|
|
}
|