From c2547a8b061f697d1b32e6c2980f8f0af5c888ed Mon Sep 17 00:00:00 2001 From: brachy84 Date: Mon, 16 Aug 2021 10:57:29 +0200 Subject: [PATCH] make current pos in PipeNetWalker.java mutable --- .../gregtech/api/pipenet/PipeNetWalker.java | 23 +++++++++++-------- .../fluidpipe/net/FluidNetWalker.java | 2 +- .../pipelike/itempipe/net/ItemNetWalker.java | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/gregtech/api/pipenet/PipeNetWalker.java b/src/main/java/gregtech/api/pipenet/PipeNetWalker.java index cf1a70e35d5..c10ccd19dcd 100644 --- a/src/main/java/gregtech/api/pipenet/PipeNetWalker.java +++ b/src/main/java/gregtech/api/pipenet/PipeNetWalker.java @@ -27,7 +27,7 @@ public abstract class PipeNetWalker { private final Set> walked = new HashSet<>(); private final List pipes = new ArrayList<>(); private List walkers; - private BlockPos currentPos; + private final BlockPos.MutableBlockPos currentPos; private int walkedBlocks; private boolean invalid; @@ -35,7 +35,7 @@ protected PipeNetWalker(PipeNet net, World world, BlockPos sourcePipe, int wa 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)); } /** @@ -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; } @@ -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) { @@ -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(); // 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); } } diff --git a/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidNetWalker.java b/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidNetWalker.java index 135a27af502..764b8771017 100644 --- a/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidNetWalker.java +++ b/src/main/java/gregtech/common/pipelike/fluidpipe/net/FluidNetWalker.java @@ -111,7 +111,7 @@ protected void checkNeighbour(IPipeTile pipeTile, BlockPos pipePos, EnumFa pathObjectsCopy.addAll(fluidFilter); List 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)); } } diff --git a/src/main/java/gregtech/common/pipelike/itempipe/net/ItemNetWalker.java b/src/main/java/gregtech/common/pipelike/itempipe/net/ItemNetWalker.java index 3da42144177..479c0601857 100644 --- a/src/main/java/gregtech/common/pipelike/itempipe/net/ItemNetWalker.java +++ b/src/main/java/gregtech/common/pipelike/itempipe/net/ItemNetWalker.java @@ -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