Search in sources :

Example 1 with UpdateEquipPacket

use of com.nukkitx.protocol.bedrock.packet.UpdateEquipPacket in project Geyser by GeyserMC.

the class JavaHorseScreenOpenTranslator method translate.

@Override
public void translate(GeyserSession session, ClientboundHorseScreenOpenPacket packet) {
    Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
    if (entity == null) {
        return;
    }
    UpdateEquipPacket updateEquipPacket = new UpdateEquipPacket();
    updateEquipPacket.setWindowId((short) packet.getContainerId());
    updateEquipPacket.setWindowType((short) ContainerType.HORSE.getId());
    updateEquipPacket.setUniqueEntityId(entity.getGeyserId());
    NbtMapBuilder builder = NbtMap.builder();
    List<NbtMap> slots = new ArrayList<>();
    InventoryTranslator inventoryTranslator;
    if (entity instanceof LlamaEntity) {
        inventoryTranslator = new LlamaInventoryTranslator(packet.getNumberOfSlots());
        slots.add(CARPET_SLOT);
    } else if (entity instanceof ChestedHorseEntity) {
        inventoryTranslator = new DonkeyInventoryTranslator(packet.getNumberOfSlots());
        slots.add(SADDLE_SLOT);
    } else {
        inventoryTranslator = new HorseInventoryTranslator(packet.getNumberOfSlots());
        slots.add(SADDLE_SLOT);
        slots.add(ARMOR_SLOT);
    }
    // Build the NbtMap that sets the icons for Bedrock (e.g. sets the saddle outline on the saddle slot)
    builder.putList("slots", NbtType.COMPOUND, slots);
    updateEquipPacket.setTag(builder.build());
    session.sendUpstreamPacket(updateEquipPacket);
    session.setInventoryTranslator(inventoryTranslator);
    InventoryUtils.openInventory(session, new Container(entity.getNametag(), packet.getContainerId(), packet.getNumberOfSlots(), null, session.getPlayerInventory()));
}
Also used : LlamaEntity(org.geysermc.geyser.entity.type.living.animal.horse.LlamaEntity) Entity(org.geysermc.geyser.entity.type.Entity) ChestedHorseEntity(org.geysermc.geyser.entity.type.living.animal.horse.ChestedHorseEntity) HorseInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.HorseInventoryTranslator) InventoryTranslator(org.geysermc.geyser.translator.inventory.InventoryTranslator) DonkeyInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.DonkeyInventoryTranslator) LlamaInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.LlamaInventoryTranslator) ChestedHorseEntity(org.geysermc.geyser.entity.type.living.animal.horse.ChestedHorseEntity) NbtMap(com.nukkitx.nbt.NbtMap) ArrayList(java.util.ArrayList) NbtMapBuilder(com.nukkitx.nbt.NbtMapBuilder) UpdateEquipPacket(com.nukkitx.protocol.bedrock.packet.UpdateEquipPacket) Container(org.geysermc.geyser.inventory.Container) LlamaEntity(org.geysermc.geyser.entity.type.living.animal.horse.LlamaEntity) LlamaInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.LlamaInventoryTranslator) DonkeyInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.DonkeyInventoryTranslator) HorseInventoryTranslator(org.geysermc.geyser.translator.inventory.horse.HorseInventoryTranslator)

Aggregations

NbtMap (com.nukkitx.nbt.NbtMap)1 NbtMapBuilder (com.nukkitx.nbt.NbtMapBuilder)1 UpdateEquipPacket (com.nukkitx.protocol.bedrock.packet.UpdateEquipPacket)1 ArrayList (java.util.ArrayList)1 Entity (org.geysermc.geyser.entity.type.Entity)1 ChestedHorseEntity (org.geysermc.geyser.entity.type.living.animal.horse.ChestedHorseEntity)1 LlamaEntity (org.geysermc.geyser.entity.type.living.animal.horse.LlamaEntity)1 Container (org.geysermc.geyser.inventory.Container)1 InventoryTranslator (org.geysermc.geyser.translator.inventory.InventoryTranslator)1 DonkeyInventoryTranslator (org.geysermc.geyser.translator.inventory.horse.DonkeyInventoryTranslator)1 HorseInventoryTranslator (org.geysermc.geyser.translator.inventory.horse.HorseInventoryTranslator)1 LlamaInventoryTranslator (org.geysermc.geyser.translator.inventory.horse.LlamaInventoryTranslator)1