Made NPCs spawn for 1.7.10 (1.7 R4) (#10).
Disabled TinyProtocol to work on some other things first.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
package net.jitse.npclib.nms.v1_7_R4;
|
||||
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import net.jitse.npclib.nms.holograms.Hologram;
|
||||
import net.jitse.npclib.nms.v1_7_R4.packets.PacketPlayOutEntityHeadRotationWrapper;
|
||||
import net.jitse.npclib.nms.v1_7_R4.packets.PacketPlayOutNamedEntitySpawnWrapper;
|
||||
import net.jitse.npclib.nms.v1_7_R4.packets.PacketPlayOutPlayerInfoWrapper;
|
||||
@@ -27,7 +26,6 @@ import java.util.UUID;
|
||||
*/
|
||||
public class NPC_v1_7_R4 extends NPC {
|
||||
|
||||
private Hologram hologram;
|
||||
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
|
||||
private PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeamRegister, packetPlayOutScoreboardTeamUnregister;
|
||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||
@@ -38,31 +36,29 @@ public class NPC_v1_7_R4 extends NPC {
|
||||
|
||||
public NPC_v1_7_R4(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
super(plugin, skin, autoHideDistance, lines);
|
||||
this.name = lines.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPackets() {
|
||||
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
|
||||
hologram.generatePackets(false, false);
|
||||
|
||||
this.legacyGameProfile = generateLegacyGameProfile(uuid, name);
|
||||
this.legacyGameProfile = generateLegacyGameProfile(uuid, name.length() < 16 ? name : name.substring(0, 15));
|
||||
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
|
||||
|
||||
// Packets for spawning the NPC:
|
||||
this.packetPlayOutScoreboardTeamRegister = new PacketPlayOutScoreboardTeamWrapper()
|
||||
.createRegisterTeam(name); // First packet to send.
|
||||
.createRegisterTeam(legacyGameProfile.getId().toString().replace("-", "").substring(0, 10), name); // First packet to send.
|
||||
|
||||
this.packetPlayOutPlayerInfoAdd = packetPlayOutPlayerInfoWrapper
|
||||
.create(0, legacyGameProfile, name); // Second packet to send.
|
||||
.create(0, legacyGameProfile, name.length() < 16 ? name : name.length() < 16 ? name : name.substring(0, 15)); // Second packet to send.
|
||||
|
||||
this.packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawnWrapper()
|
||||
.create(uuid, location, entityId); // Third packet to send.
|
||||
.create(legacyGameProfile, location, entityId); // Third packet to send.
|
||||
|
||||
this.packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotationWrapper()
|
||||
.create(location, entityId); // Fourth packet to send.
|
||||
|
||||
this.packetPlayOutPlayerInfoRemove = packetPlayOutPlayerInfoWrapper
|
||||
.create(4, legacyGameProfile, name); // Fifth packet to send (delayed).
|
||||
.create(4, legacyGameProfile, name.length() < 16 ? name : name.substring(0, 15)); // Fifth packet to send (delayed).
|
||||
|
||||
// Packet for destroying the NPC:
|
||||
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
|
||||
@@ -70,7 +66,7 @@ public class NPC_v1_7_R4 extends NPC {
|
||||
// Second packet to send is "packetPlayOutPlayerInfoRemove".
|
||||
|
||||
this.packetPlayOutScoreboardTeamUnregister = new PacketPlayOutScoreboardTeamWrapper()
|
||||
.createUnregisterTeam(name); // Third packet to send.
|
||||
.createUnregisterTeam(legacyGameProfile.getId().toString().replace("-", "").substring(0, 10)); // Third packet to send.
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,8 +78,6 @@ public class NPC_v1_7_R4 extends NPC {
|
||||
playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);
|
||||
playerConnection.sendPacket(packetPlayOutEntityHeadRotation);
|
||||
|
||||
hologram.spawn(player);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
|
||||
}
|
||||
@@ -95,8 +89,6 @@ public class NPC_v1_7_R4 extends NPC {
|
||||
playerConnection.sendPacket(packetPlayOutEntityDestroy);
|
||||
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove);
|
||||
|
||||
hologram.destroy(player);
|
||||
|
||||
if (scheduler) {
|
||||
// Sending this a bit later so the player doesn't see the name (for that split second).
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () ->
|
||||
|
||||
+4
-5
@@ -7,22 +7,21 @@ package net.jitse.npclib.nms.v1_7_R4.packets;
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import net.minecraft.server.v1_7_R4.DataWatcher;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedEntitySpawn;
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Jitse Boonstra
|
||||
*/
|
||||
public class PacketPlayOutNamedEntitySpawnWrapper {
|
||||
|
||||
public PacketPlayOutNamedEntitySpawn create(UUID uuid, Location location, int entityId) {
|
||||
public PacketPlayOutNamedEntitySpawn create(GameProfile gameProfile, Location location, int entityId) {
|
||||
PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawn();
|
||||
|
||||
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "a", int.class)
|
||||
.set(packetPlayOutNamedEntitySpawn, entityId);
|
||||
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "b", UUID.class)
|
||||
.set(packetPlayOutNamedEntitySpawn, uuid);
|
||||
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "b", GameProfile.class)
|
||||
.set(packetPlayOutNamedEntitySpawn, gameProfile);
|
||||
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "c", int.class)
|
||||
.set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getX() * 32.0D));
|
||||
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "d", int.class)
|
||||
|
||||
+18
-16
@@ -6,7 +6,6 @@ package net.jitse.npclib.nms.v1_7_R4.packets;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutScoreboardTeam;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -15,38 +14,41 @@ import java.util.Collection;
|
||||
*/
|
||||
public class PacketPlayOutScoreboardTeamWrapper {
|
||||
|
||||
public PacketPlayOutScoreboardTeam createRegisterTeam(String name) {
|
||||
public PacketPlayOutScoreboardTeam createRegisterTeam(String uuidName, String name) {
|
||||
PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam();
|
||||
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "h", int.class)
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "f", int.class)
|
||||
.set(packetPlayOutScoreboardTeam, 0);
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "b", String.class)
|
||||
.set(packetPlayOutScoreboardTeam, name);
|
||||
.set(packetPlayOutScoreboardTeam, name.length() < 16 ? name : name.substring(0, 15));
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class)
|
||||
.set(packetPlayOutScoreboardTeam, name);
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "e", String.class)
|
||||
.set(packetPlayOutScoreboardTeam, "never");
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "i", int.class)
|
||||
.set(packetPlayOutScoreboardTeam, uuidName);
|
||||
if (name.length() > 16) {
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "d", String.class)
|
||||
.set(packetPlayOutScoreboardTeam, name.substring(15));
|
||||
}
|
||||
if (name.length() > 32) {
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "c", String.class)
|
||||
.set(packetPlayOutScoreboardTeam, name.substring(31));
|
||||
}
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "g", int.class)
|
||||
.set(packetPlayOutScoreboardTeam, 1);
|
||||
// Could not get this working in the PacketPlayOutPlayerInfoWrapper class.
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "c", String.class)
|
||||
.set(packetPlayOutScoreboardTeam, ChatColor.BLUE + "[NPC] ");
|
||||
Reflection.FieldAccessor<Collection> collectionFieldAccessor = Reflection.getField(
|
||||
packetPlayOutScoreboardTeam.getClass(), "g", Collection.class);
|
||||
packetPlayOutScoreboardTeam.getClass(), "e", Collection.class);
|
||||
Collection collection = collectionFieldAccessor.get(packetPlayOutScoreboardTeam);
|
||||
collection.add(name);
|
||||
collection.add(name.length() < 16 ? name : name.substring(0, 15));
|
||||
collectionFieldAccessor.set(packetPlayOutScoreboardTeam, collection);
|
||||
|
||||
return packetPlayOutScoreboardTeam;
|
||||
}
|
||||
|
||||
public PacketPlayOutScoreboardTeam createUnregisterTeam(String name) {
|
||||
public PacketPlayOutScoreboardTeam createUnregisterTeam(String uuidName) {
|
||||
PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam();
|
||||
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "h", int.class)
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "f", int.class)
|
||||
.set(packetPlayOutScoreboardTeam, 1);
|
||||
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class)
|
||||
.set(packetPlayOutScoreboardTeam, name);
|
||||
.set(packetPlayOutScoreboardTeam, uuidName);
|
||||
|
||||
return packetPlayOutScoreboardTeam;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user