From cc2e9fe3ed489ac72ab3bc790279d4f85ab174cd Mon Sep 17 00:00:00 2001 From: Michael Gilardi <11632652+mgilardi@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:37:04 -0700 Subject: [PATCH] Let dropped items not stop healing, and add the healing bot test The first bot run found 13 of 114 blocks never came back: a step skipped any block an entity was in, including the blast's own dropped items lying in the hole. Only mobs and pets count now; the game pushes items out. test/heal.mjs then passed 19/19 on a throwaway Paper 26.3 server, with all 111 blocks back as they were. The Magic hook and claims are still untested on a server. Task: K675 Co-Authored-By: Claude Opus 5.5 --- README.md | 6 +- docs/releases/v0.4.0.md | 4 +- docs/test-audit.md | 6 +- .../extantape/rewild/heal/HealService.java | 6 +- test/heal.mjs | 148 ++++++++++++++++++ 5 files changed, 162 insertions(+), 8 deletions(-) create mode 100644 test/heal.mjs diff --git a/README.md b/README.md index f714302..f74ee23 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A Paper plugin that rewilds abandoned, mined-out land back to fresh terrain from the world's seed, and keeps every block players placed exactly where it is. Paths, builds, chests and protected places stay; the holes, quarries and craters around them fill back in. -**Status:** pre-release. 0.4.0 adds gradual healing of explosion holes and a hook for the Magic plugin; those have passed unit tests only, and haven't run on a server yet. 0.3.0 is a redesign and has passed its tests on throwaway Paper 26.3 servers with a bot as the player (see [Testing](#testing)). It hasn't run on a real server, and nobody has looked at a rewilded area in a real game client yet. +**Status:** pre-release. 0.4.0 adds gradual healing of explosion holes and a hook for the Magic plugin. Healing passed `test/heal.mjs` on a throwaway Paper 26.3 server with a bot; the Magic hook has passed unit tests only, and neither has been seen in a real game client. 0.3.0 is a redesign and has passed its tests on throwaway Paper 26.3 servers with a bot as the player (see [Testing](#testing)). It hasn't run on a real server, and nobody has looked at a rewilded area in a real game client yet. - Paper 26.1 and newer, Java 25. Not Spigot, and not 1.21.x. - Off in every world until you turn it on. Dry run by default. Worlds in `never-reset-worlds`, such as creative and lobby worlds, can never be turned on by mistake. @@ -74,7 +74,7 @@ A typical crater, 3 or 4 layers deep, takes about a week. A deeper hole fills mo A hole only heals on its own when all of this holds: the world is enabled, the land was generated after Rewild started tracking it, the blast destroyed nothing a player placed and no container, and no player's block or filled container, claim, kept area, admin-protected area, respawn point or Magic block is within 8 blocks. Any other hole waits for an admin's approved run, as before. -Healing waits while a player is within 24 blocks, while the hole's chunks aren't loaded, and while anything that would stop a reset is wrong (the claim plugin is down, say). Each step only fills air, water and blocks anything may replace, such as short grass and snow, plus the dirt or sapling an earlier step laid. It never fills a block something is in, and never replaces a block a player put there since. While `dry-run` is true, each step is only reported in the log. `/rewild healing` lists the holes healing now. +Healing waits while a player is within 24 blocks, while the hole's chunks aren't loaded, and while anything that would stop a reset is wrong (the claim plugin is down, say). Each step only fills air, water and blocks anything may replace, such as short grass and snow, plus the dirt or sapling an earlier step laid. It never fills a block a mob or pet is in, and never replaces a block a player put there since. While `dry-run` is true, each step is only reported in the log. `/rewild healing` lists the holes healing now. ### Magic @@ -163,7 +163,7 @@ If a respected provider throws, nothing in that world resets. If LanternGraves i - A below-ground repair drops mobs and items under the cut, and doesn't bring back mineshaft minecarts. - GriefPrevention is the only claim plugin supported. Animated Architecture has no hook, but its builds are made of player-placed blocks, which the tracker sees. - Undo restores a chunk as it was before the run, so anything built in it since is lost. -- Healing has passed unit tests only (0.4.0). It hasn't run on a server yet, with a bot or a player. +- The Magic hook has passed unit tests only, written against the Magic 11.3 jar's interfaces. It hasn't run against a running Magic. - If a healing sapling grows into a tree on its own before the young-tree step, that step leaves the trunk alone and adds the young tree's leaves and logs around it where there's air. - A healed hole gets back the blocks the blast destroyed. Water or lava that flowed in and set into stone or obsidian is left as it is, because it isn't air. diff --git a/docs/releases/v0.4.0.md b/docs/releases/v0.4.0.md index 3ff34ff..5c19c07 100644 --- a/docs/releases/v0.4.0.md +++ b/docs/releases/v0.4.0.md @@ -12,4 +12,6 @@ Replace the jar. New settings (`healing`, `magic`) get their defaults; add them ## Tested -Unit tests pass (103). Healing and the Magic hook haven't run on a server yet. +- Unit tests pass (103). +- `test/heal.mjs` on a throwaway Paper 26.3 server with a bot, 19 of 19: a TNT hole in fresh plains healed in 6 steps, filling from the bottom, with every one of its blocks back as it was (111 and 115 in two runs); a step waited while the bot stood near; a block set in the hole since was left alone; holes next to the bot's build and through a chest didn't heal on their own; dry run recorded and reported without placing; a healing survived a restart. +- Not yet tested: the Magic hook against a running Magic (no Magic jar in the test server), claims, and how healing looks in a real game client. diff --git a/docs/test-audit.md b/docs/test-audit.md index 941bf05..d885377 100644 --- a/docs/test-audit.md +++ b/docs/test-audit.md @@ -17,8 +17,10 @@ Offline, unit tests only: no test servers tonight (owner). 103 unit tests pass. | **A Magic world without Magic running never resets or heals**; Magic that can't answer stops resets | `MagicKeepsTest` (5 tests) | | Settings default to a week and bad values stop resets | `RegenConfigTest.healingIsOnWithAWeekAndMagicWorldsAreRead` | -Gaps, for the bot run before release (not possible tonight): -- The server side of a step: pausing near a player, waiting for unloaded chunks, not overwriting a block placed since, skipping blocks an entity is in, dry run placing nothing, claims and kept areas refusing a hole, and a blast through a chest refusing it. These need a Paper server; add them to `test/` as `heal.mjs`, with `healing.step-hours` forced through `/rewild healing step`. +Bot run, same night after the owner's go: `test/heal.mjs` on Paper 26.3, 19 of 19. It found one bug, fixed before release: a step skipped any block an entity was in, so the blast's own dropped items kept 13 of 114 blocks from coming back. Only mobs and pets count now, and the rerun brought all 111 back. + +Still open: +- Covered by `heal.mjs` now: pausing near a player, not overwriting a block placed since, dry run placing nothing, a nearby build and a blast through a chest refusing a hole, restart. Not yet: waiting for unloaded chunks, skipping a block a mob is in, claims and kept areas (the test runs with `claims: none`). - The Magic hook against a running Magic 11.3: it was written against the jar's interfaces only. Skipped: none of the pure rules; the reflection calls themselves are left to the bot run, since a mock would only test the mock. diff --git a/src/main/java/com/extantape/rewild/heal/HealService.java b/src/main/java/com/extantape/rewild/heal/HealService.java index f93b1d8..5947a7a 100644 --- a/src/main/java/com/extantape/rewild/heal/HealService.java +++ b/src/main/java/com/extantape/rewild/heal/HealService.java @@ -200,9 +200,11 @@ public String step(HealJob j, World w, long now, boolean force) { if (l.getX() >= b[0] - r && l.getX() <= b[2] + r && l.getZ() >= b[1] - r && l.getZ() <= b[3] + r) return "paused: a player is nearby"; } int placed = 0, blocked = 0; - // Never fill a block a mob, pet or dropped item is in (players are already kept well away). + // Never fill a block a mob or pet is in (players are already kept well away). Dropped items don't count: the + // game pushes them out of a block placed on them, and the blast's own drops lie in the hole. var box = new org.bukkit.util.BoundingBox(b[0], w.getMinHeight(), b[1], b[2] + 1, w.getMaxHeight(), b[3] + 1); - List occupied = w.getNearbyEntities(box).stream().map(org.bukkit.entity.Entity::getBoundingBox).toList(); + List occupied = w.getNearbyEntities(box, e -> e instanceof org.bukkit.entity.LivingEntity) + .stream().map(org.bukkit.entity.Entity::getBoundingBox).toList(); for (HealPlan.Placement p : steps.get(j.done)) { Block at = w.getBlockAt(p.x(), p.y(), p.z()); if (!replaceable(at, p.over())) { blocked++; continue; } diff --git a/test/heal.mjs b/test/heal.mjs new file mode 100644 index 0000000..861b978 --- /dev/null +++ b/test/heal.mjs @@ -0,0 +1,148 @@ +// Gradual healing (0.4.0, D224) on a live server: a TNT hole in fresh natural land heals step by step through +// /rewild healing step, waits while a player is near, never overwrites a block put there since, survives a restart, +// only reports in dry run, and refuses holes next to a player's build or through a chest. +// node heal.mjs 26.3 +import path from 'node:path' +import { readdirSync } from 'node:fs' +import { freshServer, setConfig, Server, bot, waitTop, Vec3, CACHE, REPO, sleep, check, note, report } from './harness.mjs' +import { testConfig } from './configs.mjs' + +const VERSION = process.argv[2] || '26.3' +const P = n => path.join(CACHE, 'p26', n) +const JAR = path.join(REPO, 'build/libs', readdirSync(path.join(REPO, 'build/libs')).find(f => /^Rewild-0\.4\.[\d.]+\.jar$/.test(f))) +const config = dry => testConfig({ claims: 'none', dryRun: dry }) +const dir = freshServer(VERSION, { plugins: [JAR, P('ViaVersion-5.12.2.jar'), P('ViaBackwards-5.12.2.jar')], config: config(false) }) +const s = new Server(dir) +console.log(`# Gradual healing on Paper ${VERSION}`) +await s.start() +await s.cmd('rewild plugins ignore-rest', /Ignored:|Usage|nothing/i) +let b = await bot('tester') +await s.cmd('gamemode creative tester') + +// Fresh plains far from spawn, so every chunk is generated after Rewild started (known land). +const out = await s.cmd('execute positioned 3000 0 3000 run locate biome minecraft:plains', /nearest/, 120_000) +const m = out.match(/at \[(-?\d+), [^,]+, (-?\d+)\]/) +const X = +m[1], Z = +m[2] +const away = async () => { await s.cmd(`tp tester ${X + 60} 200 ${Z}`); await sleep(1500) } +await s.cmd(`tp tester ${X} 200 ${Z}`); await sleep(4000) +await away() +const Y = (await waitTop(b, X, Z)).position.y + +const R = 5 +const blockAt = (x, y, z) => { const bl = b.blockAt(new Vec3(x, y, z)); return bl ? bl.name : '?' } +function snap(cx, cy, cz) { + const out = new Map() + for (let x = cx - R; x <= cx + R; x++) for (let z = cz - R; z <= cz + R; z++) for (let y = cy - 6; y <= cy + 3; y++) out.set(`${x},${y},${z}`, blockAt(x, y, z)) + return out +} + +async function blast(x, y, z) { + const mark = s.log.length + await s.cmd(`summon tnt ${x} ${y + 1} ${z} {fuse:1}`) + await sleep(2500) + return s.log.slice(mark) +} +async function jobs() { + const o = await s.cmd('rewild healing', /hole\(s\) healing|No explosion holes/) + // Healing ids look like h-