vehicle -> setPassenger() doesn't work

Discussion in 'Plugin Development' started by DASASS, Aug 31, 2012.

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

    DASASS

    Hey, I just tried something:
    I have a Minecart(Position1, Passenger, Velocity) and want to remove it, then spawn a new Minecart at Position2 with the same Passenger and Velocity.
    Code:
    public void Respawn(VehicleMoveEvent event){
      ...
      Vector velocity = event.getVehicle().getVelocity();
      Entity passenger = event.getVehicle().getPassenger();
      event.getVehicle().remove();
      Entity Cart2 = World.spawnEntity(Position2, EntityType.MINECART);
      Cart2.setPassenger((Entity)passenger);
      Cart2.setVelocity(velocity);
    }
    If the passenger is a mob/villager etc. it works fine, but as soon as I am the passenger myself, the minecart gets a problem.
    Then the minecart "teleports" from Position1 to Position2 and I get spawned in Cart2, BUT the Cart2 has no velocity, cannot be moved by me and doesnt react on physics, it just stands around with me as passenger.
    Does anyone know, why this problem appears and how to fix it?

    no ideas?:confused:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    sternmin8or

    It looks ok to me.. the only thing I see wrong is you have casted an Entity to an Entity again, undoing that wont fix the problem, but it will be more correct. You might want to try delaying the set velocity for 5-10 ticks (look up task scheduling on the bukkit wiki if you dont know how).
     
  3. Offline

    DASASS

    could I tell the minecart to update after the respawn? How can you do that ?
     
Thread Status:
Not open for further replies.

Share This Page