BlockIterator Stops working after hitting doors/levers/etc?

Discussion in 'Plugin Development' started by netherfoam, Jul 4, 2012.

  1. Offline

    netherfoam

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    So I'm trying to get all the blocks a players cursor is aimed at, including the ones behind other blocks, in a straight line. I want ~5 blocks away (*Not* 5 blocks in total) so it could be up to like 8 blocks for the result.

    I've googled and googled, but I think I've run google dry -_-

    I would use:
    Code:
    player.getLineOfSight(new HashSet<Byte>(), 5);
    but it uses blockIterator, so it only returns up to the nearest door and whatnot. So I end up with 2 results instead of 5+, those two results being 1. The air block my head is in, and 2. The door in front of me. Beyond that, the function can't see anything.

    I tried
    Code:
    BlockIterator bIt = new BlockIterator((LivingEntity) player, 5);
                while(bIt.hasNext()){
                    seen.add(bIt.next());
                }
    But ran into the same bug.

    Help?
  2. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    getLineOfSight returns only the blocks the player can see, mayby try addiong al the materials (blocks only) to the list (set actually, but people know better what I mean if I say list) of blocks that are ignored?
    netherfoam likes this.
  3. Offline

    netherfoam

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    What my plugin is actually doing is checking when they use e.g. a lever, that they're actually looking at it instead of using a freecam hack or lag.

    Wall has two levers on it. I look at the wall from a 45 degree angle, and flip the far lever. Technically, my cursor is pointed at the close lever's 'hitbox' (What would you call it?) but, i'm *actually* changing the far one.

    So if I add say a lever to the transparent list, because there's a lever in the way of the one the player tried to use, then the function won't ever see the lever they tried to use if I add it, and will end on the wrong lever if don't add it as transparent.

    Same with doors, open doors, yeah >_<
  4. Offline

    nisovin

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Using the BlockIterator directly like in your second example should work fine. You probably did something else wrong when testing it.
    netherfoam likes this.
  5. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    you can also use the yaw and pitch to see whits direction they are looking, and it the calculated angle to the hitten block match the angle they are looking to, then its valid?
  6. Offline

    netherfoam

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thanks :) I tried having a look but vectors aren't sitting with me too well. It was my dodgy loop... I was doing
    for(Block c: seen){
    p.sendMessage(c.getType().toString());
    if(!isTransparent(c){
    e.setCancelled(true);
    }
    }
    Which means it only tells me the transparent blocks. Failed XD

Share This Page