• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Enchantment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: deserializeEnchantments

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
private void deserializeEnchantments(DataView dataView, DataQuery query, Key<ListValue<Enchantment>> key,
        SimpleValueContainer valueContainer) {
    dataView.getViewList(query).ifPresent(views -> {
        if (!views.isEmpty()) {
            final List<Enchantment> enchantments = new ArrayList<>();
            views.forEach(view -> {
                final Optional<EnchantmentType> enchantmentType = EnchantmentTypeRegistryModule.get()
                        .getByInternalId(view.getInt(ENCHANTMENT_ID).get());
                if (enchantmentType.isPresent()) {
                    final int level = view.getInt(ENCHANTMENT_LEVEL).get();
                    enchantments.add(Enchantment.of(enchantmentType.get(), level));
                } else {
                    Lantern.getLogger().warn("Attempted to deserialize a enchantment with unknown id: {}", view.getInt(ENCHANTMENT_ID).get());
                }
            });
            valueContainer.set(key, enchantments);
        }
    });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:20,代码来源:ItemStackStore.java


示例2: getInvValue

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
@Override
public long getInvValue(Iterable<Inventory> inv){
	long value = 0;
	for (Inventory item:inv){
		if (!item.peek().isPresent()){
			continue;
		}
		ItemStack stack = item.peek().get();
		value += ((RedProtect.get().cfgs.getBlockCost(stack.getType().getId()) * stack.getQuantity()));
		if (stack.get(Keys.ITEM_ENCHANTMENTS).isPresent()){
			for (Enchantment enchant:stack.get(Keys.ITEM_ENCHANTMENTS).get()){
				value += ((RedProtect.get().cfgs.getEnchantCost(enchant.getType().getId()) * enchant.getLevel()));
			}
		}
	}
	return value;
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:18,代码来源:RPVHelper7.java


示例3: registerRecipe

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
private void registerRecipe()
{
    ItemStack axe = ItemStack.of(DIAMOND_AXE, 1);
    axe.offer(Keys.ITEM_ENCHANTMENTS, singletonList(Enchantment.builder().type(EnchantmentTypes.PUNCH).level(5).build()));
    axe.offer(Keys.DISPLAY_NAME, Text.of(GOLD, "Heavy Diamond Axe"));
    axe.offer(Keys.ITEM_LORE, singletonList(Text.of(YELLOW, "Chop Chop!")));
    axe.offer(Keys.HIDE_ENCHANTMENTS, true);

    this.recipe = CraftingRecipe.shapedBuilder()
            .aisle("aa", "as", " s")
            .where('a', Ingredient.of(DIAMOND_AXE))
            .where('s', Ingredient.of(LOG, LOG2))
            .result(axe)
            .build("chopchop", plugin);
    Sponge.getRegistry().getCraftingRecipeRegistry().register(recipe);
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:17,代码来源:Chopchop.java


示例4: hasEnchantment

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
public static boolean hasEnchantment(ItemStackSnapshot item, EnchantmentType ench)
{
    // TODO Sponge 4.0 will have a check for this?
    Optional<List<Enchantment>> enchs = item.get(Keys.ITEM_ENCHANTMENTS);
    if (enchs.isPresent())
    {
        for (Enchantment e : enchs.get())
        {
            if (e.getType().equals(ench))
            {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:17,代码来源:Spawner.java


示例5: getEnchantmentMultiplier

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
public static double getEnchantmentMultiplier(ItemStack item, double factor, double base)
{
    double enchantmentLevel = 0;
    Optional<List<Enchantment>> enchs = item.get(Keys.ITEM_ENCHANTMENTS);
    if (enchs.isPresent() && !enchs.get().isEmpty())
    {
        for (Enchantment enchantment : enchs.get())
        {
            enchantmentLevel += enchantment.getLevel();
        }
    }

    if (enchantmentLevel > 0)
    {
        double enchantmentMultiplier = factor * Math.pow(base, enchantmentLevel);

        enchantmentMultiplier = enchantmentMultiplier / 100.0 + 1.0;

        return enchantmentMultiplier;
    }
    else
    {
        return 1.0;
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:26,代码来源:RepairBlock.java


示例6: parseEnchantment

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
public static Enchantment parseEnchantment(ConfigurationNode node) {
    ConfigurationNode enchantment_node = node.getNode("ENCHANTMENT");
    ConfigurationNode level_node = node.getNode("LEVEL");
    if (enchantment_node.isVirtual()) {
        throw new RuntimeException("ENCHANTMENT node does not exist!");
    }
    try {
        EnchantmentType type = enchantment_node.getValue(TypeToken.of(EnchantmentType.class));
        int level = level_node.getInt(1);
        return Enchantment.of(type, level);
    } catch (Exception e) {
        throw new RuntimeException("Exception parsing enchantment!", e);
    }
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:15,代码来源:Utils.java


示例7: getEnchantments

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
@Override
public StringBuilder getEnchantments(StringBuilder str, ItemStack item) {
    for (Enchantment enchant:item.get(Keys.ITEM_ENCHANTMENTS).get()){
        str.append("\n "+enchant.getType().getTranslation().get()+": "+enchant.getLevel());
    }
    return str;
}
 
开发者ID:FabioZumbi12,项目名称:UltimateChat,代码行数:8,代码来源:UCVHelper78.java


示例8: from

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
@Override
public Enchantment.Builder from(final Enchantment value) {
    checkNotNull(value, "The enchantment to create a builder from cannot be null!");
    this.enchantmentType = value.getType();
    this.level = value.getLevel();
    return this;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:8,代码来源:LanternEnchantmentBuilder.java


示例9: buildContent

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
@Override
protected Optional<Enchantment> buildContent(DataView container) throws InvalidDataException {
    checkNotNull(container, "The data view cannot be null!");
    if (!container.contains(Queries.ENCHANTMENT_ID, Queries.LEVEL)) {
        return Optional.empty();
    }
    final Optional<EnchantmentType> enchantmentType = container.getCatalogType(Queries.ENCHANTMENT_ID, EnchantmentType.class);
    final int level = container.getInt(Queries.LEVEL).get();
    return enchantmentType.map(t -> Enchantment.builder().type(t).level(level).build());
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:LanternEnchantmentBuilder.java


示例10: serializeEnchantments

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
private void serializeEnchantments(DataView dataView, DataQuery query, List<Enchantment> enchantments) {
    if (enchantments.isEmpty()) {
        return;
    }
    final List<DataView> dataViews = new ArrayList<>();
    for (Enchantment enchantment : enchantments) {
        final DataView enchantmentView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
        enchantmentView.set(ENCHANTMENT_ID, (short) ((LanternEnchantmentType) enchantment.getType()).getInternalId());
        enchantmentView.set(ENCHANTMENT_LEVEL, (short) enchantment.getLevel());
        dataViews.add(enchantmentView);
    }
    dataView.set(query, dataViews);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:14,代码来源:ItemStackStore.java


示例11: setup

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
public void setup(PluginContainer plugin, ItemductConfig config)
{
    if (!this.init)
    {
        DataRegistration.<DuctData, ImmutableDuctData>builder()
                .dataClass(DuctData.class).immutableClass(ImmutableDuctData.class)
                .builder(new DuctDataBuilder()).manipulatorId("duct")
                .dataName("CubeEngine ItemDuct Data")
                .buildAndRegister(plugin);

        DuctData.FILTERS.getQuery();

        Ingredient hopper = Ingredient.of(ItemTypes.HOPPER);
        activatorItem = ItemStack.of(ItemTypes.HOPPER, 1);
        activatorItem.offer(Keys.ITEM_ENCHANTMENTS, singletonList(Enchantment.builder().type(EnchantmentTypes.LOOTING).level(1).build()));
        activatorItem.offer(Keys.DISPLAY_NAME, Text.of(TextColors.GOLD, "ItemDuct Activator"));
        activatorItem.offer(Keys.HIDE_ENCHANTMENTS, true);
        Sponge.getRegistry().getCraftingRecipeRegistry().register(
                CraftingRecipe.shapedBuilder().rows()
                        .row(hopper, hopper, hopper)
                        .row(hopper, Ingredient.of(ItemTypes.DIAMOND), hopper)
                        .row(hopper, hopper, hopper)
                        .result(activatorItem).build("ItemDuctActivator", plugin));
    }

    this.reload(config);

    this.init = true;
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:30,代码来源:ItemDuctManager.java


示例12: isActivator

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
private static boolean isActivator(ItemStack item)
{
    if (ItemTypes.HOPPER.equals(item.getType()))
    {
        Enchantment ench = Enchantment.builder().type(EnchantmentTypes.LOOTING).level(1).build();
        return item.get(Keys.ITEM_ENCHANTMENTS).orElse(Collections.emptyList()).contains(ench);
    }
    return false;
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:10,代码来源:ItemDuctListener.java


示例13: registerRecipe

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
private void registerRecipe() {
    boat = ItemStack.builder().itemType(ItemTypes.BOAT).quantity(1).build();
    boat.offer(Keys.ITEM_ENCHANTMENTS, singletonList(Enchantment.builder().type(EnchantmentTypes.UNBREAKING).level(1).build()));
    boat.offer(Keys.DISPLAY_NAME, Text.of(TextColors.GOLD, "Sturdy Boat"));
    boat.offer(Keys.ITEM_LORE, Arrays.asList(Text.of(TextColors.YELLOW, "Can take a lot!")));

    ItemStack log = ItemStack.of(ItemTypes.LOG, 1);

    /*
    ShapedRecipe recipe = Sponge.getRegistry().createBuilder(ShapedRecipe.Builder.class)
        .width(3).height(2)
        .row(0, log, null, log)
        .row(1, log, log, log)
    // TODO SpongePR#1098 .aisle("l l", "lll")
    // TODO SpongePR#1098 .where('l', log)
        .addResult(boat)
        .build();



    Sponge.getRegistry().getRecipeRegistry().register(recipe);
    */

    HashMap<Character, ItemStack> map = new HashMap<>();
    map.put('l', log);
    // TODO wait for SpongeAPI Object recipe = RecipeHack.addRecipe(boat.copy(), new String[]{"l l", "lll"}, map);
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:28,代码来源:Unbreakableboat.java


示例14: onEnable

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
@Listener
public void onEnable(GamePreInitializationEvent event)
{
    this.eggPerms = pm.register(Spawner.class, "egg", "", null);
    this.initPerm(CREEPER, SKELETON, SPIDER, ZOMBIE, SLIME, GHAST, PIG_ZOMBIE, ENDERMAN,
                  CAVE_SPIDER, SILVERFISH, BLAZE, MAGMA_CUBE, WITCH, BAT, PIG, SHEEP, COW,
                  CHICKEN, SQUID, WOLF, MUSHROOM_COW, OCELOT, HORSE, VILLAGER);

    this.spawnerItem = ItemStack.of(ItemTypes.MOB_SPAWNER, 1);
    spawnerItem.offer(Keys.ITEM_ENCHANTMENTS, singletonList(Enchantment.builder().type(LURE).level(1).build()));
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:12,代码来源:Spawner.java


示例15: onBlockBreak

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
@Listener(order = POST)
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player)
{
    if (event.getTransactions().size() != 1)
    {
        return;
    }
    Optional<ItemStackSnapshot> inHand = event.getContext().get(EventContextKeys.USED_ITEM);
    if (inHand.isPresent() &&
        hasEnchantment(inHand.get(), SILK_TOUCH) &&
        breaks(event, MOB_SPAWNER))
    {
        ItemStack clone = spawnerItem.copy();
        clone.offer(Keys.ITEM_ENCHANTMENTS, singletonList(Enchantment.builder().type(LURE).level(1).build()));
        clone.offer(Keys.DISPLAY_NAME, i18n.translate(player, NONE, "Inactive Monster Spawner"));

        Transaction<BlockSnapshot> trans = event.getTransactions().get(0);
        brokenSpawners.add(trans.getFinal().getLocation().get());

        Entity item = player.getWorld().createEntity(ITEM, player.getLocation().getPosition());
        item.offer(Keys.REPRESENTED_ITEM, clone.createSnapshot());
        Sponge.getCauseStackManager().pushCause(player);

        player.getWorld().spawnEntity(item); // TODO instead drop naturally at blockpos
        i18n.send(player, POSITIVE, "Dropped inactive Monster Spawner!");
        // TODO cancel exp drops
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:29,代码来源:Spawner.java


示例16: parseItem

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
public static ItemStack parseItem(ConfigurationNode node) {
    try {
        ConfigurationNode item_type_node = node.getNode("ITEM_TYPE");
        ConfigurationNode quantity_node = node.getNode("QUANTITY");
        ConfigurationNode sub_id_node = node.getNode("SUB_ID");
        ConfigurationNode nbt_node = node.getNode("NBT");
        ConfigurationNode durability_node = node.getNode("DURABILITY");
        ConfigurationNode display_name_node = node.getNode("DISPLAY_NAME");
        ConfigurationNode lore_node = node.getNode("LORE");
        ConfigurationNode enchantments_node = node.getNode("ENCHANTMENTS");
        ConfigurationNode hide_enchantments_node = node.getNode("HIDE_ENCHANTMENTS");
        if (item_type_node.isVirtual()) {
            throw new RuntimeException("ITEM_TYPE node does not exist!");
        }
        //Mega-shit-code start
        ConfigurationNode temp_node = node.getNode("TEMP_SPONGE_ITEM_STACK_NODE");
        temp_node.getNode("ItemType").setValue(item_type_node.getString());
        temp_node.getNode("UnsafeDamage").setValue(sub_id_node.getInt(0));
        temp_node.getNode("Count").setValue(quantity_node.getInt(1));
        ItemStack item = temp_node.getValue(TypeToken.of(ItemStack.class));
        temp_node.setValue(null);
        //Mega-shit-code end; Another not good code start
        if (!nbt_node.isVirtual()) {
            LinkedHashMap nbt_map = (LinkedHashMap) nbt_node.getValue();
            if (item.toContainer().get(DataQuery.of("UnsafeData")).isPresent()) {
                Map unsafe_data_map = item.toContainer().getMap(DataQuery.of("UnsafeData")).get();
                nbt_map.putAll(unsafe_data_map);
            }
            DataContainer container = item.toContainer().set(DataQuery.of("UnsafeData"), nbt_map);
            item = ItemStack.builder().fromContainer(container).build();
        }
        //Another not good code end
        if (!durability_node.isVirtual()) {
            int durability = durability_node.getInt();
            item.offer(Keys.ITEM_DURABILITY, durability);
        }
        if (!display_name_node.isVirtual()) {
            Text display_name = TextSerializers.FORMATTING_CODE.deserialize(display_name_node.getString());
            item.offer(Keys.DISPLAY_NAME, display_name);
        }
        if (!lore_node.isVirtual()) {
            List<Text> lore = lore_node.getList(TypeToken.of(String.class)).stream().
                    map(TextSerializers.FORMATTING_CODE::deserialize).
                    collect(Collectors.toList());
            item.offer(Keys.ITEM_LORE, lore);
        }
        if (!enchantments_node.isVirtual()) {
            List<Enchantment> item_enchantments = new ArrayList<Enchantment>();
            for (ConfigurationNode enchantment_node : enchantments_node.getChildrenList()) {
                item_enchantments.add(parseEnchantment(enchantment_node));
            }
            item.offer(Keys.ITEM_ENCHANTMENTS, item_enchantments);
        }
        if (!hide_enchantments_node.isVirtual()) {
            item.offer(Keys.HIDE_ENCHANTMENTS, hide_enchantments_node.getBoolean());
        }
        return item;
    } catch (Exception e) {
        throw new RuntimeException("Exception parsing item!", e);
    }
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:62,代码来源:Utils.java


示例17: EnchantmentView

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
public EnchantmentView(Enchantment value) {
    super(value);

    this.enchantment = value.getType();
    this.level = value.getLevel();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:7,代码来源:EnchantmentView.java


示例18: execute

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!(src instanceof Player)) {
        src.sendMessage(Text.of(TextColors.RED, "Player only!"));
        return CommandResult.success();
    }

    Player player = (Player) src;

    Optional<ItemStack> itemStackOpt = player.getItemInHand(HandTypes.MAIN_HAND);

    if (!itemStackOpt.isPresent()) {
        player.sendMessage(Text.of(TextColors.RED, "You must hold an item in your hand"));
        return CommandResult.success();
    }

    ItemStack itemStack = itemStackOpt.get();

    JSONObject awardData = new JSONObject()
            .put("type", "item")
            .put("itemType", itemStack.getType().getId())
            .put("quantity", itemStack.getQuantity());

    Optional<Text> displayNameOpt = itemStack.get(Keys.DISPLAY_NAME);
    if (displayNameOpt.isPresent()) {
        awardData.put("displayName", TextSerializers.FORMATTING_CODE.serialize(displayNameOpt.get()));
    }

    Optional<List<Text>> loreOpt = itemStack.get(Keys.ITEM_LORE);
    if (loreOpt.isPresent()) {
        JSONArray lore = new JSONArray();
        for (Text line : loreOpt.get()) {
            lore.put(TextSerializers.FORMATTING_CODE.serialize(line));
        }
        awardData.put("lore", TextSerializers.FORMATTING_CODE.serialize(displayNameOpt.get()));
    }

    Optional<List<Enchantment>> enchantmentsOpt = itemStack.get(Keys.ITEM_ENCHANTMENTS);
    if (enchantmentsOpt.isPresent()) {
        JSONArray enchantments = new JSONArray();
        for (Enchantment enchant : enchantmentsOpt.get()) {
            enchantments.put(new JSONObject()
                    .put("id", enchant.getType().getId())
                    .put("level", enchant.getLevel()));
        }
        awardData.put("enchantments", enchantments);
    }

    Optional<Integer> durabilityOpt = itemStack.get(Keys.ITEM_DURABILITY);
    if (durabilityOpt.isPresent()) {
        awardData.put("durability", durabilityOpt.get());
    }

    Optional<DyeColor> dyeColorOpt = itemStack.get(Keys.DYE_COLOR);
    if (dyeColorOpt.isPresent()) {
        awardData.put("color", dyeColorOpt.get().getId());
    }

    Optional<SkullType> skullTypeOpt = itemStack.get(Keys.SKULL_TYPE);
    if (skullTypeOpt.isPresent()) {
        awardData.put("skullType", skullTypeOpt.get());
    }

    JSONObject awardBody = new JSONObject()
            .put("name", itemStack.get(Keys.DISPLAY_NAME).orElse(Text.of(itemStack.getTranslation().get(Locale.ENGLISH))).toPlain())
            .put("description", "Created by the BadgeUp Sponge Client on " + new Date().toString())
            .put("data", awardData);

    Sponge.getScheduler().createTaskBuilder().execute(new PostAwardRunnable(player, awardBody, this.plugin.getLogger())).async()
            .submit(this.plugin);

    return CommandResult.success();
}
 
开发者ID:BadgeUp,项目名称:badgeup-sponge-client,代码行数:74,代码来源:CreateItemAwardCommandExecutor.java


示例19: LanternEnchantmentBuilder

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
public LanternEnchantmentBuilder() {
    super(Enchantment.class, 1);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:LanternEnchantmentBuilder.java


示例20: reset

import org.spongepowered.api.item.enchantment.Enchantment; //导入依赖的package包/类
@Override
public Enchantment.Builder reset() {
    this.enchantmentType = null;
    this.level = null;
    return this;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:LanternEnchantmentBuilder.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NamespaceInfoProto类代码示例发布时间:2022-05-22
下一篇:
Java ViewQuery类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap