本文整理汇总了Java中org.spongepowered.api.item.inventory.Inventory.capacity方法的典型用法代码示例。如果您正苦于以下问题:Java Inventory.capacity方法的具体用法?Java Inventory.capacity怎么用?Java Inventory.capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.item.inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.capacity方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: update
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public boolean update() {
Optional<TileEntity> chest = toGiveChest.getTileEntity();
if (chest.isPresent() && chest.get() instanceof TileEntityCarrier) {
if (!hasEnough(((TileEntityCarrier) chest.get()).getInventory(), toGive)) {
setFail();
return false;
}
} else {
setFail();
return false;
}
chest = toTakeChest.getTileEntity();
if (chest.isPresent() && chest.get() instanceof TileEntityCarrier) {
Inventory chestInv = ((TileEntityCarrier) chest.get()).getInventory();
if (chestInv.capacity() - chestInv.size() < toTake.size()) {
setFail();
return false;
}
} else {
setFail();
return false;
}
setOK();
return true;
}
示例3: update
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public boolean update() {
Optional<TileEntity> chest = sellerChest.getTileEntity();
if (chest.isPresent() && chest.get() instanceof TileEntityCarrier) {
Inventory chestInv = ((TileEntityCarrier) chest.get()).getInventory();
if (chestInv.capacity() - chestInv.size() >= itemsTemplate.size()) {
setOK();
return true;
}
}
setFail();
return false;
}
示例4: trigger
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public boolean trigger(Player player) {
Inventory inv = player.getInventory().query(InventoryRow.class);
if (!hasEnough(inv, itemsTemplate)) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You don't have the items to sell!"));
return false;
}
Optional<TileEntity> chest = sellerChest.getTileEntity();
if (chest.isPresent() && chest.get() instanceof TileEntityCarrier) {
Inventory chestInv = ((TileEntityCarrier) chest.get()).getInventory();
if (chestInv.capacity() - chestInv.size() < itemsTemplate.size()) {
player.sendMessage(Text.of(TextColors.GOLD, "This shop is full!"));
update();
return false;
}
}
Inventory invChest = ((TileEntityCarrier) chest.get()).getInventory();
Builder itemsName = Text.builder();
for (Inventory item : itemsTemplate.slots()) {
if (item.peek().isPresent()) {
Optional<ItemStack> template = getTemplate(inv, item.peek().get());
if (template.isPresent()) {
itemsName.append(Text.of(TextColors.YELLOW, " ", item.peek().get().getTranslation().get(), " x", item.peek().get().getQuantity()));
Optional<ItemStack> items = inv.query(template.get()).poll(item.peek().get().getQuantity());
if (items.isPresent()) {
invChest.offer(items.get());
} else {
return false;
}
}
}
}
UniqueAccount sellerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
TransactionResult result = sellerAccount.deposit(getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
if (result.getResult() != ResultType.SUCCESS) {
player.sendMessage(Text.of(TextColors.DARK_RED, "Unable to give you the money!"));
return false;
}
ShopsLogs.log(getOwner(), player, "sell", super.getLocation(), Optional.of(price), getRawCurrency(), Optional.of(itemsTemplate), Optional.empty());
Text report = Text.of(" sold", itemsName.build(), " for ", formatPrice(price));
player.sendMessage(Text.of("You", report));
if (!CarrotShop.noSpam(getOwner())) {
Optional<Player> seller = Sponge.getServer().getPlayer(getOwner());
if (seller.isPresent()) {
seller.get().sendMessage(Text.of(player.getName(), report));
}
}
update();
return true;
}
示例5: trigger
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public boolean trigger(Player player) {
Inventory inv = player.getInventory().query(InventoryRow.class);
if (!hasEnough(inv, itemsTemplate)) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You don't have the items to sell!"));
return false;
}
Optional<TileEntity> chest = sellerChest.getTileEntity();
if (chest.isPresent() && chest.get() instanceof TileEntityCarrier) {
Inventory chestInv = ((TileEntityCarrier) chest.get()).getInventory();
if (chestInv.capacity() - chestInv.size() < itemsTemplate.size()) {
player.sendMessage(Text.of(TextColors.GOLD, "This shop is full!"));
update();
return false;
}
}
UniqueAccount buyerAccount = CarrotShop.getEcoService().getOrCreateAccount(getOwner()).get();
if (buyerAccount.getBalance(getCurrency()).compareTo(BigDecimal.valueOf(price)) < 0) {
player.sendMessage(Text.of(TextColors.DARK_RED, "Shop owner don't have enough money!"));
return false;
}
Inventory invChest = ((TileEntityCarrier) chest.get()).getInventory();
Builder itemsName = Text.builder();
for (Inventory item : itemsTemplate.slots()) {
if (item.peek().isPresent()) {
Optional<ItemStack> template = getTemplate(inv, item.peek().get());
if (template.isPresent()) {
itemsName.append(Text.of(TextColors.YELLOW, " ", item.peek().get().getTranslation().get(), " x", item.peek().get().getQuantity()));
Optional<ItemStack> items = inv.query(template.get()).poll(item.peek().get().getQuantity());
if (items.isPresent()) {
invChest.offer(items.get());
} else {
return false;
}
}
}
}
UniqueAccount sellerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
TransactionResult result = buyerAccount.transfer(sellerAccount, getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
if (result.getResult() != ResultType.SUCCESS) {
player.sendMessage(Text.of(TextColors.DARK_RED, "Shop owner don't have enough money!"));
return false;
}
ShopsLogs.log(getOwner(), player, "sell", super.getLocation(), Optional.of(price), getRawCurrency(), Optional.of(itemsTemplate), Optional.empty());
Text report = Text.of(" sold", itemsName.build(), " for ", formatPrice(price));
player.sendMessage(Text.of("You", report));
if (!CarrotShop.noSpam(getOwner())) {
Optional<Player> seller = Sponge.getServer().getPlayer(getOwner());
if (seller.isPresent()) {
seller.get().sendMessage(Text.of(player.getName(), report));
}
}
update();
return true;
}