Search in sources :

Example 1 with MessagePlayOutWindowItems

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutWindowItems in project LanternServer by LanternPowered.

the class ClientContainer method init.

/**
 * Initializes the container for the bounded {@link Player}.
 */
public void init() {
    checkState(this.player != null);
    populate();
    final List<Message> messages = new ArrayList<>();
    final Message message = createInitMessage();
    if (message != null) {
        messages.add(message);
    }
    final ItemStack[] items = new ItemStack[getSlotFlags().length];
    for (int i = 0; i < items.length; i++) {
        items[serverSlotIndexToClient(i)] = this.slots[i].getItem();
        this.slots[i].dirtyState = 0;
    }
    // Send the inventory content
    messages.add(new MessagePlayOutWindowItems(this.containerId, items));
    // Send the cursor item if present
    if (!this.cursor.getRaw().isEmpty()) {
        messages.add(new MessagePlayOutSetWindowSlot(-1, -1, this.cursor.getItem()));
        this.cursor.dirtyState = 0;
    }
    // Collect additional messages
    collectInitMessages(messages);
    // Stream the messages to the player
    this.player.getConnection().send(messages);
}
Also used : MessagePlayOutSetWindowSlot(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetWindowSlot) Message(org.lanternpowered.server.network.message.Message) MessagePlayOutWindowItems(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutWindowItems) ArrayList(java.util.ArrayList) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Aggregations

ArrayList (java.util.ArrayList)1 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)1 Message (org.lanternpowered.server.network.message.Message)1 MessagePlayOutSetWindowSlot (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetWindowSlot)1 MessagePlayOutWindowItems (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutWindowItems)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1