Class ExistingFileHelper

java.lang.Object
net.minecraftforge.common.data.ExistingFileHelper

public class ExistingFileHelper extends Object
Enables data providers to check if other data files currently exist. The instance provided in the GatherDataEvent utilizes the standard resources (via VanillaPack), forge's resources, as well as any extra resource packs passed in via the --existing argument, or mod resources via the --existing-mod argument.
  • Field Details

  • Constructor Details

    • ExistingFileHelper

      @Deprecated public ExistingFileHelper(Collection<Path> existingPacks, boolean enable)
      Deprecated.
    • ExistingFileHelper

      @Deprecated public ExistingFileHelper(Collection<Path> existingPacks, Set<String> existingMods, boolean enable)
      Deprecated.
      Create a new helper. This should probably NOT be used by mods, as the instance provided by forge is designed to be a central instance that tracks existence of generated data.

      Only create a new helper if you intentionally want to ignore the existence of other generated files.

      Parameters:
      existingPacks -
      existingMods -
      enable -
    • ExistingFileHelper

      public ExistingFileHelper(Collection<Path> existingPacks, Set<String> existingMods, boolean enable, @Nullable String assetIndex, @Nullable File assetsDir)
  • Method Details

    • getManager

      private IResourceManager getManager(ResourcePackType packType)
    • getLocation

      private ResourceLocation getLocation(ResourceLocation base, String suffix, String prefix)
    • exists

      public boolean exists(ResourceLocation loc, ResourcePackType packType)
      Check if a given resource exists in the known resource packs.
      Parameters:
      loc - the complete location of the resource, e.g. "minecraft:textures/block/stone.png"
      packType - the type of resources to check
      Returns:
      true if the resource exists in any pack, false otherwise
    • exists

      public boolean exists(ResourceLocation loc, ExistingFileHelper.IResourceType type)
      Check if a given resource exists in the known resource packs. This is a convenience method to avoid repeating type/prefix/suffix and instead use the common definitions in ExistingFileHelper.ResourceType, or a custom ExistingFileHelper.IResourceType definition.
      Parameters:
      loc - the base location of the resource, e.g. "minecraft:block/stone"
      type - a ExistingFileHelper.IResourceType describing how to form the path to the resource
      Returns:
      true if the resource exists in any pack, false otherwise
    • exists

      public boolean exists(ResourceLocation loc, ResourcePackType packType, String pathSuffix, String pathPrefix)
      Check if a given resource exists in the known resource packs.
      Parameters:
      loc - the base location of the resource, e.g. "minecraft:block/stone"
      packType - the type of resources to check
      pathSuffix - a string to append after the path, e.g. ".json"
      pathPrefix - a string to append before the path, before a slash, e.g. "models"
      Returns:
      true if the resource exists in any pack, false otherwise
    • trackGenerated

      public void trackGenerated(ResourceLocation loc, ExistingFileHelper.IResourceType type)
      Track the existence of a generated file. This is a convenience method to avoid repeating type/prefix/suffix and instead use the common definitions in ExistingFileHelper.ResourceType, or a custom ExistingFileHelper.IResourceType definition.

      This should be called by data providers immediately when a new data object is created, i.e. not during act but instead when the "builder" (or whatever intermediate object) is created, such as a ModelBuilder.

      This represents a promise to generate the file later, since other datagen may rely on this file existing.

      Parameters:
      loc - the base location of the resource, e.g. "minecraft:block/stone"
      type - a ExistingFileHelper.IResourceType describing how to form the path to the resource
    • trackGenerated

      public void trackGenerated(ResourceLocation loc, ResourcePackType packType, String pathSuffix, String pathPrefix)
      Track the existence of a generated file.

      This should be called by data providers immediately when a new data object is created, i.e. not during act but instead when the "builder" (or whatever intermediate object) is created, such as a ModelBuilder.

      This represents a promise to generate the file later, since other datagen may rely on this file existing.

      Parameters:
      loc - the base location of the resource, e.g. "minecraft:block/stone"
      packType - the type of resources to check
      pathSuffix - a string to append after the path, e.g. ".json"
      pathPrefix - a string to append before the path, before a slash, e.g. "models"
    • getResource

      public IResource getResource(ResourceLocation loc, ResourcePackType packType, String pathSuffix, String pathPrefix) throws IOException
      Throws:
      IOException
    • getResource

      public IResource getResource(ResourceLocation loc, ResourcePackType packType) throws IOException
      Throws:
      IOException
    • isEnabled

      public boolean isEnabled()
      Returns:
      true if validation is enabled, false otherwise