Jump to content
  • Home
  • Files
  • Docs
  • Merch
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.8] [Solved] Block with ISmartModel not rendering as Item (TGG?)
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
SnowyEgret

[1.8] [Solved] Block with ISmartModel not rendering as Item (TGG?)

By SnowyEgret, August 11, 2015 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

SnowyEgret    4

SnowyEgret

SnowyEgret    4

  • Creeper Killer
  • SnowyEgret
  • Members
  • 4
  • 112 posts
Posted August 11, 2015

I have a block with an ISmartModel that renders fine when placed. When in inventory, tossed, or in hand, it is being rendered as a block with a texture (with its .png in the textures folder). It is my understanding that if I want my smart model to render as an item, I have to do this (#initClientOnly):

 

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/mbe04_block_smartblockmodel1/StartupClientOnly.java

 

Here is my implementation:

 

public void registerItemBlockModels() {
	System.out.println("Registering ItemBlock models...");
	ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();
	String name = StringUtils.underscoreNameFor(BlockMaquette.class);
	Item item = GameRegistry.findItem(MoJo.MODID, name);
	ModelResourceLocation mrl = new ModelResourceLocation(MoJo.MODID + ":" + name, "inventory");
	mesher.register(item, 0, mrl);

	System.out.println("item=" + item);
	System.out.println("mrl=" + mrl);
	System.out.println("model=" + mesher.getModelManager().getModel(mrl));
}

 

 

And here is the console:

 

 

[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.MoJo:init:46]: Intializing------------------------------------------------------------------------------------------------------------
[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.CommonProxy:registerGuiHandler:206]: Registering gui handler...
[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.CommonProxy:registerEventHandlers:132]: Registering event handlers...
[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.CommonProxy:registerTileEntities:140]: Registering tile entities...
[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.ClientProxy:registerItemModels:30]: Registering Item models...
[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.ClientProxy:registerItemBlockModels:49]: Registering ItemBlock models...
[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.ClientProxy:registerItemBlockModels:56]: item=net.minecraft.item.ItemBlock@158f0af4
[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.ClientProxy:registerItemBlockModels:57]: mrl=mojo:block_maquette#inventory
[17:46:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.ClientProxy:registerItemBlockModels:58]: model=net.minecraftforge.client.model.IFlexibleBakedModel$Wrapper@3edea9e6

 

 

As you can see, the model is being registered in init and on the client side as instructed. I am assuming the json is set up properly because it is rendering with a texture in inventory, tossed, and in hand. The ISmartModel is rendering fine when placed.

 

Is there something I have missed?

 

Where can I insert printlns or breakpoints to debug this?

  • Quote

Share this post


Link to post
Share on other sites

SnowyEgret    4

SnowyEgret

SnowyEgret    4

  • Creeper Killer
  • SnowyEgret
  • Members
  • 4
  • 112 posts
Posted August 12, 2015

Can someone suggest where I can put a breakpoint to debug my problem?

 

TGG, in MBE04, you suggest overriding #getActualState

 

 

@Override
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
  {
    return state;  //for debugging - useful spot for a breakpoint.  Not necessary.
  }

 

 

but this doesn't help me. It is not being called when the item model is being rendered.

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    711

TheGreyGhost

TheGreyGhost    711

  • Reality Controller
  • TheGreyGhost
  • Members
  • 711
  • 2805 posts
Posted August 14, 2015

Hi

 

If your item is a ISmartItemModel then handleItemState() is good.

 

Otherwise, I've used this spot a lot:

ItemModelMesher.getItemModel()

 

getActualState is useful for blocks because there are so many other blocks in addition to yours that you get hundreds of nuisance breaks.  But with items you just put yours in the hotbar and it's the only one that reaches the breakpoint, so it's not an issue.

 

-TGG

 

 

 

 

  • Quote

Share this post


Link to post
Share on other sites

SnowyEgret    4

SnowyEgret

SnowyEgret    4

  • Creeper Killer
  • SnowyEgret
  • Members
  • 4
  • 112 posts
Posted August 14, 2015

Thanks Sir Ghost for getting back to me  :)

 

I've got a breakpoint in ItemModelMesher.getItemModel(). For reference here is the method:

 

 

    public IBakedModel getItemModel(ItemStack stack)
    {
        Item item = stack.getItem();
        IBakedModel ibakedmodel = this.getItemModel(item, this.getMetadata(stack));

        if (ibakedmodel == null)
        {
            ItemMeshDefinition itemmeshdefinition = (ItemMeshDefinition)this.shapers.get(item);

            if (itemmeshdefinition != null)
            {
                ibakedmodel = this.modelManager.getModel(itemmeshdefinition.getModelLocation(stack));
            }
        }

        if(ibakedmodel instanceof net.minecraftforge.client.model.ISmartItemModel)
        {
            ibakedmodel = ((net.minecraftforge.client.model.ISmartItemModel)ibakedmodel).handleItemState(stack);
        }

        if (ibakedmodel == null)
        {
            ibakedmodel = this.modelManager.getMissingModel();
        }

        return ibakedmodel;
    }

 

 

item is an ItemBlock as expected, but ibakedmodel is an IFlexibleBakedModel. Seems I want it to be and ISmartItemModel.

 

In MB04 there is no mention of an ISmartItemModel, only the block's ISmartModel. What do I need to do so that this.getItemModel(item, this.getMetadata(stack)) returns an ISmartItemModel? Do I need an implementation of ISmartItemModel? If so, how do I register it in my ModelBakeEvent handler?

 

Here is my ModelBakeEvent handler:

 

 

public void onModelBake(ModelBakeEvent event) {
	IRegistry r = event.modelRegistry;
	r.putObject(ModelResourceLocations.forClass(BlockHighlight.class), new BlockHighlightSmartModel());

	// From MBE04 ModelBakeEventHandler:
	// IBakedModel existingModel = (IBakedModel)object;
	// CamouflageISmartBlockModelFactory customModel = new CamouflageISmartBlockModelFactory(existingModel);
	// event.modelRegistry.putObject(CamouflageISmartBlockModelFactory.modelResourceLocation, customModel);
	// From MBEO4 CamouflageISmartBlockModelFactory:
	// public static final ModelResourceLocation modelResourceLocation = new ModelResourceLocation(
	// "minecraftbyexample:mbe04_block_camouflage");

	r.putObject(new ModelResourceLocation("mojo:block_maquette"), new BlockMaquetteSmartModel());

[/spoiler]

 

 

  • Quote

Share this post


Link to post
Share on other sites

EverythingGames    19

EverythingGames

EverythingGames    19

  • Diamond Finder
  • EverythingGames
  • Forge Modder
  • 19
  • 388 posts
Posted August 14, 2015

Hi, to create your ISmartItemModel, implement it where it is needed. To add it to the model registry (in ModelBakeEvent), define your modelresourcelocation in a field use it to create an object in your ModelBakeEvent. Check the instance of the object to IBakedModel and create a cast IBakedModel to the object. Create a new YourSmartItemModelClass object (the class created implementing ISmartItemModel) and then use the putObject() method to add the smartitemmodel object you just created. Sorry if my explanation was rubbish, here's a snippet of code that might help you out:

 

ModelBakeClass:

public void onEvent(ModelBakeEvent event)
{

    Object object = event.modelRegistry.getObject(YOURMODELRESOURCELOCATION);

    if(object instanceof IBakedModel)
    {

        IBakedModel bakedmodel = (IBakedModel) object;
        
        YourSmartItemModelClass smartmodel = new YourSmartItemModelClass(bakedmodel);

        event.modelRegistry.putObject(YOURMODELRESOURCELOCATION, smartmodel);

    }

}

  • Quote

Share this post


Link to post
Share on other sites

SnowyEgret    4

SnowyEgret

SnowyEgret    4

  • Creeper Killer
  • SnowyEgret
  • Members
  • 4
  • 112 posts
Posted August 14, 2015

What should the ModelResourceLocator look like?

 

I have already registered an ISmartModel for my block with mrl=mojo:block_maquette.

When I register the ISmartItemModel should the mrl be mojo:block_maquette#inventory?

 

Also, and this is a question for TGG, MB04 seems to suggest that an ISmartItemModel is not necessary and all we have to do is the extra work during the init stage on the client side. Have I misunderstood?

 

 

  public static void initClientOnly()
  {
    // This is currently necessary in order to make your block render properly when it is an item (i.e. in the inventory
    //   or in your hand or thrown on the ground).
    // Minecraft knows to look for the item model based on the GameRegistry.registerBlock.  However the registration of
    //  the model for each item is normally done by RenderItem.registerItems(), and this is not currently aware
    //   of any extra items you have created.  Hence you have to do it manually.  This will probably change in future.
    // It must be done in the init phase, not preinit, and must be done on client only.
    Item itemBlockCamouflage = GameRegistry.findItem("minecraftbyexample", "mbe04_block_camouflage");
    ModelResourceLocation itemModelResourceLocation = new ModelResourceLocation("minecraftbyexample:mbe04_block_camouflage", "inventory");
    final int DEFAULT_ITEM_SUBTYPE = 0;
    Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemBlockCamouflage, DEFAULT_ITEM_SUBTYPE, itemModelResourceLocation);
  }

 

 

  • Quote

Share this post


Link to post
Share on other sites

SnowyEgret    4

SnowyEgret

SnowyEgret    4

  • Creeper Killer
  • SnowyEgret
  • Members
  • 4
  • 112 posts
Posted August 14, 2015

Ok, I understand.

 

My smart model must implement both ISmartModel and ISmartItemModel. ISmartItemModel adds one method #handleItemState.

 

Giving it a try...

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    711

TheGreyGhost

TheGreyGhost    711

  • Reality Controller
  • TheGreyGhost
  • Members
  • 711
  • 2805 posts
Posted August 14, 2015

Ok, I understand.

 

My smart model must implement both ISmartModel and ISmartItemModel. ISmartItemModel adds one method #handleItemState.

Also, and this is a question for TGG, MB04 seems to suggest that an ISmartItemModel is not necessary and all we have to do is the extra work during the init stage on the client side. Have I misunderstood?

You only need ISmartItemModel if you want to customise your item's appearance based on the item state (for example - change the appearance if your item is damaged - since the damage information is stored in an ItemStack).

 

To summarise - if you want to customise the block appearance when placed, you need to implement ISmartBlockModel.  It sounds like you've got this bit working.

If you also want to customise the block appearance when in inventory or tossed or in your hand, you need to implement ISmartItemModel as well - but the trick here is that you can't use the same information to customise the appearance.  ISmartBlockModel gets to look at the IBlockState but there is no such thing for an item you're holding.  Items use the ItemStack 'damage' field and (if present) NBT information.

 

Could you describe a bit more what you're trying to do?  i.e. how should the Item appearance be customised?

 

-TGG

 

  • Quote

Share this post


Link to post
Share on other sites

SnowyEgret    4

SnowyEgret

SnowyEgret    4

  • Creeper Killer
  • SnowyEgret
  • Members
  • 4
  • 112 posts
Posted August 15, 2015

The block in place should look the same as when in inventory, tossed, and in hand.

 

Here are #handleBlockState and #handleItemState:

 

 

@Override
public IBakedModel handleBlockState(IBlockState state) {

	String name = ((IExtendedBlockState) state).getValue(BlockMaquette.PROP_NAME);
	Iterable<Selection> selections = ((IExtendedBlockState) state).getValue(BlockMaquette.PROP_SELECTIONS);
	EnumFacing facing = (EnumFacing) state.getValue(BlockMaquette.PROP_FACING);

	generateQuads(name, selections, facing);
	return this;
}

@Override
public IBakedModel handleItemState(ItemStack stack) {

                // Instanciating te just to read from tag
	BlockMaquetteTileEntity te = new BlockMaquetteTileEntity();
	te.readFromNBT(stack.getTagCompound());

	String name = te.getName();
	Iterable<Selection> selections = te.getSelections();
	EnumFacing facing = te.getFacing();

	generateQuads(name, selections, facing);
	return this;
}

 

 

This is all working fine. Each method generates the same quads.

 

When I debug with a breakpoint in ItemModelMesher#getItemModel, stack.getItem() is still not returning an ISmartItemModel and this if statement evaluates false:

 

        if(ibakedmodel instanceof net.minecraftforge.client.model.ISmartItemModel)
        {
            ibakedmodel = ((net.minecraftforge.client.model.ISmartItemModel)ibakedmodel).handleItemState(stack);
        }

 

Now that my smart model implements both ISmartModel and ISmartItemModel, what should my ModelBakeEvent handler look like? Which ModelResourceLocation should be registered? or should both be registered?

 

public void onModelBake(ModelBakeEvent event) {
	event.modelRegistry.putObject(new ModelResourceLocation("mojo:block_maquette"), new BlockMaquetteSmartModel());
	event.modelRegistry.putObject(new ModelResourceLocation("mojo:block_maquette", "inventory"), new BlockMaquetteSmartModel());

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    711

TheGreyGhost

TheGreyGhost    711

  • Reality Controller
  • TheGreyGhost
  • Members
  • 711
  • 2805 posts
Posted August 15, 2015

Now that my smart model implements both ISmartModel and ISmartItemModel, what should my ModelBakeEvent handler look like? Which ModelResourceLocation should be registered? or should both be registered?

 

public void onModelBake(ModelBakeEvent event) {
	event.modelRegistry.putObject(new ModelResourceLocation("mojo:block_maquette"), new BlockMaquetteSmartModel());
	event.modelRegistry.putObject(new ModelResourceLocation("mojo:block_maquette", "inventory"), new BlockMaquetteSmartModel());

Your code looks like it should work.  Yes you should register both of those ModelResourceLocations - the first is used for blocks, the second for inventory, so if you don't register the inventory it will substitute the missing model.

 

-TGG

  • Quote

Share this post


Link to post
Share on other sites

SnowyEgret    4

SnowyEgret

SnowyEgret    4

  • Creeper Killer
  • SnowyEgret
  • Members
  • 4
  • 112 posts
Posted August 16, 2015

Finally, got it working.

 

I'll submit an issue to the MBE Github repository with notes about the additional interface needed to render the block as an item.

 

Thanks for the help, TGG.

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    711

TheGreyGhost

TheGreyGhost    711

  • Reality Controller
  • TheGreyGhost
  • Members
  • 711
  • 2805 posts
Posted August 17, 2015

I'll submit an issue to the MBE Github repository with notes about the additional interface needed to render the block as an item.

Keen, thanks!

 

Thanks for the help, TGG.

No problem :)

 

-TGG

  • Quote

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
      Memory Heap Thingy!

      By diesieben07 · Posted 2 hours ago

      That's not what this thread is about... Make your own thread and post logs.
    • gudie73
      Memory Heap Thingy!

      By gudie73 · Posted 3 hours ago

      It gets stuck on that part and doesn’t change
    • gudie73
      Memory Heap Thingy!

      By gudie73 · Posted 3 hours ago

      Wym  
    • RaphGamingz
      ScreenGui does nothing

      By RaphGamingz · Posted 3 hours ago

      any errors?
    • RaphGamingz
      Game crashing when the block is activated

      By RaphGamingz · Posted 3 hours ago

      then you    your not assigning a value to the tileEntity try in the constructor tileEntity = world.getTileEntity(pos);
  • Topics

    • Mizinov
      7
      Memory Heap Thingy!

      By Mizinov
      Started August 24

    • Jaffaaaaa
      2
      ScreenGui does nothing

      By Jaffaaaaa
      Started Wednesday at 07:03 PM

    • jun2040
      5
      Game crashing when the block is activated

      By jun2040
      Started 20 hours ago

    • Merthew
      5
      [1.12.2] Multiple Structure Generation

      By Merthew
      Started November 7, 2018

    • Professional Derp
      16
      Server frequently crashes

      By Professional Derp
      Started 13 hours ago

  • Who's Online (See full list)

    • DragonITA
    • MarkNutt0
    • crackedEgg
    • Ugdhar
    • Neverless013
    • Yanny7
    • saxon564
    • Tomasukun
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.8] [Solved] Block with ISmartModel not rendering as Item (TGG?)
  • Theme
  • Contact Us
  • Discord

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