本文整理汇总了Java中org.spongepowered.api.item.inventory.Inventory.totalItems方法的典型用法代码示例。如果您正苦于以下问题:Java Inventory.totalItems方法的具体用法?Java Inventory.totalItems怎么用?Java Inventory.totalItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.item.inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.totalItems方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CachedInventory
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的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: aSell
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public aSell(Player player, Location<World> sign) throws ExceptionInInitializerError {
super(sign);
if (!player.hasPermission("carrotshop.admin.asell"))
throw new ExceptionInInitializerError("You don't have perms to build an aSell sign");
Stack<Location<World>> locations = ShopsData.getItemLocations(player);
if (locations.isEmpty())
throw new ExceptionInInitializerError("Sell signs require a chest");
Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
throw new ExceptionInInitializerError("Sell signs require a chest");
Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
if (items.totalItems() == 0)
throw new ExceptionInInitializerError("chest cannot be empty");
price = getPrice(sign);
if (price < 0)
throw new ExceptionInInitializerError("bad price");
sellerChest = locations.peek();
itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
for(Inventory item : items.slots()) {
if (item.peek().isPresent())
itemsTemplate.offer(item.peek().get());
}
ShopsData.clearItemLocations(player);
player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup an aSell shop:"));
done(player);
info(player);
}
示例3: hasEnough
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
static public boolean hasEnough(Inventory inventory, Inventory needs) {
for (Inventory item : needs.slots()) {
if (item.peek().isPresent()) {
Optional<ItemStack> template = getTemplate(inventory, item.peek().get());
if (!template.isPresent() || inventory.query(template.get()).totalItems() < item.totalItems())
return false;
}
}
return true;
}
示例4: Buy
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public Buy(Player player, Location<World> sign) throws ExceptionInInitializerError {
super(sign);
if (!player.hasPermission("carrotshop.create.buy"))
throw new ExceptionInInitializerError("You don't have perms to build a Buy sign");
Stack<Location<World>> locations = ShopsData.getItemLocations(player);
if (locations.isEmpty())
throw new ExceptionInInitializerError("Buy signs require a chest");
Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
throw new ExceptionInInitializerError("Buy signs require a chest");
Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
if (items.totalItems() == 0)
throw new ExceptionInInitializerError("chest cannot be empty");
price = getPrice(sign);
if (price < 0)
throw new ExceptionInInitializerError("bad price");
sellerChest = locations.peek();
itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
for(Inventory item : items.slots()) {
if (item.peek().isPresent())
itemsTemplate.offer(item.peek().get());
}
setOwner(player);
ShopsData.clearItemLocations(player);
player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup a Buy shop:"));
done(player);
info(player);
}
示例5: aBuy
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public aBuy(Player player, Location<World> sign) throws ExceptionInInitializerError {
super(sign);
if (!player.hasPermission("carrotshop.admin.abuy"))
throw new ExceptionInInitializerError("You don't have perms to build an aBuy sign");
Stack<Location<World>> locations = ShopsData.getItemLocations(player);
if (locations.isEmpty())
throw new ExceptionInInitializerError("aBuy signs require a chest");
Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
throw new ExceptionInInitializerError("aBuy signs require a chest");
Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
if (items.totalItems() == 0)
throw new ExceptionInInitializerError("chest cannot be empty");
price = getPrice(sign);
if (price < 0)
throw new ExceptionInInitializerError("bad price");
sellerChest = locations.peek();
itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
for(Inventory item : items.slots()) {
if (item.peek().isPresent())
itemsTemplate.offer(item.peek().get());
}
ShopsData.clearItemLocations(player);
player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup an aBuy shop:"));
done(player);
info(player);
}
示例6: iBuy
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public iBuy(Player player, Location<World> sign) throws ExceptionInInitializerError {
super(sign);
if (!player.hasPermission("carrotshop.admin.ibuy"))
throw new ExceptionInInitializerError("You don't have perms to build an iTrade sign");
Stack<Location<World>> locations = ShopsData.getItemLocations(player);
if (locations.isEmpty())
throw new ExceptionInInitializerError("Buy signs require a chest");
Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
throw new ExceptionInInitializerError("Buy signs require a chest");
Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
if (items.totalItems() == 0)
throw new ExceptionInInitializerError("chest cannot be empty");
price = getPrice(sign);
if (price < 0)
throw new ExceptionInInitializerError("bad price");
itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
for(Inventory item : items.slots()) {
if (item.peek().isPresent())
itemsTemplate.offer(item.peek().get());
}
ShopsData.clearItemLocations(player);
player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup an iBuy shop:"));
done(player);
info(player);
}
示例7: iSell
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public iSell(Player player, Location<World> sign) throws ExceptionInInitializerError {
super(sign);
if (!player.hasPermission("carrotshop.admin.isell"))
throw new ExceptionInInitializerError("You don't have perms to build an iTrade sign");
Stack<Location<World>> locations = ShopsData.getItemLocations(player);
if (locations.isEmpty())
throw new ExceptionInInitializerError("iSell signs require a chest");
Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
throw new ExceptionInInitializerError("iSell signs require a chest");
Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
if (items.totalItems() == 0)
throw new ExceptionInInitializerError("chest cannot be empty");
price = getPrice(sign);
if (price < 0)
throw new ExceptionInInitializerError("bad price");
itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
for(Inventory item : items.slots()) {
if (item.peek().isPresent())
itemsTemplate.offer(item.peek().get());
}
ShopsData.clearItemLocations(player);
player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup an iSell shop:"));
done(player);
info(player);
}
示例8: Sell
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public Sell(Player player, Location<World> sign) throws ExceptionInInitializerError {
super(sign);
if (!player.hasPermission("carrotshop.create.sell"))
throw new ExceptionInInitializerError("You don't have perms to build a Sell sign");
Stack<Location<World>> locations = ShopsData.getItemLocations(player);
if (locations.isEmpty())
throw new ExceptionInInitializerError("Sell signs require a chest");
Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
throw new ExceptionInInitializerError("Sell signs require a chest");
Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
if (items.totalItems() == 0)
throw new ExceptionInInitializerError("chest cannot be empty");
price = getPrice(sign);
if (price < 0)
throw new ExceptionInInitializerError("bad price");
sellerChest = locations.peek();
itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
for(Inventory item : items.slots()) {
if (item.peek().isPresent())
itemsTemplate.offer(item.peek().get());
}
setOwner(player);
ShopsData.clearItemLocations(player);
player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup a Sell shop:"));
done(player);
info(player);
}
示例9: updateStock
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public void updateStock(Inventory container) {
Inventory result = container.queryAny(item);
int count = 0;
for (Inventory s : result.slots()) count += s.totalItems();
stocked = Math.min(maxStock, count);
}