Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have an item which is made from an unknown number of components, depending on the NBT data of the item. For this, I believe the easiest strategy would be to use a composite of multiple models, chosen with the code. Is there any way to do this?

  • Author

I believe I have solved it, sort of.

 

I solved it by using a custom IBakedModel class:

 

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;

public class ItemTestModel implements IBakedModel
{

@Override
public List<BakedQuad> getFaceQuads(EnumFacing p_177551_1_)
{
	List<BakedQuad> quads = new ArrayList<BakedQuad>();

	ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

	quads.addAll(0, mesher.getItemModel(new ItemStack(Items.apple)).getFaceQuads(p_177551_1_));		
	quads.addAll(0, mesher.getItemModel(new ItemStack(Items.diamond_horse_armor)).getFaceQuads(p_177551_1_));
	return quads;
}

@Override
public List<BakedQuad> getGeneralQuads()
{
	List<BakedQuad> quads = new ArrayList<BakedQuad>();

	ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

	quads.addAll(0, mesher.getItemModel(new ItemStack(Items.apple)).getGeneralQuads());		
	quads.addAll(0, mesher.getItemModel(new ItemStack(Items.diamond_horse_armor)).getGeneralQuads());
	return quads;
}

@Override
public boolean isAmbientOcclusion()
{
	return false;
}

@Override
public boolean isGui3d()
{
	return false;
}

@Override
public boolean isBuiltInRenderer()
{
	return false;
}

@Override
public TextureAtlasSprite getParticleTexture()
{
	ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

	return mesher.getItemModel(new ItemStack(Items.diamond_horse_armor)).getParticleTexture();
}

@Override
public ItemCameraTransforms getItemCameraTransforms()
{
	return ItemCameraTransforms.DEFAULT;
}

}

 

Edit: Ah, I just noticed that the item is held at a strange angle in third person, which I believe is to do with getItemCameraTransforms. If this is the case, what is the ItemCameraTransforms that I should be using, if not DEFAULT?

  • Author

I think I may be barking up the wrong tree, so to speak, with the method I am trying to use.

 

There must be a method for this - right?

  • Author

Okay, so maybe a more detailed explanation will help:

 

So I am making a mod which includes weapons and tools made from a number of different components, such as a sword blade or pickaxe head. Although all weapons/tools of a type share the same base components, tools may contain one or more optional components.

 

Now, rather than create tens or even hundreds of thousands of different models for each tool and weapon type, I want to create a model for each individual component, then use code based on the items NBT data to select which models to combine together to form the resulting model.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.