Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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

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

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.