Search in sources :

Example 1 with ClientPlayerStatePacket

use of com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket in project DragonProxy by DragonetMC.

the class PEPlayerActionPacketTranslator method translate.

public Packet[] translate(UpstreamSession session, PlayerActionPacket packet) {
    if (packet.action == PlayerActionPacket.ACTION_RESPAWN) {
        return new Packet[] { new ClientRequestPacket(ClientRequest.RESPAWN) };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_SPRINT) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SPRINTING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SPRINT) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SPRINTING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_GLIDE) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_ELYTRA_FLYING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_GLIDE) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_ELYTRA_FLYING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_SNEAK) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SNEAKING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SNEAK) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SNEAKING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SLEEPING) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.LEAVE_BED);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_DROP_ITEM) {
        ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, new Position(0, 0, 0), BlockFace.UP);
        return new Packet[] { act };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_BREAK) {
        ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.START_DIGGING, new Position(packet.position.x, packet.position.y, packet.position.z), MagicValues.key(BlockFace.class, packet.face));
        session.getDataCache().put(CacheKey.BLOCK_BREAKING_POSITION, act.getPosition());
        return new Packet[] { act };
    }
    if (session.getDataCache().containsKey(CacheKey.BLOCK_BREAKING_POSITION)) {
        if (packet.action == PlayerActionPacket.ACTION_STOP_BREAK) {
            ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.FINISH_DIGGING, (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), MagicValues.key(BlockFace.class, packet.face));
            return new Packet[] { act };
        }
        if (packet.action == PlayerActionPacket.ACTION_ABORT_BREAK) {
            ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.CANCEL_DIGGING, (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), MagicValues.key(BlockFace.class, packet.face));
            return new Packet[] { act };
        }
    }
    return null;
}
Also used : ClientPlayerActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ClientPlayerStatePacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket) PlayerActionPacket(org.dragonet.protocol.packets.PlayerActionPacket) Packet(com.github.steveice10.packetlib.packet.Packet) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) BlockFace(com.github.steveice10.mc.protocol.data.game.world.block.BlockFace) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ClientPlayerActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket) ClientPlayerStatePacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket)

Aggregations

Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 BlockFace (com.github.steveice10.mc.protocol.data.game.world.block.BlockFace)1 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)1 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)1 ClientPlayerStatePacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket)1 Packet (com.github.steveice10.packetlib.packet.Packet)1 PlayerActionPacket (org.dragonet.protocol.packets.PlayerActionPacket)1