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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Please read the FAQ and post logs as described there.
    • Upon starting the server I get; [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [     Framework (framework) has failed to load correctly §7java.lang.NoClassDefFoundError: net/minecraft/client/gui/components/toasts/Toast ] I suspect there is a (possibly a few) client-only mods installed on my server. Any help would be appreciated! (Yes I know there are a lot of mods...) Here is the crash log:   https://paste.ee/p/pRz5mhMl#s=0
    • That's basically what the failure does, my apologies for failing to specify.  It just tries again on the next tick until it detects the entities for that chunk are loaded, and then tries to load the entity.  From there it gets into different failure states depending on what goes wrong, but in short, if the entity fails to load once the entity list becomes available, the request is cleared and must be resubmitted by the end user.  There should be few cases where that actually happens. Yes, that is my understanding of forceloading.  That's why on a successful summon, it removes the forceload.  Otherwise it does just leave the chunks loaded long term. Thank you for your help, any knowledge is useful!  I don't often mess with forceloading and my prior experience is 1.16 so I'm also a bit out of my depth haha.
    • I will have to do more research about 1.18 chunk loading. You were unclear about how your code manages with the entity load failure. If you simply used a loop, I suggest submitting a tick task to the next tick which does the same thing, checking if the entities are loaded and if so teleporting the right one else submitting another tick task etc. Also I think forceloading permanently force loads the chunk, and it only starts to unload when you make a subsequent call to mark the chunk as not forceloaded. I may be completely wrong, I dont know much about 1.18, most of my experience is 1.20. Good luck I hope you figure it out after all this time 😅
    • i managed to fix it by reinstalling the modpack and re-add all the extra mods I've had previously.
  • Topics

×
×
  • Create New...

Important Information

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