Pig flying!?!?!??!?

Discussion in 'Spigot Plugin Development' started by HeeysamH, Jun 26, 2016.

  1. hey guys,


    I have a prob with my code
    i controll the pig by looking at a direction.
    but if i look up it begins to fly?
    i tryed to pig.setgravity(true);
    but diden't work...

    pls help!

    Code (Text):

    package me.heeysamh.pigr;

    import org.apache.logging.log4j.core.config.plugins.PluginManager;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Pig;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Vehicle;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
    import org.bukkit.event.vehicle.VehicleEnterEvent;
    import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;

    import net.minecraft.server.v1_10_R1.EntityPig;

    public class main extends JavaPlugin implements Listener{
       
        @SuppressWarnings("deprecation")
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onPigClick1(VehicleBlockCollisionEvent e)
        {
            if(!(e.getVehicle().getPassenger() instanceof Player)) return;
            Player player = Bukkit.getPlayer(e.getVehicle().getPassenger().getName().toString());
            if(e.getVehicle() instanceof Pig){
                if(e.getVehicle().getCustomName() == e.getVehicle().getPassenger().getName().toString()){
                    e.getVehicle().setVelocity(new Vector(0, 1.5, 0));
                }
            }
        }
       
        @EventHandler
        public void onPigClick(PlayerInteractEntityEvent e)
        {
            if(e.getRightClicked() instanceof Pig)
            {
               
               
                Pig pig = (Pig) e.getRightClicked();
                Player player = e.getPlayer();
                player.sendMessage(ChatColor.GOLD + "Sent");
                Location location = pig.getLocation();
               
                if(pig.hasSaddle() == false){
                    player.sendMessage("Pig need saddle");
                }else{
                    pig.setPassenger(player);
                }
               
                pig.setCustomName(player.getName().toString());
               
                pig.setGravity(true);
                Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                    public void run(){
                        pig.setVelocity(player.getLocation().getDirection().multiply(0.40));
                       

                       
                        if(pig.getPassenger() == null){
                            pig.setVelocity(player.getLocation().getDirection().multiply(0));
                        }
                    }
                }, 1, 1);
                Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                    public void run(){
                        if(pig.getPassenger() instanceof Player){
                            pig.getLocation().setPitch(player.getLocation().getPitch());
                            pig.getLocation().setYaw(player.getLocation().getYaw());
                        }
                    }
                }, 1, 1);
            }
        }

    }


     
     
  2. e.getVehicle().setVelocity(new Vector(0, 1.5, 0));
    You're pushing it upwards with a velocity of 1.5 Vector.
     
  3. only when it hits a block. its like a jump effect.

    if look up it flyes
     
    • Funny Funny x 1
  4. pig.setVelocity(player.getLocation().getDirection().multiply(0.40));

    If the direction is up, it goes up.
     
    • Agree Agree x 1
  5. The player's facing direction includes the vertical component.
     
  6. Now how do i make it so it can only in the x axis not the y?
    how do i make gravity work again...
     
  7. Vector direction = player.getLocation().getDirection();
    pig.setVelocity(new Vector(direction.getX(),0,direction.getZ());
     
    • Useful Useful x 1
  8. Do u know how i fix graivty?
     
  9. Code (Text):

    52 warnings
    1    Expected an assignment or function call and instead saw an expression.
    1    Missing semicolon.
    1    Expected an assignment or function call and instead saw an expression.
    3    'import' is only available in ES6 (use 'esversion: 6').
    3    Expected 'from' and instead saw '.'.
    3    Expected '(string)' and instead saw 'bukkit'.
    3    Missing semicolon.
    3    Expected an identifier and instead saw '.'.
    3    Expected an assignment or function call and instead saw an expression.
    3    Missing semicolon.
    3    Expected an assignment or function call and instead saw an expression.
    4    'import' is only available in ES6 (use 'esversion: 6').
    4    'org' has already been declared.
    4    Expected 'from' and instead saw '.'.
    4    Expected '(string)' and instead saw 'bukkit'.
    4    Missing semicolon.
    4    Expected an identifier and instead saw '.'.
    4    Expected an assignment or function call and instead saw an expression.
    4    Missing semicolon.
    4    Expected an assignment or function call and instead saw an expression.
    5    'import' is only available in ES6 (use 'esversion: 6').
    5    'org' has already been declared.
    5    Expected 'from' and instead saw '.'.
    5    Expected '(string)' and instead saw 'bukkit'.
    5    Missing semicolon.
    5    Expected an identifier and instead saw '.'.
    5    Expected an assignment or function call and instead saw an expression.
    5    Missing semicolon.
    5    Expected an assignment or function call and instead saw an expression.
    6    'import' is only available in ES6 (use 'esversion: 6').
    6    'org' has already been declared.
    6    Expected 'from' and instead saw '.'.
    6    Expected '(string)' and instead saw 'bukkit'.
    6    Missing semicolon.
    6    Expected an identifier and instead saw '.'.
    6    Expected an assignment or function call and instead saw an expression.
    6    Missing semicolon.
    6    Expected an assignment or function call and instead saw an expression.
    7    'import' is only available in ES6 (use 'esversion: 6').
    7    'org' has already been declared.
    7    Expected 'from' and instead saw '.'.
    7    Expected '(string)' and instead saw 'bukkit'.
    7    Missing semicolon.
    7    Expected an identifier and instead saw '.'.
    7    Expected an assignment or function call and instead saw an expression.
    7    Missing semicolon.
    7    Expected an assignment or function call and instead saw an expression.
    8    'import' is only available in ES6 (use 'esversion: 6').
    8    'org' has already been declared.
    8    Expected 'from' and instead saw '.'.).
    :rolleyes::rolleyes::rolleyes::rolleyes::rolleyes::eek::eek::eek:o_Oo_O
     

  10. wtf is that?
     
  11. An error list, fix them and the program will work
     
  12. Use the pig's existing y velocity for the new vector instead of setting it to 0.
     
  13. Lele thanks it worked! Figured it out a bit before but it works so thanks :D
    Do u know how i can make the rotate with the players head/camera?
     
  14. Set it's yaw and pitch to the players.
     
  15. i did but it dosent work if im riding the pig while..