Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

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 ;)

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.