Class AbstractRange<T extends Number>

java.lang.Object
com.portingdeadmods.portingdeadlibs.utils.ranges.AbstractRange<T>
Direct Known Subclasses:
FloatRange, IntRange

public abstract class AbstractRange<T extends Number> extends Object
  • Constructor Details

    • AbstractRange

      protected AbstractRange(T minInclusive, T maxInclusive, T step)
    • AbstractRange

      protected AbstractRange(T minInclusive, T maxInclusive)
  • Method Details

    • getMin

      public T getMin()
    • getMax

      public T getMax()
    • getPossibleValues

      public Collection<T> getPossibleValues()
      Returns a collection of all possible values within the range dictated by the min, max, and step values.
      Returns:
      A collection of possible values.
    • fits

      public boolean fits(T value)
      Checks if a given value fits within the range defined by min and max.
      Parameters:
      value - The value to check.
      Returns:
      true if the value is within the range, false otherwise.
    • shift

      public abstract AbstractRange<T> shift(T offset)
      Utility method to create a new range shifted by a specified offset.
      Parameters:
      offset - The offset to shift the range by.
      Returns:
      A new range that is shifted by the specified offset.
    • collectPossibleValues

      protected abstract Collection<T> collectPossibleValues()
      Collects all possible values in the range specified. Default step of 1.0f is used.
      Returns:
      A collection of all possible float values in the range with a step of 1.0f.
    • collectPossibleValues

      protected abstract Collection<T> collectPossibleValues(T step)
      Collects all possible values in the range specified.
      Parameters:
      step - The step value to use for collecting possible values.
      Returns:
      A collection of all possible float values in the range with a step of 1.0f.
    • rangeMapCodec

      public static <T extends Number, SELF extends AbstractRange<T>> com.mojang.serialization.MapCodec<SELF> rangeMapCodec(com.mojang.serialization.Codec<T> codec, BiFunction<T,T,SELF> constructor)
    • rangeStreamCodec

      public static <T extends Number, SELF extends AbstractRange<T>> net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,SELF> rangeStreamCodec(net.minecraft.network.codec.StreamCodec<io.netty.buffer.ByteBuf,T> streamCodec, BiFunction<T,T,SELF> constructor)