Solved Pressure Plate cancelling upwards velocity

Discussion in 'Plugin Development' started by Stoux, Apr 4, 2014.

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

    Stoux

    I added this bug on Dec 2, 2013 at 04:01, when there was a hacky version of 1.7 released, to my bug tracker.
    5 April -> Still haven't found a solution. I'm just clueless, I have no idea what's going on.

    The code I had worked fine used on 1.6, then we went to 1.7, and all of a sudden it didn't work anymore. So I figured it must have been something to do with Bukkit. Now months later, I still have the same issue.

    So here's what the code does:
    1. Player steps on pressurepad
    2. Code sets a velocity to that player
    3. Player launches away
    So this is pretty much [Insert any launchpad-like plugin].

    Now it seems like the pressure pad is cancelling the upwards momentum, and I have no idea how/why. I've just written some really easy code:

    I've created a vector with like x = 3, y = 3, z = 3. This would give you a slight boost in a direction.
    I set that vector to an attribute in the main plugin.
    I've made a command that only does:
    Code:java
    1. Vector v = plugin.getVector();
    2. Player target = (Player) sender;
    3. System.out.println(v);
    4. target.setVelocity(v);

    This works fine, I shoot away.


    And now in an event listener:
    Code:java
    1. @EventHandler
    2. public void stepOnPad(PlayerInteractEvent event) {
    3. if (event.getAction == Action.PHYSICAL) {
    4. Player p = event.getPlayer();
    5. Vector v = plugin.getVector();
    6. System.out.println(v);
    7. p.setVelocity(v);
    8. }
    9. }

    Pretty much the same code, only called on a pressure pad. Want to know what happens? I shoot away in the correct direction, over the ground. It just ignores the vertical velocity.

    The system.out outputs (as you expect) exactly the same on both cases
    I just have no idea anymore what the hell is going on, I'm clueless.
     
  2. Offline

    rfsantos1996

    @EventHandler(ignoreCancelled = false) maybe?
     
  3. Offline

    DamnHippo

    Code:java
    1. @EventHandler
    2. public void onPLayerMove(PlayerMoveEvent event) {
    3. Player player = event.getPlayer();
    4. Material block = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType();
    5. if(block == Material.ID)
    6. player.setVelocity(player.getVelocity().setY(0.5));
    7.  
    8. }
    9. }


    Try that.
     
  4. Offline

    Stoux

    rfsantos1996 That should (and didn't make) any difference. The event gets called correctly, it does set my velocity to the given vector. It just, somehow, fully ignores the vertical argument of the Vector. Thus I get launched away, but only over the ground.

    DamnHippo I figure you meant without the relative, as the block you're standing on is already the pressure plate. I've already tested this, and this indeed works. However, that code 9001 times heavier than just the Pressure plate event, so I cannot use it. There happens something in that tick of the event that just breaks the velocity.
     
  5. Offline

    GotRice

    Stoux When stepping on a pressure plate, PlayerInteractEvent is NEVER fired. Unless I messed up somewhere, that is my results, DamnHippo's code is probably your best option.
     
  6. Offline

    Stoux

    GotRice You messed up somewhere. As I've said, my code works fine. Just the vector blocks somehow, by something in (or more likely after I've handled) the event.

    The thing with the Tick gave me an idea, so I've now delayed the setting of the velocity by 1 tick -> I fly away into the air.
    There's a bug (?) in/after the PlayerInteractEvent (Action == Physical) that set's the player's vertical velocity to 0.
     
  7. Offline

    GotRice

    Stoux Woops, exported to the wrong place XD. That aside, a simple solution to this would be cancelling the event. The downfall of this method is that, the event will fire a couple times because your standing on the pressure plate.
     
  8. Offline

    Stoux

    GotRice Lol! Anyhow: I've also tried cancelling the event, this doesn't change anything. I still just get dragged over the ground instead of flying up. The event firing multiple times isn't a problem as I keep track of when the last time they've stepped on a pad.

    So far the only usable solution seems to be to delay setting the velocity with 1 tick.
     
  9. Offline

    GotRice

    Stoux Try this, Its working perfectly fine for me.

    Code:java
    1. @EventHandler
    2. public void stepOnPad(PlayerInteractEvent event) {
    3. // System.out.println(event.getAction());
    4. if (event.getAction() == Action.PHYSICAL) {
    5. Player p = event.getPlayer();
    6. Vector v = p.getLocation().getDirection().add(new Vector(0,3,0));
    7. event.setCancelled(true);
    8. p.setVelocity(v);
    9. }
    10. }
     
  10. Offline

    Maurdekye

    Stoux Add a print statement that prints out the player's velocity at the end of the event method;
    Code:java
    1. System.out.println(player.getVelocity());

    If it's the same, then there's likely confliction with another plugin, or Bukkit. But i'm sure you've already covered for that.
    If the case remains, then a simple workaround might be to just teleport the player 1 block up, and then fire the remainder of the command.
     
  11. Offline

    Stoux

    Maurdekye I've indeed already covered that. I know there are a couple of work arounds (Teleporting, the one tick delay), but I kind of didn't want to go there.

    Just hang around in the #BukkitDev IRC channel. Had a chat with t00thpick1 (not sure if that is his name on here) and Wolvereness. Turns out: in 1.7 they changed the order physics are applied. In 1.6 they did it before the event was triggered, and in 1.7 they do it after. So what happens:
    1. Event gets called
    2. I change the velocity
    3. Physics get applied
    4. My upwards vector gets #Rekt by the physics calculation.
    So pretty much the only way to deal with this is to delay setting the vector with 1 tick.
    Kind of solved?

    EDIT: It is his name on here, thanks again :)
     
Thread Status:
Not open for further replies.

Share This Page