I am trying to detect the block at the surface, basically in any given column of blocks what is the y of the top block before the sky, but if its under a overhang or tree it needs to be the actual floor of the ground. basically I want to find cave air blocks. world.canBlockSeeTheSky does not work. Any suggestions? Thanks!
There is a method for getting the topmost block in a given X and Z - I think it's called getTopSolidOrLiquidBlock - but for underground stuff I think you will have to write your own code.
Rollback Post to RevisionRollBack
I have made an unofficial port of the spectacular ExRollerCoaster mod, updated for Minecraft 1.12.2.
Build wonderful roller coasters which can go in ANY direction, and the camera will twist and turn with you.
I'm not releasing it through the usual channels but I hope four years on this site makes me a trustworthy modder.
Links:
public static int getNonAirNonLiquidFromAbove(World world, int x, int z)
{
int y = 255;
boolean foundGround = false;
while(!foundGround && y-- >= 0)
{
Block blockAt = world.getBlock(x,y,z);
// "ground" for our purposes is anything but air, liquid, leaves
foundGround = blockAt != Blocks.air && !blockAt.getMaterial().isLiquid() && !(blockAt instanceof BlockLeaves);
}
return y;
}
If you want to get the first air block from below, just switch a few things around:
public static int getFirstAirFromBelow(World world, int x, int z)
{
int y = 0;
boolean foundAir = false;
while(!foundAir && y++ < 255)
{
Block blockAt = world.getBlock(x,y,z);
foundAir = blockAt == Blocks.air;
}
return y;
}
Feel free to use these and modify them for your purposes. If you do use them, make sure to check that y is indeed between 0 and 255 before doing anything.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
That does return the top most block, but not its Y. Thanks!
I just looked at my code and it looks like it returns the Y but not the block actually. Either way it's not really what you're looking for.
Rollback Post to RevisionRollBack
I have made an unofficial port of the spectacular ExRollerCoaster mod, updated for Minecraft 1.12.2.
Build wonderful roller coasters which can go in ANY direction, and the camera will twist and turn with you.
I'm not releasing it through the usual channels but I hope four years on this site makes me a trustworthy modder.
Links:
That does return the top most block, but not its Y.Thanks!
I must not be understanding the question.
/**
* Finds the highest block on the x, z coordinate that is solid and returns its y coord. Args x, z
*/
public int getTopSolidOrLiquidBlock(int p_72825_1_, int p_72825_2_)
{
getTopSolidOrLiquidBlock most definitely returns a Y
EDIT: Do you want the block instead? You can use the Y to grab it.
I am trying to detect the block at the surface, basically in any given column of blocks what is the y of the top block before the sky, but if its under a overhang or tree it needs to be the actual floor of the ground. basically I want to find cave air blocks. world.canBlockSeeTheSky does not work. Any suggestions? Thanks!
There is a method for getting the topmost block in a given X and Z - I think it's called getTopSolidOrLiquidBlock - but for underground stuff I think you will have to write your own code.
I have made an unofficial port of the spectacular ExRollerCoaster mod, updated for Minecraft 1.12.2.
Build wonderful roller coasters which can go in ANY direction, and the camera will twist and turn with you.
I'm not releasing it through the usual channels but I hope four years on this site makes me a trustworthy modder.
Links:
original mod homepage
source code of my port
download mod jar here
That does return the top most block, but not its Y. Thanks!
I have this old method you can use:
If you want to get the first air block from below, just switch a few things around:
Feel free to use these and modify them for your purposes. If you do use them, make sure to check that y is indeed between 0 and 255 before doing anything.
I just looked at my code and it looks like it returns the Y but not the block actually. Either way it's not really what you're looking for.
I have made an unofficial port of the spectacular ExRollerCoaster mod, updated for Minecraft 1.12.2.
Build wonderful roller coasters which can go in ANY direction, and the camera will twist and turn with you.
I'm not releasing it through the usual channels but I hope four years on this site makes me a trustworthy modder.
Links:
original mod homepage
source code of my port
download mod jar here
I must not be understanding the question.
getTopSolidOrLiquidBlock most definitely returns a Y
EDIT: Do you want the block instead? You can use the Y to grab it.
Block block = world.getBlock(x, y, z);
Obligatory tacky self advertisement: Shovel your hard earned rupees at my Patreon, pretty please?)
(Hey, listen! Go check out Druidry!)
- Teeheehee