Solved IllegalArgumentException with PathfinderGoalSelector

Discussion in 'Spigot Plugin Development' started by Najm, Jun 21, 2016.

  1. Hi there,
    Im pretty new to NMS and just tried out a tutorial. The idea is to create a unpushable, not moving and untargetable villager. With my code I do now get this error:
    Code (Text):
    [17:46:48] [Server thread/INFO]: Najm issued server command: /npctp create
    [17:46:48] [Server thread/WARN]: java.lang.IllegalArgumentException: Can not set final java.util.Set field net.minecraft.server.v1_9_R1.PathfinderGoalSelector.b to org.bukkit.craftbukkit.v1_9_R1.util.UnsafeList
    [17:46:48] [Server thread/WARN]:     at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    [17:46:48] [Server thread/WARN]:     at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
    [17:46:48] [Server thread/WARN]:     at sun.reflect.UnsafeQualifiedObjectFieldAccessorImpl.set(Unknown Source)
    [17:46:48] [Server thread/WARN]:     at java.lang.reflect.Field.set(Unknown Source)
    [17:46:48] [Server thread/WARN]:     at de.najm.general.CustomVillager.<init>(CustomVillager.java:35)
    [17:46:48] [Server thread/WARN]:     at de.najm.general.CustomVillager.spawn(CustomVillager.java:75)
    [17:46:48] [Server thread/WARN]:     at de.najm.general.NewVillyCommand.onCommand(NewVillyCommand.java:35)
    [17:46:48] [Server thread/WARN]:     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    [17:46:48] [Server thread/WARN]:     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140)
    [17:46:48] [Server thread/WARN]:     at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServer.java:624)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.PlayerConnection.handleCommand(PlayerConnection.java:1290)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1150)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(SourceFile:37)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.PacketPlayInChat.a(SourceFile:9)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13)
    [17:46:48] [Server thread/WARN]:     at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    [17:46:48] [Server thread/WARN]:     at java.util.concurrent.FutureTask.run(Unknown Source)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:679)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:361)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:635)
    [17:46:48] [Server thread/WARN]:     at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:539)
    [17:46:48] [Server thread/WARN]:     at java.lang.Thread.run(Unknown Source)
    The method:

    Code (Text):
        public CustomVillager(World world) {
            super(world);

            try {
                Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
                bField.setAccessible(true);
                Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
                cField.setAccessible(true);

                bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
                bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
                cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
                cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
            } catch (Exception e) {
                e.printStackTrace();
            }

            this.goalSelector.a(0, new PathfinderGoalFloat(this));
            this.goalSelector.a(1, new PathfinderGoalLookAtTradingPlayer(this));
            this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this,
                    0.6D));
            this.goalSelector.a(9, new PathfinderGoalInteract(this,
                    EntityHuman.class, 3.0F, 1.0F));
            this.goalSelector.a(9, new PathfinderGoalInteract(this,
                    EntityVillager.class, 5.0F, 0.02F));
            this.goalSelector.a(9, new PathfinderGoalRandomStroll(this, 0.6D));
            this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this,
                    EntityHuman.class, 8.0F));
        }
    Anybody knows about this problem? Aswell Ive read that NMS has changed from 1.8 to 1.9, does it stand in connection with that?

    Thank you for reading
     
    • Informative Informative x 1