Make Animals leave a Minecart

Discussion in 'Plugin Development' started by Deathly, Mar 10, 2011.

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

    Deathly

    Hey :)

    I just started coding with Bukkit and wanted to make a Minecart "eject" Animals if it drives over a specified block. The problem is that all methods I tried did not work.. (Vehicle.eject(), Creature.leaveVehicle(), ...)

    Is this even possible yet, and if so.. how?

    Thank you
     
  2. Offline

    Dinnerbone Bukkit Team Member

    The problem is, they're not actually a passenger of the minecart; they're just stuck in its box. You'd have to .teleport it out of there.
     
  3. Offline

    Deathly

    Tried teleporting, got an error.

    I can remove them with a typecast to Creature and then using .remove

    Will try teleport again, thank you :)

    But you could just add a faked .eject function teleporting them out of it to bukkit?:)
    [MERGETIME="1299762687"][/MERGETIME]
    Here is the code that i tried. No effect.

    The function gets called and everything, and i can replace it with .remove and the mob is gone, but I want it to just get out of the cart :(

    Code:
                public void onVehicleMove(VehicleMoveEvent event) {
                    Vehicle vehicle = event.getVehicle();
                    if(vehicle.getPassenger() instanceof Creature)
                    {
                        Creature mob = (Creature)vehicle.getPassenger();
                        mob.teleportTo(vehicle.getWorld().getSpawnLocation());
                    }
                }
     
  4. Offline

    Afforess

    You could always ask someone who already has this in a plugin. *Cough*

    Anyway, you need to use the minecart.eject() method to eject the passenger.
     
  5. Offline

    Deathly

    Afforess thank you but this method does NOT eject Mobs :(
     
  6. Offline

    Afforess

  7. Offline

    Deathly

    Well could you try it yourself, please?

    For me it just doesnt work. Neither the vehicle.eject() nor teleporting them out or anything else..

    Thank you :)
     
  8. Offline

    Afforess

    Been working for ages with players. I usually have minecarts set up to kill mobs, not catch them, so I haven't tested that in a while. But I can't see any reason it would treat mobs differently from animals.

    Does eject() eject players correctly for you?
     
  9. Offline

    Deathly

    Yes, well yeah removing mobs works fine aswell but ejecting is impossible right now..

    So yeah i will just let it kill them.. Any way to make an animal drop its drops? :D
     
Thread Status:
Not open for further replies.

Share This Page