public final class DistExecutor
extends java.lang.Object
safeCallWhenOn(Dist, Supplier)
safeRunForDist(Supplier, Supplier)
safeRunWhenOn(Dist, Supplier)
Modifier and Type | Class and Description |
---|---|
static interface |
DistExecutor.SafeCallable<T>
SafeCallable version of
DistExecutor.SafeReferent . |
static interface |
DistExecutor.SafeReferent
A safe referent.
|
static interface |
DistExecutor.SafeRunnable
SafeRunnable version of
DistExecutor.SafeReferent |
static interface |
DistExecutor.SafeSupplier<T>
SafeSupplier version of
DistExecutor.SafeReferent |
Modifier and Type | Field and Description |
---|---|
private static org.apache.logging.log4j.Logger |
LOGGER |
Modifier | Constructor and Description |
---|---|
private |
DistExecutor() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
callWhenOn(net.minecraftforge.api.distmarker.Dist dist,
java.util.function.Supplier<java.util.concurrent.Callable<T>> toRun)
Deprecated.
use
safeCallWhenOn(Dist, Supplier) instead. This remains for advanced use cases. |
static <T> T |
runForDist(java.util.function.Supplier<java.util.function.Supplier<T>> clientTarget,
java.util.function.Supplier<java.util.function.Supplier<T>> serverTarget)
Deprecated.
|
static void |
runWhenOn(net.minecraftforge.api.distmarker.Dist dist,
java.util.function.Supplier<java.lang.Runnable> toRun)
Deprecated.
use
safeRunWhenOn(Dist, Supplier) where possible. Advanced uses only. |
static <T> T |
safeCallWhenOn(net.minecraftforge.api.distmarker.Dist dist,
java.util.function.Supplier<DistExecutor.SafeCallable<T>> toRun)
Call the SafeCallable when on the correct
Dist . |
static <T> T |
safeRunForDist(java.util.function.Supplier<DistExecutor.SafeSupplier<T>> clientTarget,
java.util.function.Supplier<DistExecutor.SafeSupplier<T>> serverTarget)
Executes one of the two suppliers, based on which side is active.
|
static void |
safeRunWhenOn(net.minecraftforge.api.distmarker.Dist dist,
java.util.function.Supplier<DistExecutor.SafeRunnable> toRun)
Call the supplied SafeRunnable when on the correct Dist.
|
static <T> T |
unsafeCallWhenOn(net.minecraftforge.api.distmarker.Dist dist,
java.util.function.Supplier<java.util.concurrent.Callable<T>> toRun) |
static <T> T |
unsafeRunForDist(java.util.function.Supplier<java.util.function.Supplier<T>> clientTarget,
java.util.function.Supplier<java.util.function.Supplier<T>> serverTarget)
Unsafe version of
safeRunForDist(Supplier, Supplier) . |
static void |
unsafeRunWhenOn(net.minecraftforge.api.distmarker.Dist dist,
java.util.function.Supplier<java.lang.Runnable> toRun)
Runs the supplied Runnable on the speicified side.
|
private static void |
validateSafeReferent(java.util.function.Supplier<? extends DistExecutor.SafeReferent> safeReferentSupplier) |
@Deprecated public static <T> T callWhenOn(net.minecraftforge.api.distmarker.Dist dist, java.util.function.Supplier<java.util.concurrent.Callable<T>> toRun)
safeCallWhenOn(Dist, Supplier)
instead. This remains for advanced use cases.Side
.
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 callabledist
- The dist to run ontoRun
- A supplier of the callable to run (Supplier wrapper to ensure classloading only on the appropriate dist)public static <T> T unsafeCallWhenOn(net.minecraftforge.api.distmarker.Dist dist, java.util.function.Supplier<java.util.concurrent.Callable<T>> toRun)
public static <T> T safeCallWhenOn(net.minecraftforge.api.distmarker.Dist dist, java.util.function.Supplier<DistExecutor.SafeCallable<T>> toRun)
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 thrownT
- The type of the SafeCallabledist
- the dist which this will run ontoRun
- the SafeCallable to run and return the result from@Deprecated public static void runWhenOn(net.minecraftforge.api.distmarker.Dist dist, java.util.function.Supplier<java.lang.Runnable> toRun)
safeRunWhenOn(Dist, Supplier)
where possible. Advanced uses only.callWhenOn(Dist, Supplier)
.
This method can cause unexpected ClassNotFound exceptions.dist
- Dist to run this code ontoRun
- The code to runcallWhenOn(Dist, Supplier)
public static void unsafeRunWhenOn(net.minecraftforge.api.distmarker.Dist dist, java.util.function.Supplier<java.lang.Runnable> toRun)
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 ontoRun
- The code to rununsafeCallWhenOn(Dist, Supplier)
public static void safeRunWhenOn(net.minecraftforge.api.distmarker.Dist dist, java.util.function.Supplier<DistExecutor.SafeRunnable> toRun)
dist
- The dist to run ontoRun
- The code to run@Deprecated public static <T> T runForDist(java.util.function.Supplier<java.util.function.Supplier<T>> clientTarget, java.util.function.Supplier<java.util.function.Supplier<T>> serverTarget)
safeRunForDist(Supplier, Supplier)
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 returnclientTarget
- The supplier supplier to run when on the Dist.CLIENT
serverTarget
- The supplier supplier to run when on the Dist.DEDICATED_SERVER
public static <T> T unsafeRunForDist(java.util.function.Supplier<java.util.function.Supplier<T>> clientTarget, java.util.function.Supplier<java.util.function.Supplier<T>> serverTarget)
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 returnclientTarget
- The supplier supplier to run when on the Dist.CLIENT
serverTarget
- The supplier supplier to run when on the Dist.DEDICATED_SERVER
public static <T> T safeRunForDist(java.util.function.Supplier<DistExecutor.SafeSupplier<T>> clientTarget, java.util.function.Supplier<DistExecutor.SafeSupplier<T>> serverTarget)
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 returnclientTarget
- The supplier supplier to run when on the Dist.CLIENT
serverTarget
- The supplier supplier to run when on the Dist.DEDICATED_SERVER
private static final void validateSafeReferent(java.util.function.Supplier<? extends DistExecutor.SafeReferent> safeReferentSupplier)