Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.x] [SOLVED - For real this time] Setting/copying a block model from/to another block
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
CosmicDan

[1.12.x] [SOLVED - For real this time] Setting/copying a block model from/to another block

By CosmicDan, September 23, 2017 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

CosmicDan    5

CosmicDan

CosmicDan    5

  • Tree Puncher
  • CosmicDan
  • Members
  • 5
  • 42 posts
Posted September 23, 2017 (edited)

Howdy,

 

I've a desire of creating blocks dynamically based on the existence of other blocks in the game. These blocks are duplicates of other blocks but with slightly changed functionality - ore variants, if it's any significance. Everything works perfectly, except the world block models just show the missing texture placeholder (the hand and inventory model/textures are fine).

 

Changes since 1.7.10 have taught me that I need to set a block model which has proven a bit more complicated than overriding getIcon. I think I need to set the IBakedModel somewhere, but all I have is this:

 

public void registerBlockRender(Block newBlock, Block baseBlock) {
	// set item model
	ItemModelMesher itemModelMesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
	itemModelMesher.register(Item.getItemFromBlock(newBlock), 0, new ModelResourceLocation(baseBlock.getRegistryName().getResourceDomain() + ":" + baseBlock.getRegistryName().getResourcePath()));

	// set world block model
	IBakedModel baseModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(baseBlock.getDefaultState());
	// ?
}

 

As mentioned, the item model works fine - it's an exact duplicate of the original item model - but I'm stuck on what to do about the actual world block model. I've looked around flailed around the sources trying to find this out but I'm clueless. Perhaps I need to register to a ModelBake event that I read about somewhere...?

 

Context: These blocks are created and registered during FMLInitializationEvent, which calls the above registration method via client proxy if the block creation and registration was successful. I do it here because I want to be sure that all other mods have registered their ores (which they should be doing in preInit).

Edited September 25, 2017 by CosmicDan
Mark as solved
  • Quote

CosmicDan.com

Windows software, Android hacking, and other curios

Share this post


Link to post
Share on other sites

Draco18s    2402

Draco18s

Draco18s    2402

  • Reality Controller
  • Draco18s
  • Members
  • 2402
  • 15924 posts
Posted September 23, 2017

For blocks, you need a custom IPerspectiveAwareModel and IStateMapper.

 

Check out GrayGhost's Camouflage block

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe04_block_dynamic_block_model1

  • Like 1
  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

CosmicDan    5

CosmicDan

CosmicDan    5

  • Tree Puncher
  • CosmicDan
  • Members
  • 5
  • 42 posts
Posted September 23, 2017
2 hours ago, Draco18s said:

For blocks, you need a custom IPerspectiveAwareModel and IStateMapper.

 

Check out GrayGhost's Camouflage block

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe04_block_dynamic_block_model1

Ah I even have a tab of GreyGhost's MBE repo to help me get up to date, funny!

 

I couldn't get it to work on first attempt but this is quite a bit to take in. However I realize now it's probably better I just copy textures into the mod myself and manually define the ore block extras as it would allow Resource Packs to retexture them too. I'll just only register the ore variants if an oredict entry exists for it, similar to what you do in Ore Flowers.

 

Thanks :)

  • Quote

CosmicDan.com

Windows software, Android hacking, and other curios

Share this post


Link to post
Share on other sites

CosmicDan    5

CosmicDan

CosmicDan    5

  • Tree Puncher
  • CosmicDan
  • Members
  • 5
  • 42 posts
Posted September 24, 2017 (edited)

At the risk of incurring the wrath of Lex, these new Forge changes feel like a serious case of over-engineering (or maybe it's Mojang to blame, or just the fact that it's an API strapped onto a reverse-engineered application...)

 

Determined to get the original goal I wanted - to assign textures/models dynamically from the base block of runtime-generated blocks - I still can't figure out the block model copying. The MBE case seems like it's way too complicated and not necessary for this case - since the models dont need to be *runtime dynamic* - I thought "Why can't I just grab the model from the base blockstate? I'll try that". So, something like this...

 

ModelLoader.setCustomStateMapper(newBlock, new BlockRichOreStateMapper());

...and...

public class BlockRichOreStateMapper extends StateMapperBase {
	@Override
	protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
		log.info(state.getBlock().getClass().getName()); // hello world
		Block blockToModel = state.getBlock();
		if (state.getBlock() instanceof BlockRichOre) {
			blockToModel = ((BlockRichOre) state.getBlock()).getBaseBlock();
		}
		return new ModelResourceLocation(Block.REGISTRY.getNameForObject(blockToModel), this.getPropertyString(state.getProperties()));
	}
}

 

No idea if that would work, but it is just a test - I don't even get any log output, the getModelResourceLocation method is never called. I am calling setCustomStateMapper from a client-sided method in the init phase.

 

So I found out about some ModelRegistryEvent and moved it to there instead, but this event is fired before init - but I need to register the blocks in init. So it seems that models are registered preInit, or at least before init - and that might be why I couldn't get something based on GreyGhost's MBE's CamoBlock working either...

 

So. Given the situation that I need to register my blocks AFTER every other mod has registered blocks, how then can I assign models to these blocks when Forge needs/wants to - which is before my blocks even exist?

Edited September 24, 2017 by CosmicDan
  • Quote

CosmicDan.com

Windows software, Android hacking, and other curios

Share this post


Link to post
Share on other sites

Choonster    1651

Choonster

Choonster    1651

  • Reality Controller
  • Choonster
  • Forge Modder
  • 1651
  • 5097 posts
Posted September 24, 2017

Blocks (and other registry entries) should be registered in the appropriate registry event (i.e. RegistryEvent.Register<Block>). You can control when your Blocks are registered in relation to the other mod using the EventPriority property of the @SubscribeEvent annotation.

  • Like 1
  • Quote

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.

Share this post


Link to post
Share on other sites

CosmicDan    5

CosmicDan

CosmicDan    5

  • Tree Puncher
  • CosmicDan
  • Members
  • 5
  • 42 posts
Posted September 24, 2017
49 minutes ago, Choonster said:

Blocks (and other registry entries) should be registered in the appropriate registry event (i.e. RegistryEvent.Register<Block>). You can control when your Blocks are registered in relation to the other mod using the EventPriority property of the @SubscribeEvent annotation.

Thanks, I didn't realize that the event priority could help make my blocks register last.

 

Indeed, when using the new Forge registration events, the registration order is as desired: Blocks -> Items -> Renderers. Fingers crossed...!

  • Quote

CosmicDan.com

Windows software, Android hacking, and other curios

Share this post


Link to post
Share on other sites

CosmicDan    5

CosmicDan

CosmicDan    5

  • Tree Puncher
  • CosmicDan
  • Members
  • 5
  • 42 posts
Posted September 25, 2017

Migrating to the new registration event system solved everything. The simpler BlockRichOreStateMapper I shared above applied through ModelLoader.setCustomStateMapper via ModelRegistryEvent worked perfectly to copy the vanilla block model on registration :) As is usually the case, only my ignorance was to blame for this frustration.

 

Thanks again guys!

  • Quote

CosmicDan.com

Windows software, Android hacking, and other curios

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      Forge Not Opening

      By diesieben07 · Posted 18 minutes ago

      Also post the debug.log.
    • diesieben07
      [1.16.4]NullPointerException when using registered custom features

      By diesieben07 · Posted 19 minutes ago

      Show this class: McbbsWikiBiomeMaker.makeMcbbsWikiNormalBiome
    • diesieben07
      Detect recover an entity right click

      By diesieben07 · Posted 25 minutes ago

      Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • diesieben07
      how to make and .smd file parser for forge

      By diesieben07 · Posted 28 minutes ago

      You need to write a renderer for it.
    • diesieben07
      [1.16.4] Get IChunk World / get current World for the overworld.

      By diesieben07 · Posted 29 minutes ago

      What's the context? If you only have an IChunk (not a Chunk) you are likely in world generation, which does not have a world yet.
  • Topics

    • myrqn
      3
      Forge Not Opening

      By myrqn
      Started 4 hours ago

    • QWERTY 52 38
      1
      [1.16.4]NullPointerException when using registered custom features

      By QWERTY 52 38
      Started 1 hour ago

    • ElpisII
      1
      Detect recover an entity right click

      By ElpisII
      Started 2 hours ago

    • bouwmeester2003
      4
      how to make and .smd file parser for forge

      By bouwmeester2003
      Started December 8, 2018

    • MistyMarshes
      1
      [1.16.4] Get IChunk World / get current World for the overworld.

      By MistyMarshes
      Started 5 hours ago

  • Who's Online (See full list)

    • Ohmlolgg
    • kolbixbro
    • tf2_mandeokyi
    • CaelTheQuail
    • CookieLukas
    • diesieben07
    • S-Spirit
    • PauJM02
    • Thorius
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.x] [SOLVED - For real this time] Setting/copying a block model from/to another block
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community