Jump to content

[1.12.2] Getting and setting the direction of any block with a PropertyDirection


Recommended Posts

Posted (edited)

I am trying to check if each block in a list has a PropertyDirection property FACING, and to then change it based on external criteria.

 

I tried to use instanceof BlockHorizontal at first, but quickly learnt that blocks like torches have a FACING variable but only extend from Block. I also tried iterating through the IBlockState.getPropertyKeys() of the block:

for(IProperty<?> p : myBlockState.getPropertyKeys())
{
	if(x == y)
	{
		world.setBlockState(myBlockPos, myBlockState.withProperty(p, Rotation.COUNTERCLOCKWISE_90.rotate((EnumFacing) myBlockState.getValue(p))));
	}
}

but this gives me the error:

The method withProperty(IProperty<T>, V) in the type IBlockState is not applicable for the arguments (IProperty<capture#4-of ?>, EnumFacing)

Are there any better ways of looking for the property of a block regardless of its type?

Edited by ashjack0
Posted (edited)

You need to check that the property is equal to either BlockFacingHorizontal.FACING or BlockFacing.FACING

Edited by Draco18s

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.

Posted
5 minutes ago, Draco18s said:

You need to check that the property is equal to either BlockFacingHorizontal.FACING or BlockFacing.FACING

I don't seem to have a BlockFacingHorizontal or BlockFacing class anywhere in my Forge library

Posted

Sorry, I screwed those names up.

BlockHorizontal is one of them. I can't remember the other one, but the dispenser definitely uses the FACING property and all vanilla blocks that use a FACING property will reference the same ones: the omnidirectional (where ever it is) and the horizontal one (in BlockHorizontal).

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.

Posted
9 hours ago, Draco18s said:

Sorry, I screwed those names up.

BlockHorizontal is one of them. I can't remember the other one, but the dispenser definitely uses the FACING property and all vanilla blocks that use a FACING property will reference the same ones: the omnidirectional (where ever it is) and the horizontal one (in BlockHorizontal).

Ah, BlockHorizontal and BlockDirectional? I initially thought of using these, but BlockTorch for example has a FACING property but does not extend from either of these, and I would still like to access this property. I suppose I could add individual checks for each block that has a FACING property that's not from the two classes above, but this could be tedious and would not account for blocks from other mods which I would ideally like to support.

 

I know that it's hacky, but would it be sensible to use the block meta numbers, and then add 0-3 to it based on what direction the block is already in? myBlockState.getValue(p) would work to verify it's initial direction, my issue above was that I couldn't then change the value of p.

Posted

I suggest looking at how Block#rotateBlock finds the property to change and doing something similar.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
4 hours ago, Choonster said:

I suggest looking at how Block#rotateBlock finds the property to change and doing something similar.

Thank you! I was able to figure it out from that.

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.