Record Class AlleleOverride<V>

java.lang.Object
java.lang.Record
forestry.api.core.genetics.alleles.AlleleOverride<V>
Type Parameters:
V - The type of value held by this override's alleles.
Record Components:
active - The active (expressed) allele, or null to leave the default in place.
inactive - The inactive allele, or null to leave the default in place.

public record AlleleOverride<V>(@Nullable Allele<V> active, @Nullable Allele<V> inactive) extends Record
One chromosome's entry in a sparse set of genome overrides: an active allele, an inactive allele, or both.

This is the serialized counterpart of the three IGenomeBuilder setters. A side that is null is left at whatever the karyotype and taxon defaults produced, so IGenomeBuilder.setActive(forestry.api.core.genetics.alleles.IChromosome<V>, forestry.api.core.genetics.alleles.Allele<V>) and IGenomeBuilder.setInactive(forestry.api.core.genetics.alleles.IChromosome<V>, forestry.api.core.genetics.alleles.Allele<V>) are expressible in data, not only in code.

The JSON form is a single allele when both sides hold the same one, so datapacks and addons written against the older format keep loading:

 "forestry:bee_effect": { "value": "forestry:bee_effect_mycophilic" }
 "forestry:speed":      { "value": 1.4, "dominant": true }
 
To set the sides apart, name each one and give it a whole allele of its own:
 "forestry:bee_effect": { "active": { "value": "forestry:bee_effect_mycophilic" } }
 "forestry:speed":      {
     "active":   { "value": 1.7, "dominant": true },
     "inactive": { "value": 0.6 }
 }
 
Ex. { "inactive": { "value": 0.6 } } -> leave the active allele alone, set the inactive one to 0.6
  • Constructor Details

    • AlleleOverride

      public AlleleOverride(@Nullable Allele<V> active, @Nullable Allele<V> inactive)
      Creates an instance of a AlleleOverride record class.
      Parameters:
      active - the value for the active record component
      inactive - the value for the inactive record component
  • Method Details

    • both

      public static <V> AlleleOverride<V> both(Allele<V> allele)
      Creates an override that sets both the active and inactive allele, the equivalent of IGenomeBuilder.set(forestry.api.core.genetics.alleles.IChromosome<java.lang.Boolean>, boolean).
    • onlyActive

      public static <V> AlleleOverride<V> onlyActive(Allele<V> allele)
    • onlyInactive

      public static <V> AlleleOverride<V> onlyInactive(Allele<V> allele)
    • overrideWith

      public AlleleOverride<V> overrideWith(AlleleOverride<V> other)
      Layers another override on top of this one. Used when a genome closure calls more than one setter for the same chromosome, so the later call wins per side rather than for the whole pair.
      Parameters:
      other - The override applied over this one.
      Returns:
      A new override taking each side from other where it sets one, otherwise from this one
    • isSameAlleles

      public boolean isSameAlleles()
      Returns:
      true if both sides are set to the same allele
    • codec

      public static <V> com.mojang.serialization.Codec<AlleleOverride<V>> codec(com.mojang.serialization.Codec<V> valueCodec)
      Returns:
      A codec for one override, serializing values inline via the given value codec
    • streamCodec

      public static <V> net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,AlleleOverride<V>> streamCodec(net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,V> valueStreamCodec)
      Returns:
      A stream codec for one override: a side mask byte, then each present side's allele
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • active

      @Nullable public Allele<V> active()
      Returns the value of the active record component.
      Returns:
      the value of the active record component
    • inactive

      @Nullable public Allele<V> inactive()
      Returns the value of the inactive record component.
      Returns:
      the value of the inactive record component