Stony things that lie in wait in the dark of caves, looking just like a lump of rock against the wall. Come too close in survival and one wakes, lunges and bites, then lumbers after you before settling down as a rock again. Look for the seam of its mouth. They're hard as stone, so a pickaxe beats them twice as fast, and a beaten one leaves flint and sometimes whatever ore it swallowed. None on a Peaceful world, and fewer on a Gentle one.
| 1 | --!strict |
| 2 | -- Rockjaws' own tests: `potluck-server --test=rockjaws`. |
| 3 | local test = require("@potluck/test@0.9") |
| 4 | local world = require("@potluck/world@0.25") |
| 5 | |
| 6 | -- a cave dug out under where a player stands, a row at a time |
| 7 | local function cave(p): vector |
| 8 | local x, z, y = math.floor(p.position.x), math.floor(p.position.z), -24 |
| 9 | for dx = -14, 14 do |
| 10 | for dz = -14, 14 do |
| 11 | world.set_block(vector.create(x + dx, y - 1, z + dz), "Stone") |
| 12 | for dy = 0, 4 do |
| 13 | world.set_block(vector.create(x + dx, y + dy, z + dz), "Air") |
| 14 | end |
| 15 | world.set_block(vector.create(x + dx, y + 5, z + dz), "Stone") |
| 16 | end |
| 17 | test.wait(0) |
| 18 | end |
| 19 | return vector.create(x + 0.5, y, z + 0.5) |
| 20 | end |
| 21 | |
| 22 | local function all(): { number } |
| 23 | local out = {} |
| 24 | for _, k in { "Rockjaw", "Rockjaw (still)" } do |
| 25 | for _, id in world.creatures(test.kind(k)) do |
| 26 | table.insert(out, id) |
| 27 | end |
| 28 | end |
| 29 | return out |
| 30 | end |
| 31 | |
| 32 | test.case("they lie in wait in caves, still as rock", function() |
| 33 | test.danger("normal") |
| 34 | local p = test.player("Ada", { survival = true }) |
| 35 | local at = cave(p) |
| 36 | test.move(p, at) |
| 37 | test.wait(16) |
| 38 | local list = all() |
| 39 | test.check(#list >= 1, "a rockjaw lies about") |
| 40 | local c = test.creature(list[1]) |
| 41 | local was = c.position |
| 42 | test.wait(3) |
| 43 | if c.kind == "Rockjaw (still)" then |
| 44 | test.check(vector.magnitude(c.position - was) < 0.1, "it doesn't move") |
| 45 | end |
| 46 | end) |
| 47 | |
| 48 | test.case("come close and one wakes and bites, then settles again", function() |
| 49 | test.danger("normal") |
| 50 | local p = test.player("Ada", { survival = true }) |
| 51 | local at = cave(p) |
| 52 | test.move(p, at + vector.create(-8, 0, 0)) |
| 53 | local id = world.spawn(test.kind("Rockjaw (still)"), at + vector.create(4, 0, 0)) |
| 54 | test.wait(1) |
| 55 | test.same(test.creature(id).kind, "Rockjaw (still)", "still") |
| 56 | test.move(p, at + vector.create(2, 0, 0)) |
| 57 | test.wait(1) |
| 58 | test.same(test.creature(id).kind, "Rockjaw", "it woke") |
| 59 | test.wait(4) |
| 60 | test.check(test.health(p) < 20, "and bit") |
| 61 | -- off to the cave's far corner, out of its reach |
| 62 | test.move(p, at + vector.create(-12, 0, -12)) |
| 63 | test.wait(16) |
| 64 | test.same(test.creature(id).kind, "Rockjaw (still)", "it settled again") |
| 65 | end) |
| 66 | |
| 67 | test.case("a pickaxe beats one faster, and it leaves flint", function() |
| 68 | test.danger("normal") |
| 69 | local p = test.player("Ada", { survival = true, carrying = { ["Iron pickaxe"] = 1 } }) |
| 70 | local at = cave(p) |
| 71 | test.move(p, at) |
| 72 | local id = world.spawn(test.kind("Rockjaw"), at + vector.create(2, 0, 0)) |
| 73 | test.wait(0.2) |
| 74 | test.hold(p, "Iron pickaxe") |
| 75 | for _ = 1, 3 do |
| 76 | test.hit(p, test.creature(id)) |
| 77 | end |
| 78 | test.same(test.creature(id), nil, "beaten") |
| 79 | test.check(world.has(p, "Flint") >= 1, "flint") |
| 80 | test.same(world.xp(p), 6, "and some XP") |
| 81 | end) |