Class FunctionEffect

java.lang.Object
com.github.thedeathlycow.thermoo.api.temperature.status.v2.effect.FunctionEffect
All Implemented Interfaces:
TemperatureEffect

public final class FunctionEffect extends Object implements TemperatureEffect
An effect which invokes datapack functions (.mcfunction files).

Note: Datapack functions are generally not very performant. In general, you should prefer to create your own temperature effect implementation when possible. This should only be used if you are limited to using datapacks exclusively.

  • Field Details

    • CODEC

      public static final com.mojang.serialization.MapCodec<FunctionEffect> CODEC
      Codec for the function effect.
  • Method Details

    • function

      public static FunctionWithArguments function(net.minecraft.resources.Identifier functionId, @Nullable @Nullable net.minecraft.nbt.CompoundTag arguments)
      Creates a new function with macro arguments.
      Parameters:
      functionId - The ID of the function. May not be null.
      arguments - The macro arguments of the function. If null, then no arguments will be supplied.
      Throws:
      NullPointerException - if functionId is null
    • function

      public static FunctionWithArguments function(net.minecraft.resources.Identifier functionId)
      Creates a new function without any macro arguments.
      Parameters:
      functionId - The ID of the function. May not be null.
      Throws:
      NullPointerException - if functionId is null
    • builder

      public static FunctionEffect.Builder builder(FunctionWithArguments function)
      Creates a new builder with an apply function.
      Parameters:
      function - The apply function. May not be null.
      Throws:
      NullPointerException - if function is null
    • create

      public static FunctionEffect create(FunctionWithArguments function)
      Creates a simple function effect which executes at a permission level of 2 and has no cleanup function,
      Parameters:
      function - The apply function. May not be null.
      Throws:
      NullPointerException - if function is null
    • apply

      public boolean apply(net.minecraft.world.entity.LivingEntity target, TemperatureEffectContext context)
      Calls the main function()
      Specified by:
      apply in interface TemperatureEffect
      Parameters:
      target - The entity receiving the effect.
      context - Additional context for the effect.
      Returns:
      Returns true when executed on the logical server AND the function was successfully executed.
    • remove

      public void remove(net.minecraft.world.entity.LivingEntity target, TemperatureEffectContext context)
      Invokes the removeFunction(), if present. Any potential cleanup logic should be implemented in that function.
      Specified by:
      remove in interface TemperatureEffect
      Parameters:
      target - The entity the effect is being removed from.
      context - Additional context for the effect.
    • codec

      public com.mojang.serialization.MapCodec<FunctionEffect> codec()
      Specified by:
      codec in interface TemperatureEffect
      Returns:
      Returns CODEC
    • function

      public FunctionWithArguments function()
      The main function that applies the effect.
    • removeFunction

      public Optional<FunctionWithArguments> removeFunction()
      The function that handles cleanup logic for the effect. Optional.
    • permissionLevel

      public @Range(from=0L,to=4L) int permissionLevel()
      The permission level that the function is executed at.
      Returns:
      Returns an int between 0 and 4 (inclusive).