Falling blocks are impossible!

Discussion in 'Plugin Development' started by Taco, Mar 31, 2012.

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

    Taco

    I cannot, for the life of me, figure out how to spawn and manipulate falling blocks. Here's my code right now for attempting to make them shoot upwards:

    Code:java
    1. EntityFallingBlock sand = new EntityFallingBlock(cWorld,b.get(i).getX(),b.get(i).getY(),b.get(i).getZ(),id,b.get(i).getData());
    2. Entity e = sand.getBukkitEntity();
    3. e.teleport(e.getLocation().add(.5,1.5,.5));
    4. cWorld.addEntity(sand);
    5. Vector vel = e.getVelocity();
    6. vel.add(new Vector(0,10,0));
    7. e.setVelocity(vel);


    The variable b is a list of blocks for clarification purposes.

    Does anyone see any obvious flaws? I'm at a loss here.

    Edit: When trying to debug this, the server recognizes the entity as being of type FALLING_BLOCK, having the correct velocity/location, and so on. What's even worse is that this: System.out.println(w.getEntities().contains(e)); returns true. Even though the entity seems to be 100% sound, it won't budge.

    I don't normally bump my own threads, but when I do, I'm lost beyond all reason.

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

    Taco

    I hate to beat a dead horse, but this still has me stumped.
     
  3. Offline

    bergerkiller

    Just for clarification purposes:
    Code:
        Block block = b.get(i);
        EntityFallingBlock sand = new EntityFallingBlock(cWorld, block.getX() + 0.5, block.getY() + 1.5, block.getZ() + 0.5, id, block.getData());
        sand.motY = 10.0;
        cWorld.addEntity(sand);
    might work, as you tried to obtain the bukkit entity before it got added to the world; before.
     
  4. Offline

    Taco

    I tried that, no dice. This is my current code:

    Code:
    EntityFallingBlock sand = new EntityFallingBlock(cWorld,block.getX(),block.getY(),block.getZ(),id,block.getData());
    sand.motY=1.0;
    cWorld.addEntity(sand);
    Entity e = sand.getBukkitEntity();
    e.teleport(e.getLocation().add(.5,1.5,.5));
    Vector vel = e.getVelocity();
    vel.add(new Vector(0,2,0));
    e.setVelocity(vel);
     
  5. Offline

    bergerkiller

    Taco did you set the block you spawn it in to air, and does the entity have enough room to spawn in? (e.g. spawn in the middle of the air to test it out)

    It is possibly turning dead because of an obstacle that is in the way, but it depends. It should work though, unless the ID is not of sand or gravel, then it simply isn't able to spawn the block.
     
  6. Offline

    Taco

    I'm testing on a flatgrass world just above the grass itself to ensure that there is enough room, and to make sure the sand isn't spawning IN the block, I put it two blocks above it.

    Here's the debug code:
    Code:
    System.out.println("ID: "+id+" Data: "+block.getData());
    System.out.println("Block Y: "+block.getY()+" Sand Y: "+sand.locY);
    Here's the output:
    Code:
    16:26:28 [INFO] Block Y: 63 Sand Y: 65.0
    16:26:31 [INFO] ID: 12 Data: 0
    16:26:31 [INFO] Block Y: 63 Sand Y: 65.0
    16:26:33 [INFO] ID: 12 Data: 0
    16:26:33 [INFO] Block Y: 63 Sand Y: 65.0
     
  7. Offline

    bergerkiller

    Taco just in case, maybe this works. (though I have my doubts...)
    Code:
    ((WorldServer) cWorld).tracker.track(sand);
     
  8. Offline

    Taco

    Still no luck. I appreciate the help, though.
     
  9. Offline

    Taco

    Bump for the hope of some insight. I've reported this as a bug since it seems that sand cannot be spawned as an entity.

    My current code:

    Code:java
    1. EntityFallingBlock sand = new EntityFallingBlock(cWorld,block.getX(),block.getY()+2,block.getZ(),id,block.getData());
    2. CraftFallingSand c = new CraftFallingSand(cWorld.getServer(), sand);
    3. System.out.println("ID: "+id+" Data: "+block.getData());
    4. ((WorldServer) cWorld).tracker.track(sand);
    5. System.out.println("Block Y: "+block.getY()+" Sand Y: "+sand.locY);
    6. cWorld.addEntity(sand);
    7. Entity e = sand.getBukkitEntity();
    8. //e.teleport(e.getLocation().add(.5,1.5,.5));
    9. //w.spawnCreature(e.getLocation().add(.5,4.5,.5), EntityType.FALLING_BLOCK);
    10. Vector vel = e.getVelocity();
    11. vel.add(new Vector(0,2,0));
    12. c.setVelocity(vel);
    13. //e.setVelocity(vel);
     
  10. Offline

    dylanisawesome1

    did you ever find a solution here? I've been searching for an answer for a while... I can't even get it to appear initially :/
     
  11. Offline

    Taco

    I had another thread on this recently and I'm still going nuts trying to figure this out.

    dylanisawesome1
     
  12. Offline

    dylanisawesome1

    I did get confirmation from fieldmaster that they are/were working on an API for this
     
  13. Offline

    Taco

    Thank god. Finally.
     
  14. Offline

    Timr

  15. Offline

    Taco

Thread Status:
Not open for further replies.

Share This Page