Search in sources :

Example 11 with PacketPlayOutEntityHeadRotation

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation in project SilkSpawners by timbru31.

the class NMSHandler method spawnEntity.

@Override
public void spawnEntity(final org.bukkit.World w, final String entityID, final double x, final double y, final double z, final Player player) {
    final NBTTagCompound tag = new NBTTagCompound();
    tag.setString("id", entityID);
    final World world = ((CraftWorld) w).getHandle();
    final Entity entity = EntityTypes.a(tag, world);
    if (entity == null) {
        Bukkit.getLogger().warning("[SilkSpawners] Failed to spawn, falling through. You should report this (entity == null)!");
        return;
    }
    final float yaw = world.random.nextFloat() * (-180 - 180) + 180;
    entity.setPositionRotation(x, y, z, yaw, 0);
    world.addEntity(entity, SpawnReason.SPAWNER_EGG);
    final PacketPlayOutEntityHeadRotation rotation = new PacketPlayOutEntityHeadRotation(entity, (byte) yaw);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(rotation);
}
Also used : Entity(net.minecraft.server.v1_10_R1.Entity) NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_10_R1.PacketPlayOutEntityHeadRotation) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) CraftWorld(org.bukkit.craftbukkit.v1_10_R1.CraftWorld) World(net.minecraft.server.v1_10_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_10_R1.CraftWorld)

Example 12 with PacketPlayOutEntityHeadRotation

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation in project SilkSpawners by timbru31.

the class NMSHandler method spawnEntity.

@Override
public void spawnEntity(final org.bukkit.World w, final String entityID, final double x, final double y, final double z, final Player player) {
    final NBTTagCompound tag = new NBTTagCompound();
    tag.setString("id", entityID);
    final World world = ((CraftWorld) w).getHandle();
    final Entity entity = EntityTypes.a(tag, world);
    if (entity == null) {
        Bukkit.getLogger().warning("[SilkSpawners] Failed to spawn, falling through. You should report this (entity == null)!");
        return;
    }
    final float yaw = world.random.nextFloat() * (-180 - 180) + 180;
    entity.setPositionRotation(x, y, z, yaw, 0);
    world.addEntity(entity, SpawnReason.SPAWNER_EGG);
    final PacketPlayOutEntityHeadRotation rotation = new PacketPlayOutEntityHeadRotation(entity, (byte) yaw);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(rotation);
}
Also used : Entity(net.minecraft.server.v1_11_R1.Entity) NBTTagCompound(net.minecraft.server.v1_11_R1.NBTTagCompound) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_11_R1.PacketPlayOutEntityHeadRotation) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) World(net.minecraft.server.v1_11_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld)

Example 13 with PacketPlayOutEntityHeadRotation

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

the class PlayerNPC116R3 method rotateHead.

public void rotateHead(float pitch, float yaw) {
    PacketPlayOutEntity.PacketPlayOutEntityLook packet = new PacketPlayOutEntity.PacketPlayOutEntityLook(handle.getId(), getPacketRotation(yaw), getPacketRotation(pitch), true);
    PacketPlayOutEntityHeadRotation packet_1 = new PacketPlayOutEntityHeadRotation();
    this.setField(packet_1, "a", handle.getId());
    this.setField(packet_1, "b", getPacketRotation(yaw));
    this.sendPacket(packet);
    this.sendPacket(packet_1);
}
Also used : PacketPlayOutEntityLook(net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook) PacketPlayOutEntity(net.minecraft.server.v1_16_R3.PacketPlayOutEntity) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation) PacketPlayOutEntityLook(net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 14 with PacketPlayOutEntityHeadRotation

use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation 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 15 with PacketPlayOutEntityHeadRotation

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

PacketPlayOutEntityLook (net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)5 PacketPlayOutEntityHeadRotation (net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation)5 PacketPlayOutEntityTeleport (net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport)3 PacketPlayOutRelEntityMoveLook (net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)2 Entity (net.minecraft.server.v1_10_R1.Entity)1 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)1 PacketPlayOutEntityHeadRotation (net.minecraft.server.v1_10_R1.PacketPlayOutEntityHeadRotation)1 World (net.minecraft.server.v1_10_R1.World)1 Entity (net.minecraft.server.v1_11_R1.Entity)1 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)1 PacketPlayOutEntityHeadRotation (net.minecraft.server.v1_11_R1.PacketPlayOutEntityHeadRotation)1 World (net.minecraft.server.v1_11_R1.World)1 Entity (net.minecraft.server.v1_12_R1.Entity)1 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)1 PacketPlayOutEntityHeadRotation (net.minecraft.server.v1_12_R1.PacketPlayOutEntityHeadRotation)1 World (net.minecraft.server.v1_12_R1.World)1 Entity (net.minecraft.server.v1_13_R2.Entity)1 NBTTagCompound (net.minecraft.server.v1_13_R2.NBTTagCompound)1 PacketPlayOutEntityHeadRotation (net.minecraft.server.v1_13_R2.PacketPlayOutEntityHeadRotation)1 World (net.minecraft.server.v1_13_R2.World)1