Class PartNetworkElement<P extends IPartType<P,S>, S extends IPartState<P>>

java.lang.Object
org.cyclops.integrateddynamics.core.network.NetworkElementBase
org.cyclops.integrateddynamics.core.network.PartNetworkElement<P,S>
All Implemented Interfaces:
Comparable<INetworkElement>, IEnergyConsumingNetworkElement, IEventListenableNetworkElement<P>, IIdentifiableNetworkElement, INetworkElement, IPartNetworkElement<P,S>, IPositionedNetworkElement, ISidedNetworkElement

public class PartNetworkElement<P extends IPartType<P,S>, S extends IPartState<P>> extends NetworkElementBase implements IPartNetworkElement<P,S>, IEnergyConsumingNetworkElement
A network element for parts.
  • Constructor Details

    • PartNetworkElement

      public PartNetworkElement(P part, PartPos center)
  • Method Details

    • getCenterPos

      protected static org.cyclops.cyclopscore.datastructure.DimPos getCenterPos(PartTarget target)
    • getCenterSide

      protected static net.minecraft.core.Direction getCenterSide(PartTarget target)
    • getTargetPos

      protected static org.cyclops.cyclopscore.datastructure.DimPos getTargetPos(PartTarget target)
    • getTargetSide

      protected static net.minecraft.core.Direction getTargetSide(PartTarget target)
    • getPart

      public P getPart()
      Specified by:
      getPart in interface IPartNetworkElement<P extends IPartType<P,S>, S extends IPartState<P>>
      Returns:
      The part.
    • getTarget

      public PartTarget getTarget()
      Specified by:
      getTarget in interface IPartNetworkElement<P extends IPartType<P,S>, S extends IPartState<P>>
      Returns:
      The target and position of this part.
    • getTarget

      public PartTarget getTarget(S partState)
    • getTempState

      public S getTempState()
    • setTempState

      public void setTempState(S tempState)
    • getPartContainer

      public IPartContainer getPartContainer()
      Specified by:
      getPartContainer in interface IPartNetworkElement<P extends IPartType<P,S>, S extends IPartState<P>>
      Returns:
      The container in which this part resides.
    • getPartContainer

      public IPartContainer getPartContainer(@Nullable net.minecraft.world.level.block.state.BlockState blockState, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity)
    • getPartContainerOptional

      public Optional<IPartContainer> getPartContainerOptional()
    • setPriorityAndChannel

      public void setPriorityAndChannel(INetwork network, int priority, int channel)
      Description copied from interface: INetworkElement
      Set the priority and channel of this element in the network.
      Specified by:
      setPriorityAndChannel in interface INetworkElement
      Parameters:
      network - The network this element is present in.
      priority - The new priority
      channel - The new channel
    • getPriority

      public int getPriority()
      Specified by:
      getPriority in interface INetworkElement
      Returns:
      The priority of this element in the network.
    • getChannel

      public int getChannel()
      Specified by:
      getChannel in interface INetworkElement
      Returns:
      The channel of this element in the network.
    • canRevalidate

      public boolean canRevalidate(INetwork network)
      Description copied from interface: INetworkElement
      Check if this element can be revalidated if it has been invalidated.
      Specified by:
      canRevalidate in interface INetworkElement
      Parameters:
      network - The network.
      Returns:
      If it can be revalidated.
    • revalidate

      public void revalidate(INetwork network)
      Description copied from interface: INetworkElement
      Revalidate this network element after it has been invalidated.
      Specified by:
      revalidate in interface INetworkElement
      Overrides:
      revalidate in class NetworkElementBase
      Parameters:
      network - The network.
    • isLoaded

      public boolean isLoaded()
      Specified by:
      isLoaded in interface INetworkElement
      Returns:
      If this element's position is currently loaded in the world.
    • hasPartState

      public boolean hasPartState()
    • getPartStateOptional

      @Nullable protected S getPartStateOptional()
      Resolve the part state of this element using a single part container lookup, or null if this element is not loaded or has no part. Contrary to calling hasPartState() and getPartState() in sequence, this only requires a single (relatively expensive) part container lookup.
      Returns:
      The part state, or null.
    • getPartStateOptionalLoaded

      @Nullable protected S getPartStateOptionalLoaded()
      Resolve the part state of this element using a single part container lookup, assuming that this element is loaded, or null if it has no part.
      Returns:
      The part state, or null.
    • getPartState

      public S getPartState() throws PartStateException
      Specified by:
      getPartState in interface IPartNetworkElement<P extends IPartType<P,S>, S extends IPartState<P>>
      Returns:
      The state for this part.
      Throws:
      PartStateException - If the part state could not be found.
    • getPartState

      public S getPartState(@Nullable net.minecraft.world.level.block.state.BlockState blockState, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity) throws PartStateException
      Throws:
      PartStateException
    • getConsumptionRate

      public int getConsumptionRate()
      Specified by:
      getConsumptionRate in interface IEnergyConsumingNetworkElement
      Returns:
      The energy consumption rate of this part for the given state.
    • postUpdate

      public void postUpdate(INetwork network, boolean updated)
      Description copied from interface: IEnergyConsumingNetworkElement
      Called after the element was updated or not. If the update was not called, this can be because the network did not contain enough energy to let this element work.
      Specified by:
      postUpdate in interface IEnergyConsumingNetworkElement
      Parameters:
      network - The network.
      updated - If the INetworkElement.update(INetwork) was called.
    • getUpdateInterval

      public int getUpdateInterval()
      Specified by:
      getUpdateInterval in interface INetworkElement
      Overrides:
      getUpdateInterval in class NetworkElementBase
      Returns:
      The tick interval to update this element.
    • isUpdate

      public boolean isUpdate()
      Specified by:
      isUpdate in interface INetworkElement
      Overrides:
      isUpdate in class NetworkElementBase
      Returns:
      If this element should be updated. This method is only called once during network initialization.
    • update

      public void update(INetwork network)
      Description copied from interface: INetworkElement
      Update at the tick interval specified.
      Specified by:
      update in interface INetworkElement
      Overrides:
      update in class NetworkElementBase
      Parameters:
      network - The network to update in.
    • beforeNetworkKill

      public void beforeNetworkKill(INetwork network, @Nullable net.minecraft.world.level.block.state.BlockState blockState, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity)
      Description copied from interface: INetworkElement
      Called right before the network is terminated or will be reset.
      Specified by:
      beforeNetworkKill in interface INetworkElement
      Overrides:
      beforeNetworkKill in class NetworkElementBase
      Parameters:
      network - The network to update in.
      blockState - The block state.
      blockEntity - The block entity.
    • afterNetworkAlive

      public void afterNetworkAlive(INetwork network)
      Description copied from interface: INetworkElement
      Called right after this network is initialized.
      Specified by:
      afterNetworkAlive in interface INetworkElement
      Overrides:
      afterNetworkAlive in class NetworkElementBase
      Parameters:
      network - The network to update in.
    • afterNetworkReAlive

      public void afterNetworkReAlive(INetwork network)
      Description copied from interface: INetworkElement
      Called right after this network has come alive again, for example after a network restart.
      Specified by:
      afterNetworkReAlive in interface INetworkElement
      Overrides:
      afterNetworkReAlive in class NetworkElementBase
      Parameters:
      network - The network to update in.
    • addDrops

      public void addDrops(net.minecraft.world.level.block.state.BlockState blockState, net.minecraft.world.level.block.entity.BlockEntity blockEntity, List<net.minecraft.world.item.ItemStack> itemStacks, boolean dropMainElement, boolean saveState)
      Description copied from interface: INetworkElement
      Add the itemstacks to drop when this element is removed.
      Specified by:
      addDrops in interface INetworkElement
      Overrides:
      addDrops in class NetworkElementBase
      Parameters:
      blockState - The block state of the container block.
      blockEntity - The block entity of the container block.
      itemStacks - The itemstack list to add to.
      dropMainElement - If the part itself should also be dropped.
      saveState - If the element state should be saved in the item.
    • onNetworkAddition

      public boolean onNetworkAddition(INetwork network)
      Description copied from interface: INetworkElement
      Called when this element is added to the network.
      Specified by:
      onNetworkAddition in interface INetworkElement
      Overrides:
      onNetworkAddition in class NetworkElementBase
      Parameters:
      network - The network.
      Returns:
      If the addition succeeded.
    • onNetworkRemoval

      public void onNetworkRemoval(INetwork network, net.minecraft.world.level.block.state.BlockState blockState, net.minecraft.world.level.block.entity.BlockEntity blockEntity)
      Description copied from interface: INetworkElement
      Called when this element is removed from the network.
      Specified by:
      onNetworkRemoval in interface INetworkElement
      Overrides:
      onNetworkRemoval in class NetworkElementBase
      Parameters:
      network - The network.
      blockState - The block state.
      blockEntity - The block entity.
    • onPreRemoved

      public void onPreRemoved(INetwork network)
      Description copied from interface: INetworkElement
      Called when this element is about to be removed. This is called before IFullNetworkListener.removeNetworkElementPre(INetworkElement).
      Specified by:
      onPreRemoved in interface INetworkElement
      Overrides:
      onPreRemoved in class NetworkElementBase
      Parameters:
      network - The network.
    • onPostRemoved

      public void onPostRemoved(INetwork network)
      Description copied from interface: INetworkElement
      Called when this element has been removed. This is called after IFullNetworkListener.removeNetworkElementPost(INetworkElement, BlockState, BlockEntity).
      Specified by:
      onPostRemoved in interface INetworkElement
      Overrides:
      onPostRemoved in class NetworkElementBase
      Parameters:
      network - The network.
    • onNeighborBlockChange

      public void onNeighborBlockChange(@Nullable INetwork network, net.minecraft.world.level.BlockGetter world, @Nullable net.minecraft.core.Direction side)
      Description copied from interface: INetworkElement
      Called when a neighbouring block is updated, more specifically when BlockBehaviour.neighborChanged(BlockState, Level, BlockPos, Block, Orientation, boolean), IBlockExtension.onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos) or BlockBehaviour.updateShape(BlockState, LevelReader, ScheduledTickAccess, BlockPos, Direction, BlockPos, BlockState, RandomSource) is called.
      Specified by:
      onNeighborBlockChange in interface INetworkElement
      Overrides:
      onNeighborBlockChange in class NetworkElementBase
      Parameters:
      network - The network to update in.
      world - The world in which the neighbour was updated.
      side - The side at the center block.
    • getNetworkEventListener

      public Optional<P> getNetworkEventListener()
      Description copied from interface: IEventListenableNetworkElement
      This listener will never be saved as an instance, this network element is always used as delegator to this listener.
      Specified by:
      getNetworkEventListener in interface IEventListenableNetworkElement<P extends IPartType<P,S>>
      Returns:
      The optional event listener.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(INetworkElement o)
      Specified by:
      compareTo in interface Comparable<P extends IPartType<P,S>>
    • getPriorityLoaded

      protected int getPriorityLoaded()
      Returns:
      The priority of this element, assuming that it is loaded.
    • getPriorityOfLoaded

      protected static int getPriorityOfLoaded(IPartNetworkElement element)
      Parameters:
      element - A loaded part network element.
      Returns:
      The priority of the given element.
    • getPosition

      public org.cyclops.cyclopscore.datastructure.DimPos getPosition()
      Specified by:
      getPosition in interface IPositionedNetworkElement
    • getSide

      public net.minecraft.core.Direction getSide()
      Specified by:
      getSide in interface ISidedNetworkElement
    • getId

      public int getId()
      Specified by:
      getId in interface IIdentifiableNetworkElement
      Returns:
      The unique id of this element.
    • getGroup

      public net.minecraft.resources.Identifier getGroup()
      Specified by:
      getGroup in interface IIdentifiableNetworkElement
      Returns:
      A group within which the element is unique.