I was trying to create a dragon mount for my rpg server. My first idea was to create a horse and if you was sneaking i set the velocity of y to go up. And desguise the horse as a dragon but idk if this is so easy as i imagined. Do anyone have like a exeple code for desguising entities or just creating a dragon with own movent. //Ceoepts
ceoepts PHP: //spawn an EnderDragon EnderDragon e = (EnderDragon) player.getWorld().spawn(player.getLocation(), EnderDragon.class);//mount the player on the EnderDragon e.setPassenger(player); Normally this would not work without Thread.sleep(5000) or some other time in ticks. Don't do it in the mean thread though. player is the player; Player player = (Player) sender; for commands, Player player = event.getPlayer(); for events
Yah that sets him as a rider but i wanted to make the player able to move the dragon. I could use player move event and get his pich,yaw but how can i set the dragon to go to where player is pointing then? Ok so im soon done (i think) ive gotten the player and the dragon and now i just need to set the dragons direction to players pich/jaw. Code: @EventHandler public void PlayerMoveEvent(PlayerMoveEvent e){ Player p = e.getPlayer(); if(plugin.MountedDragon.containsKey(p)){ EnderDragon ender = plugin.MountedDragon.get(p); Location ploc = p.getLocation(); float Yaw = ploc.getYaw(); float Pich = ploc.getPitch(); } } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
ceoepts Using my above code PHP: new BukkitRunnable(){@Overridepublic void run(){e.setVelocity(player.getLocation().getDirection());}}.runTaskTimer(this, 0L, 1L); I'm not sure if you need a runnable though. If not just use the e.setVelocity(player.getLocation().getDirection()) line Edit: ninja'd by you xD
I try first in a PlayerMoveEvent if that would work? T Worked THAT WAS AWESOME. But the dragon doesnt point in the derection it does just move EDIT by Moderator: merged posts, please use the edit button instead of double posting.
ceoepts Make a runnable like I did but instead of having the e.setVelocity, set the pitch and yaw to the player 1 question: did you just use the runnable or the single line?
I didnt use any of them this is my code: Code: @EventHandler public void PlayerMoveEvent(PlayerMoveEvent e){ Player p = e.getPlayer(); if(plugin.MountedDragon.containsKey(p)){ EnderDragon ender = plugin.MountedDragon.get(p); ender.setVelocity(p.getLocation().getDirection()); } } And it didnt work with setting the pitch i think my code is just worng: Code: Location enderlocation = ender.getLocation(); enderlocation.setYaw(p.getLocation().getYaw()); enderlocation.setPitch(p.getLocation().getPitch()); ender.teleport(enderlocation); Any easier way? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
ceoepts To be honest I have no idea Edit: try this PHP: ender.setVelocity(player.getLocation().toVector().multiply(1)); I'm not sure that would work because toVector returns a vector, not a direction necessarily.
.... Well time to search around Ok i found how i would be able to set it but. Ive always had this problem that i cant import or use craftEntity is this normal? ((CraftEntity) ender).getHandle().setPositionRotation(eX, eY, eZ, mYaw, mPitch) on craftentity it sais that it cant resolve it Ok got that working now. But now i need to rotate the yaw. How can i rotate it? Because the enderdragon has his head in his a***ole it seems like. is it +360? -360 idk anyone? OMG I GOT WORKING! -180 DDDD I have a fully functional enderdragon mount Next is Wither Edit: Sorry for spamming so much Just realized EDIT by Moderator: merged posts, please use the edit button instead of double posting.
ceoepts I think it is from -90 (directly down) to 90 (directly up) however not confirmed. PHP: Vector vector = p.getLocation().toVector();double rotX = p.getYaw();double rotY = p.getPitch();vector.setY(-Math.sin(Math.toRadians(rotY))); double h = Math.cos(Math.toRadians(rotY));vector.setX(-h * Math.sin(Math.toRadians(rotX)));vector.setZ(h * Math.cos(Math.toRadians(rotX)));ender.setVelocity(vector); If that doesn't work in ender.setVelocity, make it ender.setVelocity(vector.multiply(1)); Edit: found a solution first- good for you!
Not sure if anyone still watches this, but here's what I put together from this code: (I've tested it and it works as far as I know) Code: @EventHandler public void PlayerMoveEvent(PlayerMoveEvent e){ Player p = e.getPlayer(); if(p.getVehicle() == null) { }else { Entity ent = p.getVehicle(); if(ent.getType().equals(EntityType.ENDER_DRAGON)) { Vector vec = p.getLocation().getDirection(); ent.setVelocity(vec.multiply(5)); ((CraftEntity) ent).getHandle().setPositionRotation(ent.getLocation().getX(), ent.getLocation().getY(), ent.getLocation().getZ(), p.getLocation().getYaw() - 180, p.getLocation().getPitch()); } } }