How can i disable 'backscatter', of a minecart?

Discussion in 'Plugin Development' started by frederikbontved, Dec 27, 2012.

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

    fireblast709

    Have you tested if the events get called (like: add 'System.out.println("Something")' in the methods)
     
  2. Offline

    frederikbontved

    I've used 'Bukkit.broadcastMessage("Something.." + event.getVehicle())' and i get no messages if i use 'if (event.getVehicle() instanceof Minecart)' but if i dont use that, i get the messasge..
    But the vehicle is a pig. So the event dont works for Minecarts..
    Sorry for bad english..
     
  3. Offline

    fireblast709

    No the events are not getting called for Pigs
     
  4. Offline

    frederikbontved

    Hmm.. now it prints: Something..CraftMinecart, but when i use that code:
    Code:
    @EventHandler
        public void onVehicleBlockCollision(VehicleBlockCollisionEvent event) {
            if (event.getVehicle() instanceof Minecart) {
                event.getVehicle().setVelocity(new Vector(0, 0, 0));
            }
        }
    It still dont works..

    ..

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

    Hoolean

    DO NOT use Thread.sleep() in plugins! That means nothing at all will happen on the server (players won't move, mobs won't move, the time won't change) until the sleeping has finished! Use Bukkit's built in scheduler instead.
     
  6. Offline

    fireblast709

    Mmh haven't noticed that due pastebin's wrapping
     
  7. Offline

    frederikbontved

    Okay, i'll stop to use Thread.sleep() :)
     
  8. Offline

    frederikbontved

  9. Offline

    fireblast709

    What is the current problem? Still the same?
     
  10. Offline

    frederikbontved

    Yes! When the car(minecart) collidates with a block, its been thrown back!
    Sorry for bad english!
     
  11. Offline

    Hoolean

    Code:
    @EventHandler
        public void onVehicleBlockCollision(VehicleBlockCollisionEvent event) {
            if (event.getVehicle().toString().toLowerCase().contains("minecart")) {
                event.getVehicle().setVelocity(new Vector(0, 0, 0));
            }
        }
     
  12. Offline

    fireblast709

    event.getVehicle() instanceof Minecart ;3
     
  13. Offline

    Hoolean

    But that wasn't working for him - he said it returned CraftMinecart - so that's my suggestion :)
     
  14. Offline

    fireblast709

  15. Offline

    Hoolean

    fireblast709 likes this.
  16. Offline

    frederikbontved

    My code again:
    Code:
    @EventHandler
        public void onVehicleBlockCollision(VehicleBlockCollisionEvent event) {
            if (event.getVehicle() instanceof Minecart) {
                Bukkit.broadcastMessage("Something..");
                event.getVehicle().setVelocity(new Vector(0, 0, 0));
            }
        }
    It writes "Something.." but when the car collidates with a block, its be thrown back, like before.
    I belive the event, VehicleBlockCollisionEvent, only works when a vehicle collides with a block, and not when its 'inside' a block.
    SORRY FOR BAD ENGLISH :(
     
  17. Offline

    fireblast709

    try setting the velocity 1 tick later
     
    Codex Arcanum likes this.
  18. Offline

    frederikbontved

    Sorry, but i don't know what you means, some code could be awesome!
    SORRY FOR BAD ENGLISH!
     
  19. Offline

    fireblast709

    Code:java
    1. new BukkitRunnable()
    2. {
    3. public void run()
    4. {
    5. // this code is delayed 1 tick
    6. }
    7. }.runTaskLater(<plugin instance>, 1L);
     
  20. Offline

    frederikbontved

    I dont use multiple classes, so should i wrote 'this'?
     
  21. Offline

    fireblast709

  22. Offline

    frederikbontved

    But when the 'event.getVehicle...' is inside the code you've gived med, it dont works. It says 'Change modifer of event to final'..
    But thank you, because you'r helping me :)
     
  23. Offline

    fireblast709

    just change it to final
     
  24. Offline

    frederikbontved

    Still dont works :confused:

    Could it be an error in bukkit?

    Okay!
    I've fixed the bug :)
    (Code if anyone needs it:
    Code:
    if (event.getVehicle().getLocation().getBlock().getType() == Material.AIR || ) {
                    if(player.isInsideVehicle()) {
                        Location newLoc = event.getVehicle().getLocation();
                        Vector velocity = event.getVehicle().getPassenger().getVelocity();
                        velocity.multiply(Speed);
                        newLoc.add(new Vector(velocity.getX() * (double)Speed, 0.0D, velocity.getZ() * (double)Speed));
                        event.getVehicle().teleport(newLoc);
                        player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 0);
                    }
                }
                else {
                    event.getVehicle().setVelocity(new Vector(0, 0, 0));
                }
    Thank you to all guys, there try'ed to help me.
    But i've a last question:
    How could i get the location of a slap.

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

    frederikbontved

    Btw. can anyone tell me how to make 'his own backscatter'?
    So if the car is driving in from the left, it will be subject to the right (It is only thrown one block back!)
    Or if the car is moving forward into a wall, it will be subject to one block back.

    Thank. :)
     
  26. Offline

    fireblast709

    • What do you mean 'location of a slap'
    • the own backscatter is setting the velocity afterwards
     
  27. Offline

    frederikbontved

  28. Offline

    fireblast709

    the datavalue determines if it is a top or bottom slab
     
  29. Offline

    frederikbontved

    Thank you again, you are some awesome helpers!<3 (I'm not gay :confused:)
    But i have a question more.. Can i 'put' players in Minecarts? Eg. when a user wrote '/placecar' there will be spawned a car on a specifik location, and the player who runned the command, will be placed in the car..?
    I believe it's a hard question! (But i know you could help me!:))
     
  30. Offline

    fireblast709

    minecart.setPassenger(player)... one-liner :p
     
Thread Status:
Not open for further replies.

Share This Page