Jump to content

Rotatable Blocks


vroominator

Recommended Posts

Hi guys, I've got a little question about rotatable blocks.

By rotatable blocks I mean blocks that face you when you place them or rotate when you hit them with an item. I know one way to do this, and that's with block metadata, but I've seen mods like IC2 cram a bunch of rotatable blocks into 1 block id, so they can't be using metadata for the rotation. Example: a macerator has eight states:

On & Forward, On & Backward, On & Left, & On & Right, Off & Forward &, Off & Backward, Off & Left, Off & Right. Doing this with metadata would use up 8 of the 16 available metadata slot things. How do mods like this do it? Are they using some form of witchcraft, or am I just missing something painfully obvious?

Link to comment
Share on other sites

Either they store the rotation in TileEntities and the block types in the metadata, or vice versa.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

actually...

metadata is an int

which gives you 32(31) workable bits for metadata

you can break those bits into smaller chunks so that bits 0-3 store rotation value, 4-x store operational state, x-xx stores timer values...etc.  Requires knowledge of bitshifting and bitwise operators (bitwise and, bitwise or).

 

Several vanilla blocks do exactly that for rotational metadata.  The repeater, for instance.  Stores its rotation, delay ticks, and on-state all in meta-data.  Pistons do much the same thing.

 

I have a crafting table block that stores its rotation and current operational state both in metadata (requires breaking it up into bits to decode though).

 

Tile entities are certainly another option though, and can be much easier to work with than bitfields and bitwise operations.

Link to comment
Share on other sites

The metadata for a block is an int, yes, but the Anvil save format reserves 16 bit of block data, 12 bit for the block IDs and 4 bit of metadata. Try to create a block with metadata higher as 15. It may work, but it won't be saved correctly!

 

http://www.minecraftwiki.net/wiki/Anvil_file_format

 

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Ahh, that was info I've never seen.  No, I've never tried to use ALL the bits of a blocks meta-data. 

 

Armed with that knowledge...it makes me wonder why they even leave an int open in the block for meta-data?  Wouldn't it more clearly convey what it is for as a boolean bitfield...or something more representative of its true size? (smaller than short...bigger than byte...hmm)

 

Thanks for the link, and sorry for posting _uninformed/incorrect_ information.

 

 

Link to comment
Share on other sites

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.