Shelled snappers that swim under the sand of the deserts, the badlands and the far beaches at night. All you see is a hump and two eyes on stalks coming your way, then one bursts out, snaps its claws at you and digs back down. Swords glance off one that's under the sand, but a shovel digs it right out. Beat one and it leaves its shell, which a Moon bell takes. A torch, lantern or campfire keeps them off. None on a Peaceful world, and fewer on a Gentle one.
| 1 | --!strict |
| 2 | -- Sandsnappers' own tests: `potluck-server --test=sandsnappers`. |
| 3 | local test = require("@potluck/test@0.9") |
| 4 | local world = require("@potluck/world@0.30") |
| 5 | |
| 6 | local function snappers(): { number } |
| 7 | local out = {} |
| 8 | for _, k in { "Sandsnapper", "Sandsnapper (buried)" } do |
| 9 | for _, id in world.creatures(test.kind(k)) do |
| 10 | table.insert(out, id) |
| 11 | end |
| 12 | end |
| 13 | return out |
| 14 | end |
| 15 | |
| 16 | local function find(lands: { [string]: boolean }): vector |
| 17 | local g = world.spot("green") |
| 18 | for r = 400, 4000, 150 do |
| 19 | for i = 0, 31 do |
| 20 | local a = i / 32 * 2 * math.pi |
| 21 | local at = vector.create(math.floor(g.x + math.cos(a) * r) + 0.5, 0, math.floor(g.z + math.sin(a) * r) + 0.5) |
| 22 | if lands[world.biome(at)] then |
| 23 | return at |
| 24 | end |
| 25 | end |
| 26 | end |
| 27 | error("no such land near the island") |
| 28 | end |
| 29 | |
| 30 | -- a player in survival on a patch of sand in the desert, in the open |
| 31 | local function on_the_sand(p): vector |
| 32 | local at = find({ desert = true }) |
| 33 | test.move(p, vector.create(at.x, world.top(at.x, at.z) + 1, at.z)) |
| 34 | local y = world.top(at.x, at.z) |
| 35 | for dx = -16, 16 do |
| 36 | for dz = -16, 16 do |
| 37 | local c = vector.create(at.x + dx, y, at.z + dz) |
| 38 | world.set_block(c, "Sand") |
| 39 | for dy = 1, 4 do |
| 40 | world.set_block(c + vector.create(0, dy, 0), "Air") |
| 41 | end |
| 42 | end |
| 43 | test.wait(0) |
| 44 | end |
| 45 | local there = vector.create(at.x, y + 1.02, at.z) |
| 46 | test.move(p, there) |
| 47 | return there |
| 48 | end |
| 49 | |
| 50 | test.case("at night they come under the sand, burst out and snap", function() |
| 51 | test.danger("normal") |
| 52 | test.daytime(0) |
| 53 | local p = test.player("Ada", { survival = true }) |
| 54 | on_the_sand(p) |
| 55 | test.wait(14) |
| 56 | test.check(#snappers() >= 1, "sandsnappers came") |
| 57 | test.wait(30) |
| 58 | test.check(test.health(p) < 20, "and one snapped") |
| 59 | test.daytime(0.4) |
| 60 | test.wait(4) |
| 61 | test.same(#snappers(), 0, "gone by day") |
| 62 | end) |
| 63 | |
| 64 | test.case("none on Peaceful, and none on the island's grass", function() |
| 65 | test.danger("peaceful") |
| 66 | test.daytime(0) |
| 67 | local p = test.player("Ada", { survival = true }) |
| 68 | on_the_sand(p) |
| 69 | test.wait(12) |
| 70 | test.same(#snappers(), 0, "none on Peaceful") |
| 71 | test.danger("hard") |
| 72 | local g = world.spot("green") |
| 73 | test.move(p, vector.create(g.x + 40, world.top(g.x + 40, g.z) + 1, g.z)) |
| 74 | test.wait(12) |
| 75 | test.same(#snappers(), 0, "none on the grass") |
| 76 | end) |
| 77 | |
| 78 | test.case("blows glance off one under the sand, but a shovel digs it out", function() |
| 79 | test.danger("normal") |
| 80 | test.daytime(0) |
| 81 | local p = test.player("Ada", { survival = true, carrying = { ["Stone shovel"] = 1, ["Stone sword"] = 1 } }) |
| 82 | local at = on_the_sand(p) |
| 83 | local id = world.spawn(test.kind("Sandsnapper (buried)"), at + vector.create(7, 0, 0)) |
| 84 | test.wait(0.2) |
| 85 | test.hold(p, "Stone sword") |
| 86 | test.hit(p, test.creature(id)) |
| 87 | test.same(test.creature(id).kind, "Sandsnapper (buried)", "a sword glances off") |
| 88 | test.hold(p, "Stone shovel") |
| 89 | test.hit(p, test.creature(id)) |
| 90 | test.same(test.creature(id).kind, "Sandsnapper", "a shovel digs it out") |
| 91 | test.hold(p, "Stone sword") |
| 92 | test.hit(p, test.creature(id)) |
| 93 | test.check(test.creature(id) ~= nil, "still going") |
| 94 | test.hit(p, test.creature(id)) |
| 95 | test.same(test.creature(id), nil, "beaten") |
| 96 | test.check(world.has(p, "Snapper shell") >= 1, "its shell") |
| 97 | test.same(world.xp(p), 6, "and some XP") |
| 98 | end) |