diff --git a/src/main/java/resonantinduction/ResonantInduction.java b/src/main/java/resonantinduction/ResonantInduction.java index 469fb8712..d1df44d19 100644 --- a/src/main/java/resonantinduction/ResonantInduction.java +++ b/src/main/java/resonantinduction/ResonantInduction.java @@ -13,12 +13,14 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraftforge.common.Configuration; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; import org.modstats.ModstatInfo; import org.modstats.Modstats; +import resonantinduction.machine.crusher.ItemDust; import resonantinduction.machine.furnace.BlockAdvancedFurnace; import resonantinduction.machine.furnace.TileAdvancedFurnace; import resonantinduction.multimeter.ItemMultimeter; @@ -133,14 +135,18 @@ public class ResonantInduction } // Items - public static Item itemLinker; /** - * Forge Multipart + * Transport */ + public static Item itemLinker; private static Item itemPartWire; public static Item itemMultimeter; public static Item itemTransformer; - public static Item itemIOPanel; + + /** + * Machines + */ + public static Item itemDust; // Blocks public static Block blockTesla; @@ -181,6 +187,7 @@ public class ResonantInduction itemPartWire = new ItemWire(getNextItemID()); itemMultimeter = new ItemMultimeter(getNextItemID()); itemTransformer = new ItemTransformer(getNextItemID()); + itemDust = new ItemDust(getNextItemID()); // Blocks blockTesla = new BlockTesla(getNextBlockID()); @@ -199,6 +206,7 @@ public class ResonantInduction GameRegistry.registerItem(itemLinker, itemLinker.getUnlocalizedName()); GameRegistry.registerItem(itemMultimeter, itemMultimeter.getUnlocalizedName()); GameRegistry.registerItem(itemTransformer, itemTransformer.getUnlocalizedName()); + GameRegistry.registerItem(itemDust, itemDust.getUnlocalizedName()); GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName()); GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName()); @@ -220,6 +228,8 @@ public class ResonantInduction { material.setWire(itemPartWire); } + + MinecraftForge.EVENT_BUS.register(itemDust); } @EventHandler @@ -288,6 +298,9 @@ public class ResonantInduction GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.COPPER.getWire(), "universalCable")); } + /** Auto-gen dusts */ + ItemDust.postInit(); + /** Inject new furnace tile class */ replaceTileEntity(TileEntityFurnace.class, TileAdvancedFurnace.class); } diff --git a/src/main/java/resonantinduction/machine/crusher/ItemDust.java b/src/main/java/resonantinduction/machine/crusher/ItemDust.java new file mode 100644 index 000000000..98c281dfa --- /dev/null +++ b/src/main/java/resonantinduction/machine/crusher/ItemDust.java @@ -0,0 +1,83 @@ +package resonantinduction.machine.crusher; + +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent; +import resonantinduction.ResonantInduction; +import resonantinduction.core.base.ItemBase; +import calclavia.lib.Calclavia; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * An item used for auto-generated dusts based on registered ingots in the OreDict. + * + * @author Calclavia + * + */ +public class ItemDust extends ItemBase +{ + public static final Set ingots = new HashSet(); + + public ItemDust(int id) + { + super("dust", id); + } + + @ForgeSubscribe + public void oreRegisterEvent(OreRegisterEvent evt) + { + if (evt.Name.startsWith("ingot")) + { + String ingotName = evt.Name.replace("ingot", ""); + ingots.add(ingotName.toLowerCase()); + } + } + + public static void postInit() + { + for (String ingotName : ingots) + { + String dustName = "dust" + ingotName.substring(0, 1).toUpperCase() + ingotName.substring(1); + + if (OreDictionary.getOres(dustName).size() > 0) + { + OreDictionary.registerOre(dustName, getStackFromDust(ingotName)); + } + } + } + + public static ItemStack getStackFromDust(String name) + { + ItemStack itemStack = new ItemStack(ResonantInduction.itemDust); + NBTTagCompound nbt = Calclavia.getNBTTagCompound(itemStack); + nbt.setString("name", name); + return itemStack; + } + + public static String getDustFromStack(ItemStack itemStack) + { + NBTTagCompound nbt = Calclavia.getNBTTagCompound(itemStack); + + if (nbt.hasKey("name")) + { + return nbt.getString("name"); + } + + return null; + } + + @SideOnly(Side.CLIENT) + public int getColorFromItemStack(ItemStack itemStack, int par2) + { + /** + * Auto-color based on the texture of the ingot. + */ + return 16777215; + } +}