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


Java ItemStack.getItem方法代碼示例

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


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

示例1: of

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
/**
 * Gets a SkinRecord that has been assigned to this {@link ItemStack}.
 *
 * @param itemStack The {@link ItemStack} to get the {@link SkinRecord} of
 * @return The {@link SkinRecord}, if found, or {@link Optional#empty()} instead.
 */
public static Optional<SkinRecord> of(ItemStack itemStack) {
    if(itemStack.getItem() != ItemTypes.SKULL
            || itemStack.get(Keys.SKULL_TYPE).orElse(SkullTypes.SKELETON) != SkullTypes.PLAYER)
        return Optional.empty();

    return itemStack.get(Keys.REPRESENTED_PLAYER).flatMap(profile -> {
        Collection<ProfileProperty> properties = profile.getPropertyMap().get(PROPERTY_TEXTURES);

        if(properties.size() != 1)
            return Optional.empty();

        ProfileProperty property = properties.iterator().next();
        Optional<String> signature = property.getSignature();

        if(!signature.isPresent())
            return Optional.empty();

        return Optional.of(new SkinRecord(profile.getUniqueId(), property.getValue(), signature.get()));
    });
}
 
開發者ID:Limeth,項目名稱:MineskinSponge,代碼行數:27,代碼來源:SkinRecord.java

示例2: createItem

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Override
public CustomTool createItem(Cause cause) {
    PluginContainer plugin = getPluginContainer();
    ItemStack itemStack = itemStackSnapshot.createStack();
    ItemType itemType = itemStack.getItem();
    int durability = DurabilityRegistry.getInstance().getDurability(itemType, plugin, getDefaultModel())
            .orElseThrow(() -> new IllegalStateException("Could not get the durability for the default models."));

    itemStack.offer(Keys.UNBREAKABLE, true);
    itemStack.offer(Keys.ITEM_DURABILITY, durability);
    itemStack.offer(Keys.HIDE_UNBREAKABLE, true);
    itemStack.offer(Keys.HIDE_ATTRIBUTES, true);
    itemStack.offer(createDefaultCustomFeatureData());

    CustomTool tool = new CustomTool(itemStack, this);
    CustomItemCreationEvent event = new CustomItemCreationEvent(tool, cause);

    Sponge.getEventManager().post(event);

    return tool;
}
 
開發者ID:Limeth,項目名稱:CustomItemLibrary,代碼行數:22,代碼來源:CustomToolDefinition.java

示例3: wrapIfPossible

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Override
public Optional<CustomTool> wrapIfPossible(ItemStack itemStack) {
    if(itemStack.getItem() != itemStackSnapshot.getType())
        return Optional.empty();

    int durability = itemStack.get(Keys.ITEM_DURABILITY)
            .orElseThrow(() -> new IllegalStateException("Could not access the durability of a tool."));

    if(!DurabilityRegistry.getInstance().getModelId(itemStack.getItem(), durability).isPresent())
        return Optional.empty();

    return Optional.of(new CustomTool(itemStack, this));
}
 
開發者ID:Limeth,項目名稱:CustomItemLibrary,代碼行數:14,代碼來源:CustomToolDefinition.java

示例4: wrapIfPossible

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Override
public Optional<CustomMaterial> wrapIfPossible(ItemStack itemStack) {
    if(itemStack.getItem() != ItemTypes.SKULL)
        return Optional.empty();

    return Optional.of(new CustomMaterial(itemStack, this));
}
 
開發者ID:Limeth,項目名稱:CustomItemLibrary,代碼行數:8,代碼來源:CustomMaterialDefinition.java

示例5: ItemStackView

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public ItemStackView(ItemStack value) {
    super(value);

    this.type = value.getItem();
    this.quantity = value.getQuantity();
}
 
開發者ID:Valandur,項目名稱:Web-API,代碼行數:7,代碼來源:ItemStackView.java

示例6: DurabilityIdentifier

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public DurabilityIdentifier(ItemStack itemStack) {
    itemType = itemStack.getItem();
    durability = itemStack.get(Keys.ITEM_DURABILITY)
            .orElseThrow(() -> new IllegalArgumentException("This item does not have a durability."));
}
 
開發者ID:Limeth,項目名稱:CustomItemLibrary,代碼行數:6,代碼來源:DurabilityIdentifier.java


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