Jump to content

Recommended Posts

Posted

Hey guys,

 

So a quick question. I'm trying to check the block above my custom block to see if it's not an air block/material, I would like it to be compatible with mods that adds gasses and other stuff, that uses Material.Air. But for some reason it doesn't work.

This is what I'm trying.

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	IBlockState block_above = world.getBlockState(pos.up());
	if(!(block_above.getMaterial() == Material.AIR))
	{
		state = state.withProperty(BLOCK_ABOVE, true);
	}
	else
		state = state.withProperty(BLOCK_ABOVE, false);
	if(block_above.getProperties().containsValue(BlockSlab.EnumBlockHalf.TOP) || block_above.getProperties().containsValue(BlockStairs.EnumHalf.TOP))
	{
		state = state.withProperty(SLAB_STAIR_ABOVE, true);
	}
	else
		state = state.withProperty(SLAB_STAIR_ABOVE, false);
	return state;
}

So the first if statement is the one that doesn't work. The second one works fine.

 

Any idea what I'm doing wrong?

Posted
  On 5/20/2017 at 11:37 PM, Jay Avery said:

What do you mean by "doesn't work"? What result do you get and what do you expect?

Expand  

What I mean, is that no matter what's above my block, I get the same false result on my BLOCK_ABOVE property. What I expect is when there's any kind of block above it, the property should return true and not false, unless it's an air block/material.

Posted (edited)
  On 5/21/2017 at 9:27 AM, diesieben07 said:

Show where you try to access the property.

Expand  

Might as well show you the whole class

  Reveal hidden contents

 

I have been testing if the property BLOCK_ABOVE is working, by adding it to one of the other working if statements. Where it does work. So I can conclude that it has something to do with this if statement.

if(!(block_above.getMaterial() == Material.AIR))
{
	state = state.withProperty(BLOCK_ABOVE, true);
}
else
	state = state.withProperty(BLOCK_ABOVE, false);

 

I just can't see what's wrong with it, and as I mentioned in an earlier post, I was expecting this to return true when there's a block above and false when it's block using the material air, at least that's my end goal.

Edited by Erfurt
Posted (edited)
  On 5/21/2017 at 10:54 AM, diesieben07 said:

Ok, first of all, your boolean logic and formatting is all over the place.

 

First of all, why on earth does the if block have braces but the else block not? Also, != is a thing. Or, much much cleaner:

state = state.withProperty(BLOCK_ABOVE, block_above.getMaterial != Material.AIR)

 

This happens multiple times all over the whole class.

 

And what is this?

 

Why not if (!this.getActualState(...)) ? Why does this if statement not have braces? That is very confusing here!

Expand  

Mostly because I was writing this code while half asleep, but my code should and does still work, other than that one if statement.

 

EDIT: Maybe I need there to be an if statement, because I would need to put in some other code, when I had it working.

Edited by Erfurt

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.