Search in sources :

Example 1 with InventoryMenu

use of org.spongepowered.api.item.inventory.menu.InventoryMenu in project SpongeCommon by SpongePowered.

the class InventoryTest method doFancyStuff.

private static void doFancyStuff(final PluginContainer plugin, final Player player) {
    final GridInventory inv27Grid = player.inventory().query(PrimaryPlayerInventory.class).get().storage();
    final Inventory inv27Slots = Inventory.builder().slots(27).completeStructure().plugin(plugin).build();
    final Inventory inv27Slots2 = Inventory.builder().slots(27).completeStructure().plugin(plugin).build();
    final ViewableInventory doubleMyInventory = ViewableInventory.builder().type(ContainerTypes.GENERIC_9X6.get()).grid(inv27Slots.slots(), Vector2i.from(9, 3), Vector2i.from(0, 0)).grid(inv27Slots2.slots(), Vector2i.from(9, 3), Vector2i.from(0, 3)).completeStructure().carrier(player).plugin(plugin).build();
    final InventoryMenu menu = doubleMyInventory.asMenu();
    menu.setReadOnly(true);
    doubleMyInventory.set(0, ItemStack.of(ItemTypes.IRON_INGOT));
    doubleMyInventory.set(8, ItemStack.of(ItemTypes.GOLD_INGOT));
    doubleMyInventory.set(45, ItemStack.of(ItemTypes.EMERALD));
    doubleMyInventory.set(53, ItemStack.of(ItemTypes.DIAMOND));
    menu.registerSlotClick(new MySlotClickHandler(plugin, menu, doubleMyInventory));
    Sponge.server().scheduler().submit(Task.builder().plugin(plugin).execute(() -> {
        menu.open((ServerPlayer) player);
    }).build());
}
Also used : ViewableInventory(org.spongepowered.api.item.inventory.type.ViewableInventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) InventoryMenu(org.spongepowered.api.item.inventory.menu.InventoryMenu) ViewableInventory(org.spongepowered.api.item.inventory.type.ViewableInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) PrimaryPlayerInventory(org.spongepowered.api.item.inventory.entity.PrimaryPlayerInventory)

Aggregations

Inventory (org.spongepowered.api.item.inventory.Inventory)1 PrimaryPlayerInventory (org.spongepowered.api.item.inventory.entity.PrimaryPlayerInventory)1 InventoryMenu (org.spongepowered.api.item.inventory.menu.InventoryMenu)1 GridInventory (org.spongepowered.api.item.inventory.type.GridInventory)1 ViewableInventory (org.spongepowered.api.item.inventory.type.ViewableInventory)1