@@ -36,6 +36,9 @@ public class ItemPath {
3636 */
3737 public final BlockPos startingPos ;
3838 public final BlockPos targetPos ;
39+ /**
40+ * Contains the direction to turn for each path-element, to get from startingPos up until, but excluding targetPos.
41+ */
3942 public final Direction [] path ;
4043 private @ Nullable ItemPath reversed ;
4144
@@ -55,7 +58,22 @@ public NetworkNode<ItemHost, ItemCache> getStartingPoint(ServerLevel level) {
5558 }
5659
5760 public SimulatedInsertionTarget getInsertionTarget (Level world ) {
58- return SimulatedInsertionTargets .getTarget (world , targetPos , path [path .length - 1 ].getOpposite ());
61+ return SimulatedInsertionTargets .getTarget (world , targetPos , getTargetBlockSide ());
62+ }
63+
64+ /**
65+ * @return The last direction in this path, which corresponds with the side of the block opposite
66+ * of {@link #getTargetBlockSide()}.
67+ */
68+ public Direction getLastDirection () {
69+ return path [path .length - 1 ];
70+ }
71+
72+ /**
73+ * @return The side of the block at {@link #targetPos} this path navigates to.
74+ */
75+ public Direction getTargetBlockSide () {
76+ return getLastDirection ().getOpposite ();
5977 }
6078
6179 public TravelingItem makeTravelingItem (ItemVariant variant , long amount , double speedMultiplier ) {
@@ -70,18 +88,18 @@ public TravelingItem makeTravelingItem(ItemVariant variant, long amount, double
7088
7189 @ Nullable
7290 AttachedAttachment getEndAttachment (ServerLevel level ) {
73- var lastNode = ItemHost .MANAGER .findNode (level , targetPos .relative (path [ path . length - 1 ]. getOpposite ()));
91+ var lastNode = ItemHost .MANAGER .findNode (level , targetPos .relative (getTargetBlockSide ()));
7492 var host = lastNode .getHost ();
75- return host .getAttachment (path [ path . length - 1 ] );
93+ return host .getAttachment (getLastDirection () );
7694 }
7795
7896 /**
7997 * Return the predicate for the attachment at the very end of the pipe.
8098 */
8199 Predicate <ItemVariant > getEndFilter (ServerLevel level ) {
82- var endPipe = targetPos .relative (path [ path . length - 1 ]. getOpposite ());
100+ var endPipe = targetPos .relative (getTargetBlockSide ());
83101 if (level .getBlockEntity (endPipe ) instanceof PipeBlockEntity pipe ) {
84- if (pipe .getAttachment (path [ path . length - 1 ] ) instanceof ItemAttachedIo io ) {
102+ if (pipe .getAttachment (getLastDirection () ) instanceof ItemAttachedIo io ) {
85103 if (!io .isEnabledViaRedstone (pipe )) {
86104 return v -> false ;
87105 }
0 commit comments