Jump to content

[1.10.2] Need help checking block below my custom block


Recommended Posts

Posted

Hey guys,

 

I have some trouble checking the block below my custom block, I'm checking to see if the block is a stair/slab block or something else. If the block below is a stair/slab, I need it to add a true boolean property to my custom block, and false for everything else.

 

I have tried the code below, and that worked for checking if the block below was a stair, but not if it was a slab. Any help would be very much appreciated.

 

 

  Reveal hidden contents

 

 

Also as a little side question, is it in anyway possible to check and see if the stair/slab is the bottom variant, if so, how would I go about doing that?

Posted
  On 1/28/2017 at 1:44 AM, diesieben07 said:

This is something that should be done in getActualState, take a look at BlockFence for an example.

 

Cool thanks. However this still doesn't make the BlockSlab work. Any idea why, or how I can make it see slabs below?

New updated code

 

  Reveal hidden contents

 

Posted
  On 1/28/2017 at 2:45 AM, diesieben07 said:

Would need to see more of your code and a more detailed explanation of what's not working.

 

Whole class

 

  Reveal hidden contents

 

 

What's not working is, that when I have a slab below my custom block, is doesn't set it's property to true, as the stair does. And I really don't know why.

Posted

Regarding my little side question, I was wondering if anyone here knows if this is possible, and maybe how to do it?

  On 1/28/2017 at 1:28 AM, Erfurt said:

Also as a little side question, is it in anyway possible to check and see if the stair/slab is the bottom variant, if so, how would I go about doing that?

Posted
  On 1/28/2017 at 8:27 PM, diesieben07 said:

  Quote
if(block_under instanceof BlockSlab)

{

state = state.withProperty(SLAB_STAIR, true);

}

if(block_under instanceof BlockStairs)

{

state = state.withProperty(SLAB_STAIR, true);

}

else

state = state.withProperty(SLAB_STAIR, false);

        return state;

    }

Ok, let's walk through this assuming there is a slab below.

[*]

block_under

is a

BlockSlab

so execute the if statement: set

state

to

state.withProperty(SLAB_STAIR, true)

.

[*]

block_under

is not a

BlockStair

, so execute the else branch: set

state

to

state.withProperty(SLAB_STAIR, false)

.

End result:

SLAB_STAIR

is set to

false

.

 

I see now... I should use else if on the second if statement, or put both in the same one, right?

  Quote

  Quote
Also as a little side question, is it in anyway possible to check and see if the stair/slab is the bottom variant, if so, how would I go about doing that?
BlockSlab

and

BlockStairs

has a property

HALF

, which you can check.

 

I think I understand this, but how would I get the property from block_under? I mean is there a "simple" way of getting it?

 

I know I'm asking a lot here, and I want to thank you for your patience and help :)

Posted
  On 1/28/2017 at 9:16 PM, diesieben07 said:

  Quote
I see now... I should use else if on the second if statement, or put both in the same one, right?
else-if is the correct solution, yes.

 

  Quote
I think I understand this, but how would I get the property from block_under? I mean is there a "simple" way of getting it?
You need to keep the
IBlockState

, not the

Block

(i.e. don't immediately call

getBlock

). Then you can access all

IBlockState

methods, like

getValue

.

 

I see, thank you

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.