Class Network
java.lang.Object
org.cyclops.integrateddynamics.core.network.Network
- All Implemented Interfaces:
org.cyclops.cyclopscore.persist.nbt.INBTSerializable
,IFullNetworkListener
,INetwork
A network instance that can hold a set of
INetworkElement
s.
Note that this network only contains references to the relevant data, it does not contain the actual information.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cyclops.cyclopscore.persist.nbt.INBTSerializable
org.cyclops.cyclopscore.persist.nbt.INBTSerializable.SelfNBTClassType
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addNetworkElement
(INetworkElement element, boolean networkPreinit) Add a given network element to the network Also checks if it can tick and will handle it accordingly.void
Add a given network element to the tickable elements set.void
Called when the server loaded this network.static boolean
areNetworksEqual
(Network networkA, Network networkB) Check if two networks are equal.void
Called when the server will save this network before stopping.boolean
canUpdate
(INetworkElement element) If the given element can update.boolean
containsSidedPathElement
(ISidedPathElement pathElement) boolean
void
fromNBT
(net.minecraft.nbt.CompoundTag tag) void
fromNBTEffective
(net.minecraft.nbt.CompoundTag tag) protected net.minecraftforge.common.capabilities.CapabilityDispatcher
protected IFullNetworkListener[]
int
<T> net.minecraftforge.common.util.LazyOptional<T>
getCapability
(net.minecraftforge.common.capabilities.Capability<T> capability) Get the given capability.long
getLastSecondDuration
(INetworkElement networkElement) Get the last tick duration of the given network element.boolean
void
Initialize the network element data.protected void
initialize
(boolean silent) Called when a network is server-loaded or newly created.static Network
initiateNetworkSetup
(ISidedPathElement sidedPathElement) Initiate a full network from the given start position.void
invalidateElement
(INetworkElement element) Invalidate the given element.boolean
boolean
boolean
isKilled()
protected boolean
isValid
(INetworkElement element) void
kill()
Terminate the network elements for this network.boolean
Kills the network is it had no more network elements.protected void
protected void
void
onSkipUpdate
(INetworkElement element) When the given element is not being updated becauseIFullNetworkListener.canUpdate(INetworkElement)
returned false.protected void
onUpdate()
void
postUpdate
(INetworkElement element) Called after a network element's update was called.void
removeNetworkElementPost
(INetworkElement element) Remove a given network element from the network.boolean
removeNetworkElementPre
(INetworkElement element) Checks if the given network element can be removed from the networkvoid
Remove given network element from the tickable elements set.boolean
removePathElement
(IPathElement pathElement, net.minecraft.core.Direction side) Remove the given path element from the network.void
Reset the last second duration counts.void
revalidateElement
(INetworkElement element) Revalidate the given element.void
setCrashed
(boolean crashed) void
setPriorityAndChannel
(INetworkElement element, int priority, int channel) Set the priority and channel of the given network element.net.minecraft.nbt.CompoundTag
toNBT()
final void
update()
This network updating should be called each tick.void
This guaranteed network updating should be called each tick, even in safe-mode.
-
Constructor Details
-
Network
public Network()This constructor should not be called, except for the process of constructing networks from NBT. -
Network
Create a new network from a given cluster of path elements. Each path element will be checked if it has aINetworkElementProvider
capability at its position and will add all its elements to the network in that case. Each path element that has anIPartContainer
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
Initiate a full network from the given start position.- Parameters:
sidedPathElement
- The sided path element to start from.- Returns:
- The newly formed network.
-
areNetworksEqual
Check if two networks are equal.- Parameters:
networkA
- A network.networkB
- Another network.- Returns:
- If they are equal.
-
gatherCapabilities
protected net.minecraftforge.common.capabilities.CapabilityDispatcher gatherCapabilities() -
gatherFullNetworkListeners
-
onConstruct
protected void onConstruct() -
isInitialized
public boolean isInitialized()- Specified by:
isInitialized
in interfaceINetwork
- Returns:
- If this network and its elements have been fully initialized.
-
getEventBus
- Specified by:
getEventBus
in interfaceINetwork
- Returns:
- The event bus for this network.
-
initialize
public void initialize()Initialize the network element data. -
equals
-
toNBT
public net.minecraft.nbt.CompoundTag toNBT()- Specified by:
toNBT
in interfaceorg.cyclops.cyclopscore.persist.nbt.INBTSerializable
-
fromNBT
public void fromNBT(net.minecraft.nbt.CompoundTag tag) - Specified by:
fromNBT
in interfaceorg.cyclops.cyclopscore.persist.nbt.INBTSerializable
-
fromNBTEffective
public void fromNBTEffective(net.minecraft.nbt.CompoundTag tag) -
addNetworkElement
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 interfaceIFullNetworkListener
- Parameters:
element
- The network element.networkPreinit
- If the network is still in the process of being initialized.- Returns:
- If the addition succeeded.
-
addNetworkElementUpdateable
Description copied from interface:INetwork
Add a given network element to the tickable elements set.- Specified by:
addNetworkElementUpdateable
in interfaceINetwork
- Parameters:
element
- The network element.
-
removeNetworkElementPre
Description copied from interface:IFullNetworkListener
Checks if the given network element can be removed from the network- Specified by:
removeNetworkElementPre
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.- Returns:
- If the element was can be removed from the network.
-
setPriorityAndChannel
Description copied from interface:INetwork
Set the priority and channel of the given network element.- Specified by:
setPriorityAndChannel
in interfaceINetwork
- Parameters:
element
- The network element.priority
- The new prioritychannel
- The new channel
-
removeNetworkElementPost
Description copied from interface:IFullNetworkListener
Remove a given network element from the network. Also removed its tickable instance.- Specified by:
removeNetworkElementPost
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.
-
removeNetworkElementUpdateable
Description copied from interface:INetwork
Remove given network element from the tickable elements set.- Specified by:
removeNetworkElementUpdateable
in interfaceINetwork
- 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 interfaceIFullNetworkListener
-
killIfEmpty
public boolean killIfEmpty()Description copied from interface:INetwork
Kills the network is it had no more network elements.- Specified by:
killIfEmpty
in interfaceINetwork
- Returns:
- If the network was killed.
-
canUpdate
Description copied from interface:IFullNetworkListener
If the given element can update.- Specified by:
canUpdate
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.- Returns:
- If it can update.
-
postUpdate
Description copied from interface:IFullNetworkListener
Called after a network element's update was called.- Specified by:
postUpdate
in interfaceIFullNetworkListener
- Parameters:
element
- The network element.
-
onSkipUpdate
Description copied from interface:IFullNetworkListener
When the given element is not being updated becauseIFullNetworkListener.canUpdate(INetworkElement)
returned false.- Specified by:
onSkipUpdate
in interfaceIFullNetworkListener
- 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 interfaceIFullNetworkListener
-
update
public final void update()Description copied from interface:IFullNetworkListener
This network updating should be called each tick.- Specified by:
update
in interfaceIFullNetworkListener
-
onUpdate
protected void onUpdate() -
removePathElement
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 interfaceIFullNetworkListener
- 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 interfaceIFullNetworkListener
-
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 interfaceIFullNetworkListener
-
getElements
- Specified by:
getElements
in interfaceINetwork
- Returns:
- The network elements.
-
isKilled
public boolean isKilled() -
onNetworkChanged
protected void onNetworkChanged() -
hasChanged
public boolean hasChanged()- Specified by:
hasChanged
in interfaceINetwork
- Returns:
- If the network has changed structure or elements in the last tick.
-
getCablesCount
public int getCablesCount()- Specified by:
getCablesCount
in interfaceINetwork
- Returns:
- The number of cables in the network.
-
getLastSecondDuration
Description copied from interface:INetwork
Get the last tick duration of the given network element.- Specified by:
getLastSecondDuration
in interfaceINetwork
- 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 interfaceINetwork
-
isCrashed
public boolean isCrashed() -
setCrashed
public void setCrashed(boolean crashed) - Specified by:
setCrashed
in interfaceINetwork
- Parameters:
crashed
- The new crashed field.
-
getCapability
public <T> net.minecraftforge.common.util.LazyOptional<T> getCapability(net.minecraftforge.common.capabilities.Capability<T> capability) Description copied from interface:INetwork
Get the given capability.- Specified by:
getCapability
in interfaceINetwork
- Type Parameters:
T
- The capability type.- Parameters:
capability
- The capability to get.- Returns:
- The optional capability instance.
-
invalidateElement
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 interfaceIFullNetworkListener
- Specified by:
invalidateElement
in interfaceINetwork
- Parameters:
element
- The network element to invalidate.
-
revalidateElement
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 interfaceIFullNetworkListener
- Specified by:
revalidateElement
in interfaceINetwork
- Parameters:
element
- The network element to invalidate.
-
containsSidedPathElement
- Specified by:
containsSidedPathElement
in interfaceINetwork
- Parameters:
pathElement
- A sided path element.- Returns:
- If this network contains the given sided path element.
-
getFullNetworkListeners
- Specified by:
getFullNetworkListeners
in interfaceINetwork
- Returns:
- All registered network listeners.
-
isValid
-