Skip to content

Commit

Permalink
make current pos in PipeNetWalker.java mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Aug 16, 2021
1 parent 073b651 commit c2547a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/main/java/gregtech/api/pipenet/PipeNetWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public abstract class PipeNetWalker {
private final Set<IPipeTile<?, ?>> walked = new HashSet<>();
private final List<EnumFacing> pipes = new ArrayList<>();
private List<PipeNetWalker> walkers;
private BlockPos currentPos;
private final BlockPos.MutableBlockPos currentPos;
private int walkedBlocks;
private boolean invalid;

protected PipeNetWalker(PipeNet<?> net, World world, BlockPos sourcePipe, int walkedBlocks) {
this.world = Objects.requireNonNull(world);
this.net = Objects.requireNonNull(net);
this.walkedBlocks = walkedBlocks;
this.currentPos = Objects.requireNonNull(sourcePipe);
this.currentPos = new BlockPos.MutableBlockPos(Objects.requireNonNull(sourcePipe));
}

/**
Expand Down Expand Up @@ -100,12 +100,12 @@ public void traversePipeNet(int maxWalks) {

private boolean walk() {
if (walkers == null)
checkPos(currentPos);
checkPos();

if (pipes.size() == 0)
return true;
if (pipes.size() == 1) {
currentPos = currentPos.offset(pipes.get(0));
currentPos.move(pipes.get(0));
walkedBlocks++;
return false;
}
Expand All @@ -129,9 +129,9 @@ private boolean walk() {
return walkers.size() == 0;
}

private void checkPos(BlockPos pos) {
private void checkPos() {
pipes.clear();
TileEntity thisPipe = world.getTileEntity(pos);
TileEntity thisPipe = world.getTileEntity(currentPos);
IPipeTile<?, ?> pipeTile = (IPipeTile<?, ?>) thisPipe;
if (pipeTile == null) {
if (walkedBlocks == 1) {
Expand All @@ -141,27 +141,30 @@ private void checkPos(BlockPos pos) {
} else
throw new IllegalStateException("PipeTile was not null last walk, but now is");
}
checkPipe(pipeTile, pos);
checkPipe(pipeTile, currentPos);
pipeTile.markWalked();
walked.add(pipeTile);

BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain();

This comment has been minimized.

Copy link
@PrototypeTrousers

PrototypeTrousers Aug 16, 2021

Contributor

is this missing a release() call after the loop or is this intended ?

This comment has been minimized.

Copy link
@brachy84

brachy84 Aug 16, 2021

Author Contributor

I forgor

// check for surrounding pipes and item handlers
for (EnumFacing accessSide : EnumFacing.VALUES) {
//skip sides reported as blocked by pipe network
if (!pipeTile.isConnectionOpenAny(accessSide))
continue;

TileEntity tile = world.getTileEntity(pos.offset(accessSide));
pos.setPos(currentPos);
pos.move(accessSide);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof IPipeTile) {
IPipeTile<?, ?> otherPipe = (IPipeTile<?, ?>) tile;
if (otherPipe.isWalked())
continue;
if (isValidPipe(pipeTile, otherPipe, pos, accessSide)) {
if (isValidPipe(pipeTile, otherPipe, currentPos, accessSide)) {
pipes.add(accessSide);
continue;
}
}
checkNeighbour(pipeTile, pos, accessSide, tile);
checkNeighbour(pipeTile, currentPos, accessSide, tile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected void checkNeighbour(IPipeTile<?, ?> pipeTile, BlockPos pipePos, EnumFa
pathObjectsCopy.addAll(fluidFilter);
List<TileEntityFluidPipe> holders = new ArrayList<>(holdingPipes);
holders.add((TileEntityFluidPipe) pipeTile);
inventories.add(new FluidPipeNet.Inventory(pipePos, faceToNeighbour, getWalkedBlocks(), pathObjectsCopy, rate, holders));
inventories.add(new FluidPipeNet.Inventory(new BlockPos(pipePos), faceToNeighbour, getWalkedBlocks(), pathObjectsCopy, rate, holders));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void checkNeighbour(IPipeTile<?, ?> pipeTile, BlockPos pipePos, EnumFa
if (neighbourTile == null) return;
IItemHandler handler = neighbourTile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, faceToNeighbour.getOpposite());
if (handler != null)
inventories.add(new ItemPipeNet.Inventory(pipePos, faceToNeighbour, getWalkedBlocks(), minProperties));
inventories.add(new ItemPipeNet.Inventory(new BlockPos(pipePos), faceToNeighbour, getWalkedBlocks(), minProperties));
}

@Override
Expand Down

0 comments on commit c2547a8

Please sign in to comment.