The title may be a misleading, but I (am) actually trying to spawn herobrine! Not really. What I'm trying to do is to spawn a player NPC that will represent herobrine. The player "Herobrine" works well However, I'm getting an error when I'm trying to spawn him, he's spawning there, but he isn't moving like he should be. The error is different than most errors i usually get, therefore i have literally no idea as to what i'm doing wrong. Thus, I'm now posting this here Error: Code: ava.lang.NullPointerException at net.minecraft.server.v1_6_R2.EntityTrackerEntry.broadcastIncludingSelf(EntityTrackerEntry.java:273) at net.minecraft.server.v1_6_R2.EntityTrackerEntry.b(EntityTrackerEntry.java:245) at net.minecraft.server.v1_6_R2.EntityTrackerEntry.track(EntityTrackerEntry.java:171) at net.minecraft.server.v1_6_R2.EntityTracker.updatePlayers(EntityTracker.java:151) at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:581) at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226) at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486) at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419) at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582) Nothing in the stacktrace about my classes, but I'm 99% sure it's from my class. A bit of the code: Herobrine.java PHP: public class Herobrine extends EntityPlayer{ private int taskid;private EntityLiving target;private Entity entity;private CraftPlayer cp;private Random r = new Random();private Herobrine This;private int count;private int count2;private CraftEntity en; public Herobrine(MinecraftServer arg0, World arg1, String arg2,PlayerInteractManager arg3, Plugin plugin) {super(arg0, arg1, arg2, arg3);entity = this.getBukkitEntity();This = this;taskid = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ @Overridepublic void run() {if (target == null || target.dead){for (Entity ent: entity.getNearbyEntities(10.0, 10.0, 10.0)){if (ent.getType().equals(EntityType.PLAYER)){en = (CraftEntity)ent;target = (EntityLiving) en.getHandle();}}}else{//Go to attack the target // - snip- I'm not posting all the code here, I don't think it's necessary?}}}, 1L);} @Overridepublic void die(){Bukkit.getScheduler().cancelTask(taskid);super.die();}} How i'm spawning it: PHP: if (cmd.getName().equalsIgnoreCase("spawnherobrine") && sender instanceof Player){Player p = (Player)sender;Location l = p.getLocation();CraftWorld cw = (CraftWorld)p.getWorld(); Herobrine h = new Herobrine(cw.getHandle().getMinecraftServer(), cw.getHandle(), "Herobrine", new PlayerInteractManager(cw.getHandle()), this);cw.getHandle().addEntity(h);h.setPosition(l.getX(), l.getY(), l.getZ()); p.sendMessage("Spawned a herobrine.");return true;} Any ideas?? Also, with this line Code:text private Herobrine This; Is that an acceptable practice of doing things? I needed a way to access the class from inside the scheduler, so I couldn't use "this". How would i get around it?
https://forums.bukkit.org/threads/tutorial-updating-player-entities-to-1-6.157035/ I'm a bit clueless, but this looks relevant to your problem. Since Herobrine extends EntityPlayer, it seems likely it's the same problem.
adam753 Works, thanks! The herobrine apparently doesn't move now, so I'm not setting this to solved yet, but it doesn't throw that error anymore This is the method inside the task that is supposed to attack the player: PHP: else{//Go to attack the targetif (target.locX - entity.getLocation().getX() > 4){//More than 4 blocks awayif (r.nextBoolean()){if (count > 5){//shoot bowCraftPlayer cp = (CraftPlayer)entity;cp.setItemInHand(new ItemStack(Material.BOW, 1)); Arrow a = (Arrow)cp.launchProjectile(Arrow.class);a.setVelocity(a.getVelocity().multiply(1.5));count = 0;}else{count++;}//finally://move towards playerThis.move(target.locX, target.locY, target.locZ);}else{if (count > 5){//shoot fireballcp.setItemInHand(new ItemStack(Material.FIREBALL, 1)); LargeFireball fb = (LargeFireball)cp.launchProjectile(LargeFireball.class);fb.setVelocity(fb.getVelocity().multiply(0.75)); count = 0;}else{count++;}This.move(target.locX, target.locY, target.locZ);}}else{if (count2 > 4){//Use sword //face playerVector toPlayer = cp.getLocation().toVector().subtract(en.getLocation().toVector());float yaw = toPlayer.toLocation(cp.getWorld()).getYaw(); This.yaw = yaw;Packet18ArmAnimation packet = new Packet18ArmAnimation(); //set itemin hand to swordcp.setItemInHand(new ItemStack(Material.DIAMOND_SWORD,1)); Field field;try {field = packet.getClass().getDeclaredField("a");field.setAccessible(true);field.set(packet,This.id); Field field2 = packet.getClass().getDeclaredField("b");field2.setAccessible(true);field2.set(packet, 1);} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {cp.getServer().getLogger().severe("Something went wrong when sending the packet for Herobrine to swing his sword! Please report this to a developer immediately.");}target.damageEntity(DamageSource.MAGIC, 4F);count2 = 0;}else{count2++;}This.move(target.locX, target.locY, target.locZ);} } Any ideas as to why herobrine doesn't move?
SnowGears That's possible with an EntityPlayer?! I thought it would only work with mobs and stuff :O That would have made mu life so much easier, lol. Will go check it out now. thanks. SnowGears I assume you mean the PayhfinderGoalSelector things? I took another look at the mc-dev repo, and targetSelector and pathSelector are both fields of EntityInsentient. For example, EntityCreeper extends EntityMonster which extends EntityCreature which extends EntityInsentient, which in turn extends EntityLiving. However, EntityPlayer extends EntityHuman which directly extends EntityLiving, which would not give it a pathfinder. So, how would I use a pathfinder with it? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
SnowGears Nope, and I don't really find it applicable because it isn't open source, and i don't feel like/want to decompile it. Any other ideas?