类 DistExecutor

java.lang.Object
net.minecraftforge.fml.DistExecutor

public final class DistExecutor extends Object
Use to execute code conditionally based on sidedness.
  • 字段详细资料

    • LOGGER

      private static final org.apache.logging.log4j.Logger LOGGER
  • 构造器详细资料

    • DistExecutor

      private DistExecutor()
  • 方法详细资料

    • callWhenOn

      @Deprecated public static <T> T callWhenOn(net.minecraftforge.api.distmarker.Dist dist, Supplier<Callable<T>> toRun)
      已过时。
      use safeCallWhenOn(Dist, Supplier) instead. This remains for advanced use cases.
      Run the callable in the supplier only on the specified Dist. This method is NOT sided-safe and special care needs to be taken in code using this method that implicit class loading is not triggered by the Callable. This method can cause unexpected ClassNotFound exceptions. Use safeCallWhenOn(Dist, Supplier) where possible.
      类型参数:
      T - The return type from the callable
      参数:
      dist - The dist to run on
      toRun - A supplier of the callable to run (Supplier wrapper to ensure classloading only on the appropriate dist)
      返回:
      The callable's result
    • unsafeCallWhenOn

      public static <T> T unsafeCallWhenOn(net.minecraftforge.api.distmarker.Dist dist, Supplier<Callable<T>> toRun)
    • safeCallWhenOn

      public static <T> T safeCallWhenOn(net.minecraftforge.api.distmarker.Dist dist, Supplier<DistExecutor.SafeCallable<T>> toRun)
      Call the SafeCallable when on the correct Dist. The lambda supplied here is required to be a method reference to a method defined in another class, otherwise an invalid SafeReferent error will be thrown
      类型参数:
      T - The type of the SafeCallable
      参数:
      dist - the dist which this will run on
      toRun - the SafeCallable to run and return the result from
      返回:
      the result of the SafeCallable or null if on the wrong side
    • runWhenOn

      @Deprecated public static void runWhenOn(net.minecraftforge.api.distmarker.Dist dist, Supplier<Runnable> toRun)
      已过时。
      use safeRunWhenOn(Dist, Supplier) where possible. Advanced uses only.
      Runs the supplied Runnable on the speicified side. Same warnings apply as callWhenOn(Dist, Supplier). This method can cause unexpected ClassNotFound exceptions.
      参数:
      dist - Dist to run this code on
      toRun - The code to run
      另请参阅:
    • unsafeRunWhenOn

      public static void unsafeRunWhenOn(net.minecraftforge.api.distmarker.Dist dist, Supplier<Runnable> toRun)
      Runs the supplied Runnable on the speicified side. Same warnings apply as unsafeCallWhenOn(Dist, Supplier). This method can cause unexpected ClassNotFoundException problems in common scenarios. Understand the pitfalls of the way the class verifier works to load classes before using this. Use safeRunWhenOn(Dist, Supplier) if you can.
      参数:
      dist - Dist to run this code on
      toRun - The code to run
      另请参阅:
    • safeRunWhenOn

      public static void safeRunWhenOn(net.minecraftforge.api.distmarker.Dist dist, Supplier<DistExecutor.SafeRunnable> toRun)
      Call the supplied SafeRunnable when on the correct Dist.
      参数:
      dist - The dist to run on
      toRun - The code to run
    • runForDist

      @Deprecated public static <T> T runForDist(Supplier<Supplier<T>> clientTarget, Supplier<Supplier<T>> serverTarget)
      Executes one of the two suppliers, based on which side is active.

      Example (replacement for old SidedProxy):
      Proxy p = DistExecutor.runForDist(()->ClientProxy::new, ()->ServerProxy::new); NOTE: the double supplier is required to avoid classloading the secondary target.

      类型参数:
      T - The common type to return
      参数:
      clientTarget - The supplier supplier to run when on the Dist.CLIENT
      serverTarget - The supplier supplier to run when on the Dist.DEDICATED_SERVER
      返回:
      The returned instance
    • unsafeRunForDist

      public static <T> T unsafeRunForDist(Supplier<Supplier<T>> clientTarget, Supplier<Supplier<T>> serverTarget)
      Unsafe version of safeRunForDist(Supplier, Supplier). Use only when you know what you're doing and understand why the verifier can cause unexpected ClassNotFoundException crashes even when code is apparently not sided. Ensure you test both sides fully to be confident in using this.
      类型参数:
      T - The common type to return
      参数:
      clientTarget - The supplier supplier to run when on the Dist.CLIENT
      serverTarget - The supplier supplier to run when on the Dist.DEDICATED_SERVER
      返回:
      The returned instance
    • safeRunForDist

      public static <T> T safeRunForDist(Supplier<DistExecutor.SafeSupplier<T>> clientTarget, Supplier<DistExecutor.SafeSupplier<T>> serverTarget)
      Executes one of the two suppliers, based on which side is active.

      Example (replacement for old SidedProxy):
      Proxy p = DistExecutor.safeRunForDist(()->ClientProxy::new, ()->ServerProxy::new); NOTE: the double supplier is required to avoid classloading the secondary target.

      类型参数:
      T - The common type to return
      参数:
      clientTarget - The supplier supplier to run when on the Dist.CLIENT
      serverTarget - The supplier supplier to run when on the Dist.DEDICATED_SERVER
      返回:
      The returned instance
    • validateSafeReferent

      private static final void validateSafeReferent(Supplier<? extends DistExecutor.SafeReferent> safeReferentSupplier)