Spawning Herobrine

Discussion in 'Plugin Development' started by Axe2760, Sep 13, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Axe2760

    The title may be a misleading, but I (am) actually trying to spawn herobrine! :p Not really.

    What I'm trying to do is to spawn a player NPC that will represent herobrine. The player "Herobrine" works well :p

    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 :p

    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 arg0World arg1String arg2,
    PlayerInteractManager arg3Plugin plugin) {
    super(arg0arg1arg2arg3);
    entity this.getBukkitEntity();
    This this;
    taskid Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
     
    @
    Override
    public void run() {
    if (
    target == null || target.dead){
    for (
    Entity ententity.getNearbyEntities(10.010.010.0)){
    if (
    ent.getType().equals(EntityType.PLAYER)){
    en = (CraftEntity)ent;
    target = (EntityLivingen.getHandle();
    }
    }
    }
    else{
    //Go to attack the target
                                            // - snip- I'm not posting all the code here, I don't think it's necessary?
    }
    }
    }, 
    1L);
    }
     
    @
    Override
    public 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
    1.  
    2. private Herobrine This;
    3.  

    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?
     
  2. Offline

    adam753

    Axe2760 likes this.
  3. Offline

    Axe2760

    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 :D

    This is the method inside the task that is supposed to attack the player:
    PHP:
    else{
    //Go to attack the target
    if (target.locX entity.getLocation().getX() > 4){
    //More than 4 blocks away
    if (r.nextBoolean()){
    if (
    count 5){
    //shoot bow
    CraftPlayer cp = (CraftPlayer)entity;
    cp.setItemInHand(new ItemStack(Material.BOW1));
     
    Arrow a = (Arrow)cp.launchProjectile(Arrow.class);
    a.setVelocity(a.getVelocity().multiply(1.5));
    count 0;
    }
    else{
    count++;
    }
    //finally:
    //move towards player
    This.move(target.locXtarget.locYtarget.locZ);
    }
    else{
    if (
    count 5){
    //shoot fireball
    cp.setItemInHand(new ItemStack(Material.FIREBALL1));
     
    LargeFireball fb = (LargeFireball)cp.launchProjectile(LargeFireball.class);
    fb.setVelocity(fb.getVelocity().multiply(0.75));
     
    count 0;
    }
    else{
    count++;
    }
    This.move(target.locXtarget.locYtarget.locZ);
    }
    }
    else{
    if (
    count2 4){
    //Use sword
     
    //face player
    Vector 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 sword
    cp.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(packet1);
    } 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.MAGIC4F);
    count2 0;
    }
    else{
    count2++;
    }
    This.move(target.locXtarget.locYtarget.locZ);
    }
     
    }
    Any ideas as to why herobrine doesn't move?
     
  4. Offline

    SnowGears

    Axe2760

    You need to use pathfinding.
     
  5. Offline

    Axe2760

    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.
     
    Last edited by a moderator: Jun 4, 2016
  6. Offline

    SnowGears

  7. Offline

    Axe2760

    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. :p Any other ideas?
     
  8. Offline

    uyuyuy99

    Just to answer this quick question, you can do this:
    Code:java
    1. Herobrine.this
     
    Axe2760 likes this.
  9. Offline

    Axe2760

    Kk, alright, Ty very much! :)
     
    uyuyuy99 likes this.
Thread Status:
Not open for further replies.

Share This Page