當前位置: 首頁>>代碼示例>>Java>>正文


Java Item類代碼示例

本文整理匯總了Java中net.minecraft.item.Item的典型用法代碼示例。如果您正苦於以下問題:Java Item類的具體用法?Java Item怎麽用?Java Item使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Item類屬於net.minecraft.item包,在下文中一共展示了Item類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getEnchantmentDatas

import net.minecraft.item.Item; //導入依賴的package包/類
public static List<EnchantmentData> getEnchantmentDatas(int p_185291_0_, ItemStack p_185291_1_, boolean allowTreasure)
{
    List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList();
    Item item = p_185291_1_.getItem();
    boolean flag = p_185291_1_.getItem() == Items.BOOK;

    for (Enchantment enchantment : Enchantment.REGISTRY)
    {
        if ((!enchantment.isTreasureEnchantment() || allowTreasure) && (enchantment.type.canEnchantItem(item) || flag))
        {
            for (int i = enchantment.getMaxLevel(); i > enchantment.getMinLevel() - 1; --i)
            {
                if (p_185291_0_ >= enchantment.getMinEnchantability(i) && p_185291_0_ <= enchantment.getMaxEnchantability(i))
                {
                    list.add(new EnchantmentData(enchantment, i));
                    break;
                }
            }
        }
    }

    return list;
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:24,代碼來源:EnchantmentHelper.java

示例2: quantityDroppedWithBonus

import net.minecraft.item.Item; //導入依賴的package包/類
/**
 * Get the quantity dropped based on the given fortune level
 */
public int quantityDroppedWithBonus(int fortune, Random random)
{
    if (fortune > 0 && Item.getItemFromBlock(this) != this.getItemDropped((IBlockState)this.getBlockState().getValidStates().iterator().next(), random, fortune))
    {
        int i = random.nextInt(fortune + 2) - 1;

        if (i < 0)
        {
            i = 0;
        }

        return this.quantityDropped(random) * (i + 1);
    }
    else
    {
        return this.quantityDropped(random);
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:22,代碼來源:BlockOre.java

示例3: RenderTarget

import net.minecraft.item.Item; //導入依賴的package包/類
public RenderTarget(Entity entity) {
    this.entity = entity;
    trackEntries = EntityTrackHandler.getTrackersForEntity(entity);
    circle1 = new RenderTargetCircle();
    circle2 = new RenderTargetCircle();
    Item droppedItem = null;
    if (entity instanceof EntityLiving) {
        try {
            droppedItem = null;//TODO 1.8 EntityUtils.getLivingDrop((EntityLiving)entity);
        } catch (Throwable e) {
        }
    }
    if (droppedItem != null) {
        stat = new GuiAnimatedStat(null, entity.getName(), new ItemStack(droppedItem, 1, 0), 20, -20, 0x3000AA00, null, false);
    } else {
        stat = new GuiAnimatedStat(null, entity.getName(), "", 20, -20, 0x3000AA00, null, false);
    }
    stat.setMinDimensionsAndReset(0, 0);
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:20,代碼來源:RenderTarget.java

示例4: initStats

import net.minecraft.item.Item; //導入依賴的package包/類
private static void initStats()
{
    for (Item item : net.minecraftforge.fml.common.registry.GameData.getItemRegistry().typeSafeIterable())
    {
        if (item != null)
        {
            int i = Item.getIdFromItem(item);
            String s = getItemName(item);

            if (s != null)
            {
                OBJECT_USE_STATS[i] = (new StatCrafting("stat.useItem.", s, new TextComponentTranslation("stat.useItem", new Object[] {(new ItemStack(item)).getTextComponent()}), item)).registerStat();

                if (!(item instanceof ItemBlock))
                {
                    USE_ITEM_STATS.add((StatCrafting)OBJECT_USE_STATS[i]);
                }
            }
        }
    }

    replaceAllSimilarBlocks(OBJECT_USE_STATS, true);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:24,代碼來源:StatList.java

示例5: call

import net.minecraft.item.Item; //導入依賴的package包/類
@Override
public void call(String[] args) throws CmdException
{
	if(args.length == 0)
		throw new CmdSyntaxError();
	if(!WMinecraft.getPlayer().capabilities.isCreativeMode)
		throw new CmdError("Creative mode only.");
	ItemStack item = WMinecraft.getPlayer().inventory.getCurrentItem();
	if(item == null || Item.getIdFromItem(item.getItem()) != 387)
		throw new CmdError(
			"You are not holding a written book in your hand.");
	String author = args[0];
	for(int i = 1; i < args.length; i++)
		author += " " + args[i];
	item.setTagInfo("author", new NBTTagString(author));
}
 
開發者ID:Wurst-Imperium,項目名稱:Wurst-MC-1.12,代碼行數:17,代碼來源:AuthorCmd.java

示例6: dropBlockAsItemWithChance

import net.minecraft.item.Item; //導入依賴的package包/類
/**
 * Spawns this Block's drops into the World as EntityItems.
 */
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
    if (!worldIn.isRemote)
    {
        int i = this.quantityDroppedWithBonus(fortune, worldIn.rand);

        for (int j = 0; j < i; ++j)
        {
            if (worldIn.rand.nextFloat() <= chance)
            {
                Item item = this.getItemDropped(state, worldIn.rand, fortune);

                if (item != null)
                {
                    spawnAsEntity(worldIn, pos, new ItemStack(item, 1, this.damageDropped(state)));
                }
            }
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:24,代碼來源:Block.java

示例7: makeItemStack

import net.minecraft.item.Item; //導入依賴的package包/類
/**
 * Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
 * <p/>
 * Will return null if the item doesn't exist (because it's not from a loaded mod for example)
 * Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack}
 *
 * @param itemName  a registry name reference
 * @param meta      the meta
 * @param stackSize the stack size
 * @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
 * @return a new itemstack
 */
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString)
{
    if (itemName == null)
    {
        throw new IllegalArgumentException("The itemName cannot be null");
    }
    Item item = GameData.getItemRegistry().getObject(new ResourceLocation(itemName));
    if (item == null)
    {
        FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
        return null;
    }
    ItemStack is = new ItemStack(item, stackSize, meta);
    if (!Strings.isNullOrEmpty(nbtString))
    {
        NBTBase nbttag = null;
        try
        {
            nbttag = JsonToNBT.getTagFromJson(nbtString);
        } catch (NBTException e)
        {
            FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
            throw Throwables.propagate(e);
        }
        if (!(nbttag instanceof NBTTagCompound))
        {
            FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString);
            throw new RuntimeException("Invalid NBT JSON");
        }
        else
        {
            is.setTagCompound((NBTTagCompound)nbttag);
        }
    }
    return is;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:49,代碼來源:GameRegistry.java

示例8: updateItemUse

import net.minecraft.item.Item; //導入依賴的package包/類
/**
 * Plays sounds and makes particles for item in use state
 */
protected void updateItemUse(ItemStack stack, int eatingParticleCount)
{
    if (!stack.func_190926_b() && this.isHandActive())
    {
        if (stack.getItemUseAction() == EnumAction.DRINK)
        {
            this.playSound(SoundEvents.ENTITY_GENERIC_DRINK, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
        }

        if (stack.getItemUseAction() == EnumAction.EAT)
        {
            for (int i = 0; i < eatingParticleCount; ++i)
            {
                Vec3d vec3d = new Vec3d(((double)this.rand.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
                vec3d = vec3d.rotatePitch(-this.rotationPitch * 0.017453292F);
                vec3d = vec3d.rotateYaw(-this.rotationYaw * 0.017453292F);
                double d0 = (double)(-this.rand.nextFloat()) * 0.6D - 0.3D;
                Vec3d vec3d1 = new Vec3d(((double)this.rand.nextFloat() - 0.5D) * 0.3D, d0, 0.6D);
                vec3d1 = vec3d1.rotatePitch(-this.rotationPitch * 0.017453292F);
                vec3d1 = vec3d1.rotateYaw(-this.rotationYaw * 0.017453292F);
                vec3d1 = vec3d1.addVector(this.posX, this.posY + (double)this.getEyeHeight(), this.posZ);

                if (stack.getHasSubtypes())
                {
                    this.world.spawnParticle(EnumParticleTypes.ITEM_CRACK, vec3d1.xCoord, vec3d1.yCoord, vec3d1.zCoord, vec3d.xCoord, vec3d.yCoord + 0.05D, vec3d.zCoord, new int[] {Item.getIdFromItem(stack.getItem()), stack.getMetadata()});
                }
                else
                {
                    this.world.spawnParticle(EnumParticleTypes.ITEM_CRACK, vec3d1.xCoord, vec3d1.yCoord, vec3d1.zCoord, vec3d.xCoord, vec3d.yCoord + 0.05D, vec3d.zCoord, new int[] {Item.getIdFromItem(stack.getItem())});
                }
            }

            this.playSound(SoundEvents.ENTITY_GENERIC_EAT, 0.5F + 0.5F * (float)this.rand.nextInt(2), (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:40,代碼來源:EntityLivingBase.java

示例9: getSubBlocks

import net.minecraft.item.Item; //導入依賴的package包/類
/**
 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
 */
public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list)
{
    if (itemIn != Item.getItemFromBlock(Blocks.DOUBLE_STONE_SLAB))
    {
        for (BlockStoneSlab.EnumType blockstoneslab$enumtype : BlockStoneSlab.EnumType.values())
        {
            if (blockstoneslab$enumtype != BlockStoneSlab.EnumType.WOOD)
            {
                list.add(new ItemStack(itemIn, 1, blockstoneslab$enumtype.getMetadata()));
            }
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:17,代碼來源:BlockStoneSlab.java

示例10: registerToolModels

import net.minecraft.item.Item; //導入依賴的package包/類
public static void registerToolModels()
{
    List<Item> toolsList = Arrays.asList(ExPItems.knife, ExPItems.pickaxe, ExPItems.axe, ExPItems.shovel, ExPItems.hoe, ExPItems.sword, ExPItems.scythe, ExPItems.battleaxe, ExPItems.hammer, ExPItems.spear, ExPItems.watering_can, ExPItems.gardening_spade);
    toolsList.forEach(tool -> ModelLoader.setCustomMeshDefinition(tool, stack -> new ModelResourceLocation(new ResourceLocation(tool.getRegistryName().getResourceDomain(), "tools/" + tool.getRegistryName().getResourcePath()), "material=" + EnumToolStats.values()[stack.getMetadata()].getName())));
    for (int i = 0; i < EnumToolStats.values().length; ++i)
    {
        Integer lambdaCaptureInt = i;
        toolsList.forEach(tool -> ModelLoader.registerItemVariants(tool, new ModelResourceLocation(new ResourceLocation(tool.getRegistryName().getResourceDomain(), "tools/" + tool.getRegistryName().getResourcePath()), "material=" + EnumToolStats.values()[lambdaCaptureInt].getName())));
    }
}
 
開發者ID:V0idWa1k3r,項目名稱:ExPetrum,代碼行數:11,代碼來源:ClientRegistry.java

示例11: remap

import net.minecraft.item.Item; //導入依賴的package包/類
/**
 * Remap the missing item to the specified Item.
 *
 * Use this if you have renamed an Item.
 * Existing references using the old name will point to the new one.
 *
 * @param target Item to remap to.
 */
public void remap(Item target)
{
    if (type != GameRegistry.Type.ITEM) throw new IllegalArgumentException("Can't remap a block to an item.");
    if (target == null) throw new NullPointerException("remap target is null");
    if (GameData.getItemRegistry().getId(target) < 0) throw new IllegalArgumentException(String.format("The specified item %s hasn't been registered at startup.", target));

    action = Action.REMAP;
    this.target = target;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:18,代碼來源:FMLMissingMappingsEvent.java

示例12: doReaction

import net.minecraft.item.Item; //導入依賴的package包/類
public static ItemStack doReaction(ItemStack reagent, ItemStack potionIn)
{
    if (!potionIn.func_190926_b())
    {
        PotionType potiontype = PotionUtils.getPotionFromItem(potionIn);
        Item item = potionIn.getItem();
        int i = 0;

        for (int j = POTION_ITEM_CONVERSIONS.size(); i < j; ++i)
        {
            PotionHelper.MixPredicate<Item> mixpredicate = (PotionHelper.MixPredicate)POTION_ITEM_CONVERSIONS.get(i);

            if (mixpredicate.input == item && mixpredicate.reagent.apply(reagent))
            {
                return PotionUtils.addPotionToItemStack(new ItemStack((Item)mixpredicate.output), potiontype);
            }
        }

        i = 0;

        for (int k = POTION_TYPE_CONVERSIONS.size(); i < k; ++i)
        {
            PotionHelper.MixPredicate<PotionType> mixpredicate1 = (PotionHelper.MixPredicate)POTION_TYPE_CONVERSIONS.get(i);

            if (mixpredicate1.input == potiontype && mixpredicate1.reagent.apply(reagent))
            {
                return PotionUtils.addPotionToItemStack(new ItemStack(item), (PotionType)mixpredicate1.output);
            }
        }
    }

    return potionIn;
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:34,代碼來源:PotionHelper.java

示例13: getSubItems

import net.minecraft.item.Item; //導入依賴的package包/類
@Override
public void getSubItems(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> subItems) {
	for (int c = 0; c < subs.size(); c++) {
		ItemStack is = new ItemStack(this, 1, c);
		subItems.add(is);
	}
}
 
開發者ID:trigg,項目名稱:Firma,代碼行數:8,代碼來源:MetaItem.java

示例14: getSubBlocks

import net.minecraft.item.Item; //導入依賴的package包/類
/**
 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
 */
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
{
    for (BlockSandStone.EnumType blocksandstone$enumtype : BlockSandStone.EnumType.values())
    {
        list.add(new ItemStack(itemIn, 1, blocksandstone$enumtype.getMetadata()));
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:12,代碼來源:BlockSandStone.java

示例15: getSubBlocks

import net.minecraft.item.Item; //導入依賴的package包/類
/**
 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
 */
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
{
    for (int i = 0; i < 16; ++i)
    {
        list.add(new ItemStack(itemIn, 1, i));
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:11,代碼來源:BlockCarpet.java


注:本文中的net.minecraft.item.Item類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。