java.lang.Object
org.cyclops.integrateddynamics.core.network.Network
All Implemented Interfaces:
org.cyclops.cyclopscore.persist.nbt.INBTSerializable, IFullNetworkListener, INetwork

public class Network extends Object implements INetwork
A network instance that can hold a set of INetworkElements. Note that this network only contains references to the relevant data, it does not contain the actual information.
  • Constructor Details

    • Network

      public Network()
      This constructor should not be called, except for the process of constructing networks from NBT.
    • Network

      public Network(Cluster pathElements)
      Create a new network from a given cluster of path elements. Each path element will be checked if it has a INetworkElementProvider capability at its position and will add all its elements to the network in that case. Each path element that has an IPartContainer capability will have the network stored in its part container.
      Parameters:
      pathElements - The path elements that make up the connections in the network which can potentially provide network elements.
  • Method Details

    • initiateNetworkSetup

      public static Network initiateNetworkSetup(ISidedPathElement sidedPathElement)
      Initiate a full network from the given start position.
      Parameters:
      sidedPathElement - The sided path element to start from.
      Returns:
      The newly formed network.
    • areNetworksEqual

      public static boolean areNetworksEqual(Network networkA, Network networkB)
      Check if two networks are equal.
      Parameters:
      networkA - A network.
      networkB - Another network.
      Returns:
      If they are equal.
    • gatherCapabilities

      protected void gatherCapabilities()
    • gatherFullNetworkListeners

      protected IFullNetworkListener[] gatherFullNetworkListeners()
    • onConstruct

      protected void onConstruct()
    • isInitialized

      public boolean isInitialized()
      Specified by:
      isInitialized in interface INetwork
      Returns:
      If this network and its elements have been fully initialized.
    • getEventBus

      public INetworkEventBus getEventBus()
      Specified by:
      getEventBus in interface INetwork
      Returns:
      The event bus for this network.
    • initialize

      public void initialize()
      Initialize the network element data.
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • toNBT

      public net.minecraft.nbt.CompoundTag toNBT(net.minecraft.core.HolderLookup.Provider provider)
      Specified by:
      toNBT in interface org.cyclops.cyclopscore.persist.nbt.INBTSerializable
    • fromNBT

      public void fromNBT(net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag tag)
      Specified by:
      fromNBT in interface org.cyclops.cyclopscore.persist.nbt.INBTSerializable
    • fromNBTEffective

      public void fromNBTEffective(net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag tag)
    • addNetworkElement

      public boolean addNetworkElement(INetworkElement element, boolean networkPreinit)
      Description copied from interface: IFullNetworkListener
      Add a given network element to the network Also checks if it can tick and will handle it accordingly.
      Specified by:
      addNetworkElement in interface IFullNetworkListener
      Parameters:
      element - The network element.
      networkPreinit - If the network is still in the process of being initialized.
      Returns:
      If the addition succeeded.
    • addNetworkElementUpdateable

      public void addNetworkElementUpdateable(INetworkElement element)
      Description copied from interface: INetwork
      Add a given network element to the tickable elements set.
      Specified by:
      addNetworkElementUpdateable in interface INetwork
      Parameters:
      element - The network element.
    • removeNetworkElementPre

      public boolean removeNetworkElementPre(INetworkElement element)
      Description copied from interface: IFullNetworkListener
      Checks if the given network element can be removed from the network
      Specified by:
      removeNetworkElementPre in interface IFullNetworkListener
      Parameters:
      element - The network element.
      Returns:
      If the element was can be removed from the network.
    • setPriorityAndChannel

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

      public void removeNetworkElementPost(INetworkElement element)
      Description copied from interface: IFullNetworkListener
      Remove a given network element from the network. Also removed its tickable instance.
      Specified by:
      removeNetworkElementPost in interface IFullNetworkListener
      Parameters:
      element - The network element.
    • removeNetworkElementUpdateable

      public void removeNetworkElementUpdateable(INetworkElement element)
      Description copied from interface: INetwork
      Remove given network element from the tickable elements set.
      Specified by:
      removeNetworkElementUpdateable in interface INetwork
      Parameters:
      element - The network element.
    • initialize

      protected void initialize(boolean silent)
      Called when a network is server-loaded or newly created.
      Parameters:
      silent - If the element should not be notified for the network becoming alive.
    • kill

      public void kill()
      Description copied from interface: IFullNetworkListener
      Terminate the network elements for this network.
      Specified by:
      kill in interface IFullNetworkListener
    • killIfEmpty

      public boolean killIfEmpty()
      Description copied from interface: INetwork
      Kills the network is it had no more network elements.
      Specified by:
      killIfEmpty in interface INetwork
      Returns:
      If the network was killed.
    • canUpdate

      public boolean canUpdate(INetworkElement element)
      Description copied from interface: IFullNetworkListener
      If the given element can update.
      Specified by:
      canUpdate in interface IFullNetworkListener
      Parameters:
      element - The network element.
      Returns:
      If it can update.
    • postUpdate

      public void postUpdate(INetworkElement element)
      Description copied from interface: IFullNetworkListener
      Called after a network element's update was called.
      Specified by:
      postUpdate in interface IFullNetworkListener
      Parameters:
      element - The network element.
    • onSkipUpdate

      public void onSkipUpdate(INetworkElement element)
      Description copied from interface: IFullNetworkListener
      When the given element is not being updated because IFullNetworkListener.canUpdate(INetworkElement) returned false.
      Specified by:
      onSkipUpdate in interface IFullNetworkListener
      Parameters:
      element - The element that is not being updated.
    • updateGuaranteed

      public void updateGuaranteed()
      Description copied from interface: IFullNetworkListener
      This guaranteed network updating should be called each tick, even in safe-mode.
      Specified by:
      updateGuaranteed in interface IFullNetworkListener
    • update

      public final void update()
      Description copied from interface: IFullNetworkListener
      This network updating should be called each tick.
      Specified by:
      update in interface IFullNetworkListener
    • onUpdate

      protected void onUpdate()
    • removePathElement

      public boolean removePathElement(IPathElement pathElement, net.minecraft.core.Direction side)
      Description copied from interface: IFullNetworkListener
      Remove the given path element from the network. If the path element had any network elements registered in the network, these will be killed and removed as well.
      Specified by:
      removePathElement in interface IFullNetworkListener
      Parameters:
      pathElement - The path element.
      side - The side.
      Returns:
      If the path element was removed.
    • afterServerLoad

      public void afterServerLoad()
      Description copied from interface: IFullNetworkListener
      Called when the server loaded this network. This is the time to notify all network elements of this network.
      Specified by:
      afterServerLoad in interface IFullNetworkListener
    • beforeServerStop

      public void beforeServerStop()
      Description copied from interface: IFullNetworkListener
      Called when the server will save this network before stopping. This is the time to notify all network elements of this network.
      Specified by:
      beforeServerStop in interface IFullNetworkListener
    • getElements

      public Set<INetworkElement> getElements()
      Specified by:
      getElements in interface INetwork
      Returns:
      The network elements.
    • isKilled

      public boolean isKilled()
      Specified by:
      isKilled in interface INetwork
      Returns:
      If this network has been killed.
    • onNetworkChanged

      protected void onNetworkChanged()
    • hasChanged

      public boolean hasChanged()
      Specified by:
      hasChanged in interface INetwork
      Returns:
      If the network has changed structure or elements in the last tick.
    • getCablesCount

      public int getCablesCount()
      Specified by:
      getCablesCount in interface INetwork
      Returns:
      The number of cables in the network.
    • getLastSecondDuration

      public long getLastSecondDuration(INetworkElement networkElement)
      Description copied from interface: INetwork
      Get the last tick duration of the given network element.
      Specified by:
      getLastSecondDuration in interface INetwork
      Parameters:
      networkElement - The networkelement
      Returns:
      Duration in nanoseconds
    • resetLastSecondDurations

      public void resetLastSecondDurations()
      Description copied from interface: INetwork
      Reset the last second duration counts.
      Specified by:
      resetLastSecondDurations in interface INetwork
    • isCrashed

      public boolean isCrashed()
      Specified by:
      isCrashed in interface INetwork
      Returns:
      If this network has crashed.
    • setCrashed

      public void setCrashed(boolean crashed)
      Specified by:
      setCrashed in interface INetwork
      Parameters:
      crashed - The new crashed field.
    • getCapability

      public <T> Optional<T> getCapability(NetworkCapability<T> capability)
      Description copied from interface: INetwork
      Get the given capability.
      Specified by:
      getCapability in interface INetwork
      Type Parameters:
      T - The capability type.
      Parameters:
      capability - The capability to get.
      Returns:
      The optional capability instance.
    • invalidateElement

      public void invalidateElement(INetworkElement element)
      Description copied from interface: INetwork
      Invalidate the given element. This should be called when the element's chunk is being unloaded.
      Specified by:
      invalidateElement in interface IFullNetworkListener
      Specified by:
      invalidateElement in interface INetwork
      Parameters:
      element - The network element to invalidate.
    • revalidateElement

      public void revalidateElement(INetworkElement element)
      Description copied from interface: INetwork
      Revalidate the given element. This should be called when the element's chunk is being reloaded.
      Specified by:
      revalidateElement in interface IFullNetworkListener
      Specified by:
      revalidateElement in interface INetwork
      Parameters:
      element - The network element to invalidate.
    • containsSidedPathElement

      public boolean containsSidedPathElement(ISidedPathElement pathElement)
      Specified by:
      containsSidedPathElement in interface INetwork
      Parameters:
      pathElement - A sided path element.
      Returns:
      If this network contains the given sided path element.
    • getFullNetworkListeners

      public IFullNetworkListener[] getFullNetworkListeners()
      Specified by:
      getFullNetworkListeners in interface INetwork
      Returns:
      All registered network listeners.
    • isValid

      protected boolean isValid(INetworkElement element)