Search in sources :

Example 1 with ICustomItem

use of com.skelril.nitro.registry.item.ICustomItem in project Skree by Skelril.

the class CustomItemSystem method render.

// Invoked via reflection
@SuppressWarnings("unused")
private void render(Object item) {
    if (item instanceof Item && item instanceof ICustomItem) {
        if (Sponge.getPlatform().getExecutionType().isClient()) {
            RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
            ItemModelMesher mesher = renderItem.getItemModelMesher();
            Optional<ItemMeshDefinition> optMeshDefinition = ((ICustomItem) item).__getCustomMeshDefinition();
            if (optMeshDefinition.isPresent()) {
                mesher.register((Item) item, optMeshDefinition.get());
            }
            List<String> variants = ((ICustomItem) item).__getMeshDefinitions();
            List<ResourceLocation> modelResources = new ArrayList<>();
            for (int i = 0; i < variants.size(); ++i) {
                ModelResourceLocation resourceLocation = new ModelResourceLocation("skree:" + variants.get(i), "inventory");
                if (!optMeshDefinition.isPresent()) {
                    mesher.register((Item) item, i, resourceLocation);
                }
                modelResources.add(resourceLocation);
            }
            ModelBakery.registerItemVariants((Item) item, modelResources.toArray(new ResourceLocation[modelResources.size()]));
        }
    } else {
        throw new IllegalArgumentException("Invalid custom item!");
    }
}
Also used : ArrayList(java.util.ArrayList) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ICustomItem(com.skelril.nitro.registry.item.ICustomItem) RenderItem(net.minecraft.client.renderer.RenderItem) ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) Item(net.minecraft.item.Item) CookedItem(com.skelril.nitro.registry.item.CookedItem) ICustomItem(com.skelril.nitro.registry.item.ICustomItem) RenderItem(net.minecraft.client.renderer.RenderItem) ItemModelMesher(net.minecraft.client.renderer.ItemModelMesher) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

CookedItem (com.skelril.nitro.registry.item.CookedItem)1 ICustomItem (com.skelril.nitro.registry.item.ICustomItem)1 ArrayList (java.util.ArrayList)1 ItemMeshDefinition (net.minecraft.client.renderer.ItemMeshDefinition)1 ItemModelMesher (net.minecraft.client.renderer.ItemModelMesher)1 RenderItem (net.minecraft.client.renderer.RenderItem)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 Item (net.minecraft.item.Item)1 ResourceLocation (net.minecraft.util.ResourceLocation)1