Pale jellyfish that drift and pulse in deep water and glow softly, so the sea fills with little lights after dark. Don't swim into one in survival: it stings a little, though never too much. Bop one and it drifts away.
| 1 | --!strict |
| 2 | -- Moon jellies' own tests: `potluck-server --test=moon-jellies`. |
| 3 | local test = require("@potluck/test@0.9") |
| 4 | local world = require("@potluck/world@0.31") |
| 5 | |
| 6 | local UP = vector.create(0, 1, 0) |
| 7 | |
| 8 | local function pool(depth: number): vector |
| 9 | local g = world.spot("green") |
| 10 | local cx, cz, y = math.floor(g.x) + 80, math.floor(g.z), 90 |
| 11 | for dx = -14, 14 do |
| 12 | for dz = -14, 14 do |
| 13 | local edge = math.abs(dx) == 14 or math.abs(dz) == 14 |
| 14 | world.set_block(vector.create(cx + dx, y, cz + dz), "Stone") |
| 15 | for dy = 1, depth do |
| 16 | world.set_block(vector.create(cx + dx, y + dy, cz + dz), if edge then "Stone" else "Water") |
| 17 | end |
| 18 | end |
| 19 | test.wait(0) |
| 20 | end |
| 21 | return vector.create(cx + 0.5, y + 1, cz + 0.5) |
| 22 | end |
| 23 | |
| 24 | local function jellies(): { number } |
| 25 | return world.creatures(test.kind("Moon jelly")) |
| 26 | end |
| 27 | |
| 28 | test.case("jellies drift in deep water at night, and stay in it", function() |
| 29 | test.daytime(0) |
| 30 | local p = test.player("Ada") |
| 31 | local floor = pool(6) |
| 32 | test.move(p, floor + vector.create(0, 7, 0)) |
| 33 | test.wait(15) |
| 34 | test.check(#jellies() >= 2, "jellies came") |
| 35 | for _, id in jellies() do |
| 36 | local j = test.creature(id) |
| 37 | test.same(world.block(j.position + UP * 0.3), "Water", "in the water") |
| 38 | end |
| 39 | end) |
| 40 | |
| 41 | test.case("swim into one and it stings, but not too much", function() |
| 42 | local p = test.player("Ada", { survival = true }) |
| 43 | local floor = pool(5) |
| 44 | test.move(p, floor + vector.create(4, 2, 0)) |
| 45 | local id = world.spawn(test.kind("Moon jelly"), floor + vector.create(0, 2, 0)) |
| 46 | test.wait(0.2) |
| 47 | for _ = 1, 20 do |
| 48 | local j = test.creature(id) |
| 49 | test.move(p, j.position - UP * 0.4) |
| 50 | test.wait(0.5) |
| 51 | end |
| 52 | test.check(test.health(p) < 20, "it stung") |
| 53 | test.check(test.health(p) >= 6, "but never below six") |
| 54 | test.check(test.heard("sting") >= 1, "with a fizz") |
| 55 | end) |