Search in sources :

Example 1 with ItemWorktableToolBase

use of com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase in project artisan-worktables by codetaylor.

the class ModuleTools method onRegister.

@Override
public void onRegister(Registry registry) {
    super.onRegister(registry);
    List<String> allowedToolTypeList = new ArrayList<>(Arrays.asList(ModuleToolsConfig.ENABLED_TOOL_TYPES));
    if (allowedToolTypeList.isEmpty()) {
        // User has disabled all tool types.
        return;
    }
    if (this.materialList.isEmpty()) {
        // User has disabled all tool materials.
        return;
    }
    for (EnumWorktableToolType type : EnumWorktableToolType.values()) {
        String typeName = type.getName();
        if (!allowedToolTypeList.contains(typeName)) {
            // User has disabled this tool type.
            continue;
        }
        for (CustomMaterial material : this.materialList) {
            String materialName = material.getDataCustomMaterial().getName();
            ItemWorktableToolBase item = new ItemWorktableTool(type, material);
            this.registerTool(registry, typeName, materialName, item);
        }
        ArtisanCustomToolMaterialRegistrationEvent event = new ArtisanCustomToolMaterialRegistrationEvent();
        MinecraftForge.EVENT_BUS.post(event);
        List<CustomToolMaterialRegistrationEntry> materialList = event.getMaterialList();
        CustomMaterialConverter customMaterialConverter = new CustomMaterialConverter(RecipeItemParser.INSTANCE);
        for (CustomToolMaterialRegistrationEntry entry : materialList) {
            try {
                ICustomToolMaterial material = entry.getMaterial();
                ICustomToolProvider provider = entry.getProvider();
                CustomMaterial customMaterial = customMaterialConverter.convert(material);
                ItemWorktableToolBase item = provider.get(type, customMaterial);
                String materialName = customMaterial.getDataCustomMaterial().getName();
                this.registerTool(registry, typeName, materialName, item);
            } catch (MalformedRecipeItemException e) {
                ModuleTools.LOGGER.error("", e);
            }
        }
    }
    registry.registerItemRegistrationStrategy(forgeRegistry -> {
        if (ModuleToolsConfig.ENABLE_TOOL_TYPE_ORE_DICT_GROUPS) {
            for (ItemWorktableToolBase item : this.registeredToolList) {
                ItemStack itemStack = new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE);
                OreDictionary.registerOre(ModuleToolsConfig.TOOL_BY_TYPE_ORE_DICT_PREFIX + item.getType().getOreDictSuffix(), itemStack);
            }
        }
        if (ModuleToolsConfig.ENABLE_TOOL_MATERIAL_ORE_DICT_GROUPS) {
            for (ItemWorktableToolBase item : this.registeredToolList) {
                ItemStack itemStack = new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE);
                OreDictionary.registerOre(item.getMaterial().getDataCustomMaterial().getOreDictKey(), itemStack);
            }
        }
    });
}
Also used : ItemWorktableToolBase(com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase) ArrayList(java.util.ArrayList) ArtisanCustomToolMaterialRegistrationEvent(com.codetaylor.mc.artisanworktables.api.event.ArtisanCustomToolMaterialRegistrationEvent) CustomToolMaterialRegistrationEntry(com.codetaylor.mc.artisanworktables.api.tool.CustomToolMaterialRegistrationEntry) ICustomToolProvider(com.codetaylor.mc.artisanworktables.api.tool.ICustomToolProvider) MalformedRecipeItemException(com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException) ItemWorktableTool(com.codetaylor.mc.artisanworktables.modules.tools.item.ItemWorktableTool) ICustomToolMaterial(com.codetaylor.mc.artisanworktables.api.tool.ICustomToolMaterial) ItemStack(net.minecraft.item.ItemStack) EnumWorktableToolType(com.codetaylor.mc.artisanworktables.api.tool.reference.EnumWorktableToolType) CustomMaterial(com.codetaylor.mc.artisanworktables.api.internal.tool.CustomMaterial)

Example 2 with ItemWorktableToolBase

use of com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase in project artisan-worktables by codetaylor.

the class ModuleTools method onClientRegister.

@Override
public void onClientRegister(Registry registry) {
    super.onClientRegister(registry);
    registry.registerClientModelRegistrationStrategy(() -> {
        for (ItemWorktableToolBase item : ModuleTools.this.registeredToolList) {
            String resourcePath = item.getMaterial().getDataCustomMaterial().isShiny() ? item.getName() + "_highlighted" : item.getName();
            ResourceLocation location = new ResourceLocation(MOD_ID, resourcePath);
            ModelResourceLocation modelResourceLocation = new ModelResourceLocation(location, "inventory");
            ModelLoader.setCustomModelResourceLocation(item, 0, modelResourceLocation);
        }
    });
}
Also used : ItemWorktableToolBase(com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 3 with ItemWorktableToolBase

use of com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase in project artisan-worktables by codetaylor.

the class ModuleTools method onClientInitializationEvent.

@Override
public void onClientInitializationEvent(FMLInitializationEvent event) {
    super.onClientInitializationEvent(event);
    if (this.registeredToolList.isEmpty()) {
        // No tools were registered.
        return;
    }
    // Register item color handlers to colorize layer 1 of each item model
    // using the color stored in the material enum.
    ItemColors itemColors = Minecraft.getMinecraft().getItemColors();
    itemColors.registerItemColorHandler((stack, tintIndex) -> (tintIndex == 1) ? ((ItemWorktableToolBase) stack.getItem()).getMaterial().getColor() : 0xFFFFFF, this.registeredToolList.toArray(new ItemWorktableToolBase[this.registeredToolList.size()]));
}
Also used : ItemWorktableToolBase(com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase) ItemColors(net.minecraft.client.renderer.color.ItemColors)

Example 4 with ItemWorktableToolBase

use of com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase in project artisan-worktables by codetaylor.

the class ModuleToolsRecipes method register.

/**
 * Iterates through all given items in the tool list and registers a recipe for each.
 *
 * @param registry the recipe registry
 * @param modId    the mod id
 * @param toolList the tool list
 */
public static void register(IForgeRegistry<IRecipe> registry, String modId, List<ItemWorktableToolBase> toolList) {
    RecipeItemParser recipeItemParser = new RecipeItemParser();
    for (ItemWorktableToolBase item : toolList) {
        try {
            // Convert ingredient
            String ingredientString = item.getMaterial().getIngredientString();
            ParseResult parseResult = recipeItemParser.parse(ingredientString);
            if (parseResult == ParseResult.NULL) {
                throw new MalformedRecipeItemException("Unable to parse ingredient [" + item.getMaterial().getIngredientString() + "] for material [" + item.getMaterial() + "]");
            }
            Object ingredient;
            if ("ore".equals(parseResult.getDomain())) {
                ingredient = parseResult.getPath();
            } else {
                Item parsedItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(parseResult.getDomain(), parseResult.getPath()));
                if (parsedItem == null) {
                    throw new MalformedRecipeItemException("Unable to find registered item: " + parseResult.toString());
                }
                if (parseResult.getMeta() == OreDictionary.WILDCARD_VALUE) {
                    throw new MalformedRecipeItemException("Wildcard value not accepted for tool material ingredients: " + parseResult.toString());
                }
                ingredient = new ItemStack(parsedItem, 1, parseResult.getMeta());
            }
            Object[] recipeDefinition = ModuleToolsRecipes.getRecipeDefinition(item.getType(), ingredient);
            if (recipeDefinition == null) {
                throw new RuntimeException("Missing recipe definition for tool type: " + item.getType().getName());
            }
            ShapedOreRecipe recipe = new ShapedOreRecipe(null, item, recipeDefinition);
            recipe.setRegistryName(new ResourceLocation(modId, "recipe." + item.getName() + "." + item.getMaterial().getDataCustomMaterial().getName()));
            registry.register(recipe);
        } catch (Exception e) {
            throw new RuntimeException("Error registering recipe", e);
        }
    }
}
Also used : ItemWorktableToolBase(com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase) RecipeItemParser(com.codetaylor.mc.athenaeum.parser.recipe.item.RecipeItemParser) ParseResult(com.codetaylor.mc.athenaeum.parser.recipe.item.ParseResult) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) MalformedRecipeItemException(com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException) Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) MalformedRecipeItemException(com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemWorktableToolBase (com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase)4 MalformedRecipeItemException (com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ArtisanCustomToolMaterialRegistrationEvent (com.codetaylor.mc.artisanworktables.api.event.ArtisanCustomToolMaterialRegistrationEvent)1 CustomMaterial (com.codetaylor.mc.artisanworktables.api.internal.tool.CustomMaterial)1 CustomToolMaterialRegistrationEntry (com.codetaylor.mc.artisanworktables.api.tool.CustomToolMaterialRegistrationEntry)1 ICustomToolMaterial (com.codetaylor.mc.artisanworktables.api.tool.ICustomToolMaterial)1 ICustomToolProvider (com.codetaylor.mc.artisanworktables.api.tool.ICustomToolProvider)1 EnumWorktableToolType (com.codetaylor.mc.artisanworktables.api.tool.reference.EnumWorktableToolType)1 ItemWorktableTool (com.codetaylor.mc.artisanworktables.modules.tools.item.ItemWorktableTool)1 ParseResult (com.codetaylor.mc.athenaeum.parser.recipe.item.ParseResult)1 RecipeItemParser (com.codetaylor.mc.athenaeum.parser.recipe.item.RecipeItemParser)1 ArrayList (java.util.ArrayList)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 ItemColors (net.minecraft.client.renderer.color.ItemColors)1 Item (net.minecraft.item.Item)1 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)1