本文整理汇总了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()));
});
}
示例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;
}
示例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));
}
示例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));
}
示例5: ItemStackView
import org.spongepowered.api.item.inventory.ItemStack; //导入方法依赖的package包/类
public ItemStackView(ItemStack value) {
super(value);
this.type = value.getItem();
this.quantity = value.getQuantity();
}
示例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."));
}