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


Java Enchantment类代码示例

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


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

示例1: getSearchEntries

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * Lazy cache.
 * @return
 */
private Stream<SearchEntry> getSearchEntries(){
    if(cachedSearchEntries == null){
        NonNullList<ItemStack> itemList = NonNullList.create();

        for(Item item : Item.REGISTRY){
            if (item != null && item.getCreativeTab() != null) {
                item.getSubItems(item.getCreativeTab(), itemList);
            }
        }

        for (Enchantment enchantment : Enchantment.REGISTRY) {
            if (enchantment != null && enchantment.type != null) {
                getAllEnchantedBooks(enchantment, itemList);
            }
        }

        cachedSearchEntries = itemList.stream().map(SearchEntry::new).collect(Collectors.toList());
    }
    return cachedSearchEntries.stream();
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:25,代码来源:GuiSearcher.java

示例2: getRecipeIngredients

import net.minecraft.enchantment.Enchantment; //导入依赖的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

示例3: craftRecipe

import net.minecraft.enchantment.Enchantment; //导入依赖的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

示例4: performWork

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

示例5: serialize

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
public void serialize(JsonObject object, EnchantRandomly functionClazz, JsonSerializationContext serializationContext)
{
    if (functionClazz.enchantments != null && !functionClazz.enchantments.isEmpty())
    {
        JsonArray jsonarray = new JsonArray();

        for (Enchantment enchantment : functionClazz.enchantments)
        {
            ResourceLocation resourcelocation = (ResourceLocation)Enchantment.REGISTRY.getNameForObject(enchantment);

            if (resourcelocation == null)
            {
                throw new IllegalArgumentException("Don\'t know how to serialize enchantment " + enchantment);
            }

            jsonarray.add(new JsonPrimitive(resourcelocation.toString()));
        }

        object.add("enchantments", jsonarray);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:22,代码来源:EnchantRandomly.java

示例6: attackEntityWithRangedAttack

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * Attack the specified entity using a ranged attack.
 */
public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_)
{
    EntityArrow entityarrow = new EntityArrow(this.worldObj, this, p_82196_1_, 1.6F, (float)(14 - this.worldObj.getDifficulty().getDifficultyId() * 4));
    int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
    int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
    entityarrow.setDamage((double)(p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.getDifficulty().getDifficultyId() * 0.11F));

    if (i > 0)
    {
        entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);
    }

    if (j > 0)
    {
        entityarrow.setKnockbackStrength(j);
    }

    if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0 || this.getSkeletonType() == 1)
    {
        entityarrow.setFire(100);
    }

    this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.worldObj.spawnEntityInWorld(entityarrow);
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:29,代码来源:EntitySkeleton.java

示例7: addInformation

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * allows items to add custom lines of information to the mouseover description
 */
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
    super.addInformation(stack, playerIn, tooltip, advanced);
    NBTTagList nbttaglist = this.getEnchantments(stack);

    if (nbttaglist != null)
    {
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            int j = nbttaglist.getCompoundTagAt(i).getShort("id");
            int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");

            if (Enchantment.getEnchantmentById(j) != null)
            {
                tooltip.add(Enchantment.getEnchantmentById(j).getTranslatedName(k));
            }
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:23,代码来源:ItemEnchantedBook.java

示例8: register

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * Registers blocks, items, stats, etc.
 */
public static void register()
{
    if (!alreadyRegistered)
    {
        alreadyRegistered = true;

        if (LOGGER.isDebugEnabled())
        {
            redirectOutputToLog();
        }

        SoundEvent.registerSounds();
        Block.registerBlocks();
        BlockFire.init();
        Potion.registerPotions();
        Enchantment.registerEnchantments();
        Item.registerItems();
        PotionType.registerPotionTypes();
        PotionHelper.init();
        StatList.init();
        Biome.registerBiomes();
        registerDispenserBehaviors();
        net.minecraftforge.fml.common.registry.GameData.vanillaSnapshot();
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:29,代码来源:Bootstrap.java

示例9: addEnchantmentBooksToList

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * Adds the enchantment books from the supplied EnumEnchantmentType to the given list.
 */
public void addEnchantmentBooksToList(List<ItemStack> itemList, EnumEnchantmentType... enchantmentType)
{
    for (Enchantment enchantment : Enchantment.enchantmentsBookList)
    {
        if (enchantment != null && enchantment.type != null)
        {
            boolean flag = false;

            for (int i = 0; i < enchantmentType.length && !flag; ++i)
            {
                if (enchantment.type == enchantmentType[i])
                {
                    flag = true;
                }
            }

            if (flag)
            {
                itemList.add(Items.enchanted_book.getEnchantedItemStack(new EnchantmentData(enchantment, enchantment.getMaxLevel())));
            }
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:27,代码来源:CreativeTabs.java

示例10: improveEnchants

import net.minecraft.enchantment.Enchantment; //导入依赖的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

示例11: modifyMerchantRecipeList

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * Affects the given MerchantRecipeList to possibly add or remove MerchantRecipes.
 */
public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
{
    Enchantment enchantment = (Enchantment)Enchantment.REGISTRY.getRandomObject(random);
    int i = MathHelper.getRandomIntegerInRange(random, enchantment.getMinLevel(), enchantment.getMaxLevel());
    ItemStack itemstack = Items.ENCHANTED_BOOK.getEnchantedItemStack(new EnchantmentData(enchantment, i));
    int j = 2 + random.nextInt(5 + i * 10) + 3 * i;

    if (enchantment.isTreasureEnchantment())
    {
        j *= 2;
    }

    if (j > 64)
    {
        j = 64;
    }

    recipeList.add(new MerchantRecipe(new ItemStack(Items.BOOK), new ItemStack(Items.EMERALD, j), itemstack));
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:23,代码来源:EntityVillager.java

示例12: addEnchantment

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * Adds an enchantment with a desired level on the ItemStack.
 */
public void addEnchantment(Enchantment ench, int level)
{
    if (this.stackTagCompound == null)
    {
        this.setTagCompound(new NBTTagCompound());
    }

    if (!this.stackTagCompound.hasKey("ench", 9))
    {
        this.stackTagCompound.setTag("ench", new NBTTagList());
    }

    NBTTagList nbttaglist = this.stackTagCompound.getTagList("ench", 10);
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    nbttagcompound.setShort("id", (short)ench.effectId);
    nbttagcompound.setShort("lvl", (short)((byte)level));
    nbttaglist.appendTag(nbttagcompound);
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:22,代码来源:ItemStack.java

示例13: addEnchantment

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * Adds an enchantment with a desired level on the ItemStack.
 */
public void addEnchantment(Enchantment ench, int level)
{
    if (this.stackTagCompound == null)
    {
        this.setTagCompound(new NBTTagCompound());
    }

    if (!this.stackTagCompound.hasKey("ench", 9))
    {
        this.stackTagCompound.setTag("ench", new NBTTagList());
    }

    NBTTagList nbttaglist = this.stackTagCompound.getTagList("ench", 10);
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    nbttagcompound.setShort("id", (short)Enchantment.getEnchantmentID(ench));
    nbttagcompound.setShort("lvl", (short)((byte)level));
    nbttaglist.appendTag(nbttagcompound);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:22,代码来源:ItemStack.java

示例14: deserialize

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
public EnchantRandomly deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn)
{
    List<Enchantment> list = null;

    if (object.has("enchantments"))
    {
        list = Lists.<Enchantment>newArrayList();

        for (JsonElement jsonelement : JsonUtils.getJsonArray(object, "enchantments"))
        {
            String s = JsonUtils.getString(jsonelement, "enchantment");
            Enchantment enchantment = (Enchantment)Enchantment.REGISTRY.getObject(new ResourceLocation(s));

            if (enchantment == null)
            {
                throw new JsonSyntaxException("Unknown enchantment \'" + s + "\'");
            }

            list.add(enchantment);
        }
    }

    return new EnchantRandomly(conditionsIn, list);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:25,代码来源:EnchantRandomly.java

示例15: addEnchantmentBooksToList

import net.minecraft.enchantment.Enchantment; //导入依赖的package包/类
/**
 * Adds the enchantment books from the supplied EnumEnchantmentType to the given list.
 */
@SideOnly(Side.CLIENT)
public void addEnchantmentBooksToList(List<ItemStack> itemList, EnumEnchantmentType... enchantmentType)
{
    for (Enchantment enchantment : Enchantment.REGISTRY)
    {
        if (enchantment != null && enchantment.type != null)
        {
            boolean flag = false;

            for (int i = 0; i < enchantmentType.length && !flag; ++i)
            {
                if (enchantment.type == enchantmentType[i])
                {
                    flag = true;
                }
            }

            if (flag)
            {
                itemList.add(Items.ENCHANTED_BOOK.getEnchantedItemStack(new EnchantmentData(enchantment, enchantment.getMaxLevel())));
            }
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:28,代码来源:CreativeTabs.java


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