Move Dragon with WASD

Discussion in 'Plugin Development' started by TheCoderGuy, Jan 4, 2015.

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

    TheCoderGuy

    For the past couple of days, I have been trying to move the dragon with the wasd keys. I have found nothing able to help me, not even that tutorial that explains how to do it. I have tried just about everything, including player move event and a custom ender dragon class. The question I have is this: how would I be able to achieve this? Here is my code for the custom ender dragon class:

    Code:
    public class CustomEnderDragon extends EntityEnderDragon {
    
        private String rider;
    
        public CustomEnderDragon(World world, String rider){
            super(world);
            this.rider = rider;
        }
    
        @Override
        public void e(float sideMot, float forMot) {
            if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
                super.e(sideMot, forMot);
                this.W = 0.5F;
                return;
            }
    
            EntityHuman human = (EntityHuman) this.passenger;
            if (human.getBukkitEntity() != Bukkit.getPlayerExact(rider).getPlayer()) {
                super.e(sideMot, forMot);
                this.W = 0.5F;
                return;
            }
    
            this.lastYaw = this.yaw = this.passenger.yaw;
            this.pitch = this.passenger.pitch * 0.5F;
    
            this.b(this.yaw, this.pitch);
            this.aO = this.aM = this.yaw;
    
            this.W = 1.0F;
    
            sideMot = ((EntityLiving) this.passenger).bd * 0.5F;
            forMot = ((EntityLiving) this.passenger).be;
    
            if (forMot <= 0.0F) {
                forMot *= 0.25F;
            }
    
            sideMot *= 0.75F;
    
            float speed = 0.40F;
            this.i(speed);
            super.e(sideMot, forMot);
        }
    }
    
    And here is my join listener class:

    Code:
    public class JoinListener implements Listener {
    
        @EventHandler
        public void onJoin(final PlayerJoinEvent event) {
            event.getPlayer().getInventory().clear();
            Player p = event.getPlayer();
            p.getInventory().setItem(8, GadgetItems.hubControl);
            if(Bukkit.getWorld("world") == null){
                Bukkit.createWorld(new WorldCreator("world"));
            }
            p.teleport(new Location(Bukkit.getWorld("world"), 0, 100, 0));
    
            p.setFlying(true);
    
            for(Entity en : p.getWorld().getEntities()){
                if(!(en instanceof Player)){
                    en.remove();
                }
            }
    
            p.sendMessage(ChatColor.RED + "[DEBUG 1] " + ChatColor.WHITE + "Spawning ender dragons for departure...");
            p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 9999, 3));
            EnderDragon dragon = (EnderDragon) Bukkit.getWorld("world").spawnEntity(p.getLocation(), EntityType.ENDER_DRAGON);
            dragon.setHealth(200);
            dragon.setCustomName(null);
            dragon.setCustomNameVisible(false);
            dragon.setPassenger(p);
    
            p.sendMessage(ChatColor.RED + "[DEBUG 2] " + ChatColor.WHITE + "Allowing player to move on ender dragon...");
    
        }
    }
    No errors either. :/
    Any help would be greatly appreciated.
     
  2. Offline

    MisterErwin

    @TheCoderGuy Debugging messages - Aka broadcast a message within you CustomEnderDragon class (When it spawns and maybe in the e method)
     
  3. Offline

    TheCoderGuy

    @MisterErwin I tried that, but it went through all of the debug messages like normal. Am I supposed to put something in the join class?
     
  4. Offline

    Tiliondc

    Try put the player in flymode and spawn an enderdragon that is following the players movement :)
     
  5. How hard did you look?
     
  6. Offline

    sirrus86

    To my knowledge Ender Dragons have their own pathfinding AI that's unique to them, unlike other mobs which are simply point A to point B. This might be why it isn't working.

    There were plugins out there which already do what you're trying to do though. Try checking the source to see how they made it work.
     
  7. Offline

    TheCoderGuy

    @AdamQpzm Thats the tutorial I was talking about. If you scroll down a bit on the first page, on a post a guy made farther down, he explains how this doesn't work for ender dragons, only horses and other animals.

    @Tiliondc Hmm, I didn't think of that. That might make the ender dragon glitch a little, but it could work.

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Jan 5, 2015
  8. Offline

    TheCoderGuy

  9. Offline

    TheCoderGuy

    Anyone? I really need help on this.
     
  10. Offline

    TheCoderGuy

    I am about to give up. I can't find anything!
     
  11. Offline

    ProMCKingz

    @TheCoderGuy
    Like @sirrus86 said, check the code from pre existing plugins that do that, like Citizens.
    Otherwise you could try to set it as passenger and move towards player
     
  12. Offline

    TheCoderGuy

    @ProMCKingz I did check the code, the only problem is that there are tons of errors, as you need to import tons of classes. And yes, I have tried that setting it as a passenger and it moving towards player. The player simply can't move at all. What I tried doing is allowing a pig to move, then setting a pig as a passenger of the dragon, and the human as a passenger of the pig. Doesn't work either :/
     
  13. Offline

    ProMCKingz

  14. Offline

    TheCoderGuy

    I tried the API, but I realized that it does NOT work with ender dragons, just look in the info section area.

    1. I kept on getting an error at the navigation line, saying it expected org.bukkit.craftbukkit.v1_7_R3.Navigation but found a boolean.

    2. The answer to that thread linked to the controllable mobs api, which again does not work.

    3. I tried that, but it would not pass events to the classes after I added the depend thing in config.

    4. That is the code I used for my original past.

    5. Same with this one. Its very annoying, as it works for other people, but not me :/
     
Thread Status:
Not open for further replies.

Share This Page