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

Java Enchantment类代码示例

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

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



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

示例1: makeSpongeStack

import org.spongepowered.api.item.Enchantment; //导入依赖的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: getID

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
public static Optional<Enchantment> getID(final String name) {
	Enchantment enchant = null;
	List<Enchantment> enchantments = getAll();
	int cpt = 0;
	while(cpt < enchantments.size() && enchant == null){
		if (enchantments.get(cpt).getId().equalsIgnoreCase(name)) {
			enchant = enchantments.get(cpt);
		}
		cpt++;
	}
	return Optional.ofNullable(enchant);
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:13,代码来源:UtilsEnchantment.java


示例3: canBeAppliedToItemStack

import org.spongepowered.api.item.Enchantment; //导入依赖的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


示例4: getEnchantment

import org.spongepowered.api.item.Enchantment; //导入依赖的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


示例5: getHighestEnchantment

import org.spongepowered.api.item.Enchantment; //导入依赖的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


示例6: ItemData

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
public ItemData(ItemType material, short dura, String displayName, List<String> lore,
                Map<Enchantment, Integer> enchantments)
{
    this.material = material;
    this.dura = dura;
    this.displayName = displayName;
    this.lore = lore;
    this.enchantments = enchantments;
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:10,代码来源:ItemData.java


示例7: execute

import org.spongepowered.api.item.Enchantment; //导入依赖的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: parseValue

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
@Nullable
@Override
public Enchantment parseValue(CommandSource sender, CommandArgs args) throws ArgumentParseException {
    String value = args.next();
    Optional<Enchantment> type = Sponge.getRegistry().getType(CatalogTypes.ENCHANTMENT, value);
    if (!type.isPresent()) {
        throw args.createError(Messages.getFormatted(sender, "item.command.itemenchant.notfound", "%enchantment%", value));
    }
    return type.get();
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:11,代码来源:EnchantmentArgument.java


示例9: getAll

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
public static  List<Enchantment> getAll(){
	return Sponge.getRegistry().getAllOf(Enchantment.class).stream().collect(Collectors.toList());
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:4,代码来源:UtilsEnchantment.java


示例10: commandEnchant

import org.spongepowered.api.item.Enchantment; //导入依赖的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


示例11: getEnchantment

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
private Optional<Enchantment> getEnchantment(String enchant) {
	return UtilsEnchantment.getID("minecraft:" + enchant.toLowerCase().replace("minecraft:", ""));
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:4,代码来源:EEEnchant.java


示例12: getAllEnchants

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
@Override
public List<String> getAllEnchants() {
	return Sponge.getRegistry().getAllOf(Enchantment.class).stream().map(Enchantment::getId).collect(Collectors.toList());
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:5,代码来源:RPVHelper56.java


示例13: setEnchants

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
public void setEnchants(Map<Enchantment, Integer> enchantsToAdd)
{
    // TODO
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:5,代码来源:ItemEnchant.java


示例14: getItemEnchantmentDamage

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
/**
 * Utility method to calculate the modified damage from an Enchantment damage caused by an Armor
 * piece or Weapon. The {@link com.afterkraft.kraftrpg.api.entity.Insentient} is used to check
 * for any possible {@link com.afterkraft.kraftrpg.api.role.Role} damage modifications
 * necessary.  If varying damage is enabled, the damage will already take this into account.
 *
 * @param being       wearing/using the enchanted ItemStack
 * @param enchantment to calculate for
 * @param item        that is enchanted
 *
 * @return calculated damage that may be varied if enabled
 */
double getItemEnchantmentDamage(Insentient being, Enchantment enchantment,
                                ItemStack item);
 
开发者ID:AfterKraft,项目名称:KraftRPG-API,代码行数:15,代码来源:DamageManager.java


示例15: getEnchantmentDamage

import org.spongepowered.api.item.Enchantment; //导入依赖的package包/类
double getEnchantmentDamage(Enchantment enchantment, int enchantmentLevel); 
开发者ID:AfterKraft,项目名称:KraftRPG-API,代码行数:2,代码来源:DamageManager.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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