Search in sources :

Example 1 with MobEffectPacket

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

the class PCEntityRemoveEffectPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityRemoveEffectPacket 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;
        }
    }
    int effectId = MagicValues.value(Integer.class, packet.getEffect());
    if (!entity.effects.contains(effectId)) {
        return null;
    }
    MobEffectPacket eff = new MobEffectPacket();
    eff.rtid = entity.proxyEid;
    eff.eventId = MobEffectPacket.EVENT_REMOVE;
    return new PEPacket[] { eff };
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket) MobEffectPacket(org.dragonet.protocol.packets.MobEffectPacket)

Example 2 with MobEffectPacket

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

the class PCEntityEffectPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityEffectPacket 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;
        }
    }
    int effectId = MagicValues.value(Integer.class, packet.getEffect());
    PocketPotionEffect effect = PocketPotionEffect.getByID(effectId);
    if (effect == null) {
        System.out.println("Unknown effect ID: " + effectId);
        return null;
    }
    MobEffectPacket eff = new MobEffectPacket();
    eff.rtid = entity.proxyEid;
    eff.effectId = effect.getEffect();
    if (entity.effects.contains(effectId)) {
        eff.eventId = MobEffectPacket.EVENT_MODIFY;
    } else {
        eff.eventId = MobEffectPacket.EVENT_ADD;
        entity.effects.add(effectId);
    }
    eff.amplifier = packet.getAmplifier();
    eff.duration = packet.getDuration();
    eff.particles = packet.getShowParticles();
    return new PEPacket[] { eff };
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PocketPotionEffect(org.dragonet.common.data.PocketPotionEffect) PEPacket(org.dragonet.protocol.PEPacket) MobEffectPacket(org.dragonet.protocol.packets.MobEffectPacket)

Aggregations

PEPacket (org.dragonet.protocol.PEPacket)2 MobEffectPacket (org.dragonet.protocol.packets.MobEffectPacket)2 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)2 PocketPotionEffect (org.dragonet.common.data.PocketPotionEffect)1