Java Code Examples for net.minecraftforge.client.model.ModelLoader#setCustomMeshDefinition()

The following examples show how to use net.minecraftforge.client.model.ModelLoader#setCustomMeshDefinition() . 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: MetaBlocks.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
public static void registerItemModels() {
    ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(MACHINE), stack -> MetaTileEntityRenderer.MODEL_LOCATION);
    ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(CABLE), stack -> CableRenderer.MODEL_LOCATION);
    ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(FLUID_PIPE), stack -> FluidPipeRenderer.MODEL_LOCATION);
    registerItemModel(BOILER_CASING);
    registerItemModel(BOILER_FIREBOX_CASING);
    registerItemModel(METAL_CASING);
    registerItemModel(TURBINE_CASING);
    registerItemModel(MACHINE_CASING);
    registerItemModel(MUTLIBLOCK_CASING);
    registerItemModel(WIRE_COIL);
    registerItemModel(WARNING_SIGN);
    registerItemModel(GRANITE);
    registerItemModel(MINERAL);
    registerItemModel(CONCRETE);
    registerItemModelWithOverride(LOG, ImmutableMap.of(BlockGregLog.LOG_AXIS, EnumAxis.Y));
    registerItemModel(LEAVES);
    registerItemModel(SAPLING);

    COMPRESSED.values().stream().distinct().forEach(MetaBlocks::registerItemModel);
    FRAMES.values().forEach(it -> registerItemModelWithFilteredProperties(it));
    ORES.stream().distinct().forEach(MetaBlocks::registerItemModel);
}
 
Example 3
Source File: ClientProxy.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void preInit(FMLPreInitializationEvent event) {
	super.preInit(event);

	if (ConfigValues.versionCheckerEnabled)
		VersionChecker.register();

	ModEntities.initModels();

	CustomBlockMapSprites.INSTANCE.register(new ResourceLocation(Wizardry.MODID, "blocks/mana_crystal_ring"));
	CustomBlockMapSprites.INSTANCE.register(new ResourceLocation(Wizardry.MODID, "blocks/mana_crystal_ring_outer"));
	CustomBlockMapSprites.INSTANCE.register(new ResourceLocation(Wizardry.MODID, "blocks/mana_crystal"));
	CustomBlockMapSprites.INSTANCE.register(new ResourceLocation(Wizardry.MODID, "blocks/outputPearl"));
	CustomBlockMapSprites.INSTANCE.register(new ResourceLocation(Wizardry.MODID, "blocks/mana_orb"));
	CustomBlockMapSprites.INSTANCE.register(new ResourceLocation(Wizardry.MODID, "blocks/mana_pearl_cube"));
	CustomBlockMapSprites.INSTANCE.register(new ResourceLocation(Wizardry.MODID, "blocks/nacre_pearl_cube"));

	// Load and bake the 2D models
	ModelBakery.registerItemVariants(ModItems.BOOK, new ModelResourceLocation("wizardry:book", "inventory"));
	ModelResourceLocation default3dPath = new ModelResourceLocation("wizardry:book", "inventory");
	ModelLoader.setCustomMeshDefinition(ModItems.BOOK, stack -> default3dPath);

	ModKeybinds.register();
}
 
Example 4
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 5
Source File: BakedModelHandler.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void addBuiltInBlock(Block block, String particleTexture) {
    this.builtInBlocks.add(new Tuple<>(block, particleTexture));
    ModelLoader.setCustomStateMapper(block, SIMPLE_STATE_MAPPER);
    Item itemFromBlock = Item.getItemFromBlock(block);
    if (itemFromBlock != Items.AIR) {
        ModelLoader.setCustomMeshDefinition(itemFromBlock, SIMPLE_MESH_DEFINITION);
    }
}
 
Example 6
Source File: FluidWitchWater.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public void initModel() {
	Block block = this.getBlock();
	
	FluidStateMapper mapper = new FluidStateMapper(this);
	
	Item item = Item.getItemFromBlock(block);
	if (item != null) {
		ModelLoader.registerItemVariants(item);
		ModelLoader.setCustomMeshDefinition(item, mapper);
	}
	
	ModelLoader.setCustomStateMapper(block, mapper);		
}
 
Example 7
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 8
Source File: ClientProxy.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void registerItem(FWItem item) {
	super.registerItem(item);

	//Hacks to inject custom item definition
	ModelLoader.setCustomMeshDefinition(item, stack -> new ModelResourceLocation(Item.REGISTRY.getNameForObject(item), "inventory"));
}
 
Example 9
Source File: ClientProxy.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void postRegisterBlock(FWBlock block) {
	super.postRegisterBlock(block);

	//Hack to inject custom itemblock definition
	Item itemFromBlock = Item.getItemFromBlock(block);

	ModelLoader.setCustomMeshDefinition(itemFromBlock, stack -> new ModelResourceLocation(Item.REGISTRY.getNameForObject(itemFromBlock), "inventory"));
}
 
Example 10
Source File: ClientProxy.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void registerItem(FWItem item) {
	super.registerItem(item);

	//Hacks to inject custom item definition
	ModelLoader.setCustomMeshDefinition(item, stack -> {
		ResourceLocation itemRL = (ResourceLocation) Item.itemRegistry.getNameForObject(item);
		return new ModelResourceLocation(itemRL, "inventory");
	});
}
 
Example 11
Source File: ClientProxy.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void postRegisterBlock(FWBlock block) {
	super.postRegisterBlock(block);

	//Hack to inject custom itemblock definition
	Item itemFromBlock = Item.getItemFromBlock(block);

	ModelLoader.setCustomMeshDefinition(itemFromBlock, stack -> {
		ResourceLocation itemRL = (ResourceLocation) Item.itemRegistry.getNameForObject(itemFromBlock);
		return new ModelResourceLocation(itemRL, "inventory");
	});
}
 
Example 12
Source File: RegistryItemQueue.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public void registerMeshes()
{
	Entry e; 
	while (!listMesh.isEmpty())
	{
		e = listMesh.pop();
		ModelLoader.setCustomMeshDefinition(e.item, new MeshDef(new ModelResourceLocation(Reference.ModID + ":"+e.item.getRegistryName(), "inventory")));
	}

}
 
Example 13
Source File: ClientProxy.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void registerItemModelWithVariantsAndMeshDefinition(ItemEnderUtilities item)
{
    if (item.isEnabled())
    {
        ModelLoader.registerItemVariants(item, item.getItemVariants());
        ModelLoader.setCustomMeshDefinition(item, ItemMeshDefinitionWrapper.instance());
    }
}
 
Example 14
Source File: ClientProxy.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
private void registerItemMesh(Item i, ModelResourceLocation mrl)
{
	ModelLoader.setCustomMeshDefinition(i, new MeshDef(mrl));
}
 
Example 15
Source File: ClientProxy.java    From AdvancedRocketry with MIT License 3 votes vote down vote up
private void registerFluidModel(IFluidBlock fluidBlock) {
	Item item = Item.getItemFromBlock((Block) fluidBlock);

	ModelBakery.registerItemVariants(item);

	final ModelResourceLocation modelResourceLocation = new ModelResourceLocation("advancedrocketry:fluid", fluidBlock.getFluid().getName());
	
	//ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> modelResourceLocation));

	
	StateMapperBase ignoreState = new FluidStateMapper(modelResourceLocation);
	ModelLoader.setCustomStateMapper((Block) fluidBlock, ignoreState);
	ModelLoader.setCustomMeshDefinition(item, new FluidItemMeshDefinition(modelResourceLocation));
	ModelBakery.registerItemVariants(item, modelResourceLocation);
}
 
Example 16
Source File: ModelUtils.java    From OpenModsLib with MIT License 3 votes vote down vote up
public static void registerMetaInsensitiveModel(Item item, String variant) {
	final ModelResourceLocation location = new ModelResourceLocation(item.getRegistryName(), variant);

	ModelBakery.registerItemVariants(item, location);

	ModelLoader.setCustomMeshDefinition(item, stack -> location);
}