net.minecraft.client.renderer.ItemMeshDefinition Java Examples

The following examples show how to use net.minecraft.client.renderer.ItemMeshDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenderHandler.java    From EmergingTechnology with MIT License 6 votes vote down vote up
public static void registerMeshesAndStatesForBlock(Block block) {

        ModelResourceLocation resourceLocation = new ModelResourceLocation(
                block.getRegistryName(), "fluid");

        ItemMeshDefinition meshDefinition = new ItemMeshDefinition() {
            @Override
            public ModelResourceLocation getModelLocation(ItemStack stack) {
                return resourceLocation;
            }
        };

        StateMapperBase stateMapper = new StateMapperBase() {
            @Override
            public ModelResourceLocation getModelResourceLocation(IBlockState state) {
                return resourceLocation;
            }
        };

        ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(block), meshDefinition);
        ModelLoader.setCustomStateMapper(block, stateMapper);

    }
 
Example #2
Source File: Fluids.java    From BaseMetals with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SideOnly(Side.CLIENT)
public static void bakeModels(String modID){
	for(Fluid fluid : fluidBlocks.keySet()){
		BlockFluidBase block = fluidBlocks.get(fluid);
		Item item = Item.getItemFromBlock(block);
		final ModelResourceLocation fluidModelLocation = new ModelResourceLocation(
				modID.toLowerCase() + ":" + fluidBlockNames.get(block), "fluid");
           ModelBakery.registerItemVariants(item);
		ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
		{
			public ModelResourceLocation getModelLocation(ItemStack stack)
			{
				return fluidModelLocation;
			}
		});
		ModelLoader.setCustomStateMapper(block, new StateMapperBase()
		{
			protected ModelResourceLocation getModelResourceLocation(IBlockState state)
			{
				return fluidModelLocation;
			}
		});
	}
}
 
Example #3
Source File: OreRegistry.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public static void initModels() {
	final ItemMeshDefinition ORES = new ItemMeshDefinition() {
		@Override
		public ModelResourceLocation getModelLocation(ItemStack stack) {
			switch (stack.getItemDamage()) {
			case 0:
				return new ModelResourceLocation("exnihiloadscensio:itemOre", "type=piece");
			case 1:
				return new ModelResourceLocation("exnihiloadscensio:itemOre", "type=hunk");
			case 2:
				return new ModelResourceLocation("exnihiloadscensio:itemOre", "type=dust");
			case 3:
				return new ModelResourceLocation("exnihiloadscensio:itemOre", "type=ingot");
			default:
				return new ModelResourceLocation(stack.getItem().getRegistryName(), "inventory");
			}
		}
	};
	for (ItemOre ore : itemOreRegistry) {
		ModelLoader.setCustomMeshDefinition(ore, ORES);
		ModelBakery.registerItemVariants(ore, new ModelResourceLocation("exnihiloadscensio:itemOre", "type=piece"),
				new ModelResourceLocation("exnihiloadscensio:itemOre", "type=hunk"),
				new ModelResourceLocation("exnihiloadscensio:itemOre", "type=dust"),
				new ModelResourceLocation("exnihiloadscensio:itemOre", "type=ingot"));
		Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(ore, ORES);
	}
}
 
Example #4
Source File: ModelNullifierBaked.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
private IModel getItemModel(ItemStack stack)
{
    // Unfortunately this can't be done before the init phase...
    this.reflectMaps();

    Item item = stack.getItem();
    ModelResourceLocation mrl = null;
    Int2ObjectMap<ModelResourceLocation> map = LOCATIONS.get(item.delegate);

    if (map != null)
    {
        mrl = map.get(stack.getMetadata());
    }

    if (mrl == null)
    {
        ItemMeshDefinition mesh = SHAPERS.get(item);

        if (mesh != null)
        {
            mrl = mesh.getModelLocation(stack);
        }
    }

    if (mrl != null)
    {
        try
        {
            return ModelLoaderRegistry.getModel(mrl);
        }
        catch (Exception e)
        {
            return STATE_MODELS.get(mrl);
        }
    }

    return null;
}
 
Example #5
Source File: ModelRegistryHelper.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void registerItemRenderer(Item item, IItemRenderer renderer, ResourceLocation location) {
    final ModelResourceLocation modelLoc = new ModelResourceLocation(location, "inventory");
    register(modelLoc, renderer);
    registerItemMesher(item, new ItemMeshDefinition() {
        @Override
        public ModelResourceLocation getModelLocation(ItemStack stack) {
            return modelLoc;
        }
    });
}
 
Example #6
Source File: ModelRegistryHelper.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void registerItemMesher(Item item, ItemMeshDefinition mesher) {
    Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, mesher);
}