Search in sources :

Example 1 with DataWatcher

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;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) EntityPlayer(net.minecraft.server.level.EntityPlayer) WorldServer(net.minecraft.server.level.WorldServer) Method(java.lang.reflect.Method) Location(org.bukkit.Location) MinecraftServer(net.minecraft.server.MinecraftServer) DataWatcher(net.minecraft.network.syncher.DataWatcher)

Example 2 with DataWatcher

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);
}
Also used : PacketPlayOutNamedEntitySpawn(net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn) PacketPlayOutEntityHeadRotation(net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation) EntityPlayer(net.minecraft.server.level.EntityPlayer) PacketPlayOutPlayerInfo(net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo) DataWatcher(net.minecraft.network.syncher.DataWatcher)

Aggregations

DataWatcher (net.minecraft.network.syncher.DataWatcher)2 EntityPlayer (net.minecraft.server.level.EntityPlayer)2 GameProfile (com.mojang.authlib.GameProfile)1 Method (java.lang.reflect.Method)1 PacketPlayOutEntityHeadRotation (net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation)1 PacketPlayOutNamedEntitySpawn (net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn)1 PacketPlayOutPlayerInfo (net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 WorldServer (net.minecraft.server.level.WorldServer)1 Location (org.bukkit.Location)1