Search in sources :

Example 16 with PEPacket

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

the class PCEntityVelocityPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerEntityVelocityPacket 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.motionX = packet.getMotionX();
    entity.motionY = packet.getMotionY();
    entity.motionZ = packet.getMotionZ();
    SetEntityMotionPacket pk = new SetEntityMotionPacket();
    pk.rtid = entity.proxyEid;
    pk.motion = new Vector3F((float) packet.getMotionX(), (float) packet.getMotionY(), (float) packet.getMotionZ());
    return new PEPacket[] { pk };
}
Also used : SetEntityMotionPacket(org.dragonet.protocol.packets.SetEntityMotionPacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Vector3F(org.dragonet.common.maths.Vector3F) PEPacket(org.dragonet.protocol.PEPacket)

Example 17 with PEPacket

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

the class PCNotifyClientPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerNotifyClientPacket packet) {
    switch(packet.getNotification()) {
        case CHANGE_GAMEMODE:
            GameMode gm = (GameMode) packet.getValue();
            SetPlayerGameTypePacket pkgm = new SetPlayerGameTypePacket();
            pkgm.gamemode = gm == GameMode.CREATIVE ? 1 : 0;
            AdventureSettingsPacket adv = new AdventureSettingsPacket();
            adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, gm.equals(GameMode.ADVENTURE));
            adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, gm.equals(GameMode.CREATIVE) || gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.NO_CLIP, gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !gm.equals(GameMode.SPECTATOR) || !gm.equals(GameMode.ADVENTURE));
            adv.setFlag(AdventureSettingsPacket.FLYING, gm.equals(GameMode.SPECTATOR));
            adv.setFlag(AdventureSettingsPacket.MUTED, false);
            adv.eid = session.getEntityCache().getClientEntity().proxyEid;
            adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL;
            adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER;
            session.sendPacket(pkgm);
            session.sendPacket(adv);
            if (gm == GameMode.CREATIVE)
                session.sendCreativeInventory();
            break;
        case START_RAIN:
            LevelEventPacket evtStartRain = new LevelEventPacket();
            evtStartRain.eventId = LevelEventPacket.EVENT_START_RAIN;
            return new PEPacket[] { evtStartRain };
        case STOP_RAIN:
            LevelEventPacket evtStopRain = new LevelEventPacket();
            evtStopRain.eventId = LevelEventPacket.EVENT_STOP_RAIN;
            return new PEPacket[] { evtStopRain };
    }
    return null;
}
Also used : SetPlayerGameTypePacket(org.dragonet.protocol.packets.SetPlayerGameTypePacket) GameMode(com.github.steveice10.mc.protocol.data.game.entity.player.GameMode) AdventureSettingsPacket(org.dragonet.protocol.packets.AdventureSettingsPacket) LevelEventPacket(org.dragonet.protocol.packets.LevelEventPacket) PEPacket(org.dragonet.protocol.PEPacket)

Example 18 with PEPacket

use of org.dragonet.protocol.PEPacket 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)

Example 19 with PEPacket

use of org.dragonet.protocol.PEPacket 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 20 with PEPacket

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

the class PCExplosionTranslator method translate.

@Override
public PEPacket[] translate(UpstreamSession session, ServerExplosionPacket packet) {
    ExplodePacket pk = new ExplodePacket();
    pk.position = new Vector3F(packet.getX(), packet.getY(), packet.getZ());
    pk.radius = packet.getRadius();
    pk.destroyedBlocks = new ArrayList<>(packet.getExploded().size());
    for (ExplodedBlockRecord record : packet.getExploded()) pk.destroyedBlocks.add(new BlockPosition(record.getX(), record.getY(), record.getZ()));
    return new PEPacket[] { pk };
}
Also used : ExplodedBlockRecord(com.github.steveice10.mc.protocol.data.game.world.block.ExplodedBlockRecord) Vector3F(org.dragonet.common.maths.Vector3F) BlockPosition(org.dragonet.common.maths.BlockPosition) PEPacket(org.dragonet.protocol.PEPacket) ExplodePacket(org.dragonet.protocol.packets.ExplodePacket)

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