Search in sources :

Example 1 with MobEquipmentPacket

use of org.dragonet.protocol.packets.MobEquipmentPacket in project DragonProxy by DragonetMC.

the class PCEntityEquipmentPacketTranslator method translate.

@Override
public PEPacket[] translate(UpstreamSession session, ServerEntityEquipmentPacket packet) {
    CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
    if (entity == null) {
        if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) {
            entity = session.getEntityCache().getClientEntity();
        } else {
            return null;
        }
    }
    ItemStack items = packet.getItem();
    boolean handModified = false;
    switch(packet.getSlot()) {
        case HELMET:
            entity.helmet = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case CHESTPLATE:
            entity.chestplate = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case LEGGINGS:
            entity.leggings = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case BOOTS:
            entity.boots = ItemBlockTranslator.translateSlotToPE(items);
            break;
        case MAIN_HAND:
            entity.mainHand = ItemBlockTranslator.translateSlotToPE(items);
        case OFF_HAND:
            handModified = true;
            break;
    }
    entity.updateEquipment(session);
    if (handModified) {
        MobEquipmentPacket equipPacket = new MobEquipmentPacket();
        equipPacket.rtid = entity.proxyEid;
        equipPacket.item = entity.mainHand;
        equipPacket.inventorySlot = 0;
        equipPacket.hotbarSlot = 0;
        equipPacket.windowId = 0;
        session.sendPacket(equipPacket);
    }
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) ItemStack(com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack) MobEquipmentPacket(org.dragonet.protocol.packets.MobEquipmentPacket)

Aggregations

ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)1 MobEquipmentPacket (org.dragonet.protocol.packets.MobEquipmentPacket)1 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)1