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);
}
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)));
}
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);
}
Aggregations