Search in sources :

Example 1 with PacketPlayOutEntityTeleport

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

the class PlayerNPC116R3 method spawnFor.

public void spawnFor(Player player) {
    if (isDestroyed)
        return;
    // resync
    location = getEntity().getLocation();
    location.setYaw(originalYaw);
    handle.setCustomNameVisible(false);
    sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, handle), player);
    sync(() -> sendPacket(new PacketPlayOutNamedEntitySpawn(handle), player), 1);
    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", getPacketRotation(location.getYaw()));
    setField(tp, "f", getPacketRotation(location.getPitch()));
    setField(tp, "g", handle.isOnGround());
    sync(() -> sendPacket(new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true), player), 2);
    sync(() -> setTablistName(getTablistName()), 2);
    sync(() -> sendPacket(tp, player), 3);
    sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, getPacketRotation(location.getYaw())), player), 6);
    sync(() -> removeFromTablistFor(player), 20 + (int) Math.ceil(2 * bridge.getPing(player) * 20 / 1000));
    lastSeenLocation.put(player, location.clone());
    // https://www.spigotmc.org/threads/remove-nameplate-of-an-nms-player-entity.436099/ (Phaze)
    ScoreboardTeam team = new ScoreboardTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), player.getName());
    team.setNameTagVisibility(ScoreboardTeamBase.EnumNameTagVisibility.NEVER);
    sendPacket(new PacketPlayOutScoreboardTeam(team, 1), player);
    sendPacket(new PacketPlayOutScoreboardTeam(team, 0), player);
    sendPacket(new PacketPlayOutScoreboardTeam(team, List.of(handle.getName()), 3), player);
}
Also used : PacketPlayOutScoreboardTeam(net.minecraft.server.v1_16_R3.PacketPlayOutScoreboardTeam) PacketPlayOutNamedEntitySpawn(net.minecraft.server.v1_16_R3.PacketPlayOutNamedEntitySpawn) PacketPlayOutEntityMetadata(net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation) PacketPlayOutPlayerInfo(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo) PacketPlayOutEntityTeleport(net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport) PacketPlayOutScoreboardTeam(net.minecraft.server.v1_16_R3.PacketPlayOutScoreboardTeam) ScoreboardTeam(net.minecraft.server.v1_16_R3.ScoreboardTeam)

Example 2 with PacketPlayOutEntityTeleport

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

the class PlayerNPC116R3 method refreshRotationFor.

public void refreshRotationFor(Player player) {
    // resync
    location = getEntity().getLocation();
    location.setYaw(originalYaw);
    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", getPacketRotation(location.getYaw()));
    setField(tp, "f", getPacketRotation(location.getPitch()));
    setField(tp, "g", handle.isOnGround());
    PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(getEntityId(), getPacketRotation(location.getYaw()), getPacketRotation(location.getPitch()), handle.isOnGround());
    sync(() -> sendPacket(tp, player));
    sync(() -> sendPacket(look, player));
    sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, getPacketRotation(location.getYaw())), player));
}
Also used : PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation) PacketPlayOutEntityTeleport(net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport) PacketPlayOutEntityLook(net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 3 with PacketPlayOutEntityTeleport

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

the class PlayerNPC116R3 method teleport.

public void teleport(Location location, boolean onGround) {
    PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport();
    this.setField(packet, "a", handle.getId());
    this.setField(packet, "b", location.getX());
    this.setField(packet, "c", location.getY());
    this.setField(packet, "d", location.getZ());
    this.setField(packet, "e", getPacketRotation(location.getYaw()));
    this.setField(packet, "f", getPacketRotation(location.getPitch()));
    this.setField(packet, "g", onGround);
    this.sendPacket(packet);
    this.rotateHead(location.getPitch(), location.getYaw());
    this.location = location;
}
Also used : PacketPlayOutEntityTeleport(net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport)

Example 4 with PacketPlayOutEntityTeleport

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport 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)

Aggregations

PacketPlayOutEntityTeleport (net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport)4 PacketPlayOutEntityHeadRotation (net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation)3 PacketPlayOutEntityLook (net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)1 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)1 PacketPlayOutEntityMetadata (net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata)1 PacketPlayOutNamedEntitySpawn (net.minecraft.server.v1_16_R3.PacketPlayOutNamedEntitySpawn)1 PacketPlayOutPlayerInfo (net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo)1 PacketPlayOutScoreboardTeam (net.minecraft.server.v1_16_R3.PacketPlayOutScoreboardTeam)1 ScoreboardTeam (net.minecraft.server.v1_16_R3.ScoreboardTeam)1 Vector (org.bukkit.util.Vector)1