ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/util/ItemUtil.java
Ellpeck d02c5f61e9 Finished Tool Table Logic
(When an extra item is in the tool table that doesn't belong to the recipe, it'll just be ignored and not taken away)
2015-09-22 23:32:19 +02:00

71 lines
2.1 KiB
Java

/*
* This file ("ItemUtil.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015 Ellpeck
*/
package ellpeck.actuallyadditions.util;
import cpw.mods.fml.common.registry.GameRegistry;
import ellpeck.actuallyadditions.creative.CreativeTab;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ItemUtil{
public static Item getItemFromName(String name){
if(Item.itemRegistry.containsKey(name)){
return (Item)Item.itemRegistry.getObject(name);
}
return null;
}
public static void registerItems(Item[] items){
for(Item item : items){
register(item);
}
}
public static void register(Item item){
register(item, true);
}
public static void register(Item item, boolean addTab){
item.setCreativeTab(addTab ? CreativeTab.instance : null);
item.setUnlocalizedName(createUnlocalizedName(item));
GameRegistry.registerItem(item, ((INameableItem)item).getName());
}
public static String createUnlocalizedName(Item item){
return ModUtil.MOD_ID_LOWER+"."+((INameableItem)item).getName();
}
/**
* Returns true if stacksOne contains every ItemStack in stackTwo
*/
public static boolean containsAll(ItemStack[] stacksOne, ItemStack[] stacksTwo){
for(ItemStack stackTwo : stacksTwo){
if(!contains(stacksOne, stackTwo)){
return false;
}
}
return true;
}
/**
* Returns true if array contains stack or if both contain null
*/
public static boolean contains(ItemStack[] array, ItemStack stack){
for(ItemStack aStack : array){
if((stack == null && aStack == null) || (stack != null && aStack != null && aStack.isItemEqual(stack))){
return true;
}
}
return false;
}
}