Skip to content

Commit 7064bf2

Browse files
authored
Fix #47: Attractors extracting from the wrong side of the source block. (#48)
1 parent 1399016 commit 7064bf2

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/main/java/dev/technici4n/moderndynamics/network/item/ItemHost.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void tickAttachments() {
221221
long toTransfer = maxTransfer;
222222

223223
for (var path : paths) {
224-
var extractTarget = ItemStorage.SIDED.find(pipe.getLevel(), path.targetPos, path.path[path.path.length - 1]);
224+
var extractTarget = ItemStorage.SIDED.find(pipe.getLevel(), path.targetPos, path.getTargetBlockSide());
225225
if (extractTarget != null) {
226226
// Make sure to check the filter at the endpoint.
227227
var endpointFilter = path.getEndFilter(cache.level);

src/main/java/dev/technici4n/moderndynamics/network/item/ItemPath.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)