Jump to content

get the block instance thingy from block


ImaFool

Recommended Posts

Hey guys, probably a java question:

When I for example call

world.getBlockState(pos).getBlock()

and there is a sand block, I want to have "Blocks.sand" as a String. The closest i got to is

world.getBlockState(pos).getBlock().getClass().getTypeName()

but well thats the BlockSand class..

 

So, basically I got the class X with the variable y in it, how can i get the String "X.y"?

Link to comment
Share on other sites

Well, I'm writing a tool for structure generation, (I know there are a few out there), so basically u hit 2 blocks with a new item and it should give you the java code for all the blocks in between there like:

world.setBlockState(pos, Blocks.sand.getStateFromMeta(..));

So what would you suggest to do?

Can I get the block back from the id?

Link to comment
Share on other sites

Hi

 

This link might help to understand BlockStates and metadata and IDs and such.

http://greyminecraftcoder.blogspot.co.at/2014/12/blocks-18.html

 

Bottom line is - you need to think in terms of IBlockStates, not BlockID and metadata.  The only part of your code that needs to know about the metadata numbers is the Block itself, which provides translation between metadata and BlockState for vanilla saving & loading to disk only.  Everything else uses IBlockStates including other parts of your code that interact with your Block.

 

-TGG

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.