Search in sources :

Example 6 with PacketPlayOutRelEntityMoveLook

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method updateLocationFor.

public void updateLocationFor(Player player, float pitch, float yaw) {
    if (!lastSeenLocation.containsKey(player)) {
        spawnFor(player);
        return;
    }
    // resync
    location = getEntity().getLocation();
    location.setYaw(originalYaw);
    byte byaw = getPacketRotation(yaw);
    byte bpitch = getPacketRotation(pitch);
    Vector move = getEntity().getLocation().subtract(lastSeenLocation.get(player)).toVector();
    // since error in the dx/dy/dz's can accumulate or get desynced with the client.
    if (move.lengthSquared() > 63.996 || System.currentTimeMillis() - lastForceRefresh.getOrDefault(player, 0L) > FORCE_REFRESH_LOCATION_INTERVAL_MS) {
        PacketPlayOutEntityTeleport tp = new PacketPlayOutEntityTeleport();
        setField(tp, "a", getEntityId());
        setField(tp, "b", location.getX());
        setField(tp, "c", location.getY());
        setField(tp, "d", location.getZ());
        setField(tp, "e", byaw);
        setField(tp, "f", bpitch);
        setField(tp, "g", handle.isOnGround());
        sync(() -> sendPacket(tp, player));
        lastForceRefresh.put(player, System.currentTimeMillis());
    } else // But usually we can just send dx/dy/dz, resulting in smoother movement
    // and smaller packets
    {
        int dx = (int) move.getX() * 4096;
        int dy = (int) move.getY() * 4096;
        int dz = (int) move.getZ() * 4096;
        boolean onGround = handle.isOnGround();
        PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(getEntityId(), (short) dx, (short) dy, (short) dz, byaw, bpitch, onGround);
        sendPacket(packet, player);
    }
    sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, byaw), player));
    lastSeenLocation.put(player, location);
}
Also used : PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation) PacketPlayOutRelEntityMoveLook(net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook) PacketPlayOutEntityTeleport(net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport) Vector(org.bukkit.util.Vector)

Example 7 with PacketPlayOutRelEntityMoveLook

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_14_R1 method setPositionRotation.

@Override
public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) {
    PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(cache, dx, dy, dz, yaw, pitch, false);
    PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw));
    sendPackets(packet, head);
}
Also used : PacketPlayOutRelEntityMoveLook(net.minecraft.server.v1_14_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)

Example 8 with PacketPlayOutRelEntityMoveLook

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_9_R2 method setPositionRotation.

@Override
public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) {
    PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(cache, dx, dy, dz, yaw, pitch, false);
    PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw));
    sendPackets(packet, head);
}
Also used : PacketPlayOutRelEntityMoveLook(net.minecraft.server.v1_9_R2.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)

Example 9 with PacketPlayOutRelEntityMoveLook

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_12_R1 method setPositionRotation.

@Override
public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) {
    PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(cache, dx, dy, dz, yaw, pitch, false);
    PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw));
    sendPackets(packet, head);
}
Also used : PacketPlayOutRelEntityMoveLook(net.minecraft.server.v1_12_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)

Aggregations

PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)2 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_10_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)1 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_11_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)1 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_12_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)1 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_13_R2.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)1 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_14_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)1 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)1 PacketPlayOutEntityHeadRotation (net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation)1 PacketPlayOutEntityTeleport (net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport)1 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_9_R2.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)1 Vector (org.bukkit.util.Vector)1