use of net.minecraft.network.syncher.DataWatcher in project Nokaut by smaks6.
the class NpcNew method spawnNPC.
// ChatColor.RED +
private EntityPlayer spawnNPC() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
Location location = knockedPlayer.getLocation();
MinecraftServer nmsServer = (MinecraftServer) Reflection.getNMSServer();
WorldServer nmsWorld = (WorldServer) Reflection.getNMSWorld();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), knockedPlayer.getName());
if (is1_18()) {
if (Main.getVersion().equals("v1_18_R1")) {
Method method = EntityPlayer.class.getMethod("fp");
GameProfile knockedPlayerGameProfile = (GameProfile) method.invoke(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)));
gameProfile.getProperties().putAll(knockedPlayerGameProfile.getProperties());
} else {
gameProfile.getProperties().putAll(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)).fq().getProperties());
}
} else {
Method method = EntityPlayer.class.getMethod("getProfile");
GameProfile knockedPlayerGameProfile = (GameProfile) method.invoke(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)));
gameProfile.getProperties().putAll(knockedPlayerGameProfile.getProperties());
}
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile);
setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), npc);
// npc.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), 40f);
DataWatcher watcher = null;
if (is1_18()) {
entityplayerId = npc.ae();
} else {
Method getId = EntityPlayer.class.getMethod("getId");
entityplayerId = (int) getId.invoke(npc);
}
// a - ADD_Player
// e - REMOVE-PLAYER
sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc));
sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
// d - swimming
if (is1_18()) {
watcher = npc.ai();
byte o = (Byte) watcher.a(DataWatcherRegistry.a.a(17));
watcher.b(DataWatcherRegistry.a.a(17), o);
watcher.b(DataWatcherRegistry.s.a(6), EntityPose.d);
sendPacket(new PacketPlayOutEntityMetadata(entityplayerId, watcher, true));
} else {
Method getDataWatcher = EntityPlayer.class.getMethod("getDataWatcher");
watcher = (DataWatcher) getDataWatcher.invoke(npc);
setPose(npc);
sendPacket(new PacketPlayOutEntityMetadata(entityplayerId, watcher, false));
}
return npc;
}
use of net.minecraft.network.syncher.DataWatcher in project Nexus by ProjectEdenGG.
the class FakeNPCPacketUtils method spawnFakeNPC.
// NPCs
public static void spawnFakeNPC(HasPlayer hasPlayer, FakeNPC fakeNPC) {
EntityPlayer entityPlayer = fakeNPC.getEntityPlayer();
PacketPlayOutPlayerInfo playerInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.a, entityPlayer);
PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(entityPlayer);
PacketPlayOutEntityHeadRotation headRotationPacket = new PacketPlayOutEntityHeadRotation(entityPlayer, PacketUtils.encodeAngle(fakeNPC.getLocation().getYaw()));
// untested
DataWatcher dataWatcher = entityPlayer.getDataWatcher();
dataWatcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 127);
sendPacket(hasPlayer, playerInfoPacket, spawnPacket, headRotationPacket);
spawnHologram(hasPlayer, fakeNPC);
}
Aggregations