Class ConditionalOps<T>

java.lang.Object
net.minecraft.resources.DelegatingOps<T>
net.minecraft.resources.RegistryOps<T>
net.neoforged.neoforge.common.conditions.ConditionalOps<T>
All Implemented Interfaces:
com.mojang.serialization.DynamicOps<T>

public class ConditionalOps<T> extends RegistryOps<T>
Extension of RegistryOps that also encapsulates a ICondition.IContext. This allows getting the ICondition.IContext while decoding an entry from within a codec.
  • Field Details

    • context

      private final ICondition.IContext context
    • DEFAULT_CONDITIONS_KEY

      public static final String DEFAULT_CONDITIONS_KEY
      Key used for the conditions inside an object.
      See Also:
    • CONDITIONAL_VALUE_KEY

      public static final String CONDITIONAL_VALUE_KEY
      Key used to store the value associated with conditions, when the value is not represented as a map. For example, if we wanted to store the value 2 with some conditions, we could do:
       {
           "neoforge:conditions": [ ... ],
           "neoforge:value": 2
       }
       
      See Also:
  • Constructor Details

  • Method Details

    • retrieveContext

      public static com.mojang.serialization.MapCodec<ICondition.IContext> retrieveContext()
      Returns a codec that can retrieve a ICondition.IContext from a registry ops, for example with retrieveContext().decode(ops, ops.emptyMap()).
    • createConditionalCodec

      public static <T> com.mojang.serialization.Codec<Optional<T>> createConditionalCodec(com.mojang.serialization.Codec<T> ownerCodec)
      See Also:
    • createConditionalCodec

      public static <T> com.mojang.serialization.Codec<Optional<T>> createConditionalCodec(com.mojang.serialization.Codec<T> ownerCodec, String conditionalsKey)
      Creates a conditional codec.

      The conditional codec is generally not suitable for use as a dispatch target because it is never a MapCodec.MapCodecCodec.

    • decodeListWithElementConditions

      public static <T> com.mojang.serialization.Codec<List<T>> decodeListWithElementConditions(com.mojang.serialization.Codec<T> ownerCodec)
      Creates a codec that can decode a list of elements, and will check for conditions on each element.
    • createConditionalCodecWithConditions

      public static <T> com.mojang.serialization.Codec<Optional<WithConditions<T>>> createConditionalCodecWithConditions(com.mojang.serialization.Codec<T> ownerCodec)
      See Also:
    • createConditionalCodecWithConditions

      public static <T> com.mojang.serialization.Codec<Optional<WithConditions<T>>> createConditionalCodecWithConditions(com.mojang.serialization.Codec<T> ownerCodec, String conditionalsKey)
      Creates a conditional codec.

      The conditional codec is generally not suitable for use as a dispatch target because it is never a MapCodec.MapCodecCodec.