Skip to content

Commit

Permalink
Merge pull request #121 from Mooselk/master
Browse files Browse the repository at this point in the history
Look at location method + 1.16.x support
  • Loading branch information
Jitse Boonstra authored Nov 24, 2020
2 parents 24606bf + f709be1 commit a5e716c
Show file tree
Hide file tree
Showing 47 changed files with 1,398 additions and 109 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>npclib</artifactId>
<groupId>net.jitse</groupId>
<version>2.9-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>

<artifactId>npclib-api</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/net/jitse/npclib/api/NPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,6 @@ public interface NPC {
* @return The UUID of the NPC.
*/
UUID getUniqueId();

void lookAt(Location location);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public enum MinecraftVersion {
V1_13_R2,
V1_14_R1,
V1_15_R1,
V1_16_R1;
V1_16_R1,
V1_16_R2,
V1_16_R3;

public boolean isAboveOrEqual(MinecraftVersion compare) {
return ordinal() >= compare.ordinal();
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/net/jitse/npclib/internal/NPCBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,9 @@ public NPC setText(List<String> text) {
public List<String> getText() {
return text;
}

@Override
public void lookAt(Location location) {
sendHeadRotationPackets(location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import net.jitse.npclib.api.state.NPCAnimation;
import net.jitse.npclib.api.state.NPCSlot;

import org.bukkit.Location;
import org.bukkit.entity.Player;

/**
Expand All @@ -27,6 +29,8 @@ interface NPCPacketHandler {

void sendAnimationPacket(Player player, NPCAnimation animation);

void sendHeadRotationPackets(Location location);

default void sendEquipmentPackets(Player player) {
for (NPCSlot slot : NPCSlot.values())
sendEquipmentPacket(player, slot, true);
Expand Down
4 changes: 3 additions & 1 deletion nms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib</artifactId>
<version>2.9-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>

<artifactId>npclib-nms</artifactId>
Expand All @@ -25,6 +25,8 @@
<module>v1_14_R1</module>
<module>v1_15_R1</module>
<module>v1_16_R1</module>
<module>v1_16_R2</module>
<module>v1_16_R3</module>
</modules>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion nms/v1_10_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.9-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>

<artifactId>npclib-nms-v1_10_R1</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,43 @@

package net.jitse.npclib.nms.v1_10_R1;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;

import net.jitse.npclib.NPCLib;
import net.jitse.npclib.api.skin.Skin;
import net.jitse.npclib.api.state.NPCAnimation;
import net.jitse.npclib.api.state.NPCSlot;
import net.jitse.npclib.hologram.Hologram;
import net.jitse.npclib.internal.MinecraftVersion;
import net.jitse.npclib.internal.NPCBase;
import net.jitse.npclib.nms.v1_10_R1.packets.*;
import net.minecraft.server.v1_10_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.List;
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutAnimationWrapper;
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutEntityHeadRotationWrapper;
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutEntityMetadataWrapper;
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutPlayerInfoWrapper;
import net.jitse.npclib.nms.v1_10_R1.packets.PacketPlayOutScoreboardTeamWrapper;
import net.minecraft.server.v1_10_R1.EnumItemSlot;
import net.minecraft.server.v1_10_R1.PacketPlayOutAnimation;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntity;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityEquipment;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityHeadRotation;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_10_R1.PacketPlayOutNamedEntitySpawn;
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_10_R1.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_10_R1.PlayerConnection;

/**
* @author Jitse Boonstra
Expand Down Expand Up @@ -147,4 +166,22 @@ public void updateSkin(Skin skin) {
playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);
}
}

@Override
public void sendHeadRotationPackets(Location location) {
for (Player player : Bukkit.getOnlinePlayers()) {
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;

Location npcLocation = getLocation();
Vector dirBetweenLocations = location.toVector().subtract(npcLocation.toVector());

npcLocation.setDirection(dirBetweenLocations);

float yaw = npcLocation.getYaw();
float pitch = npcLocation.getPitch();

connection.sendPacket(new PacketPlayOutEntity.PacketPlayOutEntityLook(getEntityId(), (byte) ((yaw % 360.) * 256 / 360), (byte) ((pitch % 360.) * 256 / 360), false));
connection.sendPacket(new PacketPlayOutEntityHeadRotationWrapper().create(npcLocation, entityId));
}
}
}
2 changes: 1 addition & 1 deletion nms/v1_11_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.9-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>

<artifactId>npclib-nms-v1_11_R1</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import net.jitse.npclib.nms.v1_11_R1.packets.*;
import net.minecraft.server.v1_11_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

import java.util.List;

Expand Down Expand Up @@ -147,4 +149,22 @@ public void updateSkin(Skin skin) {
playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);
}
}

@Override
public void sendHeadRotationPackets(Location location) {
for (Player player : Bukkit.getOnlinePlayers()) {
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;

Location npcLocation = getLocation();
Vector dirBetweenLocations = location.toVector().subtract(npcLocation.toVector());

npcLocation.setDirection(dirBetweenLocations);

float yaw = npcLocation.getYaw();
float pitch = npcLocation.getPitch();

connection.sendPacket(new PacketPlayOutEntity.PacketPlayOutEntityLook(getEntityId(), (byte) ((yaw % 360.) * 256 / 360), (byte) ((pitch % 360.) * 256 / 360), false));
connection.sendPacket(new PacketPlayOutEntityHeadRotationWrapper().create(npcLocation, entityId));
}
}
}
2 changes: 1 addition & 1 deletion nms/v1_12_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.9-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>

<artifactId>npclib-nms-v1_12_R1</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,43 @@

package net.jitse.npclib.nms.v1_12_R1;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;

import net.jitse.npclib.NPCLib;
import net.jitse.npclib.api.skin.Skin;
import net.jitse.npclib.api.state.NPCAnimation;
import net.jitse.npclib.api.state.NPCSlot;
import net.jitse.npclib.hologram.Hologram;
import net.jitse.npclib.internal.MinecraftVersion;
import net.jitse.npclib.internal.NPCBase;
import net.jitse.npclib.nms.v1_12_R1.packets.*;
import net.minecraft.server.v1_12_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.List;
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutAnimationWrapper;
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutEntityHeadRotationWrapper;
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutEntityMetadataWrapper;
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutPlayerInfoWrapper;
import net.jitse.npclib.nms.v1_12_R1.packets.PacketPlayOutScoreboardTeamWrapper;
import net.minecraft.server.v1_12_R1.EnumItemSlot;
import net.minecraft.server.v1_12_R1.PacketPlayOutAnimation;
import net.minecraft.server.v1_12_R1.PacketPlayOutEntity;
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityEquipment;
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityHeadRotation;
import net.minecraft.server.v1_12_R1.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_12_R1.PacketPlayOutNamedEntitySpawn;
import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_12_R1.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_12_R1.PlayerConnection;

/**
* @author Jitse Boonstra
Expand Down Expand Up @@ -147,4 +166,23 @@ public void updateSkin(Skin skin) {
playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);
}
}

@Override
public void sendHeadRotationPackets(Location location) {
for (Player player : Bukkit.getOnlinePlayers()) {
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;

Location npcLocation = getLocation();
Vector dirBetweenLocations = location.toVector().subtract(npcLocation.toVector());

npcLocation.setDirection(dirBetweenLocations);

float yaw = npcLocation.getYaw();
float pitch = npcLocation.getPitch();

connection.sendPacket(new PacketPlayOutEntity.PacketPlayOutEntityLook(getEntityId(), (byte) ((yaw % 360.) * 256 / 360), (byte) ((pitch % 360.) * 256 / 360), false));
connection.sendPacket(new PacketPlayOutEntityHeadRotationWrapper().create(npcLocation, entityId));
}
}
}

2 changes: 1 addition & 1 deletion nms/v1_13_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.9-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>

<artifactId>npclib-nms-v1_13_R1</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,43 @@

package net.jitse.npclib.nms.v1_13_R1;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;

import net.jitse.npclib.NPCLib;
import net.jitse.npclib.api.skin.Skin;
import net.jitse.npclib.api.state.NPCAnimation;
import net.jitse.npclib.api.state.NPCSlot;
import net.jitse.npclib.hologram.Hologram;
import net.jitse.npclib.internal.MinecraftVersion;
import net.jitse.npclib.internal.NPCBase;
import net.jitse.npclib.nms.v1_13_R1.packets.*;
import net.minecraft.server.v1_13_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.List;
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutAnimationWrapper;
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutEntityHeadRotationWrapper;
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutEntityMetadataWrapper;
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutPlayerInfoWrapper;
import net.jitse.npclib.nms.v1_13_R1.packets.PacketPlayOutScoreboardTeamWrapper;
import net.minecraft.server.v1_13_R1.EnumItemSlot;
import net.minecraft.server.v1_13_R1.PacketPlayOutAnimation;
import net.minecraft.server.v1_13_R1.PacketPlayOutEntity;
import net.minecraft.server.v1_13_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_13_R1.PacketPlayOutEntityEquipment;
import net.minecraft.server.v1_13_R1.PacketPlayOutEntityHeadRotation;
import net.minecraft.server.v1_13_R1.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_13_R1.PacketPlayOutNamedEntitySpawn;
import net.minecraft.server.v1_13_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_13_R1.PacketPlayOutScoreboardTeam;
import net.minecraft.server.v1_13_R1.PlayerConnection;

/**
* @author Jitse Boonstra
Expand Down Expand Up @@ -147,4 +166,22 @@ public void updateSkin(Skin skin) {
playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);
}
}

@Override
public void sendHeadRotationPackets(Location location) {
for (Player player : Bukkit.getOnlinePlayers()) {
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;

Location npcLocation = getLocation();
Vector dirBetweenLocations = location.toVector().subtract(npcLocation.toVector());

npcLocation.setDirection(dirBetweenLocations);

float yaw = npcLocation.getYaw();
float pitch = npcLocation.getPitch();

connection.sendPacket(new PacketPlayOutEntity.PacketPlayOutEntityLook(getEntityId(), (byte) ((yaw % 360.) * 256 / 360), (byte) ((pitch % 360.) * 256 / 360), false));
connection.sendPacket(new PacketPlayOutEntityHeadRotationWrapper().create(npcLocation, entityId));
}
}
}
2 changes: 1 addition & 1 deletion nms/v1_13_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.9-SNAPSHOT</version>
<version>2.11-SNAPSHOT</version>
</parent>

<artifactId>npclib-nms-v1_13_R2</artifactId>
Expand Down
Loading

0 comments on commit a5e716c

Please sign in to comment.