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, ornullto leave the default in place.inactive- The inactive allele, ornullto 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 Summary
ConstructorsConstructorDescriptionAlleleOverride(Allele<V> active, Allele<V> inactive) Creates an instance of aAlleleOverriderecord class. -
Method Summary
Modifier and TypeMethodDescriptionactive()Returns the value of theactiverecord component.static <V> AlleleOverride<V> Creates an override that sets both the active and inactive allele, the equivalent ofIGenomeBuilder.set(forestry.api.core.genetics.alleles.IChromosome<java.lang.Boolean>, boolean).static <V> com.mojang.serialization.Codec<AlleleOverride<V>> codec(com.mojang.serialization.Codec<V> valueCodec) final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.inactive()Returns the value of theinactiverecord component.booleanstatic <V> AlleleOverride<V> onlyActive(Allele<V> allele) Creates an override that sets only the active allele, the equivalent ofIGenomeBuilder.setActive(forestry.api.core.genetics.alleles.IChromosome<V>, forestry.api.core.genetics.alleles.Allele<V>).static <V> AlleleOverride<V> onlyInactive(Allele<V> allele) Creates an override that sets only the inactive allele, the equivalent ofIGenomeBuilder.setInactive(forestry.api.core.genetics.alleles.IChromosome<V>, forestry.api.core.genetics.alleles.Allele<V>).overrideWith(AlleleOverride<V> other) Layers another override on top of this one.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) final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
both
Creates an override that sets both the active and inactive allele, the equivalent ofIGenomeBuilder.set(forestry.api.core.genetics.alleles.IChromosome<java.lang.Boolean>, boolean). -
onlyActive
Creates an override that sets only the active allele, the equivalent ofIGenomeBuilder.setActive(forestry.api.core.genetics.alleles.IChromosome<V>, forestry.api.core.genetics.alleles.Allele<V>). -
onlyInactive
Creates an override that sets only the inactive allele, the equivalent ofIGenomeBuilder.setInactive(forestry.api.core.genetics.alleles.IChromosome<V>, forestry.api.core.genetics.alleles.Allele<V>). -
overrideWith
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
otherwhere it sets one, otherwise from this one
-
isSameAlleles
public boolean isSameAlleles()- Returns:
trueif 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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
active
Returns the value of theactiverecord component.- Returns:
- the value of the
activerecord component
-
inactive
Returns the value of theinactiverecord component.- Returns:
- the value of the
inactiverecord component
-