本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
}
示例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);
}
示例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;
}