diff --git a/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java b/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java index 8592789..fc69005 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java +++ b/IronChests2/client/cpw/mods/ironchest/client/GUIChest.java @@ -1,31 +1,31 @@ package cpw.mods.ironchest.client; -import org.lwjgl.opengl.GL11; - -import cpw.mods.ironchest.ContainerDiamondChest; -import cpw.mods.ironchest.ContainerGoldChest; -import cpw.mods.ironchest.ContainerIronChestBase; -import cpw.mods.ironchest.IronChestType; -import cpw.mods.ironchest.TileEntityIronChest; import net.minecraft.src.Container; import net.minecraft.src.EntityPlayer; import net.minecraft.src.GuiContainer; import net.minecraft.src.IInventory; import net.minecraft.src.ModLoader; +import org.lwjgl.opengl.GL11; + +import cpw.mods.ironchest.ContainerIronChestBase; +import cpw.mods.ironchest.IronChestType; +import cpw.mods.ironchest.TileEntityIronChest; + public class GUIChest extends GuiContainer { public enum GUI { - GOLD(ContainerGoldChest.class,184,256,"/ic2/sprites/goldcontainer.png",IronChestType.GOLD), - DIAMOND(ContainerDiamondChest.class,238,256,"/ic2/sprites/diamondcontainer.png",IronChestType.DIAMOND); + IRON(184,202,"/cpw/mods/ironchest/sprites/ironcontainer.png",IronChestType.IRON), + GOLD(184,256,"/cpw/mods/ironchest/sprites/goldcontainer.png",IronChestType.GOLD), + DIAMOND(238,256,"/cpw/mods/ironchest/sprites/diamondcontainer.png",IronChestType.DIAMOND), + COPPER(184,184,"/cpw/mods/ironchest/sprites/coppercontainer.png",IronChestType.COPPER), + SILVER(184,238,"/cpw/mods/ironchest/sprites/silvercontainer.png",IronChestType.SILVER); - private Class clazz; private int xSize; private int ySize; private String guiTexture; private IronChestType mainType; - private GUI(Class clazz, int xSize, int ySize, String guiTexture, IronChestType mainType) { - this.clazz=clazz; + private GUI(int xSize, int ySize, String guiTexture, IronChestType mainType) { this.xSize=xSize; this.ySize=ySize; this.guiTexture=guiTexture; @@ -33,13 +33,7 @@ public class GUIChest extends GuiContainer { } protected Container makeContainer(IInventory player, IInventory chest) { - try { - return clazz.getConstructor(IInventory.class,IInventory.class).newInstance(player,chest); - } catch (Exception e) { - // unpossible - e.printStackTrace(); - throw new RuntimeException(e); - } + return new ContainerIronChestBase(player,chest, mainType, xSize, ySize); } public static void showGUI(TileEntityIronChest te, EntityPlayer player) { @@ -53,6 +47,9 @@ public class GUIChest extends GuiContainer { } } + public int getRowLength() { + return type.mainType.getRowLength(); + } private GUI type; private GUIChest(GUI type, IInventory player, IInventory chest) { diff --git a/IronChests2/client/net/minecraft/src/mod_IronChest.java b/IronChests2/client/net/minecraft/src/mod_IronChest.java index aba0b61..90f25d0 100644 --- a/IronChests2/client/net/minecraft/src/mod_IronChest.java +++ b/IronChests2/client/net/minecraft/src/mod_IronChest.java @@ -11,6 +11,8 @@ import cpw.mods.ironchest.client.IronChestRenderHelper; import cpw.mods.ironchest.client.TileEntityIronChestRenderer; import net.minecraft.client.Minecraft; import net.minecraft.src.forge.Configuration; +import net.minecraft.src.forge.IOreHandler; +import net.minecraft.src.forge.MinecraftForge; import net.minecraft.src.forge.MinecraftForgeClient; public class mod_IronChest extends BaseModMp { @@ -26,16 +28,10 @@ public class mod_IronChest extends BaseModMp { @Override public void load() { File cfgFile = new File(Minecraft.getMinecraftDir(), "config/IronChest.cfg"); - // If our config file exists - boolean defaultCompatibility = cfgFile.exists(); Configuration cfg = new Configuration(cfgFile); try { cfg.load(); - // But doesn't have the compatibilityMode flag, enable compatibility - // mode - compatibilityMode = Boolean.parseBoolean(cfg.getOrCreateBooleanProperty("compatibilityMode", Configuration.GENERAL_PROPERTY, - defaultCompatibility).value); - ironChestBlock = new BlockIronChest(Integer.parseInt(cfg.getOrCreateBlockIdProperty("blockVeryLargeChest", 181).value)); + ironChestBlock = new BlockIronChest(Integer.parseInt(cfg.getOrCreateBlockIdProperty("ironChests", 181).value)); IronChestType.initGUIs(cfg); } catch (Exception e) { ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully"); @@ -45,13 +41,27 @@ public class mod_IronChest extends BaseModMp { cfg.save(); } + MinecraftForge.registerOreHandler(new IOreHandler() { + @Override + public void registerOre(String oreClass, ItemStack ore) { + if ("ingotCopper".equals(oreClass)) { + IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.COPPER, ore); + } + if ("ingotSilver".equals(oreClass)) { + IronChestType.generateRecipesForType(ironChestBlock, ironChestBlock, IronChestType.SILVER, ore); + } + if ("ingotRefinedIron".equals(oreClass)) { + IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.IRON, ore); + } + } + }); ModLoader.RegisterBlock(ironChestBlock, ItemIronChest.class); IronChestType.registerTranslations(); IronChestType.registerTileEntities(TileEntityIronChestRenderer.class); - IronChestType.registerRecipes(ironChestBlock); + IronChestType.generateTieredRecipies(ironChestBlock); ChestItemRenderHelper.instance=new IronChestRenderHelper(); - MinecraftForgeClient.preloadTexture("ic2/sprites/ironchest_block_tex.png"); + MinecraftForgeClient.preloadTexture("cpw/mods/ironchest/sprites/block_textures.png"); } public static void openGUI(EntityPlayer player, TileEntityIronChest te) { diff --git a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java index 2cbb8b4..c0fec2e 100644 --- a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java @@ -12,7 +12,6 @@ import net.minecraft.src.Material; import net.minecraft.src.MathHelper; import net.minecraft.src.NBTTagCompound; import net.minecraft.src.TileEntity; -import net.minecraft.src.TileEntityChest; import net.minecraft.src.World; import net.minecraft.src.mod_IronChest; import net.minecraft.src.forge.ITextureProvider; @@ -34,7 +33,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider { @Override public String getTextureFile() { - return "ic2/sprites/ironchest_block_tex.png"; + return "cpw/mods/ironchest/sprites/block_textures.png"; } @Override @@ -140,7 +139,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider { public void onBlockRemoval(World world, int i, int j, int k) { - TileEntityChest tileentitychest = (TileEntityChest)world.getBlockTileEntity(i, j, k); + TileEntityIronChest tileentitychest = (TileEntityIronChest)world.getBlockTileEntity(i, j, k); if (tileentitychest != null) { for (int l = 0; l < tileentitychest.getSizeInventory(); l++) diff --git a/IronChests2/common/cpw/mods/ironchest/ContainerDiamondChest.java b/IronChests2/common/cpw/mods/ironchest/ContainerDiamondChest.java deleted file mode 100644 index 9d96740..0000000 --- a/IronChests2/common/cpw/mods/ironchest/ContainerDiamondChest.java +++ /dev/null @@ -1,46 +0,0 @@ -package cpw.mods.ironchest; - -import net.minecraft.src.IInventory; -import net.minecraft.src.Slot; - -public class ContainerDiamondChest extends ContainerIronChestBase { - public ContainerDiamondChest(IInventory playerInventory, IInventory chestInventory) { - super(playerInventory, chestInventory); - } - - private static final int NUM_ROWS = 9; - private static final int ROW_LENGTH = 12; - - - @Override - protected void layoutContainer(IInventory playerInventory, IInventory chestInventory) { - for(int i = 0; i < NUM_ROWS; i++) - { - for(int l = 0; l < ROW_LENGTH; l++) - { - addSlot(new Slot(chestInventory, l + i * ROW_LENGTH, 12 + l * 18, 8 + i * 18)); - } - - } - - for(int j = 0; j < 3; j++) - { - for(int i1 = 0; i1 < 9; i1++) - { - addSlot(new Slot(playerInventory, i1 + j * 9 + 9, 39 + i1 * 18, 174 + j * 18)); - } - - } - - for(int k = 0; k < 9; k++) - { - addSlot(new Slot(playerInventory, k, 39 + k * 18, 232)); - } - } - - @Override - protected int getRowLength() { - return ROW_LENGTH; - } - -} diff --git a/IronChests2/common/cpw/mods/ironchest/ContainerGoldChest.java b/IronChests2/common/cpw/mods/ironchest/ContainerGoldChest.java deleted file mode 100644 index bc9aab0..0000000 --- a/IronChests2/common/cpw/mods/ironchest/ContainerGoldChest.java +++ /dev/null @@ -1,50 +0,0 @@ -// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov. -// Jad home page: http://www.kpdus.com/jad.html -// Decompiler options: packimports(3) braces deadcode - -package cpw.mods.ironchest; - -import net.minecraft.src.IInventory; -import net.minecraft.src.Slot; - -public class ContainerGoldChest extends ContainerIronChestBase -{ - - private static final int NUM_ROWS = 9; - private static final int ROW_LENGTH = 9; - - public ContainerGoldChest(IInventory playerInventory, IInventory chestInventory) { - super(playerInventory,chestInventory); - } - - @Override - protected int getRowLength() { - return ROW_LENGTH; - } - - protected void layoutContainer(IInventory playerInventory, IInventory chestInventory) { - for(int i = 0; i < NUM_ROWS; i++) - { - for(int l = 0; l < NUM_ROWS; l++) - { - addSlot(new Slot(chestInventory, l + i * ROW_LENGTH, 12 + l * 18, 8 + i * 18)); - } - - } - - for(int j = 0; j < 3; j++) - { - for(int i1 = 0; i1 < 9; i1++) - { - addSlot(new Slot(playerInventory, i1 + j * 9 + 9, 12 + i1 * 18, 174 + j * 18)); - } - - } - - for(int k = 0; k < 9; k++) - { - addSlot(new Slot(playerInventory, k, 12 + k * 18, 232)); - } - } - -} diff --git a/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java b/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java index e37ba1d..1a03421 100644 --- a/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java +++ b/IronChests2/common/cpw/mods/ironchest/ContainerIronChestBase.java @@ -6,18 +6,15 @@ import net.minecraft.src.IInventory; import net.minecraft.src.ItemStack; import net.minecraft.src.Slot; -public abstract class ContainerIronChestBase extends Container { - public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory) { - numRows = chestInventory.getSizeInventory() / getRowLength(); +public class ContainerIronChestBase extends Container { + private IronChestType type; + public ContainerIronChestBase(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { chest = chestInventory; + this.type=type; chestInventory.openChest(); - layoutContainer(playerInventory, chestInventory); - + layoutContainer(playerInventory, chestInventory, type, xSize, ySize); } - protected abstract void layoutContainer(IInventory playerInventory, IInventory chestInventory); - protected abstract int getRowLength(); - public boolean canInteractWith(EntityPlayer player) { return chest.isUseableByPlayer(player); @@ -31,14 +28,14 @@ public abstract class ContainerIronChestBase extends Container { { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); - if(i < numRows * getRowLength()) + if(i < type.size) { - if(!mergeItemStack(itemstack1, numRows * getRowLength(), inventorySlots.size(), true)) + if(!mergeItemStack(itemstack1, type.size, inventorySlots.size(), true)) { return null; } } else - if(!mergeItemStack(itemstack1, 0, numRows * getRowLength(), false)) + if(!mergeItemStack(itemstack1, 0, type.size, false)) { return null; } @@ -59,6 +56,31 @@ public abstract class ContainerIronChestBase extends Container { chest.closeChest(); } - private IInventory chest; - private int numRows; + protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) { + for(int chestRow = 0; chestRow < type.getRowCount(); chestRow++) + { + for(int chestCol = 0; chestCol < type.getRowLength(); chestCol++) + { + addSlot(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18)); + } + + } + + int leftCol=(xSize-162)/2 + 1; + for(int playerInvRow = 0; playerInvRow < 3; playerInvRow++) + { + for(int playerInvCol = 0; playerInvCol < 9; playerInvCol++) + { + addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4-playerInvRow) * 18 - 10)); + } + + } + + for(int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) + { + addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, ySize-24)); + } + } + + private IInventory chest; } diff --git a/IronChests2/common/cpw/mods/ironchest/IronChestType.java b/IronChests2/common/cpw/mods/ironchest/IronChestType.java index b13da64..7bbeedd 100644 --- a/IronChests2/common/cpw/mods/ironchest/IronChestType.java +++ b/IronChests2/common/cpw/mods/ironchest/IronChestType.java @@ -6,15 +6,18 @@ import net.minecraft.src.ItemStack; import net.minecraft.src.ModLoader; import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntitySpecialRenderer; -import net.minecraft.src.mod_IronChest; import net.minecraft.src.forge.Configuration; public enum IronChestType { - IRON(54, "Iron Chest", null, "ironchest.png", 0, Item.ingotIron, TileEntityIronChest.class, "mmmmPmmmm"), - GOLD(81, "Gold Chest", "guiGoldChest", "goldchest.png", 1, Item.ingotGold, TileEntityGoldChest.class, "mmmmPmmmm"), - DIAMOND(108,"Diamond Chest","guiDiamondChest", "diamondchest.png", 2, Item.diamond, TileEntityDiamondChest.class, "mmmmPmmmm"); + IRON(54, 9, true, "Iron Chest", null, "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", "mmmm3mmmm"); int size; + private int rowLength; String friendlyName; + private boolean tieredChest; private String modelTexture; private String guiName; private int textureRow; @@ -23,15 +26,18 @@ public enum IronChestType { private String[] recipes; private int guiId; - IronChestType(int size, String friendlyName, String guiName, String modelTexture, int textureRow, Item mat, Class clazz, String... recipes) { + 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 = "/ic2/sprites/"+modelTexture; + this.guiName = guiName; + this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture; this.textureRow = textureRow; this.clazz = clazz; this.mat = mat; - this.recipes=recipes; + this.recipes = recipes; } public String getModelTexture() { @@ -43,19 +49,10 @@ public enum IronChestType { } public static TileEntity makeEntity(int metadata) { - //Compatibility - int chesttype=metadata; - int facing=0; - - if (metadata>2) { - chesttype=metadata<<2; - facing=metadata&3; - } + // Compatibility + int chesttype = metadata; try { - TileEntityIronChest te=values()[chesttype].clazz.newInstance(); - if (mod_IronChest.compatibilityMode) { - te.setFacing((byte)facing); - } + TileEntityIronChest te = values()[chesttype].clazz.newInstance(); return te; } catch (InstantiationException e) { // unpossible @@ -70,8 +67,8 @@ public enum IronChestType { public static void registerTileEntities(Class renderer) { for (IronChestType typ : values()) { try { - if (renderer!=null) { - ModLoader.RegisterTileEntity(typ.clazz, typ.name(),renderer.newInstance()); + if (renderer != null) { + ModLoader.RegisterTileEntity(typ.clazz, typ.name(), renderer.newInstance()); } else { ModLoader.RegisterTileEntity(typ.clazz, typ.name()); } @@ -87,19 +84,29 @@ public enum IronChestType { public static void registerTranslations() { for (IronChestType typ : values()) { - ModLoader.AddLocalization(typ.name()+".name", typ.friendlyName); + ModLoader.AddLocalization(typ.name() + ".name", typ.friendlyName); } } - public static void registerRecipes(BlockIronChest blockResult) { - ItemStack previous=new ItemStack(Block.chest); + + public static void generateTieredRecipies(BlockIronChest blockResult) { + ItemStack previous = new ItemStack(Block.chest); for (IronChestType typ : values()) { - for (String recipe : typ.recipes) { - String[] recipeSplit=new String[] { recipe.substring(0,3),recipe.substring(3,6), recipe.substring(6,9) }; - addRecipe(new ItemStack(blockResult, 1, typ.ordinal()), recipeSplit, 'm', typ.mat, 'P', previous, 'G', Block.glass, 'C', Block.chest); - } - previous=new ItemStack(blockResult,1,typ.ordinal()); + 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)); + } + } + private static void addRecipe(ItemStack is, Object... parts) { ModLoader.AddRecipe(is, parts); } @@ -107,15 +114,25 @@ public enum IronChestType { public int getGUI() { return guiId; } - + public static void initGUIs(Configuration cfg) { - int defGUI=51; + int defGUI = 51; for (IronChestType typ : values()) { - if (typ.guiName!=null) { - typ.guiId=Integer.parseInt(cfg.getOrCreateIntProperty(typ.guiName, Configuration.GENERAL_PROPERTY, defGUI++).value); + if (typ.guiName != null) { + typ.guiId = Integer.parseInt(cfg.getOrCreateIntProperty(typ.guiName, Configuration.GENERAL_PROPERTY, defGUI++).value); } else { - typ.guiId=-1; + typ.guiId = -1; } } } + + public int getRowCount() { + return size / rowLength; + } + + public int getRowLength() { + // TODO Auto-generated method stub + return rowLength; + } + } \ No newline at end of file diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntityCopperChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntityCopperChest.java new file mode 100644 index 0000000..4d04ed9 --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/TileEntityCopperChest.java @@ -0,0 +1,8 @@ +package cpw.mods.ironchest; + +public class TileEntityCopperChest extends TileEntityIronChest { + public TileEntityCopperChest() { + super(IronChestType.COPPER); + } + +} diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntitySilverChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntitySilverChest.java new file mode 100644 index 0000000..48f72d2 --- /dev/null +++ b/IronChests2/common/cpw/mods/ironchest/TileEntitySilverChest.java @@ -0,0 +1,7 @@ +package cpw.mods.ironchest; + +public class TileEntitySilverChest extends TileEntityIronChest { + public TileEntitySilverChest() { + super(IronChestType.SILVER); + } +} diff --git a/IronChests2/resources/cpw/mods/ironchest/sprites/coppercontainer.png b/IronChests2/resources/cpw/mods/ironchest/sprites/coppercontainer.png new file mode 100644 index 0000000..2fdb824 Binary files /dev/null and b/IronChests2/resources/cpw/mods/ironchest/sprites/coppercontainer.png differ diff --git a/IronChests2/resources/cpw/mods/ironchest/sprites/silvercontainer.png b/IronChests2/resources/cpw/mods/ironchest/sprites/silvercontainer.png new file mode 100644 index 0000000..65179f2 Binary files /dev/null and b/IronChests2/resources/cpw/mods/ironchest/sprites/silvercontainer.png differ