Class MNode
java.lang.Object
com.minecolonies.core.entity.pathfinding.MNode
- All Implemented Interfaces:
Comparable<MNode>
Nodes used in pathfinding.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMNode(@Nullable MNode parent, @org.jetbrains.annotations.NotNull int posX, int posY, int posZ, double cost, double heuristic) Create a Node that inherits from a parent, and has a Cost and Heuristic estimate.MNode(net.minecraft.network.RegistryFriendlyByteBuf byteBuf) Create an MNode from a bytebuf. -
Method Summary
Modifier and TypeMethodDescriptionintstatic intcomputeNodeKey(int x, int y, int z) Generate a pseudo-unique key for identifying a given node by it's coordinates Encodes the lowest 12 bits of x,z and all useful bits of y.booleandoublegetCost()Getter of the cost of the node.intGet the added indexintGetter of the added counter.doubleGetter of the heuristic.doublegetScore()Getter of the score of the node.intGet the visited countinthashCode()voidSets the node as closed.booleanWhether the node is reached by a workerbooleanisLadder()Checks if node is on a ladder.booleanCheck if is on rails.booleanWhether the node is reached by a workerbooleanChecks if node is in water.booleanChecks if node is closed.voidserializeToBuf(net.minecraft.network.RegistryFriendlyByteBuf byteBuf) Serialize the Node to buf.voidsetCornerNode(boolean isCornerNode) Marks the node as reached by the workervoidsetCost(double cost) Sets the node cost.voidsetCounterAdded(int counterAdded) Sets the added counter.voidsetHeuristic(double heuristic) Sets the node heuristic.voidSets the node as a ladder node.voidsetOnRails(boolean isOnRails) Setup rails params.voidsetReachedByWorker(boolean reached) Marks the node as reached by the workervoidSets the node as a swimming node.toString()
-
Field Details
-
x
@NotNull public final @org.jetbrains.annotations.NotNull int xThe position of the node. -
y
public final int y -
z
public final int z -
parent
The parent of the node (Node preceding this node).
-
-
Constructor Details
-
MNode
public MNode(@Nullable @Nullable MNode parent, @NotNull @org.jetbrains.annotations.NotNull int posX, int posY, int posZ, double cost, double heuristic) Create a Node that inherits from a parent, and has a Cost and Heuristic estimate.- Parameters:
parent- parent node arrives from.cost- node cost.heuristic- heuristic estimate.
-
MNode
public MNode(net.minecraft.network.RegistryFriendlyByteBuf byteBuf) Create an MNode from a bytebuf.- Parameters:
byteBuf- the buffer to load it from.
-
-
Method Details
-
serializeToBuf
public void serializeToBuf(net.minecraft.network.RegistryFriendlyByteBuf byteBuf) Serialize the Node to buf.- Parameters:
byteBuf-
-
compareTo
- Specified by:
compareToin interfaceComparable<MNode>
-
hashCode
public int hashCode() -
equals
-
isVisited
public boolean isVisited()Checks if node is closed.- Returns:
- true if so.
-
getVisitedCount
public int getVisitedCount()Get the visited count- Returns:
-
isLadder
public boolean isLadder()Checks if node is on a ladder.- Returns:
- true if so.
-
isSwimming
public boolean isSwimming()Checks if node is in water.- Returns:
- true if so.
-
increaseVisited
public void increaseVisited()Sets the node as closed. -
getScore
public double getScore()Getter of the score of the node.- Returns:
- the score.
-
getCost
public double getCost()Getter of the cost of the node.- Returns:
- the cost.
-
setCost
public void setCost(double cost) Sets the node cost.- Parameters:
cost- the cost.
-
setLadder
public void setLadder()Sets the node as a ladder node. -
setSwimming
public void setSwimming()Sets the node as a swimming node. -
getHeuristic
public double getHeuristic()Getter of the heuristic.- Returns:
- the heuristic.
-
setHeuristic
public void setHeuristic(double heuristic) Sets the node heuristic.- Parameters:
heuristic- the heuristic.
-
getDebugAddedIndex
public int getDebugAddedIndex()Getter of the added counter.- Returns:
- the amount.
-
setCounterAdded
public void setCounterAdded(int counterAdded) Sets the added counter.- Parameters:
counterAdded- amount to set.
-
setOnRails
public void setOnRails(boolean isOnRails) Setup rails params.- Parameters:
isOnRails- if on rails.
-
isOnRails
public boolean isOnRails()Check if is on rails.- Returns:
- true if so.
-
setReachedByWorker
public void setReachedByWorker(boolean reached) Marks the node as reached by the worker- Parameters:
reached- if reached or reset.
-
isReachedByWorker
public boolean isReachedByWorker()Whether the node is reached by a worker- Returns:
- reached
-
setCornerNode
public void setCornerNode(boolean isCornerNode) Marks the node as reached by the worker -
isCornerNode
public boolean isCornerNode()Whether the node is reached by a worker- Returns:
- reached
-
getCounterAdded
public int getCounterAdded()Get the added index- Returns:
-
computeNodeKey
public static int computeNodeKey(int x, int y, int z) Generate a pseudo-unique key for identifying a given node by it's coordinates Encodes the lowest 12 bits of x,z and all useful bits of y. This creates unique keys for all blocks within a 4096x256x4096 cube, which is FAR bigger volume than one should attempt to pathfind within- Returns:
- key for node in map
-
toString
-