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


Java EnchantmentHelper.getEnchantments方法代码示例

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


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

示例1: getRecipeIngredients

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
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,代码行数:23,代码来源:PressureChamberPressureEnchantHandler.java

示例2: craftRecipe

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
@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,代码行数:20,代码来源:PressureChamberVacuumEnchantHandler.java

示例3: improveEnchants

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
private static boolean improveEnchants(ItemStack item) {
	boolean improved = false;
	Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(item);

	if (enchantments.isEmpty()) {
		return false;
	}

	for (Entry<Enchantment, Integer> enchant : enchantments.entrySet()) {
		if (shouldImproveEnchantment(rand, enchant.getKey(), enchant.getValue())) {
			enchantments.put(enchant.getKey(), enchant.getValue() + 1);
			improved = true;
		}
	}

	if (improved) {
		EnchantmentHelper.setEnchantments(enchantments, item);
	}

	return improved;
}
 
开发者ID:ToroCraft,项目名称:NemesisSystem,代码行数:22,代码来源:NemesisUtil.java

示例4: getUpgradableStack

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
/** Gets an upgradeable stack */
public @Nonnull ItemStack getUpgradableStack(@Nonnull List<ItemStack> s) {
	if(ACUtils.doesItemStackListContain(s, upgrade, true)) {
		ItemStack toUpgrade = s.get(0);
		if(enchant.canApply(toUpgrade) && toUpgrade.getItem() instanceof ItemSword) {
			Map<Enchantment, Integer> activeEnchs = EnchantmentHelper.getEnchantments(toUpgrade);
			for(Enchantment i : activeEnchs.keySet()) {
				if(i == enchant) {
					int level = activeEnchs.get(i);
					if(level >= maxLevel) {
						return ItemStack.EMPTY;
					}
				}
			}
			return toUpgrade.copy();
		}
	}
	return ItemStack.EMPTY;
}
 
开发者ID:sblectric,项目名称:AdvancedCombat,代码行数:20,代码来源:RecipeEnchantmentUpgrade.java

示例5: getUpgradableStack

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
/** Gets an upgradeable stack */
@Override
public @Nonnull ItemStack getUpgradableStack(List<ItemStack> s) {
	if(ACUtils.doesItemStackListContain(s, upgrade, true)) {
		ItemStack toUpgrade = s.get(0);
		if(enchant.canApply(toUpgrade)) { // no sword needed now!
			Map<Enchantment, Integer> activeEnchs = EnchantmentHelper.getEnchantments(toUpgrade);
			for(Enchantment i : activeEnchs.keySet()) {
				if(i == enchant) {
					int level = activeEnchs.get(i);
					if(level >= maxLevel) {
						return ItemStack.EMPTY;
					}
				}
			}
			return toUpgrade.copy();
		}
	}
	return ItemStack.EMPTY;
}
 
开发者ID:sblectric,项目名称:AdvancedCombat,代码行数:21,代码来源:RecipeFlexibleUpgrade.java

示例6: craftRecipe

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
@Override
public NonNullList<ItemStack> craftRecipe(ItemStackHandler inputStacks) {
    ItemStack[] recipeIngredients = getRecipeIngredients(inputStacks);
    ItemStack enchantedTool = recipeIngredients[0];
    ItemStack enchantedBook = recipeIngredients[1];
    
    Map<Enchantment, Integer> bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
    bookMap.forEach((enchant, lvl) -> enchantedTool.addEnchantment(enchant, lvl));
    
    enchantedBook.shrink(1);
    return NonNullList.from(ItemStack.EMPTY, new ItemStack(Items.BOOK));
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:13,代码来源:PressureChamberPressureEnchantHandler.java

示例7: performWork

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
@Override
protected float performWork() {
    if (WorkUtils.isDisabled(this.getBlockType())) return 0;
    if (!canWork()) return 0;
    int xp = (int) (getLevels() * 100);
    if (experienceTank.getFluidAmount() >= xp && ItemHandlerHelper.insertItem(outEnchantedItem, inItem.getStackInSlot(0), true).isEmpty()) {
        Map<Enchantment, Integer> mapFirst = EnchantmentHelper.getEnchantments(inEnchantedBook.getStackInSlot(0));
        Map<Enchantment, Integer> mapSecond = EnchantmentHelper.getEnchantments(inItem.getStackInSlot(0));
        for (Enchantment enchantmentFirst : mapFirst.keySet()) {
            if (enchantmentFirst != null) {
                if (mapSecond.containsKey(enchantmentFirst) && mapFirst.get(enchantmentFirst) == mapSecond.get(enchantmentFirst) && mapFirst.get(enchantmentFirst) >= enchantmentFirst.getMaxLevel())
                    return 0;
                int value = mapSecond.containsKey(enchantmentFirst) && mapFirst.get(enchantmentFirst) == mapSecond.get(enchantmentFirst) ? Math.min(mapFirst.get(enchantmentFirst) + 1, enchantmentFirst.getMaxLevel()) : mapFirst.get(enchantmentFirst);
                if (mapSecond.replace(enchantmentFirst, value) == null) {
                    mapSecond.put(enchantmentFirst, value);
                }
            }
        }
        ItemStack stack = inItem.getStackInSlot(0).copy();
        EnchantmentHelper.setEnchantments(mapSecond, stack);
        ItemHandlerHelper.insertItem(outEnchantedItem, stack, false);
        inItem.getStackInSlot(0).setCount(0);
        inEnchantedBook.getStackInSlot(0).setCount(0);
        experienceTank.drain(xp, true);
        return 500;
    }
    return 0;
}
 
开发者ID:Buuz135,项目名称:Industrial-Foregoing,代码行数:29,代码来源:EnchantmentAplicatorTile.java

示例8: updateCooldownCap

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
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,代码行数:15,代码来源:TileEntityBlockBreaker.java

示例9: renderToolTip

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
protected void renderToolTip(ItemStack stack, int x, int y)
{
    if (selectedTabIndex == CreativeTabs.tabAllSearch.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<Integer, Integer> map = EnchantmentHelper.getEnchantments(stack);

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

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

        if (creativetabs != null)
        {
            list.add(1, "" + EnumChatFormatting.BOLD + EnumChatFormatting.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, EnumChatFormatting.GRAY + (String)list.get(i));
            }
        }

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

示例10: breakBlock

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
@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,代码行数:57,代码来源:TileEntityBlockBreaker.java

示例11: renderToolTip

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
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,代码行数:51,代码来源:GuiContainerCreative.java

示例12: renderToolTip

import net.minecraft.enchantment.EnchantmentHelper; //导入方法依赖的package包/类
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,代码行数:53,代码来源:GuiContainerCreative.java


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