Search in sources :

Example 1 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PCSpawnPositionPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerSpawnPositionPacket packet) {
    CachedEntity entity = session.getEntityCache().getClientEntity();
    entity.spawnPosition = new BlockPosition(packet.getPosition());
    SetSpawnPositionPacket pk = new SetSpawnPositionPacket();
    pk.position = entity.spawnPosition;
    return new PEPacket[] {};
}
Also used : SetSpawnPositionPacket(org.dragonet.protocol.packets.SetSpawnPositionPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) BlockPosition(org.dragonet.common.maths.BlockPosition) PEPacket(org.dragonet.protocol.PEPacket)

Example 2 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PCUpdateHealthPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlayerHealthPacket packet) {
    // Always round up
    int newHealth = (int) Math.ceil(packet.getHealth());
    SetHealthPacket h = new SetHealthPacket(newHealth);
    CachedEntity peSelfPlayer = session.getEntityCache().getClientEntity();
    peSelfPlayer.attributes.put(PEEntityAttribute.HEALTH, PEEntityAttribute.findAttribute(PEEntityAttribute.HEALTH).setValue(newHealth));
    if (peSelfPlayer.foodPacketCount == 0) {
        peSelfPlayer.attributes.put(PEEntityAttribute.FOOD, PEEntityAttribute.findAttribute(PEEntityAttribute.FOOD).setValue(packet.getFood()));
    }
    UpdateAttributesPacket pk = new UpdateAttributesPacket();
    pk.rtid = peSelfPlayer.proxyEid;
    pk.entries = peSelfPlayer.attributes.values();
    if (newHealth <= 0)
        return new PEPacket[] { h, pk, new RespawnPacket() };
    return new PEPacket[] { h, pk };
}
Also used : SetHealthPacket(org.dragonet.protocol.packets.SetHealthPacket) UpdateAttributesPacket(org.dragonet.protocol.packets.UpdateAttributesPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) PEPacket(org.dragonet.protocol.PEPacket) RespawnPacket(org.dragonet.protocol.packets.RespawnPacket)

Example 3 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PCUpdateTimePacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerUpdateTimePacket packet) {
    SetTimePacket pk = new SetTimePacket();
    pk.time = (int) Math.abs(packet.getTime());
    return new PEPacket[] { pk };
}
Also used : PEPacket(org.dragonet.protocol.PEPacket) SetTimePacket(org.dragonet.protocol.packets.SetTimePacket)

Example 4 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PCEntityPositionRotationPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityPositionRotationPacket 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.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), 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 5 with PEPacket

use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.

the class PCPlaySoundPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlaySoundPacket packet) {
    try {
        String soundName;
        if (BuiltinSound.class.isAssignableFrom(packet.getSound().getClass())) {
            BuiltinSound sound = (BuiltinSound) packet.getSound();
            soundName = sound.name();
        } else {
            soundName = ((CustomSound) packet.getSound()).getName();
        }
        if (soundName == null) {
            return null;
        }
        PlaySoundPacket pk = new PlaySoundPacket();
        pk.blockPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ());
        pk.name = soundName;
        pk.volume = packet.getVolume();
        pk.pitch = packet.getPitch();
        return new PEPacket[] { pk };
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) PEPacket(org.dragonet.protocol.PEPacket) BuiltinSound(com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound) PlaySoundPacket(org.dragonet.protocol.packets.PlaySoundPacket) ServerPlaySoundPacket(com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket)

Aggregations

PEPacket (org.dragonet.protocol.PEPacket)28 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)14 Vector3F (org.dragonet.common.maths.Vector3F)8 MoveEntityPacket (org.dragonet.protocol.packets.MoveEntityPacket)5 BlockPosition (org.dragonet.common.maths.BlockPosition)4 UpdateAttributesPacket (org.dragonet.protocol.packets.UpdateAttributesPacket)3 MobEffectPacket (org.dragonet.protocol.packets.MobEffectPacket)2 Timing (co.aikar.timings.Timing)1 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 Attribute (com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute)1 GameMode (com.github.steveice10.mc.protocol.data.game.entity.player.GameMode)1 ExplodedBlockRecord (com.github.steveice10.mc.protocol.data.game.world.block.ExplodedBlockRecord)1 BuiltinSound (com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound)1 TranslationMessage (com.github.steveice10.mc.protocol.data.message.TranslationMessage)1 ServerPlaySoundPacket (com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket)1 JsonParseException (com.google.gson.JsonParseException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 PocketPotionEffect (org.dragonet.common.data.PocketPotionEffect)1 PEEntityAttribute (org.dragonet.common.data.entity.PEEntityAttribute)1