Skip to content

Commit

Permalink
Use LinkedHashSet for Breadth First Search.
Browse files Browse the repository at this point in the history
When using a spray can that runs out partway through, we want
to paint the nearest blocks, rather than a random selection of
discovered blocks.
  • Loading branch information
tomprince committed Jan 6, 2025
1 parent 4f4cb8b commit 6ad554e
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BreadthFirstBlockSearch {

public static Set<BlockPos> search(Predicate<BlockPos> value, BlockPos start, int limit) {
Set<BlockPos> alreadyVisited = new HashSet<>();
Set<BlockPos> valid = new HashSet<>();
Set<BlockPos> valid = new LinkedHashSet<>();
int iteration = 0;

Queue<BlockPos> queue = new ArrayDeque<>();
Expand Down Expand Up @@ -58,7 +58,7 @@ public static <T extends BlockEntity> Set<T> conditionalBlockEntitySearch(Class<
var level = start.getLevel();
if (level == null) return Set.of();

var passed = new HashSet<T>();
var passed = new LinkedHashSet<T>();
var queue = new ObjectArrayFIFOQueue<Triple<T, T, Direction>>(16);
queue.enqueue(new ImmutableTriple<>(null, start, null));

Expand Down Expand Up @@ -87,7 +87,7 @@ public static <T extends BlockEntity> Set<T> conditionalBlockEntitySearch(Class<

public static Set<BlockPos> conditionalBlockPosSearch(BlockPos start, BiPredicate<BlockPos, BlockPos> condition,
int blockLimit, int iterationLimit) {
var passed = new HashSet<BlockPos>();
var passed = new LinkedHashSet<BlockPos>();
var queue = new ObjectArrayFIFOQueue<Tuple<BlockPos, BlockPos>>(16);
queue.enqueue(new Tuple<>(null, start));

Expand Down

0 comments on commit 6ad554e

Please sign in to comment.