Java Code Examples for net.minecraft.item.ItemStack#getMetadata()

The following examples show how to use net.minecraft.item.ItemStack#getMetadata() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TileEntityBarrel.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
    if (stack.isEmpty() == false && stack.getItem() == EnderUtilitiesItems.ENDER_PART)
    {
        int meta = stack.getMetadata();

        switch (slot)
        {
            case 0: return meta == 70; // Barrel Label
            case 1: return meta == 71; // Barrel Structural Upgrade
            case 2: return meta == 72; // Barrel Capacity Upgrade
            case 3: return meta == 73; // Barrel Void Upgrade
            default: return false;
        }
    }

    return false;
}
 
Example 2
Source File: ItemMesh.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@Override
public int getItemEnchantability(ItemStack stack)
{
    switch(stack.getMetadata())
    {
        case 1:
            return 15;
        case 2:
            return 7;
        case 3:
            return 14;
        case 4:
            return 10;
        default:
            return 0;
    }
}
 
Example 3
Source File: AgriSeed.java    From AgriCraft with MIT License 6 votes vote down vote up
@Nonnull
public ItemStack toStack(int size) {
    // Get the stack.
    final ItemStack stack = Preconditions.checkNotNull(this.plant.getSeed());

    // Get the tag.
    final NBTTagCompound tag = Optional.ofNullable(stack.getTagCompound())
            .map(NBTTagCompound::copy)
            .orElseGet(NBTTagCompound::new);

    // Write the stat to the tag.
    this.stat.writeToNBT(tag);

    // Return a new stack.
    // Thanks @darthvader45
    ItemStack ret = new ItemStack(stack.getItem(), size, stack.getMetadata());
    ret.setTagCompound(tag);
    return ret;
}
 
Example 4
Source File: ItemLinkCrystal.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    ItemStack stack = player.getHeldItem(hand);

    if (stack.getMetadata() == TYPE_PORTAL && world.getBlockState(pos).getBlock() != EnderUtilitiesBlocks.PORTAL)
    {
        return EnumActionResult.PASS;
    }

    return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
}
 
Example 5
Source File: ItemEnderCapacitor.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String getTranslationKey(ItemStack stack)
{
    // Damage 0: Ender Capacitor (Basic)
    // Damage 1: Ender Capacitor (Enhanced)
    // Damage 2: Ender Capacitor (Advanced)
    // Damage 3: Ender Capacitor (Creative)
    if (stack.getMetadata() >= 0 && stack.getMetadata() <= 3)
    {
        return super.getTranslationKey() + "_" + stack.getMetadata();
    }

    return super.getTranslationKey();
}
 
Example 6
Source File: ItemEnderPart.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void activateEnderCore(ItemStack stack)
{
    int meta = stack.getMetadata();
    // Inactive Ender Cores

    if (meta >= 10 && meta <= 12)
    {
        // "Activate" the Ender Core (ie. change the item)
        stack.setItemDamage(meta + 5);
    }
}
 
Example 7
Source File: ItemBlockEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String getTranslationKey(ItemStack stack)
{
    if (this.blockNames != null && stack.getMetadata() < this.blockNames.length)
    {
        return "tile." + ReferenceNames.getDotPrefixedName(this.blockNames[stack.getMetadata()]);
    }

    return super.getTranslationKey(stack);
}
 
Example 8
Source File: ToolTip.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean isCorrectItem(ItemStack eventStack)
{
    boolean itemEqual = eventStack.getMetadata() == OreDictionary.WILDCARD_VALUE
                        ? stack.isItemEqualIgnoreDurability(eventStack)
                        : stack.isItemEqual(eventStack);

    boolean nbtEqual = !eventStack.hasTagCompound() || ItemStack.areItemStackTagsEqual(eventStack, stack);

    return itemEqual && nbtEqual;
}
 
Example 9
Source File: InventoryUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Checks if there is a matching ItemStack in the provided array of stacks
 */
public static boolean matchingStackFoundOnList(NonNullList<ItemStack> list,
        @Nonnull ItemStack stackTemplate, boolean ignoreMeta, boolean ignoreNbt)
{
    Item item = stackTemplate.getItem();
    int meta = stackTemplate.getMetadata();
    final int size = list.size();

    for (int i = 0; i < size; i++)
    {
        ItemStack stackTmp = list.get(i);

        if (stackTmp.isEmpty() || stackTmp.getItem() != item)
        {
            continue;
        }

        if (ignoreMeta == false && (meta != OreDictionary.WILDCARD_VALUE && stackTmp.getMetadata() != meta))
        {
            continue;
        }

        if (ignoreNbt == false && ItemStack.areItemStackTagsEqual(stackTemplate, stackTmp) == false)
        {
            continue;
        }

        return true;
    }

    return false;
}
 
Example 10
Source File: DataManager.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void setHeldItemAsTool()
{
    EntityPlayer player = Minecraft.getMinecraft().player;

    if (player != null)
    {
        ItemStack stack = player.getHeldItemMainhand();
        toolItem = stack.isEmpty() ? ItemStack.EMPTY : stack.copy();
        String cfgStr = "";

        if (stack.isEmpty() == false)
        {
            cfgStr = Item.REGISTRY.getNameForObject(stack.getItem()).toString();
            NBTTagCompound nbt = stack.getTagCompound();

            if (stack.isItemStackDamageable() == false || nbt != null)
            {
                cfgStr += "@" + stack.getMetadata();

                if (nbt != null)
                {
                    cfgStr += nbt.toString();
                }
            }
        }

        Configs.Generic.TOOL_ITEM.setValueFromString(cfgStr);
        InfoUtils.printActionbarMessage("litematica.message.set_currently_held_item_as_tool");
    }
}
 
Example 11
Source File: ItemLinkCrystal.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ModuleType getModuleType(ItemStack stack)
{
    if (stack.getMetadata() >= 0 && stack.getMetadata() <= 2)
    {
        return ModuleType.TYPE_LINKCRYSTAL;
    }

    return ModuleType.TYPE_INVALID;
}
 
Example 12
Source File: ItemLinkCrystal.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String getTranslationKey(ItemStack stack)
{
    // Damage 0: Link Crystal (In-World)
    // Damage 1: Link Crystal (Inventory)
    // Damage 2: Link Crystal (Portal)
    if (stack.getMetadata() >= 0 && stack.getMetadata() <= 2)
    {
        return super.getTranslationKey() + "_" + stack.getMetadata();
    }

    return super.getTranslationKey();
}
 
Example 13
Source File: ItemEnderPorter.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean isAdvancedPorter(ItemStack stack)
{
    // damage 1: Advanced Ender Porter
    return stack.getMetadata() == 1;
}
 
Example 14
Source File: ItemHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int getSizeInventory(ItemStack containerStack)
{
    return containerStack.getMetadata() == META_TIER_2 ? INV_SIZE_TIER_2 : INV_SIZE_TIER_1;
}
 
Example 15
Source File: InventoryPlayerTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
public static boolean stackEqualExact(ItemStack stack1, ItemStack stack2)
{
	return stack1.getItem() == stack2.getItem() && (!stack1.getHasSubtypes() || stack1.getMetadata() == stack2.getMetadata()) && 
			(ItemStack.areItemStackTagsEqual(stack1, stack2) || (stack1.getItem() instanceof IFood && stack2.getItem() instanceof IFood && Food.areEqual(stack1, stack2)));
}
 
Example 16
Source File: TileEntityModuleMachine.java    From customstuff4 with GNU General Public License v3.0 4 votes vote down vote up
private boolean isWetSponge(ItemStack stack)
{
    return stack.getItem() == Item.getItemFromBlock(Blocks.SPONGE) && stack.getMetadata() == 1;
}
 
Example 17
Source File: ItemSyringe.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand)
{
    int meta = stack.getMetadata();

    if (meta == 0 || (target instanceof EntityLiving) == false)
    {
        return super.itemInteractionForEntity(stack, playerIn, target, hand);
    }

    EntityLiving living = (EntityLiving) target;

    // 1: Paralyzer - set NoAI
    // 2: Stimulant - disable NoAI
    if (meta == 1 || meta == 2)
    {
        boolean noAI = meta == 1;

        if (living.isAIDisabled() != noAI)
        {
            if (playerIn.getEntityWorld().isRemote == false)
            {
                living.setNoAI(noAI);

                if (playerIn.capabilities.isCreativeMode == false)
                {
                    stack.setItemDamage(0);
                }

                playerIn.getEntityWorld().playSound(null, playerIn.getPosition(), SoundEvents.ITEM_BUCKET_EMPTY_LAVA, SoundCategory.MASTER, 0.9f, 3.0f);
            }

            return true;
        }
    }

    // 3: Passifier - remove target AI tasks and set a flag which causes the removal to happen on (re-)spawn
    if (meta == 3)
    {
        if (playerIn.getEntityWorld().isRemote == false && passifyEntity(living))
        {
            if (playerIn.capabilities.isCreativeMode == false)
            {
                stack.setItemDamage(0);
            }

            playerIn.getEntityWorld().playSound(null, playerIn.getPosition(), SoundEvents.ITEM_BUCKET_EMPTY_LAVA, SoundCategory.MASTER, 0.9f, 3.0f);
        }

        return true;
    }

    return super.itemInteractionForEntity(stack, playerIn, target, hand);
}
 
Example 18
Source File: StackHelper.java    From EmergingTechnology with MIT License 4 votes vote down vote up
public static boolean compareItemStacks(ItemStack stack1, ItemStack stack2) {
    return stack2.getItem() == stack1.getItem()
            && (stack2.getMetadata() == OreDictionary.WILDCARD_VALUE || stack2.getMetadata() == stack1.getMetadata());
}
 
Example 19
Source File: ItemEnderPart.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int getModuleTier(ItemStack stack)
{
    int meta = stack.getMetadata();

    // Inactive Ender Cores
    if (meta >= 10 && meta <= 12)
    {
        return meta - 10 + ENDER_CORE_TYPE_INACTIVE_BASIC;
    }

    // Active Ender Cores
    if (meta >= 15 && meta <= 17)
    {
        return meta - 15 + ENDER_CORE_TYPE_ACTIVE_BASIC;
    }

    // Creative Breaking module
    if (meta == 30)
    {
        return 0;
    }

    // Mob Persistence
    if (this.getModuleType(stack).equals(ModuleType.TYPE_MOBPERSISTENCE))
    {
        return 0;
    }

    // Memory Card (misc)
    if (meta == 50)
    {
        return MEMORY_CARD_TYPE_MISC;
    }

    // Memory Card (items)
    if (this.getModuleType(stack).equals(ModuleType.TYPE_MEMORY_CARD_ITEMS))
    {
        int tier = meta - 51;

        switch (tier)
        {
            case 0: return MEMORY_CARD_TYPE_ITEMS_6B;
            case 1: return MEMORY_CARD_TYPE_ITEMS_8B;
            case 2: return MEMORY_CARD_TYPE_ITEMS_10B;
            case 3: return MEMORY_CARD_TYPE_ITEMS_12B;
        }
    }

    return -1; // Invalid item (= non-module)
}
 
Example 20
Source File: FuzzyStack.java    From AgriCraft with MIT License 4 votes vote down vote up
public boolean isMetaEqual(@Nullable ItemStack other) {
    return (other != null) && (this.ignoreMeta || this.getMeta() == other.getMetadata());
}