Record Class PartConfigSnapshot

java.lang.Object
java.lang.Record
org.cyclops.integrateddynamics.core.part.PartConfigSnapshot
Record Components:
version - The version of this snapshot format.
sourcePartType - The unique name of the part type this snapshot was taken from.
partSettings - The non-default general part settings.
aspectProperties - The serialized non-default aspect properties, by aspect unique name.
variableCards - All variables, of every section.
extraData - The state that the part type itself stored, by section.
disabledEntries - The entries that the player switched off, which are kept but not pasted.

public record PartConfigSnapshot(int version, net.minecraft.resources.Identifier sourcePartType, Optional<PartConfigSnapshot.PartSettings> partSettings, Map<net.minecraft.resources.Identifier, net.minecraft.nbt.CompoundTag> aspectProperties, List<PartConfigSnapshot.VariableCard> variableCards, Map<PartConfigSection, net.minecraft.nbt.CompoundTag> extraData, List<String> disabledEntries) extends Record
An immutable snapshot of the configuration of a part, which can be pasted onto another part. Only things that a player can configure are stored, so no part id, enabled state, error messages or active aspect. Only values that differ from the defaults of the copied part are stored, so that pasting only overwrites what was deliberately configured.
  • Field Details

  • Constructor Details

  • Method Details

    • getVariableCards

      public List<PartConfigSnapshot.VariableCard> getVariableCards(Set<PartConfigSection> sections)
      Parameters:
      sections - The sections that will be pasted.
      Returns:
      The variables that this snapshot holds for the given sections.
    • getExtraData

      public net.minecraft.nbt.CompoundTag getExtraData(PartConfigSection section)
      Part types can store anything that this snapshot does not know about itself, such as the state that an addon adds to its own part types.
      Parameters:
      section - A config section.
      Returns:
      What the part type stored for the given section, which is empty if it stored nothing.
    • getRequiredMaxOffset

      public int getRequiredMaxOffset(Set<PartConfigSection> sections)
      The offset enhancements that a part holds can not be taken out again without breaking the part, so pasting them has to consume enhancements from the player, just like the variable cards do.
      Parameters:
      sections - The sections that will be pasted.
      Returns:
      The offset enhancement value that pasting those sections needs at most.
    • getRequiredBlankVariables

      public int getRequiredBlankVariables(Set<PartConfigSection> sections)
      Parameters:
      sections - The sections that will be pasted.
      Returns:
      The number of blank Variable Cards that pasting those sections needs at most.
    • isEnabled

      public boolean isEnabled(String id)
      Parameters:
      id - The identifier of an entry.
      Returns:
      If that entry is pasted, as opposed to being switched off by the player.
    • withEntryEnabled

      public PartConfigSnapshot withEntryEnabled(String id, boolean enabled)
      Parameters:
      id - The identifier of an entry.
      enabled - If that entry should be pasted.
      Returns:
      A copy of this snapshot in which that entry is switched on or off.
    • getEntries

      public List<PartConfigEntry> getEntries(ValueDeseralizationContext valueDeseralizationContext)
      The entries are what the player switches on and off, so this lists everything that this snapshot holds, whether it is switched on or not.
      Returns:
      Everything inside this snapshot, in the order that it is shown in.
    • addAspectEntries

      protected void addAspectEntries(ValueDeseralizationContext valueDeseralizationContext, List<PartConfigEntry> entries, @Nullable IPartType<?,?> partType, net.minecraft.resources.Identifier aspectName, List<PartConfigSnapshot.VariableCard> cards)
      Add everything that this snapshot holds for one aspect, starting with the card that makes it the aspect that the part uses, followed by its properties, each one directly above the variable that drives it.
      Parameters:
      valueDeseralizationContext - A value deserialization context.
      entries - The entries so far.
      partType - The part type this snapshot was taken from, or null if it is no longer known.
      aspectName - The unique name of the aspect.
      cards - The cards of that aspect.
    • variableCardEntry

      protected static PartConfigEntry variableCardEntry(PartConfigSnapshot.VariableCard card, @Nullable IAspect<?,?> cardAspect)
      Parameters:
      card - A variable card inside this snapshot.
      cardAspect - The aspect that it drives, if any.
      Returns:
      The entry for that card.
    • getVariableCardPropertyKey

      @Nullable protected static String getVariableCardPropertyKey(@Nullable IAspect<?,?> aspect, PartConfigSnapshot.VariableCard card)
      Parameters:
      aspect - The aspect of a setting variable, if it is known.
      card - A variable card inside this snapshot.
      Returns:
      The name of the property that the card drives, or null if it drives no property.
    • getAspectColor

      protected static OptionalInt getAspectColor(@Nullable IAspect<?,?> aspect)
      Parameters:
      aspect - An aspect, or null if the entry belongs to none.
      Returns:
      The colour that a part gui shows that aspect in, so that both guis colour the same thing the same way.
    • getVariableCardAspect

      @Nullable protected static IAspect<?,?> getVariableCardAspect(@Nullable IPartType<?,?> partType, PartConfigSnapshot.VariableCard card)
      Parameters:
      partType - The part type this snapshot was taken from, or null if it is no longer known.
      card - A variable card inside this snapshot.
      Returns:
      The aspect that the card drives, or null if it drives something else than an aspect.
    • getVariableCardGroup

      protected static net.minecraft.network.chat.Component getVariableCardGroup(PartConfigSnapshot.VariableCard card, @Nullable IAspect<?,?> cardAspect)
      Parameters:
      card - A variable card inside this snapshot.
      cardAspect - The aspect that it drives, if any.
      Returns:
      What the card belongs to, which is empty when the name of the card already says it.
    • getVariableCardLabel

      protected static net.minecraft.network.chat.Component getVariableCardLabel(PartConfigSnapshot.VariableCard card, @Nullable IAspect<?,?> cardAspect)
      Parameters:
      card - A variable card inside this snapshot.
      cardAspect - The aspect that it drives, if any.
      Returns:
      What the card drives, rather than the name of the card itself.
    • addPartSetting

      protected void addPartSetting(List<PartConfigEntry> entries, String setting, Optional<net.minecraft.network.chat.Component> value)
    • addPartSetting

      protected void addPartSetting(List<PartConfigEntry> entries, String setting, Optional<net.minecraft.network.chat.Component> value, net.minecraft.world.item.ItemStack icon)
    • getOffsetEnhancements

      public static net.minecraft.world.item.ItemStack getOffsetEnhancements(int maxOffset)
      Parameters:
      maxOffset - A maximum offset.
      Returns:
      The offset enhancements that raising a part to that offset takes.
    • readPropertyValue

      protected static net.minecraft.network.chat.Component readPropertyValue(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag property)
      Parameters:
      valueDeseralizationContext - A value deserialization context.
      property - One stored aspect property.
      Returns:
      The value of that property, in the same compact shape that the part gui shows it in.
    • hasSection

      public boolean hasSection(PartConfigSection section)
      Parameters:
      section - A config section.
      Returns:
      If this snapshot holds anything for the given section.
    • hasEnabledPartSetting

      protected boolean hasEnabledPartSetting(PartConfigSnapshot.PartSettings settings)
    • hasEnabledAspectProperty

      protected boolean hasEnabledAspectProperty()
    • getSections

      public Set<PartConfigSection> getSections()
      Returns:
      All sections that this snapshot holds something for.
    • isEmpty

      public boolean isEmpty()
      Returns:
      If this snapshot holds nothing at all.
    • toNBT

      public net.minecraft.nbt.CompoundTag toNBT(net.minecraft.core.HolderLookup.Provider provider)
      Parameters:
      provider - A holder lookup provider, used to serialize the variable cards.
      Returns:
      The NBT representation of this snapshot.
    • fromNBT

      public static Optional<PartConfigSnapshot> fromNBT(net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag tag)
      Parameters:
      provider - A holder lookup provider, used to deserialize the variable cards.
      tag - An NBT representation of a snapshot.
      Returns:
      The snapshot, or empty if it could not be read.
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • version

      public int version()
      Returns the value of the version record component.
      Returns:
      the value of the version record component
    • sourcePartType

      public net.minecraft.resources.Identifier sourcePartType()
      Returns the value of the sourcePartType record component.
      Returns:
      the value of the sourcePartType record component
    • partSettings

      public Optional<PartConfigSnapshot.PartSettings> partSettings()
      Returns the value of the partSettings record component.
      Returns:
      the value of the partSettings record component
    • aspectProperties

      public Map<net.minecraft.resources.Identifier, net.minecraft.nbt.CompoundTag> aspectProperties()
      Returns the value of the aspectProperties record component.
      Returns:
      the value of the aspectProperties record component
    • variableCards

      public List<PartConfigSnapshot.VariableCard> variableCards()
      Returns the value of the variableCards record component.
      Returns:
      the value of the variableCards record component
    • extraData

      public Map<PartConfigSection, net.minecraft.nbt.CompoundTag> extraData()
      Returns the value of the extraData record component.
      Returns:
      the value of the extraData record component
    • disabledEntries

      public List<String> disabledEntries()
      Returns the value of the disabledEntries record component.
      Returns:
      the value of the disabledEntries record component