diff --git a/IronChests2/.classpath b/IronChests2/.classpath index cfe2f1b..259f253 100644 --- a/IronChests2/.classpath +++ b/IronChests2/.classpath @@ -1,6 +1,5 @@ - diff --git a/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java b/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java deleted file mode 100644 index 79abe80..0000000 --- a/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java +++ /dev/null @@ -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; - } - } -} diff --git a/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java b/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java deleted file mode 100644 index b5f8ecc..0000000 --- a/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java +++ /dev/null @@ -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); - } -} diff --git a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java deleted file mode 100644 index a5b07bf..0000000 --- a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java +++ /dev/null @@ -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 renderList = new HashMap(); - - 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; -} diff --git a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java index ade168d..40df9a5 100644 --- a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java @@ -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; @@ -33,188 +33,218 @@ import net.minecraftforge.common.ForgeDirection; public class BlockIronChest extends BlockContainer { - private Random random; + private Random random; - public BlockIronChest(int id) { - super(id, Material.iron); - setBlockName("IronChest"); - setHardness(3.0F); - setRequiresSelfNotify(); - setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); - random = new Random(); - setCreativeTab(CreativeTabs.tabDecorations); - } - - @Override - public TileEntity createNewTileEntity(World w) { - return null; - } - - @Override - public String getTextureFile() { - return "/cpw/mods/ironchest/sprites/block_textures.png"; - } - - @Override - public boolean isOpaqueCube() { - return false; - } - - @Override - public boolean renderAsNormalBlock() { - return false; - } - - @Override - public int getRenderType() { - return 22; - } - - @Override - public TileEntity createNewTileEntity(World world, int metadata) { - return IronChestType.makeEntity(metadata); - } - - 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) { - icte = (TileEntityIronChest) te; - } - if (l == 0 || l == 1) { // Top and Bottom - return type.getTextureRow() * 16 + 1; - } else if (icte != null && l == icte.getFacing()) { // Front - return type.getTextureRow() * 16 + 2; - } else { // Back and Sides - return type.getTextureRow() * 16; - } - } - - @Override - public int getBlockTextureFromSideAndMetadata(int i, int j) { - IronChestType typ = IronChestType.values()[j]; - switch (i) { - case 0: - case 1: - return typ.getTextureRow() * 16 + 1; - case 3: - return typ.getTextureRow() * 16 + 2; - default: - return typ.getTextureRow() * 16; - } - } - - @Override - 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)) + public BlockIronChest(int id) { - return true; + super(id, Material.iron); + setBlockName("IronChest"); + setHardness(3.0F); + setRequiresSelfNotify(); + setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); + random = new Random(); + setCreativeTab(CreativeTabs.tabDecorations); } - if (world.isBlockSolidOnSide(i, j + 1, k, ForgeDirection.DOWN)) + @Override + public TileEntity createNewTileEntity(World w) { - return true; + return null; } - if (world.isRemote) { - return true; - } - - player.openGui(IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k); - return true; - } - - @Override - 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) { - byte chestFacing = 0; - int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3; - if (facing == 0) { - chestFacing = 2; - } - if (facing == 1) { - chestFacing = 5; - } - if (facing == 2) { - chestFacing = 3; - } - if (facing == 3) { - chestFacing = 4; - } - TileEntity te = world.getBlockTileEntity(i, j, k); - if (te != null && te instanceof TileEntityIronChest) { - ((TileEntityIronChest) te).setFacing(chestFacing); - world.markBlockForUpdate(i, j, k); - } - } - - @Override - public int damageDropped(int i) { - return i; - } - - @Override - public void breakBlock(World world, int i, int j, int k, int i1, int i2) - { - TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k); - if (tileentitychest != null) + @Override + public String getTextureFile() { - dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord); + return "/cpw/mods/ironchest/sprites/block_textures.png"; } - super.breakBlock(world, i, j, k, i1, i2); - } - public void dropContent(int newSize, IInventory chest, World world, int xCoord, int yCoord, int zCoord) { - for (int l = newSize; l < chest.getSizeInventory(); l++) + @Override + public boolean isOpaqueCube() { - ItemStack itemstack = chest.getStackInSlot(l); - if (itemstack == null) - { - continue; - } - float f = random.nextFloat() * 0.8F + 0.1F; - float f1 = random.nextFloat() * 0.8F + 0.1F; - float f2 = random.nextFloat() * 0.8F + 0.1F; - while (itemstack.stackSize > 0) - { - int i1 = random.nextInt(21) + 10; - if (i1 > itemstack.stackSize) + return false; + } + + @Override + public boolean renderAsNormalBlock() + { + return false; + } + + @Override + public int getRenderType() + { + return 22; + } + + @Override + public TileEntity createNewTileEntity(World world, int metadata) + { + return IronChestType.makeEntity(metadata); + } + + 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) { - i1 = itemstack.stackSize; + icte = (TileEntityIronChest) te; } - itemstack.stackSize -= i1; - EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2, - new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage())); - float f3 = 0.05F; - entityitem.motionX = (float) random.nextGaussian() * f3; - entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F; - entityitem.motionZ = (float) random.nextGaussian() * f3; - if (itemstack.hasTagCompound()) - { - entityitem.item.setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); + if (l == 0 || l == 1) + { // Top and Bottom + return type.getTextureRow() * 16 + 1; + } + else if (icte != null && l == icte.getFacing()) + { // Front + return type.getTextureRow() * 16 + 2; + } + else + { // Back and Sides + return type.getTextureRow() * 16; } - world.spawnEntityInWorld(entityitem); - } } - } - @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) - @SideOnly(Side.CLIENT) - 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())); - } - } - } + @Override + public int getBlockTextureFromSideAndMetadata(int i, int j) + { + IronChestType typ = IronChestType.values()[j]; + switch (i) + { + case 0: + case 1: + return typ.getTextureRow() * 16 + 1; + case 3: + return typ.getTextureRow() * 16 + 2; + default: + return typ.getTextureRow() * 16; + } + } + + @Override + 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)) + { + return true; + } + + if (world.isBlockSolidOnSide(i, j + 1, k, ForgeDirection.DOWN)) + { + return true; + } + + if (world.isRemote) + { + return true; + } + + player.openGui(IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k); + return true; + } + + @Override + 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) + { + byte chestFacing = 0; + int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3; + if (facing == 0) + { + chestFacing = 2; + } + if (facing == 1) + { + chestFacing = 5; + } + if (facing == 2) + { + chestFacing = 3; + } + if (facing == 3) + { + chestFacing = 4; + } + TileEntity te = world.getBlockTileEntity(i, j, k); + if (te != null && te instanceof TileEntityIronChest) + { + ((TileEntityIronChest) te).setFacing(chestFacing); + world.markBlockForUpdate(i, j, k); + } + } + + @Override + public int damageDropped(int i) + { + return i; + } + + @Override + public void breakBlock(World world, int i, int j, int k, int i1, int i2) + { + TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k); + if (tileentitychest != null) + { + dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord); + } + super.breakBlock(world, i, j, k, i1, i2); + } + + 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); + if (itemstack == null) + { + continue; + } + float f = random.nextFloat() * 0.8F + 0.1F; + float f1 = random.nextFloat() * 0.8F + 0.1F; + float f2 = random.nextFloat() * 0.8F + 0.1F; + while (itemstack.stackSize > 0) + { + int i1 = random.nextInt(21) + 10; + if (i1 > itemstack.stackSize) + { + i1 = itemstack.stackSize; + } + itemstack.stackSize -= i1; + EntityItem entityitem = new EntityItem(world, (float) xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, (float) zCoord + f2, + new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage())); + float f3 = 0.05F; + entityitem.motionX = (float) random.nextGaussian() * f3; + entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F; + entityitem.motionZ = (float) random.nextGaussian() * f3; + if (itemstack.hasTagCompound()) + { + entityitem.func_92014_d().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); + } + world.spawnEntityInWorld(entityitem); + } + } + } + + @Override + @SuppressWarnings({ "rawtypes", "unchecked" }) + @SideOnly(Side.CLIENT) + 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())); + } + } + } } diff --git a/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java b/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java index a677a90..a88ebde 100644 --- a/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java +++ b/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java @@ -19,63 +19,72 @@ 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; - public String itemName; - public String descriptiveName; - private ItemChestChanger item; - private String[] recipe; + private IronChestType source; + private IronChestType target; + public String itemName; + public String descriptiveName; + private ItemChestChanger item; + private String[] recipe; - private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe) { - this.source = source; - this.target = target; - this.itemName = itemName; - this.descriptiveName = descriptiveName; - this.recipe = recipe; - } - - public boolean canUpgrade(IronChestType from) { - return from == this.source; - } - - public int getTarget() { - return this.target.ordinal(); - } - - 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()) { - 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); - } + private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe) + { + this.source = source; + this.target = target; + this.itemName = itemName; + this.descriptiveName = descriptiveName; + this.recipe = recipe; } - } - public static void buildItems(Configuration cfg, int defaultId) { - for (ChestChangerType type : values()) { - type.buildItem(cfg, defaultId++); + public boolean canUpgrade(IronChestType from) + { + return from == this.source; } - } - public static void generateRecipes() { - for (ChestChangerType item : values()) { - item.addRecipes(); + public int getTarget() + { + return this.target.ordinal(); + } + + 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()) + { + 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); + } + } + } + + public static void buildItems(Configuration cfg, int defaultId) + { + for (ChestChangerType type : values()) + { + type.buildItem(cfg, defaultId++); + } + } + + public static void generateRecipes() + { + for (ChestChangerType item : values()) + { + item.addRecipes(); + } } - } } diff --git a/IronChests2/common/cpw/mods/ironchest/CommonProxy.java b/IronChests2/common/cpw/mods/ironchest/CommonProxy.java index 9d4a256..3b1315c 100644 --- a/IronChests2/common/cpw/mods/ironchest/CommonProxy.java +++ b/IronChests2/common/cpw/mods/ironchest/CommonProxy.java @@ -16,34 +16,40 @@ import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; public class CommonProxy implements IGuiHandler { - public void registerRenderInformation() - { + public void registerRenderInformation() + { - } + } - public void registerTileEntitySpecialRenderer(IronChestType typ) - { + public void registerTileEntitySpecialRenderer(IronChestType typ) + { - } + } - @Override - public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - return null; - } + @Override + 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) { - TileEntity te = world.getBlockTileEntity(X, Y, Z); - if (te != null && te instanceof TileEntityIronChest) { - TileEntityIronChest icte = (TileEntityIronChest) te; - return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0); - } else { - return null; - } - } + @Override + 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) + { + TileEntityIronChest icte = (TileEntityIronChest) te; + return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0); + } + else + { + return null; + } + } - public World getClientWorld() { - return null; - } + public World getClientWorld() + { + return null; + } } diff --git a/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java b/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java index 28fd6d3..c26b06d 100644 --- a/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java +++ b/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java @@ -18,88 +18,94 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerIronChestBase extends Container { - private IronChestType type; - private EntityPlayer player; - private IInventory chest; + private IronChestType type; + private EntityPlayer player; + private IInventory chest; - public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { - chest = chestInventory; - player = ((InventoryPlayer) playerInventory).player; - this.type = type; - chestInventory.openChest(); - layoutContainer(playerInventory, chestInventory, type, xSize, ySize); - } - - @Override - public boolean canInteractWith(EntityPlayer player) - { - return chest.isUseableByPlayer(player); - } - - @Override - public ItemStack transferStackInSlot(EntityPlayer p, int i) - { - ItemStack itemstack = null; - Slot slot = (Slot) inventorySlots.get(i); - if (slot != null && slot.getHasStack()) + public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { - ItemStack itemstack1 = slot.getStack(); - itemstack = itemstack1.copy(); - if (i < type.size) - { - if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) + chest = chestInventory; + player = ((InventoryPlayer) playerInventory).player; + this.type = type; + chestInventory.openChest(); + layoutContainer(playerInventory, chestInventory, type, xSize, ySize); + } + + @Override + public boolean canInteractWith(EntityPlayer player) + { + return chest.isUseableByPlayer(player); + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer p, int i) + { + ItemStack itemstack = null; + Slot slot = (Slot) inventorySlots.get(i); + if (slot != null && slot.getHasStack()) { - return null; + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + if (i < type.size) + { + if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) + { + return null; + } + } + else if (!mergeItemStack(itemstack1, 0, type.size, false)) + { + return null; + } + if (itemstack1.stackSize == 0) + { + slot.putStack(null); + } + else + { + slot.onSlotChanged(); + } } - } else if (!mergeItemStack(itemstack1, 0, type.size, false)) - { - return null; - } - if (itemstack1.stackSize == 0) - { - slot.putStack(null); - } else - { - slot.onSlotChanged(); - } + return itemstack; } - return itemstack; - } - @Override - public void onCraftGuiClosed(EntityPlayer entityplayer) - { - super.onCraftGuiClosed(entityplayer); - chest.closeChest(); - } - - protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { - for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++) + @Override + public void onCraftGuiClosed(EntityPlayer entityplayer) { - for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++) - { - addSlotToContainer(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18)); - } - + super.onCraftGuiClosed(entityplayer); + chest.closeChest(); } - int leftCol = (xSize - 162) / 2 + 1; - for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++) + protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { - for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) - { - addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10)); - } + for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++) + { + for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++) + { + addSlotToContainer(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18)); + } + } + + int leftCol = (xSize - 162) / 2 + 1; + for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++) + { + for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) + { + addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 + - 10)); + } + + } + + for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) + { + addSlotToContainer(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24)); + } } - for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) + public EntityPlayer getPlayer() { - addSlotToContainer(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24)); + return player; } - } - - public EntityPlayer getPlayer() { - return player; - } } diff --git a/IronChests2/common/cpw/mods/ironchest/IronChest.java b/IronChests2/common/cpw/mods/ironchest/IronChest.java index 1e65f7c..cae3b49 100644 --- a/IronChests2/common/cpw/mods/ironchest/IronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/IronChest.java @@ -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; @@ -29,59 +30,71 @@ import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; -@Mod(modid = "IronChest", name = "Iron Chests", dependencies="required-after:Forge@[6.0,)") +@Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[6.0,)") @NetworkMod(channels = { "IronChest" }, versionBounds = "[4.2,)", clientSideRequired = true, serverSideRequired = false, packetHandler = PacketHandler.class) public class IronChest { - public static BlockIronChest ironChestBlock; - @SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy") - public static CommonProxy proxy; - @Instance("IronChest") - public static IronChest instance; - public static boolean CACHE_RENDER = true; - public static boolean OCELOTS_SITONCHESTS = true; - private int blockId; + public static BlockIronChest ironChestBlock; + @SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy") + public static CommonProxy proxy; + @Instance("IronChest") + public static IronChest instance; + public static boolean CACHE_RENDER = true; + public static boolean OCELOTS_SITONCHESTS = true; + private int blockId; - @PreInit - public void preInit(FMLPreInitializationEvent event) { - Version.init(event.getVersionProperties()); - event.getModMetadata().version = Version.fullVersionString(); - Configuration cfg = new Configuration(event.getSuggestedConfigurationFile()); - 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) { - FMLLog.log(Level.SEVERE, e, "IronChest has a problem loading it's configuration"); - } finally { - cfg.save(); - } - } + @PreInit + public void preInit(FMLPreInitializationEvent event) + { + Version.init(event.getVersionProperties()); + event.getModMetadata().version = Version.fullVersionString(); + Configuration cfg = new Configuration(event.getSuggestedConfigurationFile()); + 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) + { + FMLLog.log(Level.SEVERE, e, "IronChest has a problem loading it's configuration"); + } + finally + { + cfg.save(); + } + } - @Init - public void load(FMLInitializationEvent evt) { - ironChestBlock = new BlockIronChest(blockId); - GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class); - 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()) { - LanguageRegistry.instance().addStringLocalization("item." + typ.itemName + ".name", "en_US", typ.descriptiveName); - } - IronChestType.generateTieredRecipes(ironChestBlock); - ChestChangerType.generateRecipes(); - NetworkRegistry.instance().registerGuiHandler(instance, proxy); - proxy.registerRenderInformation(); - if (OCELOTS_SITONCHESTS) - { - MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); - } - } + @Init + public void load(FMLInitializationEvent evt) + { + ironChestBlock = new BlockIronChest(blockId); + GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class); + 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()) + { + LanguageRegistry.instance().addStringLocalization("item." + typ.itemName + ".name", "en_US", typ.descriptiveName); + } + IronChestType.generateTieredRecipes(ironChestBlock); + ChestChangerType.generateRecipes(); + NetworkRegistry.instance().registerGuiHandler(instance, proxy); + proxy.registerRenderInformation(); + if (OCELOTS_SITONCHESTS) + { + MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); + } + MinecraftForge.EVENT_BUS.register(this); + } + + @PostInit + public void modsLoaded(FMLPostInitializationEvent evt) + { + } - @PostInit - public void modsLoaded(FMLPostInitializationEvent evt) { - } } diff --git a/IronChests2/common/cpw/mods/ironchest/IronChestAIOcelotSit.java b/IronChests2/common/cpw/mods/ironchest/IronChestAIOcelotSit.java index c05cc9e..6e8c87b 100644 --- a/IronChests2/common/cpw/mods/ironchest/IronChestAIOcelotSit.java +++ b/IronChests2/common/cpw/mods/ironchest/IronChestAIOcelotSit.java @@ -5,15 +5,18 @@ import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.world.World; public class IronChestAIOcelotSit extends EntityAIOcelotSit { - public IronChestAIOcelotSit(EntityOcelot par1EntityOcelot, float par2) { - super(par1EntityOcelot, 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) { - return true; - } - return super.isSittableBlock(world, x, y, z); - } + @Override + 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); + } } diff --git a/IronChests2/common/cpw/mods/ironchest/IronChestType.java b/IronChests2/common/cpw/mods/ironchest/IronChestType.java index 4f4a2a3..fb126a2 100644 --- a/IronChests2/common/cpw/mods/ironchest/IronChestType.java +++ b/IronChests2/common/cpw/mods/ironchest/IronChestType.java @@ -22,143 +22,182 @@ 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); - int size; - private int rowLength; - public String friendlyName; - private boolean tieredChest; - private String modelTexture; - private int textureRow; - public Class clazz; - private String[] recipes; - private ArrayList matList; + 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; + private boolean tieredChest; + private String modelTexture; + private int textureRow; + public Class clazz; + private String[] recipes; + private ArrayList matList; - IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List mats, - Class clazz, String... recipes) { - this.size = size; - this.rowLength = rowLength; - this.tieredChest = tieredChest; - this.friendlyName = friendlyName; - this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture; - this.textureRow = textureRow; - this.clazz = clazz; - this.recipes = recipes; - this.matList = new ArrayList(); - matList.addAll(mats); - } - - public String getModelTexture() { - return modelTexture; - } - - public int getTextureRow() { - return textureRow; - } - - public static TileEntityIronChest makeEntity(int metadata) { - // Compatibility - int chesttype = validateMeta(metadata); - if (chesttype == metadata) { - try { - TileEntityIronChest te = values()[chesttype].clazz.newInstance(); - return te; - } catch (InstantiationException e) { - // unpossible - e.printStackTrace(); - } catch (IllegalAccessException e) { - // unpossible - e.printStackTrace(); - } + IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List mats, + Class clazz, String... recipes) + { + this.size = size; + this.rowLength = rowLength; + this.tieredChest = tieredChest; + this.friendlyName = friendlyName; + this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture; + this.textureRow = textureRow; + this.clazz = clazz; + this.recipes = recipes; + this.matList = new ArrayList(); + matList.addAll(mats); } - return null; - } - public static void registerTranslations() { - } - - public static void generateTieredRecipes(BlockIronChest blockResult) { - ItemStack previous = new ItemStack(Block.chest); - for (IronChestType typ : values()) { - generateRecipesForType(blockResult, previous, typ); - if (typ.tieredChest) - previous = new ItemStack(blockResult, 1, typ.ordinal()); + public String getModelTexture() + { + return modelTexture; } - } - 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) { - 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*/ - '1', new ItemStack(blockResult, 1, 1), /* Gold Chest*/ - '2', new ItemStack(blockResult, 1, 1), /* Diamond Chest*/ - '3', new ItemStack(blockResult, 1, 3), /* Copper Chest */ - '4', new ItemStack(blockResult, 1, 4)/* Silver Chest */ - ); - } + public int getTextureRow() + { + return textureRow; } - } - public static Object translateOreName(String mat) { - if (mat == "ingotIron" ) { - return Item.ingotIron; - } else if (mat == "ingotGold") { - return Item.ingotGold; - } else if (mat == "gemDiamond") { - return Item.diamond; - } else if (mat == "blockGlass") { - return Block.glass; - } else if (mat == "blockPlanks") { - return Block.planks; + public static TileEntityIronChest makeEntity(int metadata) + { + // Compatibility + int chesttype = validateMeta(metadata); + if (chesttype == metadata) + { + try + { + TileEntityIronChest te = values()[chesttype].clazz.newInstance(); + return te; + } + catch (InstantiationException e) + { + // unpossible + e.printStackTrace(); + } + catch (IllegalAccessException e) + { + // unpossible + e.printStackTrace(); + } + } + return null; } - return mat; - } - @SuppressWarnings("unchecked") - public static void addRecipe(ItemStack is, Object... parts) { - ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts); - GameRegistry.addRecipe(oreRecipe); - } - - public int getRowCount() { - return size / rowLength; - } - - public int getRowLength() { - return rowLength; - } - - public boolean isTransparent() { - return this == CRYSTAL; - } - - public List getMatList() { - return matList; - } - - public static int validateMeta(int i) { - if (i < values().length && values()[i].size>0) { - return i; - } else { - return 0; + public static void registerTranslations() + { } - } - public boolean isValidForCreativeMode() { - return validateMeta(ordinal())==ordinal(); - } + public static void generateTieredRecipes(BlockIronChest blockResult) + { + ItemStack previous = new ItemStack(Block.chest); + for (IronChestType typ : values()) + { + generateRecipesForType(blockResult, previous, typ); + 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) + { + String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) }; + Object mainMaterial = null; + 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 + */ + '1', new ItemStack(blockResult, 1, 1), /* Gold Chest */ + '2', new ItemStack(blockResult, 1, 1), /* Diamond Chest */ + '3', new ItemStack(blockResult, 1, 3), /* Copper Chest */ + '4', new ItemStack(blockResult, 1, 4)/* Silver Chest */ + ); + } + } + } + + public static Object translateOreName(String mat) + { + if (mat == "ingotIron") + { + return Item.ingotIron; + } + else if (mat == "ingotGold") + { + return Item.ingotGold; + } + else if (mat == "gemDiamond") + { + return Item.diamond; + } + else if (mat == "blockGlass") + { + return Block.glass; + } + else if (mat == "blockPlanks") + { + return Block.planks; + } + return mat; + } + + @SuppressWarnings("unchecked") + public static void addRecipe(ItemStack is, Object... parts) + { + ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts); + GameRegistry.addRecipe(oreRecipe); + } + + public int getRowCount() + { + return size / rowLength; + } + + public int getRowLength() + { + return rowLength; + } + + public boolean isTransparent() + { + return this == CRYSTAL; + } + + public List getMatList() + { + return matList; + } + + public static int validateMeta(int i) + { + if (i < values().length && values()[i].size > 0) + { + return i; + } + else + { + return 0; + } + } + + public boolean isValidForCreativeMode() + { + return validateMeta(ordinal()) == ordinal(); + } } diff --git a/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java b/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java index bf1b85f..8fb0b58 100644 --- a/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java +++ b/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java @@ -21,79 +21,92 @@ import cpw.mods.fml.common.ObfuscationReflectionHelper; public class ItemChestChanger extends Item { - private ChestChangerType type; + private ChestChangerType type; - public ItemChestChanger(int id, ChestChangerType type) { - super(id); - setMaxStackSize(1); - this.type=type; - setIconIndex(type.ordinal()); - setItemName(type.itemName); - setCreativeTab(CreativeTabs.tabMisc); - } + public ItemChestChanger(int id, ChestChangerType type) + { + super(id); + setMaxStackSize(1); + this.type = type; + setIconIndex(type.ordinal()); + setItemName(type.itemName); + setCreativeTab(CreativeTabs.tabMisc); + } - @Override - public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side) { - if (world.isRemote) - return false; - TileEntity te=world.getBlockTileEntity(X,Y,Z); - TileEntityIronChest newchest; - if (te!=null && te instanceof TileEntityIronChest) { - TileEntityIronChest ironchest=(TileEntityIronChest)te; - newchest=ironchest.applyUpgradeItem(this); - if (newchest==null) { - return false; - } - } else if (te!=null && te instanceof TileEntityChest) { - TileEntityChest tec = (TileEntityChest) te; - if (tec.numUsingPlayers > 0) { - return false; - } - if (!getType().canUpgrade(IronChestType.WOOD)) { - return false; - } - // Force old TE out of the world so that adjacent chests can update - newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal())); - int newSize = newchest.chestContents.length; - ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0); - System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length)); - BlockIronChest block = IronChest.ironChestBlock; - block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord); - newchest.setFacing((byte)tec.getBlockMetadata()); - newchest.sortTopStacks(); - for (int i = 0; i< Math.min(newSize, chestContents.length); i++) - { - chestContents[i]=null; - } - // Clear the old block out - 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 - tec.checkForAdjacentChests(); - // And put in our block instead - world.setBlock(X, Y, Z, block.blockID); - } else { - return false; - } - world.setBlockTileEntity(X, Y, Z, newchest); - world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal()); - world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z)); - world.markBlockForUpdate(X, Y, Z); - stack.stackSize=0; - return true; - } + @Override + 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) + { + TileEntityIronChest ironchest = (TileEntityIronChest) te; + newchest = ironchest.applyUpgradeItem(this); + if (newchest == null) + { + return false; + } + } + else if (te != null && te instanceof TileEntityChest) + { + TileEntityChest tec = (TileEntityChest) te; + if (tec.numUsingPlayers > 0) + { + return false; + } + if (!getType().canUpgrade(IronChestType.WOOD)) + { + return false; + } + // Force old TE out of the world so that adjacent chests can update + newchest = IronChestType.makeEntity(getTargetChestOrdinal(IronChestType.WOOD.ordinal())); + int newSize = newchest.chestContents.length; + ItemStack[] chestContents = ObfuscationReflectionHelper.getPrivateValue(TileEntityChest.class, tec, 0); + System.arraycopy(chestContents, 0, newchest.chestContents, 0, Math.min(newSize, chestContents.length)); + BlockIronChest block = IronChest.ironChestBlock; + block.dropContent(newSize, tec, world, tec.xCoord, tec.yCoord, tec.zCoord); + newchest.setFacing((byte) tec.getBlockMetadata()); + newchest.sortTopStacks(); + for (int i = 0; i < Math.min(newSize, chestContents.length); i++) + { + chestContents[i] = null; + } + // Clear the old block out + 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 + tec.checkForAdjacentChests(); + // And put in our block instead + world.setBlock(X, Y, Z, block.blockID); + } + else + { + return false; + } + world.setBlockTileEntity(X, Y, Z, newchest); + world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal()); + world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z)); + world.markBlockForUpdate(X, Y, Z); + stack.stackSize = 0; + return true; + } - @Override - public String getTextureFile() { - return "/cpw/mods/ironchest/sprites/item_textures.png"; - } + @Override + public String getTextureFile() + { + return "/cpw/mods/ironchest/sprites/item_textures.png"; + } - public int getTargetChestOrdinal(int sourceOrdinal) { - return type.getTarget(); - } + public int getTargetChestOrdinal(int sourceOrdinal) + { + return type.getTarget(); + } - public ChestChangerType getType() { - return type; - } + public ChestChangerType getType() + { + return type; + } } diff --git a/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java b/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java index ab4a0f5..a93f795 100644 --- a/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/ItemIronChest.java @@ -15,18 +15,22 @@ import net.minecraft.item.ItemStack; public class ItemIronChest extends ItemBlock { - public ItemIronChest(int id) { - super(id); + public ItemIronChest(int id) + { + super(id); setMaxDamage(0); setHasSubtypes(true); - } + } - @Override - public int getMetadata(int i) { - return IronChestType.validateMeta(i); - } - @Override - public String getItemNameIS(ItemStack itemstack) { - return IronChestType.values()[itemstack.getItemDamage()].name(); - } + @Override + public int getMetadata(int i) + { + return IronChestType.validateMeta(i); + } + + @Override + public String getItemNameIS(ItemStack itemstack) + { + return IronChestType.values()[itemstack.getItemDamage()].name(); + } } diff --git a/IronChests2/common/cpw/mods/ironchest/MappableItemStackWrapper.java b/IronChests2/common/cpw/mods/ironchest/MappableItemStackWrapper.java index 2361199..e74a7f5 100644 --- a/IronChests2/common/cpw/mods/ironchest/MappableItemStackWrapper.java +++ b/IronChests2/common/cpw/mods/ironchest/MappableItemStackWrapper.java @@ -3,24 +3,31 @@ package cpw.mods.ironchest; import net.minecraft.item.ItemStack; public class MappableItemStackWrapper { - private ItemStack wrap; + private ItemStack wrap; - public MappableItemStackWrapper(ItemStack toWrap) { - wrap=toWrap; - } - @Override - public boolean equals(Object obj) { - if (!(obj instanceof MappableItemStackWrapper)) return false; - MappableItemStackWrapper isw = (MappableItemStackWrapper) obj; - if (wrap.getHasSubtypes()) { - return isw.wrap.isItemEqual(wrap); - } else { - return isw.wrap.itemID == wrap.itemID; + public MappableItemStackWrapper(ItemStack toWrap) + { + wrap = toWrap; } - } - @Override - public int hashCode() { - return wrap.itemID; - } + @Override + public boolean equals(Object obj) + { + if (!(obj instanceof MappableItemStackWrapper)) return false; + MappableItemStackWrapper isw = (MappableItemStackWrapper) obj; + if (wrap.getHasSubtypes()) + { + return isw.wrap.isItemEqual(wrap); + } + else + { + return isw.wrap.itemID == wrap.itemID; + } + } + + @Override + public int hashCode() + { + return wrap.itemID; + } } diff --git a/IronChests2/common/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java b/IronChests2/common/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java index bc640e3..bb994c7 100644 --- a/IronChests2/common/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java +++ b/IronChests2/common/cpw/mods/ironchest/OcelotsSitOnChestsHandler.java @@ -9,22 +9,23 @@ import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingEvent; public class OcelotsSitOnChestsHandler { - @ForgeSubscribe - public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt) { - if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot) - { - EntityOcelot ocelot = (EntityOcelot) evt.entityLiving; - @SuppressWarnings("unchecked") - List tasks = ocelot.tasks.taskEntries; + @ForgeSubscribe + public void changeSittingTaskForOcelots(LivingEvent.LivingUpdateEvent evt) + { + if (evt.entityLiving.ticksExisted < 5 && evt.entityLiving instanceof EntityOcelot) + { + EntityOcelot ocelot = (EntityOcelot) evt.entityLiving; + @SuppressWarnings("unchecked") + List tasks = ocelot.tasks.taskEntries; - for (int i=0; i() { - @Override - public int compare(ItemStack o1, ItemStack o2) { - if (o1 == null) { - return 1; - } else if (o2 == null) { - return -1; - } 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) { - topStacks[p++] = tempCopy[i]; - if (p == topStacks.length) { - break; - } - } - } - for (int i = p; i < topStacks.length; i++) { - topStacks[i] = null; - } - if (worldObj!=null) { - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - } - } - - @Override - public ItemStack decrStackSize(int i, int j) { - if (chestContents[i] != null) + public TileEntityIronChest() { - if (chestContents[i].stackSize <= j) - { - ItemStack itemstack = chestContents[i]; - chestContents[i] = null; - onInventoryChanged(); - return itemstack; - } - ItemStack itemstack1 = chestContents[i].splitStack(j); - if (chestContents[i].stackSize == 0) - { - chestContents[i] = null; - } - onInventoryChanged(); - return itemstack1; + this(IronChestType.IRON); } - else + + protected TileEntityIronChest(IronChestType type) { - return null; + super(); + this.type = type; + this.chestContents = new ItemStack[getSizeInventory()]; + this.topStacks = new ItemStack[8]; } - } - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - chestContents[i] = itemstack; - if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + public ItemStack[] getContents() { - itemstack.stackSize = getInventoryStackLimit(); + return chestContents; } - onInventoryChanged(); - } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) - { - super.readFromNBT(nbttagcompound); - NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); - chestContents = new ItemStack[getSizeInventory()]; - for (int i = 0; i < nbttaglist.tagCount(); i++) + @Override + public int getSizeInventory() { - NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i); - int j = nbttagcompound1.getByte("Slot") & 0xff; - if (j >= 0 && j < chestContents.length) - { - chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); - } + return type.size; } - facing = nbttagcompound.getByte("facing"); - sortTopStacks(); - } - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) - { - super.writeToNBT(nbttagcompound); - NBTTagList nbttaglist = new NBTTagList(); - for (int i = 0; i < chestContents.length; i++) + public byte getFacing() { - if (chestContents[i] != null) - { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - chestContents[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } + return this.facing; } - nbttagcompound.setTag("Items", nbttaglist); - nbttagcompound.setByte("facing", facing); - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - if (worldObj == null) { - return true; + @Override + public String getInvName() + { + return type.name(); } - 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() { - super.updateEntity(); - // Resynchronize clients with the server state - if ((++ticksSinceSync % 20) * 4 == 0) { - worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); - if (inventoryTouched) { - inventoryTouched = false; + public IronChestType getType() + { + return type; + } + + @Override + public ItemStack getStackInSlot(int i) + { + inventoryTouched = true; + return chestContents[i]; + } + + @Override + public void onInventoryChanged() + { + super.onInventoryChanged(); sortTopStacks(); - } } - prevLidAngle = lidAngle; - float f = 0.1F; - 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) { - float f1 = lidAngle; - if (numUsingPlayers > 0) { - lidAngle += f; - } else { - lidAngle -= f; - } - if (lidAngle > 1.0F) { - lidAngle = 1.0F; - } - float f2 = 0.5F; - 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) { - lidAngle = 0.0F; - } - } - } - - @Override - public void receiveClientEvent(int i, int j) - { - if (i == 1) + protected void sortTopStacks() { - numUsingPlayers = j; - } else if (i == 2) { - facing = (byte) j; - } else if (i == 3) { - facing = (byte) (j & 0x7); - numUsingPlayers = (j & 0xF8) >> 3; - } - } - - @Override - 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; - numUsingPlayers--; - worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers); - } - - public void setFacing(byte chestFacing) { - this.facing = chestFacing; - } - - public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) { - if (numUsingPlayers > 0) { - return null; - } - if (!itemChestChanger.getType().canUpgrade(this.getType())) { - return null; - } - TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal())); - int newSize = newEntity.chestContents.length; - System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length)); - BlockIronChest block = IronChest.ironChestBlock; - block.dropContent(newSize, this, this.worldObj, this.xCoord, this.yCoord, this.zCoord); - newEntity.setFacing(facing); - newEntity.sortTopStacks(); - return newEntity; - } - - public ItemStack[] getTopItemStacks() { - return topStacks; - } - - 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); - } - } - return this; - } - - @Override - public Packet getDescriptionPacket() { - return PacketHandler.getPacket(this); - } - - public void handlePacketData(int typeData, int[] intData) { - TileEntityIronChest chest = this; - if (this.type.ordinal() != typeData) { - chest = updateFromMetadata(typeData); - } - if (IronChestType.values()[typeData].isTransparent() && intData != null) { - int pos = 0; - if (intData.length < chest.topStacks.length * 3) { - return; - } - 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 { - chest.topStacks[i] = null; + if (!type.isTransparent() || (worldObj != null && worldObj.isRemote)) + { + return; } - pos += 3; - } - } - } - - public int[] buildIntDataList() { - if (type.isTransparent()) { - int[] sortList = new int[topStacks.length * 3]; - int pos = 0; - for (ItemStack is : topStacks) { - if (is != null) { - sortList[pos++] = is.itemID; - sortList[pos++] = is.getItemDamage(); - sortList[pos++] = is.stackSize; - } else { - sortList[pos++] = 0; - sortList[pos++] = 0; - sortList[pos++] = 0; + 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])) + { + tempCopy[j].stackSize += chestContents[i].stackSize; + continue mainLoop; + } + } + tempCopy[compressedIdx++] = chestContents[i].copy(); + hasStuff = true; + } + } + if (!hasStuff && hadStuff) + { + hadStuff = false; + for (int i = 0; i < topStacks.length; i++) + { + topStacks[i] = null; + } + if (worldObj != null) + { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + return; + } + hadStuff = true; + Arrays.sort(tempCopy, new Comparator() { + @Override + public int compare(ItemStack o1, ItemStack o2) + { + if (o1 == null) + { + return 1; + } + else if (o2 == null) + { + return -1; + } + 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) + { + topStacks[p++] = tempCopy[i]; + if (p == topStacks.length) + { + break; + } + } + } + for (int i = p; i < topStacks.length; i++) + { + topStacks[i] = null; + } + if (worldObj != null) + { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } - } - return sortList; } - return null; - } - public ItemStack getStackInSlotOnClosing(int par1) - { - if (this.chestContents[par1] != null) + @Override + public ItemStack decrStackSize(int i, int j) { - ItemStack var2 = this.chestContents[par1]; - this.chestContents[par1] = null; - return var2; + if (chestContents[i] != null) + { + if (chestContents[i].stackSize <= j) + { + ItemStack itemstack = chestContents[i]; + chestContents[i] = null; + onInventoryChanged(); + return itemstack; + } + ItemStack itemstack1 = chestContents[i].splitStack(j); + if (chestContents[i].stackSize == 0) + { + chestContents[i] = null; + } + onInventoryChanged(); + return itemstack1; + } + else + { + return null; + } } - else - { - return null; - } - } - public void setMaxStackSize(int size) { - } + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) + { + chestContents[i] = itemstack; + if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + { + itemstack.stackSize = getInventoryStackLimit(); + } + onInventoryChanged(); + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) + { + super.readFromNBT(nbttagcompound); + NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); + chestContents = new ItemStack[getSizeInventory()]; + for (int i = 0; i < nbttaglist.tagCount(); i++) + { + NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i); + int j = nbttagcompound1.getByte("Slot") & 0xff; + if (j >= 0 && j < chestContents.length) + { + chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + } + } + facing = nbttagcompound.getByte("facing"); + sortTopStacks(); + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) + { + super.writeToNBT(nbttagcompound); + NBTTagList nbttaglist = new NBTTagList(); + for (int i = 0; i < chestContents.length; i++) + { + if (chestContents[i] != null) + { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte) i); + chestContents[i].writeToNBT(nbttagcompound1); + nbttaglist.appendTag(nbttagcompound1); + } + } + + nbttagcompound.setTag("Items", nbttaglist); + nbttagcompound.setByte("facing", facing); + } + + @Override + public int getInventoryStackLimit() + { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + if (worldObj == null) + { + return true; + } + 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() + { + super.updateEntity(); + // Resynchronize clients with the server state + if ((++ticksSinceSync % 20) * 4 == 0) + { + worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); + if (inventoryTouched) + { + inventoryTouched = false; + sortTopStacks(); + } + } + prevLidAngle = lidAngle; + float f = 0.1F; + 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) + { + float f1 = lidAngle; + if (numUsingPlayers > 0) + { + lidAngle += f; + } + else + { + lidAngle -= f; + } + if (lidAngle > 1.0F) + { + lidAngle = 1.0F; + } + float f2 = 0.5F; + 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) + { + lidAngle = 0.0F; + } + } + } + + @Override + public void receiveClientEvent(int i, int j) + { + if (i == 1) + { + numUsingPlayers = j; + } + else if (i == 2) + { + facing = (byte) j; + } + else if (i == 3) + { + facing = (byte) (j & 0x7); + numUsingPlayers = (j & 0xF8) >> 3; + } + } + + @Override + 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; + numUsingPlayers--; + worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock.blockID, 1, numUsingPlayers); + } + + public void setFacing(byte chestFacing) + { + this.facing = chestFacing; + } + + public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) + { + if (numUsingPlayers > 0) + { + return null; + } + if (!itemChestChanger.getType().canUpgrade(this.getType())) + { + return null; + } + TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal())); + int newSize = newEntity.chestContents.length; + System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length)); + BlockIronChest block = IronChest.ironChestBlock; + block.dropContent(newSize, this, this.worldObj, this.xCoord, this.yCoord, this.zCoord); + newEntity.setFacing(facing); + newEntity.sortTopStacks(); + return newEntity; + } + + public ItemStack[] getTopItemStacks() + { + return topStacks; + } + + 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); + } + } + return this; + } + + @Override + public Packet getDescriptionPacket() + { + return PacketHandler.getPacket(this); + } + + public void handlePacketData(int typeData, int[] intData) + { + TileEntityIronChest chest = this; + if (this.type.ordinal() != typeData) + { + chest = updateFromMetadata(typeData); + } + if (IronChestType.values()[typeData].isTransparent() && intData != null) + { + int pos = 0; + if (intData.length < chest.topStacks.length * 3) + { + return; + } + 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 + { + chest.topStacks[i] = null; + } + pos += 3; + } + } + } + + public int[] buildIntDataList() + { + if (type.isTransparent()) + { + int[] sortList = new int[topStacks.length * 3]; + int pos = 0; + for (ItemStack is : topStacks) + { + if (is != null) + { + sortList[pos++] = is.itemID; + sortList[pos++] = is.getItemDamage(); + sortList[pos++] = is.stackSize; + } + else + { + sortList[pos++] = 0; + sortList[pos++] = 0; + sortList[pos++] = 0; + } + } + return sortList; + } + return null; + } + + public ItemStack getStackInSlotOnClosing(int par1) + { + if (this.chestContents[par1] != null) + { + ItemStack var2 = this.chestContents[par1]; + this.chestContents[par1] = null; + return var2; + } + else + { + return null; + } + } + + public void setMaxStackSize(int size) + { + + } } diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntitySilverChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntitySilverChest.java index 7dbad65..439d266 100644 --- a/IronChests2/common/cpw/mods/ironchest/TileEntitySilverChest.java +++ b/IronChests2/common/cpw/mods/ironchest/TileEntitySilverChest.java @@ -11,7 +11,8 @@ package cpw.mods.ironchest; public class TileEntitySilverChest extends TileEntityIronChest { - public TileEntitySilverChest() { - super(IronChestType.SILVER); - } + public TileEntitySilverChest() + { + super(IronChestType.SILVER); + } } diff --git a/IronChests2/common/cpw/mods/ironchest/Version.java b/IronChests2/common/cpw/mods/ironchest/Version.java index b3298b2..07096d7 100644 --- a/IronChests2/common/cpw/mods/ironchest/Version.java +++ b/IronChests2/common/cpw/mods/ironchest/Version.java @@ -9,23 +9,26 @@ package cpw.mods.ironchest; import java.util.Properties; public class Version { - private static String major; - private static String minor; - private static String rev; - private static String build; - private static String mcversion; + private static String major; + private static String minor; + private static String rev; + private static String build; + private static String mcversion; - 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"); - build = properties.getProperty("IronChest.build.number"); - mcversion = properties.getProperty("IronChest.build.mcversion"); + 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"); + build = properties.getProperty("IronChest.build.number"); + mcversion = properties.getProperty("IronChest.build.mcversion"); + } } - } - public static String fullVersionString() { - return String.format("%s.%s.%s build %s", major,minor,rev, build); - } + public static String fullVersionString() + { + return String.format("%s.%s.%s build %s", major, minor, rev, build); + } } diff --git a/IronChests2/common/cpw/mods/ironchest/client/ClientProxy.java b/IronChests2/common/cpw/mods/ironchest/client/ClientProxy.java new file mode 100644 index 0000000..06b0cff --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/client/ClientProxy.java @@ -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; + } + } +} diff --git a/IronChests2/common/cpw/mods/ironchest/client/GUIChest.java b/IronChests2/common/cpw/mods/ironchest/client/GUIChest.java new file mode 100644 index 0000000..31b4b4e --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/client/GUIChest.java @@ -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); + } +} diff --git a/IronChests2/client/cpw/mods/ironchest/client/IronChestRenderHelper.java b/IronChests2/common/cpw/mods/ironchest/client/IronChestRenderHelper.java similarity index 58% rename from IronChests2/client/cpw/mods/ironchest/client/IronChestRenderHelper.java rename to IronChests2/common/cpw/mods/ironchest/client/IronChestRenderHelper.java index dcb512c..3b51b9d 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/IronChestRenderHelper.java +++ b/IronChests2/common/cpw/mods/ironchest/client/IronChestRenderHelper.java @@ -23,20 +23,26 @@ import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.TileEntityIronChest; public class IronChestRenderHelper extends ChestItemRenderHelper { - private Map itemRenders = Maps.newHashMap(); + private Map itemRenders = Maps.newHashMap(); - 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) { - TileEntityRenderer.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F); - } else { - super.renderChest(block, i, f); - } - } + 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) + { + TileEntityRenderer.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F); + } + else + { + super.renderChest(block, i, f); + } + } } diff --git a/IronChests2/common/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java b/IronChests2/common/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java new file mode 100644 index 0000000..bf47c07 --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java @@ -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 renderList = new HashMap(); + + 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; +}