How to make minecart fly

Discussion in 'Plugin Development' started by PieMan456, Dec 2, 2013.

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

    PieMan456

    Hello Everyone,

    I was interested in trying to make a plugin that allows you to make a minecraft fly like a plane. I have seen other plugins like this so I know it is possible. I would just like to know how to do it. Do I have to set the velocity of the minecart or spawn an entity underneath it to make it fly? Thanks!
     
  2. Offline

    Squid_Boss

    Well, if you want to minecart to go in a specific direction then you'd have to spawn the minecart entity, and then set it to a desired vector. If you want the minecart to go in a direction specified by the player, then you'd have to spawn the minecart entity, put the player inside of it, and then (based off of the players direction) create a vector that best fits. So, if the player was facing north if X goes positive in the north direction the vector may be something like this:
    (<positive x>, <smaller y (to make a gradual accent)>, <0 z>), but I'd say things get trickier when the direction of the player is like North East, South West, etc.
     
  3. Offline

    Rocoty

    Squid_Boss Don't you know you can get the view direction of the player as a vector?
     
  4. Offline

    Squid_Boss

    Oh, that will probably solve a lot of problems... PieMan456 do what Rocoty said! :p
     
  5. Offline

    PieMan456

    Squid_Boss
    Lol ok.

    Squid_Boss Rocoty
    How would I check if a player is in a minecart?

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

    xTrollxDudex

  7. Offline

    PieMan456

    xTrollxDudex
    Yeah but how do I check if the player is in a minecart specifically.
     
  8. Offline

    xTrollxDudex

    PieMan456
    PHP:
    if(player.getVehicle() instanceof Minecart)
     
  9. Offline

    PieMan456

    xTrollxDudex
    Oh derp.

    xTrollxDudex Squid_Boss Rocoty
    Ok so I have this but all it does is teleport you into the ground if you are looking at the ground or shoot you up into the air if you are in the air. How do I make it so it comes off the ground and goes the way the player is looking?
    Code:java
    1. package me.pieman.planes;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Minecart;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.vehicle.VehicleEnterEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13. import org.bukkit.util.Vector;
    14.  
    15. public class Planes extends JavaPlugin implements Listener {
    16.  
    17. public void onEnable(){
    18. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    19. }
    20.  
    21. @EventHandler
    22. public void onVehicleEnter(VehicleEnterEvent e){
    23. if(e.getEntered() instanceof Player){
    24. Player p = (Player) e.getEntered();
    25. if(!p.hasPermission("planes.fly")) return;
    26.  
    27. }
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    31. if(!(sender instanceof Player)){
    32. sender.sendMessage(ChatColor.RED + "Only players can use this command!");
    33. return true;
    34. }
    35. Player p = (Player) sender;
    36. if(cmd.getName().equalsIgnoreCase("fly")){
    37. if(p.hasPermission("planes.fly")){
    38. if(p.isInsideVehicle()){
    39. if(p.getVehicle() instanceof Minecart){
    40. Vector v = p.getLocation().getDirection().multiply(2.0);
    41. p.getVehicle().remove();
    42. Minecart m = p.getLocation().getWorld().spawn(p.getLocation().add(v.getX(), v.getY(), v.getZ()), Minecart.class);
    43. m.setPassenger(p);
    44. m.setVelocity(p.getEyeLocation().getDirection().multiply(5.0));
    45. }
    46. } else {
    47. p.sendMessage(ChatColor.RED + "You are not in a vehicle!");
    48. return true;
    49. }
    50. } else {
    51. p.sendMessage(ChatColor.RED + "You do not have permission!");
    52. return true;
    53. }
    54. }
    55. return true;
    56. }
    57.  
    58. }
    59.  


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

    xTrollxDudex

    That is expected.
     
  11. Offline

    PieMan456

  12. Offline

    sgavster

    PieMan456 You could: teleport the minecart up a couple blocks, then make a runnable that teleports the minecart to the direction they are looking. Probably very buggy and laggy though :p
     
Thread Status:
Not open for further replies.

Share This Page