本文整理匯總了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."));
}