Class InfoBookParser

java.lang.Object
org.cyclops.cyclopscore.infobook.InfoBookParser

public class InfoBookParser extends Object
XML parser which will generate the infobook.
  • Field Details

  • Constructor Details

    • InfoBookParser

      public InfoBookParser()
  • Method Details

    • getNodeResourceLocation

      protected static net.minecraft.resources.ResourceLocation getNodeResourceLocation(Element node)
    • registerSectionFactory

      public static void registerSectionFactory(String name, InfoBookParser.IInfoSectionFactory factory)
      Register a new info section factory.
      Parameters:
      name - The unique name for this factory, make sure to namespace this to your mod to avoid collisions.
      factory - The factory
    • registerIgnoredFactory

      public static void registerIgnoredFactory(String name)
      Indicate that the given factory should be ignored, this is useful when a target is somehow being disabled and no corresponding factory results should be shown.
      Parameters:
      name - The unique name for this factory, make sure to namespace this to your mod to avoid collisions.
    • registerAppendixFactory

      public static void registerAppendixFactory(String name, InfoBookParser.IAppendixFactory factory)
      Register a new appendix factory.
      Parameters:
      name - The unique name for this factory, make sure to namespace this to your mod to avoid collisions.
      factory - The factory
    • registerAppendixItemFactory

      public static void registerAppendixItemFactory(String name, InfoBookParser.IAppendixItemFactory factory)
      Register a new appendix item factory.
      Parameters:
      name - The unique name for this factory, make sure to namespace this to your mod to avoid collisions.
      factory - The factory
    • registerAppendixRecipeFactories

      public static <C extends net.minecraft.world.Container, R extends net.minecraft.world.item.crafting.Recipe<C>> void registerAppendixRecipeFactories(net.minecraft.world.item.crafting.RecipeType<R> recipeType, InfoBookParser.IAppendixItemFactory<C,R> factory)
      Register new appendix recipe factories.
      Type Parameters:
      C - The recipe inventory type
      R - The recipe type
      Parameters:
      recipeType - The recipe type
      factory - The factory
    • registerAppendixListFactory

      public static void registerAppendixListFactory(String name, InfoBookParser.IAppendixListFactory factory)
      Register a new appendix list factory.
      Parameters:
      name - The unique name for this factory, make sure to namespace this to your mod to avoid collisions.
      factory - The factory
    • registerAppendixRewardFactory

      public static void registerAppendixRewardFactory(String name, IRewardFactory factory)
      Register a new reward factory.
      Parameters:
      name - The unique name for this factory, make sure to namespace this to your mod to avoid collisions.
      factory - The factory
    • getIndex

      public static int getIndex(Element node)
      Get the index attribute value of the given node.
      Parameters:
      node - An element node.
      Returns:
      The index attribute
    • createStack

      public static net.minecraft.world.item.ItemStack createStack(Element node) throws InfoBookParser.InvalidAppendixException
      Get the itemstack represented by the given node. Interpreted attributes: amount: the stacksize, defaults to 1.
      Parameters:
      node - A node
      Returns:
      An itemstack.
      Throws:
      InfoBookParser.InvalidAppendixException - If the node was incorrectly structured.
    • createStacksFromIngredient

      public static net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> createStacksFromIngredient(Element ingredientNode) throws InfoBookParser.InvalidAppendixException
      Get a list of stacks from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'item' nodes.
      Returns:
      The list of stacks.
      Throws:
      InfoBookParser.InvalidAppendixException - If one of the item nodes was invalid
    • createStackFromIngredient

      public static net.minecraft.world.item.ItemStack createStackFromIngredient(Element ingredientNode) throws InfoBookParser.InvalidAppendixException
      Get the item from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'item' nodes.
      Returns:
      The stack.
      Throws:
      InfoBookParser.InvalidAppendixException - If not exactly one item node was found or if the item node was invalid.
    • createOptionalStackFromIngredient

      public static net.minecraft.world.item.ItemStack createOptionalStackFromIngredient(Element ingredientNode)
      Get the item from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'item' nodes.
      Returns:
      The valid stack.
    • createOptionalStacksFromIngredient

      public static net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> createOptionalStacksFromIngredient(Element ingredientNode)
      Get a list of stacks from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'item' nodes.
      Returns:
      The list of valid stacks.
    • createIngredient

      public static net.minecraft.world.item.crafting.Ingredient createIngredient(Element node) throws InfoBookParser.InvalidAppendixException
      Get the ingredient from the given node.
      Parameters:
      node - A node
      Returns:
      An ingredient
      Throws:
      InfoBookParser.InvalidAppendixException - If the node was incorrectly structured.
    • createIngredientsFromIngredient

      public static net.minecraft.core.NonNullList<net.minecraft.world.item.crafting.Ingredient> createIngredientsFromIngredient(Element ingredientNode) throws InfoBookParser.InvalidAppendixException
      Get a list of ingredients from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'item' nodes.
      Returns:
      The list of ingredients.
      Throws:
      InfoBookParser.InvalidAppendixException - If one of the item nodes was invalid
    • createOptionalIngredientFromIngredient

      public static net.minecraft.world.item.crafting.Ingredient createOptionalIngredientFromIngredient(Element ingredientNode)
      Get the ingredient from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'item' nodes.
      Returns:
      The valid ingredient.
    • createOptionalIngredientsFromIngredient

      public static net.minecraft.core.NonNullList<net.minecraft.world.item.crafting.Ingredient> createOptionalIngredientsFromIngredient(Element ingredientNode)
      Get a list of ingredients from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'item' nodes.
      Returns:
      The list of valid ingredients.
    • createIngredientFromIngredient

      public static net.minecraft.world.item.crafting.Ingredient createIngredientFromIngredient(Element ingredientNode) throws InfoBookParser.InvalidAppendixException
      Get the ingredient from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'item' nodes.
      Returns:
      The ingredient.
      Throws:
      InfoBookParser.InvalidAppendixException - If not exactly one item node was found or if the item node was invalid.
    • createFluidStack

      public static net.neoforged.neoforge.fluids.FluidStack createFluidStack(Element node) throws InfoBookParser.InvalidAppendixException
      Get the fluidstack represented by the given node. Interpreted attributes: amount: the fluid amount, defaults to 1000.
      Parameters:
      node - A node
      Returns:
      A fluidstack.
      Throws:
      InfoBookParser.InvalidAppendixException - If the node was incorrectly structured.
    • createFluidStacksFromIngredient

      public static List<net.neoforged.neoforge.fluids.FluidStack> createFluidStacksFromIngredient(Element ingredientNode) throws InfoBookParser.InvalidAppendixException
      Get a list of fluidstacks from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'fluid' nodes.
      Returns:
      The list of fluidstacks.
      Throws:
      InfoBookParser.InvalidAppendixException - If one of the fluid nodes was invalid
    • createFluidStackFromIngredient

      @Nullable public static net.neoforged.neoforge.fluids.FluidStack createFluidStackFromIngredient(Element ingredientNode) throws InfoBookParser.InvalidAppendixException
      Get the fluidstack from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'fluid' nodes.
      Returns:
      The ingredient.
      Throws:
      InfoBookParser.InvalidAppendixException - If not exactly one fluid node was found or if the fluid node was invalid.
    • createOptionalFluidStackFromIngredient

      @Nullable public static net.neoforged.neoforge.fluids.FluidStack createOptionalFluidStackFromIngredient(Element ingredientNode)
      Get the fluidstack from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'fluid' nodes.
      Returns:
      The valid fluidstack.
    • createOptionalFluidStacksFromIngredient

      public static List<net.neoforged.neoforge.fluids.FluidStack> createOptionalFluidStacksFromIngredient(Element ingredientNode)
      Get a list of fluidstacks from the given ingredient node.
      Parameters:
      ingredientNode - A node that can contain 'fluid' nodes.
      Returns:
      The list of valid fluidstacks.
    • invalidAppendixExceptionThrowableOr

      public static <R> R invalidAppendixExceptionThrowableOr(InfoBookParser.InvalidAppendixException.IThrower<R> thrower, R fallback)
    • initializeInfoBook

      public static InfoSection initializeInfoBook(ModBase<?> mod, IInfoBook infoBook, String path, @Nullable InfoSection parent)
      Initialize the given infobook from the given xml file.
      Parameters:
      mod - The mod owning the section
      infoBook - The infobook to register.
      path - The path to the xml file of the book.
      parent - The parent section.
      Returns:
      The root of the infobook.
    • buildSection

      protected static InfoSection buildSection(IInfoBook infoBook, InfoSection parent, int childIndex, Element sectionElement)
    • createSection

      protected static InfoSection createSection(IInfoBook infoBook, InfoSection parent, int childIndex, String type, String translationKey, ArrayList<String> paragraphs, List<SectionAppendix> appendixes, ArrayList<String> tagList)
    • createAppendix

      protected static SectionAppendix createAppendix(IInfoBook infoBook, String type, Element node) throws InfoBookParser.InvalidAppendixException
      Throws:
      InfoBookParser.InvalidAppendixException
    • createAppendix

      protected static SectionAppendix createAppendix(IInfoBook infoBook, String type, net.minecraft.world.item.crafting.RecipeHolder<net.minecraft.world.item.crafting.Recipe<?>> recipe) throws InfoBookParser.InvalidAppendixException
      Throws:
      InfoBookParser.InvalidAppendixException
    • createAppendixes

      protected static List<SectionAppendix> createAppendixes(IInfoBook infoBook, String factory, Element node) throws InfoBookParser.InvalidAppendixException
      Throws:
      InfoBookParser.InvalidAppendixException
    • createReward

      protected static IReward createReward(IInfoBook infoBook, String type, Element node) throws InfoBookParser.InvalidAppendixException
      Throws:
      InfoBookParser.InvalidAppendixException