当前位置: 首页>>代码示例>>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;未经允许,请勿转载。