Move mod to my own package, update for new forge ore dictionary recipes
This commit is contained in:
parent
6cbc221271
commit
3290802a7d
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
* 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
|
||||
* Contributors: cpw - initial API and implementation
|
||||
******************************************************************************/
|
||||
package cpw.mods.ironchest;
|
||||
|
||||
|
@ -20,14 +16,14 @@ 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;
|
||||
|
@ -37,15 +33,15 @@ public enum ChestChangerType {
|
|||
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;
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.itemName = itemName;
|
||||
this.descriptiveName = descriptiveName;
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
public boolean canUpgrade(IronChestType from) {
|
||||
return from==this.source;
|
||||
return from == this.source;
|
||||
}
|
||||
|
||||
public int getTarget() {
|
||||
|
@ -53,31 +49,30 @@ public enum ChestChangerType {
|
|||
}
|
||||
|
||||
public ItemChestChanger buildItem(Configuration cfg, int id) {
|
||||
int itemId=Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.CATEGORY_ITEM, id).value);
|
||||
item=new ItemChestChanger(itemId,this);
|
||||
int itemId = Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.CATEGORY_ITEM, id).value);
|
||||
item = new ItemChestChanger(itemId, this);
|
||||
return item;
|
||||
}
|
||||
|
||||
public void addRecipe() {
|
||||
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', target.mat,'s',source.mat,'G',Block.glass,'O',Block.obsidian);
|
||||
public void addRecipes() {
|
||||
for (String sourceMat : source.getMatList()) {
|
||||
for (String targetMat : target.getMatList()) {
|
||||
Object targetMaterial = IronChestType.translateOreName(targetMat);
|
||||
Object sourceMaterial = IronChestType.translateOreName(sourceMat);
|
||||
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', targetMaterial, 's', sourceMaterial, 'G', Block.glass, 'O', Block.obsidian);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void buildItems(Configuration cfg, int defaultId) {
|
||||
for (ChestChangerType type: values()) {
|
||||
for (ChestChangerType type : values()) {
|
||||
type.buildItem(cfg, defaultId++);
|
||||
}
|
||||
}
|
||||
|
||||
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 static void generateRecipes() {
|
||||
for (ChestChangerType item : values()) {
|
||||
item.addRecipes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,21 +10,23 @@
|
|||
******************************************************************************/
|
||||
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<? extends TileEntityIronChest> clazz;
|
||||
Item mat;
|
||||
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) {
|
||||
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<ItemStack>();
|
||||
if (mat != null) {
|
||||
matList.add(new ItemStack(mat));
|
||||
}
|
||||
this.matList = new ArrayList<String>();
|
||||
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);
|
||||
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<ItemStack> getMatList() {
|
||||
return matList;
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return this == CRYSTAL;
|
||||
}
|
||||
|
||||
public List<String> getMatList() {
|
||||
return matList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -16,8 +16,11 @@ 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;
|
||||
|
||||
|
@ -44,6 +47,6 @@ public class Version {
|
|||
if (!loaded) {
|
||||
init();
|
||||
}
|
||||
return major+"."+minor+"."+rev;
|
||||
return major+"."+minor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,23 +8,16 @@
|
|||
* 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()]);
|
||||
}
|
Loading…
Reference in New Issue