Jump to content

Recommended Posts

Posted (edited)

2018-06-16_13_38_24.thumb.png.6bf53140c5f8f993ccb4776c3c84a3fe.png

I am creating a StandingArrowSign block with 2 blockstate values:

  • rotation: Stores the direction the sign is facing, like Vanilla signs | int, 0-15.
  • arrowFacing: Stores the direction of the arrow on its face | int, 0-7.
public static final PropertyInteger arrowFacing = PropertyInteger.create("arrowfacing", 0, 7);
public static final PropertyInteger ROTATION = PropertyInteger.create("rotation", 0, 15);

There are 16.8=128 possible combinations of these two blockstates, 8 times more than the 16 limit of metadata. So I only stored the rotation value into metadata, and overrid the getActualState method of parent class Block:

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
  	return state.withProperty(arrowFacing, world.getBlockState(pos).getValue(arrowFacing));
}

like the docs said. But reloading the world still resets the rotation to default.

 

My whole class:

  Reveal hidden contents

How to make this value be written into the world saves, like other Vanilla blocks do?

Edited by leduyquang753
Add image
Posted (edited)

The whole point of using Block#getActualState is to set the values of properties that aren't saved to metadata and are instead derived from other data (e.g. surrounding blocks or a TileEntity). World#getBlockState only returns the metadata-based state at that position, so your override of Block#getActualState sets the facing property of the state argument to the same value it already had (0).

 

Since the facing property can't be saved to metadata or derived from surrounding blocks, you need to store it in a TileEntity.

Edited by Choonster
  • Sad 1

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

Capture.png

getActualState isn't magic.

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.

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.