From 3290802a7d21d4ff4dfd7f658b465b9d5cd17d58 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 26 Jun 2012 16:12:36 -0400 Subject: [PATCH] Move mod to my own package, update for new forge ore dictionary recipes --- .../client/IronChestRenderHelper.java | 2 +- .../cpw/mods/ironchest/BlockIronChest.java | 1 - .../cpw/mods/ironchest/ChestChangerType.java | 119 +++++++++--------- .../cpw/mods/ironchest/IronChestType.java | 88 ++++++++----- .../cpw/mods/ironchest/PacketHandler.java | 1 - .../mods/ironchest/TileEntityIronChest.java | 1 - .../common/cpw/mods/ironchest/Version.java | 9 +- .../mods/ironchest}/mod_IronChest.java | 57 +++------ 8 files changed, 134 insertions(+), 144 deletions(-) rename IronChests2/common/{net/minecraft/src => cpw/mods/ironchest}/mod_IronChest.java (59%) diff --git a/IronChests2/client/cpw/mods/ironchest/client/IronChestRenderHelper.java b/IronChests2/client/cpw/mods/ironchest/client/IronChestRenderHelper.java index e8369d0..1fbcfb6 100644 --- a/IronChests2/client/cpw/mods/ironchest/client/IronChestRenderHelper.java +++ b/IronChests2/client/cpw/mods/ironchest/client/IronChestRenderHelper.java @@ -10,10 +10,10 @@ ******************************************************************************/ package cpw.mods.ironchest.client; +import cpw.mods.ironchest.mod_IronChest; import net.minecraft.src.Block; import net.minecraft.src.ChestItemRenderHelper; import net.minecraft.src.TileEntityRenderer; -import net.minecraft.src.mod_IronChest; public class IronChestRenderHelper extends ChestItemRenderHelper { @Override diff --git a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java index 7909c96..5219ac7 100644 --- a/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/BlockIronChest.java @@ -24,7 +24,6 @@ import net.minecraft.src.MathHelper; import net.minecraft.src.NBTTagCompound; import net.minecraft.src.TileEntity; import net.minecraft.src.World; -import net.minecraft.src.mod_IronChest; import net.minecraft.src.forge.ITextureProvider; public class BlockIronChest extends BlockContainer implements ITextureProvider { diff --git a/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java b/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java index f38cbf0..0704455 100644 --- a/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java +++ b/IronChests2/common/cpw/mods/ironchest/ChestChangerType.java @@ -1,12 +1,8 @@ /******************************************************************************* - * Copyright (c) 2012 cpw. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html - * - * Contributors: - * cpw - initial API and implementation + * Copyright (c) 2012 cpw. All rights reserved. This program and the accompanying materials are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html + * + * Contributors: cpw - initial API and implementation ******************************************************************************/ package cpw.mods.ironchest; @@ -20,64 +16,63 @@ import static cpw.mods.ironchest.IronChestType.CRYSTAL; import net.minecraft.src.Block; import net.minecraft.src.ItemStack; import net.minecraft.src.forge.Configuration; -import net.minecraft.src.forge.MinecraftForge; + 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"); + 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"); - private IronChestType source; - private IronChestType target; - public String itemName; - public String descriptiveName; - private ItemChestChanger item; - private String[] recipe; + private IronChestType source; + private IronChestType target; + public String itemName; + public String descriptiveName; + private ItemChestChanger item; + private String[] recipe; - private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe) { - this.source=source; - this.target=target; - this.itemName=itemName; - this.descriptiveName=descriptiveName; - this.recipe=recipe; - } - - public boolean canUpgrade(IronChestType from) { - return from==this.source; - } - - public int getTarget() { - return this.target.ordinal(); - } + 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 ItemChestChanger buildItem(Configuration cfg, int id) { - int itemId=Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.CATEGORY_ITEM, id).value); - item=new ItemChestChanger(itemId,this); - return item; - } + public boolean canUpgrade(IronChestType from) { + return from == this.source; + } - public void addRecipe() { - IronChestType.addRecipe(new ItemStack(item), recipe, 'm', target.mat,'s',source.mat,'G',Block.glass,'O',Block.obsidian); - } - - public static void buildItems(Configuration cfg, int defaultId) { - for (ChestChangerType type: values()) { - type.buildItem(cfg, defaultId++); - } - } + public int getTarget() { + return this.target.ordinal(); + } - public static void generateRecipe(IronChestType type) { - for (ChestChangerType item: values()) { - if (item.source==type || item.target==type) { - for (Object[] recipe : MinecraftForge.generateRecipes(item.recipe[0],item.recipe[1],item.recipe[2],'s',item.source.getMatList(),'m',item.target.getMatList(),'G',Block.glass,'O',Block.obsidian)) { - if (recipe[4]==null || recipe[6]==null) { - continue; - } - IronChestType.addRecipe(new ItemStack(item.item), recipe); - } - } - } - } + public ItemChestChanger buildItem(Configuration cfg, int id) { + int itemId = Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.CATEGORY_ITEM, id).value); + item = new ItemChestChanger(itemId, this); + return item; + } + + public void addRecipes() { + for (String sourceMat : source.getMatList()) { + for (String targetMat : target.getMatList()) { + Object targetMaterial = IronChestType.translateOreName(targetMat); + Object sourceMaterial = IronChestType.translateOreName(sourceMat); + IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Block.glass, 'O', Block.obsidian); + } + } + } + + public static void buildItems(Configuration cfg, int defaultId) { + for (ChestChangerType type : values()) { + type.buildItem(cfg, defaultId++); + } + } + + public static void generateRecipes() { + for (ChestChangerType item : values()) { + item.addRecipes(); + } + } } diff --git a/IronChests2/common/cpw/mods/ironchest/IronChestType.java b/IronChests2/common/cpw/mods/ironchest/IronChestType.java index afe894f..c065c6f 100644 --- a/IronChests2/common/cpw/mods/ironchest/IronChestType.java +++ b/IronChests2/common/cpw/mods/ironchest/IronChestType.java @@ -4,27 +4,29 @@ * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html - * + * * Contributors: * cpw - initial API and implementation ******************************************************************************/ package cpw.mods.ironchest; +import java.util.Arrays; import java.util.ArrayList; import java.util.List; import net.minecraft.src.Block; +import net.minecraft.src.CraftingManager; import net.minecraft.src.Item; import net.minecraft.src.ItemStack; -import net.minecraft.src.ModLoader; +import net.minecraft.src.forge.oredict.ShapedOreRecipe; public enum IronChestType { - 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"); + 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, "mmmm0mmmm", "mGmG3GmGm"), + CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"); int size; private int rowLength; public String friendlyName; @@ -32,11 +34,10 @@ public enum IronChestType { private String modelTexture; private int textureRow; public Class clazz; - Item mat; private String[] recipes; - private ArrayList matList; + private ArrayList matList; - IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, Item mat, + IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List mats, Class clazz, String... recipes) { this.size = size; this.rowLength = rowLength; @@ -45,12 +46,9 @@ public enum IronChestType { 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)); - } + this.matList = new ArrayList(); + matList.addAll(mats); } public String getModelTexture() { @@ -80,27 +78,53 @@ public enum IronChestType { public static void registerTranslations() { } - public static void generateTieredRecipies(BlockIronChest blockResult) { + public static void generateTieredRecipes(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()); + generateRecipesForType(blockResult, previous, typ); + if (typ.tieredChest) + previous = new ItemStack(blockResult, 1, typ.ordinal()); } } - public static void generateRecipesForType(BlockIronChest blockResult, Object previousTier, IronChestType type, Object 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) }; - 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)); + Object mainMaterial = null; + for (String mat : type.matList) { + mainMaterial = translateOreName(mat); + addRecipe(new ItemStack(blockResult, 1, type.ordinal()), recipeSplit, + 'm', mainMaterial, + 'P', previousTier, /* previous tier of chest */ + 'G', Block.glass, + 'C', Block.chest, + '0', new ItemStack(blockResult, 1, 0), /* Iron Chest*/ + '1', new ItemStack(blockResult, 1, 1), /* Gold Chest*/ + '2', new ItemStack(blockResult, 1, 1), /* Diamond Chest*/ + '3', new ItemStack(blockResult, 1, 3), /* Copper Chest */ + '4', new ItemStack(blockResult, 1, 4)/* Silver Chest */ + ); + } } } + public static Object translateOreName(String mat) { + if (mat == "ingotIron" ) { + return Item.ingotIron; + } else if (mat == "ingotGold") { + return Item.ingotGold; + } else if (mat == "gemDiamond") { + return Item.diamond; + } else if (mat == "blockGlass") { + return Block.glass; + } + return mat; + } + + @SuppressWarnings("unchecked") public static void addRecipe(ItemStack is, Object... parts) { - ModLoader.addRecipe(is, parts); + ShapedOreRecipe oreRecipe = new ShapedOreRecipe(is, parts); + CraftingManager.getInstance().getRecipeList().add(oreRecipe); } public int getRowCount() { @@ -111,16 +135,12 @@ public enum IronChestType { return rowLength; } - public void addMat(ItemStack ore) { - this.matList.add(ore); - } - - public List getMatList() { - return matList; - } - public boolean isTransparent() { return this == CRYSTAL; } + public List getMatList() { + return matList; + } + } diff --git a/IronChests2/common/cpw/mods/ironchest/PacketHandler.java b/IronChests2/common/cpw/mods/ironchest/PacketHandler.java index e9ed0e9..1042d7d 100644 --- a/IronChests2/common/cpw/mods/ironchest/PacketHandler.java +++ b/IronChests2/common/cpw/mods/ironchest/PacketHandler.java @@ -22,7 +22,6 @@ 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; diff --git a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java index 2b3d7b4..0ef4f7c 100644 --- a/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/TileEntityIronChest.java @@ -20,7 +20,6 @@ import net.minecraft.src.NBTTagCompound; import net.minecraft.src.NBTTagList; import net.minecraft.src.Packet; import net.minecraft.src.TileEntity; -import net.minecraft.src.mod_IronChest; public class TileEntityIronChest extends TileEntity implements IInventory { private int ticksSinceSync; diff --git a/IronChests2/common/cpw/mods/ironchest/Version.java b/IronChests2/common/cpw/mods/ironchest/Version.java index 0884f5c..48a03c2 100644 --- a/IronChests2/common/cpw/mods/ironchest/Version.java +++ b/IronChests2/common/cpw/mods/ironchest/Version.java @@ -1,7 +1,7 @@ /******************************************************************************* * Copyright (c) 2012 cpw. All rights reserved. This program and the accompanying materials are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html - * + * * Contributors: cpw - initial API and implementation ******************************************************************************/ package cpw.mods.ironchest; @@ -16,15 +16,18 @@ import cpw.mods.fml.common.FMLCommonHandler; public class Version { private static String major; private static String minor; + @SuppressWarnings("unused") private static String rev; + @SuppressWarnings("unused") private static String build; + @SuppressWarnings("unused") private static String mcversion; private static boolean loaded; private static void init() { InputStream stream = Version.class.getClassLoader().getResourceAsStream("ironchestversion.properties"); Properties properties = new Properties(); - + if (stream != null) { try { properties.load(stream); @@ -44,6 +47,6 @@ public class Version { if (!loaded) { init(); } - return major+"."+minor+"."+rev; + return major+"."+minor; } } diff --git a/IronChests2/common/net/minecraft/src/mod_IronChest.java b/IronChests2/common/cpw/mods/ironchest/mod_IronChest.java similarity index 59% rename from IronChests2/common/net/minecraft/src/mod_IronChest.java rename to IronChests2/common/cpw/mods/ironchest/mod_IronChest.java index ba5d61a..065fe64 100644 --- a/IronChests2/common/net/minecraft/src/mod_IronChest.java +++ b/IronChests2/common/cpw/mods/ironchest/mod_IronChest.java @@ -4,27 +4,20 @@ * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html - * + * * Contributors: * cpw - initial API and implementation ******************************************************************************/ -package net.minecraft.src; +package cpw.mods.ironchest; import java.io.File; import java.lang.reflect.Method; +import net.minecraft.src.ModLoader; +import net.minecraft.src.SidedProxy; 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.Version; public class mod_IronChest extends NetworkMod { @@ -41,16 +34,13 @@ public class mod_IronChest extends NetworkMod { @Override public void load() { - MinecraftForge.versionDetect("IronChest", 3, 2, 4); + MinecraftForge.versionDetect("IronChest", 3, 3, 7); instance = this; 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) { @@ -62,32 +52,10 @@ public class mod_IronChest extends NetworkMod { } 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); + IronChestType.generateTieredRecipes(ironChestBlock); + ChestChangerType.generateRecipes(); MinecraftForge.setGuiHandler(this, proxy); MinecraftForge.registerConnectionHandler(new PacketHandler()); @@ -100,8 +68,15 @@ public class mod_IronChest extends NetworkMod { 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 }; + int[] chestEMCValues = new int[] + { + 8 * 8 + 256 * 8, /* iron chest */ + 8 * 8 + 256 * 8 + 2048 * 8, /* gold chest */ + 2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6, /* diamond chest */ + 85 * 8 + 8 * 8, /* copper chest */ + 85 * 8 + 8 * 8 + 512 * 8, /* silver chest */ + 2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6 + 8 /* crystal chest */ + }; for (IronChestType icType : IronChestType.values()) { addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]); }