Class ResourceConverter

java.lang.Object
fr.robie.machineengine.api.resource.convert.ResourceConverter
All Implemented Interfaces:
net.kyori.adventure.key.Keyed

public final class ResourceConverter extends Object implements net.kyori.adventure.key.Keyed
An explicitly registered conversion between two resource types (ARCHITECTURE.md ยง9.4). MachineEngine never calls a converter on its own: machines, ports or transports that declare one do. Conversions must be pure and deterministic.
  • Method Details

    • of

      @NotNull public static @NotNull ResourceConverter of(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull ResourceType from, @NotNull @NotNull ResourceType to, @NotNull @NotNull ResourceConverter.Conversion conversion)
    • ratio

      @NotNull public static @NotNull ResourceConverter ratio(@NotNull @NotNull net.kyori.adventure.key.Key key, @NotNull @NotNull ResourceType from, long inputAmount, @NotNull @NotNull ResourceType to, long outputAmount)
      Converts in whole units: every inputAmount of from becomes outputAmount of to's default variant. Leftovers smaller than inputAmount are not consumed.
    • key

      @NotNull public @NotNull net.kyori.adventure.key.Key key()
      Specified by:
      key in interface net.kyori.adventure.key.Keyed
    • from

      @NotNull public @NotNull ResourceType from()
    • to

      @NotNull public @NotNull ResourceType to()
    • convert

      @Nullable public @Nullable ResourceConverter.ConversionResult convert(@NotNull @NotNull ResourceVariant input, long available)
      Parameters:
      input - the variant to convert; must be of type from()
      available - how much of it may be consumed
      Returns:
      what is consumed and produced, or null if nothing can be converted
    • toString

      public String toString()
      Overrides:
      toString in class Object