From 138274e1e9dfbb6e4a49fe919a94fbe77296737a Mon Sep 17 00:00:00 2001 From: Taylor Shuler Date: Sun, 11 May 2014 16:00:59 -0400 Subject: [PATCH] The Great Wall of Pink (purely aesthetic changes, no logic altered) --- .../cpw/mods/ironchest/BlockIronChest.java | 512 +++++------ .../cpw/mods/ironchest/ChestChangerType.java | 115 ++- .../java/cpw/mods/ironchest/CommonProxy.java | 53 +- .../mods/ironchest/ContainerIronChest.java | 161 ++-- .../java/cpw/mods/ironchest/IronChest.java | 56 +- .../cpw/mods/ironchest/IronChestType.java | 366 ++++---- .../cpw/mods/ironchest/ItemChestChanger.java | 148 ++-- .../cpw/mods/ironchest/ItemIronChest.java | 32 +- .../ironchest/MappableItemStackWrapper.java | 45 +- .../cpw/mods/ironchest/PacketHandler.java | 301 ++++--- .../mods/ironchest/TileEntityCopperChest.java | 9 +- .../ironchest/TileEntityCrystalChest.java | 9 +- .../ironchest/TileEntityDiamondChest.java | 9 +- .../mods/ironchest/TileEntityDirtChest.java | 60 +- .../mods/ironchest/TileEntityGoldChest.java | 9 +- .../mods/ironchest/TileEntityIronChest.java | 801 ++++++++---------- .../ironchest/TileEntityObsidianChest.java | 9 +- .../mods/ironchest/TileEntitySilverChest.java | 9 +- .../cpw/mods/ironchest/ValidatingSlot.java | 22 +- src/main/java/cpw/mods/ironchest/Version.java | 31 +- .../mods/ironchest/client/ClientProxy.java | 51 +- .../cpw/mods/ironchest/client/GUIChest.java | 88 -- .../mods/ironchest/client/GuiIronChest.java | 81 ++ .../client/IronChestRenderHelper.java | 38 +- .../client/TileEntityIronChestRenderer.java | 260 +++--- 25 files changed, 1443 insertions(+), 1832 deletions(-) delete mode 100644 src/main/java/cpw/mods/ironchest/client/GUIChest.java create mode 100644 src/main/java/cpw/mods/ironchest/client/GuiIronChest.java diff --git a/src/main/java/cpw/mods/ironchest/BlockIronChest.java b/src/main/java/cpw/mods/ironchest/BlockIronChest.java index 7a049e9..ad3ff3b 100644 --- a/src/main/java/cpw/mods/ironchest/BlockIronChest.java +++ b/src/main/java/cpw/mods/ironchest/BlockIronChest.java @@ -36,308 +36,242 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class BlockIronChest extends BlockContainer { + private Random random = new Random(); - private Random random; + public BlockIronChest() { + super(Material.iron); + setBlockName("IronChest"); + setHardness(3.0F); + setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); + setCreativeTab(CreativeTabs.tabDecorations); + } - @SideOnly(Side.CLIENT) - private IIcon[][] icons; - - public BlockIronChest() - { - super(Material.iron); - setBlockName("IronChest"); - setHardness(3.0F); - setBlockBounds(0.0625F, 0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); - random = new Random(); - setCreativeTab(CreativeTabs.tabDecorations); - } - - /** - * Overridden by {@link #createTileEntity(World, int)} - */ - @Override - public TileEntity createNewTileEntity(World w, int i) - { - return null; - } - - @Override - public boolean isOpaqueCube() - { - return false; - } - - @Override - public boolean renderAsNormalBlock() - { - return false; - } - - @Override - public int getRenderType() - { - return 22; - } - - @Override - public TileEntity createTileEntity(World world, int metadata) - { - return IronChestType.makeEntity(metadata); - } - - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(int i, int j) - { - if (j < IronChestType.values().length) - { - IronChestType type = IronChestType.values()[j]; - return type.getIcon(i); - } - return null; - } - - @Override - public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) - { - ArrayList items = Lists.newArrayList(); - ItemStack stack = new ItemStack(this,1,metadata); - IronChestType.values()[IronChestType.validateMeta(metadata)].adornItemDrop(stack); - items.add(stack); - return items; - } - - @Override - public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3) - { - if (world.isRemote) - return true; - else - { - IInventory iinventory = chestInventory(world, i, j, k); - - if (iinventory != null && world.getTileEntity(i, j, k) instanceof TileEntityIronChest) - player.openGui(IronChest.instance, ((TileEntityIronChest) world.getTileEntity(i, j, k)).getType().ordinal(), world, i, j, k); - - return true; - } - } - - public IInventory chestInventory(World world, int i, int j, int k) - { - TileEntity object = (TileEntityIronChest)world.getTileEntity(i, j, k); - - if (object == null) - { - return null; - } - else if (world.isSideSolid(i, j + 1, k, DOWN)) - { - return null; - } - else if (isOcelotOnChest(world, i, j, k)) - { - return null; - } - else if (world.getBlock(i - 1, j, k) == this && (world.isSideSolid(i - 1, j + 1, k, DOWN) || isOcelotOnChest(world, i - 1, j, k))) - { - return null; - } - else if (world.getBlock(i + 1, j, k) == this && (world.isSideSolid(i + 1, j + 1, k, DOWN) || isOcelotOnChest(world, i + 1, j, k))) - { - return null; - } - else if (world.getBlock(i, j, k - 1) == this && (world.isSideSolid(i, j + 1, k - 1, DOWN) || isOcelotOnChest(world, i, j, k - 1))) - { - return null; - } - else if (world.getBlock(i, j, k + 1) == this && (world.isSideSolid(i, j + 1, k + 1, DOWN) || isOcelotOnChest(world, i, j, k + 1))) - { - return null; - } - else - return (IInventory)object; - } - - private static boolean isOcelotOnChest(World world, int i, int j, int k) - { - Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getAABBPool().getAABB((double)i, (double)(j + 1), (double)k, (double)(i + 1), (double)(j + 2), (double)(k + 1))).iterator(); - EntityOcelot entityocelot1; - - do - { - if (!iterator.hasNext()) - return false; - - EntityOcelot entityocelot = (EntityOcelot)iterator.next(); - entityocelot1 = (EntityOcelot)entityocelot; - } - while (!entityocelot1.isSitting()); - - return true; - } + /** + * Overridden by {@link #createTileEntity(World, int)} + */ + @Override + public TileEntity createNewTileEntity(World w, int i) { + return null; + } @Override - public void onBlockAdded(World world, int i, int j, int k) - { - super.onBlockAdded(world, i, j, k); - world.markBlockForUpdate(i, j, k); - } + public boolean isOpaqueCube() { + return false; + } - @Override - public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack itemStack) - { - 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.getTileEntity(i, j, k); - if (te != null && te instanceof TileEntityIronChest) - { - TileEntityIronChest teic = (TileEntityIronChest) te; - teic.wasPlaced(entityliving, itemStack); - teic.setFacing(chestFacing); - world.markBlockForUpdate(i, j, k); - } - } + @Override + public boolean renderAsNormalBlock() { + return false; + } - @Override - public int damageDropped(int i) - { - return i; - } + @Override + public int getRenderType() { + return 22; + } - @Override - public void breakBlock(World world, int i, int j, int k, Block i1, int i2) - { - TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getTileEntity(i, j, k); - if (tileentitychest != null) - { - tileentitychest.removeAdornments(); - dropContent(0, tileentitychest, world, tileentitychest.xCoord, tileentitychest.yCoord, tileentitychest.zCoord); - } - super.breakBlock(world, i, j, k, i1, i2); - } + @Override + public TileEntity createTileEntity(World world, int metadata) { + return IronChestType.makeEntity(metadata); + } - 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.getItem(), 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.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); - } - world.spawnEntityInWorld(entityitem); - } - } - } + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int i, int j) { + if (j < IronChestType.values().length) { + IronChestType type = IronChestType.values()[j]; + return type.getIcon(i); + } + return null; + } - @Override - @SideOnly(Side.CLIENT) - public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) - { - for (IronChestType type : IronChestType.values()) - { - if (type.isValidForCreativeMode()) - { - par3List.add(new ItemStack(this, 1, type.ordinal())); - } - } - } + @Override + public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { + ArrayList items = Lists.newArrayList(); + ItemStack stack = new ItemStack(this, 1, metadata); + IronChestType.values()[IronChestType.validateMeta(metadata)].adornItemDrop(stack); + items.add(stack); + return items; + } - @Override - public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) - { - TileEntity te = world.getTileEntity(x, y, z); - if (te instanceof TileEntityIronChest) - { - TileEntityIronChest teic = (TileEntityIronChest) te; - if (teic.getType().isExplosionResistant()) - { - return 10000f; - } - } - return super.getExplosionResistance(par1Entity, world, x, y, z, explosionX, explosionY, explosionZ); - } + @Override + public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int i1, float f1, float f2, float f3) { + if (world.isRemote) + return true; + else { + IInventory iinventory = chestInventory(world, i, j, k); + if (iinventory != null) + player.openGui(IronChest.instance, ((TileEntityIronChest) world.getTileEntity(i, j, k)).getType().ordinal(), world, i, j, k); - @Override - public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5) - { - return Container.calcRedstoneFromInventory((TileEntityIronChest) par1World.getTileEntity(par2, par3, par4)); - } + return true; + } + } + public IInventory chestInventory(World world, int i, int j, int k) { + TileEntity object = (TileEntityIronChest) world.getTileEntity(i, j, k); - @Override - @SideOnly(Side.CLIENT) - public void registerBlockIcons(IIconRegister par1IconRegister) - { - for (IronChestType typ: IronChestType.values()) - { - typ.makeIcons(par1IconRegister); - } - } + if (object == null) { + return null; + } else if (world.isSideSolid(i, j + 1, k, DOWN)) { + return null; + } else if (isOcelotOnChest(world, i, j, k)) { + return null; + } else if (world.getBlock(i - 1, j, k) == this && (world.isSideSolid(i - 1, j + 1, k, DOWN) || isOcelotOnChest(world, i - 1, j, k))) { + return null; + } else if (world.getBlock(i + 1, j, k) == this && (world.isSideSolid(i + 1, j + 1, k, DOWN) || isOcelotOnChest(world, i + 1, j, k))) { + return null; + } else if (world.getBlock(i, j, k - 1) == this && (world.isSideSolid(i, j + 1, k - 1, DOWN) || isOcelotOnChest(world, i, j, k - 1))) { + return null; + } else if (world.getBlock(i, j, k + 1) == this && (world.isSideSolid(i, j + 1, k + 1, DOWN) || isOcelotOnChest(world, i, j, k + 1))) { + return null; + } else + return (IInventory) object; + } - private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN }; - - @Override - public ForgeDirection[] getValidRotations(World worldObj, int x, int y, int z) - { - return validRotationAxes; - } + private static boolean isOcelotOnChest(World world, int i, int j, int k) { + Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getAABBPool().getAABB((double) i, (double) (j + 1), (double) k, (double) (i + 1), (double) (j + 2), (double) (k + 1))).iterator(); + EntityOcelot entityocelot1; - @Override - public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) - { - if (worldObj.isRemote) - { - return false; - } - if (axis == UP || axis == DOWN) - { - TileEntity tileEntity = worldObj.getTileEntity(x, y, z); - if (tileEntity instanceof TileEntityIronChest) { - TileEntityIronChest icte = (TileEntityIronChest) tileEntity; - icte.rotateAround(axis); - } - return true; - } - return false; - } -} + do { + if (!iterator.hasNext()) + return false; + + EntityOcelot entityocelot = (EntityOcelot) iterator.next(); + entityocelot1 = (EntityOcelot) entityocelot; + } while (!entityocelot1.isSitting()); + + 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, EntityLivingBase entityliving, ItemStack itemStack) { + 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.getTileEntity(i, j, k); + if (te != null && te instanceof TileEntityIronChest) { + TileEntityIronChest teic = (TileEntityIronChest) te; + teic.wasPlaced(entityliving, itemStack); + teic.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, Block b, int l) { + TileEntityIronChest te = (TileEntityIronChest) world.getTileEntity(i, j, k); + if (te != null) { + te.removeAdornments(); + dropContent(0, te, world, te.xCoord, te.yCoord, te.zCoord); + } + super.breakBlock(world, i, j, k, b, l); + } + + 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.getItem(), 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.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); + } + world.spawnEntityInWorld(entityitem); + } + } + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) { + for (IronChestType type : IronChestType.values()) { + if (type.isValidForCreativeMode()) { + par3List.add(new ItemStack(this, 1, type.ordinal())); + } + } + } + + @Override + public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof TileEntityIronChest) { + TileEntityIronChest teic = (TileEntityIronChest) te; + if (teic.getType().isExplosionResistant()) { + return 10000F; + } + } + return super.getExplosionResistance(par1Entity, world, x, y, z, explosionX, explosionY, explosionZ); + } + + @Override + public int getComparatorInputOverride(World world, int i, int j, int k, int l) { + return Container.calcRedstoneFromInventory((TileEntityIronChest) world.getTileEntity(i, j, k)); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister par1IconRegister) { + for (IronChestType typ : IronChestType.values()) { + typ.makeIcons(par1IconRegister); + } + } + + private static final ForgeDirection[] validRotationAxes = new ForgeDirection[] { UP, DOWN }; + + @Override + public ForgeDirection[] getValidRotations(World world, int x, int y, int z) { + return validRotationAxes; + } + + @Override + public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) { + if (worldObj.isRemote) { + return false; + } + if (axis == UP || axis == DOWN) { + TileEntity tileEntity = worldObj.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityIronChest) { + TileEntityIronChest icte = (TileEntityIronChest) tileEntity; + icte.rotateAround(axis); + } + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/ChestChangerType.java b/src/main/java/cpw/mods/ironchest/ChestChangerType.java index 15fdcd1..fc4da1f 100644 --- a/src/main/java/cpw/mods/ironchest/ChestChangerType.java +++ b/src/main/java/cpw/mods/ironchest/ChestChangerType.java @@ -10,79 +10,64 @@ import static cpw.mods.ironchest.IronChestType.SILVER; import static cpw.mods.ironchest.IronChestType.WOOD; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraftforge.common.config.Configuration; import cpw.mods.fml.common.registry.GameRegistry; 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"), - DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "Diamond to Obsidian Chest Upgrade", "mmm", "mGm", "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"), + DIAMONDOBSIDIAN(DIAMOND, OBSIDIAN, "diamondObsidianUpgrade", "Diamond to Obsidian Chest Upgrade", "mmm", "mGm", "mmm"); - private IronChestType source; - private IronChestType target; - public String itemName; - public String descriptiveName; - private ItemChestChanger item; - private String[] recipe; + private IronChestType source, target; + public String itemName, descriptiveName, recipe[]; + private ItemChestChanger item; - 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; - } + 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 boolean canUpgrade(IronChestType from) { + return from == this.source; + } - public int getTarget() - { - return this.target.ordinal(); - } + public int getTarget() { + return this.target.ordinal(); + } - public ItemChestChanger buildItem() - { - item = new ItemChestChanger(this); - GameRegistry.registerItem(item, itemName); - return item; - } + public ItemChestChanger buildItem() { + item = new ItemChestChanger(this); + GameRegistry.registerItem(item, itemName); + 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', Blocks.glass, 'O', Blocks.obsidian); - } - } - } + 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', Blocks.glass, 'O', Blocks.obsidian); + } + } + } - public static void buildItems() - { - for (ChestChangerType type : values()) - { - type.buildItem(); - } - } + public static void buildItems() { + for (ChestChangerType type : values()) { + type.buildItem(); + } + } - public static void generateRecipes() - { - for (ChestChangerType item : values()) - { - item.addRecipes(); - } - } -} + public static void generateRecipes() { + for (ChestChangerType item : values()) { + item.addRecipes(); + } + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/CommonProxy.java b/src/main/java/cpw/mods/ironchest/CommonProxy.java index 9afe209..44d40a3 100644 --- a/src/main/java/cpw/mods/ironchest/CommonProxy.java +++ b/src/main/java/cpw/mods/ironchest/CommonProxy.java @@ -6,40 +6,27 @@ 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 getServerGuiElement(int ID, EntityPlayer player, World world, int X, int Y, int Z) { + TileEntity te = world.getTileEntity(X, Y, Z); + if (te != null && te instanceof TileEntityIronChest) { + TileEntityIronChest icte = (TileEntityIronChest) te; + return new ContainerIronChest(player.inventory, icte, icte.getType(), 0, 0); + } else { + 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.getTileEntity(X, Y, Z); - if (te != null && te instanceof TileEntityIronChest) - { - TileEntityIronChest icte = (TileEntityIronChest) te; - return new ContainerIronChest(player.inventory, icte, icte.getType(), 0, 0); - } - else - { - return null; - } - } - - public World getClientWorld() - { - return null; - } - -} + public World getClientWorld() { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/ContainerIronChest.java b/src/main/java/cpw/mods/ironchest/ContainerIronChest.java index 48737e0..1509741 100644 --- a/src/main/java/cpw/mods/ironchest/ContainerIronChest.java +++ b/src/main/java/cpw/mods/ironchest/ContainerIronChest.java @@ -1,115 +1,86 @@ package cpw.mods.ironchest; +import invtweaks.api.container.ChestContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import invtweaks.api.container.ChestContainer; @ChestContainer(isLargeChest = true) public class ContainerIronChest extends Container { - private IronChestType type; - private EntityPlayer player; - private IInventory chest; + private IronChestType type; + private EntityPlayer player; + private IInventory chest; - public ContainerIronChest(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) - { - chest = chestInventory; - player = ((InventoryPlayer) playerInventory).player; - this.type = type; - chestInventory.openInventory(); - layoutContainer(playerInventory, chestInventory, type, xSize, ySize); - } + public ContainerIronChest(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { + chest = chestInventory; + player = ((InventoryPlayer) playerInventory).player; + this.type = type; + chestInventory.openInventory(); + layoutContainer(playerInventory, chestInventory, type, xSize, ySize); + } - @Override - public boolean canInteractWith(EntityPlayer player) - { - return chest.isUseableByPlayer(player); - } + @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()) - { - ItemStack itemstack1 = slot.getStack(); - itemstack = itemstack1.copy(); - if (i < type.size) - { - if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) - { - return null; - } - } - else if (!type.acceptsStack(itemstack1)) - { - return null; - } - else if (!mergeItemStack(itemstack1, 0, type.size, false)) - { - return null; - } - if (itemstack1.stackSize == 0) - { - slot.putStack(null); - } - else - { - slot.onSlotChanged(); - } - } - return itemstack; - } + @Override + public ItemStack transferStackInSlot(EntityPlayer p, int i) { + ItemStack itemstack = null; + Slot slot = (Slot) inventorySlots.get(i); + if (slot != null && slot.getHasStack()) { + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + if (i < type.size) { + if (!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) { + return null; + } + } else if (!type.acceptsStack(itemstack1)) { + return null; + } else if (!mergeItemStack(itemstack1, 0, type.size, false)) { + return null; + } + if (itemstack1.stackSize == 0) { + slot.putStack(null); + } else { + slot.onSlotChanged(); + } + } + return itemstack; + } - @Override - public void onContainerClosed(EntityPlayer entityplayer) - { - super.onContainerClosed(entityplayer); - chest.closeInventory(); - } + @Override + public void onContainerClosed(EntityPlayer entityplayer) { + super.onContainerClosed(entityplayer); + chest.closeInventory(); + } - protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) - { - if (type == IronChestType.DIRTCHEST9000) { - addSlotToContainer(type.makeSlot(chestInventory, 0, 12 + 4 * 18, 8 + 2 * 18)); - } else { - for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++) - { - for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++) - { - addSlotToContainer(type.makeSlot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18)); - } - } - } + protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { + if (type == IronChestType.DIRTCHEST9000) { + addSlotToContainer(type.makeSlot(chestInventory, 0, 12 + 4 * 18, 8 + 2 * 18)); + } else + for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++) + for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++) + addSlotToContainer(type.makeSlot(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)); - } + 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++) - { - addSlotToContainer(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize - 24)); - } - } + public EntityPlayer getPlayer() { + return player; + } - public EntityPlayer getPlayer() - { - return player; - } - - @ChestContainer.RowSizeCallback - public int getNumColumns() { - return type.getRowLength(); - } -} + @ChestContainer.RowSizeCallback + public int getNumColumns() { + return type.getRowLength(); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/IronChest.java b/src/main/java/cpw/mods/ironchest/IronChest.java index f8800dd..2a0335c 100644 --- a/src/main/java/cpw/mods/ironchest/IronChest.java +++ b/src/main/java/cpw/mods/ironchest/IronChest.java @@ -11,32 +11,32 @@ import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = "IronChest", name = "Iron Chests", dependencies = "required-after:Forge@[7.0,);required-after:FML@[5.0.5,)") 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 BlockIronChest ironChestBlock; - @EventHandler - public void load(FMLInitializationEvent e) - { - ChestChangerType.buildItems(); - - ironChestBlock = new BlockIronChest(); - GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest"); - - PacketHandler.INSTANCE.ordinal(); - for (IronChestType typ : IronChestType.values()) - { - GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest."+typ.name(), typ.name()); - proxy.registerTileEntitySpecialRenderer(typ); - } - IronChestType.registerBlocksAndRecipes(ironChestBlock); - ChestChangerType.generateRecipes(); - NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); - proxy.registerRenderInformation(); - MinecraftForge.EVENT_BUS.register(this); - } -} + @SidedProxy(clientSide = "cpw.mods.ironchest.client.ClientProxy", serverSide = "cpw.mods.ironchest.CommonProxy") + public static CommonProxy proxy; + + @Instance("IronChest") + public static IronChest instance; + + @EventHandler + public void load(FMLInitializationEvent e) { + ChestChangerType.buildItems(); + + ironChestBlock = new BlockIronChest(); + GameRegistry.registerBlock(ironChestBlock, ItemIronChest.class, "BlockIronChest"); + + for (IronChestType typ : IronChestType.values()) { + GameRegistry.registerTileEntityWithAlternatives(typ.clazz, "IronChest." + typ.name(), typ.name()); + proxy.registerTileEntitySpecialRenderer(typ); + } + + IronChestType.registerBlocksAndRecipes(ironChestBlock); + ChestChangerType.generateRecipes(); + + PacketHandler.INSTANCE.ordinal(); + NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); + proxy.registerRenderInformation(); + MinecraftForge.EVENT_BUS.register(this); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/IronChestType.java b/src/main/java/cpw/mods/ironchest/IronChestType.java index 7435262..e9c8c51 100644 --- a/src/main/java/cpw/mods/ironchest/IronChestType.java +++ b/src/main/java/cpw/mods/ironchest/IronChestType.java @@ -3,6 +3,7 @@ package cpw.mods.ironchest; import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -18,238 +19,179 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; 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"), - OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"), - DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png",7,Arrays.asList("dirt"), TileEntityDirtChest.class,Item.getItemFromBlock(Blocks.dirt),"mmmmCmmmm"), - WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), 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; - private Item itemFilter; + 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"), + OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"), + DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png", 7, Arrays.asList("dirt"), TileEntityDirtChest.class, Item.getItemFromBlock(Blocks.dirt), "mmmmCmmmm"), + WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), null); - IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List mats, - Class clazz, String... recipes) - { - this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item)null, recipes); - } - IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List mats, - Class clazz, Item itemFilter, String... recipes) - { - this.size = size; - this.rowLength = rowLength; - this.tieredChest = tieredChest; - this.friendlyName = friendlyName; - this.modelTexture = modelTexture; - this.textureRow = textureRow; - this.clazz = clazz; - this.itemFilter = itemFilter; - this.recipes = recipes; - this.matList = new ArrayList(); - matList.addAll(mats); - } + public int size, rowLength, textureRow; + public String friendlyName, modelTexture, recipes[]; + private boolean tieredChest; + public Class clazz; + private ArrayList matList; + private Item itemFilter; - public String getModelTexture() - { - return modelTexture; - } + IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List mats, Class clazz, String... recipes) { + this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item) null, recipes); + } - public int getTextureRow() - { - return textureRow; - } + IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List mats, Class clazz, Item itemFilter, String... recipes) { + this.size = size; + this.rowLength = rowLength; + this.tieredChest = tieredChest; + this.friendlyName = friendlyName; + this.modelTexture = modelTexture; + this.textureRow = textureRow; + this.clazz = clazz; + this.itemFilter = itemFilter; + this.recipes = recipes; + this.matList = new ArrayList(); + matList.addAll(mats); + } - 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; - } + public String getModelTexture() { + return modelTexture; + } - public static void registerTranslations() - { - } + public int getTextureRow() { + return textureRow; + } - public static void registerBlocksAndRecipes(BlockIronChest blockResult) - { - ItemStack previous = new ItemStack(Blocks.chest); - for (IronChestType typ : values()) - { - generateRecipesForType(blockResult, previous, typ); - ItemStack chest = new ItemStack(blockResult, 1, typ.ordinal()); - if (typ.isValidForCreativeMode()) GameRegistry.registerCustomItemStack(typ.friendlyName, chest); - if (typ.tieredChest) previous = chest; - } - } + public static TileEntityIronChest makeEntity(int metadata) { + int chesttype = validateMeta(metadata); + if (chesttype == metadata) { + try { + return values()[chesttype].clazz.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + return null; + } - 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', Blocks.glass, 'C', Blocks.chest, - '0', new ItemStack(blockResult, 1, 0), /* Iron Chest */ - '1', new ItemStack(blockResult, 1, 1), /* Gold Chest */ - '2', new ItemStack(blockResult, 1, 2), /* Diamond Chest */ - '3', new ItemStack(blockResult, 1, 3), /* Copper Chest */ - '4', new ItemStack(blockResult, 1, 4)/* Silver Chest */ - ); - } - } - } + public static void registerBlocksAndRecipes(BlockIronChest blockResult) { + ItemStack previous = new ItemStack(Blocks.chest); + for (IronChestType typ : values()) { + generateRecipesForType(blockResult, previous, typ); + ItemStack chest = new ItemStack(blockResult, 1, typ.ordinal()); + if (typ.isValidForCreativeMode()) + GameRegistry.registerCustomItemStack(typ.friendlyName, chest); + if (typ.tieredChest) + previous = chest; + } + } - public static Object translateOreName(String mat) - { - if (mat == "ingotIron") - { - return Items.iron_ingot; - } - else if (mat == "ingotGold") - { - return Items.gold_ingot; - } - else if (mat == "gemDiamond") - { - return Items.diamond; - } - else if (mat == "blockGlass") - { - return Blocks.glass; - } - else if (mat == "obsidian") - { - return Blocks.obsidian; - } - else if (mat == "dirt") - { - return Blocks.dirt; - } - return mat; - } + 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 chest tier */ 'G', Blocks.glass, 'C', Blocks.chest, + '0', new ItemStack(blockResult, 1, 0), /* Iron Chest */ + '1', new ItemStack(blockResult, 1, 1), /* Gold Chest */ + '2', new ItemStack(blockResult, 1, 2), /* Diamond Chest */ + '3', new ItemStack(blockResult, 1, 3), /* Copper Chest */ + '4', new ItemStack(blockResult, 1, 4)/* Silver Chest */ + ); + } + } + } - public static void addRecipe(ItemStack is, Object... parts) - { - ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts); - GameRegistry.addRecipe(oreRecipe); - } + public static Object translateOreName(String mat) { + if (mat == "ingotIron") { + return Items.iron_ingot; + } else if (mat == "ingotGold") { + return Items.gold_ingot; + } else if (mat == "gemDiamond") { + return Items.diamond; + } else if (mat == "blockGlass") { + return Blocks.glass; + } else if (mat == "obsidian") { + return Blocks.obsidian; + } else if (mat == "dirt") { + return Blocks.dirt; + } + return mat; + } - public int getRowCount() - { - return size / rowLength; - } + public static void addRecipe(ItemStack is, Object... parts) { + ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts); + GameRegistry.addRecipe(oreRecipe); + } - public int getRowLength() - { - return rowLength; - } + public int getRowCount() { + return size / rowLength; + } - public boolean isTransparent() - { - return this == CRYSTAL; - } + public int getRowLength() { + return rowLength; + } - public List getMatList() - { - return matList; - } + public boolean isTransparent() { + return this == CRYSTAL; + } - public static int validateMeta(int i) - { - if (i < values().length && values()[i].size > 0) - { - return i; - } - else - { - return 0; - } - } + public List getMatList() { + return matList; + } - public boolean isValidForCreativeMode() - { - return validateMeta(ordinal()) == ordinal(); - } + public static int validateMeta(int i) { + if (i < values().length && values()[i].size > 0) { + return i; + } else { + return 0; + } + } - public boolean isExplosionResistant() - { - return this == OBSIDIAN; - } + public boolean isValidForCreativeMode() { + return validateMeta(ordinal()) == ordinal(); + } - @SideOnly(Side.CLIENT) - private IIcon[] icons; + public boolean isExplosionResistant() { + return this == OBSIDIAN; + } - @SideOnly(Side.CLIENT) - public void makeIcons(IIconRegister par1IconRegister) - { - if (isValidForCreativeMode()) - { - icons = new IIcon[3]; - int i = 0; - for (String s : sideNames) - { - icons[i++] = par1IconRegister.registerIcon(String.format("ironchest:%s_%s",name().toLowerCase(),s)); - } - } - } + @SideOnly(Side.CLIENT) + private IIcon[] icons; - @SideOnly(Side.CLIENT) - public IIcon getIcon(int side) - { + @SideOnly(Side.CLIENT) + public void makeIcons(IIconRegister par1IconRegister) { + if (isValidForCreativeMode()) { + icons = new IIcon[3]; + int i = 0; + for (String s : sideNames) { + icons[i++] = par1IconRegister.registerIcon(String.format("ironchest:%s_%s", name().toLowerCase(), s)); + } + } + } - return icons[sideMapping[side]]; - } + @SideOnly(Side.CLIENT) + public IIcon getIcon(int side) { + return icons[sideMapping[side]]; + } - private static String[] sideNames = { "top", "front", "side" }; - private static int[] sideMapping = { 0, 0, 2, 1, 2, 2, 2 }; + private static String[] sideNames = { "top", "front", "side" }; + private static int[] sideMapping = { 0, 0, 2, 1, 2, 2, 2 }; - public Slot makeSlot(IInventory chestInventory, int index, int x, int y) - { - return new ValidatingSlot(chestInventory, index, x, y, this); - } + public Slot makeSlot(IInventory chestInventory, int index, int x, int y) { + return new ValidatingSlot(chestInventory, index, x, y, this); + } - public boolean acceptsStack(ItemStack itemstack) - { - return itemFilter == null || itemstack == null || itemstack.getItem() == itemFilter; - } - public void adornItemDrop(ItemStack item) - { - if (this == DIRTCHEST9000) - { - item.setTagInfo("dirtchest", new NBTTagByte((byte) 1)); - } - } -} + public boolean acceptsStack(ItemStack itemstack) { + return itemFilter == null || itemstack == null || itemstack.getItem() == itemFilter; + } + + public void adornItemDrop(ItemStack item) { + if (this == DIRTCHEST9000) { + item.setTagInfo("dirtchest", new NBTTagByte((byte) 1)); + } + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java index 0fd9d8b..2b86d6c 100644 --- a/src/main/java/cpw/mods/ironchest/ItemChestChanger.java +++ b/src/main/java/cpw/mods/ironchest/ItemChestChanger.java @@ -14,92 +14,72 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ItemChestChanger extends Item { + private ChestChangerType type; - private ChestChangerType type; + public ItemChestChanger(ChestChangerType type) { + super(); + setMaxStackSize(1); + this.type = type; + setUnlocalizedName("ironchest:" + type.name()); + setCreativeTab(CreativeTabs.tabMisc); + } - public ItemChestChanger(ChestChangerType type) - { - super(); - setMaxStackSize(1); - this.type = type; - setUnlocalizedName("ironchest:"+type.name()); - setCreativeTab(CreativeTabs.tabMisc); - } + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister par1IconRegister) { + this.itemIcon = par1IconRegister.registerIcon("ironchest:" + type.itemName); + } + @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.getTileEntity(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.numPlayersUsing > 0) { + return false; + } + if (!getType().canUpgrade(IronChestType.WOOD)) { + return false; + } + // force the old tileentity 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; + } + world.setBlock(X, Y, Z, Blocks.air, 0, 3); // clear the old block out + tec.updateContainingBlockInfo(); // reset neighboring block knowledge + tec.checkForAdjacentChests(); // update neighboring blocks + world.setBlock(X, Y, Z, block, newchest.getType().ordinal(), 3); // add in the iron chest + } else { + return false; + } + world.setTileEntity(X, Y, Z, newchest); + world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal(), 3); + stack.stackSize = 0; + return true; + } - @Override - @SideOnly(Side.CLIENT) - public void registerIcons(IIconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon("ironchest:"+type.itemName); - } + public int getTargetChestOrdinal(int sourceOrdinal) { + return type.getTarget(); + } - @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.getTileEntity(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.numPlayersUsing > 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, Blocks.air, 0, 3); - // 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, newchest.getType().ordinal(), 3); - } - else - { - return false; - } - world.setTileEntity(X, Y, Z, newchest); - world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal(), 3); - stack.stackSize = 0; - return true; - } - - public int getTargetChestOrdinal(int sourceOrdinal) - { - return type.getTarget(); - } - - public ChestChangerType getType() - { - return type; - } -} + public ChestChangerType getType() { + return type; + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/ItemIronChest.java b/src/main/java/cpw/mods/ironchest/ItemIronChest.java index 7c74444..2da03d3 100644 --- a/src/main/java/cpw/mods/ironchest/ItemIronChest.java +++ b/src/main/java/cpw/mods/ironchest/ItemIronChest.java @@ -5,23 +5,19 @@ import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; public class ItemIronChest extends ItemBlock { + public ItemIronChest(Block block) { + super(block); + setMaxDamage(0); + setHasSubtypes(true); + } - public ItemIronChest(Block block) - { - super(block); - setMaxDamage(0); - setHasSubtypes(true); - } + @Override + public int getMetadata(int i) { + return IronChestType.validateMeta(i); + } - @Override - public int getMetadata(int i) - { - return IronChestType.validateMeta(i); - } - - @Override - public String getUnlocalizedName(ItemStack itemstack) - { - return "tile.ironchest:"+IronChestType.values()[itemstack.getItemDamage()].name(); - } -} + @Override + public String getUnlocalizedName(ItemStack itemstack) { + return "tile.ironchest:" + IronChestType.values()[itemstack.getItemDamage()].name(); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/MappableItemStackWrapper.java b/src/main/java/cpw/mods/ironchest/MappableItemStackWrapper.java index 95a8a40..f5f7d38 100644 --- a/src/main/java/cpw/mods/ironchest/MappableItemStackWrapper.java +++ b/src/main/java/cpw/mods/ironchest/MappableItemStackWrapper.java @@ -3,31 +3,26 @@ package cpw.mods.ironchest; import net.minecraft.item.ItemStack; public class MappableItemStackWrapper { - private ItemStack wrap; + private ItemStack wrap; - public MappableItemStackWrapper(ItemStack toWrap) - { - wrap = toWrap; - } + 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 == wrap; - } - } + @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 == wrap; + } + } - @Override - public int hashCode() - { - return System.identityHashCode(wrap); - } -} + @Override + public int hashCode() { + return System.identityHashCode(wrap); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/PacketHandler.java b/src/main/java/cpw/mods/ironchest/PacketHandler.java index 4bdcc9a..75e3dd1 100644 --- a/src/main/java/cpw/mods/ironchest/PacketHandler.java +++ b/src/main/java/cpw/mods/ironchest/PacketHandler.java @@ -3,7 +3,9 @@ package cpw.mods.ironchest; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; + import java.util.EnumMap; + import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -17,174 +19,155 @@ import cpw.mods.fml.relauncher.SideOnly; /** * Handles the packet wrangling for IronChest + * * @author cpw - * + * */ public enum PacketHandler { - INSTANCE; + INSTANCE; - /** - * Our channel "pair" from {@link NetworkRegistry} - */ - private EnumMap channels; + /** + * Our channel "pair" from {@link NetworkRegistry} + */ + private EnumMap channels; - /** - * Make our packet handler, and add an {@link IronChestCodec} always - */ - private PacketHandler() - { - // request a channel pair for IronChest from the network registry - // Add the IronChestCodec as a member of both channel pipelines - this.channels = NetworkRegistry.INSTANCE.newChannel("IronChest", new IronChestCodec()); - if (FMLCommonHandler.instance().getSide() == Side.CLIENT) - { - addClientHandler(); - } - } + /** + * Make our packet handler, and add an {@link IronChestCodec} always + */ + private PacketHandler() { + // request a channel pair for IronChest from the network registry + // Add the IronChestCodec as a member of both channel pipelines + this.channels = NetworkRegistry.INSTANCE.newChannel("IronChest", new IronChestCodec()); + if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { + addClientHandler(); + } + } - /** - * This is only called on the client side - it adds an - * {@link IronChestMessageHandler} to the client side pipeline, since the - * only place we expect to handle messages is on the client. - */ - @SideOnly(Side.CLIENT) - private void addClientHandler() { - FMLEmbeddedChannel clientChannel = this.channels.get(Side.CLIENT); - // These two lines find the existing codec (Ironchestcodec) and insert our message handler after it - // in the pipeline - String codec = clientChannel.findChannelHandlerNameForType(IronChestCodec.class); - clientChannel.pipeline().addAfter(codec, "ClientHandler", new IronChestMessageHandler()); - } + /** + * This is only called on the client side - it adds an + * {@link IronChestMessageHandler} to the client side pipeline, since the + * only place we expect to handle messages is on the client. + */ + @SideOnly(Side.CLIENT) + private void addClientHandler() { + FMLEmbeddedChannel clientChannel = this.channels.get(Side.CLIENT); + // These two lines find the existing codec (Ironchestcodec) and insert + // our message handler after it in the pipeline + String codec = clientChannel.findChannelHandlerNameForType(IronChestCodec.class); + clientChannel.pipeline().addAfter(codec, "ClientHandler", new IronChestMessageHandler()); + } - /** - * This class simply handles the {@link IronChestMessage} when it's received - * at the client side It can contain client only code, because it's only run - * on the client. - * - * @author cpw - * - */ - private static class IronChestMessageHandler extends SimpleChannelInboundHandler - { - @Override - protected void channelRead0(ChannelHandlerContext ctx, IronChestMessage msg) throws Exception - { - World world = IronChest.proxy.getClientWorld(); - TileEntity te = world.getTileEntity(msg.x, msg.y, msg.z); - if (te instanceof TileEntityIronChest) - { - TileEntityIronChest icte = (TileEntityIronChest) te; - icte.setFacing(msg.facing); - icte.handlePacketData(msg.type, msg.items); - } - } - } + /** + * This class simply handles the {@link IronChestMessage} when it's received + * at the client side It can contain client only code, because it's only run + * on the client. + * + * @author cpw + * + */ + private static class IronChestMessageHandler extends SimpleChannelInboundHandler { + @Override + protected void channelRead0(ChannelHandlerContext ctx, IronChestMessage msg) throws Exception { + World world = IronChest.proxy.getClientWorld(); + TileEntity te = world.getTileEntity(msg.x, msg.y, msg.z); + if (te instanceof TileEntityIronChest) { + TileEntityIronChest icte = (TileEntityIronChest) te; + icte.setFacing(msg.facing); + icte.handlePacketData(msg.type, msg.items); + } + } + } - /** - * This is our "message". In fact, {@link FMLIndexedMessageToMessageCodec} - * can handle many messages on the same channel at once, using a - * discriminator byte. But for IronChest, we only need the one message, so - * we have just this. - * - * @author cpw - * - */ - public static class IronChestMessage - { - int x; - int y; - int z; - int type; - int facing; - int[] items; - } + /** + * This is our "message". In fact, {@link FMLIndexedMessageToMessageCodec} + * can handle many messages on the same channel at once, using a + * discriminator byte. But for IronChest, we only need the one message, so + * we have just this. + * + * @author cpw + * + */ + public static class IronChestMessage { + int x, y, z, type, facing, items[]; + } - /** - * This is the codec that automatically transforms the - * {@link FMLProxyPacket} which wraps the client and server custom payload - * packets into a message we care about. - * - * @author cpw - * - */ - private class IronChestCodec extends FMLIndexedMessageToMessageCodec - { - /** - * We register our discriminator bytes here. We only have the one type, so we only - * register one. - */ - public IronChestCodec() - { - addDiscriminator(0, IronChestMessage.class); - } - @Override - public void encodeInto(ChannelHandlerContext ctx, IronChestMessage msg, ByteBuf target) throws Exception - { - target.writeInt(msg.x); - target.writeInt(msg.y); - target.writeInt(msg.z); - int typeAndFacing = ((msg.type & 0x0F) | ((msg.facing & 0x0F) << 4)) & 0xFF; - target.writeByte(typeAndFacing); - target.writeBoolean(msg.items != null); - if (msg.items != null) - { - int[] items = msg.items; - for (int j = 0; j < items.length; j++) - { - int i = items[j]; - target.writeInt(i); - } - } - } + /** + * This is the codec that automatically transforms the + * {@link FMLProxyPacket} which wraps the client and server custom payload + * packets into a message we care about. + * + * @author cpw + * + */ + private class IronChestCodec extends FMLIndexedMessageToMessageCodec { + /** + * We register our discriminator bytes here. We only have the one type, + * so we only register one. + */ + public IronChestCodec() { + addDiscriminator(0, IronChestMessage.class); + } - @Override - public void decodeInto(ChannelHandlerContext ctx, ByteBuf dat, IronChestMessage msg) - { - msg.x = dat.readInt(); - msg.y = dat.readInt(); - msg.z = dat.readInt(); - int typDat = dat.readByte(); - msg.type = (byte)(typDat & 0xf); - msg.facing = (byte)((typDat >> 4) & 0xf); - boolean hasStacks = dat.readBoolean(); - msg.items = new int[0]; - if (hasStacks) - { - msg.items = new int[24]; - for (int i = 0; i < msg.items.length; i++) - { - msg.items[i] = dat.readInt(); - } - } - } + @Override + public void encodeInto(ChannelHandlerContext ctx, IronChestMessage msg, ByteBuf target) throws Exception { + target.writeInt(msg.x); + target.writeInt(msg.y); + target.writeInt(msg.z); + int typeAndFacing = ((msg.type & 0x0F) | ((msg.facing & 0x0F) << 4)) & 0xFF; + target.writeByte(typeAndFacing); + target.writeBoolean(msg.items != null); + if (msg.items != null) { + int[] items = msg.items; + for (int j = 0; j < items.length; j++) { + int i = items[j]; + target.writeInt(i); + } + } + } - } + @Override + public void decodeInto(ChannelHandlerContext ctx, ByteBuf dat, IronChestMessage msg) { + msg.x = dat.readInt(); + msg.y = dat.readInt(); + msg.z = dat.readInt(); + int typDat = dat.readByte(); + msg.type = (byte) (typDat & 0xf); + msg.facing = (byte) ((typDat >> 4) & 0xf); + boolean hasStacks = dat.readBoolean(); + msg.items = new int[0]; + if (hasStacks) { + msg.items = new int[24]; + for (int i = 0; i < msg.items.length; i++) { + msg.items[i] = dat.readInt(); + } + } + } + } - /** - * This is a utility method called to transform a packet from a custom - * packet into a "system packet". We're called from - * {@link TileEntity#getDescriptionPacket()} in this case, but there are - * others. All network packet methods in minecraft have been adapted to - * handle {@link FMLProxyPacket} but general purpose objects can't be - * handled sadly. - * - * This method uses the {@link IronChestCodec} to transform a custom packet - * {@link IronChestMessage} into an {@link FMLProxyPacket} by using the - * utility method {@link FMLEmbeddedChannel#generatePacketFrom(Object)} on - * the channel to do exactly that. - * - * @param tileEntityIronChest - * @return - */ - public static Packet getPacket(TileEntityIronChest tileEntityIronChest) - { - IronChestMessage msg = new IronChestMessage(); - msg.x = tileEntityIronChest.xCoord; - msg.y = tileEntityIronChest.yCoord; - msg.z = tileEntityIronChest.zCoord; - msg.type = tileEntityIronChest.getType().ordinal(); - msg.facing = tileEntityIronChest.getFacing(); - msg.items = tileEntityIronChest.buildIntDataList(); - return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg); - } -} + /** + * This is a utility method called to transform a packet from a custom + * packet into a "system packet". We're called from + * {@link TileEntity#getDescriptionPacket()} in this case, but there are + * others. All network packet methods in minecraft have been adapted to + * handle {@link FMLProxyPacket} but general purpose objects can't be + * handled sadly. + * + * This method uses the {@link IronChestCodec} to transform a custom packet + * {@link IronChestMessage} into an {@link FMLProxyPacket} by using the + * utility method {@link FMLEmbeddedChannel#generatePacketFrom(Object)} on + * the channel to do exactly that. + * + * @param tileEntityIronChest + * @return + */ + public static Packet getPacket(TileEntityIronChest tileEntityIronChest) { + IronChestMessage msg = new IronChestMessage(); + msg.x = tileEntityIronChest.xCoord; + msg.y = tileEntityIronChest.yCoord; + msg.z = tileEntityIronChest.zCoord; + msg.type = tileEntityIronChest.getType().ordinal(); + msg.facing = tileEntityIronChest.getFacing(); + msg.items = tileEntityIronChest.buildIntDataList(); + return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/TileEntityCopperChest.java b/src/main/java/cpw/mods/ironchest/TileEntityCopperChest.java index fae6992..b5b72bc 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntityCopperChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityCopperChest.java @@ -1,8 +1,7 @@ package cpw.mods.ironchest; public class TileEntityCopperChest extends TileEntityIronChest { - public TileEntityCopperChest() - { - super(IronChestType.COPPER); - } -} + public TileEntityCopperChest() { + super(IronChestType.COPPER); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/TileEntityCrystalChest.java b/src/main/java/cpw/mods/ironchest/TileEntityCrystalChest.java index 268aa19..3ed64fa 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntityCrystalChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityCrystalChest.java @@ -1,8 +1,7 @@ package cpw.mods.ironchest; public class TileEntityCrystalChest extends TileEntityIronChest { - public TileEntityCrystalChest() - { - super(IronChestType.CRYSTAL); - } -} + public TileEntityCrystalChest() { + super(IronChestType.CRYSTAL); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/TileEntityDiamondChest.java b/src/main/java/cpw/mods/ironchest/TileEntityDiamondChest.java index 8a0afc2..3a8411d 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntityDiamondChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityDiamondChest.java @@ -1,8 +1,7 @@ package cpw.mods.ironchest; public class TileEntityDiamondChest extends TileEntityIronChest { - public TileEntityDiamondChest() - { - super(IronChestType.DIAMOND); - } -} + public TileEntityDiamondChest() { + super(IronChestType.DIAMOND); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/TileEntityDirtChest.java b/src/main/java/cpw/mods/ironchest/TileEntityDirtChest.java index a7608c0..46e4a96 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntityDirtChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityDirtChest.java @@ -8,35 +8,35 @@ import net.minecraft.nbt.NBTTagString; import net.minecraft.util.StatCollector; public class TileEntityDirtChest extends TileEntityIronChest { - private static ItemStack dirtChest9000GuideBook = new ItemStack(Items.written_book); - static { - dirtChest9000GuideBook.setTagInfo("author", new NBTTagString("cpw")); - dirtChest9000GuideBook.setTagInfo("title", new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.title"))); - NBTTagList pages = new NBTTagList(); - pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page1"))); - pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page2"))); - pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page3"))); - pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page4"))); - pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page5"))); - dirtChest9000GuideBook.setTagInfo("pages", pages); - } - public TileEntityDirtChest() { - super(IronChestType.DIRTCHEST9000); - } + private static ItemStack dirtChest9000GuideBook = new ItemStack(Items.written_book); - @Override - public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) - { - if (!(itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("dirtchest"))) { - setInventorySlotContents(0, dirtChest9000GuideBook.copy()); - } - } + static { + dirtChest9000GuideBook.setTagInfo("author", new NBTTagString("cpw")); + dirtChest9000GuideBook.setTagInfo("title", new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.title"))); + NBTTagList pages = new NBTTagList(); + pages.appendTag(new NBTTagString(StatCollector .translateToLocal("book.ironchest:dirtchest9000.page1"))); + pages.appendTag(new NBTTagString(StatCollector .translateToLocal("book.ironchest:dirtchest9000.page2"))); + pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page3"))); + pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page4"))); + pages.appendTag(new NBTTagString(StatCollector.translateToLocal("book.ironchest:dirtchest9000.page5"))); + dirtChest9000GuideBook.setTagInfo("pages", pages); + } - @Override - public void removeAdornments() - { - if (chestContents[0] != null && chestContents[0].isItemEqual(dirtChest9000GuideBook)) { - chestContents[0] = null; - } - } -} + public TileEntityDirtChest() { + super(IronChestType.DIRTCHEST9000); + } + + @Override + public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) { + if (!(itemStack.hasTagCompound() && itemStack.getTagCompound().getBoolean("dirtchest"))) { + setInventorySlotContents(0, dirtChest9000GuideBook.copy()); + } + } + + @Override + public void removeAdornments() { + if (chestContents[0] != null && chestContents[0].isItemEqual(dirtChest9000GuideBook)) { + chestContents[0] = null; + } + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/TileEntityGoldChest.java b/src/main/java/cpw/mods/ironchest/TileEntityGoldChest.java index ac4397d..2b2e4cb 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntityGoldChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityGoldChest.java @@ -1,8 +1,7 @@ package cpw.mods.ironchest; public class TileEntityGoldChest extends TileEntityIronChest { - public TileEntityGoldChest() - { - super(IronChestType.GOLD); - } -} + public TileEntityGoldChest() { + super(IronChestType.GOLD); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java index 246c518..997ae36 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityIronChest.java @@ -19,504 +19,377 @@ import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityIronChest extends TileEntity implements IInventory { - private int ticksSinceSync = -1; - public float prevLidAngle; - public float lidAngle; - private int numUsingPlayers; - private IronChestType type; - public ItemStack[] chestContents; - private ItemStack[] topStacks; - private int facing; - private boolean inventoryTouched; - private boolean hadStuff; + private int ticksSinceSync = -1, numUsingPlayers, facing; + public float prevLidAngle, lidAngle; + private IronChestType type; + public ItemStack[] chestContents, topStacks; + private boolean inventoryTouched, hadStuff; - public TileEntityIronChest() - { - this(IronChestType.IRON); - } + public TileEntityIronChest() { + this(IronChestType.IRON); + } - protected TileEntityIronChest(IronChestType type) - { - super(); - this.type = type; - this.chestContents = new ItemStack[getSizeInventory()]; - this.topStacks = new ItemStack[8]; - } + protected TileEntityIronChest(IronChestType type) { + super(); + this.type = type; + chestContents = new ItemStack[getSizeInventory()]; + topStacks = new ItemStack[8]; + } - public ItemStack[] getContents() - { - return chestContents; - } + public ItemStack[] getContents() { + return chestContents; + } - @Override - public int getSizeInventory() - { - return type.size; - } + @Override + public int getSizeInventory() { + return type.size; + } - public int getFacing() - { - return this.facing; - } + public int getFacing() { + return facing; + } - @Override - public String getInventoryName() - { - return type.name(); - } + @Override + public String getInventoryName() { + return type.name(); + } - public IronChestType getType() - { - return type; - } + public IronChestType getType() { + return type; + } - @Override - public ItemStack getStackInSlot(int i) - { - inventoryTouched = true; - return chestContents[i]; - } + @Override + public ItemStack getStackInSlot(int i) { + inventoryTouched = true; + return chestContents[i]; + } - @Override - public void markDirty() - { - super.markDirty(); - sortTopStacks(); - } + @Override + public void markDirty() { + super.markDirty(); + sortTopStacks(); + } - protected void sortTopStacks() - { - if (!type.isTransparent() || (worldObj != null && worldObj.isRemote)) - { - return; - } - ItemStack[] tempCopy = new ItemStack[getSizeInventory()]; - boolean hasStuff = false; - int compressedIdx = 0; - mainLoop: for (int i = 0; i < getSizeInventory(); i++) - { - if (chestContents[i] != null) - { - for (int j = 0; j < compressedIdx; j++) - { - if (tempCopy[j].isItemEqual(chestContents[i])) - { - 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); - } - } + protected void sortTopStacks() { + if (!type.isTransparent() || (worldObj != null && worldObj.isRemote)) { + return; + } + ItemStack[] tempCopy = new ItemStack[getSizeInventory()]; + boolean hasStuff = false; + int compressedIdx = 0; + mainLoop: for (int i = 0; i < getSizeInventory(); i++) { + if (chestContents[i] != null) { + for (int j = 0; j < compressedIdx; j++) { + if (tempCopy[j].isItemEqual(chestContents[i])) { + 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); + } + } - @Override - public ItemStack decrStackSize(int i, int j) - { - if (chestContents[i] != null) - { - if (chestContents[i].stackSize <= j) - { - ItemStack itemstack = chestContents[i]; - chestContents[i] = null; - markDirty(); - return itemstack; - } - ItemStack itemstack1 = chestContents[i].splitStack(j); - if (chestContents[i].stackSize == 0) - { - chestContents[i] = null; - } - markDirty(); - return itemstack1; - } - else - { - return null; - } - } + @Override + public ItemStack decrStackSize(int i, int j) { + if (chestContents[i] != null) { + if (chestContents[i].stackSize <= j) { + ItemStack itemstack = chestContents[i]; + chestContents[i] = null; + markDirty(); + return itemstack; + } + ItemStack itemstack1 = chestContents[i].splitStack(j); + if (chestContents[i].stackSize == 0) { + chestContents[i] = null; + } + markDirty(); + return itemstack1; + } else { + return null; + } + } - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) - { - chestContents[i] = itemstack; - if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) - { - itemstack.stackSize = getInventoryStackLimit(); - } - markDirty(); - } + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) { + chestContents[i] = itemstack; + if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { + itemstack.stackSize = getInventoryStackLimit(); + } + markDirty(); + } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) - { - super.readFromNBT(nbttagcompound); - NBTTagList nbttaglist = nbttagcompound.getTagList("Items", Constants.NBT.TAG_COMPOUND); - chestContents = new ItemStack[getSizeInventory()]; - for (int i = 0; i < nbttaglist.tagCount(); i++) - { - NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(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 readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + NBTTagList nbttaglist = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND); + chestContents = new ItemStack[getSizeInventory()]; + for (int i = 0; i < nbttaglist.tagCount(); i++) { + NBTTagCompound nbt1 = nbttaglist.getCompoundTagAt(i); + int j = nbt1.getByte("Slot") & 0xff; + if (j >= 0 && j < chestContents.length) { + chestContents[j] = ItemStack.loadItemStackFromNBT(nbt1); + } + } + facing = nbt.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); - } - } + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + NBTTagList nbttaglist = new NBTTagList(); + for (int i = 0; i < chestContents.length; i++) { + if (chestContents[i] != null) { + NBTTagCompound nbt1 = new NBTTagCompound(); + nbt1.setByte("Slot", (byte) i); + chestContents[i].writeToNBT(nbt1); + nbttaglist.appendTag(nbt1); + } + } + nbt.setTag("Items", nbttaglist); + nbt.setByte("facing", (byte) facing); + } - nbttagcompound.setTag("Items", nbttaglist); - nbttagcompound.setByte("facing", (byte)facing); - } + @Override + public int getInventoryStackLimit() { + return 64; + } - @Override - public int getInventoryStackLimit() - { - return 64; - } + @Override + public boolean isUseableByPlayer(final EntityPlayer player) { + return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64.0; + } - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - if (worldObj == null) - { - return true; - } - if (worldObj.getTileEntity(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(); + if (worldObj != null && !worldObj.isRemote && numUsingPlayers != 0 && (ticksSinceSync + xCoord + yCoord + zCoord) % 200 == 0) { + numUsingPlayers = 0; + float var1 = 5.0F; + List var2 = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB((double) ((float) xCoord - var1), (double) ((float) yCoord - var1), (double) ((float) zCoord - var1), (double) ((float) (xCoord + 1) + var1), (double) ((float) (yCoord + 1) + var1), (double) ((float) (zCoord + 1) + var1))); + Iterator var3 = var2.iterator(); - @Override - public void updateEntity() - { - super.updateEntity(); - // Resynchronize clients with the server state - if (worldObj != null && !this.worldObj.isRemote && this.numUsingPlayers != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0) - { - this.numUsingPlayers = 0; - float var1 = 5.0F; - @SuppressWarnings("unchecked") - List var2 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB((double)((float)this.xCoord - var1), (double)((float)this.yCoord - var1), (double)((float)this.zCoord - var1), (double)((float)(this.xCoord + 1) + var1), (double)((float)(this.yCoord + 1) + var1), (double)((float)(this.zCoord + 1) + var1))); - Iterator var3 = var2.iterator(); + while (var3.hasNext()) { + EntityPlayer var4 = var3.next(); - while (var3.hasNext()) - { - EntityPlayer var4 = var3.next(); + if (var4.openContainer instanceof ContainerIronChest) { + ++numUsingPlayers; + } + } + } - if (var4.openContainer instanceof ContainerIronChest) - { - ++this.numUsingPlayers; - } - } - } + if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0) { + worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); + } + if (!worldObj.isRemote && inventoryTouched) { + inventoryTouched = false; + sortTopStacks(); + } - if (worldObj != null && !worldObj.isRemote && ticksSinceSync < 0) - { - worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); - } - if (!worldObj.isRemote && inventoryTouched) - { - inventoryTouched = false; - sortTopStacks(); - } + ticksSinceSync++; + 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; + } + } + } - this.ticksSinceSync++; - 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 boolean 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; + } + return true; + } - @Override - public boolean 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; - } - return true; - } + @Override + public void openInventory() { + ++numUsingPlayers; + worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers); + } - @Override - public void openInventory() - { - if (worldObj == null) return; - numUsingPlayers++; - worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers); - } + @Override + public void closeInventory() { + --numUsingPlayers; + worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers); + } - @Override - public void closeInventory() - { - if (worldObj == null) return; - numUsingPlayers--; - worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 1, numUsingPlayers); - } + public void setFacing(int facing2) { + facing = facing2; + } - public void setFacing(int facing2) - { - this.facing = facing2; - } + public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) { + if (numUsingPlayers > 0 || !itemChestChanger.getType().canUpgrade(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, worldObj, xCoord, yCoord, zCoord); + newEntity.setFacing(facing); + newEntity.sortTopStacks(); + newEntity.ticksSinceSync = -1; + return newEntity; + } - 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(); - newEntity.ticksSinceSync = -1; - return newEntity; - } + public ItemStack[] getTopItemStacks() { + return topStacks; + } - public ItemStack[] getTopItemStacks() - { - return topStacks; - } + public TileEntityIronChest updateFromMetadata(int l) { + if (worldObj != null && worldObj.isRemote) { + if (l != type.ordinal()) { + worldObj.setTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l)); + return (TileEntityIronChest) worldObj.getTileEntity(xCoord, yCoord, zCoord); + } + } + return this; + } - public TileEntityIronChest updateFromMetadata(int l) - { - if (worldObj != null && worldObj.isRemote) - { - if (l != type.ordinal()) - { - worldObj.setTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l)); - return (TileEntityIronChest) worldObj.getTileEntity(xCoord, yCoord, zCoord); - } - } - return this; - } + @Override + public Packet getDescriptionPacket() { + return PacketHandler.getPacket(this); + } - @Override - public Packet getDescriptionPacket() - { - return PacketHandler.getPacket(this); - } + public void handlePacketData(int typeData, int[] intData) { + TileEntityIronChest chest = this; + if (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) { + Item it = Item.getItemById(intData[pos]); + ItemStack is = new ItemStack(it, intData[pos + 2], intData[pos + 1]); + chest.topStacks[i] = is; + } else { + chest.topStacks[i] = null; + } + pos += 3; + } + } + } - 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) - { - Item it = Item.getItemById(intData[pos]); - ItemStack is = new ItemStack(it, 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++] = Item.getIdFromItem(is.getItem()); + sortList[pos++] = is.getItemDamage(); + sortList[pos++] = is.stackSize; + } else { + sortList[pos++] = 0; + sortList[pos++] = 0; + sortList[pos++] = 0; + } + } + return sortList; + } + return null; + } - 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++] = Item.getIdFromItem(is.getItem()); - sortList[pos++] = is.getItemDamage(); - sortList[pos++] = is.stackSize; - } - else - { - sortList[pos++] = 0; - sortList[pos++] = 0; - sortList[pos++] = 0; - } - } - return sortList; - } - return null; - } + @Override + public ItemStack getStackInSlotOnClosing(int par1) { + if (chestContents[par1] != null) { + ItemStack var2 = chestContents[par1]; + chestContents[par1] = null; + return var2; + } else { + return null; + } + } - @Override - public ItemStack getStackInSlotOnClosing(int par1) - { - if (this.chestContents[par1] != null) - { - ItemStack var2 = this.chestContents[par1]; - this.chestContents[par1] = null; - return var2; - } - else - { - return null; - } - } + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return type.acceptsStack(itemstack); + } - public void setMaxStackSize(int size) - { + @Override + public boolean hasCustomInventoryName() { + return false; + } - } + void rotateAround(ForgeDirection axis) { + setFacing((byte) ForgeDirection.getOrientation(facing).getRotation(axis).ordinal()); + worldObj.addBlockEvent(xCoord, yCoord, zCoord, IronChest.ironChestBlock, 2, getFacing()); + } - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) - { - return type.acceptsStack(itemstack); - } + public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) {} - @Override - public boolean hasCustomInventoryName() - { - return false; - } - - void rotateAround(ForgeDirection axis) - { - setFacing((byte)ForgeDirection.getOrientation(facing).getRotation(axis).ordinal()); - worldObj.addBlockEvent(this.xCoord, this.yCoord, this.zCoord, IronChest.ironChestBlock, 2, getFacing()); - } - - public void wasPlaced(EntityLivingBase entityliving, ItemStack itemStack) - { - } - - public void removeAdornments() - { - - } -} + public void removeAdornments() {} +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/TileEntityObsidianChest.java b/src/main/java/cpw/mods/ironchest/TileEntityObsidianChest.java index 021c3ae..fed9039 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntityObsidianChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntityObsidianChest.java @@ -1,8 +1,7 @@ package cpw.mods.ironchest; public class TileEntityObsidianChest extends TileEntityIronChest { - public TileEntityObsidianChest() - { - super(IronChestType.OBSIDIAN); - } -} + public TileEntityObsidianChest() { + super(IronChestType.OBSIDIAN); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/TileEntitySilverChest.java b/src/main/java/cpw/mods/ironchest/TileEntitySilverChest.java index 4743d0c..5fd4e13 100644 --- a/src/main/java/cpw/mods/ironchest/TileEntitySilverChest.java +++ b/src/main/java/cpw/mods/ironchest/TileEntitySilverChest.java @@ -1,8 +1,7 @@ package cpw.mods.ironchest; public class TileEntitySilverChest extends TileEntityIronChest { - public TileEntitySilverChest() - { - super(IronChestType.SILVER); - } -} + public TileEntitySilverChest() { + super(IronChestType.SILVER); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/ValidatingSlot.java b/src/main/java/cpw/mods/ironchest/ValidatingSlot.java index f0348c9..78bd7dd 100644 --- a/src/main/java/cpw/mods/ironchest/ValidatingSlot.java +++ b/src/main/java/cpw/mods/ironchest/ValidatingSlot.java @@ -5,17 +5,15 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ValidatingSlot extends Slot { - private IronChestType type; + private IronChestType type; - public ValidatingSlot(IInventory par1iInventory, int par2, int par3, int par4, IronChestType type) - { - super(par1iInventory, par2, par3, par4); - this.type = type; - } + public ValidatingSlot(IInventory inv, int i, int j, int k, IronChestType type) { + super(inv, i, j, k); + this.type = type; + } - @Override - public boolean isItemValid(ItemStack par1ItemStack) - { - return type.acceptsStack(par1ItemStack); - } -} + @Override + public boolean isItemValid(ItemStack is) { + return type.acceptsStack(is); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/Version.java b/src/main/java/cpw/mods/ironchest/Version.java index b93fd34..50428fd 100644 --- a/src/main/java/cpw/mods/ironchest/Version.java +++ b/src/main/java/cpw/mods/ironchest/Version.java @@ -3,22 +3,19 @@ package cpw.mods.ironchest; import java.util.Properties; public class Version { - private static String major, minor, rev, build, mcversion; + private static String major, minor, rev, 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"); - } - } + 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); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/client/ClientProxy.java b/src/main/java/cpw/mods/ironchest/client/ClientProxy.java index c1737cc..dc9179e 100644 --- a/src/main/java/cpw/mods/ironchest/client/ClientProxy.java +++ b/src/main/java/cpw/mods/ironchest/client/ClientProxy.java @@ -11,35 +11,28 @@ import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.TileEntityIronChest; public class ClientProxy extends CommonProxy { - @Override - public void registerRenderInformation() - { - TileEntityRendererChestHelper.instance = new IronChestRenderHelper(); - } + @Override + public void registerRenderInformation() { + TileEntityRendererChestHelper.instance = new IronChestRenderHelper(); + } - @Override - public void registerTileEntitySpecialRenderer(IronChestType typ) - { - ClientRegistry.bindTileEntitySpecialRenderer(typ.clazz, new TileEntityIronChestRenderer()); - } + @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.getTileEntity(x, y, z); + if (te != null && te instanceof TileEntityIronChest) { + return GuiIronChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te); + } else { + return null; + } + } - @Override - public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) - { - TileEntity te = world.getTileEntity(x, y, z); - if (te != null && te instanceof TileEntityIronChest) - { - return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te); - } - else - { - return null; - } - } -} + @Override + public World getClientWorld() { + return FMLClientHandler.instance().getClient().theWorld; + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/client/GUIChest.java b/src/main/java/cpw/mods/ironchest/client/GUIChest.java deleted file mode 100644 index 79cd934..0000000 --- a/src/main/java/cpw/mods/ironchest/client/GUIChest.java +++ /dev/null @@ -1,88 +0,0 @@ -package cpw.mods.ironchest.client; - -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.util.ResourceLocation; - -import org.lwjgl.opengl.GL11; - -import cpw.mods.ironchest.ContainerIronChest; -import cpw.mods.ironchest.IronChestType; -import cpw.mods.ironchest.TileEntityIronChest; - -public class GUIChest extends GuiContainer { - public enum ResourceList { - IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")), - COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")), - SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")), - GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")), - DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")), - DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png")); - public final ResourceLocation location; - private ResourceList(ResourceLocation loc) { - this.location = loc; - } - } - public enum GUI { - IRON(184, 202, ResourceList.IRON, IronChestType.IRON), - GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD), - DIAMOND(238, 256, ResourceList.DIAMOND, IronChestType.DIAMOND), - COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER), - SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER), - CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL), - OBSIDIAN(238, 256, ResourceList.DIAMOND, IronChestType.OBSIDIAN), - DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000); - - private int xSize; - private int ySize; - private ResourceList guiResourceList; - private IronChestType mainType; - - private GUI(int xSize, int ySize, ResourceList guiResourceList, IronChestType mainType) - { - this.xSize = xSize; - this.ySize = ySize; - this.guiResourceList = guiResourceList; - this.mainType = mainType; - - } - - protected Container makeContainer(IInventory player, IInventory chest) - { - return new ContainerIronChest(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) - { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - // new "bind tex" - this.mc.getTextureManager().bindTexture(type.guiResourceList.location); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - } -} diff --git a/src/main/java/cpw/mods/ironchest/client/GuiIronChest.java b/src/main/java/cpw/mods/ironchest/client/GuiIronChest.java new file mode 100644 index 0000000..62df18a --- /dev/null +++ b/src/main/java/cpw/mods/ironchest/client/GuiIronChest.java @@ -0,0 +1,81 @@ +package cpw.mods.ironchest.client; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.ironchest.ContainerIronChest; +import cpw.mods.ironchest.IronChestType; +import cpw.mods.ironchest.TileEntityIronChest; + +public class GuiIronChest extends GuiContainer { + public enum ResourceList { + IRON(new ResourceLocation("ironchest", "textures/gui/ironcontainer.png")), + COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")), + SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")), + GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")), + DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")), + DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png")); + public final ResourceLocation location; + + private ResourceList(ResourceLocation loc) { + this.location = loc; + } + } + + public enum GUI { + IRON(184, 202, ResourceList.IRON, IronChestType.IRON), + GOLD(184, 256, ResourceList.GOLD, IronChestType.GOLD), + DIAMOND(238, 256, ResourceList.DIAMOND, IronChestType.DIAMOND), + COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER), + SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER), + CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL), + OBSIDIAN(238, 256, ResourceList.DIAMOND, IronChestType.OBSIDIAN), + DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000); + + private int xSize, ySize; + private ResourceList guiResourceList; + private IronChestType mainType; + + private GUI(int xSize, int ySize, ResourceList guiResourceList, IronChestType mainType) { + this.xSize = xSize; + this.ySize = ySize; + this.guiResourceList = guiResourceList; + this.mainType = mainType; + } + + protected Container makeContainer(IInventory player, IInventory chest) { + return new ContainerIronChest(player, chest, mainType, xSize, ySize); + } + + public static GuiIronChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory) { + return new GuiIronChest(values()[chestInventory.getType().ordinal()], playerInventory, chestInventory); + } + } + + public int getRowLength() { + return type.mainType.getRowLength(); + } + + private GUI type; + + private GuiIronChest(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) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(type.guiResourceList.location); + int x = (width - xSize) / 2; + int y = (height - ySize) / 2; + drawTexturedModalRect(x, y, 0, 0, xSize, ySize); + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/client/IronChestRenderHelper.java b/src/main/java/cpw/mods/ironchest/client/IronChestRenderHelper.java index 5780cda..988703d 100644 --- a/src/main/java/cpw/mods/ironchest/client/IronChestRenderHelper.java +++ b/src/main/java/cpw/mods/ironchest/client/IronChestRenderHelper.java @@ -1,35 +1,31 @@ package cpw.mods.ironchest.client; import java.util.Map; + import net.minecraft.block.Block; import net.minecraft.client.renderer.tileentity.TileEntityRendererChestHelper; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; + import com.google.common.collect.Maps; + import cpw.mods.ironchest.IronChest; import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.TileEntityIronChest; public class IronChestRenderHelper extends TileEntityRendererChestHelper { - 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())); - } - } + 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) - { - TileEntityRendererDispatcher.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F); - } - else - { - super.renderChest(block, i, f); - } - } -} + @Override + public void renderChest(Block block, int i, float f) { + if (block == IronChest.ironChestBlock) { + TileEntityRendererDispatcher.instance.renderTileEntityAt(itemRenders.get(i), 0.0D, 0.0D, 0.0D, 0.0F); + } else { + super.renderChest(block, i, f); + } + } +} \ No newline at end of file diff --git a/src/main/java/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java b/src/main/java/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java index 32c90a0..c8f54a0 100644 --- a/src/main/java/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java +++ b/src/main/java/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java @@ -8,11 +8,11 @@ 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.client.model.ModelChest; -import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; @@ -20,146 +20,140 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.primitives.SignedBytes; + import cpw.mods.ironchest.IronChestType; -import cpw.mods.ironchest.MappableItemStackWrapper; import cpw.mods.ironchest.TileEntityIronChest; public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { - private static Map locations; - - static { - Builder builder = ImmutableMap.builder(); - for (IronChestType typ : IronChestType.values()) { - builder.put(typ, new ResourceLocation("ironchest","textures/model/"+typ.getModelTexture())); - } - locations = builder.build(); - } - - private Random random; - private RenderItem itemRenderer; + private ModelChest model; + private static Map locations; - 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 }, }; + static { + Builder builder = ImmutableMap. builder(); + for (IronChestType typ : IronChestType.values()) + builder.put(typ, new ResourceLocation("ironchest", "textures/model/" + typ.getModelTexture())); + locations = builder.build(); + } - public TileEntityIronChestRenderer() - { - model = new ModelChest(); - random = new Random(); - itemRenderer = new RenderItem() { - @Override - public byte getMiniBlockCount(ItemStack stack, byte original) { - return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1); - } - @Override - public byte getMiniItemCount(ItemStack stack, byte original) { - return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 7) + 1); - } - @Override - public boolean shouldBob() { - return false; - } - @Override - public boolean shouldSpreadItems() { - return false; - } - }; - itemRenderer.setRenderManager(RenderManager.instance); - } + private Random random; + private RenderItem itemRenderer; - 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.hasWorldObj()) { - facing = tile.getFacing(); - type = tile.getType(); - int typ = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord); - type = IronChestType.values()[typ]; - } - bindTexture(locations.get(type)); - 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.field_147501_a.field_147560_j, this.field_147501_a.field_147561_k, this.field_147501_a.field_147558_l) < 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(field_147501_a.field_147550_f); - customitem.hoverStart = 0f; - for (ItemStack item : tile.getTopItemStacks()) { - if (shift > shifts.length) { - break; - } - if (item == null) { - shift++; - continue; - } - shiftX = shifts[shift][0]; - shiftY = shifts[shift][1]; - shiftZ = shifts[shift][2]; - shift++; - glPushMatrix(); - glTranslatef(shiftX, shiftY, shiftZ); - glRotatef(timeD, 0.0F, 1.0F, 0.0F); - glScalef(blockScale, blockScale, blockScale); - customitem.setEntityItemStack(item); - itemRenderer.doRender(customitem, 0, 0, 0, 0, 0); - glPopMatrix(); - } - glEnable(2896 /* GL_LIGHTING */); - glPopMatrix(); - glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - } - } + 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 }, }; - @Override - public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick) - { - render((TileEntityIronChest) tileentity, x, y, z, partialTick); - } + public TileEntityIronChestRenderer() { + model = new ModelChest(); + random = new Random(); + itemRenderer = new RenderItem() { + @Override + public byte getMiniBlockCount(ItemStack stack, byte original) { + return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 15) + 1); + } - private ModelChest model; -} + @Override + public byte getMiniItemCount(ItemStack stack, byte original) { + return SignedBytes.saturatedCast(Math.min(stack.stackSize / 32, 7) + 1); + } + + @Override + public boolean shouldBob() { + return false; + } + + @Override + public boolean shouldSpreadItems() { + return false; + } + }; + itemRenderer.setRenderManager(RenderManager.instance); + } + + 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.hasWorldObj()) { + facing = tile.getFacing(); + type = tile.getType(); + int typ = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord); + type = IronChestType.values()[typ]; + } + bindTexture(locations.get(type)); + glPushMatrix(); + glEnable(32826); + 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); + model.renderAll(); + glDisable(32826); + glPopMatrix(); + glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + if (type.isTransparent() && tile.getDistanceFrom(this.field_147501_a.field_147560_j, this.field_147501_a.field_147561_k, this.field_147501_a.field_147558_l) < 128d) { + random.setSeed(254L); + float shiftX, shiftY, shiftZ, blockScale = 0.70F; + int shift = 0; + if (tile.getTopItemStacks()[1] == null) { + shift = 8; + blockScale = 0.85F; + } + glPushMatrix(); + glDisable(2896); + glTranslatef((float) x, (float) y, (float) z); + EntityItem customitem = new EntityItem(field_147501_a.field_147550_f); + 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((float) (360.0 * (double) (System.currentTimeMillis() & 0x3FFFL) / (double) 0x3FFFL), 0.0F, 1.0F, 0.0F); + glScalef(blockScale, blockScale, blockScale); + customitem.setEntityItemStack(item); + itemRenderer.doRender(customitem, 0, 0, 0, 0, 0); + glPopMatrix(); + } + glEnable(2896); + glPopMatrix(); + glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + } + } + + @Override + public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTick) { + render((TileEntityIronChest) tileentity, x, y, z, partialTick); + } +} \ No newline at end of file