Class PartStateAspectVariablesHandler<P extends IPartType>

java.lang.Object
org.cyclops.integrateddynamics.core.part.PartStateAspectVariablesHandler<P>

public class PartStateAspectVariablesHandler<P extends IPartType> extends Object
Handles variables that dynamically determine aspect properties (aspect settings) inside part states. Each aspect that has properties can have an inventory with one variable slot for each of its properties. If a variable is present in such a slot, its value will override the statically configured property value.
  • Field Details

    • INVENTORY_NAME_PREFIX

      public static final String INVENTORY_NAME_PREFIX
      Prefix of the named inventories in which the aspect setting variables are stored. The prefix is followed by the unique name of the aspect.
      See Also:
    • aspectVariables

      protected final Map<IAspect, PartStateAspectVariablesHandler<P extends IPartType>.AspectVariables> aspectVariables
    • aspectVariablesSlotMessages

      protected final Map<IAspect, it.unimi.dsi.fastutil.ints.Int2ObjectMap<net.minecraft.network.chat.MutableComponent>> aspectVariablesSlotMessages
      The errors of all aspect setting variable slots, by aspect. These are part of the part state, so that they are also known client-side, without having to be synced by every gui that wants to show them.
    • dirty

      protected boolean dirty
  • Constructor Details

    • PartStateAspectVariablesHandler

      public PartStateAspectVariablesHandler()
  • Method Details

    • getInventoryName

      public static String getInventoryName(IAspect aspect)
      Parameters:
      aspect - An aspect.
      Returns:
      The name of the named inventory in which the setting variables of the given aspect are stored.
    • getAspectByInventoryName

      @Nullable public static IAspect getAspectByInventoryName(String inventoryName)
      Parameters:
      inventoryName - A named inventory name.
      Returns:
      The aspect this inventory name refers to, or null if it is not an aspect variables inventory.
    • getPropertyTypes

      public static List<IAspectPropertyTypeInstance> getPropertyTypes(IAspect aspect)
      Parameters:
      aspect - An aspect.
      Returns:
      The ordered list of property types of the given aspect.
    • getVariablesInventory

      public static org.cyclops.cyclopscore.inventory.SimpleInventory getVariablesInventory(IPartState<?> partState, IAspect aspect)
      Get the variables inventory for the given aspect within the given part state.
      Parameters:
      partState - A part state.
      aspect - An aspect.
      Returns:
      The inventory, which has one slot for each property of the aspect.
    • markAspectVariablesChanged

      public void markAspectVariablesChanged()
      Indicate that the contents of one of the aspect variables inventories have changed.
    • invalidateDerivedProperties

      public void invalidateDerivedProperties(IAspect aspect)
      Indicate that the statically configured properties of the given aspect have changed, so that any derived properties must be recalculated.
      Parameters:
      aspect - An aspect.
    • getDerivedProperties

      @Nullable public IAspectProperties getDerivedProperties(IAspect aspect, IAspectProperties baseProperties)
      Get the properties of the given aspect after applying all variable-driven property values.
      Parameters:
      aspect - An aspect.
      baseProperties - The statically configured properties.
      Returns:
      The derived properties, or null if no variable-driven values are present.
    • getAspectVariableValue

      @Nullable public IValue getAspectVariableValue(IAspect aspect, int slot)
      Parameters:
      aspect - An aspect.
      slot - A property slot.
      Returns:
      The value that the variable in the given slot currently produces, or null if the slot has no (valid) variable.
    • getAspectVariableError

      @Nullable public net.minecraft.network.chat.MutableComponent getAspectVariableError(IAspect aspect, int slot)
      Parameters:
      aspect - An aspect.
      slot - A property slot.
      Returns:
      The current error in the given slot, or null if there is no error.
    • getAspectVariablesSlotMessages

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<net.minecraft.network.chat.MutableComponent> getAspectVariablesSlotMessages(IAspect aspect)
      Parameters:
      aspect - An aspect.
      Returns:
      The mutable errors of all setting variable slots of the given aspect.
    • getAspectVariablesSlotMessages

      public Map<IAspect, it.unimi.dsi.fastutil.ints.Int2ObjectMap<net.minecraft.network.chat.MutableComponent>> getAspectVariablesSlotMessages()
      Returns:
      The errors of all aspect setting variable slots, by aspect.
    • hasAspectVariables

      public boolean hasAspectVariables()
      Returns:
      If at least one aspect has a variable-driven property.
    • updateAspectVariables

      public void updateAspectVariables(P partType, IPartState<P> partState, INetwork network, IPartNetwork partNetwork, PartTarget target)
      Tick all aspect variables.
      Parameters:
      partType - The part type.
      partState - The part state.
      network - The network.
      partNetwork - The part network.
      target - The part target.
    • reloadAspectVariables

      public void reloadAspectVariables(P partType, IPartState<P> partState, INetwork network, IPartNetwork partNetwork, PartTarget target)
      Reload all aspect variables based on the named inventories inside the given part state.
      Parameters:
      partType - The part type.
      partState - The part state.
      network - The network.
      partNetwork - The part network.
      target - The part target.