Search in sources :

Example 1 with MessagePlayOutSetWindowSlot

use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetWindowSlot 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)

Example 2 with MessagePlayOutSetWindowSlot

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

the class LanternPlayer method sendBookView.

@Override
public void sendBookView(BookView bookView) {
    checkNotNull(bookView, "bookView");
    final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    WrittenBookItemTypeObjectSerializer.writeBookData(dataView, bookView, this.locale);
    // Written book internal id
    final RawItemStack rawItemStack = new RawItemStack(387, 0, 1, dataView);
    final int slot = this.inventory.getHotbar().getSelectedSlotIndex();
    this.session.send(new MessagePlayOutSetWindowSlot(-2, slot, rawItemStack));
    this.session.send(new MessagePlayOutOpenBook(HandTypes.MAIN_HAND));
    this.session.send(new MessagePlayOutSetWindowSlot(-2, slot, this.inventory.getHotbar().getSelectedSlot().peek().orElse(null)));
}
Also used : DataView(org.spongepowered.api.data.DataView) MessagePlayOutSetWindowSlot(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetWindowSlot) RawItemStack(org.lanternpowered.server.network.objects.RawItemStack) MessagePlayOutOpenBook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutOpenBook)

Example 3 with MessagePlayOutSetWindowSlot

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

the class ClientContainer method collectChangeMessages.

protected void collectChangeMessages(List<Message> messages) {
    final int[] flags = getSlotFlags();
    for (int i = 0; i < this.slots.length; i++) {
        final BaseClientSlot slot = this.slots[i];
        if ((slot.dirtyState & BaseClientSlot.IS_DIRTY) != 0) {
            int containerId = getContainerId();
            final int index;
            final int hotbarSlot;
            // Check if we can do a silent update
            if ((slot.dirtyState & BaseClientSlot.SILENT_UPDATE) != 0 && (hotbarSlot = (flags[i] & FLAG_HOTBAR) >> 4) != 0) {
                index = hotbarSlot - 1;
                containerId = -2;
            } else {
                index = i;
            }
            // Reset the dirty state
            slot.dirtyState = 0;
            // Add a update message
            messages.add(new MessagePlayOutSetWindowSlot(containerId, serverSlotIndexToClient(index), slot.getItem()));
        }
    }
    // Update the cursor item if needed
    if ((this.cursor.dirtyState & BaseClientSlot.IS_DIRTY) != 0) {
        messages.add(new MessagePlayOutSetWindowSlot(-1, -1, this.cursor.getItem()));
        this.cursor.dirtyState = 0;
    }
    // Collect the property changes
    collectPropertyChanges(messages);
}
Also used : MessagePlayOutSetWindowSlot(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetWindowSlot)

Aggregations

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