TechReborn/src/main/java/techreborn/items/ItemCells.java

114 lines
3.1 KiB
Java
Raw Normal View History

2015-04-17 00:42:05 +02:00
package techreborn.items;
import ic2.core.Ic2Items;
import ic2.core.item.ItemFluidCell;
2015-04-17 00:42:05 +02:00
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import techreborn.client.TechRebornCreativeTab;
import techreborn.init.ModItems;
import techreborn.util.LogHelper;
2015-04-17 00:42:05 +02:00
2015-07-02 20:51:24 +02:00
import java.util.List;
2015-06-26 09:17:02 +02:00
public class ItemCells extends ItemTR {
public static ItemStack getCellByName(String name, int count)
{
ItemFluidCell itemFluidCell = (ItemFluidCell) Ic2Items.FluidCell.getItem();
Fluid fluid = FluidRegistry.getFluid("fluid" + name.toLowerCase());
if(fluid != null){
ItemStack stack = Ic2Items.FluidCell.copy();
itemFluidCell.fill(stack, new FluidStack(fluid.getID(), 2147483647), true);
2015-06-26 09:17:02 +02:00
stack.stackSize = count;
return stack;
} else {
LogHelper.error("Could not find " + "fluid" + name + " in the fluid registry!");
}
int index = -1;
for (int i = 0; i < types.length; i++) {
if (types[i].equals(name)) {
index = i;
break;
}
}
return new ItemStack(ModItems.cells, count, index);
}
public static ItemStack getCellByName(String name)
{
return getCellByName(name, 1);
}
2015-04-24 15:20:09 +02:00
public static final String[] types = new String[]
{ "Berylium", "biomass", "calciumCarbonate", "calcium", "carbon",
"chlorine", "deuterium", "diesel", "ethanol", "glyceryl",
"helium3", "helium", "heliumPlasma", "hydrogen", "ice", "lithium",
"mercury", "methane", "nitrocarbon", "nitroCoalfuel",
"nitroDiesel", "nitrogen", "nitrogenDioxide", "oil", "potassium",
"seedOil", "silicon", "sodium", "sodiumPersulfate",
2015-05-04 05:54:38 +02:00
"sodiumSulfide", "sulfur", "sulfuricAcid", "tritium", "wolframium", };
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
private IIcon[] textures;
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
public ItemCells()
{
setUnlocalizedName("techreborn.cell");
setHasSubtypes(true);
setCreativeTab(TechRebornCreativeTab.instance);
2015-04-24 15:20:09 +02:00
}
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
@Override
// Registers Textures For All Dusts
public void registerIcons(IIconRegister iconRegister)
{
textures = new IIcon[types.length];
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
for (int i = 0; i < types.length; ++i)
{
textures[i] = iconRegister.registerIcon("techreborn:" + "cells/"
+ types[i] + "Cell");
}
}
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
@Override
// Adds Texture what match's meta data
public IIcon getIconFromDamage(int meta)
{
if (meta < 0 || meta >= textures.length)
{
meta = 0;
}
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
return textures[meta];
}
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
@Override
// gets Unlocalized Name depending on meta data
public String getUnlocalizedName(ItemStack itemStack)
{
int meta = itemStack.getItemDamage();
if (meta < 0 || meta >= types.length)
{
meta = 0;
}
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
return super.getUnlocalizedName() + "." + types[meta];
}
2015-04-17 00:42:05 +02:00
2015-04-24 15:20:09 +02:00
// Adds Dusts SubItems To Creative Tab
public void getSubItems(Item item, CreativeTabs creativeTabs, List list)
{
for (int meta = 0; meta < types.length; ++meta)
{
list.add(new ItemStack(item, 1, meta));
}
}
2015-04-17 00:42:05 +02:00
}