Update for 1.4.6. Change render handling a bit.

This commit is contained in:
Christian 2012-12-18 11:22:21 -05:00
parent 70232000a8
commit 2735d04de2
27 changed files with 1622 additions and 1437 deletions

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="client"/>
<classpathentry kind="src" path="common"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/Forge"/>

View File

@ -1,52 +0,0 @@
/*******************************************************************************
* 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 net.minecraft.client.renderer.ChestItemRenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.ironchest.CommonProxy;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class ClientProxy extends CommonProxy {
@Override
public void registerRenderInformation() {
ChestItemRenderHelper.instance = new IronChestRenderHelper();
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png");
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
}
@Override
public void registerTileEntitySpecialRenderer(IronChestType typ) {
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
}
@Override
public World getClientWorld() {
return FMLClientHandler.instance().getClient().theWorld;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te != null && te instanceof TileEntityIronChest) {
return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
} else {
return null;
}
}
}

View File

@ -1,75 +0,0 @@
/*******************************************************************************
* 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 net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import org.lwjgl.opengl.GL11;
import cpw.mods.ironchest.ContainerIronChestBase;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class GUIChest extends GuiContainer {
public enum GUI {
IRON(184,202,"/cpw/mods/ironchest/sprites/ironcontainer.png",IronChestType.IRON),
GOLD(184,256,"/cpw/mods/ironchest/sprites/goldcontainer.png",IronChestType.GOLD),
DIAMOND(238,256,"/cpw/mods/ironchest/sprites/diamondcontainer.png",IronChestType.DIAMOND),
COPPER(184,184,"/cpw/mods/ironchest/sprites/coppercontainer.png",IronChestType.COPPER),
SILVER(184,238,"/cpw/mods/ironchest/sprites/silvercontainer.png",IronChestType.SILVER),
CRYSTAL(238,256,"/cpw/mods/ironchest/sprites/diamondcontainer.png",IronChestType.CRYSTAL);
private int xSize;
private int ySize;
private String guiTexture;
private IronChestType mainType;
private GUI(int xSize, int ySize, String guiTexture, IronChestType mainType) {
this.xSize=xSize;
this.ySize=ySize;
this.guiTexture=guiTexture;
this.mainType=mainType;
}
protected Container makeContainer(IInventory player, IInventory chest) {
return new ContainerIronChestBase(player,chest, mainType, xSize, ySize);
}
public static GUIChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory) {
return new GUIChest(values()[chestInventory.getType().ordinal()],playerInventory,chestInventory);
}
}
public int getRowLength() {
return type.mainType.getRowLength();
}
private GUI type;
private GUIChest(GUI type, IInventory player, IInventory chest) {
super(type.makeContainer(player,chest));
this.type=type;
this.xSize=type.xSize;
this.ySize=type.ySize;
this.allowUserInput=false;
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
int tex = mc.renderEngine.getTexture(type.guiTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(tex);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

View File

@ -1,249 +0,0 @@
/*******************************************************************************
* 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.GL_COMPILE_AND_EXECUTE;
import static org.lwjgl.opengl.GL11.glCallList;
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.glEndList;
import static org.lwjgl.opengl.GL11.glGenLists;
import static org.lwjgl.opengl.GL11.glNewList;
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;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.MappableItemStackWrapper;
import cpw.mods.ironchest.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
private Random random;
private RenderBlocks renderBlocks;
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 }, };
public TileEntityIronChestRenderer() {
model = new ModelChest();
random = new Random();
renderBlocks = new RenderBlocks();
}
private void overrideTexture(Object obj) {
if (obj instanceof Item) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(((Item) obj).getTextureFile()));
} else if (obj instanceof Block) {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(((Block) obj).getTextureFile()));
}
}
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
if (tile == null) {
return;
}
int facing = 3;
IronChestType type = tile.getType();
if (tile != null && tile.getWorldObj() != null) {
facing = tile.getFacing();
type = tile.getType();
int typ = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
type = IronChestType.values()[typ];
}
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);
EntityItem customitem = new EntityItem(tileEntityRenderer.worldObj);
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;
if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null && Block.blocksList[item.itemID].blockID != 0) {
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);
}
MappableItemStackWrapper mis = new MappableItemStackWrapper(item);
if (!IronChest.CACHE_RENDER || !renderList.containsKey(mis)) { // Added support for using only old system.
// TODO add support for the skull TESR
IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, IItemRenderer.ItemRenderType.ENTITY);
if (customRenderer != null) {
customitem.item = item;
bindTextureByName("/terrain.png");
overrideTexture(item.getItem());
customRenderer.renderItem(IItemRenderer.ItemRenderType.ENTITY, item, renderBlocks, customitem);
} else if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID] != null && Block.blocksList[item.itemID].blockID != 0 && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) {
bindTextureByName("/terrain.png");
overrideTexture(Block.blocksList[item.itemID]);
renderBlocks.renderBlockAsItem(Block.blocksList[item.itemID], item.getItemDamage(), 1.0F);
} else {
int render = 0;
if (IronChest.CACHE_RENDER) {
render = glGenLists(1);
if (render != 0)
{
renderList.put(mis, render);
glNewList(render, GL_COMPILE_AND_EXECUTE);
}
}
int i = item.getIconIndex();
if (item.itemID >= Block.blocksList.length || Block.blocksList[item.itemID] == null || Block.blocksList[item.itemID].blockID == 0) {
bindTextureByName("/gui/items.png");
overrideTexture(Item.itemsList[item.itemID]);
} else {
bindTextureByName("/terrain.png");
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();
if (IronChest.CACHE_RENDER && render != 0) {
glEndList();
}
}
} else {
Integer integer = renderList.get(mis);
if (integer != null) { // Added null check for auto-unboxing JUST in case.
glCallList(integer.intValue());
}
}
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;
}

View File

@ -13,8 +13,8 @@ package cpw.mods.ironchest;
import java.util.List;
import java.util.Random;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@ -35,7 +35,8 @@ public class BlockIronChest extends BlockContainer {
private Random random;
public BlockIronChest(int id) {
public BlockIronChest(int id)
{
super(id, Material.iron);
setBlockName("IronChest");
setHardness(3.0F);
@ -46,56 +47,71 @@ public class BlockIronChest extends BlockContainer {
}
@Override
public TileEntity createNewTileEntity(World w) {
public TileEntity createNewTileEntity(World w)
{
return null;
}
@Override
public String getTextureFile() {
public String getTextureFile()
{
return "/cpw/mods/ironchest/sprites/block_textures.png";
}
@Override
public boolean isOpaqueCube() {
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock() {
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public int getRenderType() {
public int getRenderType()
{
return 22;
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
public TileEntity createNewTileEntity(World world, int metadata)
{
return IronChestType.makeEntity(metadata);
}
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) {
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l)
{
int meta = worldAccess.getBlockMetadata(i, j, k);
IronChestType type = IronChestType.values()[meta];
TileEntity te = worldAccess.getBlockTileEntity(i, j, k);
TileEntityIronChest icte = null;
if (te != null && te instanceof TileEntityIronChest) {
if (te != null && te instanceof TileEntityIronChest)
{
icte = (TileEntityIronChest) te;
}
if (l == 0 || l == 1) { // Top and Bottom
if (l == 0 || l == 1)
{ // Top and Bottom
return type.getTextureRow() * 16 + 1;
} else if (icte != null && l == icte.getFacing()) { // Front
}
else if (icte != null && l == icte.getFacing())
{ // Front
return type.getTextureRow() * 16 + 2;
} else { // Back and Sides
}
else
{ // Back and Sides
return type.getTextureRow() * 16;
}
}
@Override
public int getBlockTextureFromSideAndMetadata(int i, int j) {
public int getBlockTextureFromSideAndMetadata(int i, int j)
{
IronChestType typ = IronChestType.values()[j];
switch (i) {
switch (i)
{
case 0:
case 1:
return typ.getTextureRow() * 16 + 1;
@ -107,7 +123,8 @@ public class BlockIronChest extends BlockContainer {
}
@Override
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3) {
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3)
{
TileEntity te = world.getBlockTileEntity(i, j, k);
if (te == null || !(te instanceof TileEntityIronChest))
@ -120,7 +137,8 @@ public class BlockIronChest extends BlockContainer {
return true;
}
if (world.isRemote) {
if (world.isRemote)
{
return true;
}
@ -129,36 +147,44 @@ public class BlockIronChest extends BlockContainer {
}
@Override
public void onBlockAdded(World world, int i, int j, int k) {
public void onBlockAdded(World world, int i, int j, int k)
{
super.onBlockAdded(world, i, j, k);
world.markBlockForUpdate(i, j, k);
}
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) {
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
{
byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0) {
if (facing == 0)
{
chestFacing = 2;
}
if (facing == 1) {
if (facing == 1)
{
chestFacing = 5;
}
if (facing == 2) {
if (facing == 2)
{
chestFacing = 3;
}
if (facing == 3) {
if (facing == 3)
{
chestFacing = 4;
}
TileEntity te = world.getBlockTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest) {
if (te != null && te instanceof TileEntityIronChest)
{
((TileEntityIronChest) te).setFacing(chestFacing);
world.markBlockForUpdate(i, j, k);
}
}
@Override
public int damageDropped(int i) {
public int damageDropped(int i)
{
return i;
}
@ -173,7 +199,8 @@ public class BlockIronChest extends BlockContainer {
super.breakBlock(world, i, j, k, i1, i2);
}
public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord) {
public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord)
{
for (int l = newSize; l < chest.getSizeInventory(); l++)
{
ItemStack itemstack = chest.getStackInSlot(l);
@ -200,7 +227,7 @@ public class BlockIronChest extends BlockContainer {
entityitem.motionZ = (float) random.nextGaussian() * f3;
if (itemstack.hasTagCompound())
{
entityitem.item.setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
entityitem.func_92014_d().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
}
world.spawnEntityInWorld(entityitem);
}
@ -210,9 +237,12 @@ public class BlockIronChest extends BlockContainer {
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) {
for (IronChestType type : IronChestType.values()) {
if (type.isValidForCreativeMode()) {
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (IronChestType type : IronChestType.values())
{
if (type.isValidForCreativeMode())
{
par3List.add(new ItemStack(this, 1, type.ordinal()));
}
}

View File

@ -19,14 +19,12 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
public enum ChestChangerType {
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"),
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"),
COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm", "msm", "mmm"),
SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"),
COPPERIRON(COPPER, IRON, "copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"),
DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade", "Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"),
WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm", "msm", "mmm"),
WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm");
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"), GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade",
"Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"), COPPERSILVER(COPPER, SILVER, "copperSilverUpgrade", "Copper to Silver Chest Upgrade", "mmm",
"msm", "mmm"), SILVERGOLD(SILVER, GOLD, "silverGoldUpgrade", "Silver to Gold Chest Upgrade", "mGm", "GsG", "mGm"), COPPERIRON(COPPER, IRON,
"copperIronUpgrade", "Copper to Iron Chest Upgrade", "mGm", "GsG", "mGm"), DIAMONDCRYSTAL(DIAMOND, CRYSTAL, "diamondCrystalUpgrade",
"Diamond to Crystal Chest Upgrade", "GGG", "GOG", "GGG"), WOODIRON(WOOD, IRON, "woodIronUpgrade", "Normal chest to Iron Chest Upgrade", "mmm",
"msm", "mmm"), WOODCOPPER(WOOD, COPPER, "woodCopperUpgrade", "Normal chest to Copper Chest Upgrade", "mmm", "msm", "mmm");
private IronChestType source;
private IronChestType target;
@ -35,7 +33,8 @@ public enum ChestChangerType {
private ItemChestChanger item;
private String[] recipe;
private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe) {
private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe)
{
this.source = source;
this.target = target;
this.itemName = itemName;
@ -43,23 +42,29 @@ public enum ChestChangerType {
this.recipe = recipe;
}
public boolean canUpgrade(IronChestType from) {
public boolean canUpgrade(IronChestType from)
{
return from == this.source;
}
public int getTarget() {
public int getTarget()
{
return this.target.ordinal();
}
public ItemChestChanger buildItem(Configuration cfg, int id) {
public ItemChestChanger buildItem(Configuration cfg, int id)
{
int itemId = cfg.get(Configuration.CATEGORY_ITEM, itemName, id).getInt(id);
item = new ItemChestChanger(itemId, this);
return item;
}
public void addRecipes() {
for (String sourceMat : source.getMatList()) {
for (String targetMat : target.getMatList()) {
public void addRecipes()
{
for (String sourceMat : source.getMatList())
{
for (String targetMat : target.getMatList())
{
Object targetMaterial = IronChestType.translateOreName(targetMat);
Object sourceMaterial = IronChestType.translateOreName(sourceMat);
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Block.glass, 'O', Block.obsidian);
@ -67,14 +72,18 @@ public enum ChestChangerType {
}
}
public static void buildItems(Configuration cfg, int defaultId) {
for (ChestChangerType type : values()) {
public static void buildItems(Configuration cfg, int defaultId)
{
for (ChestChangerType type : values())
{
type.buildItem(cfg, defaultId++);
}
}
public static void generateRecipes() {
for (ChestChangerType item : values()) {
public static void generateRecipes()
{
for (ChestChangerType item : values())
{
item.addRecipes();
}
}

View File

@ -27,22 +27,28 @@ public class CommonProxy implements IGuiHandler {
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return null;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int X, int Y, int Z) {
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int X, int Y, int Z)
{
TileEntity te = world.getBlockTileEntity(X, Y, Z);
if (te != null && te instanceof TileEntityIronChest) {
if (te != null && te instanceof TileEntityIronChest)
{
TileEntityIronChest icte = (TileEntityIronChest) te;
return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0);
} else {
}
else
{
return null;
}
}
public World getClientWorld() {
public World getClientWorld()
{
return null;
}

View File

@ -22,7 +22,8 @@ public class ContainerIronChestBase extends Container {
private EntityPlayer player;
private IInventory chest;
public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{
chest = chestInventory;
player = ((InventoryPlayer) playerInventory).player;
this.type = type;
@ -51,14 +52,16 @@ public class ContainerIronChestBase extends Container {
{
return null;
}
} else if (!mergeItemStack(itemstack1, 0, type.size, false))
}
else if (!mergeItemStack(itemstack1, 0, type.size, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack(null);
} else
}
else
{
slot.onSlotChanged();
}
@ -73,7 +76,8 @@ public class ContainerIronChestBase extends Container {
chest.closeChest();
}
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) {
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
{
for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
@ -88,7 +92,8 @@ public class ContainerIronChestBase extends Container {
{
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
{
addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10));
addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18
- 10));
}
}
@ -99,7 +104,8 @@ public class ContainerIronChestBase extends Container {
}
}
public EntityPlayer getPlayer() {
public EntityPlayer getPlayer()
{
return player;
}
}

View File

@ -14,6 +14,7 @@ import java.util.logging.Level;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
@ -42,33 +43,42 @@ public class IronChest {
private int blockId;
@PreInit
public void preInit(FMLPreInitializationEvent event) {
public void preInit(FMLPreInitializationEvent event)
{
Version.init(event.getVersionProperties());
event.getModMetadata().version = Version.fullVersionString();
Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
try {
try
{
cfg.load();
blockId = cfg.get(Configuration.CATEGORY_BLOCK, "ironChests", 181).getInt(181);
ChestChangerType.buildItems(cfg, 29501);
CACHE_RENDER = cfg.get(Configuration.CATEGORY_GENERAL, "cacheRenderingInformation", true).getBoolean(true);
OCELOTS_SITONCHESTS = cfg.get(Configuration.CATEGORY_GENERAL, "ocelotsSitOnChests", true).getBoolean(true);
} catch (Exception e) {
}
catch (Exception e)
{
FMLLog.log(Level.SEVERE, e, "IronChest has a problem loading it's configuration");
} finally {
}
finally
{
cfg.save();
}
}
@Init
public void load(FMLInitializationEvent evt) {
public void load(FMLInitializationEvent evt)
{
ironChestBlock = new BlockIronChest(blockId);
GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class);
for (IronChestType typ : IronChestType.values()) {
for (IronChestType typ : IronChestType.values())
{
GameRegistry.registerTileEntity(typ.clazz, typ.name());
LanguageRegistry.instance().addStringLocalization(typ.name() + ".name", "en_US", typ.friendlyName);
proxy.registerTileEntitySpecialRenderer(typ);
}
for (ChestChangerType typ : ChestChangerType.values()) {
for (ChestChangerType typ : ChestChangerType.values())
{
LanguageRegistry.instance().addStringLocalization("item." + typ.itemName + ".name", "en_US", typ.descriptiveName);
}
IronChestType.generateTieredRecipes(ironChestBlock);
@ -79,9 +89,12 @@ public class IronChest {
{
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
}
MinecraftForge.EVENT_BUS.register(this);
}
@PostInit
public void modsLoaded(FMLPostInitializationEvent evt) {
public void modsLoaded(FMLPostInitializationEvent evt)
{
}
}

View File

@ -5,13 +5,16 @@ import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.world.World;
public class IronChestAIOcelotSit extends EntityAIOcelotSit {
public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2) {
public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2)
{
super(par1EntityOcelot, par2);
}
@Override
protected boolean isSittableBlock(World world, int x, int y, int z) {
if (world.getBlockId(x, y, z) == IronChest.ironChestBlock.blockID) {
protected boolean isSittableBlock(World world, int x, int y, int z)
{
if (world.getBlockId(x, y, z) == IronChest.ironChestBlock.blockID)
{
return true;
}
return super.isSittableBlock(world, x, y, z);

View File

@ -22,13 +22,13 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.ShapedOreRecipe;
public enum IronChestType {
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Arrays.asList("ingotIron","ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"),
GOLD(81, 9, true, "Gold Chest", "goldchest.png", 1, Arrays.asList("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"),
DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"),
COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"),
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"),
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
WOOD(0,0,false,"","",-1,Arrays.asList("blockPlanks"),null);
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Arrays.asList("ingotIron", "ingotRefinedIron"), TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"), GOLD(
81, 9, true, "Gold Chest", "goldchest.png", 1, Arrays.asList("ingotGold"), TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"), DIAMOND(108, 12,
true, "Diamond Chest", "diamondchest.png", 2, Arrays.asList("gemDiamond"), TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"), COPPER(45, 9,
false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"), SILVER(72, 9, false,
"Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"), CRYSTAL(108, 12, true,
"Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"), WOOD(0, 0, false, "", "", -1,
Arrays.asList("blockPlanks"), null);
int size;
private int rowLength;
public String friendlyName;
@ -40,7 +40,8 @@ public enum IronChestType {
private ArrayList<String> matList;
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, String... recipes) {
Class<? extends TileEntityIronChest> clazz, String... recipes)
{
this.size = size;
this.rowLength = rowLength;
this.tieredChest = tieredChest;
@ -53,25 +54,34 @@ public enum IronChestType {
matList.addAll(mats);
}
public String getModelTexture() {
public String getModelTexture()
{
return modelTexture;
}
public int getTextureRow() {
public int getTextureRow()
{
return textureRow;
}
public static TileEntityIronChest makeEntity(int metadata) {
public static TileEntityIronChest makeEntity(int metadata)
{
// Compatibility
int chesttype = validateMeta(metadata);
if (chesttype == metadata) {
try {
if (chesttype == metadata)
{
try
{
TileEntityIronChest te = values()[chesttype].clazz.newInstance();
return te;
} catch (InstantiationException e) {
}
catch (InstantiationException e)
{
// unpossible
e.printStackTrace();
} catch (IllegalAccessException e) {
}
catch (IllegalAccessException e)
{
// unpossible
e.printStackTrace();
}
@ -79,30 +89,39 @@ public enum IronChestType {
return null;
}
public static void registerTranslations() {
public static void registerTranslations()
{
}
public static void generateTieredRecipes(BlockIronChest blockResult) {
public static void generateTieredRecipes(BlockIronChest blockResult)
{
ItemStack previous = new ItemStack(Block.chest);
for (IronChestType typ : values()) {
for (IronChestType typ : values())
{
generateRecipesForType(blockResult, previous, typ);
if (typ.tieredChest)
previous = new ItemStack(blockResult, 1, typ.ordinal());
if (typ.tieredChest) previous = new ItemStack(blockResult, 1, typ.ordinal());
}
}
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type) {
for (String recipe : type.recipes) {
public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type)
{
for (String recipe : type.recipes)
{
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) };
Object mainMaterial = null;
for (String mat : type.matList) {
for (String mat : type.matList)
{
mainMaterial = translateOreName(mat);
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit,
'm', mainMaterial,
'P', previousTier, /* previous tier of chest */
'G', Block.glass,
'C', Block.chest,
'0', new ItemStack(blockResult, 1, 0), /* Iron Chest*/
addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mainMaterial, 'P', previousTier, /*
* previous
* tier
* of
* chest
*/
'G', Block.glass, 'C', Block.chest, '0', new ItemStack(blockResult, 1, 0), /*
* Iron
* Chest
*/
'1', new ItemStack(blockResult, 1, 1), /* Gold Chest */
'2', new ItemStack(blockResult, 1, 1), /* Diamond Chest */
'3', new ItemStack(blockResult, 1, 3), /* Copper Chest */
@ -112,52 +131,72 @@ public enum IronChestType {
}
}
public static Object translateOreName(String mat) {
if (mat == "ingotIron" ) {
public static Object translateOreName(String mat)
{
if (mat == "ingotIron")
{
return Item.ingotIron;
} else if (mat == "ingotGold") {
}
else if (mat == "ingotGold")
{
return Item.ingotGold;
} else if (mat == "gemDiamond") {
}
else if (mat == "gemDiamond")
{
return Item.diamond;
} else if (mat == "blockGlass") {
}
else if (mat == "blockGlass")
{
return Block.glass;
} else if (mat == "blockPlanks") {
}
else if (mat == "blockPlanks")
{
return Block.planks;
}
return mat;
}
@SuppressWarnings("unchecked")
public static void addRecipe(ItemStack is, Object... parts) {
public static void addRecipe(ItemStack is, Object... parts)
{
ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts);
GameRegistry.addRecipe(oreRecipe);
}
public int getRowCount() {
public int getRowCount()
{
return size / rowLength;
}
public int getRowLength() {
public int getRowLength()
{
return rowLength;
}
public boolean isTransparent() {
public boolean isTransparent()
{
return this == CRYSTAL;
}
public List<String> getMatList() {
public List<String> getMatList()
{
return matList;
}
public static int validateMeta(int i) {
if (i < values().length && values()[i].size>0) {
public static int validateMeta(int i)
{
if (i < values().length && values()[i].size > 0)
{
return i;
} else {
}
else
{
return 0;
}
}
public boolean isValidForCreativeMode() {
public boolean isValidForCreativeMode()
{
return validateMeta(ordinal()) == ordinal();
}

View File

@ -23,7 +23,8 @@ public class ItemChestChanger extends Item {
private ChestChangerType type;
public ItemChestChanger(int id, ChestChangerType type) {
public ItemChestChanger(int id, ChestChangerType type)
{
super(id);
setMaxStackSize(1);
this.type = type;
@ -33,23 +34,29 @@ public class ItemChestChanger extends Item {
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side) {
if (world.isRemote)
return false;
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side, float hitX, float hitY, float hitZ)
{
if (world.isRemote) return false;
TileEntity te = world.getBlockTileEntity(X, Y, Z);
TileEntityIronChest newchest;
if (te!=null && te instanceof TileEntityIronChest) {
if (te != null && te instanceof TileEntityIronChest)
{
TileEntityIronChest ironchest = (TileEntityIronChest) te;
newchest = ironchest.applyUpgradeItem(this);
if (newchest==null) {
if (newchest == null)
{
return false;
}
} else if (te!=null && te instanceof TileEntityChest) {
}
else if (te != null && te instanceof TileEntityChest)
{
TileEntityChest tec = (TileEntityChest) te;
if (tec.numUsingPlayers > 0) {
if (tec.numUsingPlayers > 0)
{
return false;
}
if (!getType().canUpgrade(IronChestType.WOOD)) {
if (!getType().canUpgrade(IronChestType.WOOD))
{
return false;
}
// Force old TE out of the world so that adjacent chests can update
@ -69,11 +76,14 @@ public class ItemChestChanger extends Item {
world.setBlock(X, Y, Z, 0);
// Force the Chest TE to reset it's knowledge of neighbouring blocks
tec.updateContainingBlockInfo();
// Force the Chest TE to update any neighbours so they update next tick
// Force the Chest TE to update any neighbours so they update next
// tick
tec.checkForAdjacentChests();
// And put in our block instead
world.setBlock(X, Y, Z, block.blockID);
} else {
}
else
{
return false;
}
world.setBlockTileEntity(X, Y, Z, newchest);
@ -85,15 +95,18 @@ public class ItemChestChanger extends Item {
}
@Override
public String getTextureFile() {
public String getTextureFile()
{
return "/cpw/mods/ironchest/sprites/item_textures.png";
}
public int getTargetChestOrdinal(int sourceOrdinal) {
public int getTargetChestOrdinal(int sourceOrdinal)
{
return type.getTarget();
}
public ChestChangerType getType() {
public ChestChangerType getType()
{
return type;
}
}

View File

@ -15,18 +15,22 @@ import net.minecraft.item.ItemStack;
public class ItemIronChest extends ItemBlock {
public ItemIronChest(int id) {
public ItemIronChest(int id)
{
super(id);
setMaxDamage(0);
setHasSubtypes(true);
}
@Override
public int getMetadata(int i) {
public int getMetadata(int i)
{
return IronChestType.validateMeta(i);
}
@Override
public String getItemNameIS(ItemStack itemstack) {
public String getItemNameIS(ItemStack itemstack)
{
return IronChestType.values()[itemstack.getItemDamage()].name();
}
}

View File

@ -5,22 +5,29 @@ import net.minecraft.item.ItemStack;
public class MappableItemStackWrapper {
private ItemStack wrap;
public MappableItemStackWrapper(ItemStack toWrap) {
public MappableItemStackWrapper(ItemStack toWrap)
{
wrap = toWrap;
}
@Override
public boolean equals(Object obj) {
public boolean equals(Object obj)
{
if (!(obj instanceof MappableItemStackWrapper)) return false;
MappableItemStackWrapper isw = (MappableItemStackWrapper) obj;
if (wrap.getHasSubtypes()) {
if (wrap.getHasSubtypes())
{
return isw.wrap.isItemEqual(wrap);
} else {
}
else
{
return isw.wrap.itemID == wrap.itemID;
}
}
@Override
public int hashCode() {
public int hashCode()
{
return wrap.itemID;
}
}

View File

@ -10,7 +10,8 @@ import net.minecraftforge.event.entity.living.LivingEvent;
public class OcelotsSitOnChestsHandler {
@ForgeSubscribe
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt) {
public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt)
{
if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot)
{
EntityOcelot ocelot = (EntityOcelot) evt.entityLiving;

View File

@ -28,7 +28,8 @@ import cpw.mods.fml.common.network.Player;
public class PacketHandler implements IPacketHandler {
@Override
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player) {
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player)
{
ByteArrayDataInput dat = ByteStreams.newDataInput(packet.data);
int x = dat.readInt();
int y = dat.readInt();
@ -36,21 +37,25 @@ public class PacketHandler implements IPacketHandler {
byte typ = dat.readByte();
boolean hasStacks = dat.readByte() != 0;
int[] items = new int[0];
if (hasStacks) {
if (hasStacks)
{
items = new int[24];
for (int i = 0; i < items.length; i++) {
for (int i = 0; i < items.length; i++)
{
items[i] = dat.readInt();
}
}
World world = IronChest.proxy.getClientWorld();
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityIronChest) {
if (te instanceof TileEntityIronChest)
{
TileEntityIronChest icte = (TileEntityIronChest) te;
icte.handlePacketData(typ, items);
}
}
public static Packet getPacket(TileEntityIronChest tileEntityIronChest) {
public static Packet getPacket(TileEntityIronChest tileEntityIronChest)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(140);
DataOutputStream dos = new DataOutputStream(bos);
int x = tileEntityIronChest.xCoord;
@ -59,18 +64,23 @@ public class PacketHandler implements IPacketHandler {
int typ = tileEntityIronChest.getType().ordinal();
int[] items = tileEntityIronChest.buildIntDataList();
boolean hasStacks = (items != null);
try {
try
{
dos.writeInt(x);
dos.writeInt(y);
dos.writeInt(z);
dos.writeByte(typ);
dos.writeByte(hasStacks ? 1 : 0);
if (hasStacks) {
for (int i = 0; i < 24; i++) {
if (hasStacks)
{
for (int i = 0; i < 24; i++)
{
dos.writeInt(items[i]);
}
}
} catch (IOException e) {
}
catch (IOException e)
{
// UNPOSSIBLE?
}
Packet250CustomPayload pkt = new Packet250CustomPayload();

View File

@ -11,7 +11,8 @@
package cpw.mods.ironchest;
public class TileEntityCopperChest extends TileEntityIronChest {
public TileEntityCopperChest() {
public TileEntityCopperChest()
{
super(IronChestType.COPPER);
}

View File

@ -11,7 +11,8 @@
package cpw.mods.ironchest;
public class TileEntityCrystalChest extends TileEntityIronChest {
public TileEntityCrystalChest() {
public TileEntityCrystalChest()
{
super(IronChestType.CRYSTAL);
}
}

View File

@ -11,7 +11,8 @@
package cpw.mods.ironchest;
public class TileEntityDiamondChest extends TileEntityIronChest {
public TileEntityDiamondChest() {
public TileEntityDiamondChest()
{
super(IronChestType.DIAMOND);
}
}

View File

@ -12,7 +12,8 @@ package cpw.mods.ironchest;
public class TileEntityGoldChest extends TileEntityIronChest {
public TileEntityGoldChest() {
public TileEntityGoldChest()
{
super(IronChestType.GOLD);
}
}

View File

@ -33,62 +33,77 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
private boolean inventoryTouched;
private boolean hadStuff;
public TileEntityIronChest() {
public TileEntityIronChest()
{
this(IronChestType.IRON);
}
protected TileEntityIronChest(IronChestType type) {
protected TileEntityIronChest(IronChestType type)
{
super();
this.type = type;
this.chestContents = new ItemStack[getSizeInventory()];
this.topStacks = new ItemStack[8];
}
public ItemStack[] getContents() {
public ItemStack[] getContents()
{
return chestContents;
}
@Override
public int getSizeInventory() {
public int getSizeInventory()
{
return type.size;
}
public byte getFacing() {
public byte getFacing()
{
return this.facing;
}
@Override
public String getInvName() {
public String getInvName()
{
return type.name();
}
public IronChestType getType() {
public IronChestType getType()
{
return type;
}
@Override
public ItemStack getStackInSlot(int i) {
public ItemStack getStackInSlot(int i)
{
inventoryTouched = true;
return chestContents[i];
}
@Override
public void onInventoryChanged() {
public void onInventoryChanged()
{
super.onInventoryChanged();
sortTopStacks();
}
protected void sortTopStacks() {
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote)) {
protected void sortTopStacks()
{
if (!type.isTransparent() || (worldObj != null && worldObj.isRemote))
{
return;
}
ItemStack[] tempCopy = new ItemStack[getSizeInventory()];
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop: for (int i = 0; i < getSizeInventory(); i++) {
if (chestContents[i] != null) {
for (int j = 0; j < compressedIdx; j++) {
if (tempCopy[j].isItemEqual(chestContents[i])) {
mainLoop: for (int i = 0; i < getSizeInventory(); i++)
{
if (chestContents[i] != null)
{
for (int j = 0; j < compressedIdx; j++)
{
if (tempCopy[j].isItemEqual(chestContents[i]))
{
tempCopy[j].stackSize += chestContents[i].stackSize;
continue mainLoop;
}
@ -97,12 +112,15 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
hasStuff = true;
}
}
if (!hasStuff && hadStuff) {
if (!hasStuff && hadStuff)
{
hadStuff = false;
for (int i = 0; i < topStacks.length; i++) {
for (int i = 0; i < topStacks.length; i++)
{
topStacks[i] = null;
}
if (worldObj!=null) {
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
return;
@ -110,35 +128,47 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
hadStuff = true;
Arrays.sort(tempCopy, new Comparator<ItemStack>() {
@Override
public int compare(ItemStack o1, ItemStack o2) {
if (o1 == null) {
public int compare(ItemStack o1, ItemStack o2)
{
if (o1 == null)
{
return 1;
} else if (o2 == null) {
}
else if (o2 == null)
{
return -1;
} else {
}
else
{
return o2.stackSize - o1.stackSize;
}
}
});
int p = 0;
for (int i = 0; i < tempCopy.length; i++) {
if (tempCopy[i] != null && tempCopy[i].stackSize > 0) {
for (int i = 0; i < tempCopy.length; i++)
{
if (tempCopy[i] != null && tempCopy[i].stackSize > 0)
{
topStacks[p++] = tempCopy[i];
if (p == topStacks.length) {
if (p == topStacks.length)
{
break;
}
}
}
for (int i = p; i < topStacks.length; i++) {
for (int i = p; i < topStacks.length; i++)
{
topStacks[i] = null;
}
if (worldObj!=null) {
if (worldObj != null)
{
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@Override
public ItemStack decrStackSize(int i, int j) {
public ItemStack decrStackSize(int i, int j)
{
if (chestContents[i] != null)
{
if (chestContents[i].stackSize <= j)
@ -163,7 +193,8 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
public void setInventorySlotContents(int i, ItemStack itemstack)
{
chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
@ -212,101 +243,123 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
@Override
public int getInventoryStackLimit() {
public int getInventoryStackLimit()
{
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
if (worldObj == null) {
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
if (worldObj == null)
{
return true;
}
if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) {
if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this)
{
return false;
}
return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D;
}
@Override
public void updateEntity() {
public void updateEntity()
{
super.updateEntity();
// Resynchronize clients with the server state
if ((++ticksSinceSync % 20) * 4 == 0) {
if ((++ticksSinceSync % 20) * 4 == 0)
{
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7));
if (inventoryTouched) {
if (inventoryTouched)
{
inventoryTouched = false;
sortTopStacks();
}
}
prevLidAngle = lidAngle;
float f = 0.1F;
if (numUsingPlayers > 0 && lidAngle == 0.0F) {
if (numUsingPlayers > 0 && lidAngle == 0.0F)
{
double d = (double) xCoord + 0.5D;
double d1 = (double) zCoord + 0.5D;
worldObj.playSoundEffect(d, (double) yCoord + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F) {
if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F)
{
float f1 = lidAngle;
if (numUsingPlayers > 0) {
if (numUsingPlayers > 0)
{
lidAngle += f;
} else {
}
else
{
lidAngle -= f;
}
if (lidAngle > 1.0F) {
if (lidAngle > 1.0F)
{
lidAngle = 1.0F;
}
float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2) {
if (lidAngle < f2 && f1 >= f2)
{
double d2 = (double) xCoord + 0.5D;
double d3 = (double) zCoord + 0.5D;
worldObj.playSoundEffect(d2, (double) yCoord + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
if (lidAngle < 0.0F) {
if (lidAngle < 0.0F)
{
lidAngle = 0.0F;
}
}
}
@Override
public void receiveClientEvent(int i, int j)
{
if (i == 1)
{
numUsingPlayers = j;
} else if (i == 2) {
}
else if (i == 2)
{
facing = (byte) j;
} else if (i == 3) {
}
else if (i == 3)
{
facing = (byte) (j & 0x7);
numUsingPlayers = (j & 0xF8) >> 3;
}
}
@Override
public void openChest() {
if (worldObj == null)
return;
public void openChest()
{
if (worldObj == null) return;
numUsingPlayers++;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers);
}
@Override
public void closeChest() {
if (worldObj == null)
return;
public void closeChest()
{
if (worldObj == null) return;
numUsingPlayers--;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers);
}
public void setFacing(byte chestFacing) {
public void setFacing(byte chestFacing)
{
this.facing = chestFacing;
}
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
if (numUsingPlayers > 0) {
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger)
{
if (numUsingPlayers > 0)
{
return null;
}
if (!itemChestChanger.getType().canUpgrade(this.getType())) {
if (!itemChestChanger.getType().canUpgrade(this.getType()))
{
return null;
}
TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
@ -319,13 +372,17 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
return newEntity;
}
public ItemStack[] getTopItemStacks() {
public ItemStack[] getTopItemStacks()
{
return topStacks;
}
public TileEntityIronChest updateFromMetadata(int l) {
if (worldObj != null && worldObj.isRemote) {
if (l != type.ordinal()) {
public TileEntityIronChest updateFromMetadata(int l)
{
if (worldObj != null && worldObj.isRemote)
{
if (l != type.ordinal())
{
worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l));
return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
}
@ -334,25 +391,34 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
@Override
public Packet getDescriptionPacket() {
public Packet getDescriptionPacket()
{
return PacketHandler.getPacket(this);
}
public void handlePacketData(int typeData, int[] intData) {
public void handlePacketData(int typeData, int[] intData)
{
TileEntityIronChest chest = this;
if (this.type.ordinal() != typeData) {
if (this.type.ordinal() != typeData)
{
chest = updateFromMetadata(typeData);
}
if (IronChestType.values()[typeData].isTransparent() && intData != null) {
if (IronChestType.values()[typeData].isTransparent() && intData != null)
{
int pos = 0;
if (intData.length < chest.topStacks.length * 3) {
if (intData.length < chest.topStacks.length * 3)
{
return;
}
for (int i = 0; i < chest.topStacks.length; i++) {
if (intData[pos + 2] != 0) {
for (int i = 0; i < chest.topStacks.length; i++)
{
if (intData[pos + 2] != 0)
{
ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is;
} else {
}
else
{
chest.topStacks[i] = null;
}
pos += 3;
@ -360,16 +426,22 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
}
public int[] buildIntDataList() {
if (type.isTransparent()) {
public int[] buildIntDataList()
{
if (type.isTransparent())
{
int[] sortList = new int[topStacks.length * 3];
int pos = 0;
for (ItemStack is : topStacks) {
if (is != null) {
for (ItemStack is : topStacks)
{
if (is != null)
{
sortList[pos++] = is.itemID;
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
} else {
}
else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
@ -393,7 +465,9 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
return null;
}
}
public void setMaxStackSize(int size) {
public void setMaxStackSize(int size)
{
}
}

View File

@ -11,7 +11,8 @@
package cpw.mods.ironchest;
public class TileEntitySilverChest extends TileEntityIronChest {
public TileEntitySilverChest() {
public TileEntitySilverChest()
{
super(IronChestType.SILVER);
}
}

View File

@ -15,8 +15,10 @@ public class Version {
private static String build;
private static String mcversion;
static void init(Properties properties) {
if (properties != null) {
static void init(Properties properties)
{
if (properties != null)
{
major = properties.getProperty("IronChest.build.major.number");
minor = properties.getProperty("IronChest.build.minor.number");
rev = properties.getProperty("IronChest.build.revision.number");
@ -25,7 +27,8 @@ public class Version {
}
}
public static String fullVersionString() {
public static String fullVersionString()
{
return String.format("%s.%s.%s build %s", major, minor, rev, build);
}
}

View File

@ -0,0 +1,58 @@
/*******************************************************************************
* 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 net.minecraft.client.renderer.ChestItemRenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.ironchest.CommonProxy;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class ClientProxy extends CommonProxy {
@Override
public void registerRenderInformation()
{
ChestItemRenderHelper.instance = new IronChestRenderHelper();
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png");
MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png");
}
@Override
public void registerTileEntitySpecialRenderer(IronChestType typ)
{
ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer());
}
@Override
public World getClientWorld()
{
return FMLClientHandler.instance().getClient().theWorld;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te != null && te instanceof TileEntityIronChest)
{
return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te);
}
else
{
return null;
}
}
}

View File

@ -0,0 +1,80 @@
/*******************************************************************************
* 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 net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import org.lwjgl.opengl.GL11;
import cpw.mods.ironchest.ContainerIronChestBase;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
public class GUIChest extends GuiContainer {
public enum GUI {
IRON(184, 202, "/cpw/mods/ironchest/sprites/ironcontainer.png", IronChestType.IRON), GOLD(184, 256, "/cpw/mods/ironchest/sprites/goldcontainer.png",
IronChestType.GOLD), DIAMOND(238, 256, "/cpw/mods/ironchest/sprites/diamondcontainer.png", IronChestType.DIAMOND), COPPER(184, 184,
"/cpw/mods/ironchest/sprites/coppercontainer.png", IronChestType.COPPER), SILVER(184, 238, "/cpw/mods/ironchest/sprites/silvercontainer.png",
IronChestType.SILVER), CRYSTAL(238, 256, "/cpw/mods/ironchest/sprites/diamondcontainer.png", IronChestType.CRYSTAL);
private int xSize;
private int ySize;
private String guiTexture;
private IronChestType mainType;
private GUI(int xSize, int ySize, String guiTexture, IronChestType mainType)
{
this.xSize = xSize;
this.ySize = ySize;
this.guiTexture = guiTexture;
this.mainType = mainType;
}
protected Container makeContainer(IInventory player, IInventory chest)
{
return new ContainerIronChestBase(player, chest, mainType, xSize, ySize);
}
public static GUIChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory)
{
return new GUIChest(values()[chestInventory.getType().ordinal()], playerInventory, chestInventory);
}
}
public int getRowLength()
{
return type.mainType.getRowLength();
}
private GUI type;
private GUIChest(GUI type, IInventory player, IInventory chest)
{
super(type.makeContainer(player, chest));
this.type = type;
this.xSize = type.xSize;
this.ySize = type.ySize;
this.allowUserInput = false;
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
{
int tex = mc.renderEngine.getTexture(type.guiTexture);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(tex);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}

View File

@ -25,17 +25,23 @@ import cpw.mods.ironchest.TileEntityIronChest;
public class IronChestRenderHelper extends ChestItemRenderHelper {
private Map<Integer, TileEntityIronChest> itemRenders = Maps.newHashMap();
public IronChestRenderHelper() {
public IronChestRenderHelper()
{
for (IronChestType typ : IronChestType.values())
{
itemRenders.put(typ.ordinal(), (TileEntityIronChest) IronChest.ironChestBlock.createTileEntity(null, typ.ordinal()));
}
}
@Override
public void renderChest(Block block, int i, float f) {
if (block==IronChest.ironChestBlock) {
public void renderChest(Block block, int i, float f)
{
if (block == IronChest.ironChestBlock)
{
TileEntityRenderer.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F);
} else {
}
else
{
super.renderChest(block, i, f);
}
}

View File

@ -0,0 +1,195 @@
/*******************************************************************************
* 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.GL_COMPILE_AND_EXECUTE;
import static org.lwjgl.opengl.GL11.glCallList;
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.glEndList;
import static org.lwjgl.opengl.GL11.glGenLists;
import static org.lwjgl.opengl.GL11.glNewList;
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;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelChest;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderBlocks;
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.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;
import org.lwjgl.opengl.GL11;
import com.google.common.primitives.SignedBytes;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.MappableItemStackWrapper;
import cpw.mods.ironchest.TileEntityIronChest;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer {
private static Map<MappableItemStackWrapper, Integer> renderList = new HashMap<MappableItemStackWrapper, Integer>();
private Random random;
private RenderBlocks renderBlocks;
private RenderItem itemRenderer;
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 }, };
public TileEntityIronChestRenderer()
{
model = new ModelChest();
random = new Random();
renderBlocks = new RenderBlocks();
itemRenderer = new RenderItem() {
@Override
public byte getMiniBlockCountForItemStack(ItemStack stack) {
return SignedBytes.saturatedCast((stack.stackSize / 32) + 1);
}
public byte getMiniItemCountForItemStack(ItemStack stack) {
return SignedBytes.saturatedCast((stack.stackSize / 32) + 1);
};
public boolean shouldBob() {
return false;
};
public boolean shouldSpreadItems() {
return false;
};
};
itemRenderer.setRenderManager(RenderManager.instance);
}
private void overrideTexture(Object obj)
{
if (obj instanceof Item)
{
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(((Item) obj).getTextureFile()));
}
else if (obj instanceof Block)
{
GL11.glBindTexture(GL11.GL_TEXTURE_2D, FMLClientHandler.instance().getClient().renderEngine.getTexture(((Block) obj).getTextureFile()));
}
}
public void render(TileEntityIronChest tile, double x, double y, double z, float partialTick) {
if (tile == null) {
return;
}
int facing = 3;
IronChestType type = tile.getType();
if (tile != null && tile.getWorldObj() != null) {
facing = tile.getFacing();
type = tile.getType();
int typ = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
type = IronChestType.values()[typ];
}
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() && tile.getDistanceFrom(this.tileEntityRenderer.playerX, this.tileEntityRenderer.playerY, this.tileEntityRenderer.playerZ) < 128d) {
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();
glDisable(2896 /* GL_LIGHTING */);
glTranslatef((float) x, (float) y, (float) z);
EntityItem customitem = new EntityItem(tileEntityRenderer.worldObj);
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.func_92013_a(item);
itemRenderer.doRenderItem(customitem, 0, 0, 0, 0, 0);
glPopMatrix();
}
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;
}