Jump to content

[SOLVED] Get a variant string value from block meta/state


CosmicDan

Recommended Posts

Hi,

 

I've been trying to figure out how to get a variant property string (for the purposes of building a ModelResourceLocation for a subblock) programmatically, given a block meta and/or blockstate. The variants seem to be ordered the same as meta, but I am not sure if this is always the case. If it is, is there a better way than doing blockState.getValue(blockState.getPropertyKeys(...))? If it is not the case, how would one achieve this?

 

Also, I've noticed there is a getVariants method in BlockStateMapper, but I'm unable to get a handle on the BlockModelShapes as early as I require (in the ModelRegistryEvent) sadly.

 

Cheers.

Edited by CosmicDan
Mark as solved

Windows software, Android hacking, and other curios

Link to comment
Share on other sites

Create an instance of an anonymous class that extends StateMapperBase and implements StateMapperBase#getModelResourceLocation to return a dummy ModelResourceLocation (e.g. new ModelResourceLocation("minecraft:air")). You can then use StateMapperBase#getPropertyString to get a property string to use as the variant of a ModelResourceLocation.

 

You can see how I do this in my mod here and here.

  • Like 2

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.

Link to comment
Share on other sites

Oh wow that seems really obvious now, I already use #getPropertyString in an actual StateMapper already *facepalm*

 

Thanks heaps!

 

An aside, would you happen to have any recommended reading for the latest Forge stuff (in addition to the Forge docs and TheGreyGhost's articles/MBE repo)? I recently read a gist of yours that was helpful.

Windows software, Android hacking, and other curios

Link to comment
Share on other sites

I try to keep TestMod3 up to date with the latest Forge/Minecraft changes, so you can reference it to see how to adapt to recent changes or how to implement various features.

 

You can also search this forum to see if anyone has asked about the topic before.

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

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.