Posted February 24, 201411 yr I want to check if there there isn't a block in specific coodinates Block block = world.getBlock(x, y, z); so have i to say if (block == null).... or if(block == Blocks.air).... ?? or is it the same? Actually i don't know what to write in this signature soooo.... anyway
February 24, 201411 yr Do instead if (block == null || block.material == Material.air) The first one checks to make sure the block isn't null (to avoid null reference errors) the second check checks to see if the block that is there is of the material air, because with mods there can be blocks that should be treated like air, but are not air. (Gasses, technical lighting blocks, etc.) Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
February 24, 201411 yr I may be wrong, but in 1.7 and up it shouldn't really be possible to get a null reference to a block anymore (unless you are working with world gen and have the possibility of not-yet loaded chunks), since air blocks are real blocks now. That being said, it doesn't hurt to check http://i.imgur.com/NdrFdld.png[/img]
February 24, 201411 yr The whole point of getBlock is to return a block no matter what. It can't be null, at worst it would already crash while trying to get the block. It defaults to Blocks.air in most cases. By the way, you have World#isAirBlock.
February 25, 201411 yr I want to check if there there isn't a block in specific coodinates Block block = world.getBlock(x, y, z); so have i to say if (block == null).... or if(block == Blocks.air).... ?? or is it the same? if(block .isAir(world, x, y, z)) would check for air just remember if you pull the code form a specific block when your checking around that block to increase the coordinates as needed if(block .isAir(world, x, y + 1, z)) would check if there's an air block above the Block
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.