Jump to content

Recommended Posts

Posted (edited)

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 <
	minecraft:coal_ore
>

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) {
		super(Material.ROCK);
		this.oreId = oreId;
		this.oreMeta = oreMeta;
		
		setRegistryName(new ResourceLocation(JASBTweaks.MOD_ID, "decorative_ore_" + oreId.replace(":", "_") + "_" + oreMeta));
		setTranslationKey(translationKey);
		setCreativeTab(CreativeTabs.DECORATIONS);
		setHardness(1.5f);
		setResistance(5.0f);
		setHarvestLevel("pickaxe", 0);
		ModBlocks.BLOCKS.add(this);
	}
	
	
}

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
Posted
2 hours ago, Big_Bad_E said:

I believe you can use a custom IStateMapper to set the blockstate of your block to the model of the vanilla/modded ore block.

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

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

https://github.com/AbrarSyed/SecretRoomsMod-forge/tree/master/src/main/java/com/wynprice/secretroomsmod/render

Classes of interest:

https://github.com/AbrarSyed/SecretRoomsMod-forge/blob/master/src/main/java/com/wynprice/secretroomsmod/base/BaseFakeBlock.java

https://github.com/AbrarSyed/SecretRoomsMod-forge/blob/master/src/main/java/com/wynprice/secretroomsmod/render/fakemodels/FakeBlockModel.java

https://github.com/AbrarSyed/SecretRoomsMod-forge/blob/master/src/main/java/com/wynprice/secretroomsmod/base/interfaces/ISecretBlock.java

Use this to get the IBakedModel from a BlockState:

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

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

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.