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

Java ItemEnchantment类代码示例

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

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



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

示例1: makeSpongeStack

import org.spongepowered.api.data.meta.ItemEnchantment; //导入依赖的package包/类
@Override
public ItemStack makeSpongeStack(BaseItemStack baseItemStack) {
    final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(baseItemStack.getType())
            .orElseThrow(() -> new IllegalStateException("Invalid item type: " + baseItemStack.getType()));
    final LanternItemStack itemStack = new LanternItemStack(itemType, baseItemStack.getAmount());
    final ObjectStore<LanternItemStack> store = ObjectStoreRegistry.get().get(LanternItemStack.class)
            .orElseThrow(() -> new IllegalStateException("Unable to access the LanternItemStack store."));
    final DataView view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    view.set(DATA_VALUE, baseItemStack.getData());
    store.deserialize(itemStack, view);
    final Map<Integer, Integer> enchantments = baseItemStack.getEnchantments();
    if (!enchantments.isEmpty()) {
        itemStack.offer(Keys.ITEM_ENCHANTMENTS, enchantments.entrySet().stream()
                .map(entry -> {
                    final Enchantment enchantment = EnchantmentRegistryModule.get().getByInternalId(entry.getKey())
                            .orElseThrow(() -> new IllegalStateException("Invalid enchantment type: " + entry.getKey()));
                    return new ItemEnchantment(enchantment, entry.getValue());
                })
                .collect(Collectors.toList()));
    }
    return itemStack;
}
 
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:23,代码来源:LanternImplAdapter.java


示例2: getInvValue

import org.spongepowered.api.data.meta.ItemEnchantment; //导入依赖的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.getItem().getId()) * stack.getQuantity()));
		if (stack.get(Keys.ITEM_ENCHANTMENTS).isPresent()){
			for (ItemEnchantment enchant:stack.get(Keys.ITEM_ENCHANTMENTS).get()){
				value += ((RedProtect.get().cfgs.getEnchantCost(enchant.getEnchantment().getId()) * enchant.getLevel()));
			}
		}
	}
	return value;
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:18,代码来源:RPVHelper56.java


示例3: getEnchantments

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


示例4: canBeAppliedToItemStack

import org.spongepowered.api.data.meta.ItemEnchantment; //导入依赖的package包/类
public static boolean canBeAppliedToItemStack(ItemStack item, Enchantment enchantment) {
	if (enchantment.canBeAppliedToStack(item)) {
		EnchantmentData enchantment_data = item.getOrCreate(EnchantmentData.class).get();
		
		for (ItemEnchantment enchantment_item : enchantment_data.enchantments()) {
			if (!enchantment.isCompatibleWith(enchantment_item.getEnchantment())) {
				return false;
			}
		}
	} else {
		return false;
	}
	return true;
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:15,代码来源:UtilsEnchantment.java


示例5: getEnchantment

import org.spongepowered.api.data.meta.ItemEnchantment; //导入依赖的package包/类
public static List<ItemEnchantment> getEnchantment(CompositeValueStore<?, ?> valueStore, Enchantment enchantment) {
  Optional<List<ItemEnchantment>> results = valueStore.get(Keys.ITEM_ENCHANTMENTS);
  if (results.isPresent()) {
    List<ItemEnchantment> enchantments = results.get();
    return enchantments.stream().filter(e -> e.getEnchantment().equals(enchantment)).collect(Collectors.toList());
  }
  return Lists.newArrayList();
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:9,代码来源:EnchantmentUtil.java


示例6: getHighestEnchantment

import org.spongepowered.api.data.meta.ItemEnchantment; //导入依赖的package包/类
public static Optional<ItemEnchantment> getHighestEnchantment(CompositeValueStore<?, ?> valueStore, Enchantment enchantment) {
  List<ItemEnchantment> enchantments = getEnchantment(valueStore, enchantment);
  if (!enchantments.isEmpty()) {
    return Optional.of(enchantments.stream().sorted(Comparator.comparingInt(ItemEnchantment::getLevel)).findFirst().get());
  }
  return Optional.empty();
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:8,代码来源:EnchantmentUtil.java


示例7: execute

import org.spongepowered.api.data.meta.ItemEnchantment; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, ItemPermissions.UC_ITEM_ITEMENCHANT_BASE);
    Player p = (Player) sender;

    if (!p.getItemInHand(HandTypes.MAIN_HAND).isPresent() || p.getItemInHand(HandTypes.MAIN_HAND).get().getItem().equals(ItemTypes.NONE)) {
        throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand"));
    }
    ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND).get();

    Enchantment ench = args.<Enchantment>getOne("enchantment").get();
    int level = args.hasAny("level") ? args.<Integer>getOne("level").get() : 1;

    if (level > ItemPermissions.UC_ITEM_ITEMENCHANT_MAXLEVEL.getIntFor(p)) {
        throw Messages.error(p, "item.command.itemenchant.maxlevel", "%max%", ItemPermissions.UC_ITEM_ITEMENCHANT_MAXLEVEL.getIntFor(p));
    }

    List<ItemEnchantment> enchs = stack.get(Keys.ITEM_ENCHANTMENTS).orElse(new ArrayList<>());
    if (level > 0) {
        enchs.add(new ItemEnchantment(ench, level));
        stack.offer(Keys.ITEM_ENCHANTMENTS, enchs);
        p.setItemInHand(HandTypes.MAIN_HAND, stack);
        Messages.send(sender, "item.command.itemenchant.success", "%enchant%", ench.getTranslation().get(), "%level%", level);
        return CommandResult.success();
    } else {
        enchs = enchs.stream().filter(e -> !e.getEnchantment().equals(ench)).collect(Collectors.toList());
        stack.offer(Keys.ITEM_ENCHANTMENTS, enchs);
        p.setItemInHand(HandTypes.MAIN_HAND, stack);
        Messages.send(sender, "item.command.itemenchant.success2", "%enchant%", ench.getTranslation().get(), "%level%", level);
        return CommandResult.success();
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:34,代码来源:ItemenchantCommand.java


示例8: commandEnchant

import org.spongepowered.api.data.meta.ItemEnchantment; //导入依赖的package包/类
private CompletableFuture<Boolean> commandEnchant(final EPlayer player, Enchantment enchantment, int level) {
	// Le joueur n'a pas d'item dans la main
	if (!player.getItemInMainHand().isPresent()) {
		EAMessages.EMPTY_ITEM_IN_HAND.sender()
			.prefix(EEMessages.PREFIX)
			.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	ItemStack item = player.getItemInMainHand().get();
		
	// Le level est trop faible
	if (level < enchantment.getMinimumLevel()) {
		EEMessages.ENCHANT_LEVEL_TOO_LOW.sender()
			.replace("{number}", String.valueOf(level))
			.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	if (level > enchantment.getMaximumLevel()) {
		EEMessages.ENCHANT_LEVEL_TOO_HIGHT.sender()
			.replace("{number}", String.valueOf(level))
			.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}

	EnchantmentData enchantment_data = item.getOrCreate(EnchantmentData.class).get();
				
	// L'enchantement n'est pas applicable sur cet item
	if (!UtilsEnchantment.canBeAppliedToItemStack(item, enchantment)) {
		EEMessages.ENCHANT_INCOMPATIBLE.sender()
			.replace("{enchantment}", () -> enchantment.getId().toLowerCase().replace("minecraft:", "").replaceAll(" ", ""))
			.replace("{level}", String.valueOf(level))
			.replace("{item}", () -> EChat.getButtomItem(item, EEMessages.ENCHANT_ITEM_COLOR.getColor()))
			.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	enchantment_data.set(enchantment_data.enchantments().add(new ItemEnchantment(enchantment, level)));
	item.offer(enchantment_data);
	player.setItemInMainHand(item);
	
	EEMessages.ENCHANT_SUCCESSFULL.sender()
		.replace("{enchantment}", enchantment.getTranslation().get())
		.replace("{level}", String.valueOf(level))
		.replace("{item}", () -> EChat.getButtomItem(item, EEMessages.ENCHANT_ITEM_COLOR.getColor()))
		.sendTo(player);
	return CompletableFuture.completedFuture(true);
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:50,代码来源:EEEnchant.java


示例9: offerEnchantment

import org.spongepowered.api.data.meta.ItemEnchantment; //导入依赖的package包/类
@Override
public ItemStack offerEnchantment(ItemStack item) {
	item.offer(Keys.ITEM_ENCHANTMENTS, Collections.singletonList(new ItemEnchantment(Enchantments.UNBREAKING, 1)));
	return item;
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:6,代码来源:RPVHelper56.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Meta类代码示例发布时间:2022-05-22
下一篇:
Java PropertyListFormatException类代码示例发布时间: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