Search in sources :

Example 1 with InventoryContentPacket

use of cn.nukkit.network.protocol.InventoryContentPacket in project Nukkit by Nukkit.

the class BaseInventory method sendContents.

@Override
public void sendContents(Player... players) {
    InventoryContentPacket pk = new InventoryContentPacket();
    pk.slots = new Item[this.getSize()];
    for (int i = 0; i < this.getSize(); ++i) {
        pk.slots[i] = this.getItem(i);
    }
    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1 || !player.spawned) {
            this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk);
    }
}
Also used : Player(cn.nukkit.Player) InventoryContentPacket(cn.nukkit.network.protocol.InventoryContentPacket)

Example 2 with InventoryContentPacket

use of cn.nukkit.network.protocol.InventoryContentPacket in project Nukkit by Nukkit.

the class PlayerInventory method sendArmorContents.

public void sendArmorContents(Player[] players) {
    Item[] armor = this.getArmorContents();
    MobArmorEquipmentPacket pk = new MobArmorEquipmentPacket();
    pk.eid = this.getHolder().getId();
    pk.slots = armor;
    pk.encode();
    pk.isEncoded = true;
    for (Player player : players) {
        if (player.equals(this.getHolder())) {
            InventoryContentPacket pk2 = new InventoryContentPacket();
            pk2.inventoryId = InventoryContentPacket.SPECIAL_ARMOR;
            pk2.slots = armor;
            player.dataPacket(pk2);
        } else {
            player.dataPacket(pk);
        }
    }
}
Also used : Item(cn.nukkit.item.Item) Player(cn.nukkit.Player) MobArmorEquipmentPacket(cn.nukkit.network.protocol.MobArmorEquipmentPacket) InventoryContentPacket(cn.nukkit.network.protocol.InventoryContentPacket)

Example 3 with InventoryContentPacket

use of cn.nukkit.network.protocol.InventoryContentPacket in project Nukkit by Nukkit.

the class PlayerInventory method sendCreativeContents.

public void sendCreativeContents() {
    if (!(this.getHolder() instanceof Player)) {
        return;
    }
    Player p = (Player) this.getHolder();
    InventoryContentPacket pk = new InventoryContentPacket();
    pk.inventoryId = ContainerIds.CREATIVE;
    if (!p.isSpectator()) {
        // fill it for all gamemodes except spectator
        pk.slots = Item.getCreativeItems().stream().toArray(Item[]::new);
    }
    p.dataPacket(pk);
}
Also used : Item(cn.nukkit.item.Item) Player(cn.nukkit.Player) InventoryContentPacket(cn.nukkit.network.protocol.InventoryContentPacket)

Example 4 with InventoryContentPacket

use of cn.nukkit.network.protocol.InventoryContentPacket in project Nukkit by Nukkit.

the class PlayerInventory method sendContents.

@Override
public void sendContents(Player[] players) {
    InventoryContentPacket pk = new InventoryContentPacket();
    pk.slots = new Item[this.getSize()];
    for (int i = 0; i < this.getSize(); ++i) {
        pk.slots[i] = this.getItem(i);
    }
    for (Player player : players) {
        int id = player.getWindowId(this);
        if (id == -1 || !player.spawned) {
            this.close(player);
            continue;
        }
        pk.inventoryId = id;
        player.dataPacket(pk.clone());
    }
}
Also used : Player(cn.nukkit.Player) InventoryContentPacket(cn.nukkit.network.protocol.InventoryContentPacket)

Aggregations

Player (cn.nukkit.Player)4 InventoryContentPacket (cn.nukkit.network.protocol.InventoryContentPacket)4 Item (cn.nukkit.item.Item)2 MobArmorEquipmentPacket (cn.nukkit.network.protocol.MobArmorEquipmentPacket)1