Let FallingBlockEnitys ignore gravity

Discussion in 'Plugin Development' started by MiniDigger, Jul 2, 2013.

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

    MiniDigger

    Hi all,
    i want to spawn a FallingBlockEntity which moves only in x and z direction, not in the y. If i set the velocity to 2 0 2 its slowly starts falling down cause of the gravity. But i dont like it to do. So i created a AsyncTimer which sets set velocity back every tick. But now, the block just jumps a bit.

    So my question is: Is there a way to do that smoother?

    My code so far:
    Code:java
    1. private void spawnFallingBlock(Location loc,final double i_1,final double i_2){
    2. World w = loc.getWorld();
    3. final FallingBlock b = w.spawnFallingBlock(loc, Material.STONE, (byte) 0);
    4. Bukkit.getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
    5.  
    6. @Override
    7. public void run() {
    8. b.setVelocity(new Vector(i_1, 0, i_2));
    9. }
    10. }, 1,1);
     
  2. Offline

    skore87

    You don't want to modify the entity with async. It can cause crashes.
     
  3. Offline

    MiniDigger

    I tryed it with async and without. It dont crahed and its dont work like i want in both cases ;D
     
  4. Offline

    skore87

    I'm not kidding, you WILL eventually find an error that has a seemingly random occurrence and that is why. But for your gravity issue what you already chose is what I would have suggested although it isn't entirely pretty.
     
    Milkywayz likes this.
  5. Offline

    Shiny Quagsire

    I've found that the best way to do this is to create an override on the FallingBlock class to prevent them from despawning, and to provide a small upward velocity so that it ignores gravity for the time that it has an upward velocity. If you can find Minecraft's default downward velocity and set it to that so that it balances out to 0, you should be able to accomplish something. Again though, a timer is needed, and I'd recommend not using async. It's better to be safe than to have an angry mob of server owners complaining about corrupted worlds/entities.
     
  6. Offline

    MiniDigger

    Do you know where is thedownward velocity in the class? I'll search latert to. Thanks to your reply
     
Thread Status:
Not open for further replies.

Share This Page