Jump to content

Recommended Posts

Posted (edited)

Your question is a bit vague, it's equivalent to asking about getting the int from a Block.

 

Which ResourceLocation do you want? The registry name? The model location? Something else?

Edited by Choonster

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

The registry name is the object's unique identifier, it's not directly related to rendering (though it's used as the default location for blockstates files [for Blocks] and item models [for Items]).

 

Blocks don't have textures, they have models. Models do have textures, though.

 

What exactly are you trying to do?

 

You can use BlockRendererDispatcher#getModelForState to get the IBakedModel for an IBlockState. If you need the model's location rather than the model itself, use BlockStateMapper#getVariants to get a Map<IBlockState, ModelResourceLocation> for a Block and use it to look up the ModelResourceLocation for an IBlockState.

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

Use IBakedModel#getQuads to get the model's BakedQuads and use BakedQuad#getSprite to get the texture of a BakedQuad.

 

You can also use IBakedModel#getParticleTexture to get a model's particle texture.

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 (edited)

In case you want something more specific, this should work.

First you'll have to choose the block state you want to use. For example:

IBlockState state = Blocks.STONE.getDefaultState();

 

Then use:

Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state);

 

EDIT

If you want to specify the side/facing etc. use:

Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);

 

Then you can use something like this to get the texture:

 

    private TextureAtlasSprite getTexture(IBakedModel ibakedmodel, IBlockState state, EnumFacing facing) {
    	List<BakedQuad> quadList = ibakedmodel.getQuads(state, facing, 0L);
        TextureAtlasSprite sprite = quadList.isEmpty() ? ibakedmodel.getParticleTexture() : quadList.get(0).getSprite();
        return sprite == null ? this.missingTexture : sprite;
    }

 

My method above is for my own usage and won't work for some blocks like lava, water and certain tile entity blocks but .getTexture(state) should.

Better yet, take a look at BlockModelShapes.getTexture(state) method. You could copy that and modify it to your liking.

 

You can change the quadList.get(index) to another index to get another quad attached to that facing.

Edited by Vryday_Vrything
punctuation, elaboration
Posted
7 hours ago, MCrafterzz said:

Thanks both of you. Choonster what should I get the IBakedModel from because it can't be used staticly

 

9 hours ago, Choonster said:

You can use BlockRendererDispatcher#getModelForState to get the IBakedModel for an IBlockState.

 

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

BlockRendererDispatcher.getModelForState isn't a static method, it's an instance one. You need to call the method on an instance of BlockRendererDispatcher. You can obtain that instance from Minecraft.getMinecraft().getBlockRendererDispatcher().

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

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.