當前位置: 首頁>>代碼示例>>Java>>正文


Java ItemStack.get方法代碼示例

本文整理匯總了Java中org.spongepowered.api.item.inventory.ItemStack.get方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemStack.get方法的具體用法?Java ItemStack.get怎麽用?Java ItemStack.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.spongepowered.api.item.inventory.ItemStack的用法示例。


在下文中一共展示了ItemStack.get方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getItemID

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public String getItemID(ItemStack si) {
    if (si.supports(Keys.ITEM_BLOCKSTATE)) {
        Optional<BlockState> bs = si.get(Keys.ITEM_BLOCKSTATE);
        if (bs.isPresent()) {
            return bs.get().getId();
        }
    }
    return si.getItem().getId();
}
 
開發者ID:Time6628,項目名稱:CatClearLag,代碼行數:10,代碼來源:CatClearLag.java

示例2: repairInventory

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static ItemStack repairInventory(final ItemStack stack) {
	Optional<Integer> data = stack.get(Keys.ITEM_DURABILITY);
	if (data.isPresent()) {
		stack.offer(Keys.ITEM_DURABILITY, Integer.MAX_VALUE);
	}
	return stack;
}
 
開發者ID:EverCraft,項目名稱:EverAPI,代碼行數:8,代碼來源:UtilsItemStack.java

示例3: commandRepair

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private CompletableFuture<Boolean> commandRepair(final EPlayer player) {
	Optional<ItemStack> optItem = player.getItemInMainHand();
	if (!optItem.isPresent()) {
		EAMessages.EMPTY_ITEM_IN_HAND.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	ItemStack item = optItem.get();
	Optional<Integer> durability = item.get(Keys.ITEM_DURABILITY);
	if (!durability.isPresent()) {
		EEMessages.REPAIR_HAND_ERROR.sender()
        	.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
        	.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	item.offer(Keys.ITEM_DURABILITY, Integer.MAX_VALUE);
	if (item.get(Keys.ITEM_DURABILITY).get() == durability.get()) {
		EEMessages.REPAIR_HAND_MAX_DURABILITY.sender()
        	.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
        	.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
       player.setItemInMainHand(item);
       EEMessages.REPAIR_HAND_PLAYER.sender()
       	.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
       	.sendTo(player);
       return CompletableFuture.completedFuture(true);
}
 
開發者ID:EverCraft,項目名稱:EverEssentials,代碼行數:31,代碼來源:EERepairHand.java

示例4: getData

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private static DataView getData(ItemStack itemStack) {
    Optional<CustomItemData> opData = itemStack.get(CustomItemData.class);
    if (opData.isPresent()) {
        return opData.get().getData();
    }
    return null;
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:8,代碼來源:CustomItem.java

示例5: execute

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的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


注:本文中的org.spongepowered.api.item.inventory.ItemStack.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。