Set Minecart Velocity to Move on Enter

Discussion in 'Plugin Development' started by AppleBabies, Dec 11, 2015.

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

    AppleBabies

    Okay, so here I have a couple of events that allow a person to drive a Minecart on land. This works GREAT - but you have to start on a rail. I do not want this.

    So, my question is this - how can I go upon setting the velocity of the Minecart to make it start moving when a player enters it? Also, how could I utilize the VehicleBlockCollisionEvent to make it so you can still move it even when it hits a block? Thank you!
    Code:
    @EventHandler
    public void onVehicleLeave(VehicleExitEvent e) {
        if(e.getVehicle() instanceof Minecart) {
        Minecart m = (Minecart) e.getVehicle();
        Player p = (Player) e.getExited();
        m.remove();
        p.sendMessage("Minecart despawned!");
        }
    }
    
    @EventHandler
    public void onVehicleEnter(VehicleEnterEvent e) {
        if(e.getVehicle() instanceof Minecart){
        Minecart m = (Minecart) e.getVehicle();
        Player player = (Player) m.getPassenger();
       
        Vector playerVector = player.getLocation().getDirection();
       
        double x = Math.round(playerVector.getX());
        double z = Math.round(playerVector.getZ());
        
        Vector velocity = new Vector(x, 0, z);
        
        Vector velocityMod = new Vector(1, 0, 1);
        
        m.setDerailedVelocityMod(velocityMod);
        m.setVelocity(velocity);
        }
    }
    
    @EventHandler
    public void onVehicleMove(VehicleMoveEvent event) {
        Minecart vehicle = (Minecart) event.getVehicle();
        Player player = (Player) vehicle.getPassenger();
        Vector playerVector = player.getLocation().getDirection();
       
        vehicle.setPassenger(player);
        vehicle.setCustomName(player + "'s Minecart");
       
        double x = Math.round(playerVector.getX());
        double z = Math.round(playerVector.getZ());
        
        Vector velocity = new Vector(x, 0, z);
        
        Vector velocityMod = new Vector(1, 0, 1);
        
        vehicle.setDerailedVelocityMod(velocityMod);
        vehicle.setVelocity(velocity);
    }
     
  2. Offline

    Zombie_Striker

    @AppleBabies
    Well, a "hack" would be that you set the block under the minecart to be a rail, and after one tick you would remove the rails.
     
  3. Offline

    AppleBabies

    @Zombie_Striker Yeah, I've tried that, but "hacks" don't work unfortunately.
     
  4. Offline

    Zombie_Striker

  5. Offline

    AppleBabies

    @Zombie_Striker That was another though, except that I DESPISE NMS. I want a way to cheat around having to use NMS, which probably will fail indefinitely at trying.
     
  6. Offline

    Zombie_Striker

    @AppleBabies
    The problem is, this "problem" is caused by base minecraft wanting to stop all minecarts from moving. You would have to override what base minecraft wants, and the only way to do this in a "non-hacky way" would be NMS. If you understand NMS, it should not be a problem.

    Another way to go about velocities would be to have something that sets the velocity of the minecart every ___ seconds to move towards where the player is looking.
     
  7. Offline

    AppleBabies

Thread Status:
Not open for further replies.

Share This Page