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 net.minecraft.resources.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.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
     
    private static final class 
     

    Nested classes/interfaces inherited from class net.minecraft.resources.RegistryOps

    net.minecraft.resources.RegistryOps.HolderLookupAdapter, net.minecraft.resources.RegistryOps.RegistryInfo<T>, net.minecraft.resources.RegistryOps.RegistryInfoLookup

    Nested classes/interfaces inherited from class net.minecraft.resources.DelegatingOps

    net.minecraft.resources.DelegatingOps.DelegateListBuilder, net.minecraft.resources.DelegatingOps.DelegateRecordBuilder
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Key used to store the value associated with conditions, when the value is not represented as a map.
    private final ICondition.IContext
     
    static final String
    Key used for the conditions inside an object.

    Fields inherited from class net.minecraft.resources.RegistryOps

    lookupProvider

    Fields inherited from class net.minecraft.resources.DelegatingOps

    delegate
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConditionalOps(net.minecraft.resources.RegistryOps<T> ops, ICondition.IContext context)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> com.mojang.serialization.Codec<Optional<T>>
    createConditionalCodec(com.mojang.serialization.Codec<T> ownerCodec)
     
    static <T> com.mojang.serialization.Codec<Optional<T>>
    createConditionalCodec(com.mojang.serialization.Codec<T> ownerCodec, String conditionalsKey)
    Creates a conditional codec.
    static <T> com.mojang.serialization.Codec<Optional<WithConditions<T>>>
    createConditionalCodecWithConditions(com.mojang.serialization.Codec<T> ownerCodec)
     
    static <T> com.mojang.serialization.Codec<Optional<WithConditions<T>>>
    createConditionalCodecWithConditions(com.mojang.serialization.Codec<T> ownerCodec, String conditionalsKey)
    Creates a conditional codec.
    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.
    static com.mojang.serialization.MapCodec<ICondition.IContext>
    Returns a codec that can retrieve a ICondition.IContext from a registry ops, for example with retrieveContext().decode(ops, ops.emptyMap()).

    Methods inherited from class net.minecraft.resources.RegistryOps

    create, create, equals, getter, hashCode, injectRegistryContext, owner, retrieveElement, retrieveGetter, retrieveRegistryLookup, withParent

    Methods inherited from class net.minecraft.resources.DelegatingOps

    compressMaps, convertTo, createBoolean, createByte, createByteList, createDouble, createFloat, createInt, createIntList, createList, createLong, createLongList, createMap, createMap, createNumeric, createShort, createString, empty, emptyList, emptyMap, getBooleanValue, getByteBuffer, getIntStream, getList, getLongStream, getMap, getMapEntries, getMapValues, getNumberValue, getStream, getStringValue, listBuilder, mapBuilder, mergeToList, mergeToList, mergeToMap, mergeToMap, mergeToMap, mergeToPrimitive, remove

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.mojang.serialization.DynamicOps

    convertList, convertMap, get, getGeneric, getNumberValue, set, update, updateGeneric, withDecoder, withEncoder, withParser
  • 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

    • ConditionalOps

      public ConditionalOps(net.minecraft.resources.RegistryOps<T> ops, ICondition.IContext context)
  • 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.