Move mod to my own package, update for new forge ore dictionary recipes

This commit is contained in:
Christian 2012-06-26 16:12:36 -04:00
parent 6cbc221271
commit 3290802a7d
8 changed files with 134 additions and 144 deletions

View File

@ -10,10 +10,10 @@
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest.client; package cpw.mods.ironchest.client;
import cpw.mods.ironchest.mod_IronChest;
import net.minecraft.src.Block; import net.minecraft.src.Block;
import net.minecraft.src.ChestItemRenderHelper; import net.minecraft.src.ChestItemRenderHelper;
import net.minecraft.src.TileEntityRenderer; import net.minecraft.src.TileEntityRenderer;
import net.minecraft.src.mod_IronChest;
public class IronChestRenderHelper extends ChestItemRenderHelper { public class IronChestRenderHelper extends ChestItemRenderHelper {
@Override @Override

View File

@ -24,7 +24,6 @@ import net.minecraft.src.MathHelper;
import net.minecraft.src.NBTTagCompound; import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.World; import net.minecraft.src.World;
import net.minecraft.src.mod_IronChest;
import net.minecraft.src.forge.ITextureProvider; import net.minecraft.src.forge.ITextureProvider;
public class BlockIronChest extends BlockContainer implements ITextureProvider { public class BlockIronChest extends BlockContainer implements ITextureProvider {

View File

@ -1,12 +1,8 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2012 cpw. * 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
* All rights reserved. This program and the accompanying materials * which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html
* 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: * Contributors: cpw - initial API and implementation
* cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
@ -20,7 +16,7 @@ import static cpw.mods.ironchest.IronChestType.CRYSTAL;
import net.minecraft.src.Block; import net.minecraft.src.Block;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
import net.minecraft.src.forge.Configuration; import net.minecraft.src.forge.Configuration;
import net.minecraft.src.forge.MinecraftForge;
public enum ChestChangerType { public enum ChestChangerType {
IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"), IRONGOLD(IRON, GOLD, "ironGoldUpgrade", "Iron to Gold Chest Upgrade", "mmm", "msm", "mmm"),
GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"), GOLDDIAMOND(GOLD, DIAMOND, "goldDiamondUpgrade", "Gold to Diamond Chest Upgrade", "GGG", "msm", "GGG"),
@ -58,8 +54,14 @@ public enum ChestChangerType {
return item; return item;
} }
public void addRecipe() { public void addRecipes() {
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', target.mat,'s',source.mat,'G',Block.glass,'O',Block.obsidian); 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) { public static void buildItems(Configuration cfg, int defaultId) {
@ -68,16 +70,9 @@ public enum ChestChangerType {
} }
} }
public static void generateRecipe(IronChestType type) { public static void generateRecipes() {
for (ChestChangerType item : values()) { for (ChestChangerType item : values()) {
if (item.source==type || item.target==type) { item.addRecipes();
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);
}
}
} }
} }
} }

View File

@ -10,21 +10,23 @@
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.src.Block; import net.minecraft.src.Block;
import net.minecraft.src.CraftingManager;
import net.minecraft.src.Item; import net.minecraft.src.Item;
import net.minecraft.src.ItemStack; import net.minecraft.src.ItemStack;
import net.minecraft.src.ModLoader; import net.minecraft.src.forge.oredict.ShapedOreRecipe;
public enum IronChestType { public enum IronChestType {
IRON(54, 9, true, "Iron Chest", "ironchest.png", 0, Item.ingotIron, TileEntityIronChest.class, "mmmmPmmmm", "mGmG3GmGm"), 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, Item.ingotGold, TileEntityGoldChest.class, "mmmmPmmmm", "mGmG4GmGm"), 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, Item.diamond, TileEntityDiamondChest.class, "GGGmPmGGG", "GGGG4Gmmm"), 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, null, TileEntityCopperChest.class, "mmmmCmmmm"), COPPER(45, 9, false, "Copper Chest", "copperchest.png", 3, Arrays.asList("ingotCopper"), TileEntityCopperChest.class, "mmmmCmmmm"),
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, null, TileEntitySilverChest.class, "mmmm0mmmm", "mGmG3GmGm"), 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, Item.itemsList[Block.glass.blockID], TileEntityCrystalChest.class, "GGGGPGGGG"); CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG");
int size; int size;
private int rowLength; private int rowLength;
public String friendlyName; public String friendlyName;
@ -32,11 +34,10 @@ public enum IronChestType {
private String modelTexture; private String modelTexture;
private int textureRow; private int textureRow;
public Class<? extends TileEntityIronChest> clazz; public Class<? extends TileEntityIronChest> clazz;
Item mat;
private String[] recipes; private String[] recipes;
private ArrayList<ItemStack> matList; private ArrayList<String> 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<String> mats,
Class<? extends TileEntityIronChest> clazz, String... recipes) { Class<? extends TileEntityIronChest> clazz, String... recipes) {
this.size = size; this.size = size;
this.rowLength = rowLength; this.rowLength = rowLength;
@ -45,12 +46,9 @@ public enum IronChestType {
this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture; this.modelTexture = "/cpw/mods/ironchest/sprites/" + modelTexture;
this.textureRow = textureRow; this.textureRow = textureRow;
this.clazz = clazz; this.clazz = clazz;
this.mat = mat;
this.recipes = recipes; this.recipes = recipes;
this.matList = new ArrayList<ItemStack>(); this.matList = new ArrayList<String>();
if (mat != null) { matList.addAll(mats);
matList.add(new ItemStack(mat));
}
} }
public String getModelTexture() { public String getModelTexture() {
@ -80,27 +78,53 @@ public enum IronChestType {
public static void registerTranslations() { public static void registerTranslations() {
} }
public static void generateTieredRecipies(BlockIronChest blockResult) { public static void generateTieredRecipes(BlockIronChest blockResult) {
ItemStack previous = new ItemStack(Block.chest); ItemStack previous = new ItemStack(Block.chest);
for (IronChestType typ : values()) { for (IronChestType typ : values()) {
if (!typ.tieredChest) generateRecipesForType(blockResult, previous, typ);
continue; if (typ.tieredChest)
generateRecipesForType(blockResult, previous, typ, typ.mat);
previous = new ItemStack(blockResult, 1, typ.ordinal()); 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) { for (String recipe : type.recipes) {
String[] recipeSplit = new String[] { recipe.substring(0, 3), recipe.substring(3, 6), recipe.substring(6, 9) }; 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, Object mainMaterial = null;
'0', new ItemStack(blockResult, 1, 0)/* Iron */, '1', new ItemStack(blockResult, 1, 1)/* GOLD */, '3', new ItemStack(blockResult, for (String mat : type.matList) {
1, 3)/* Copper */, '4', new ItemStack(blockResult, 1, 4)); 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) { 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() { public int getRowCount() {
@ -111,16 +135,12 @@ public enum IronChestType {
return rowLength; return rowLength;
} }
public void addMat(ItemStack ore) {
this.matList.add(ore);
}
public List<ItemStack> getMatList() {
return matList;
}
public boolean isTransparent() { public boolean isTransparent() {
return this == CRYSTAL; return this == CRYSTAL;
} }
public List<String> getMatList() {
return matList;
}
} }

View File

@ -22,7 +22,6 @@ import net.minecraft.src.Packet1Login;
import net.minecraft.src.Packet250CustomPayload; import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.World; import net.minecraft.src.World;
import net.minecraft.src.mod_IronChest;
import net.minecraft.src.forge.IConnectionHandler; import net.minecraft.src.forge.IConnectionHandler;
import net.minecraft.src.forge.IPacketHandler; import net.minecraft.src.forge.IPacketHandler;
import net.minecraft.src.forge.MessageManager; import net.minecraft.src.forge.MessageManager;

View File

@ -20,7 +20,6 @@ import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList; import net.minecraft.src.NBTTagList;
import net.minecraft.src.Packet; import net.minecraft.src.Packet;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.mod_IronChest;
public class TileEntityIronChest extends TileEntity implements IInventory { public class TileEntityIronChest extends TileEntity implements IInventory {
private int ticksSinceSync; private int ticksSinceSync;

View File

@ -16,8 +16,11 @@ import cpw.mods.fml.common.FMLCommonHandler;
public class Version { public class Version {
private static String major; private static String major;
private static String minor; private static String minor;
@SuppressWarnings("unused")
private static String rev; private static String rev;
@SuppressWarnings("unused")
private static String build; private static String build;
@SuppressWarnings("unused")
private static String mcversion; private static String mcversion;
private static boolean loaded; private static boolean loaded;
@ -44,6 +47,6 @@ public class Version {
if (!loaded) { if (!loaded) {
init(); init();
} }
return major+"."+minor+"."+rev; return major+"."+minor;
} }
} }

View File

@ -8,23 +8,16 @@
* Contributors: * Contributors:
* cpw - initial API and implementation * cpw - initial API and implementation
******************************************************************************/ ******************************************************************************/
package net.minecraft.src; package cpw.mods.ironchest;
import java.io.File; import java.io.File;
import java.lang.reflect.Method; 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.Configuration;
import net.minecraft.src.forge.IOreHandler;
import net.minecraft.src.forge.MinecraftForge; import net.minecraft.src.forge.MinecraftForge;
import net.minecraft.src.forge.NetworkMod; 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 { public class mod_IronChest extends NetworkMod {
@ -41,16 +34,13 @@ public class mod_IronChest extends NetworkMod {
@Override @Override
public void load() { public void load() {
MinecraftForge.versionDetect("IronChest", 3, 2, 4); MinecraftForge.versionDetect("IronChest", 3, 3, 7);
instance = this; instance = this;
File cfgFile = new File(proxy.getMinecraftDir(), "config/IronChest.cfg"); File cfgFile = new File(proxy.getMinecraftDir(), "config/IronChest.cfg");
Configuration cfg = new Configuration(cfgFile); Configuration cfg = new Configuration(cfgFile);
try { try {
cfg.load(); cfg.load();
int bId = cfg.getOrCreateBlockIdProperty("ironChests", 181).getInt(181); 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); ironChestBlock = new BlockIronChest(bId);
ChestChangerType.buildItems(cfg, 19501); ChestChangerType.buildItems(cfg, 19501);
} catch (Exception e) { } catch (Exception e) {
@ -62,32 +52,10 @@ public class mod_IronChest extends NetworkMod {
} }
ModLoader.registerBlock(ironChestBlock, ItemIronChest.class); 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.registerTranslations();
proxy.registerTileEntities(); proxy.registerTileEntities();
ChestChangerType.generateRecipe(IronChestType.IRON); IronChestType.generateTieredRecipes(ironChestBlock);
ChestChangerType.generateRecipe(IronChestType.GOLD); ChestChangerType.generateRecipes();
ChestChangerType.generateRecipe(IronChestType.DIAMOND);
IronChestType.generateTieredRecipies(ironChestBlock);
MinecraftForge.setGuiHandler(this, proxy); MinecraftForge.setGuiHandler(this, proxy);
MinecraftForge.registerConnectionHandler(new PacketHandler()); MinecraftForge.registerConnectionHandler(new PacketHandler());
@ -100,8 +68,15 @@ public class mod_IronChest extends NetworkMod {
Class<?> equivexmaps = Class.forName("ee.EEMaps"); Class<?> equivexmaps = Class.forName("ee.EEMaps");
Method addEMC = equivexmaps.getMethod("addEMC", int.class, int.class, int.class); Method addEMC = equivexmaps.getMethod("addEMC", int.class, int.class, int.class);
Method addMeta = equivexmaps.getMethod("addMeta", 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, int[] chestEMCValues = new int[]
85 * 8 + 8 * 8 + 512 * 8, 2 * 8192 + 8 * 8 + 256 * 8 + 2048 * 8 + 6 + 8 }; {
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()) { for (IronChestType icType : IronChestType.values()) {
addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]); addEMC.invoke(null, ironChestBlock.blockID, icType.ordinal(), chestEMCValues[icType.ordinal()]);
} }