Big, gentle turtles out in deep water, now and then near anyone by the sea. Climb on one and it carries you over the water at the top, so you can breathe: steer it where you want to go. Bop one and it hides in its shell for a moment.
| 1 | --!strict |
| 2 | -- Sea turtles' own tests: `potluck-server --test=sea-turtles`. |
| 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 | -- a stone basin of water high in the sky, away from the Green, `depth` |
| 9 | -- deep: the middle of its floor |
| 10 | local function pool(depth: number): vector |
| 11 | local g = world.spot("green") |
| 12 | local cx, cz, y = math.floor(g.x) + 80, math.floor(g.z), 90 |
| 13 | for dx = -16, 16 do |
| 14 | for dz = -16, 16 do |
| 15 | local edge = math.abs(dx) == 16 or math.abs(dz) == 16 |
| 16 | world.set_block(vector.create(cx + dx, y, cz + dz), "Stone") |
| 17 | for dy = 1, depth do |
| 18 | world.set_block(vector.create(cx + dx, y + dy, cz + dz), if edge then "Stone" else "Water") |
| 19 | end |
| 20 | end |
| 21 | test.wait(0) |
| 22 | end |
| 23 | return vector.create(cx + 0.5, y + 1, cz + 0.5) |
| 24 | end |
| 25 | |
| 26 | local function turtles(): { number } |
| 27 | return world.creatures(test.kind("Sea turtle")) |
| 28 | end |
| 29 | |
| 30 | test.case("turtles turn up out in deep water", function() |
| 31 | local p = test.player("Ada") |
| 32 | local floor = pool(6) |
| 33 | test.move(p, floor + vector.create(0, 7, 0)) |
| 34 | test.wait(40) |
| 35 | test.check(#turtles() >= 1, "a turtle came") |
| 36 | local t = test.creature(turtles()[1]) |
| 37 | test.same(world.block(t.position + UP * 0.3), "Water", "in the water") |
| 38 | end) |
| 39 | |
| 40 | test.case("ridden, a turtle swims at the top of the water", function() |
| 41 | local p = test.player("Ada") |
| 42 | local floor = pool(6) |
| 43 | test.move(p, floor + vector.create(3, 6, 0)) |
| 44 | local id = world.spawn(test.kind("Sea turtle"), floor + vector.create(0, 1, 0)) |
| 45 | test.wait(0.2) |
| 46 | local t = test.creature(id) |
| 47 | test.ride(p, t) |
| 48 | test.wait(6) |
| 49 | test.same(t.rider and t.rider.id, p.id, "Ada's on") |
| 50 | test.same(world.block(t.position + UP * 0.3), "Water", "it's in the water") |
| 51 | test.same(world.block(t.position + UP * 1.6), "Air", "up at the top") |
| 52 | end) |
| 53 | |
| 54 | test.case("bopped, it hides in its shell for a moment", function() |
| 55 | local p = test.player("Ada") |
| 56 | local floor = pool(4) |
| 57 | test.move(p, floor + vector.create(3, 4, 0)) |
| 58 | local id = world.spawn(test.kind("Sea turtle"), floor + vector.create(0, 1, 0)) |
| 59 | test.wait(0.2) |
| 60 | test.hit(p, test.creature(id)) |
| 61 | test.same(test.creature(id).kind, "Sea turtle (in its shell)", "it hid") |
| 62 | test.wait(5) |
| 63 | test.same(test.creature(id).kind, "Sea turtle", "and came out again") |
| 64 | end) |