Jump to content

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


SnowyEgret

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

 

 

Link to comment
Share on other sites

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]

 

 

Link to comment
Share on other sites

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);

    }

}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

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);
  }

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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

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

    • LOGIN DAN DAFTAR DISINI CEPAT!! AYUTOGEL adalah situs judi online yang memudahkan para pemainnya, dengan menggunakan deposit pulsa terbilang cukup memudahkan para pemainnya dikarenakan setiap orang pasti bisa mengisi pulsa di mana pun dengan agen agen pulsa, dengan mudah di dapat kan dimana mana jika para pemain tidak memiliki e-money atau m-banking anda tidak perlu khawatir lagi di karenakan AYUTOGEL adalah situs slot deposit pulsa. Slot Deposit pulsa adalah sebuah situs judi slot online yang melayani deposit menggunakan transfer pulsa atau menggunakan pulsa ponsel yang tersedia.
    • DAFTAR DAN LOGIN DISINI   Hantogel atau handogel adalah bentuk pengumpulan duka uang yang populer di dunia judi online, khususnya dalam permainan slot gacor. Banyak situs judi online yang menawarkan handogel slot gacor, dan sebagai pemain, penting untuk mengetahui cara memilih dan mengakses situs tersebut dengan aman dan amanah. Dalam artikel ini, kami akan membahas cara memilih situs slot gacor online yang berkualitas dan tahu cara mengakses handogelnya.
    • DAFTAR & LOGIN SIRITOGEL Siritogel adalah kumpulan kata yang mungkin baru saja dikenal oleh masyarakat, namun dengan perkembangan teknologi dan banyaknya informasi yang tersedia di internet, kalau kita siritogel (mencari informasi dengan cara yang cermat dan rinci) tentang situs slot gacor online, maka kita akan menemukan banyak hal yang menarik dan membahayakan sama sekali. Dalam artikel ini, kita akan mencoba menjelaskan apa itu situs slot gacor online dan bagaimana cara mengatasi dampaknya yang negatif.
    • This honestly might just work for you @SubscribeEvent public static void onScreenRender(ScreenEvent.Render.Post event) { final var player = Minecraft.getInstance().player; final var options = Minecraft.getInstance().options; if(!hasMyEffect(player)) return; // TODO: You provide hasMyEffect float f = Mth.lerp(event.getPartialTick(), player.oSpinningEffectIntensity, player.spinningEffectIntensity); float f1 = ((Double)options.screenEffectScale().get()).floatValue(); if(f <= 0F || f1 >= 1F) return; float p_282656_ = f * (1.0F - f1); final var p_282460_ = event.getGuiGraphics(); int i = p_282460_.guiWidth(); int j = p_282460_.guiHeight(); p_282460_.pose().pushPose(); float f5 = Mth.lerp(p_282656_, 2.0F, 1.0F); p_282460_.pose().translate((float)i / 2.0F, (float)j / 2.0F, 0.0F); p_282460_.pose().scale(f5, f5, f5); p_282460_.pose().translate((float)(-i) / 2.0F, (float)(-j) / 2.0F, 0.0F); float f4 = 0.2F * p_282656_; float f2 = 0.4F * p_282656_; float f3 = 0.2F * p_282656_; RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE); p_282460_.setColor(f4, f2, f3, 1.0F); p_282460_.blit(new ResourceLocation("textures/misc/nausea.png"), 0, 0, -90, 0.0F, 0.0F, i, j, i, j); p_282460_.setColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); p_282460_.pose().popPose(); }   Note: Most of this is directly copied from GameRenderer as you pointed out you found. The only thing you'll have to likely do is update the `oSpinningEffectIntensity` + `spinningEffectIntensity` variables on the player when your effect is applied. Which values should be there? Not 100% sure, might be a game of guess and check, but `handleNetherPortalClient` in LocalPlayer has some hard coded you might be able to start with.
    • Dalam dunia perjudian online yang berkembang pesat, mencari platform yang dapat memberikan kemenangan maksimal dan hasil terbaik adalah impian setiap penjudi. OLXTOTO, dengan bangga, mempersembahkan dirinya sebagai jawaban atas pencarian itu. Sebagai platform terbesar untuk kemenangan maksimal dan hasil optimal, OLXTOTO telah menciptakan gelombang besar di komunitas perjudian online. Satu dari banyak keunggulan yang dimiliki OLXTOTO adalah koleksi permainan yang luas dan beragam. Dari togel hingga slot online, dari live casino hingga permainan kartu klasik, OLXTOTO memiliki sesuatu untuk setiap pemain. Dibangun dengan teknologi terkini dan dikembangkan oleh para ahli industri, setiap permainan di platform ini dirancang untuk memberikan pengalaman yang tak tertandingi bagi para penjudi. Namun, keunggulan OLXTOTO tidak hanya terletak pada variasi permainan yang mereka tawarkan. Mereka juga menonjol karena komitmen mereka terhadap keamanan dan keadilan. Dengan sistem keamanan tingkat tinggi dan proses audit yang ketat, OLXTOTO memastikan bahwa setiap putaran permainan berjalan dengan adil dan transparan. Para pemain dapat merasa aman dan yakin bahwa pengalaman berjudi mereka di OLXTOTO tidak akan terganggu oleh masalah keamanan atau keadilan. Tak hanya itu, OLXTOTO juga terkenal karena layanan pelanggan yang luar biasa. Tim dukungan mereka selalu siap sedia untuk membantu para pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Dengan respon cepat dan solusi yang efisien, OLXTOTO memastikan bahwa pengalaman berjudi para pemain tetap mulus dan menyenangkan. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi pilihan utama bagi jutaan penjudi online di seluruh dunia. Jika Anda mencari platform yang dapat memberikan kemenangan maksimal dan hasil optimal, tidak perlu mencari lebih jauh dari OLXTOTO. Bergabunglah dengan OLXTOTO hari ini dan mulailah petualangan Anda menuju kemenangan besar dan hasil terbaik!
  • Topics

×
×
  • Create New...

Important Information

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