Jump to content

Not equal to air


Durtle02

Recommended Posts

How do I make this if it isn't equal to air?

 

if (worldIn.isAirBlock(pos.up())){}

 

I have this but it doesn't seem to work. Is there a different block declaration or do I need to test for both air and null?

 

world.getBlockState(positionNumber)!=Blocks.AIR

I don't optimize my code before it works.

Link to comment
Share on other sites

you're comparing a blockstate to a block. add

..... != Blocks.AIR.getDefaultState()

or you can get the block from world.getBlockState(positionNumber).getBlock()

 

so:

 

world.getBlockState(positionNumber) != Blocks.AIR.getDefaultState()

 

or

 

world.getBlockState(positionNumber).getBlock() != Blocks.AIR

 

EDIT:

I take this is something to do with 1.11? as in 1.10.2 there still is a worldObj.isAirBlock(pos);

 

Link to comment
Share on other sites

Please don't check against the air block.  Many mods use "technical" blocks for various things (usually lighting), but which should be treated like air.

 

I'd suggest checking the block's material against Material.AIR

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.

Link to comment
Share on other sites

Oh derp, I got confused with

 

How do I make this if it isn't equal to air?

 

if (worldIn.isAirBlock(pos.up())){}

 

Just add a "!" to the front

 

if (!worldIn.isAirBlock(pos.up())){}

 

isAirBlock returns a boolean so you can use "!" to check for false

Link to comment
Share on other sites

Also one last thing, I still don't understand why my method for players clicking on the block isn't working. Could someone give me a correction of the code?

 

public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ){}

I don't optimize my code before it works.

Link to comment
Share on other sites

Also one last thing, I still don't understand why my method for players clicking on the block isn't working. Could someone give me a correction of the code?

 

public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ){}

You parameters match is it not running at all? Try adding an @Override above it.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Your method signature is wrong.

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.

Link to comment
Share on other sites

Open up the Block class.

Ctrl-F "onBlockActivated"

Copy-paste

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.

Link to comment
Share on other sites

Guys... We live in 2016. IDEs are a thing.

 

While I know I can do this with Eclipse, I prefer not to for very large classes like Block because the list is very very large and often I'm already looking at the method I want to override.

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.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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