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

72 lines
2.2 KiB
Java
Raw Normal View History

2015-05-04 22:52:08 +02:00
package techreborn.items;
2016-12-10 09:15:39 +01:00
import com.google.common.base.CaseFormat;
2015-05-04 22:52:08 +02:00
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2016-11-25 14:23:42 +01:00
import net.minecraft.util.NonNullList;
import net.minecraftforge.oredict.OreDictionary;
2015-05-04 22:52:08 +02:00
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModItems;
2015-05-04 22:52:08 +02:00
import java.security.InvalidParameterException;
2016-12-10 09:15:39 +01:00
public class ItemPlates extends ItemTRNoDestroy {
2016-03-25 10:47:34 +01:00
//Vanilla plates or plates not from ingots or gems
public static String[] types = new String[] {
2016-10-08 21:46:16 +02:00
"iron", "gold", "carbon", "wood", "redstone", "diamond", "emerald", "lapis", "coal", "obsidian", "lazurite"
};
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
public ItemPlates() {
2016-03-25 10:47:34 +01:00
setUnlocalizedName("techreborn.plate");
setHasSubtypes(true);
setCreativeTab(TechRebornCreativeTabMisc.instance);
}
2016-10-08 21:46:16 +02:00
public static ItemStack getPlateByName(String name, int count) {
for (int i = 0; i < types.length; i++) {
if (types[i].equalsIgnoreCase(name)) {
2016-03-25 10:47:34 +01:00
return new ItemStack(ModItems.plate, count, i);
}
}
throw new InvalidParameterException("The plate " + name + " could not be found.");
}
2016-10-08 21:46:16 +02:00
public static ItemStack getPlateByName(String name) {
2016-03-25 10:47:34 +01:00
return getPlateByName(name, 1);
}
public static void registerType(String plateType) {
for (String type : types) {
2016-10-08 21:46:16 +02:00
if (type.equals(plateType))
return;
}
int plateIndex = types.length;
String[] newTypes = new String[plateIndex + 1];
System.arraycopy(types, 0, newTypes, 0, types.length);
types = newTypes;
newTypes[plateIndex] = plateType;
2016-12-10 09:15:39 +01:00
String oreName = "plate" + CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, plateType);
OreDictionary.registerOre(oreName, new ItemStack(ModItems.plate, 1, plateIndex));
}
2016-10-08 21:46:16 +02:00
@Override
2016-12-10 09:15:39 +01:00
// gets Unlocalized Name depending on meta data
public String getUnlocalizedName(ItemStack itemStack) {
int meta = itemStack.getItemDamage();
if (meta < 0 || meta >= types.length) {
meta = 0;
}
2016-03-25 10:47:34 +01:00
2016-12-10 09:15:39 +01:00
return super.getUnlocalizedName() + "." + types[meta];
2016-03-25 10:47:34 +01:00
}
2015-11-24 23:58:18 +01:00
2016-12-10 09:15:39 +01:00
// Adds Dusts SubItems To Creative Tab
public void getSubItems(Item item, CreativeTabs creativeTabs, NonNullList list) {
for (int meta = 0; meta < types.length; ++meta) {
list.add(new ItemStack(item, 1, meta));
}
}
2015-05-04 22:52:08 +02:00
}