Search in sources :

Example 1 with ClientVehicleMovePacket

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

the class PEMovePlayerPacketTranslator method translate.

public Packet[] translate(UpstreamSession session, MovePlayerPacket packet) {
    CachedEntity entity = session.getEntityCache().getClientEntity();
    if (entity.riding != 0 && packet.ridingRuntimeId != 0) {
        // Riding case
        ClientVehicleMovePacket pk = new ClientVehicleMovePacket(packet.position.x, packet.position.y - EntityType.PLAYER.getOffset(), packet.position.z, packet.yaw, packet.pitch);
        session.getDownstream().send(pk);
    } else {
        // not riding
        ClientPlayerPositionRotationPacket pk = new ClientPlayerPositionRotationPacket(packet.onGround, packet.position.x, // To simplify the movements
        ceilToHalf(packet.position.y - EntityType.PLAYER.getOffset()), packet.position.z, packet.yaw, packet.pitch);
        // Special blocks handling
        boolean isColliding = false;
        BlockPosition blockPos = new BlockPosition(NukkitMath.floorDouble(packet.position.x), NukkitMath.floorDouble(packet.position.y), NukkitMath.floorDouble(packet.position.z));
        // System.out.println("block " + blockPos.toString());
        try {
            ItemEntry PEBlock = session.getChunkCache().translateBlock(blockPos.asPosition());
            if (PEBlock != null) {
                Block b = Block.get(PEBlock.getId(), PEBlock.getPEDamage(), blockPos);
                if (b != null && b.collidesWithBB(session.getEntityCache().getClientEntity().boundingBox.clone())) {
                    DragonProxy.getInstance().getLogger().info("Player position : " + entity.x + ", " + entity.y + ", " + entity.z + " collide with " + b.getClass().getSimpleName() + " on " + blockPos.toString());
                    isColliding = true;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        entity.absoluteMove(pk.getX(), pk.getY(), pk.getZ(), (float) pk.getYaw(), (float) pk.getPitch());
        if (!isColliding) {
            session.getDownstream().send(pk);
            session.getChunkCache().sendOrderedChunks();
        }
    }
    return null;
}
Also used : ClientVehicleMovePacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) BlockPosition(org.dragonet.common.maths.BlockPosition) ClientPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket) Block(org.dragonet.common.data.blocks.Block) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Aggregations

ClientPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket)1 ClientVehicleMovePacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket)1 Block (org.dragonet.common.data.blocks.Block)1 ItemEntry (org.dragonet.common.data.itemsblocks.ItemEntry)1 BlockPosition (org.dragonet.common.maths.BlockPosition)1 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)1