本文整理汇总了Java中org.spongepowered.api.item.inventory.Inventory.peek方法的典型用法代码示例。如果您正苦于以下问题:Java Inventory.peek方法的具体用法?Java Inventory.peek怎么用?Java Inventory.peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.item.inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.peek方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeInventory
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static List<DataView> serializeInventory(Inventory inventory) {
DataContainer container;
List<DataView> slots = new LinkedList<>();
int i = 0;
Optional<ItemStack> stack;
for (Inventory inv : inventory.slots()) {
stack = inv.peek();
if (stack.isPresent()) {
container = new org.spongepowered.api.data.MemoryDataContainer();
container.set(SLOT, i);
container.set(STACK, serializeItemStack(stack.get()));
slots.add(container);
}
i++;
}
return slots;
}
示例2: getState
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public PlayerState getState() {
Player player = getPlayer().orElseThrow(IllegalStateException::new);
ImmutableList.Builder<WarItem> builder = ImmutableList.builder();
for (Inventory inventory : player.getInventory().slots()) {
Optional<ItemStack> peek = inventory.peek();
if (peek.isPresent()) {
builder.add(plugin.getWarItem(peek.get()));
}
}
int gameMode = 0;
GameMode gameMode1 = player.getGameModeData().getValue(Keys.GAME_MODE).orElseThrow(IllegalStateException::new).get();
if (gameMode1 == GameModes.CREATIVE)
gameMode = WarGameMode.CREATIVE;
// return new PlayerState(gameMode, (WarItem[]) builder.build().toArray(),
// null, null, null, null,
// player.getHealthData().getValue(Keys.HEALTH).orElseThrow(IllegalStateException::new).get(),
// player.getS);
throw new UnsupportedOperationException("Not implemented yet");
}
示例3: getTemplate
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
static public Optional<ItemStack> getTemplate(Inventory inventory, ItemStack needle) {
for (Inventory item : inventory.slots()) {
if (item.peek().isPresent()) {
if (equalTo(item.peek().get(), needle))
return item.peek();
}
}
return Optional.empty();
}
示例4: freeSlots
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public static int freeSlots(Iterable<Inventory> slots) {
int count = 0;
for (Inventory i : slots) {
Optional<ItemStack> ois = i.peek();
if (!ois.isPresent() || ois.get().getItem() == ItemTypes.NONE) {
count++;
}
}
return count;
}
示例5: usedSlots
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public static int usedSlots(Iterable<Inventory> slots) {
int count = 0;
for (Inventory i : slots) {
Optional<ItemStack> ois = i.peek();
if (ois.isPresent() && ois.get().getItem() != ItemTypes.NONE) {
count++;
}
}
return count;
}
示例6: getEquipped
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
default Optional<ItemStack> getEquipped(EquipmentType type) {
checkNotNull(type, "type");
final Inventory inventory = getInventory().query(Holder.EQUIPMENT_INVENTORY_OPERATION);
if (inventory instanceof EmptyInventory) {
return Optional.empty();
}
return inventory.peek();
}