Java Code Examples for net.minecraftforge.client.model.ModelLoaderRegistry#getModel()

The following examples show how to use net.minecraftforge.client.model.ModelLoaderRegistry#getModel() . 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: EventsClient.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@SubscribeEvent
public void onModelBake(ModelBakeEvent event) {
    GibsModelRegistry.onModelBakeEvent(event);

    ResourceLocation modelResourceLocation = new ResourceLocation(ValkyrienSkiesMod.MOD_ID,
        "item/infuser_core_main");
    try {
        IModel model = ModelLoaderRegistry.getModel(modelResourceLocation);
        IBakedModel inventoryModel = model
            .bake(model.getDefaultState(), DefaultVertexFormats.ITEM,
                ModelLoader.defaultTextureGetter());
        IBakedModel handModel = event.getModelRegistry()
            .getObject(new ModelResourceLocation(
                ValkyrienSkiesMod.MOD_ID + ":" + ValkyrienSkiesMod.INSTANCE.physicsCore
                    .getTranslationKey()
                    .substring(5), "inventory"));

        event.getModelRegistry()
            .putObject(
                new ModelResourceLocation(ValkyrienSkiesMod.MOD_ID + ":testmodel", "inventory"),
                new InfuserCoreBakedModel(handModel, inventoryModel));
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 2
Source File: GibsModelRegistry.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
public static void registerTextures(TextureStitchEvent event) {
    System.out.println(
        "Valkyrien Skies got a register textures pre event! " + NAMES_TO_RESOURCE_LOCATION
            .size());

    for (ResourceLocation location : NAMES_TO_RESOURCE_LOCATION.values()) {
        try {
            // Get the model so that registry will remember to register its textures.
            IModel model = ModelLoaderRegistry.getModel(location);
            Collection<ResourceLocation> resourceLocations = model.getTextures();
            for (ResourceLocation texture : resourceLocations) {
                // Register the found texture into the texture map.
                event.getMap()
                    .registerSprite(texture);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 3
Source File: ModelLoader.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public IModel loadModel(ResourceLocation resourceLocation) {
	String resourcePath = resourceLocation.getResourcePath();
	/*if (!resourcePath.startsWith(SMART_MODEL_RESOURCE_LOCATION)) {
		assert false : "loadModel expected " + SMART_MODEL_RESOURCE_LOCATION + " but found " + resourcePath;
	}*/
	String modelName = resourcePath;//.substring(SMART_MODEL_RESOURCE_LOCATION.length());

	if (modelName.contains("rocketmotor")) {
		return new ModelRocket();
	} else {
		try {
			return ModelLoaderRegistry.getModel(new ResourceLocation(modelName));
		} catch (Exception e) {
			return ModelLoaderRegistry.getMissingModel();
		}// ModelLoaderRegistry.getMissingModel();
	}
}
 
Example 4
Source File: BakedModelInserter.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
{
    IModel baseModel = null;
    IModel sideModel = null;

    try
    {
        baseModel = ModelLoaderRegistry.getModel(BASE_MODEL);
        sideModel = ModelLoaderRegistry.getModel(SIDE_MODEL);
    }
    catch (Exception e)
    {
        EnderUtilities.logger.warn("Failed to load a model for the Inserter!");
    }

    return new BakedModelInserter(this, baseModel, sideModel, state, format, bakedTextureGetter);
}
 
Example 5
Source File: ModelCamouflageBlock.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public IModel retexture(ImmutableMap<String, String> textures)
{
    IModel baseModel    = ModelLoaderRegistry.getMissingModel();
    IModel overlayModel = null;

    try
    {
        baseModel = ModelLoaderRegistry.getModel(this.baseModelLocation);
        baseModel = baseModel.retexture(textures);

        if (this.overlayModelLocation != null)
        {
            overlayModel = ModelLoaderRegistry.getModel(this.overlayModelLocation);
            overlayModel = overlayModel.retexture(textures);
        }
    }
    catch (Exception e)
    {
        EnderUtilities.logger.warn("Failed to load a model for a camouflage block", e);
    }

    return new ModelCamouflageBlockBase(this.baseModelLocation, this.overlayModelLocation, baseModel, overlayModel, textures);
}
 
Example 6
Source File: BakedModelBarrel.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public IModel retexture(ImmutableMap<String, String> textures)
{
    IModel baseModel = ModelLoaderRegistry.getMissingModel();
    IModel overlayModel = ModelLoaderRegistry.getMissingModel();
    
    try
    {
        baseModel = ModelLoaderRegistry.getModel(BARREL_BASE_MODEL);
        baseModel = baseModel.retexture(this.textures);

        overlayModel = ModelLoaderRegistry.getModel(BARREL_OVERLAY_MODEL);
        overlayModel = overlayModel.retexture(this.textures);
    }
    catch (Exception e)
    {
        EnderUtilities.logger.warn("Failed to load the base model for a Barrel", e);
    }

    return new ModelBarrel(baseModel, overlayModel, textures);
}
 
Example 7
Source File: ModelNullifierBaked.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
{
    IModel baseModel = null;
    IModel lockedModel = null;

    try
    {
        baseModel   = ModelLoaderRegistry.getModel(BASE_MODEL);
        lockedModel = ModelLoaderRegistry.getModel(LOCKED_MODEL);
        lockedModel = lockedModel.retexture(ImmutableMap.of("layer0", TEX_LOCKED));
    }
    catch (Exception e)
    {
        EnderUtilities.logger.warn("Failed to load a model for the Nullifier!");
    }

    return new ModelNullifierBaked(baseModel, lockedModel, state, format, bakedTextureGetter);
}
 
Example 8
Source File: ModelRocket.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public IBakedModel bake(IModelState state, VertexFormat format,
		Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
	
	IModel subComponent;
	try {
		subComponent = ModelLoaderRegistry.getModel(resource);
		IBakedModel bakedModelCore = subComponent.bake(state, format, bakedTextureGetter);
		return bakedModelCore;
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example 9
Source File: ModelBakeHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static void replaceAnvilModel(ModelResourceLocation modelVariantLocation, ResourceLocation modelLocation, ModelBakeEvent event) {
	try {
		IModel model = ModelLoaderRegistry.getModel(modelLocation);
		IBakedModel standard = event.getModelRegistry().getObject(modelVariantLocation);
		if(standard instanceof IPerspectiveAwareModel) {
			IBakedModel finalModel = new BakedAnvilModel((IPerspectiveAwareModel) standard, DefaultVertexFormats.BLOCK);

			event.getModelRegistry().putObject(modelVariantLocation, finalModel);
		}

	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
Example 10
Source File: ModelBakeHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static void replacePitKilnModel(ModelResourceLocation modelVariantLocation, ResourceLocation modelLocation, ModelBakeEvent event) {
	try {
		IModel model = ModelLoaderRegistry.getModel(modelLocation);
		IBakedModel standard = event.getModelRegistry().getObject(modelVariantLocation);
		if(standard instanceof IPerspectiveAwareModel) {
			IBakedModel finalModel = new BakedPitKilnModel((IPerspectiveAwareModel) standard, DefaultVertexFormats.BLOCK);

			event.getModelRegistry().putObject(modelVariantLocation, finalModel);
		}

	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
Example 11
Source File: ModelBakeHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
public static void replaceSmallVesselModel(ModelResourceLocation modelVariantLocation, ResourceLocation modelLocation, ModelBakeEvent event) {
	try {
		IModel model = ModelLoaderRegistry.getModel(modelLocation);
		IBakedModel standard = event.getModelRegistry().getObject(modelVariantLocation);
		if(standard instanceof IPerspectiveAwareModel) {
			IBakedModel finalModel = new BakedSmallVesselModel((IPerspectiveAwareModel) standard, DefaultVertexFormats.BLOCK);

			event.getModelRegistry().putObject(modelVariantLocation, finalModel);
		}

	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
Example 12
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 13
Source File: ProxyClient.java    From WearableBackpacks with MIT License 5 votes vote down vote up
private static IModel getModel(ResourceLocation location) {
	try {
		IModel model = ModelLoaderRegistry.getModel(location);
		if (model == null) WearableBackpacks.LOG.error(
			"Model " + location + " is missing! THIS WILL CAUSE A CRASH!");
		return model;
	} catch (Exception e) { e.printStackTrace(); return null; }
}
 
Example 14
Source File: ModelPortableBarrel.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
	try {
		parentModel = ModelLoaderRegistry.getModel(PARENT_RL);
	} catch (Exception e) {
		e.printStackTrace();
		parentModel = ModelLoaderRegistry.getMissingModel();
	}
	parent = parentModel.bake(state, format, bakedTextureGetter);
	return this;
}