Search in sources :

Example 1 with ClientPlayerPositionRotationPacket

use of com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket in project CyanBot by XjCyan1de.

the class UpdatePositionHandler method onUpdate.

@Override
public void onUpdate() {
    loc.add(speed);
    // не отправляем, если чанк не прогружен
    if (bot.getWorld().hasChunkAt(loc)) {
        boolean pos = Double.compare(prev.getX(), loc.getX()) != 0 || Double.compare(prev.getY(), loc.getY()) != 0 || Double.compare(prev.getZ(), loc.getZ()) != 0;
        boolean rot = Float.compare(prev.getPitch(), loc.getPitch()) != 0 || Float.compare(prev.getYaw(), loc.getYaw()) != 0;
        if (pos && rot) {
            bot.sendPacket(new ClientPlayerPositionRotationPacket(bot.isOnGround(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()));
        } else if (pos) {
            bot.sendPacket(new ClientPlayerPositionPacket(bot.isOnGround(), loc.getX(), loc.getY(), loc.getZ()));
        } else if (rot) {
            bot.sendPacket(new ClientPlayerRotationPacket(bot.isOnGround(), loc.getYaw(), loc.getPitch()));
        } else {
            return;
        }
        prev.set(loc);
    }
}
Also used : ClientPlayerPositionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionPacket) ClientPlayerRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerRotationPacket) ClientPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket)

Example 2 with ClientPlayerPositionRotationPacket

use of com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket 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)2 ClientPlayerPositionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionPacket)1 ClientPlayerRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerRotationPacket)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