Class PlatformLoader

java.lang.Object
net.dillon.dillonlib.platform.PlatformLoader

public class PlatformLoader extends Object
Service loaders are a built-in Java feature that allow us to locate implementations of an interface that vary from one environment to another. In the context of DillonLib we use this feature to access a mock API in the common code that is swapped out for the platform-specific implementation at runtime.
Since:
1.0
  • Constructor Details

    • PlatformLoader

      public PlatformLoader()
  • Method Details

    • load

      public static <T> T load(Class<T> clazz, String modId)
      This code is used to load a service for the current environment. Your implementation of the service must be defined manually by including a text file in META-INF/services named with the fully qualified class id of the service. Inside the file you should write the fully qualified class id of the implementation to load for the platform. For example our file on Forge points to ForgePlatformImpl while Fabric points to FabricPlatformImpl.
      Parameters:
      modId - should match ModPlatform or MixinModPlatform mod id!
      See Also:
    • collectionOf

      public static <T> List<T> collectionOf(Class<T> clazz)
      Returns:
      all service loaders with a specified class. You can use this method in combo with executeForEachPlatform(Consumer) to execute a task for all instances of a certain platform (an instance of Loadable.
      See Also:
    • executeForEachPlatform

      public static int executeForEachPlatform(Consumer<ModPlatform> function)
      Executes a given task (or method) for all instances ModPlatform classes, and then returns the total amount of platforms (excluding DillonLib's base platform).
    • executeForEachMixinPlatform

      public static int executeForEachMixinPlatform(Consumer<MixinModPlatform> function)
      Executes a given task (or method) for all instances MixinModPlatform classes, and then returns the total amount of mixin platforms (excluding DillonLib's base mixin platform).
    • executeForEachClientPlatform

      public static int executeForEachClientPlatform(Consumer<ClientModPlatform> function)
      Executes a given task (or method) for all instances ClientModPlatform classes, and then returns the total amount of client platforms (excluding DillonLib's base client platform).
    • i_

      public static void i_()
      Initializes this class.