Search in sources :

Example 1 with CustomMaterial

use of com.codetaylor.mc.artisanworktables.api.internal.tool.CustomMaterial 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 CustomMaterial

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

the class ItemWorktableToolBase method getItemStackDisplayName.

@Nonnull
@Override
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
    // This is called on the server so we can't use net/minecraft/client/resources/I18n here.
    Item item = stack.getItem();
    if (item instanceof ItemWorktableToolBase) {
        CustomMaterial material = ((ItemWorktableToolBase) item).getMaterial();
        String parameter = I18n.translateToLocalFormatted(material.getDataCustomMaterial().getLangKey());
        return I18n.translateToLocalFormatted(this.getUnlocalizedNameInefficiently(stack) + ".name", parameter);
    }
    return super.getItemStackDisplayName(stack);
}
Also used : Item(net.minecraft.item.Item) CustomMaterial(com.codetaylor.mc.artisanworktables.api.internal.tool.CustomMaterial) Nonnull(javax.annotation.Nonnull)

Example 3 with CustomMaterial

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

the class CustomMaterialListConverter method convert.

public List<CustomMaterial> convert(DataCustomMaterialList data, Logger logger) {
    List<CustomMaterial> result = new ArrayList<>();
    List<DataCustomMaterial> list = data.getList();
    for (ICustomToolMaterial dataCustomMaterial : list) {
        try {
            this.customMaterialValidator.validate(dataCustomMaterial);
        } catch (CustomMaterialValidationException e) {
            logger.error("", e);
            continue;
        }
        try {
            result.add(this.customMaterialConverter.convert(dataCustomMaterial));
        } catch (MalformedRecipeItemException e) {
            logger.error("", e);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) MalformedRecipeItemException(com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException) ICustomToolMaterial(com.codetaylor.mc.artisanworktables.api.tool.ICustomToolMaterial) CustomMaterial(com.codetaylor.mc.artisanworktables.api.internal.tool.CustomMaterial)

Aggregations

CustomMaterial (com.codetaylor.mc.artisanworktables.api.internal.tool.CustomMaterial)3 ICustomToolMaterial (com.codetaylor.mc.artisanworktables.api.tool.ICustomToolMaterial)2 MalformedRecipeItemException (com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException)2 ArrayList (java.util.ArrayList)2 ArtisanCustomToolMaterialRegistrationEvent (com.codetaylor.mc.artisanworktables.api.event.ArtisanCustomToolMaterialRegistrationEvent)1 CustomToolMaterialRegistrationEntry (com.codetaylor.mc.artisanworktables.api.tool.CustomToolMaterialRegistrationEntry)1 ICustomToolProvider (com.codetaylor.mc.artisanworktables.api.tool.ICustomToolProvider)1 ItemWorktableToolBase (com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase)1 EnumWorktableToolType (com.codetaylor.mc.artisanworktables.api.tool.reference.EnumWorktableToolType)1 ItemWorktableTool (com.codetaylor.mc.artisanworktables.modules.tools.item.ItemWorktableTool)1 Nonnull (javax.annotation.Nonnull)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1