Search in sources :

Example 1 with Attribute

use of com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute in project DragonProxy by DragonetMC.

the class PCEntityPropertiesPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityPropertiesPacket 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;
        }
    }
    for (Attribute attr : packet.getAttributes()) {
        switch(attr.getType()) {
            case GENERIC_FOLLOW_RANGE:
                entity.attributes.put(PEEntityAttribute.FOLLOW_RANGE, PEEntityAttribute.findAttribute(PEEntityAttribute.FOLLOW_RANGE).setValue((float) attr.getValue()));
                break;
            case GENERIC_KNOCKBACK_RESISTANCE:
                entity.attributes.put(PEEntityAttribute.KNOCKBACK_RESISTANCE, PEEntityAttribute.findAttribute(PEEntityAttribute.KNOCKBACK_RESISTANCE).setValue((float) attr.getValue()));
                break;
            case GENERIC_MOVEMENT_SPEED:
                entity.attributes.put(PEEntityAttribute.MOVEMENT_SPEED, PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED).setValue((float) attr.getValue()));
                break;
            case GENERIC_ATTACK_DAMAGE:
                entity.attributes.put(PEEntityAttribute.ATTACK_DAMAGE, PEEntityAttribute.findAttribute(PEEntityAttribute.ATTACK_DAMAGE).setValue((float) attr.getValue()));
                break;
            case GENERIC_FLYING_SPEED:
                entity.attributes.put(PEEntityAttribute.MOVEMENT_SPEED, PEEntityAttribute.findAttribute(PEEntityAttribute.MOVEMENT_SPEED).setValue((float) attr.getValue()));
                break;
        }
    }
    if (entity.spawned) {
        UpdateAttributesPacket pk = new UpdateAttributesPacket();
        pk.rtid = entity.proxyEid;
        pk.entries = entity.attributes.values();
        return new PEPacket[] { pk };
    }
    return null;
}
Also used : Attribute(com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute) PEEntityAttribute(org.dragonet.common.data.entity.PEEntityAttribute) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket)

Aggregations

Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1 PEEntityAttribute (org.dragonet.common.data.entity.PEEntityAttribute)1 PEPacket (org.dragonet.protocol.PEPacket)1 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)1 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)1