Easy question for logic, but having a mental block.

Discussion in 'Plugin Development' started by dxwarlock, Jun 21, 2012.

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

    dxwarlock

    What I'm doing is getting a block randomly 10 blocks from a player on X and Z..then trying to search up until it finds air...but maybe Ive been trying too long, and just missing something simple here for logic...

    what I have is:

    Code:java
    1.  
    2. Location loc = p.getLocation();
    3. double y = loc.getY();
    4. double x = loc.getX() + ra.nextDouble() * (Math.random() < 0.5 ? -10 : 10);
    5. double z = loc.getZ() + ra.nextDouble() * (Math.random() < 0.5 ? -10 : 10);
    6. Location check = new Location(p.getWorld(), x, y, z);
    7. Block block = check.getBlock();
    8. while (check.getBlock().getTypeId() != 0) {
    9. y++;
    10. }
    11. Location bspawn = new Location(p.getWorld(), x, y, z);
    12. p.getWorld().spawnCreature(bspawn, EntityType.ZOMBIE);
    13.  


    the while loop is kicking my butt...
    since 'block' doesn't change of course inside it, y just keeps counting up...since that blocks (at that location) always is the same...

    How would I have it check that block, increase y check THAT block..ect until my 'getblocktypeID != air..

    do I need a 'do-while' or an 'if-else' with a loop, im out of ideas...and it seems it simple and I just cant think of it :p

    Or if someone knows an easier way to find the first 'air' block on a Y axis.
    because of course I also need to figure out how to make it wait until Y matches air..before using that loc to spawn the thing :p

    holy crap...I was an idiot...it was really simple
    Code:java
    1.  
    2. Location loc = p.getLocation();
    3. double y = loc.getY();
    4. double x = loc.getX() + ra.nextDouble() * (Math.random() < 0.5 ? -10 : 10);
    5. double z = loc.getZ() + ra.nextDouble() * (Math.random() < 0.5 ? -10 : 10);
    6. Location check = new Location(p.getWorld(), x, y, z);
    7. while (check.getBlock().getTypeId() != 0) {
    8. y++;
    9. check = new Location(p.getWorld(), x, y, z);
    10. }
    11. Location bspawn = new Location(p.getWorld(), x, y, z);
    12. p.getWorld().spawnCreature(bspawn, EntityType.ZOMBIE);
    13. }
    14.  

    just define 'check' inside the while :p

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

    Jeff.Halbert

    this doesn't concider if the block 1o random away is already air. are you trying to spawn on the surface only, or do you mind if zombies fall from the sky :) ??
     
  3. Offline

    dxwarlock

    doesn't matter if he falls, not that worried about it :)
    if they are high enough up for it to fall and die, spawning it on the ground below them..it couldn't get to them anyway :)

    its only called a few times every hour, so not like it will be raining zombies ..lol

    unless you know a really simple way to put them on the ground no matter what..might as well.
    just wasn't worth a lot of math and random loops (the way I was thinking to check anyway) for it.
     
  4. Offline

    Jeff.Halbert

    dude, raining zombies! did anyone say zombiepocolype server plugin?
     
Thread Status:
Not open for further replies.

Share This Page