Jump to content

[1.12] Apply textures via code?


Recommended Posts

I'm making a simple mod to have decorative ores. I would like to have this thing dynamically, so you can add ores by adding the Id via config.

E.g. The config would look like 

"Ore to create decoration block"
S: decorationOre <

This would create a new block named JASBTweaks:decorative_ore_minecraft_coal_ore. The problem is I really don't know how to get the textures for the block, since I need to use the original ones and need to be applied via code.

This is the DecorativeOre Class:

public class BlockDecorativeOre extends Block{

	public String oreId;
	public short oreMeta;
	public BlockDecorativeOre(String oreId, short oreMeta, String translationKey) {
		this.oreId = oreId;
		this.oreMeta = oreMeta;
		setRegistryName(new ResourceLocation(JASBTweaks.MOD_ID, "decorative_ore_" + oreId.replace(":", "_") + "_" + oreMeta));
		setHarvestLevel("pickaxe", 0);

So when the config is loaded I can register the block like

List<BlockDecorativeOre> decorativeOres = new ArrayList<DecorativeOre>();

public void onConfigLoad() {
	for (int i = 0; i < config.decorativeOres.length; i++) {
		//Get all the meta etc.
		decorativeOres.add(new DecorativeOre(name, meta, translationKey);

The translation key part will surely be treated in another way.

Edited by Insane96MCP
Link to comment
Share on other sites

57 minutes ago, Insane96MCP said:

Uhm, seems like the texture id is still taken from the block's resource location.

Your right, that would only work for vanilla ores.

I'd suggest looking at the ghost block's code.


Classes of interest:




Use this to get the IBakedModel from a BlockState:


Getting it from a ResourceLocation:

IBakedModel bakedModel;
IModel model;
try {
	model = ModelLoaderRegistry.getModel(resourceLocation);
} catch (Exception e) {
  throw new RuntimeException(e);
bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.BLOCK,
		location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()));


Edited by Big_Bad_E
  • Like 1
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.

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.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.