How to make Minecarts drive on Blocks

Discussion in 'Plugin Development' started by Finicalmist, May 21, 2013.

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

    Finicalmist

    Hello,

    How do i get Minecarts drive on Blocks(Not Rails)?

    Pls Post a Example!
     
  2. Offline

    JWhy

    You can't do this resource effectively. You could actually teleport the minecart e.g. every second one block further, but this would look like playing crysis 3 on a Win95 machine.
    If you would want to have a smoother movement, you would have to teleport it in very little intervals, which would be much more resource-intensive. And it still wouldn't look as if the cart was actually on rails.
    That's the technical view on it and indeed it's not impossible, however I can't recommend doing that
     
  3. Offline

    Stigosaurus

    I am looking for a way to do this also. JWhy it's possible... How is it done here?

    It is controllable with WASD much like boats.
     
  4. Offline

    Eatmybiglazer

    That's not WASD, that's setting the Minecart's velocity to a normalized vector of the player's direction.
     
  5. Offline

    JWhy

    I said it's possible, but either resource-intensive or looking unrealistic
     
  6. Offline

    Stigosaurus

    No... It's WASD... Try it for yourself: play.gameslabs.net
     
  7. Offline

    chasechocolate

    +1 - I need this for my MineKart plugin, but I have no idea how to do it :/
     
  8. Offline

    LucasEmanuel

    bergerkiller might know, he seems to be the forum expert on minecarts :)
     
  9. Offline

    chasechocolate

  10. Offline

    bergerkiller

    I'm going to be honest with you: it's not easy to do it. It's not a matter of changing a few values, you will have to rewrite the physics of minecarts entirely. In TrainCarts minecarts can travel on pressure plates and ladders, but guess what, it is not easy peasy.

    Link1.
    Link2.
    Link3.
     
  11. Offline

    ase34

    On a line of rails, you can drive the minecart backwards with the S key, which means the client notifies the server (in some way) about pressing WASD (or at least S). With those information, velocities can be applied to the minecarts to the right directions.
     
  12. Offline

    bergerkiller

    ase34
    That is not driving on blocks, that is sliding/pushing the minecart on the ground. Unless that is what OP wants.
     
  13. Offline

    ase34

    The main thing is that packets about movements are still sent even if the player is in a minecart.
     
  14. Offline

    bergerkiller

    ase34
    ???
    Anyway, OP has to be clear whether he wants minecarts to drive on blocks like rails, or whether he wants yet another 'move where you look or walk' functionality.

    He said nothing about WASD or player-controlled movement, that is what the lots of you made of it.
     
  15. Offline

    ase34

    If the minecart should't be controlled by WASD, then simply apply a velocity to the minecart.
     
  16. Offline

    bergerkiller

    ase34
    Yes, the easiest way then is to use onVehicleUpdate to multiply the velocity of the minecart with a factor to negate the slowing-down factor (ground friction multiplier) of the velocity. The downside is that the vehicle is moved before onUpdate/onMove is fired, as a result it will look a bit glitchy now and then when moved is not the same as velocity.
     
    JWhy likes this.
  17. Offline

    Finicalmist

  18. Offline

    bergerkiller

    Finicalmist
    Sorta like this, didn't check it:
    Code:
    @EventHandler(priority=EventPriority.LOWEST)
    public void onVehicleMove(VehicleMoveEvent event) {
        Vector velocity = event.getVehicle().getVelocity();
    velocity = velocity.divide(((Minecart) event.getVehicle()).getDerailedMultiplyer());
    event.getVehicle().setVelocity(velocity);
    // perhaps also: event.setTo(event.getFrom().add(velocity));
    }
     
  19. Offline

    Finicalmist

    bergerkiller

    Ok thx i got it. Do you know how i stop Minecarts glitching in to Blocks? Pls post a example when know it. Thx.
     
  20. Offline

    bergerkiller

    Finicalmist
    No I do not, as I had to bugfix all these block entering bugs myself when rewriting the Minecart physics. I do not know how to do it in a way that uses the default Minecart physics in the background.
     
  21. Offline

    Comphenix

    You could probably do this by setting air blocks in the direction the minecart is travelling to powered rails for a bit, before reverting back to the original block. These could even be invisible by sending fake block changes (player.sendBlockChange() or ProtocolLib) to nearby players, tricking the client into seeing air where there really is rail.

    That's probably easier than injecting a custom Minecart entity, like bergerkiller did.
     
    MasterDoctor and bergerkiller like this.
  22. Offline

    chasechocolate

    bergerkiller Comphenix I have been playing around with this. In fact, you don't even need to use custom minecarts or event NMS/NBT! Woo! Version independent!
     
Thread Status:
Not open for further replies.

Share This Page