Jump to content

[1.8] How do we use ISmartItemModel to create dynamic models?


Recommended Posts

Posted

What I want to do is render my item as a series of mini-blocks stored in the item's NBT data.

 

I'm used to doing this via IItemRenderer, and seeing as how that's deprecated, I've been guided into using ISmartItemModel. Problem is, I don't know where to start.

 

Has anyone delved into this?

 

How would I go about doing this?

 

I'm trying to use SimpleBakedModel's builder, and don't really know where to go from there.

 

I have no code to show, because I don't know what I'm doing to begin with. Just being honest here.

 

All I've done is create empty fields to see what methods are what, and what parameters they can take, so that I could have a general idea of a starting ground, but would rather not waste my time banging out code that's wrong or won't compile or run.

 

Help me, without spoon-feeding complete code? I'd like to learn the new way of dynamic model generation.

Posted

Hi

 

The key bit to understand is that ISmartItemModel lets you choose which IBakedModel to return, based on the itemstack given to its method

 

    IBakedModel handleItemState(ItemStack stack);

 

So- you can create as many SimpleBakedModels as you like - and pick which one to return.  I'd suggest you create a variant for each one just like you would normally register them and just return the variant by name.

 

This example 12 does something very similar using the Item.getModel() method instead of handleItemState().

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

 

Alternatively, if you implement IBakedModel with your own class, you can change which faces are returned by getFaceQuads() and getGeneralQuads() depending on what your handleItemState has told it to.

 

For example (won't compile but you get the idea?)

    IBakedModel handleItemState(ItemStack stack) {

if (stack.stackSize == 1) return new MyBakedModel(SINGLE_FACE);
if (stack.stackSize == 2) return new MyBakedModel(TWO_FACES);
return new MyBakedModel(MANY_FACES);

}
where
class MyBakedModel implements IBakedModel {

  private FaceCount facecount;
  public MyBakedModel(FaceCount i_facecount) {
     facecount = i_facecount;
  }

  public List getFaceQuads(EnumFacing p_177551_1_)
    {
        List allfaces = new List();
        allfaces.add(FIRST_BAKED_QUAD);
        if (facecount == SINGLE_FACE) return allFaces;
        allfaces.add(SECOND_BAKED_QUAD);
        if (facecount == TWO_FACES) return allFaces;
        allfaces.add(THIRD_BAKED_QUAD);
       return allFaces;
    }
}

 

In your specific case, you might implement an IBakedModel that contains a number of mini-blocks and the getFaceQuads method compiles a list from all the miniblocks listed one after the other.

 

-TGG

 

 

Posted

Alright, and is there a function that gets the block models of said blocks?

 

I'm thinking getItemModel() in the ItemMesher, but I don't know if that will work. If it's wrong, where do I start with that?

 

Also, when I return the TextureAtlasSprite, how will I compile all the textures of all the blocks into one? And if I do so, will all the block faces grab the right textures, or do I have to re-uv map them?

Posted

Vanilla uses

BlockRendererDispatcher.getModelFromBlockState()

you can get BlockRendererDispatcher from

Minecraft.getMinecraft.getBlockRendererDispatcher()

 

The TextureAtlasSprite is just used for the block breaking texture I think.

 

I think that if your block models are registered in the normal way, the uv mappings will all be correct because the textures are automatically stitched together into a single sheet and the BlockModel already got its own uv when it was baked.

I'm not sure of that - try it and let us know?

 

-TGG

Posted

What parameters would I be passing in for the IBlockState, IBlockAccess, and BlockPos? Cause it's not physical blocks in the world, it's just ItemStacks stored in NBT. Is it safe to pass null for the last two? This is why I thought getItemModel would work cause I will be using item stacks.

Posted

Hi

 

well, I _think_ nulls for world and blockPos are probably ok, because of this in getModelFromBlockState:

 

            try
            {
                p_175022_1_ = block.getActualState(p_175022_1_, p_175022_2_, p_175022_3_);
            }
            catch (Exception exception)
            {
                ;
            }

but I reckon it would be better to bypass it properly, using just 

IBakedModel ibakedmodel = blockModelShapes.getModelForState(blockState);

 

You can get blockModelShapes from BlockRendererDispatcher using the corresponding get method.

 

-TGG

 

Posted

See, the thing is, is I have no block states since the blocks aren't real. They are only ItemStacks.

 

Should I just fetch the default states from the blocks?

Ah. I think I've misunderstood what you want.  I reckon your thought about getItemModel() in the ItemMesher is right, i.e.:

 

If your ItemStack has an NBT with (say) two ItemStacks "A" and "B" in it, you would get the vanilla IBakedModels for those items using

 

IBakedModel ibakedmodel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(itemStackA);

and same for B.

 

The only trick is - if the Camera Transforms aren't the same for both items, you will have to choose one of the two...

 

-TGG

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.