Class TemperaturePredicate

java.lang.Object
com.github.thedeathlycow.thermoo.api.predicate.TemperaturePredicate

public class TemperaturePredicate extends Object
Predicate for testing the temperature of a TemperatureAware

This is injected into EntityPredicate via mixin. This mean that this is NOT a new loot condition, it is actually an extension of the vanilla predicate EntityPredicate and can therefore be used anywhere that it is used. For exameple, as part of the vanilla loot condition minecraft:entity_properties

Example usage:

 {
            "condition": "minecraft:entity_properties",
            "entity": "this",
            "predicate": {
                    "thermoo.temperature": {
                            "scale": NumberRange.FloatRange,
                            "temperature": NumberRange.IntRange
          }
      }
 }
 

Note that both scale and temperature are optional, and if not supplied will default to NumberRange.FloatRange.ANY and NumberRange.IntRange.ANY respectively.

See Also:
  • EntityPredicate
  • Field Details

    • ANY

      public static final TemperaturePredicate ANY
      "Any" predicate that will always return as true when tested
  • Constructor Details

    • TemperaturePredicate

      public TemperaturePredicate(net.minecraft.predicate.NumberRange.FloatRange scaleRange, net.minecraft.predicate.NumberRange.IntRange temperatureRange)
      Constructs a new temperature predicate with a scale and temperature range
      Parameters:
      scaleRange - The temperature scale range accepted by this predicate
      temperatureRange - The absolute temperature value range accepted by this predicate
  • Method Details

    • test

      public boolean test(TemperatureAware tempAware)
      Tests the temperature of a TemperatureAware against this predicate.

      If this predicate is ANY then this test will always be true.

      Otherwise, BOTH the temperature scale and temperature value of the tempAware must match the ranges of this predicate

      Parameters:
      tempAware - The TemperatureAware to test
      Returns:
      Returns true if the predicate accepts tempAware
    • toJson

      public com.google.gson.JsonElement toJson()
      Serializes this predicate to JSON

      If this instance is ANY, then returns JsonNull

      Returns:
      Returns a JsonElement that represents this instance
    • fromJson

      @Contract("!null->new") public static TemperaturePredicate fromJson(@Nullable @Nullable com.google.gson.JsonElement json)
      Returns the TemperaturePredicate that is represented by the given json.

      If the given json is null or JsonNull, then returns ANY

      Parameters:
      json - The json object to deserialize
      Returns:
      Returns the temperature predicate represented by the given json.