本文整理汇总了Java中org.spongepowered.api.item.inventory.Inventory.slots方法的典型用法代码示例。如果您正苦于以下问题:Java Inventory.slots方法的具体用法?Java Inventory.slots怎么用?Java Inventory.slots使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.item.inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.slots方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getInventory
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public Inventory getInventory() {
Inventory woop = Inventory.builder()
.property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9,1))
.property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(Text.of(TextColors.DARK_RED,"INVALID CRATE TYPE!")))
.listener(InteractInventoryEvent.class, evt ->{
if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof InteractInventoryEvent.Close)){
evt.setCancelled(true);
}
//System.out.println(evt.getClass());
})
.build(plugin);
woop.offer(ItemStack.of(ItemTypes.BARRIER,256*2 + 64));
for(Inventory e : woop.slots()){
ItemStack b = e.peek().get();
b.setQuantity(1);
e.set(b);
}
return woop;
}
示例3: 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) {}
}
示例4: getFrom
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
/** Tries to take a certain amount of items represented by this item from the inventory
* @param quantity the amount of items supposed to take, overriding the default in item
* @returns the amount of items taken out of the inventory */
public int getFrom(Inventory inv, int quantity) {
int ammountLeft = quantity;
Inventory result = inv.queryAny(item);
for (Inventory s : result.slots()) {
ItemStack onSlot = s.poll(ammountLeft).orElse(null);
if (onSlot == null)continue;
if (onSlot.getQuantity()<=ammountLeft) {
ammountLeft -= onSlot.getQuantity();
} else {
onSlot.setQuantity(onSlot.getQuantity()-ammountLeft);
ammountLeft = 0;
s.offer(onSlot);
}
if (ammountLeft == 0) break;
}
return quantity-ammountLeft;
}
示例5: serialize
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的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);
}
示例6: invToArray
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
private static JsonArray invToArray(Inventory inv) {
JsonArray array = new JsonArray();
for (Inventory slot : inv.slots()) {
if (slot.peek().isPresent()) {
JsonObject item = new JsonObject();
item.addProperty("id", slot.peek().get().getItem().getId());
item.addProperty("name", slot.peek().get().getTranslation().get());
item.addProperty("quantity", slot.peek().get().getQuantity());
array.add(item);
}
}
return array;
}
示例7: serialize
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public void serialize(TypeToken<?> type, Inventory obj, ConfigurationNode value) throws ObjectMappingException {
ConfigurationNode items = value.getNode("items");
for (Inventory slot : obj.slots()) {
if (slot.peek().isPresent()) {
ConfigurationNode item = items.getAppendedNode();
item.setValue(TypeToken.of(ItemStack.class), slot.peek().get());
}
}
}
示例8: 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);
}
示例9: 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;
}
示例10: 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();
}
示例11: 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);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}