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.

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

Featured Replies

Posted

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

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.

  • Author
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

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.

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

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.

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

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.