Interface IPartState<P extends IPartType>

All Known Subinterfaces:
IPartStateReader<P>, IPartStateWriter<P>
All Known Implementing Classes:
PartStateActiveVariableBase, PartStateBase, PartStateEmpty, PartStateReaderBase, PartStateWriterBase, PartTypeConnector.State, PartTypeConnectorMonoDirectional.State, PartTypeConnectorOmniDirectional.State, PartTypePanelDisplay.State, PartTypePanelLightDynamic.State, PartTypePanelVariableDriven.State

public interface IPartState<P extends IPartType>
A value holder for an IPartType. This is what will be serialized from and to NBT. This object is mutable and should not be recreated. Note that you should be careful when passing around this state, because when the server sends an update to the client, this state could be overwritten with a new version, so always try to use the part container to get the state.
  • Field Details

  • Method Details

    • writeToNBT

      void writeToNBT(net.minecraft.nbt.CompoundTag tag)
      Write a state to NBT.
      Parameters:
      tag - The tag to write to.
    • readFromNBT

      void readFromNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag)
      Read a state from NBT.
      Parameters:
      valueDeseralizationContext - Getter for blocks.
      tag - The tag to read from.
    • generateId

      void generateId()
      Generate a server-wide unique ID for this part state.
    • getId

      int getId()
      A server-wide unique ID for this part that is persisted when the part is broken and moved.
      Returns:
      The unique ID
    • setUpdateInterval

      void setUpdateInterval(int updateInterval)
      Set the update interval for this state.
      Parameters:
      updateInterval - The tick interval to update this element.
    • getUpdateInterval

      int getUpdateInterval()
      Returns:
      The tick interval to update this element.
    • setPriority

      @Deprecated void setPriority(int priority)
      Deprecated.
      Set the priority of this part in the network.
      Parameters:
      priority - The new priority
    • getPriority

      int getPriority()
      Returns:
      The priority of this part in the network.
    • setChannel

      @Deprecated void setChannel(int channel)
      Deprecated.
      Set the channel for this state.
      Parameters:
      channel - The new channel
    • getChannel

      int getChannel()
      Returns:
      This part's channel.
    • getTargetOffset

      net.minecraft.core.Vec3i getTargetOffset()
      Returns:
      The target position offset.
    • setTargetOffset

      void setTargetOffset(net.minecraft.core.Vec3i offset)
      Parameters:
      offset - The target position offset.
    • setTargetSideOverride

      void setTargetSideOverride(@Nullable net.minecraft.core.Direction side)
      Indicate that the given part should interact with the given side of the target.
      Parameters:
      side - The side of the target block to interact with. Null removes the side override.
    • getTargetSideOverride

      @Nullable net.minecraft.core.Direction getTargetSideOverride()
      Returns:
      The side of the target block to interact with. Can be null.
    • markDirty

      void markDirty()
      Indicate that this state has changes that must be saved to the world.
    • isDirtyAndReset

      boolean isDirtyAndReset()
      Check if dirty and reset the dirty state.
      Returns:
      If this state has changed since the last time and needs to be persisted to NBT eventually.
    • isUpdateAndReset

      boolean isUpdateAndReset()
      Check if this part state should update and reset the flag.
      Returns:
      If this state has changed since the last time and needs to be updated to the client.
    • forceBlockRenderUpdate

      void forceBlockRenderUpdate()
      Set a flag indicating that the next time that IPartType.shouldTriggerBlockRenderUpdate(IPartState, IPartState) is queried, it should return true. This is useful in cases where the player makes changes inside a part, the state difference checking can not be relied upon, and a state update should be forced in any case. This should only be called client-side.
    • isForceBlockRenderUpdateAndReset

      boolean isForceBlockRenderUpdateAndReset()
      Returns:
      If a block render update is forced. This flagged will be set to false after this method is called. This should only be called client-side.
    • getAspectProperties

      IAspectProperties getAspectProperties(IAspect aspect)
      Get the properties for the given aspect. This will only retrieve the already saved properties, so this could be null if not set before. It is better to call the IAspect.getProperties(IPartType, PartTarget, IPartState) method instead.
      Parameters:
      aspect - The aspect to get the properties from.
      Returns:
      The properties, this can be null if still the default.
    • setAspectProperties

      void setAspectProperties(IAspect aspect, IAspectProperties properties)
      Set the properties for the given aspect.
      Parameters:
      aspect - The aspect to get the properties from.
      properties - The properties, this can be null if still the default.
    • setEnabled

      void setEnabled(boolean enabled)
      Enable the part from working.
      Parameters:
      enabled - If it should work.
    • isEnabled

      boolean isEnabled()
      Returns:
      If the part should work.
    • gatherCapabilities

      void gatherCapabilities(P partType)
      Gathers the capabilities of this part state. Don't call this unless you know what you're doing!
      Parameters:
      partType - The part type this state is associated with.
    • getCapability

      <T> net.minecraftforge.common.util.LazyOptional<T> getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, INetwork network, IPartNetwork partNetwork, PartTarget target)
      Get the given capability.
      Type Parameters:
      T - The capability type.
      Parameters:
      capability - The capability to get.
      network - The network the part belongs to.
      partNetwork - The part network the part belongs to.
      target - The target.
      Returns:
      The optional capability instance.
    • addVolatileCapability

      <T> void addVolatileCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraftforge.common.util.LazyOptional<T> value)
      Add a capability to this state that will not be automatically persisted to NBT.
      Type Parameters:
      T - The capability type.
      Parameters:
      capability - The optional capability.
      value - The capability instance.
    • removeVolatileCapability

      void removeVolatileCapability(net.minecraftforge.common.capabilities.Capability<?> capability)
      Remove a non-persisted capability.
      Parameters:
      capability - The capability.
    • loadInventoryNamed

      default void loadInventoryNamed(String name, net.minecraft.world.Container inventory)
      Load the inventory of the given name from the part state.
      Parameters:
      name - The inventory name.
      inventory - The inventory object to load into.
    • saveInventoryNamed

      default void saveInventoryNamed(String name, net.minecraft.world.Container inventory)
      Save the inventory of the given name into the part state.
      Parameters:
      name - The inventory name.
      inventory - The inventory object to save.
    • getInventoryNamed

      @Nullable net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> getInventoryNamed(String name)
      Parameters:
      name - The inventory name.
      Returns:
      Get the inventory contents of the given name.
    • setInventoryNamed

      void setInventoryNamed(String name, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> inventory)
      Set the inventory of the given name.
      Parameters:
      name - The inventory name.
      inventory - Inventory contents.
    • getInventoriesNamed

      Map<String,net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>> getInventoriesNamed()
      Returns:
      All named inventories.
    • clearInventoriesNamed

      void clearInventoriesNamed()
      Clear all named inventories.
    • initializeOffsets

      void initializeOffsets(PartTarget target)
      Run the initialization logic for offset handling.
    • updateOffsetVariables

      void updateOffsetVariables(P partType, INetwork network, IPartNetwork partNetwork, PartTarget target)
      Tick any internal offset variables.
      Parameters:
      partType - The part type.
      network - The network.
      partNetwork - The part network.
      target - The part target.
    • markOffsetVariablesChanged

      void markOffsetVariablesChanged()
      Indicate that the contents of the offset variables inventory have changed.
    • getOffsetVariableError

      @Nullable net.minecraft.network.chat.MutableComponent getOffsetVariableError(int slot)
      Parameters:
      slot - The offset variable slot.
      Returns:
      The current error, or null if no error.
    • requiresOffsetUpdates

      boolean requiresOffsetUpdates()
      Returns:
      If the part contains variable-driven offsets that require updating.
    • getMaxOffset

      int getMaxOffset()
      Returns:
      The max offset allowed in this part.
    • setMaxOffset

      void setMaxOffset(int offset)
      Update the max offset for this part.
      Parameters:
      offset - The new offset.