Class PartStateBase<P extends IPartType>

java.lang.Object
org.cyclops.integrateddynamics.core.part.PartStateBase<P>
All Implemented Interfaces:
org.cyclops.cyclopscore.persist.IDirtyMarkListener, IPartState<P>
Direct Known Subclasses:
PartStateActiveVariableBase, PartStateEmpty, PartStateReaderBase, PartTypeConnector.State

public abstract class PartStateBase<P extends IPartType> extends Object implements IPartState<P>, org.cyclops.cyclopscore.persist.IDirtyMarkListener
A default implementation of the IPartState.
  • Constructor Details

    • PartStateBase

      public PartStateBase()
  • Method Details

    • writeToNBT

      public void writeToNBT(net.minecraft.nbt.CompoundTag tag)
      Description copied from interface: IPartState
      Write a state to NBT.
      Specified by:
      writeToNBT in interface IPartState<P extends IPartType>
      Parameters:
      tag - The tag to write to.
    • readFromNBT

      public void readFromNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag)
      Description copied from interface: IPartState
      Read a state from NBT.
      Specified by:
      readFromNBT in interface IPartState<P extends IPartType>
      Parameters:
      valueDeseralizationContext - Getter for blocks.
      tag - The tag to read from.
    • writeAspectProperties

      protected void writeAspectProperties(String name, net.minecraft.nbt.CompoundTag tag)
    • readAspectProperties

      public void readAspectProperties(ValueDeseralizationContext valueDeseralizationContext, String name, net.minecraft.nbt.CompoundTag tag)
    • generateId

      public void generateId()
      Description copied from interface: IPartState
      Generate a server-wide unique ID for this part state.
      Specified by:
      generateId in interface IPartState<P extends IPartType>
    • getId

      public int getId()
      Description copied from interface: IPartState
      A server-wide unique ID for this part that is persisted when the part is broken and moved.
      Specified by:
      getId in interface IPartState<P extends IPartType>
      Returns:
      The unique ID
    • setUpdateInterval

      public void setUpdateInterval(int updateInterval)
      Description copied from interface: IPartState
      Set the update interval for this state.
      Specified by:
      setUpdateInterval in interface IPartState<P extends IPartType>
      Parameters:
      updateInterval - The tick interval to update this element.
    • getUpdateInterval

      public int getUpdateInterval()
      Specified by:
      getUpdateInterval in interface IPartState<P extends IPartType>
      Returns:
      The tick interval to update this element.
    • setPriority

      public void setPriority(int priority)
      Description copied from interface: IPartState
      Set the priority of this part in the network.
      Specified by:
      setPriority in interface IPartState<P extends IPartType>
      Parameters:
      priority - The new priority
    • getPriority

      public int getPriority()
      Specified by:
      getPriority in interface IPartState<P extends IPartType>
      Returns:
      The priority of this part in the network.
    • setChannel

      public void setChannel(int channel)
      Description copied from interface: IPartState
      Set the channel for this state.
      Specified by:
      setChannel in interface IPartState<P extends IPartType>
      Parameters:
      channel - The new channel
    • getChannel

      public int getChannel()
      Specified by:
      getChannel in interface IPartState<P extends IPartType>
      Returns:
      This part's channel.
    • getTargetOffset

      public net.minecraft.core.Vec3i getTargetOffset()
      Specified by:
      getTargetOffset in interface IPartState<P extends IPartType>
      Returns:
      The target position offset.
    • setTargetOffset

      public void setTargetOffset(net.minecraft.core.Vec3i targetOffset)
      Specified by:
      setTargetOffset in interface IPartState<P extends IPartType>
      Parameters:
      targetOffset - The target position offset.
    • setTargetSideOverride

      public void setTargetSideOverride(net.minecraft.core.Direction targetSide)
      Description copied from interface: IPartState
      Indicate that the given part should interact with the given side of the target.
      Specified by:
      setTargetSideOverride in interface IPartState<P extends IPartType>
      Parameters:
      targetSide - The side of the target block to interact with. Null removes the side override.
    • getTargetSideOverride

      @Nullable public net.minecraft.core.Direction getTargetSideOverride()
      Specified by:
      getTargetSideOverride in interface IPartState<P extends IPartType>
      Returns:
      The side of the target block to interact with. Can be null.
    • markDirty

      public void markDirty()
      Description copied from interface: IPartState
      Indicate that this state has changes that must be saved to the world.
      Specified by:
      markDirty in interface IPartState<P extends IPartType>
    • isDirtyAndReset

      public boolean isDirtyAndReset()
      Description copied from interface: IPartState
      Check if dirty and reset the dirty state.
      Specified by:
      isDirtyAndReset in interface IPartState<P extends IPartType>
      Returns:
      If this state has changed since the last time and needs to be persisted to NBT eventually.
    • isUpdateAndReset

      public boolean isUpdateAndReset()
      Description copied from interface: IPartState
      Check if this part state should update and reset the flag.
      Specified by:
      isUpdateAndReset in interface IPartState<P extends IPartType>
      Returns:
      If this state has changed since the last time and needs to be updated to the client.
    • forceBlockRenderUpdate

      public void forceBlockRenderUpdate()
      Description copied from interface: IPartState
      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.
      Specified by:
      forceBlockRenderUpdate in interface IPartState<P extends IPartType>
    • isForceBlockRenderUpdateAndReset

      public boolean isForceBlockRenderUpdateAndReset()
      Specified by:
      isForceBlockRenderUpdateAndReset in interface IPartState<P extends IPartType>
      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.
    • onDirty

      public void onDirty()
      Specified by:
      onDirty in interface org.cyclops.cyclopscore.persist.IDirtyMarkListener
    • sendUpdate

      public void sendUpdate()
      Enables a flag that tells the part container to send an NBT update to the client(s).
    • getAspectProperties

      public IAspectProperties getAspectProperties(IAspect aspect)
      Description copied from interface: IPartState
      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.
      Specified by:
      getAspectProperties in interface IPartState<P extends IPartType>
      Parameters:
      aspect - The aspect to get the properties from.
      Returns:
      The properties, this can be null if still the default.
    • setAspectProperties

      public void setAspectProperties(IAspect aspect, IAspectProperties properties)
      Description copied from interface: IPartState
      Set the properties for the given aspect.
      Specified by:
      setAspectProperties in interface IPartState<P extends IPartType>
      Parameters:
      aspect - The aspect to get the properties from.
      properties - The properties, this can be null if still the default.
    • setEnabled

      public void setEnabled(boolean enabled)
      Description copied from interface: IPartState
      Enable the part from working.
      Specified by:
      setEnabled in interface IPartState<P extends IPartType>
      Parameters:
      enabled - If it should work.
    • isEnabled

      public boolean isEnabled()
      Specified by:
      isEnabled in interface IPartState<P extends IPartType>
      Returns:
      If the part should work.
    • getInventoryNamed

      public net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> getInventoryNamed(String name)
      Specified by:
      getInventoryNamed in interface IPartState<P extends IPartType>
      Parameters:
      name - The inventory name.
      Returns:
      Get the inventory contents of the given name.
    • setInventoryNamed

      public void setInventoryNamed(String name, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> inventory)
      Description copied from interface: IPartState
      Set the inventory of the given name.
      Specified by:
      setInventoryNamed in interface IPartState<P extends IPartType>
      Parameters:
      name - The inventory name.
      inventory - Inventory contents.
    • getInventoriesNamed

      public Map<String,net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>> getInventoriesNamed()
      Specified by:
      getInventoriesNamed in interface IPartState<P extends IPartType>
      Returns:
      All named inventories.
    • clearInventoriesNamed

      public void clearInventoriesNamed()
      Description copied from interface: IPartState
      Clear all named inventories.
      Specified by:
      clearInventoriesNamed in interface IPartState<P extends IPartType>
    • gatherCapabilities

      public void gatherCapabilities(P partType)
      Gathers the capabilities of this part state. Don't call this unless you know what you're doing!
      Specified by:
      gatherCapabilities in interface IPartState<P extends IPartType>
      Parameters:
      partType - The part type this state is associated with.
    • getCapability

      public <T> net.minecraftforge.common.util.LazyOptional<T> getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, INetwork network, IPartNetwork partNetwork, PartTarget target)
      Description copied from interface: IPartState
      Get the given capability.
      Specified by:
      getCapability in interface IPartState<P extends IPartType>
      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

      public <T> void addVolatileCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraftforge.common.util.LazyOptional<T> value)
      Description copied from interface: IPartState
      Add a capability to this state that will not be automatically persisted to NBT.
      Specified by:
      addVolatileCapability in interface IPartState<P extends IPartType>
      Type Parameters:
      T - The capability type.
      Parameters:
      capability - The optional capability.
      value - The capability instance.
    • removeVolatileCapability

      public void removeVolatileCapability(net.minecraftforge.common.capabilities.Capability<?> capability)
      Description copied from interface: IPartState
      Remove a non-persisted capability.
      Specified by:
      removeVolatileCapability in interface IPartState<P extends IPartType>
      Parameters:
      capability - The capability.
    • getDefaultUpdateInterval

      protected int getDefaultUpdateInterval()
    • initializeOffsets

      public void initializeOffsets(PartTarget target)
      Description copied from interface: IPartState
      Run the initialization logic for offset handling.
      Specified by:
      initializeOffsets in interface IPartState<P extends IPartType>
    • updateOffsetVariables

      public void updateOffsetVariables(P partType, INetwork network, IPartNetwork partNetwork, PartTarget target)
      Description copied from interface: IPartState
      Tick any internal offset variables.
      Specified by:
      updateOffsetVariables in interface IPartState<P extends IPartType>
      Parameters:
      partType - The part type.
      network - The network.
      partNetwork - The part network.
      target - The part target.
    • getOffsetVariableError

      @Nullable public net.minecraft.network.chat.MutableComponent getOffsetVariableError(int slot)
      Specified by:
      getOffsetVariableError in interface IPartState<P extends IPartType>
      Parameters:
      slot - The offset variable slot.
      Returns:
      The current error, or null if no error.
    • requiresOffsetUpdates

      public boolean requiresOffsetUpdates()
      Specified by:
      requiresOffsetUpdates in interface IPartState<P extends IPartType>
      Returns:
      If the part contains variable-driven offsets that require updating.
    • markOffsetVariablesChanged

      public void markOffsetVariablesChanged()
      Description copied from interface: IPartState
      Indicate that the contents of the offset variables inventory have changed.
      Specified by:
      markOffsetVariablesChanged in interface IPartState<P extends IPartType>
    • getMaxOffset

      public int getMaxOffset()
      Specified by:
      getMaxOffset in interface IPartState<P extends IPartType>
      Returns:
      The max offset allowed in this part.
    • setMaxOffset

      public void setMaxOffset(int maxOffset)
      Description copied from interface: IPartState
      Update the max offset for this part.
      Specified by:
      setMaxOffset in interface IPartState<P extends IPartType>
      Parameters:
      maxOffset - The new offset.