From 77709fb41efedacaac82cbdbbd0da9be379d4d3a Mon Sep 17 00:00:00 2001 From: XxFran10xX <318299142+XxFran10xX@users.noreply.github.com> Date: Fri, 30 Oct 2026 11:39:07 +0100 Subject: [PATCH] perf: look only at pedestals when finding a meditation circle Every tick, each player sitting anywhere (chairs, horses, boats) checks for a circle around the seat. The check now keeps only the uncarried pedestals from the nearby chunks, and stops when there are fewer of them than the ring has posts, since each post needs a pedestal of its own. The posts are matched exactly as before, so a circle forms and meditation starts on the same tick, with the same messages. Co-Authored-By: Claude Opus 5.5 --- .../magic/meditation/MeditationCircle.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/tfminecraft/magic/meditation/MeditationCircle.java b/src/main/java/net/tfminecraft/magic/meditation/MeditationCircle.java index 3984371..9be9289 100644 --- a/src/main/java/net/tfminecraft/magic/meditation/MeditationCircle.java +++ b/src/main/java/net/tfminecraft/magic/meditation/MeditationCircle.java @@ -351,7 +351,11 @@ public static MeditationCircle detect(Location sitLocation) { World world = sitLocation.getWorld(); int[][] offsets = ringOffsets(); - List candidates = collectNearby(world, cx, cz); + List candidates = nearbyPedestals(world, cx, cz); + // Every post takes a pedestal of its own, so fewer pedestals than posts never make a ring. + if (candidates.size() < offsets.length) { + return null; + } List matched = new ArrayList<>(); for (int[] offset : offsets) { Furniture found = matchAt(candidates, cx + offset[0], cy, cz + offset[1], matched); @@ -391,10 +395,7 @@ private static Furniture matchAt( Furniture best = null; double bestDist = 0.75; for (Furniture furniture : candidates) { - if (already.contains(furniture) || furniture.isCarried()) { - continue; - } - if (!MeditationCache.pedestalId.equalsIgnoreCase(furniture.getId())) { + if (already.contains(furniture)) { continue; } Location anchor = furniture.getOriginBlockLocation().orElse(furniture.getLoc()); @@ -415,7 +416,8 @@ private static Furniture matchAt( return best; } - private static List collectNearby(World world, int cx, int cz) { + /** The pedestals, not carried, in the sit's chunk and the eight around it. */ + private static List nearbyPedestals(World world, int cx, int cz) { List out = new ArrayList<>(); InteractibleFurniture plugin = InteractibleFurniture.getInstance(); int chunkX = cx >> 4; @@ -426,7 +428,11 @@ private static List collectNearby(World world, int cx, int cz) { continue; // an unloaded chunk holds no live furniture; never load one here } Chunk chunk = world.getChunkAt(chunkX + dx, chunkZ + dz); - out.addAll(plugin.getFurnitureManager().getFurnitureInChunk(chunk)); + for (Furniture furniture : plugin.getFurnitureManager().getFurnitureInChunk(chunk)) { + if (!furniture.isCarried() && MeditationCache.pedestalId.equalsIgnoreCase(furniture.getId())) { + out.add(furniture); + } + } } } return out;