Cant't set minecarts pitch or yaw

Discussion in 'Plugin Development' started by timmaker, Feb 7, 2015.

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

    timmaker

    for some reason i can't set the yaw or pitch for a minecart the carts are not on rails and spawned by my plugin

    Code:
    public void start(World world, ArrayList<Minecart> carts)
        {
            final Minecart cart1 = carts.get(0);
            Minecart cart2 = carts.get(1);
            Minecart cart3 = carts.get(2);
            Minecart cart4 = carts.get(3);
           
            Vector vecCart1To = new Location(world, 1389, 66, 161).toVector();
            Vector vecCart1 = cart1.getLocation().toVector().add(vecCart1To).normalize().multiply(new Vector(0, 2, 0)).setY(2.7D);
           
            Vector vecCart2To = new Location(world, 1391, 66, 163).toVector();
            Vector vecCart2 = cart1.getLocation().toVector().add(vecCart2To).normalize().multiply(new Vector(0, 2, 0)).setY(2.7D);
           
            Vector vecCart3To = new Location(world, 1389, 66, 165).toVector();
            Vector vecCart3 = cart1.getLocation().toVector().add(vecCart3To).normalize().multiply(new Vector(0, 2, 0)).setY(2.7D);
           
            Vector vecCart4To = new Location(world, 1387, 66, 163).toVector();
            Vector vecCart4 = cart1.getLocation().toVector().add(vecCart4To).normalize().multiply(new Vector(0, 2, 0)).setY(2.7D);
           
            Bukkit.getServer().broadcastMessage("calculated vectors");
           
            Bukkit.getServer().broadcastMessage("Launched");
           
            cart1.setVelocity(vecCart1);
            cart2.setVelocity(vecCart2);
            cart3.setVelocity(vecCart3);
            cart4.setVelocity(vecCart4);
           
            cart1.getLocation().setYaw(90F);
        }
     
  2. Offline

    timmaker

  3. Offline

    floop222

    How are they spawned in your plugin? Is that to your full code
     
  4. Offline

    timmaker

    @floop222 no there is the command to spawn them:
    Code:
    package nl.mcadventure.mcadventure.commands;
    
    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Minecart;
    import nl.mcadventure.mcadventure.listeners.ShooterListener;
    
    /**
    * @author tim
    */
    public class RideCommand implements CommandExecutor {
       
        ShooterListener sListener = new ShooterListener();
        ArrayList<Minecart> shooterCarts = new ArrayList<>();
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if (cmd.getName().equalsIgnoreCase("ride")) {
                if (args.length == 3) {
                    if ((args[0].equalsIgnoreCase("shooter1")) && (args[1].equalsIgnoreCase("spawn")) && ((sender.hasPermission("mcadventure.shooter.spawn")))) {
                       
                        shooterCarts.clear();
                       
                        World world = Bukkit.getWorld(args[2]);
                        Location locCart1 = new Location(world, 1389.5, 54.5, 161.5);
                        Location locCart2 = new Location(world, 1391.5, 54.5, 163.5);
                        Location locCart3 = new Location(world, 1389.5, 54.5, 165.5);
                        Location locCart4 = new Location(world, 1387.5, 54.5, 163.5);
                       
                        Minecart cart1 = world.spawn(locCart1, Minecart.class);
                        Minecart cart2 = world.spawn(locCart2, Minecart.class);
                        Minecart cart3 = world.spawn(locCart3, Minecart.class);
                        Minecart cart4 = world.spawn(locCart4, Minecart.class);
                       
                        shooterCarts.add(cart1);
                        shooterCarts.add(cart2);
                        shooterCarts.add(cart3);
                        shooterCarts.add(cart4);
                       
                        return true;
                    } else if ((args[0].equalsIgnoreCase("shooter1")) && (args[1].equalsIgnoreCase("start")) && ((sender.hasPermission("mcadventure.shooter.start")))) {
                        sListener.start(Bukkit.getWorld(args[2]), shooterCarts);
                        sender.sendMessage("started!");
                        return true;
                    }
                }
            }
            return false;
        }
    }
    
     
  5. Offline

    Techy4198

    Try
    Code:
    cart1.teleport(cart1.getLocation().setYaw(90));
    I think that .getLocation() returns a new copy of the location, and any modifications don't have an effect on the entity you got it from unless you set it back to that location.
     
Thread Status:
Not open for further replies.

Share This Page