本文整理汇总了Java中org.spongepowered.api.item.inventory.Slot.peek方法的典型用法代码示例。如果您正苦于以下问题:Java Slot.peek方法的具体用法?Java Slot.peek怎么用?Java Slot.peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.item.inventory.Slot
的用法示例。
在下文中一共展示了Slot.peek方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CachedInventory
import org.spongepowered.api.item.inventory.Slot; //导入方法依赖的package包/类
public CachedInventory(Inventory inv) {
super(inv, false);
this.name = inv.getName().get();
this.capacity = inv.capacity();
this.totalItems = inv.totalItems();
this.type = new CachedCatalogType(inv.getArchetype());
items = new ArrayList<>();
try {
for (Inventory subInv : inv.slots()) {
Slot slot = (Slot) subInv;
Optional<ItemStack> optItem = slot.peek();
optItem.ifPresent(itemStack -> items.add(itemStack.copy()));
}
} catch (AbstractMethodError ignored) {}
}
示例2: serialize
import org.spongepowered.api.item.inventory.Slot; //导入方法依赖的package包/类
@Override
public void serialize(T object, DataView dataView) {
super.serialize(object, dataView);
final ObjectSerializer<LanternItemStack> itemStackSerializer = ObjectSerializerRegistry.get().get(LanternItemStack.class).get();
final List<DataView> itemViews = new ArrayList<>();
final Inventory inventory = object.getInventory();
final Iterable<Slot> slots = inventory.slots();
for (Slot slot : slots) {
final Optional<ItemStack> optItemStack = slot.peek();
if (!optItemStack.isPresent()) {
continue;
}
final DataView itemView = itemStackSerializer.serialize((LanternItemStack) optItemStack.get());
//noinspection ConstantConditions
itemView.set(SLOT, (byte) inventory.getProperty(slot, SlotIndex.class, null).get().getValue().intValue());
itemViews.add(itemView);
}
dataView.set(ITEMS, itemViews);
}
示例3: clear
import org.spongepowered.api.item.inventory.Slot; //导入方法依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public int clear(int id, int data) {
int removed = 0;
for (Slot slot : this.getHandle().<Slot>slots()) {
Optional<org.spongepowered.api.item.inventory.ItemStack> stackOptional = slot.peek();
if (stackOptional.isPresent()) {
org.spongepowered.api.item.inventory.ItemStack stack = stackOptional.get();
if (id == -1 || stack.getItem() == MaterialConverter.asItem(Material.getMaterial(id))) {
int damage = DurabilityConverter.getDamageValue(stack.getContainers());
if (data == -1 || damage == data) {
removed += stack.getQuantity();
slot.clear();
}
}
}
}
return removed;
}
示例4: countItems
import org.spongepowered.api.item.inventory.Slot; //导入方法依赖的package包/类
public int countItems(Inventory i, ItemType type){
int count = 0;
for (Inventory isl : i.query(QueryOperationTypes.ITEM_TYPE.of(type)).slots()){
Slot sl = (Slot) isl;
Optional<ItemStack> ois = sl.peek();
if (ois.isPresent()){
count += ois.get().getQuantity();
}
}
return count;
}
示例5: serializeEnderChest
import org.spongepowered.api.item.inventory.Slot; //导入方法依赖的package包/类
private static List<DataView> serializeEnderChest(GridInventory enderChestInventory) {
final List<DataView> itemViews = new ArrayList<>();
final Iterable<Slot> slots = enderChestInventory.slots();
for (Slot slot : slots) {
final Optional<ItemStack> optItemStack = slot.peek();
if (!optItemStack.isPresent()) {
continue;
}
final DataView itemView = ItemStackStore.INSTANCE.serialize((LanternItemStack) optItemStack.get());
itemView.set(SLOT, (byte) enderChestInventory.getProperty(slot, SlotIndex.class, null).get().getValue().intValue());
itemViews.add(itemView);
}
return itemViews;
}
示例6: serializeSlot
import org.spongepowered.api.item.inventory.Slot; //导入方法依赖的package包/类
private static void serializeSlot(int index, Slot slot, ObjectSerializer<LanternItemStack> itemStackSerializer, List<DataView> views) {
final Optional<ItemStack> optItemStack = slot.peek();
if (!optItemStack.isPresent()) {
return;
}
final ItemStack itemStack = optItemStack.get();
final DataView itemView = itemStackSerializer.serialize((LanternItemStack) itemStack);
itemView.set(SLOT, (byte) index);
views.add(itemView);
}
示例7: remove
import org.spongepowered.api.item.inventory.Slot; //导入方法依赖的package包/类
@Override
public void remove(Material material) throws IllegalArgumentException {
for (Slot slot : this.getHandle().<Slot>slots()) {
Optional<org.spongepowered.api.item.inventory.ItemStack> stack = slot.peek();
if (stack.isPresent()) {
if (stack.get().getItem() == MaterialConverter.asItem(material)) {
slot.clear();
return;
}
}
}
}