From e4d36feb31a58f511bc4070663fb85b197823918 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Thu, 29 Mar 2012 00:31:46 -0400 Subject: [PATCH] Update to 1.2.4, no modloadermp anymore --- IronChests2/.classpath | 3 +- IronChests2/build.xml | 29 +- .../mods/ironchest/client/ClientProxy.java | 137 ++-- .../cpw/mods/ironchest/client/GUIChest.java | 15 +- .../client/TileEntityIronChestRenderer.java | 12 +- .../cpw/mods/ironchest/BlockIronChest.java | 338 ++++----- .../cpw/mods/ironchest/ChestChangerType.java | 2 +- .../ironchest/ContainerIronChestBase.java | 1 - .../common/cpw/mods/ironchest/IProxy.java | 18 +- .../cpw/mods/ironchest/IronChestType.java | 201 +++--- .../cpw/mods/ironchest/ItemChestChanger.java | 3 +- .../cpw/mods/ironchest/PacketHandler.java | 96 +++ .../cpw/mods/ironchest/ServerClientProxy.java | 14 +- .../mods/ironchest/TileEntityIronChest.java | 676 +++++++++--------- .../common/cpw/mods/ironchest/Version.java | 17 + .../net/minecraft/src/mod_IronChest.java | 175 ++--- .../mods/ironchest/server/ServerProxy.java | 51 +- 17 files changed, 921 insertions(+), 867 deletions(-) create mode 100644 IronChests2/common/cpw/mods/ironchest/PacketHandler.java create mode 100644 IronChests2/common/cpw/mods/ironchest/Version.java diff --git a/IronChests2/.classpath b/IronChests2/.classpath index 205dfb9..597b9fe 100644 --- a/IronChests2/.classpath +++ b/IronChests2/.classpath @@ -2,8 +2,7 @@ - - + diff --git a/IronChests2/build.xml b/IronChests2/build.xml index 1b9fdf0..d8efd84 100644 --- a/IronChests2/build.xml +++ b/IronChests2/build.xml @@ -7,14 +7,20 @@ cpw ====================================================================== --> - + Iron Chests - - + + + + + + + + @@ -74,7 +80,8 @@ - + + @@ -82,11 +89,13 @@ - - + + + + @@ -108,6 +117,14 @@ + + + + + + + + diff --git a/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java b/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java index 04557e8..6487c01 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java +++ b/IronChests2/client/cpw/mods/ironchest/client/ClientProxy.java @@ -3,112 +3,73 @@ package cpw.mods.ironchest.client; import java.io.File; import net.minecraft.client.Minecraft; -import net.minecraft.src.BaseModMp; import net.minecraft.src.ChestItemRenderHelper; import net.minecraft.src.EntityItem; -import net.minecraft.src.EntityPlayer; +import net.minecraft.src.EntityPlayerSP; import net.minecraft.src.GuiScreen; import net.minecraft.src.ModLoader; -import net.minecraft.src.ModLoaderMp; import net.minecraft.src.NBTTagCompound; -import net.minecraft.src.Packet; import net.minecraft.src.TileEntity; +import net.minecraft.src.World; import net.minecraft.src.forge.MinecraftForgeClient; import cpw.mods.ironchest.ChestChangerType; import cpw.mods.ironchest.IProxy; import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.TileEntityIronChest; -public class ClientProxy extends BaseModMp implements IProxy { - @Override - public void registerRenderInformation() { - ChestItemRenderHelper.instance=new IronChestRenderHelper(); - MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png"); - MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png"); - } +public class ClientProxy implements IProxy { + @Override + public void registerRenderInformation() { + ChestItemRenderHelper.instance = new IronChestRenderHelper(); + MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/block_textures.png"); + MinecraftForgeClient.preloadTexture("/cpw/mods/ironchest/sprites/item_textures.png"); + } - @Override - public void registerTileEntities() { - for (IronChestType typ : IronChestType.values()) { - ModLoader.registerTileEntity(typ.clazz, typ.name(), new TileEntityIronChestRenderer()); - } - } + @Override + public void registerTileEntities() { + for (IronChestType typ : IronChestType.values()) { + ModLoader.registerTileEntity(typ.clazz, typ.name(), new TileEntityIronChestRenderer()); + } + } - @Override - public void registerTranslations() { - for (IronChestType typ : IronChestType.values()) { - ModLoader.addLocalization(typ.name() + ".name", typ.friendlyName); - } - for (ChestChangerType typ : ChestChangerType.values()) { - ModLoader.addLocalization("item."+typ.itemName+".name", typ.descriptiveName); - } - } + @Override + public void registerTranslations() { + for (IronChestType typ : IronChestType.values()) { + ModLoader.addLocalization(typ.name() + ".name", typ.friendlyName); + } + for (ChestChangerType typ : ChestChangerType.values()) { + ModLoader.addLocalization("item." + typ.itemName + ".name", typ.descriptiveName); + } + } - @Override - public void showGUI(TileEntityIronChest te, EntityPlayer player) { - GUIChest.GUI.showGUI(te, player); - - } + @Override + public File getMinecraftDir() { + return Minecraft.getMinecraftDir(); + } - @Override - public File getMinecraftDir() { - return Minecraft.getMinecraftDir(); - } + @Override + public void applyExtraDataToDrops(EntityItem entityitem, NBTTagCompound data) { + entityitem.item.setTagCompound(data); - @Override - public void applyExtraDataToDrops(EntityItem entityitem, NBTTagCompound data) { - entityitem.item.setTagCompound(data); - - } + } - @Override - public void registerGUI(int guiId) { - ModLoaderMp.registerGUI(this, guiId); - } + @Override + public boolean isRemote() { + return ModLoader.getMinecraftInstance().theWorld.isRemote; + } - @Override - public String getVersion() { - // Do nothing, we never get loaded like that - return ""; - } + @Override + public GuiScreen getGuiScreen(int ID, EntityPlayerSP player, World world, int X, int Y, int Z) { + TileEntity te = world.getBlockTileEntity(X, Y, Z); + if (te != null && te instanceof TileEntityIronChest) { + return GUIChest.GUI.buildGUI(IronChestType.values()[ID], player.inventory, (TileEntityIronChest) te); + } else { + return null; + } + } - @Override - public void load() { - // Do Nothing, we never get loaded like that - } - - @Override - public GuiScreen handleGUI(int i) { - for (IronChestType type: IronChestType.values()) { - if (type.guiId==i) { - return GUIChest.GUI.buildGUI(type,ModLoader.getMinecraftInstance().thePlayer.inventory,IronChestType.makeEntity(type.ordinal())); - } - } - return null; - } - - @Override - public void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData) { - TileEntity te=ModLoader.getMinecraftInstance().theWorld.getBlockTileEntity(x, y, z); - if (te!=null && te instanceof TileEntityIronChest) { - TileEntityIronChest icte=(TileEntityIronChest)te; - icte.handlePacketData(type,intData,floatData,stringData); - } - } - - @Override - public Packet getDescriptionPacket(TileEntityIronChest tile) { - // NOOP on client - return null; - } - - @Override - public void sendTileEntityUpdate(TileEntityIronChest tile) { - // NOOP on client - } - - @Override - public boolean isRemote() { - return ModLoader.getMinecraftInstance().theWorld.isRemote; - } + @Override + public World getCurrentWorld() { + return ModLoader.getMinecraftInstance().theWorld; + } } diff --git a/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java b/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java index 05bd1e7..612b754 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java +++ b/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java @@ -38,20 +38,7 @@ public class GUIChest extends GuiContainer { } public static GUIChest buildGUI(IronChestType type, IInventory playerInventory, TileEntityIronChest chestInventory) { - for (GUI gui : values()) { - if (chestInventory.getType()==gui.mainType) { - return new GUIChest(gui,playerInventory,chestInventory); - } - } - return null; - } - public static void showGUI(TileEntityIronChest te, EntityPlayer player) { - GUIChest gui=buildGUI(te.getType(),player.inventory,te); - if (gui!=null) { - ModLoader.openGUI(player, gui); - } else { - player.displayGUIChest(te); - } + return new GUIChest(values()[chestInventory.getType().ordinal()],playerInventory,chestInventory); } } diff --git a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java index 55421e5..7603f88 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java +++ b/IronChests2/client/cpw/mods/ironchest/client/TileEntityIronChestRenderer.java @@ -12,6 +12,7 @@ import static org.lwjgl.opengl.GL11.glTranslatef; import java.util.Random; import net.minecraft.src.Block; +import net.minecraft.src.EntityItem; import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.ModelChest; @@ -20,7 +21,8 @@ import net.minecraft.src.Tessellator; import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntitySpecialRenderer; import net.minecraft.src.forge.ForgeHooksClient; -import net.minecraft.src.forge.ICustomItemRenderer; +import net.minecraft.src.forge.IItemRenderer; +import net.minecraft.src.forge.ItemRenderType; import net.minecraft.src.forge.MinecraftForgeClient; import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.TileEntityIronChest; @@ -101,6 +103,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { glDisable(2896 /* GL_LIGHTING */); glEnable(32826 /* GL_RESCALE_NORMAL_EXT */); glTranslatef((float) x, (float) y, (float) z); + EntityItem customitem=new EntityItem(tileEntityRenderer.worldObj); for (ItemStack item : tile.getTopItemStacks()) { if (shift > shifts.length) { break; @@ -113,7 +116,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { shiftY = shifts[shift][1]; shiftZ = shifts[shift][2]; shift++; - ICustomItemRenderer customRenderer = MinecraftForgeClient.getCustomItemRenderer(item.itemID); + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item,ItemRenderType.ENTITY); float localScale = blockScale; if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID]!=null) { int j = Block.blocksList[item.itemID].getRenderType(); @@ -135,9 +138,10 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer { } if (customRenderer != null) { + customitem.item=item; bindTextureByName("/terrain.png"); - ForgeHooksClient.overrideTexture(item.getItem()); - ForgeHooksClient.renderCustomItem(customRenderer, renderBlocks, item.itemID, item.getItemDamage(), 1.0F); + ForgeHooksClient.overrideTexture(item.getItem()); + ForgeHooksClient.renderEntityItem(customRenderer, renderBlocks, customitem); } else if (item.itemID < Block.blocksList.length && Block.blocksList[item.itemID]!=null && RenderBlocks.renderItemIn3d(Block.blocksList[item.itemID].getRenderType())) { bindTextureByName("/terrain.png"); ForgeHooksClient.overrideTexture(Block.blocksList[item.itemID]); diff --git a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java index 4acf6dc..15a9729 100644 --- a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java @@ -19,179 +19,185 @@ import net.minecraft.src.forge.ITextureProvider; public class BlockIronChest extends BlockContainer implements ITextureProvider { - private Random random; - public BlockIronChest(int id) { - super(id, Material.iron); - setBlockName("IronChest"); - setHardness(3.0F); - setRequiresSelfNotify(); - if (id>=256) { - disableStats(); - } - random=new Random(); - } + private Random random; - @Override - public TileEntity getBlockEntity() { - return null; - } + public BlockIronChest(int id) { + super(id, Material.iron); + setBlockName("IronChest"); + setHardness(3.0F); + setRequiresSelfNotify(); + if (id >= 256) { + disableStats(); + } + random = new Random(); + } - @Override - public String getTextureFile() { - return "/cpw/mods/ironchest/sprites/block_textures.png"; - } + @Override + public TileEntity getBlockEntity() { + return null; + } - @Override - public boolean isOpaqueCube() { - return false; - } - - @Override - public boolean renderAsNormalBlock() { - return false; - } - @Override - public int getRenderType() { - return 22; - } - @Override - public TileEntity getBlockEntity(int metadata) { - return IronChestType.makeEntity(metadata); - } + @Override + public String getTextureFile() { + return "/cpw/mods/ironchest/sprites/block_textures.png"; + } - public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) { - int meta=worldAccess.getBlockMetadata(i, j, k); - IronChestType type=IronChestType.values()[meta]; - TileEntity te = worldAccess.getBlockTileEntity(i, j, k); - TileEntityIronChest icte=null; - if (te!=null && te instanceof TileEntityIronChest) { - icte=(TileEntityIronChest)te; - } - if (l==0 || l==1) { // Top and Bottom - return type.getTextureRow()*16+1; - } else if (icte!=null && l==icte.getFacing()) { // Front - return type.getTextureRow()*16+2; - } else { // Back and Sides - return type.getTextureRow()*16; - } - } + @Override + public boolean isOpaqueCube() { + return false; + } - @Override - public int getBlockTextureFromSideAndMetadata(int i, int j) { - IronChestType typ=IronChestType.values()[j]; - switch (i) { - case 0: - case 1: - return typ.getTextureRow()*16+1; - case 3: - return typ.getTextureRow()*16+2; - default: - return typ.getTextureRow()*16; - } - } - @Override - public boolean blockActivated(World world, int i, int j, int k, EntityPlayer player) { - TileEntity te = world.getBlockTileEntity(i, j, k); - - if(te == null || !(te instanceof TileEntityIronChest)) + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public int getRenderType() { + return 22; + } + + @Override + public TileEntity getBlockEntity(int metadata) { + return IronChestType.makeEntity(metadata); + } + + public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) { + int meta = worldAccess.getBlockMetadata(i, j, k); + IronChestType type = IronChestType.values()[meta]; + TileEntity te = worldAccess.getBlockTileEntity(i, j, k); + TileEntityIronChest icte = null; + if (te != null && te instanceof TileEntityIronChest) { + icte = (TileEntityIronChest) te; + } + if (l == 0 || l == 1) { // Top and Bottom + return type.getTextureRow() * 16 + 1; + } else if (icte != null && l == icte.getFacing()) { // Front + return type.getTextureRow() * 16 + 2; + } else { // Back and Sides + return type.getTextureRow() * 16; + } + } + + @Override + public int getBlockTextureFromSideAndMetadata(int i, int j) { + IronChestType typ = IronChestType.values()[j]; + switch (i) { + case 0: + case 1: + return typ.getTextureRow() * 16 + 1; + case 3: + return typ.getTextureRow() * 16 + 2; + default: + return typ.getTextureRow() * 16; + } + } + + @Override + public boolean blockActivated(World world, int i, int j, int k, EntityPlayer player) { + TileEntity te = world.getBlockTileEntity(i, j, k); + + if (te == null || !(te instanceof TileEntityIronChest)) + { + return true; + } + + if (world.isBlockSolidOnSide(i, j + 1, k, 0)) + { + return true; + } + + if (world.isRemote) { + return true; + } + + player.openGui(mod_IronChest.instance, ((TileEntityIronChest) te).getType().ordinal(), world, i, j, k); + return true; + } + + @Override + public void onBlockAdded(World world, int i, int j, int k) { + super.onBlockAdded(world, i, j, k); + world.markBlockNeedsUpdate(i, j, k); + } + + @Override + public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) { + byte chestFacing = 0; + int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3; + if (facing == 0) { + chestFacing = 2; + } + if (facing == 1) { + chestFacing = 5; + } + if (facing == 2) { + chestFacing = 3; + } + if (facing == 3) { + chestFacing = 4; + } + TileEntity te = world.getBlockTileEntity(i, j, k); + if (te != null && te instanceof TileEntityIronChest) { + ((TileEntityIronChest) te).setFacing(chestFacing); + world.markBlockNeedsUpdate(i, j, k); + } + } + + @Override + protected int damageDropped(int i) { + return i; + } + + public void onBlockRemoval(World world, int i, int j, int k) + { + TileEntityIronChest tileentitychest = (TileEntityIronChest) world.getBlockTileEntity(i, j, k); + if (tileentitychest != null) + { + dropContent(0, tileentitychest, world); + } + super.onBlockRemoval(world, i, j, k); + } + + public void dropContent(int newSize, TileEntityIronChest chest, World world) { + 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) { - return true; + i1 = itemstack.stackSize; } - - if(world.isBlockSolidOnSide(i, j + 1, k, 0)) + itemstack.stackSize -= i1; + EntityItem entityitem = new EntityItem(world, (float) chest.xCoord + f, (float) chest.yCoord + (newSize > 0 ? 1 : 0) + f1, (float) chest.zCoord + f2, + new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage())); + float f3 = 0.05F; + entityitem.motionX = (float) random.nextGaussian() * f3; + entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F; + entityitem.motionZ = (float) random.nextGaussian() * f3; + if (itemstack.hasTagCompound()) { - return true; + mod_IronChest.proxy.applyExtraDataToDrops(entityitem, (NBTTagCompound) itemstack.getTagCompound().copy()); } - - if (world.isRemote) { - return true; - } - - mod_IronChest.openGUI(player, (TileEntityIronChest)te); - return true; - } - - @Override - public void onBlockAdded(World world, int i, int j, int k) { - super.onBlockAdded(world, i, j, k); - world.markBlockNeedsUpdate(i, j, k); - } - - @Override - public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) { - byte chestFacing = 0; - int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3; - if (facing == 0) { - chestFacing = 2; - } - if (facing == 1) { - chestFacing = 5; - } - if (facing == 2) { - chestFacing = 3; - } - if (facing == 3) { - chestFacing = 4; - } - TileEntity te = world.getBlockTileEntity(i, j, k); - if (te != null && te instanceof TileEntityIronChest) { - ((TileEntityIronChest) te).setFacing(chestFacing); - world.markBlockNeedsUpdate(i, j, k); - } - } - @Override - protected int damageDropped(int i) { - return i; - } + world.spawnEntityInWorld(entityitem); + } + } + } - public void onBlockRemoval(World world, int i, int j, int k) - { - TileEntityIronChest tileentitychest = (TileEntityIronChest)world.getBlockTileEntity(i, j, k); - if (tileentitychest != null) - { - dropContent(0, tileentitychest, world); - } - super.onBlockRemoval(world, i, j, k); - } - - public void dropContent(int newSize, TileEntityIronChest chest, World world) { - 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)chest.xCoord + f, (float)chest.yCoord + (newSize>0 ? 1 : 0) + f1, (float)chest.zCoord + f2, new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage())); - float f3 = 0.05F; - entityitem.motionX = (float)random.nextGaussian() * f3; - entityitem.motionY = (float)random.nextGaussian() * f3 + 0.2F; - entityitem.motionZ = (float)random.nextGaussian() * f3; - if (itemstack.hasTagCompound()) - { - mod_IronChest.proxy.applyExtraDataToDrops(entityitem, (NBTTagCompound)itemstack.getTagCompound().copy()); - } - world.spawnEntityInWorld(entityitem); - } - } - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void addCreativeItems(ArrayList itemList) { - for (IronChestType type : IronChestType.values()) { - itemList.add(new ItemStack(this,1,type.ordinal())); - } - } -} \ No newline at end of file + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addCreativeItems(ArrayList itemList) { + for (IronChestType type : IronChestType.values()) { + itemList.add(new ItemStack(this, 1, type.ordinal())); + } + } +} \ No newline at end of file diff --git a/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java b/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java index 9a4c8ec..6dd350c 100644 --- a/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java +++ b/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java @@ -43,7 +43,7 @@ public enum ChestChangerType { } public ItemChestChanger buildItem(Configuration cfg, int id) { - int itemId=Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.ITEM_PROPERTY, id).value); + int itemId=Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.CATEGORY_ITEM, id).value); item=new ItemChestChanger(itemId,this); return item; } diff --git a/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java b/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java index 0f37009..1a03421 100644 --- a/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java +++ b/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java @@ -3,7 +3,6 @@ package cpw.mods.ironchest; import net.minecraft.src.Container; import net.minecraft.src.EntityPlayer; import net.minecraft.src.IInventory; -import net.minecraft.src.InventoryPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.Slot; diff --git a/IronChests2/common/cpw/mods/ironchest/IProxy.java b/IronChests2/common/cpw/mods/ironchest/IProxy.java index 909abca..e5fffcb 100644 --- a/IronChests2/common/cpw/mods/ironchest/IProxy.java +++ b/IronChests2/common/cpw/mods/ironchest/IProxy.java @@ -3,11 +3,11 @@ package cpw.mods.ironchest; import java.io.File; import net.minecraft.src.EntityItem; -import net.minecraft.src.EntityPlayer; import net.minecraft.src.NBTTagCompound; -import net.minecraft.src.Packet; +import net.minecraft.src.World; +import net.minecraft.src.forge.IGuiHandler; -public interface IProxy { +public interface IProxy extends IGuiHandler { public abstract void registerRenderInformation(); @@ -15,19 +15,11 @@ public interface IProxy { public abstract void registerTranslations(); - public abstract void showGUI(TileEntityIronChest te, EntityPlayer player); - public abstract File getMinecraftDir(); public abstract void applyExtraDataToDrops(EntityItem item, NBTTagCompound data); - public abstract void registerGUI(int guiId); - - public abstract void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData); - - public abstract Packet getDescriptionPacket(TileEntityIronChest tile); - - public abstract void sendTileEntityUpdate(TileEntityIronChest tile); - public abstract boolean isRemote(); + + public abstract World getCurrentWorld(); } diff --git a/IronChests2/common/cpw/mods/ironchest/IronChestType.java b/IronChests2/common/cpw/mods/ironchest/IronChestType.java index e1a2afc..2aafe14 100644 --- a/IronChests2/common/cpw/mods/ironchest/IronChestType.java +++ b/IronChests2/common/cpw/mods/ironchest/IronChestType.java @@ -7,131 +7,110 @@ import net.minecraft.src.Block; import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.ModLoader; -import net.minecraft.src.mod_IronChest; -import net.minecraft.src.forge.Configuration; public enum IronChestType { - IRON(54, 9, true, "Iron Chest", "guiIronChest", "ironchest.png", 0, Item.ingotIron, TileEntityIronChest.class, "mmmmPmmmm","mGmG3GmGm"), - GOLD(81, 9, true, "Gold Chest", "guiGoldChest", "goldchest.png", 1, Item.ingotGold, TileEntityGoldChest.class, "mmmmPmmmm","mGmG4GmGm"), - DIAMOND(108, 12, true, "Diamond Chest", "guiDiamondChest", "diamondchest.png", 2, Item.diamond, TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"), - COPPER(45, 9, false, "Copper Chest", "guiCopperChest", "copperchest.png", 3, null, TileEntityCopperChest.class, "mmmmCmmmm"), - SILVER(72, 9, false, "Silver Chest", "guiSilverChest", "silverchest.png", 4, null, TileEntitySilverChest.class, "mmmm0mmmm", "mGmG3GmGm"), - CRYSTAL(108, 12, true, "Crystal Chest", "guiDiamondChest", "crystalchest.png", 5, Item.itemsList[Block.glass.blockID], TileEntityCrystalChest.class, "GGGGPGGGG"); - int size; - private int rowLength; - public String friendlyName; - private boolean tieredChest; - private String modelTexture; - private String guiName; - private int textureRow; - public Class clazz; - Item mat; - private String[] recipes; - public int guiId; - private ArrayList matList; + IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Item.ingotIron, TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"), + GOLD(81, 9, true, "Gold Chest", "goldchest.png", 1, Item.ingotGold, TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"), + DIAMOND(108, 12, true, "Diamond Chest", "diamondchest.png", 2, Item.diamond, TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"), + COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, null, TileEntityCopperChest.class, "mmmmCmmmm"), + SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, null, TileEntitySilverChest.class, "mmmm0mmmm", "mGmG3GmGm"), + CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Item.itemsList[Block.glass.blockID], TileEntityCrystalChest.class, "GGGGPGGGG"); + int size; + private int rowLength; + public String friendlyName; + private boolean tieredChest; + private String modelTexture; + private int textureRow; + public Class clazz; + Item mat; + private String[] recipes; + private ArrayList matList; - IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String guiName, String modelTexture, int textureRow, Item mat, - Class clazz, String... recipes) { - this.size = size; - this.rowLength = rowLength; - this.tieredChest = tieredChest; - this.friendlyName = friendlyName; - this.guiName = guiName; - this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture; - this.textureRow = textureRow; - this.clazz = clazz; - this.mat = mat; - this.recipes = recipes; - this.matList=new ArrayList(); - if (mat!=null) { - matList.add(new ItemStack(mat)); - } - } + IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, Item mat, + Class clazz, String... recipes) { + this.size = size; + this.rowLength = rowLength; + this.tieredChest = tieredChest; + this.friendlyName = friendlyName; + this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture; + this.textureRow = textureRow; + this.clazz = clazz; + this.mat = mat; + this.recipes = recipes; + this.matList = new ArrayList(); + if (mat != null) { + matList.add(new ItemStack(mat)); + } + } - public String getModelTexture() { - return modelTexture; - } + public String getModelTexture() { + return modelTexture; + } - public int getTextureRow() { - return textureRow; - } + public int getTextureRow() { + return textureRow; + } - public static TileEntityIronChest makeEntity(int metadata) { - // Compatibility - int 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 static TileEntityIronChest makeEntity(int metadata) { + // Compatibility + int 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 static void registerTranslations() { - } + public static void registerTranslations() { + } - public static void generateTieredRecipies(BlockIronChest blockResult) { - ItemStack previous = new ItemStack(Block.chest); - for (IronChestType typ : values()) { - if (!typ.tieredChest) - continue; - generateRecipesForType(blockResult, previous, typ, typ.mat); - previous = new ItemStack(blockResult, 1, typ.ordinal()); - } - } + public static void generateTieredRecipies(BlockIronChest blockResult) { + ItemStack previous = new ItemStack(Block.chest); + for (IronChestType typ : values()) { + if (!typ.tieredChest) + continue; + generateRecipesForType(blockResult, previous, typ, typ.mat); + previous = new ItemStack(blockResult, 1, typ.ordinal()); + } + } - public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type, Object mat) { - for (String recipe : type.recipes) { - String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) }; - addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mat, 'P', previousTier, 'G', Block.glass, 'C', Block.chest, - '0', new ItemStack(blockResult, 1, 0)/* Iron */, '1', new ItemStack(blockResult, 1, 1)/* GOLD */, '3', new ItemStack(blockResult, - 1, 3)/* Copper */, '4', new ItemStack(blockResult,1,4)); - } - } + public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type, Object mat) { + for (String recipe : type.recipes) { + String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) }; + addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, 'm', mat, 'P', previousTier, 'G', Block.glass, 'C', Block.chest, + '0', new ItemStack(blockResult, 1, 0)/* Iron */, '1', new ItemStack(blockResult, 1, 1)/* GOLD */, '3', new ItemStack(blockResult, + 1, 3)/* Copper */, '4', new ItemStack(blockResult, 1, 4)); + } + } - public static void addRecipe(ItemStack is, Object... parts) { - ModLoader.addRecipe(is, parts); - } + public static void addRecipe(ItemStack is, Object... parts) { + ModLoader.addRecipe(is, parts); + } - public int getGUI() { - return guiId; - } + public int getRowCount() { + return size / rowLength; + } - public static void initGUIs(Configuration cfg) { - int defGUI = 51; - for (IronChestType typ : values()) { - if (typ.guiName != null) { - typ.guiId = Integer.parseInt(cfg.getOrCreateIntProperty(typ.guiName, Configuration.GENERAL_PROPERTY, defGUI++).value); - mod_IronChest.proxy.registerGUI(typ.guiId); - } else { - typ.guiId = -1; - } - } - } + public int getRowLength() { + return rowLength; + } - public int getRowCount() { - return size / rowLength; - } + public void addMat(ItemStack ore) { + this.matList.add(ore); + } - public int getRowLength() { - return rowLength; - } + public List getMatList() { + return matList; + } - public void addMat(ItemStack ore) { - this.matList.add(ore); - } - - public List getMatList() { - return matList; - } - - public boolean isTransparent() { - return this==CRYSTAL; - } + public boolean isTransparent() { + return this == CRYSTAL; + } } \ No newline at end of file diff --git a/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java b/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java index 5cb8a99..3e04576 100644 --- a/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java +++ b/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java @@ -5,7 +5,6 @@ import net.minecraft.src.Item; import net.minecraft.src.ItemStack; import net.minecraft.src.TileEntity; import net.minecraft.src.World; -import net.minecraft.src.mod_IronChest; import net.minecraft.src.forge.ITextureProvider; public class ItemChestChanger extends Item implements ITextureProvider { @@ -32,8 +31,8 @@ public class ItemChestChanger extends Item implements ITextureProvider { world.setBlockTileEntity(X, Y, Z, newchest); world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal()); world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z)); + world.markBlockNeedsUpdate(X, Y, Z); stack.stackSize=0; - mod_IronChest.proxy.sendTileEntityUpdate(newchest); return true; } else { return false; diff --git a/IronChests2/common/cpw/mods/ironchest/PacketHandler.java b/IronChests2/common/cpw/mods/ironchest/PacketHandler.java new file mode 100644 index 0000000..b2338b5 --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/PacketHandler.java @@ -0,0 +1,96 @@ +package cpw.mods.ironchest; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet; +import net.minecraft.src.Packet1Login; +import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.TileEntity; +import net.minecraft.src.World; +import net.minecraft.src.mod_IronChest; +import net.minecraft.src.forge.IConnectionHandler; +import net.minecraft.src.forge.IPacketHandler; +import net.minecraft.src.forge.MessageManager; + +public class PacketHandler implements IPacketHandler, IConnectionHandler { + @Override + public void onConnect(NetworkManager network) { + } + + @Override + public void onLogin(NetworkManager network, Packet1Login login) { + MessageManager.getInstance().registerChannel(network, this, "IronChest"); + } + + @Override + public void onDisconnect(NetworkManager network, String message, Object[] args) { + MessageManager.getInstance().removeConnection(network); + } + + @Override + public void onPacketData(NetworkManager network, String channel, byte[] data) { + DataInputStream dis=new DataInputStream(new ByteArrayInputStream(data)); + int x; + int y; + int z; + int typ; + boolean hasStacks; + int[] items=null; + try { + x = dis.readInt(); + y = dis.readInt(); + z = dis.readInt(); + typ=dis.readByte(); + hasStacks=dis.readByte()!=0; + if (hasStacks) { + items = new int[24]; + for (int i=0; i() { - @Override - public int compare(ItemStack o1, ItemStack o2) { - if (o1 == null) { - return 1; - } else if (o2 == null) { - return -1; - } else { - return o2.stackSize - o1.stackSize; - } - } - }); - int p = 0; - for (int i = 0; i < tempCopy.length; i++) { - if (tempCopy[i] != null && tempCopy[i].stackSize > 0) { - topStacks[p++] = tempCopy[i]; - if (p == topStacks.length) { - break; - } - } - } - for (int i = p; i < topStacks.length; i++) { - topStacks[i] = null; - } - mod_IronChest.proxy.sendTileEntityUpdate(this); - } + protected void sortTopStacks() { + if (!type.isTransparent() || mod_IronChest.proxy.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.markBlockNeedsUpdate(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.markBlockNeedsUpdate(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; - onInventoryChanged(); - return itemstack; - } - ItemStack itemstack1 = chestContents[i].splitStack(j); - if (chestContents[i].stackSize == 0) - { - chestContents[i] = null; - } - onInventoryChanged(); - 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; + onInventoryChanged(); + return itemstack; + } + ItemStack itemstack1 = chestContents[i].splitStack(j); + if (chestContents[i].stackSize == 0) + { + chestContents[i] = null; + } + onInventoryChanged(); + 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(); - } - onInventoryChanged(); - } + @Override + public void setInventorySlotContents(int i, ItemStack itemstack) { + chestContents[i] = itemstack; + if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) + { + itemstack.stackSize = getInventoryStackLimit(); + } + onInventoryChanged(); + } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) - { - super.readFromNBT(nbttagcompound); - NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); - chestContents = new ItemStack[getSizeInventory()]; - for (int i = 0; i < nbttaglist.tagCount(); i++) - { - NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i); - int j = nbttagcompound1.getByte("Slot") & 0xff; - if (j >= 0 && j < chestContents.length) - { - chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); - } - } - facing = nbttagcompound.getByte("facing"); - sortTopStacks(); - } + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) + { + super.readFromNBT(nbttagcompound); + NBTTagList nbttaglist = nbttagcompound.getTagList("Items"); + chestContents = new ItemStack[getSizeInventory()]; + for (int i = 0; i < nbttaglist.tagCount(); i++) + { + NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i); + int j = nbttagcompound1.getByte("Slot") & 0xff; + if (j >= 0 && j < chestContents.length) + { + chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); + } + } + facing = nbttagcompound.getByte("facing"); + sortTopStacks(); + } - @Override - public void writeToNBT(NBTTagCompound nbttagcompound) - { - super.writeToNBT(nbttagcompound); - NBTTagList nbttaglist = new NBTTagList(); - for (int i = 0; i < chestContents.length; i++) - { - if (chestContents[i] != null) - { - NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte) i); - chestContents[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); - } - } + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) + { + super.writeToNBT(nbttagcompound); + NBTTagList nbttaglist = new NBTTagList(); + for (int i = 0; i < chestContents.length; i++) + { + if (chestContents[i] != null) + { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte) i); + chestContents[i].writeToNBT(nbttagcompound1); + nbttaglist.appendTag(nbttagcompound1); + } + } - nbttagcompound.setTag("Items", nbttaglist); - nbttagcompound.setByte("facing", facing); - } + nbttagcompound.setTag("Items", nbttaglist); + nbttagcompound.setByte("facing", facing); + } - @Override - public int getInventoryStackLimit() { - return 64; - } + @Override + public int getInventoryStackLimit() { + return 64; + } - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - if (worldObj == null) { - return true; - } - if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) { - return false; - } - return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D; - } + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) { + if (worldObj == null) { + return true; + } + if (worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) != this) { + return false; + } + return entityplayer.getDistanceSq((double) xCoord + 0.5D, (double) yCoord + 0.5D, (double) zCoord + 0.5D) <= 64D; + } - @Override - public void updateEntity() { - super.updateEntity(); - // Resynchronize clients with the server state - if ((++ticksSinceSync % 20) * 4 == 0) { - worldObj.playNoteAt(xCoord, yCoord, zCoord, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); - if (inventoryTouched) { - inventoryTouched = false; - sortTopStacks(); - } - } - prevLidAngle = lidAngle; - float f = 0.1F; - if (numUsingPlayers > 0 && lidAngle == 0.0F) { - double d = (double) xCoord + 0.5D; - double d1 = (double) zCoord + 0.5D; - worldObj.playSoundEffect(d, (double) yCoord + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); - } - if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F) { - float f1 = lidAngle; - if (numUsingPlayers > 0) { - lidAngle += f; - } else { - lidAngle -= f; - } - if (lidAngle > 1.0F) { - lidAngle = 1.0F; - } - float f2 = 0.5F; - if (lidAngle < f2 && f1 >= f2) { - double d2 = (double) xCoord + 0.5D; - double d3 = (double) zCoord + 0.5D; - worldObj.playSoundEffect(d2, (double) yCoord + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); - } - if (lidAngle < 0.0F) { - lidAngle = 0.0F; - } - } - } + @Override + public void updateEntity() { + super.updateEntity(); + // Resynchronize clients with the server state + if ((++ticksSinceSync % 20) * 4 == 0) { + worldObj.playNoteAt(xCoord, yCoord, zCoord, 3, ((numUsingPlayers << 3) & 0xF8) | (facing & 0x7)); + if (inventoryTouched) { + inventoryTouched = false; + sortTopStacks(); + } + } + prevLidAngle = lidAngle; + float f = 0.1F; + if (numUsingPlayers > 0 && lidAngle == 0.0F) { + double d = (double) xCoord + 0.5D; + double d1 = (double) zCoord + 0.5D; + worldObj.playSoundEffect(d, (double) yCoord + 0.5D, d1, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); + } + if (numUsingPlayers == 0 && lidAngle > 0.0F || numUsingPlayers > 0 && lidAngle < 1.0F) { + float f1 = lidAngle; + if (numUsingPlayers > 0) { + lidAngle += f; + } else { + lidAngle -= f; + } + if (lidAngle > 1.0F) { + lidAngle = 1.0F; + } + float f2 = 0.5F; + if (lidAngle < f2 && f1 >= f2) { + double d2 = (double) xCoord + 0.5D; + double d3 = (double) zCoord + 0.5D; + worldObj.playSoundEffect(d2, (double) yCoord + 0.5D, d3, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F); + } + if (lidAngle < 0.0F) { + lidAngle = 0.0F; + } + } + } - @Override - public void onTileEntityPowered(int i, int j) - { - if (i == 1) - { - numUsingPlayers = j; - } else if (i == 2) { - facing = (byte) j; - } else if (i == 3) { - facing = (byte) (j & 0x7); - numUsingPlayers = (j & 0xF8) >> 3; - } - } + @Override + public void onTileEntityPowered(int i, int j) + { + if (i == 1) + { + numUsingPlayers = j; + } else if (i == 2) { + facing = (byte) j; + } else if (i == 3) { + facing = (byte) (j & 0x7); + numUsingPlayers = (j & 0xF8) >> 3; + } + } - @Override - public void openChest() { - if (worldObj == null) - return; - numUsingPlayers++; - worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); - } + @Override + public void openChest() { + if (worldObj == null) + return; + numUsingPlayers++; + worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); + } - @Override - public void closeChest() { - if (worldObj == null) - return; - numUsingPlayers--; - worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); - } + @Override + public void closeChest() { + if (worldObj == null) + return; + numUsingPlayers--; + worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers); + } - public void setFacing(byte chestFacing) { - this.facing = chestFacing; - } + public void setFacing(byte chestFacing) { + this.facing = chestFacing; + } - public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) { - if (numUsingPlayers > 0) { - return null; - } - if (!itemChestChanger.getType().canUpgrade(this.getType())) { - return null; - } - TileEntityIronChest newEntity = IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal())); - int newSize = newEntity.chestContents.length; - System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize, chestContents.length)); - BlockIronChest block = mod_IronChest.ironChestBlock; - block.dropContent(newSize, this, this.worldObj); - newEntity.setFacing(facing); - newEntity.sortTopStacks(); - 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 = mod_IronChest.ironChestBlock; + block.dropContent(newSize, this, this.worldObj); + newEntity.setFacing(facing); + newEntity.sortTopStacks(); + 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.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l)); - return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord); - } - } - return this; - } + public TileEntityIronChest updateFromMetadata(int l) { + if (worldObj != null && worldObj.isRemote) { + if (l != type.ordinal()) { + worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, IronChestType.makeEntity(l)); + return (TileEntityIronChest) worldObj.getBlockTileEntity(xCoord, yCoord, zCoord); + } + } + return this; + } - public Packet getDescriptionPacket() { - return mod_IronChest.proxy.getDescriptionPacket(this); - } + public Packet getDescriptionPacket() { + return PacketHandler.getPacket(this); + } - public void handlePacketData(int typeData, int[] intData, float[] floatData, String[] stringData) { - TileEntityIronChest chest = this; - if (this.type.ordinal() != typeData) { - chest = updateFromMetadata(typeData); - } - if (IronChestType.values()[typeData].isTransparent() && intData != null) { - int pos = 0; - if (intData.length < chest.topStacks.length * 3) { - return; - } - for (int i = 0; i < chest.topStacks.length; i++) { - if (intData[pos + 2] != 0) { - ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]); - chest.topStacks[i] = is; - } else { - chest.topStacks[i] = null; - } - pos += 3; - } - } - } + public void handlePacketData(int typeData, int[] intData) { + TileEntityIronChest chest = this; + if (this.type.ordinal() != typeData) { + chest = updateFromMetadata(typeData); + } + if (IronChestType.values()[typeData].isTransparent() && intData != null) { + int pos = 0; + if (intData.length < chest.topStacks.length * 3) { + return; + } + for (int i = 0; i < chest.topStacks.length; i++) { + if (intData[pos + 2] != 0) { + ItemStack is = new ItemStack(intData[pos], intData[pos + 2], intData[pos + 1]); + chest.topStacks[i] = is; + } else { + chest.topStacks[i] = null; + } + pos += 3; + } + } + } - public int[] buildIntDataList() { - if (type.isTransparent()) { - int[] sortList = new int[topStacks.length * 3]; - int pos = 0; - for (ItemStack is : topStacks) { - if (is != null) { - sortList[pos++] = is.itemID; - sortList[pos++] = is.getItemDamage(); - sortList[pos++] = is.stackSize; - } else { - sortList[pos++] = 0; - sortList[pos++] = 0; - sortList[pos++] = 0; - } - } - return sortList; - } - return null; - } + public int[] buildIntDataList() { + if (type.isTransparent()) { + int[] sortList = new int[topStacks.length * 3]; + int pos = 0; + for (ItemStack is : topStacks) { + if (is != null) { + sortList[pos++] = is.itemID; + sortList[pos++] = is.getItemDamage(); + sortList[pos++] = is.stackSize; + } else { + sortList[pos++] = 0; + sortList[pos++] = 0; + sortList[pos++] = 0; + } + } + return sortList; + } + return null; + } - public ItemStack getStackInSlotOnClosing(int par1) - { - if (this.chestContents[par1] != null) - { - ItemStack var2 = this.chestContents[par1]; - this.chestContents[par1] = null; - return var2; - } - else - { - return null; - } - } + public ItemStack getStackInSlotOnClosing(int par1) + { + if (this.chestContents[par1] != null) + { + ItemStack var2 = this.chestContents[par1]; + this.chestContents[par1] = null; + return var2; + } + else + { + return null; + } + } } diff --git a/IronChests2/common/cpw/mods/ironchest/Version.java b/IronChests2/common/cpw/mods/ironchest/Version.java new file mode 100644 index 0000000..32f1a80 --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/Version.java @@ -0,0 +1,17 @@ +package cpw.mods.ironchest; + + +public class Version { + public static final String MAJOR="@MAJOR@"; + public static final String MINOR="@MINOR@"; + public static final String REV="@REV@"; + public static final String BUILD="@BUILD@"; + + public static final String version() { + return MAJOR+"."+MINOR; + } + + public static final String name() { + return "Iron Chest ("+MAJOR+"."+MINOR+") rev "+REV+" build "+BUILD; + } +} diff --git a/IronChests2/common/net/minecraft/src/mod_IronChest.java b/IronChests2/common/net/minecraft/src/mod_IronChest.java index d322745..db7781a 100644 --- a/IronChests2/common/net/minecraft/src/mod_IronChest.java +++ b/IronChests2/common/net/minecraft/src/mod_IronChest.java @@ -6,103 +6,110 @@ import java.lang.reflect.Method; import net.minecraft.src.forge.Configuration; import net.minecraft.src.forge.IOreHandler; import net.minecraft.src.forge.MinecraftForge; +import net.minecraft.src.forge.NetworkMod; import cpw.mods.ironchest.BlockIronChest; import cpw.mods.ironchest.ChestChangerType; import cpw.mods.ironchest.IProxy; import cpw.mods.ironchest.IronChestType; import cpw.mods.ironchest.ItemChestChanger; import cpw.mods.ironchest.ItemIronChest; +import cpw.mods.ironchest.PacketHandler; import cpw.mods.ironchest.ServerClientProxy; -import cpw.mods.ironchest.TileEntityIronChest; +import cpw.mods.ironchest.Version; -public class mod_IronChest extends BaseModMp { +public class mod_IronChest extends NetworkMod { - public static BlockIronChest ironChestBlock; - public static ItemChestChanger itemChestChanger; - public static IProxy proxy; + public static BlockIronChest ironChestBlock; + public static ItemChestChanger itemChestChanger; + public static IProxy proxy; + public static mod_IronChest instance; - @Override - public String getVersion() { - return "3.1"; - } + @Override + public String getVersion() { + return Version.version(); + } - @Override - public void load() { - MinecraftForge.versionDetect("IronChest", 1, 4, 0); - proxy = ServerClientProxy.getProxy(); - File cfgFile = new File(proxy.getMinecraftDir(), "config/IronChest.cfg"); - Configuration cfg = new Configuration(cfgFile); - try { - cfg.load(); - int bId=Integer.parseInt(cfg.getOrCreateBlockIdProperty("ironChests", 181).value); - if (bId>=256) { - throw new RuntimeException(String.format("IronChest detected an invalid block id %s\n",bId)); - } - ironChestBlock = new BlockIronChest(bId); - ChestChangerType.buildItems(cfg, 19501); - IronChestType.initGUIs(cfg); - } catch (Exception e) { - ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully"); - e.printStackTrace(System.err); - throw new RuntimeException(e); - } finally { - cfg.save(); - } + @Override + public void load() { + MinecraftForge.versionDetect("IronChest", 2, 0, 0); + instance = this; + proxy = ServerClientProxy.getProxy(); + File cfgFile = new File(proxy.getMinecraftDir(), "config/IronChest.cfg"); + Configuration cfg = new Configuration(cfgFile); + try { + cfg.load(); + int bId = cfg.getOrCreateBlockIdProperty("ironChests", 181).getInt(181); + if (bId >= 256) { + throw new RuntimeException(String.format("IronChest detected an invalid block id %s\n", bId)); + } + ironChestBlock = new BlockIronChest(bId); + ChestChangerType.buildItems(cfg, 19501); + } catch (Exception e) { + ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully"); + e.printStackTrace(System.err); + throw new RuntimeException(e); + } finally { + cfg.save(); + } - ModLoader.registerBlock(ironChestBlock, ItemIronChest.class); - MinecraftForge.registerOreHandler(new IOreHandler() { - @Override - public void registerOre(String oreClass, ItemStack ore) { - if ("ingotCopper".equals(oreClass)) { - IronChestType.COPPER.addMat(ore); - IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.COPPER, ore); - ChestChangerType.generateRecipe(IronChestType.COPPER); - } - if ("ingotSilver".equals(oreClass)) { - IronChestType.SILVER.addMat(ore); - IronChestType.generateRecipesForType(ironChestBlock, ironChestBlock, IronChestType.SILVER, ore); - ChestChangerType.generateRecipe(IronChestType.SILVER); - } - if ("ingotRefinedIron".equals(oreClass)) { - IronChestType.IRON.addMat(ore); - IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.IRON, ore); - ChestChangerType.generateRecipe(IronChestType.IRON); - } - } - }); - proxy.registerTranslations(); - proxy.registerTileEntities(); - ChestChangerType.generateRecipe(IronChestType.IRON); - ChestChangerType.generateRecipe(IronChestType.GOLD); - ChestChangerType.generateRecipe(IronChestType.DIAMOND); - IronChestType.generateTieredRecipies(ironChestBlock); + ModLoader.registerBlock(ironChestBlock, ItemIronChest.class); + MinecraftForge.registerOreHandler(new IOreHandler() { + @Override + public void registerOre(String oreClass, ItemStack ore) { + if ("ingotCopper".equals(oreClass)) { + IronChestType.COPPER.addMat(ore); + IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.COPPER, ore); + ChestChangerType.generateRecipe(IronChestType.COPPER); + } + if ("ingotSilver".equals(oreClass)) { + IronChestType.SILVER.addMat(ore); + IronChestType.generateRecipesForType(ironChestBlock, ironChestBlock, IronChestType.SILVER, ore); + ChestChangerType.generateRecipe(IronChestType.SILVER); + } + if ("ingotRefinedIron".equals(oreClass)) { + IronChestType.IRON.addMat(ore); + IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.IRON, ore); + ChestChangerType.generateRecipe(IronChestType.IRON); + } + } + }); + proxy.registerTranslations(); + proxy.registerTileEntities(); + ChestChangerType.generateRecipe(IronChestType.IRON); + ChestChangerType.generateRecipe(IronChestType.GOLD); + ChestChangerType.generateRecipe(IronChestType.DIAMOND); + IronChestType.generateTieredRecipies(ironChestBlock); - proxy.registerRenderInformation(); - } + MinecraftForge.setGuiHandler(this, proxy); + MinecraftForge.registerConnectionHandler(new PacketHandler()); + proxy.registerRenderInformation(); + } + @Override + public void modsLoaded() { + try { + Class equivexmaps = Class.forName("ee.EEMaps"); + Method addEMC = equivexmaps.getMethod("addEMC", int.class, int.class, int.class); + Method addMeta = equivexmaps.getMethod("addMeta", int.class, int.class); + int[] chestEMCValues = new int[] { 8 * 8 + 256 * 8, 8 * 8 + 256 * 8 + 2048 * 8, 2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6, 85 * 8 + 8 * 8, + 85 * 8 + 8 * 8 + 512 * 8, 2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6 + 8 }; + for (IronChestType icType : IronChestType.values()) { + addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]); + } + addMeta.invoke(null, ironChestBlock.blockID, IronChestType.values().length - 1); + ModLoader.getLogger().fine("mod_IronChest registered chests with Equivalent Exchange"); + } catch (Exception ex) { + ModLoader.getLogger().fine("mod_IronChest unable to load Equivalent Exchange integration"); + } + } - @Override - public void modsLoaded() { - try { - Class equivexmaps=Class.forName("ee.EEMaps"); - Method addEMC=equivexmaps.getMethod("addEMC",int.class,int.class,int.class); - Method addMeta=equivexmaps.getMethod("addMeta",int.class,int.class); - int[] chestEMCValues=new int[] { 8*8+256*8, 8*8+256*8+2048*8, 2*8192+8*8+256*8+2048*8+6, 85*8+8*8, 85*8+8*8+512*8, 2*8192+8*8+256*8+2048*8+6+8 }; - for (IronChestType icType : IronChestType.values()) { - addEMC.invoke(null,ironChestBlock.blockID,icType.ordinal(),chestEMCValues[icType.ordinal()]); - } - addMeta.invoke(null,ironChestBlock.blockID,IronChestType.values().length-1); - ModLoader.getLogger().fine("mod_IronChest registered chests with Equivalent Exchange"); - } catch (Exception ex) { - ModLoader.getLogger().fine("mod_IronChest unable to load Equivalent Exchange integration"); - } - } - - public static void openGUI(EntityPlayer player, TileEntityIronChest te) { - proxy.showGUI(te,player); - } - - public void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData) { - proxy.handleTileEntityPacket(x,y,z,type,intData,floatData,stringData); - } + @Override + public boolean clientSideRequired() { + return true; + } + + @Override + public boolean serverSideRequired() { + return true; + } } diff --git a/IronChests2/server/cpw/mods/ironchest/server/ServerProxy.java b/IronChests2/server/cpw/mods/ironchest/server/ServerProxy.java index a46eb32..03db7c3 100644 --- a/IronChests2/server/cpw/mods/ironchest/server/ServerProxy.java +++ b/IronChests2/server/cpw/mods/ironchest/server/ServerProxy.java @@ -2,14 +2,13 @@ package cpw.mods.ironchest.server; import java.io.File; -import net.minecraft.src.BaseModMp; +import net.minecraft.src.Container; import net.minecraft.src.EntityItem; -import net.minecraft.src.EntityPlayer; +import net.minecraft.src.EntityPlayerMP; import net.minecraft.src.ModLoader; -import net.minecraft.src.ModLoaderMp; import net.minecraft.src.NBTTagCompound; -import net.minecraft.src.Packet; -import net.minecraft.src.mod_IronChest; +import net.minecraft.src.TileEntity; +import net.minecraft.src.World; import cpw.mods.ironchest.ContainerIronChestBase; import cpw.mods.ironchest.IProxy; import cpw.mods.ironchest.IronChestType; @@ -34,11 +33,6 @@ public class ServerProxy implements IProxy { // NOOP on server } - @Override - public void showGUI(TileEntityIronChest te, EntityPlayer player) { - ModLoader.openGUI(player, te.getType().guiId, te, new ContainerIronChestBase(player.inventory,te, te.getType(), 1, 1)); - } - @Override public File getMinecraftDir() { return new File("."); @@ -49,29 +43,26 @@ public class ServerProxy implements IProxy { entityitem.item.setTagCompound(data); } - @Override - public void registerGUI(int guiId) { - // NOOP on server - } - - @Override - public void handleTileEntityPacket(int x, int y, int z, int type, int[] intData, float[] floatData, String[] stringData) { - // NOOP on server - } - - @Override - public Packet getDescriptionPacket(TileEntityIronChest tile) { - return ModLoaderMp.getTileEntityPacket(ModLoaderMp.getModInstance(mod_IronChest.class), tile.xCoord, tile.yCoord, tile.zCoord, tile.getType().ordinal(), tile.buildIntDataList(),null,null); - } - - @Override - public void sendTileEntityUpdate(TileEntityIronChest tile) { - ModLoaderMp.sendTileEntityPacket(tile); - } - @Override public boolean isRemote() { return false; } + @Override + public Container getGuiContainer(int ID, EntityPlayerMP player, World world, int X, int Y, int Z) { + TileEntity te=world.getBlockTileEntity(X, Y, Z); + if (te!=null && te instanceof TileEntityIronChest) { + TileEntityIronChest icte=(TileEntityIronChest) te; + return new ContainerIronChestBase(player.inventory, icte, icte.getType(), 0, 0); + } else { + return null; + } + } + + @Override + public World getCurrentWorld() { + // NOOP on server: there's lots + return null; + } + }