Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion docs/releases/v0.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 4 additions & 2 deletions docs/test-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/extantape/rewild/heal/HealService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<org.bukkit.util.BoundingBox> occupied = w.getNearbyEntities(box).stream().map(org.bukkit.entity.Entity::getBoundingBox).toList();
List<org.bukkit.util.BoundingBox> 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; }
Expand Down
148 changes: 148 additions & 0 deletions test/heal.mjs
Original file line number Diff line number Diff line change
@@ -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<date>-<time>-<hex>.
return [...new Set(o.split(/\s+/).map(w => w.replace(/\.$/, '')).filter(w => w.startsWith('h2') && w.split('-').length === 3))]
}

// 1. A hole in natural land, nothing near, is recorded to heal on its own.
const before = snap(X, Y, Z)
const log1 = await blast(X, Y, Z)
const after = snap(X, Y, Z)
const destroyed = [...before].filter(([k, v]) => v !== 'air' && after.get(k) === 'air').map(([k]) => k)
check('TNT made a hole', destroyed.length > 20, `${destroyed.length} blocks`)
check('a hole in natural land with nothing near is set to heal on its own', /will heal over about 7 days/.test(log1), log1.split('\n').find(l => /heal/.test(l)))
const [id] = await jobs()
check('/rewild healing lists it', !!id)

// 2. A player nearby pauses it.
await s.cmd(`tp tester ${X + 3} ${Y + 2} ${Z}`); await sleep(1500)
const paused = await s.cmd(`rewild healing step ${id}`, /paused|Healed|waiting/)
check('a step waits while a player is nearby', /paused: a player is nearby/.test(paused))
check('and places nothing', destroyed.every(k => blockAt(...k.split(',').map(Number)) === 'air'))
await away()

// 3. Something put in the hole since is never overwritten.
const lowest = destroyed.map(k => k.split(',').map(Number)).sort((a, b) => a[1] - b[1])[0]
await s.cmd(`setblock ${lowest[0]} ${lowest[1]} ${lowest[2]} minecraft:diamond_block`)
await sleep(500)

// 4. Step through to the end.
let steps = 0, finished = false, first = ''
const layers = []
for (let i = 0; i < 12 && !finished; i++) {
const o = await s.cmd(`rewild healing step ${id}`, /Healed step|finished|waiting|paused/)
if (/waiting|paused/.test(o)) { check('steps run when nobody is near', false, o.split('\n').find(l => /waiting|paused/.test(l))); break }
steps++
if (i === 0) first = o
await sleep(800)
layers.push(destroyed.filter(k => blockAt(...k.split(',').map(Number)) !== 'air').length)
finished = /is finished/.test(o)
}
check('a typical crater heals in about a week of daily steps', finished && steps >= 4 && steps <= 7, `${steps} steps`)
check('it fills gradually, step by step', layers.every((n, i) => i === 0 || n >= layers[i - 1]) && layers[0] < destroyed.length, layers.join(' → '))
check('the first step fills the bottom first', destroyed.filter(k => blockAt(...k.split(',').map(Number)) !== 'air').length > 0)
check('a block put there since stays', blockAt(...lowest) === 'diamond_block' && /left alone because something is there now/.test(first))
const healed = snap(X, Y, Z)
const wrong = destroyed.filter(k => k !== lowest.join(',') && healed.get(k) !== before.get(k))
check('every destroyed block comes back as it was (allowing 5%)', wrong.length <= destroyed.length * 0.05,
`${wrong.length} of ${destroyed.length} differ: ` + wrong.slice(0, 5).map(k => `${k} ${before.get(k)}→${healed.get(k)}`).join(', '))
check('the finished healing is gone from the list', !(await jobs()).includes(id))

// 5. A player's build nearby: the hole waits for an admin.
const X2 = X + 30
await s.cmd(`tp tester ${X2} ${Y + 3} ${Z}`); await sleep(1500)
const Y2 = (await waitTop(b, X2, Z)).position.y
const built = await (async () => {
await s.cmd(`give tester minecraft:oak_planks 4`); await sleep(500)
const ref = b.blockAt(new Vec3(X2 + 4, Y2, Z))
await b.equip(b.inventory.items().find(i => i.name === 'oak_planks'), 'hand')
await b.lookAt(ref.position.offset(0.5, 1, 0.5))
try { await b.placeBlock(ref, new Vec3(0, 1, 0)) } catch { }
await sleep(800)
return blockAt(X2 + 4, Y2 + 1, Z) === 'oak_planks'
})()
check('the bot placed a block next to the next blast', built)
await away()
const n0 = (await jobs()).length
await blast(X2, Y2, Z)
check('a hole next to a player\'s build doesn\'t heal on its own', (await jobs()).length === n0)

// 6. A blast through a chest: the hole waits for an admin.
const X3 = X - 30
const Y3 = (await waitTop(b, X3, Z)).position.y
await s.cmd(`setblock ${X3 + 1} ${Y3 + 1} ${Z} minecraft:chest`)
await blast(X3, Y3, Z)
check('a hole that destroyed a chest doesn\'t heal on its own', (await jobs()).length === n0)

// 7. Dry run: recorded, stepped in the log only, nothing placed; and a job survives a restart.
setConfig(dir, config(true))
await s.cmd('rewild reload', /Config reloaded/)
const X4 = X, Z4 = Z + 30
const Y4 = (await waitTop(b, X4, Z4)).position.y
const before4 = snap(X4, Y4, Z4)
await blast(X4, Y4, Z4)
const after4 = snap(X4, Y4, Z4)
const holes4 = [...before4].filter(([k, v]) => v !== 'air' && after4.get(k) === 'air').map(([k]) => k)
const [id4] = (await jobs()).filter(j => j !== id)
check('dry run still records a hole', !!id4)
await s.stop()
await s.start()
await sleep(1000)
check('healing survives a restart', (await jobs()).includes(id4))
b = await bot('tester')
await s.cmd(`tp tester ${X4 + 60} 200 ${Z4}`); await sleep(4000)
const o4 = await s.cmd(`rewild healing step ${id4}`, /Dry run: would heal|waiting|paused/)
check('a dry-run step only reports', /Dry run: would heal step 1/.test(o4))
await sleep(800)
check('and places nothing', holes4.every(k => blockAt(...k.split(',').map(Number)) === 'air'), `${holes4.length} hole blocks`)

const errors = s.log.split('\n').filter(l => /ERROR|Exception/.test(l) && !/Via/.test(l))
check('no errors in the log', errors.length === 0, errors.slice(0, 3).join(' | '))
note('not covered here', 'Magic plugin hook (no Magic jar in the test server), claims (claims: none), real client look')
b.quit()
await s.stop()
process.exit(report(path.join(dir, 'heal-results.json')) ? 1 : 0)
Loading