Mobs, decriptions on how to make them move please

Discussion in 'Plugin Development' started by unforgiven5232, May 8, 2013.

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

    unforgiven5232

    Can someone go in detail with me and teach me how to make a zombie move to a specific location that i want, so go to coords


    I got this from CorrieKay but im still confused :/
    Code:
      Entity mob = car; //again, "Mob" needs to be a type of creature you wish to control
                   Block to = e.getClickedBlock();//block location they need to travel to.
                   EntityCreature ec = ((CraftCreature)mob).getHandle();
                   PathEntity pf = ((CraftWorld)to.getWorld()).getHandle().a(ec, to.getX(), to.getY(), to.getZ(), 16.0f, true, false, false, true);
                   ec.setPathEntity(pf);
     
  2. Offline

    ZeusAllMighty11

    Entity has to be an entity, not a variable. 'car' is a variable and not a valid Entity.

    However,
    Code:
    Entity mob = (Entity) car;
    
    That would cause car (whatever it is) to be cast as an entity, but will throw a ClassCastException if it is not an entity.

    So in her example, you need to define what car is. This code should also be in PlayerInteractEvent, as e.getClickedBlock() is a method if it.
     
  3. Offline

    unforgiven5232

    Well here is my whole code so u may have a better understanding
    Code:
     
    @EventHandler (priority = EventPriority.HIGH)
     
         public void onPlayerInteract(PlayerInteractEvent e){ 
          
           if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
               Player player = e.getPlayer();
            
               if(player.getItemInHand().getType().equals(Material.APPLE)){
             player.sendMessage("kk");      
              Entity car = player.getVehicle();
                  
              if (car == null) return;
                  
              
                     
                   Entity mob = (Entity) car; //again, "Mob" needs to be a type of creature you wish to control
                   Block to = e.getClickedBlock();//block location they need to travel to.
                   EntityCreature ec = ((CraftCreature)mob).getHandle();
                   PathEntity pf = ((CraftWorld)to.getWorld()).getHandle().a(ec, to.getX(), to.getY(), to.getZ(), 16.0f, true, false, false, true);
                   ec.setPathEntity(pf);
     
                      
                   }                     
               }                 
             }
     
  4. Offline

    ZeusAllMighty11

    Oooh you are trying to move a minecart? I don't think that works
     
  5. Offline

    devilquak

    unforgiven5232

    Not possible to move minecarts like that. Minecarts are entities, but not mobs. They don't have a path finding AI, so there's no AI to direct to a location.
     
  6. Offline

    unforgiven5232

    TheGreenGamerHD devilquak
    No no, thats just the example im attempting to go off of, but im trying to make a zombie move to a specific location.
     
  7. Offline

    savagesun

    It looks like right now you have to be mounted on a rideable entity, hence the player.getVehicle(). Does using this code work for you when mounted? I haven't tried it out, but assuming setting the path works, all you have to do is pass an entity other than the player's vehicle, in your situation it would be a zombie. Something like:
    Code:
        public void onPlayerInteract(PlayerInteractEvent evt) {
            if(evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                //get block and spawn a zombie there.
                Block b = evt.getClickedBlock();
                Entity zombie = b.getWorld().spawnEntity(b.getLocation(), EntityType.ZOMBIE);
             
                //the new location, change as necessary..
                Location to = new Location(b.getWorld(), b.getX() + 10, b.getY(), b.getZ() + 10);
             
                //set the new destination
                EntityCreature ec = ((CraftCreature)zombie).getHandle();
                PathEntity pf = ((CraftWorld)to.getWorld()).getHandle().a(ec, to.getX(), to.getY(), to.getZ(), 16.0f, true, false, false, true);
                ec.setPathEntity(pf);
            }
        }
    This would spawn a zombie and set it's new destination up and to the right ten blocks.
     
  8. Offline

    unforgiven5232

    I was ontop of a ridable pig, but anyways the code you gave me with the
    Code:
    PathEntity pf = ((CraftWorld)to.getWorld()).getHandle().a(ec, to.getX(), to.getY(), to.getZ(), 16.0f, true, false, false, true);
    [code\]
    the letter "a" gives an error, any help?
     
  9. Offline

    savagesun

    What's the error?
     
  10. Offline

    unforgiven5232

    the method a(double, double, double, String, float, float, boolean) in the type World is not applicable for the arguments (EntityCreature, double, double, double, float, boolean, boolean, boolean, boolean)

    savagesun
    Also, i tried this before when i was researching this, and i've gotten the same error

    TheGreenGamerHD devilquak
    Can you guys help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  11. Offline

    ZeusAllMighty11

    I already answered your question, I can't really help you much more because i'm not experienced in this myself
     
  12. Offline

    unforgiven5232

    Thanks for the reply anyways
     
  13. Offline

    savagesun

    It looks like you are passing a double instead of the entity, or trying to pass a world into it. Double check your code to make sure it looks like this:
    Code:
     PathEntity pf = ((CraftWorld)to.getWorld()).getHandle().a(ec, to.getX(), to.getY(), to.getZ(), 16.0f, true, false, false, true);
     
  14. Offline

    unforgiven5232

    I copied and pasted dude, its still giving me errors, FYI i have craftbukkit and bukkit as APIs heres the code
    Code:
     @EventHandler (priority = EventPriority.HIGH)
     
         public void onPlayerInteract(PlayerInteractEvent e){ 
          
           if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
               Player player = e.getPlayer();
            
               if(player.getItemInHand().getType().equals(Material.APPLE)){
             player.sendMessage("kk");      
             Block b = e.getClickedBlock();
                   Entity zombie = b.getWorld().spawnEntity(b.getLocation(), EntityType.ZOMBIE);
                  
             
                   Location to = new Location(b.getWorld(), b.getX() + 10, b.getY(), b.getZ() + 10);
              
                     
                   
                   EntityCreature ec = ((CraftCreature)zombie).getHandle();
                   PathEntity pf = ((CraftWorld)to.getWorld()).getHandle().a(ec, to.getX(), to.getY(), to.getZ(), 16.0f, true, false, false, true);
                   ec.setPathEntity(pf);
     
                      
                   }                     
               }                 
             }
     
  15. Offline

    ZeusAllMighty11

    unforgiven5232
    CraftBukkit and Bukkit?

    You only need one or the other, and in this case you need CB
     
  16. Offline

    unforgiven5232

    still stuck :/ i dont know whats going on..
     
  17. Offline

    devilquak

    a.) You need to post the actual errors so we can tell what's actually going wrong

    b.) Code is almost never supposed to be directly copied and pasted and work perfectly. Don't expect something to work for you just because you copied word-for-word from something else.
     
  18. Offline

    unforgiven5232

    a.) i did post the error if u bothered to read it


    b.) I've seen the code else where and this IS the proper format to do this, I'm getting this error ( That I posted) for some reason. ..

    2 day bump i guess :S

    Ok so quick update, i have this new code that fixes the "a()" error but in game it spawns the monster but no movement , also tells me that i have a internal error
    Code:
    if (cmd.getName().equalsIgnoreCase("kk")){
     
    p.sendMessage("kk");
    Location loc = new Location(Bukkit.getWorld("world"), -541.0D, 5.0D, 
        -39.0D);
    Block b = p.getTargetBlock(null, 50);
    Block to = loc.getWorld().getBlockAt(loc);
     
    Entity zombie = b.getWorld().spawnEntity(b.getLocation(), EntityType.ZOMBIE);
     
     
     
    //Block te = (Block) new Location(b.getWorld(), b.getX() + 10, b.getY(), b.getZ() + 5);
     
     
    EntityCreature ec = ((CraftCreature)zombie).getHandle();
     
     
    PathEntity pf = ((CraftWorld) to.getWorld()).getHandle().a(ec, to.getX(), to.getY(), to.getZ(), .7F, true, false, false, true);
     
               ec.setPathEntity(pf);
           
               
     
    }
    Ok so now, no errors, no in game errors, but the zombies are not moving to the desired location..
    Code:
    if (cmd.getName().equalsIgnoreCase("kk")){
     
    p.sendMessage("kk");
    Location loc = new Location(Bukkit.getWorld("world"), -541.0D, 5.0D, 
        -39.0D);
    Block b = p.getTargetBlock(null, 50);
    Block to = loc.getBlock();
     
    Entity zombie = b.getWorld().spawnEntity(b.getLocation(), EntityType.ZOMBIE);
     
     
     
    //Block te = (Block) new Location(b.getWorld(), b.getX() + 10, b.getY(), b.getZ() + 5);
     
     
    EntityCreature ec = ((CraftCreature)zombie).getHandle();
     
     
    PathEntity pf = ((CraftWorld) to.getWorld()).getHandle().a(ec, to.getX(), to.getY(), to.getZ(), .7F, true, false, false, true);
     
               ec.setPathEntity(pf);
           
               
     
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  19. Offline

    ktar5

    Im just tempted to say this (Be alert I've only skimmed the topic):
    Make a minecart ride the mob ^~^ (Had to be said)
     
  20. Offline

    unforgiven5232

    U can do that already with a client mod for making maps for minecraft
     
  21. Offline

    Barinade

Thread Status:
Not open for further replies.

Share This Page