How to detect how many blocks above player

Discussion in 'Plugin Development' started by henrylee99, May 3, 2012.

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

    henrylee99

    Hey I'm trying to create a suffication mod and I was wondering how to detect how many blocks are above the player. For example if the player has 3 or more blocks above him his exp level starts to drop and eventually starts taking damage....


    Also I was wondering of there are any thirst mods or if you can tell me how to create one...

    Thanks in advance...
     
  2. Offline

    lx3krypticx

    Mod or Plugin?
     
  3. Offline

    Iron_Crystal

    Plugin? This is plugin development after all...

    henrylee99

    You can get the players location, and then make a for loop that checks every block above the player. If the block is not Air, then it is solid.
     
  4. Offline

    Father Of Time

    I would do as stated above, except I would personally use a BlockIterator over a loop. You know the world height (256 isn't it... Shrugs), so I would do the following: (note: this was written in notepad and likely contains typos)

    Code:
        public Integer GetSolidBlocksAbove()
        {
            Player player = YOURPLAYERSOURCE;
            World world = player.getWorld();
            Location location = player.getLocation();
            int distance = 256 - loc.getBlockY();
            int SolidAboveCount = 0;
     
            BlockIterator bi = new BlockIterator( world, location.toVector(), new Vector( 0, 1, 0 ), 0, distance );
            while( bi.hasNext() )
            {
                Block toinspect = bi.next();
                if( toinspect.getType() != Material.AIR )
                    SolidAboveCount++;
            }
            return SolidAboveCount;
        }
    This will take the players location, look straight up and shoot a 'ray' the exact amount of blocks from where you stand to the maps max height, then it takes every block the 'ray' passes through and evaluates them in a loop, if any of those blocks aren't air it counts it. Once the loop and counting is done the function returns the total count of solid blocks above the player.

    I hope this makes sense and helps, good luck with your project! :D
     
Thread Status:
Not open for further replies.

Share This Page