Java Code Examples for net.minecraft.item.Item.getByNameOrId()

The following are Jave code examples for showing how to use getByNameOrId() of the net.minecraft.item.Item class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Backmemed   File: JsonUtils.java   Source Code and License Vote up 6 votes
public static Item getItem(JsonElement json, String memberName)
{
    if (json.isJsonPrimitive())
    {
        String s = json.getAsString();
        Item item = Item.getByNameOrId(s);

        if (item == null)
        {
            throw new JsonSyntaxException("Expected " + memberName + " to be an item, was unknown string \'" + s + "\'");
        }
        else
        {
            return item;
        }
    }
    else
    {
        throw new JsonSyntaxException("Expected " + memberName + " to be an item, was " + toString(json));
    }
}
 
Example 2
Project: CombinedPotions   File: RecipeCombinedPotions2.java   Source Code and License Vote up 6 votes
private boolean canCombineItems(ItemStack stackA, ItemStack stackB)
{
	if (ItemStack.areItemsEqual(stackA, stackB)) return true;

	if (stackA.getItem() == Items.POTIONITEM && stackB.getItem() == Item.getByNameOrId("potioncore:custom_potion") && stackB.getMetadata() == 0) return true;
	if (stackA.getItem() == Items.SPLASH_POTION && stackB.getItem() == Item.getByNameOrId("potioncore:custom_potion") && stackB.getMetadata() == 1) return true;
	if (stackA.getItem() == Items.LINGERING_POTION && stackB.getItem() == Item.getByNameOrId("potioncore:custom_potion") && stackB.getMetadata() == 2) return true;

	if (stackB.getItem() == Items.POTIONITEM && stackA.getItem() == Item.getByNameOrId("potioncore:custom_potion") && stackA.getMetadata() == 0) return true;
	if (stackB.getItem() == Items.SPLASH_POTION && stackA.getItem() == Item.getByNameOrId("potioncore:custom_potion") && stackA.getMetadata() == 1) return true;
	if (stackB.getItem() == Items.LINGERING_POTION && stackA.getItem() == Item.getByNameOrId("potioncore:custom_potion") && stackA.getMetadata() == 2) return true;

	if (stackA.getItem() == Items.TIPPED_ARROW && stackB.getItem() == Item.getByNameOrId("potioncore:custom_arrow")) return true;
	if (stackB.getItem() == Items.TIPPED_ARROW && stackA.getItem() == Item.getByNameOrId("potioncore:custom_arrow")) return true;

	return false;
}
 
Example 3
Project: CombinedPotions   File: RecipeCombinedPotions2.java   Source Code and License Vote up 6 votes
private ItemStack getOutputStack(ItemStack inputStack)
{
	Item item = inputStack.getItem();

	if (item == Items.POTIONITEM || (item == Item.getByNameOrId("potioncore:custom_potion") && inputStack.getMetadata() == 0))
	{
		return new ItemStack(Items.POTIONITEM, 1, 0);
	}
	else if (item == Items.SPLASH_POTION || (item == Item.getByNameOrId("potioncore:custom_potion") && inputStack.getMetadata() == 1))
	{
		return new ItemStack(Items.SPLASH_POTION, 1, 0);
	}
	else if (item == Items.LINGERING_POTION || (item == Item.getByNameOrId("potioncore:custom_potion") && inputStack.getMetadata() == 2))
	{
		return new ItemStack(Items.LINGERING_POTION, 1, 0);
	}
	else if (item == Items.TIPPED_ARROW || item == Item.getByNameOrId("potioncore:custom_arrow"))
	{
		return new ItemStack(Items.TIPPED_ARROW, 1, 0);
	}

	else return ItemStack.EMPTY;
}
 
Example 4
Project: CustomWorldGen   File: JsonUtils.java   Source Code and License Vote up 6 votes
public static Item getItem(JsonElement json, String memberName)
{
    if (json.isJsonPrimitive())
    {
        String s = json.getAsString();
        Item item = Item.getByNameOrId(s);

        if (item == null)
        {
            throw new JsonSyntaxException("Expected " + memberName + " to be an item, was unknown string \'" + s + "\'");
        }
        else
        {
            return item;
        }
    }
    else
    {
        throw new JsonSyntaxException("Expected " + memberName + " to be an item, was " + toString(json));
    }
}
 
Example 5
Project: Firma   File: SoFTileEntity.java   Source Code and License Vote up 5 votes
@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);
	String id = compound.getString("shitid");
	int meta = compound.getInteger("meta");
	itemstack = new ItemStack(Item.getByNameOrId(id),1,meta);
}
 
Example 6
Project: Industrial-Foregoing   File: BlackHoleUnitBlock.java   Source Code and License Vote up 5 votes
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    super.onBlockPlacedBy(world, pos, state, placer, stack);
    if (stack.hasTagCompound() && world.getTileEntity(pos) != null && world.getTileEntity(pos) instanceof BlackHoleUnitTile && Item.getByNameOrId(stack.getTagCompound().getString(BlackHoleUnitTile.NBT_ITEMSTACK)) != null) {
        BlackHoleUnitTile tile = (BlackHoleUnitTile) world.getTileEntity(pos);
        if (stack.getTagCompound().hasKey(BlackHoleUnitTile.NBT_ITEMSTACK) && stack.getTagCompound().hasKey(BlackHoleUnitTile.NBT_META)) {
            ItemStack item = new ItemStack(Item.getByNameOrId(stack.getTagCompound().getString(BlackHoleUnitTile.NBT_ITEMSTACK)), 1, stack.getTagCompound().getInteger(BlackHoleUnitTile.NBT_META));
            if (stack.getTagCompound().hasKey(BlackHoleUnitTile.NBT_ITEM_NBT))
                item.setTagCompound(stack.getTagCompound().getCompoundTag(BlackHoleUnitTile.NBT_ITEM_NBT));
            tile.setStack(item);
        }
        if (stack.getTagCompound().hasKey(BlackHoleUnitTile.NBT_AMOUNT))
            tile.setAmount(stack.getTagCompound().getInteger(BlackHoleUnitTile.NBT_AMOUNT));
    }
}
 
Example 7
Project: Industrial-Foregoing   File: BlackHoleUnitBlock.java   Source Code and License Vote up 5 votes
@Override
public List<String> getTooltip(ItemStack stack) {
    List<String> tooltip = super.getTooltip(stack);
    if (stack.hasTagCompound() && Item.getByNameOrId(stack.getTagCompound().getString(BlackHoleUnitTile.NBT_ITEMSTACK)) != null) {
        if (stack.getTagCompound().hasKey(BlackHoleUnitTile.NBT_ITEMSTACK) && stack.getTagCompound().hasKey(BlackHoleUnitTile.NBT_META)) {
            tooltip.add(new TextComponentTranslation("text.industrialforegoing.display.item").getUnformattedText() + " " + new TextComponentTranslation(new ItemStack(Item.getByNameOrId(stack.getTagCompound().getString(BlackHoleUnitTile.NBT_ITEMSTACK)), 1, stack.getTagCompound().getInteger(BlackHoleUnitTile.NBT_META)).getUnlocalizedName() + ".name").getUnformattedText());
        }
        if (stack.getTagCompound().hasKey(BlackHoleUnitTile.NBT_AMOUNT))
            tooltip.add(new TextComponentTranslation("text.industrialforegoing.display.amount").getUnformattedText() + " " + stack.getTagCompound().getInteger(BlackHoleUnitTile.NBT_AMOUNT));
    }
    return tooltip;
}
 
Example 8
Project: UraniumBigReactor   File: UraniumBigReactorMod.java   Source Code and License Vote up 5 votes
@EventHandler
public void init(FMLPostInitializationEvent event)
{
    ReactorInterior.registerFluid("ic2coolant", 0.66F, 0.95F, 6F, IHeatEntity.conductivityDiamond);
    ReactorInterior.registerFluid("ic2uu_matter", 0.9F, 0.99F, 18F, IHeatEntity.conductivityDiamond);

    Reactants.registerReactant("uFuel", 0, 0x46c81a);
    Reactants.registerReactant("plutonium", 1, 0xaaaaaa);
    ReactorConversions.register("uFuel", "plutonium");

    Reactants.registerSolid("uraniumFuel", "uFuel");
    Reactants.registerSolid("tinyPlutonium", "plutonium");
    Item uraniumFuel = Item.getByNameOrId("ic2:nuclear");
    if(uraniumFuel != null)
    {
        OreDictionary.registerOre("uraniumFuel", uraniumFuel);
        OreDictionary.registerOre("tinyPlutonium", new ItemStack(uraniumFuel, 1, 7));
    }
    else
    {
        OreDictionary.registerOre("tinyPlutonium", new ItemStack(Item.getByNameOrId("bigreactors:ingotMetals"), 0, 1));
    }

    Fluid fluidUranium = FluidRegistry.getFluid("uraniumfuel");
    if(fluidUranium != null)
        Reactants.registerFluid(fluidUranium, "uFuel");
}
 
Example 9
Project: CharcoalPit   File: PotteryKilnRecipe.java   Source Code and License Vote up 5 votes
public static void initCustomRecipes(String[] customRecipes){
	if(customRecipes!=null){
		for(int i=0;i<customRecipes.length;i++){
			String[] customRecipe=customRecipes[i].split(" ");
			if(customRecipe.length!=4)
				continue;
			Item input=Item.getByNameOrId(customRecipe[0]);
			Item output=Item.getByNameOrId(customRecipe[2]);
			if(input!=null&&output!=null){
				recipes.add(new PotteryKilnRecipe(new ItemStack(input, 1, Integer.parseInt(customRecipe[1])), new ItemStack(output, 1, Integer.parseInt(customRecipe[3]))));
			}
		}
	}
}
 
Example 10
Project: BaseClient   File: TileEntityFlowerPot.java   Source Code and License Vote up 5 votes
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);

    if (compound.hasKey("Item", 8))
    {
        this.flowerPotItem = Item.getByNameOrId(compound.getString("Item"));
    }
    else
    {
        this.flowerPotItem = Item.getItemById(compound.getInteger("Item"));
    }

    this.flowerPotData = compound.getInteger("Data");
}
 
Example 11
Project: BaseClient   File: TileEntityFlowerPot.java   Source Code and License Vote up 5 votes
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);

    if (compound.hasKey("Item", 8))
    {
        this.flowerPotItem = Item.getByNameOrId(compound.getString("Item"));
    }
    else
    {
        this.flowerPotItem = Item.getItemById(compound.getInteger("Item"));
    }

    this.flowerPotData = compound.getInteger("Data");
}
 
Example 12
Project: Backmemed   File: TileEntityFlowerPot.java   Source Code and License Vote up 5 votes
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);

    if (compound.hasKey("Item", 8))
    {
        this.flowerPotItem = Item.getByNameOrId(compound.getString("Item"));
    }
    else
    {
        this.flowerPotItem = Item.getItemById(compound.getInteger("Item"));
    }

    this.flowerPotData = compound.getInteger("Data");
}
 
Example 13
Project: CustomWorldGen   File: TileEntityFlowerPot.java   Source Code and License Vote up 5 votes
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);

    if (compound.hasKey("Item", 8))
    {
        this.flowerPotItem = Item.getByNameOrId(compound.getString("Item"));
    }
    else
    {
        this.flowerPotItem = Item.getItemById(compound.getInteger("Item"));
    }

    this.flowerPotData = compound.getInteger("Data");
}
 
Example 14
Project: Zombe-Modpack   File: ZWrapper.java   Source Code and License Vote up 4 votes
public static Item getItem(String name) {
    return Item.getByNameOrId(name);
}
 
Example 15
Project: Mob-Option-Redux   File: JSONEquipmentReader.java   Source Code and License Vote up 4 votes
public static ItemStack getStackFromString(String string) {
	String[] values = string.split("#");
	Item item = Item.getByNameOrId(values[0]);
	int meta = Integer.parseInt(values[1]);
	return new ItemStack(item, 1, meta);
}
 
Example 16
Project: EMC   File: IItem.java   Source Code and License Vote up 4 votes
public IItem(String name) {
	this.item = Item.getByNameOrId(name);
}
 
Example 17
Project: EMC   File: IItemStack.java   Source Code and License Vote up 4 votes
public IItemStack(String name) {
	this.stack = new ItemStack(Item.getByNameOrId(name));
}
 
Example 18
Project: EMC   File: IItemStack.java   Source Code and License Vote up 4 votes
public static boolean validName(String name) {
	return Item.getByNameOrId(name) != null;
}