Class DifficultyContext

java.lang.Object
johnsmith.enchantingoverhauled.api.enchantment.value.DifficultyContext

public final class DifficultyContext extends Object
Global context holder providing the active world Difficulty for DifficultyBasedValue evaluations where a Level reference is not directly passed by vanilla's LevelBasedValue.calculate(int) signature.
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.world.Difficulty
    Resolves the current world Difficulty, preferring the active server's world data and falling back to the client difficulty supplier.
    static void
    setClientFallback(Supplier<net.minecraft.world.Difficulty> fallback)
    Sets the client-side fallback supplier used to query difficulty from the client level.
    static void
    setServer(@Nullable net.minecraft.server.MinecraftServer server)
    Sets or clears the active MinecraftServer reference on server startup/shutdown.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setServer

      public static void setServer(@Nullable @Nullable net.minecraft.server.MinecraftServer server)
      Sets or clears the active MinecraftServer reference on server startup/shutdown.
      Parameters:
      server - The active MinecraftServer, or null when the server stops.
    • setClientFallback

      public static void setClientFallback(Supplier<net.minecraft.world.Difficulty> fallback)
      Sets the client-side fallback supplier used to query difficulty from the client level.
      Parameters:
      fallback - A supplier returning the client's current Difficulty.
    • getDifficulty

      public static net.minecraft.world.Difficulty getDifficulty()
      Resolves the current world Difficulty, preferring the active server's world data and falling back to the client difficulty supplier.
      Returns:
      The active Difficulty.