当前位置: 首页>>代码示例>>Java>>正文


Java Items.ENCHANTED_BOOK属性代码示例

本文整理汇总了Java中net.minecraft.init.Items.ENCHANTED_BOOK属性的典型用法代码示例。如果您正苦于以下问题:Java Items.ENCHANTED_BOOK属性的具体用法?Java Items.ENCHANTED_BOOK怎么用?Java Items.ENCHANTED_BOOK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在net.minecraft.init.Items的用法示例。


在下文中一共展示了Items.ENCHANTED_BOOK属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRecipeIngredients

private ItemStack[] getRecipeIngredients(ItemStackHandler inputStacks) {
    List<ItemStack> enchantedBooks = new ItemStackHandlerIterable(inputStacks)
                                                .stream()
                                                .filter(book -> book.getItem() == Items.ENCHANTED_BOOK)
                                                .collect(Collectors.toList());

    if (enchantedBooks.isEmpty()) return null;

    for (ItemStack inputStack : new ItemStackHandlerIterable(inputStacks)) {
        if ((inputStack.isItemEnchantable() || inputStack.isItemEnchanted()) && inputStack.getItem() != Items.ENCHANTED_BOOK) {
            for (ItemStack enchantedBook : enchantedBooks) {
                Map<Enchantment, Integer> bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
                for (Map.Entry<Enchantment, Integer> entry : bookMap.entrySet()) {
                    if (entry.getKey().canApply(inputStack)) {
                        return new ItemStack[]{ inputStack, enchantedBook};
                    }
                }
            }
        }
    }
    return null;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:22,代码来源:PressureChamberPressureEnchantHandler.java

示例2: craftRecipe

@Override
public NonNullList<ItemStack> craftRecipe(ItemStackHandler inputStacks) {
    ItemStack enchantedStack = getDisenchantableItem(inputStacks);
    getBook(inputStacks).shrink(1);
    
    // take a random enchantment off the enchanted item...
    Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedStack);
    List<Enchantment> l = new ArrayList<>(enchantments.keySet());
    Enchantment strippedEnchantment = l.get(new Random().nextInt(l.size()));
    int level = enchantments.get(strippedEnchantment);
    enchantments.remove(strippedEnchantment);
    EnchantmentHelper.setEnchantments(enchantments, enchantedStack);

    // ...and create an enchanted book with it
    ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
    EnchantmentHelper.setEnchantments(ImmutableMap.of(strippedEnchantment, level), enchantedBook);

    return NonNullList.from(ItemStack.EMPTY, enchantedBook);
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:19,代码来源:PressureChamberVacuumEnchantHandler.java

示例3: performWork

@Override
protected float performWork() {
    if (WorkUtils.isDisabled(this.getBlockType())) return 0;

    if (!hasBooks() || getItem().isEmpty()) return 0;
    ItemStack enchantedItem = getItem();
    ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
    if (ItemHandlerHelper.insertItem(outEnchanted, enchantedBook, true).isEmpty() && ItemHandlerHelper.insertItem(outItem, enchantedItem, true).isEmpty()) {
        NBTTagCompound base = (NBTTagCompound) enchantedItem.getEnchantmentTagList().get(0);
        ((ItemEnchantedBook) Items.ENCHANTED_BOOK).addEnchantment(enchantedBook, new EnchantmentData(Enchantment.getEnchantmentByID(base.getShort("id")), base.getShort("lvl")));
        enchantedItem.getEnchantmentTagList().removeTag(0);
        ItemHandlerHelper.insertItem(outEnchanted, enchantedBook, false);
        ItemHandlerHelper.insertItem(outItem, enchantedItem.copy(), false);
        inBook.getStackInSlot(0).setCount(inBook.getStackInSlot(0).getCount() - 1);
        enchantedItem.setCount(enchantedItem.getCount() - 1);
        return 500;
    }

    return 0;
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:20,代码来源:EnchantmentExtractorTile.java

示例4: matches

@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
   boolean hasSlingshot = false, hasBook = false;
   for (int i = inv.getSizeInventory(); --i >= 0; ) {
      ItemStack stack = inv.getStackInSlot(i);
      if (null != stack) {
         Item item = stack.getItem();
         if (item == ModItems.slingshot) {
            if (hasSlingshot)
               return false;
            hasSlingshot = true;
         } else if (item == Items.ENCHANTED_BOOK) {
            if (hasBook)
               return false;
            if (getBookLootingLevel(stack) <= 0)
               return false;
            hasBook = true;
         } else
            return false;
      }
   }

   return hasSlingshot && hasBook;
}
 
开发者ID:arucil,项目名称:mc-Slingshot,代码行数:24,代码来源:RecipeLooting.java

示例5: getEnchantments

public static Map<Enchantment, Integer> getEnchantments(ItemStack stack)
{
    Map<Enchantment, Integer> map = Maps.<Enchantment, Integer>newLinkedHashMap();
    NBTTagList nbttaglist = stack.getItem() == Items.ENCHANTED_BOOK ? Items.ENCHANTED_BOOK.getEnchantments(stack) : stack.getEnchantmentTagList();

    if (nbttaglist != null)
    {
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            Enchantment enchantment = Enchantment.getEnchantmentByID(nbttaglist.getCompoundTagAt(i).getShort("id"));
            int j = nbttaglist.getCompoundTagAt(i).getShort("lvl");
            map.put(enchantment, Integer.valueOf(j));
        }
    }

    return map;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:17,代码来源:EnchantmentHelper.java

示例6: getEnchantmentIdLevels

private static int[][] getEnchantmentIdLevels(ItemStack p_getEnchantmentIdLevels_0_)
{
    Item item = p_getEnchantmentIdLevels_0_.getItem();
    NBTTagList nbttaglist = item == Items.ENCHANTED_BOOK ? Items.ENCHANTED_BOOK.getEnchantments(p_getEnchantmentIdLevels_0_) : p_getEnchantmentIdLevels_0_.getEnchantmentTagList();

    if (nbttaglist != null && nbttaglist.tagCount() > 0)
    {
        int[][] aint = new int[nbttaglist.tagCount()][2];

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
            int j = nbttagcompound.getShort("id");
            int k = nbttagcompound.getShort("lvl");
            aint[i][0] = j;
            aint[i][1] = k;
        }

        return aint;
    }
    else
    {
        return EMPTY_INT2_ARRAY;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:25,代码来源:CustomItems.java

示例7: getAllEnchantedBooks

private void getAllEnchantedBooks(Enchantment enchantment, NonNullList<ItemStack> list) {
    for (int i = enchantment.getMinLevel(); i <= enchantment.getMaxLevel(); ++i) {
        ItemStack itemstack = new ItemStack(Items.ENCHANTED_BOOK);
        itemstack.addEnchantment(enchantment, i);
        list.add(itemstack);
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:7,代码来源:GuiSearcher.java

示例8: updateCooldownCap

public void updateCooldownCap() {
	int cap = this.worker.getMaxWork();
	if (this.world.getBlockState(pos).getValue(BlockBreaker.TYPE) == ChipTypes.BASIC)
		cap = VExConfig.machineCooldownBasic;
	else
		cap = VExConfig.machineCooldownAdvanced;
	if (this.handler.getStackInSlot(9).getItem() == Items.ENCHANTED_BOOK) {
		Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(this.handler.getStackInSlot(9));
		if (enchantments.containsKey(Enchantments.EFFICIENCY)) {
			cap -= Math.pow(enchantments.get(Enchantments.EFFICIENCY), 2) % cap;
		}
	}
	this.worker.setMaxCooldown(cap);
}
 
开发者ID:IvanSteklow,项目名称:VanillaExtras,代码行数:14,代码来源:TileEntityBlockBreaker.java

示例9: transferStackInSlot

@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
	ItemStack previous = ItemStack.EMPTY;
	Slot slot = (Slot) this.inventorySlots.get(fromSlot);

	if (slot != null && slot.getHasStack()) {
		ItemStack current = slot.getStack();
		previous = current.copy();

		if (fromSlot < this.handler.getSlots()) {
			// From the block breaker inventory to player's inventory
			if (!this.mergeItemStack(current, handler.getSlots(), handler.getSlots() + 36, true))
				return ItemStack.EMPTY;
		} else {
			// From the player's inventory to block breaker's inventory
			if (current.getItem() == Items.ENCHANTED_BOOK) {
				if (!this.mergeItemStack(current, 9, handler.getSlots(), false))
					return ItemStack.EMPTY;
			}
			if (!this.mergeItemStack(current, 0, handler.getSlots(), false))
				return ItemStack.EMPTY;
		}

		if (current.getCount() == 0)
			slot.putStack(ItemStack.EMPTY);
		else
			slot.onSlotChanged();

		if (current.getCount() == previous.getCount())
			return null;
		slot.onTake(playerIn, current);
	}
	return previous;
}
 
开发者ID:IvanSteklow,项目名称:VanillaExtras,代码行数:34,代码来源:ContainerBlockBreaker.java

示例10: getSellingStack

@Override
public ItemStack getSellingStack(ITradeList t)
{
	ListEnchantedBookForEmeralds trade = (ListEnchantedBookForEmeralds)t;
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK, 1, 0);
	return stack;
}
 
开发者ID:crazysnailboy,项目名称:VillagerTrades,代码行数:7,代码来源:TradeHandlers.java

示例11: setEnchantments

/**
 * Set the enchantments for the specified stack.
 */
public static void setEnchantments(Map<Enchantment, Integer> enchMap, ItemStack stack)
{
    NBTTagList nbttaglist = new NBTTagList();

    for (Entry<Enchantment, Integer> entry : enchMap.entrySet())
    {
        Enchantment enchantment = (Enchantment)entry.getKey();

        if (enchantment != null)
        {
            int i = ((Integer)entry.getValue()).intValue();
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setShort("id", (short)Enchantment.getEnchantmentID(enchantment));
            nbttagcompound.setShort("lvl", (short)i);
            nbttaglist.appendTag(nbttagcompound);

            if (stack.getItem() == Items.ENCHANTED_BOOK)
            {
                Items.ENCHANTED_BOOK.addEnchantment(stack, new EnchantmentData(enchantment, i));
            }
        }
    }

    if (nbttaglist.hasNoTags())
    {
        if (stack.hasTagCompound())
        {
            stack.getTagCompound().removeTag("ench");
        }
    }
    else if (stack.getItem() != Items.ENCHANTED_BOOK)
    {
        stack.setTagInfo("ench", nbttaglist);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:38,代码来源:EnchantmentHelper.java

示例12: breakBlock

@SuppressWarnings("deprecation")
public void breakBlock(EnumFacing facing) {
	BlockPos newPos = pos.offset(facing, 1);
	IBlockState state = this.world.getBlockState(newPos);
	Block block = state.getBlock();
	if (!block.isAir(state, this.world, newPos) && block.getBlockHardness(state, this.world, newPos) >= 0
			&& !(block instanceof BlockDynamicLiquid) && !(block instanceof BlockStaticLiquid)) {
		// Creates a fake player which will berak the block
		EntityPlayer player = new EntityPlayer(world, new GameProfile(null, "BlockBreaker")) {

			@Override
			public boolean isSpectator() {
				return true;
			}

			@Override
			public boolean isCreative() {
				return false;
			}
		};
		List<ItemStack> drops = new ArrayList<ItemStack>();
		boolean customDrops = false;
		if (this.handler.getStackInSlot(9).getItem() == Items.ENCHANTED_BOOK) {
			ItemStack enchantedBook = this.handler.getStackInSlot(9);
			Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedBook);
			if (enchantments.containsKey(Enchantments.FORTUNE)) {
				int fortune = enchantments.get(Enchantments.FORTUNE);
				drops.add(new ItemStack(block.getItemDropped(state, this.random, fortune),
						block.quantityDroppedWithBonus(fortune, this.random), block.damageDropped(state)));
				customDrops = true;
			}
			if (enchantments.containsKey(Enchantments.SILK_TOUCH)
					&& block.canSilkHarvest(world, newPos, state, player)) {
				// HARD FIX FOR LAPIS
				if (block == Blocks.LAPIS_ORE)
					drops.add(new ItemStack(block, 1));
				else
					drops.add(new ItemStack(block, 1, block.damageDropped(state)));
				customDrops = true;
			}
		}
		if (!customDrops)
			drops = block.getDrops(world, newPos, state, 0);
		for (ItemStack stack : drops) {
			Utils.addStackToInventory(this.handler, 9, stack, false);
		}
		if (!Utils.isInventoryFull(this.handler, 9)) {
			this.world.playEvent(2001, pos, Block.getStateId(state));
			this.world.playSound(null, pos, block.getSoundType(state, world, newPos, player).getBreakSound(),
					SoundCategory.BLOCKS, 1, 1);
			this.world.setBlockToAir(newPos);
			if (block == Blocks.ICE)
				this.world.setBlockState(newPos, Blocks.FLOWING_WATER.getDefaultState());
		}
	}
}
 
开发者ID:IvanSteklow,项目名称:VanillaExtras,代码行数:56,代码来源:TileEntityBlockBreaker.java

示例13: renderToolTip

protected void renderToolTip(ItemStack stack, int x, int y)
{
    if (selectedTabIndex == CreativeTabs.SEARCH.getTabIndex())
    {
        List<String> list = stack.getTooltip(this.mc.player, this.mc.gameSettings.advancedItemTooltips);
        CreativeTabs creativetabs = stack.getItem().getCreativeTab();

        if (creativetabs == null && stack.getItem() == Items.ENCHANTED_BOOK)
        {
            Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(stack);

            if (map.size() == 1)
            {
                Enchantment enchantment = (Enchantment)map.keySet().iterator().next();

                for (CreativeTabs creativetabs1 : CreativeTabs.CREATIVE_TAB_ARRAY)
                {
                    if (creativetabs1.hasRelevantEnchantmentType(enchantment.type))
                    {
                        creativetabs = creativetabs1;
                        break;
                    }
                }
            }
        }

        if (creativetabs != null)
        {
            list.add(1, "" + TextFormatting.BOLD + TextFormatting.BLUE + I18n.format(creativetabs.getTranslatedTabLabel(), new Object[0]));
        }

        for (int i = 0; i < list.size(); ++i)
        {
            if (i == 0)
            {
                list.set(i, stack.getRarity().rarityColor + (String)list.get(i));
            }
            else
            {
                list.set(i, TextFormatting.GRAY + (String)list.get(i));
            }
        }

        this.drawHoveringText(list, x, y);
    }
    else
    {
        super.renderToolTip(stack, x, y);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:50,代码来源:GuiContainerCreative.java

示例14: renderToolTip

protected void renderToolTip(ItemStack stack, int x, int y)
{
    if (selectedTabIndex == CreativeTabs.SEARCH.getTabIndex())
    {
        List<String> list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
        CreativeTabs creativetabs = stack.getItem().getCreativeTab();

        if (creativetabs == null && stack.getItem() == Items.ENCHANTED_BOOK)
        {
            Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(stack);

            if (map.size() == 1)
            {
                Enchantment enchantment = (Enchantment)map.keySet().iterator().next();

                for (CreativeTabs creativetabs1 : CreativeTabs.CREATIVE_TAB_ARRAY)
                {
                    if (creativetabs1.hasRelevantEnchantmentType(enchantment.type))
                    {
                        creativetabs = creativetabs1;
                        break;
                    }
                }
            }
        }

        if (creativetabs != null)
        {
            list.add(1, "" + TextFormatting.BOLD + TextFormatting.BLUE + I18n.format(creativetabs.getTranslatedTabLabel(), new Object[0]));
        }

        for (int i = 0; i < list.size(); ++i)
        {
            if (i == 0)
            {
                list.set(i, stack.getRarity().rarityColor + (String)list.get(i));
            }
            else
            {
                list.set(i, TextFormatting.GRAY + (String)list.get(i));
            }
        }

        net.minecraftforge.fml.client.config.GuiUtils.preItemToolTip(stack);
        this.drawHoveringText(list, x, y);
        net.minecraftforge.fml.client.config.GuiUtils.postItemToolTip();
    }
    else
    {
        super.renderToolTip(stack, x, y);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:52,代码来源:GuiContainerCreative.java


注:本文中的net.minecraft.init.Items.ENCHANTED_BOOK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。