Search in sources :

Example 21 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class PCEntityTeleportPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityTeleportPacket 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;
        }
    }
    entity.absoluteMove(packet.getX(), packet.getY(), packet.getZ(), packet.getYaw(), packet.getPitch());
    if (entity.shouldMove) {
        MoveEntityPacket pk = new MoveEntityPacket();
        pk.rtid = entity.proxyEid;
        pk.yaw = (byte) (entity.yaw / (360d / 256d));
        pk.headYaw = (byte) (entity.headYaw / (360d / 256d));
        pk.pitch = (byte) (entity.pitch / (360d / 256d));
        pk.position = new Vector3F((float) entity.x, (float) entity.y + entity.peType.getOffset(), (float) entity.z);
        pk.onGround = packet.isOnGround();
        entity.shouldMove = false;
        return new PEPacket[] { pk };
    }
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Vector3F(org.dragonet.common.maths.Vector3F) PEPacket(org.dragonet.protocol.PEPacket) MoveEntityPacket(org.dragonet.protocol.packets.MoveEntityPacket)

Example 22 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class PCSpawnPaintingPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerSpawnPaintingPacket packet) {
    CachedEntity entity = session.getEntityCache().newEntity(packet);
    if (entity == null)
        return null;
    entity.spawn(session);
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity)

Example 23 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity 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)

Example 24 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class PCEntityHeadLookPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityHeadLookPacket 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;
        }
    }
    entity.headYaw = packet.getHeadYaw();
    MoveEntityPacket pk = new MoveEntityPacket();
    pk.rtid = entity.proxyEid;
    pk.yaw = (byte) (entity.yaw / (360d / 256d));
    pk.headYaw = (byte) (entity.headYaw / (360d / 256d));
    pk.pitch = (byte) (entity.pitch / (360d / 256d));
    pk.position = new Vector3F((float) entity.x, (float) entity.y + entity.peType.getOffset(), (float) entity.z);
    pk.onGround = true;
    return new PEPacket[] { pk };
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Vector3F(org.dragonet.common.maths.Vector3F) PEPacket(org.dragonet.protocol.PEPacket) MoveEntityPacket(org.dragonet.protocol.packets.MoveEntityPacket)

Example 25 with CachedEntity

use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.

the class PCSpawnExpOrbPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerSpawnExpOrbPacket packet) {
    CachedEntity entity = session.getEntityCache().newEntity(packet);
    if (entity == null)
        return null;
    if (session.isSpawned()) {
        SpawnExperienceOrb spawnXpOrb = new SpawnExperienceOrb();
        spawnXpOrb.position = new Vector3F((float) entity.x, (float) entity.y + entity.peType.getOffset(), (float) entity.z);
        spawnXpOrb.count = packet.getExp();
        entity.spawned = true;
        session.sendPacket(spawnXpOrb);
    }
    return null;
}
Also used : CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) SpawnExperienceOrb(org.dragonet.protocol.packets.SpawnExperienceOrb) Vector3F(org.dragonet.common.maths.Vector3F)

Aggregations

CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)26 PEPacket (org.dragonet.protocol.PEPacket)14 Vector3F (org.dragonet.common.maths.Vector3F)9 BlockPosition (org.dragonet.common.maths.BlockPosition)5 MoveEntityPacket (org.dragonet.protocol.packets.MoveEntityPacket)5 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)3 ArrayList (java.util.ArrayList)2 MobEffectPacket (org.dragonet.protocol.packets.MobEffectPacket)2 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)1 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 InteractAction (com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction)1 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)1 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)1 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)1 ClientPlayerInteractEntityPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket)1 ClientPlayerPlaceBlockPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket)1 ClientPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket)1 ClientPlayerSwingArmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket)1