Started working on auto-gen ItemDust

This commit is contained in:
Calclavia 2014-01-04 13:18:26 +08:00
parent a1ac29149c
commit 457404b6bf
2 changed files with 99 additions and 3 deletions

View file

@ -13,12 +13,14 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.Configuration; import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe;
import org.modstats.ModstatInfo; import org.modstats.ModstatInfo;
import org.modstats.Modstats; import org.modstats.Modstats;
import resonantinduction.machine.crusher.ItemDust;
import resonantinduction.machine.furnace.BlockAdvancedFurnace; import resonantinduction.machine.furnace.BlockAdvancedFurnace;
import resonantinduction.machine.furnace.TileAdvancedFurnace; import resonantinduction.machine.furnace.TileAdvancedFurnace;
import resonantinduction.multimeter.ItemMultimeter; import resonantinduction.multimeter.ItemMultimeter;
@ -133,14 +135,18 @@ public class ResonantInduction
} }
// Items // Items
public static Item itemLinker;
/** /**
* Forge Multipart * Transport
*/ */
public static Item itemLinker;
private static Item itemPartWire; private static Item itemPartWire;
public static Item itemMultimeter; public static Item itemMultimeter;
public static Item itemTransformer; public static Item itemTransformer;
public static Item itemIOPanel;
/**
* Machines
*/
public static Item itemDust;
// Blocks // Blocks
public static Block blockTesla; public static Block blockTesla;
@ -181,6 +187,7 @@ public class ResonantInduction
itemPartWire = new ItemWire(getNextItemID()); itemPartWire = new ItemWire(getNextItemID());
itemMultimeter = new ItemMultimeter(getNextItemID()); itemMultimeter = new ItemMultimeter(getNextItemID());
itemTransformer = new ItemTransformer(getNextItemID()); itemTransformer = new ItemTransformer(getNextItemID());
itemDust = new ItemDust(getNextItemID());
// Blocks // Blocks
blockTesla = new BlockTesla(getNextBlockID()); blockTesla = new BlockTesla(getNextBlockID());
@ -199,6 +206,7 @@ public class ResonantInduction
GameRegistry.registerItem(itemLinker, itemLinker.getUnlocalizedName()); GameRegistry.registerItem(itemLinker, itemLinker.getUnlocalizedName());
GameRegistry.registerItem(itemMultimeter, itemMultimeter.getUnlocalizedName()); GameRegistry.registerItem(itemMultimeter, itemMultimeter.getUnlocalizedName());
GameRegistry.registerItem(itemTransformer, itemTransformer.getUnlocalizedName()); GameRegistry.registerItem(itemTransformer, itemTransformer.getUnlocalizedName());
GameRegistry.registerItem(itemDust, itemDust.getUnlocalizedName());
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName()); GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName()); GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
@ -220,6 +228,8 @@ public class ResonantInduction
{ {
material.setWire(itemPartWire); material.setWire(itemPartWire);
} }
MinecraftForge.EVENT_BUS.register(itemDust);
} }
@EventHandler @EventHandler
@ -288,6 +298,9 @@ public class ResonantInduction
GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.COPPER.getWire(), "universalCable")); GameRegistry.addRecipe(new ShapelessOreRecipe(EnumWireMaterial.COPPER.getWire(), "universalCable"));
} }
/** Auto-gen dusts */
ItemDust.postInit();
/** Inject new furnace tile class */ /** Inject new furnace tile class */
replaceTileEntity(TileEntityFurnace.class, TileAdvancedFurnace.class); replaceTileEntity(TileEntityFurnace.class, TileAdvancedFurnace.class);
} }

View file

@ -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<String> ingots = new HashSet<String>();
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;
}
}