Change Velocity on a specific block

Discussion in 'Plugin Development' started by r0w, May 9, 2012.

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

    r0w

    Hi,

    I'm willing to increase the movement speed of the player when he's running on a stone brick block, that's what I've done :

    Code:
        public void onPlayerMove(PlayerMoveEvent e) {
           
            Player player = e.getPlayer();
            Location location = new Location (player.getWorld(), player.getLocation().getX(), player.getLocation().getBlockY()-1, player.getLocation().getBlockZ());
            Block block = location.getBlock();
     
            if(block.getTypeId() == 98) {
                    player.setVelocity(player.getLocation().getDirection().multiply(0.4).setY(0));
            }
            
    But this is like a conveyor belt, It won't stop until you reached the end. How can let player stop and be able to walk backwards also?

    Thanks :)
     
  2. Offline

    ZachBora

    You could try to save on which block he is and if the new location is the same block dont increase velocity? Not sure if that'd change anything...

    You could also just teleport the player further when he moves.
    I'm seeing a way to do this with a new event so it doesn't fire upon itself.

    I once did something somewhat similar but it required toggling sneak on and off.
    It'd probably loop if the same thing was done on the move event. You can check what I had done here:
    https://github.com/ZachBora/SneakRa...worldcretornica/sneakracer/SneakListener.java

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

    r0w

    Going to check this out, thx.

    In the mean time, I gave the user a speed potion effect, but I can't be very accurate about the speed I'm giving
     
Thread Status:
Not open for further replies.

Share This Page