Solved Get highest block (which is a barrier)

Discussion in 'Plugin Development' started by i3ick, Jul 28, 2017.

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

    i3ick

    I'm trying to prevent mob spawning under barrier block, but my code doesn't seem to be working.
    I've already tried a few alternatives and my conclusion is that maybe bukkit sees the barrier block as
    air?

    Code:
        public boolean isAboveBarrier(Location spawnplace){
            int LY = spawnplace.getWorld().getHighestBlockYAt(spawnplace);
           Block block = new Location(spawnplace.getWorld(), spawnplace.getX() + 0.5, LY, spawnplace.getZ()+0.5).getBlock();
    
            if(block.getType() == Material.BARRIER){
                return true;
            }
    
      
            return false;
        }
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    i3ick

  4. Online

    timtower Administrator Administrator Moderator

    @i3ick Then you don't need to make another call to get the block.
    Try printing the material to the console on a place that you are certain that there is a barrier as highest block.
     
  5. Offline

    i3ick

    @timtower ok i found out bukkit indeed doesn't see the barrier block. Is there any other way to detect it or another invisible block that i could try?
     
  6. Online

    timtower Administrator Administrator Moderator

    @i3ick You could loop through all the blocks in that x z coordinate.
     
  7. Offline

    i3ick

    @timtower

    I made a makeshift solution.

    Basically, i 30 blocks above the highest block for a barrier material match.

    Code:
        public Block toThirty = null;
        public boolean isAboveBarrier(Location spawnplace){
            int LY = spawnplace.getWorld().getHighestBlockYAt(spawnplace);
            Block block =  spawnplace.getWorld().getHighestBlockAt(spawnplace);
    
            toThirty = block;
            for(int i=0; i<30; i++){
                if(toThirty.getType().equals(Material.BARRIER)){
                    plugin.getLogger().info("Found a barrier at coords " + toThirty.getLocation());
                    return true;
                }
                toThirty = toThirty.getRelative(BlockFace.UP);
            }
            toThirty = null;
    
            return false;
    }
     
  8. Offline

    Machine Maker

    @i3ick
    Please mark this thread as Solved if your issue has been resolved.
     
  9. Online

    timtower Administrator Administrator Moderator

    @i3ick That is a very tricky solution when under ground.
     
  10. Offline

    i3ick

    @X1machinemaker1X I know how to use the forums, thank you.
    I did not mark it as a solution as someone might still have a better idea on how to solve this. As I stated this is just a quick dirty hack.

    @timtower not sure what you are thinking of atm but you made me realize something. If my mobs always spawn on the highest block then if the mini game map has a tunnel they will be spawning on it rather than in it. But that's a topic for another thread :)
     
Thread Status:
Not open for further replies.

Share This Page