Sign in
world

Crystal Grottos

by Potluck · version 1 · Checked for all ages

Geodes lie in the rock beside the caves: crack one's gray shell open and it's lined with crystal that shines in the dark, with crystal buds to break for crystal and, now and then, glimmer seeds that grow into flowers that glow. Far deeper, whole grottos of crystal wait, and somewhere in them a singing crystal for the Curator.

1--!strict
2-- Crystal Grottos' own tests: `potluck-server --test=crystal-grottos`.
3
4local test = require("@potluck/test@0.8")
5local world = require("@potluck/world@0.26")
6local store = require("@potluck/store")
7
8-- the tools creation gives pickaxes their levels; these tests don't run it
9world.digging("Iron pickaxe", { hard = 3, glass = 3, level = 4 })
10
11-- a little cave dug in the rock under the island, far from the Green, for
12-- a player to stand in
13local function cave(p, y: number): vector
14 local g = world.spot("green") :: vector
15 local x, z = math.floor(g.x) - 100, math.floor(g.z) + 30
16 for dx = -2, 2 do
17 for dz = -2, 2 do
18 for dy = 0, 2 do
19 world.set_block(vector.create(x + dx, y + dy, z + dz), "Air")
20 end
21 world.set_block(vector.create(x + dx, y - 1, z + dz), "Stone")
22 end
23 end
24 local at = vector.create(x + 0.5, y, z + 0.5)
25 test.move(p, at)
26 return at
27end
28
29local function wait_for(what: string, n: number?): any
30 for _ = 1, 40 do
31 test.wait(1)
32 local list = store.get(what) :: { any }?
33 if list and #list >= (n or 1) and (what ~= "grottos" or list[1].built) then
34 -- let it finish
35 test.wait(1)
36 return list[1]
37 end
38 end
39 return nil
40end
41
42test.case("a geode forms in the rock beside a cave, lined with crystal around a hollow", function()
43 local p = test.player("Ada")
44 cave(p, -12)
45 local c = wait_for("geodes") :: vector?
46 test.check(c ~= nil, "a geode formed")
47 local at = c :: vector
48 test.same(world.block(at), "Air", "it's hollow")
49 test.same(world.block(at - vector.create(0, 2, 0)), "Grotto crystal", "lined with crystal")
50 local shell = 0
51 for _, d in { vector.create(3, 0, 0), vector.create(-3, 0, 0), vector.create(0, 3, 0), vector.create(0, -3, 0), vector.create(0, 0, 3), vector.create(0, 0, -3) } do
52 if world.block(at + d) == "Slate" then
53 shell += 1
54 end
55 end
56 test.check(shell >= 4, "in a shell of slate: " .. shell)
57end)
58
59test.case("a crystal bud breaks into crystal with an iron pickaxe", function()
60 local p = test.player("Ada", { survival = true, carrying = { ["Iron pickaxe"] = 1 } })
61 local x, z = p.position.x + 2, p.position.z
62 local y = world.top(x, z) + 1
63 world.set_block(vector.create(x, y, z), "Grotto crystal")
64 local bud = vector.create(x, y + 1, z)
65 world.set_block(bud, "Crystal bud")
66 test.check(not test.dig(p, bud), "not by hand")
67 test.hold(p, "Iron pickaxe")
68 test.check(test.dig(p, bud), "it breaks")
69 local got = world.has(p, "Crystal")
70 test.check(got >= 1 and got <= 2, "1 or 2 crystal, not " .. got)
71 test.same(world.has(p, "Crystal bud"), 0, "not the bud itself")
72end)
73
74test.case("glimmer seeds grow into a bloom that glows, which gives a seed back", function()
75 local p = test.player("Ada", { survival = true, carrying = { ["Glimmer seeds"] = 2 } })
76 test.hold(p, "Glimmer seeds")
77 local x, z = p.position.x + 2, p.position.z
78 local y = world.top(x, z) + 1
79 local soil = vector.create(x, y, z)
80 world.set_block(soil, "Dirt")
81 test.use_block(p, soil)
82 local at = soil + vector.create(0, 1, 0)
83 test.same(world.block(at), "Fern", "planted: a little green shoot")
84 test.same(world.has(p, "Glimmer seeds"), 1, "a seed used")
85 test.wait(4 * 60 + 6)
86 test.same(world.block(at), "Glimmer bloom", "grown")
87 test.check(test.dig(p, at), "picked")
88 test.same(world.has(p, "Glimmer bloom"), 1, "the bloom")
89 test.same(world.has(p, "Glimmer seeds"), 2, "and a seed back")
90end)
91
92test.case("a glimmer shoot dug up gives its seed back, and a wild fern doesn't", function()
93 local p = test.player("Ada", { survival = true, carrying = { ["Glimmer seeds"] = 1 } })
94 test.hold(p, "Glimmer seeds")
95 local x, z = p.position.x + 2, p.position.z
96 local soil = vector.create(x, world.top(x, z) + 1, z)
97 world.set_block(soil, "Dirt")
98 test.use_block(p, soil)
99 local at = soil + vector.create(0, 1, 0)
100 test.same(world.has(p, "Glimmer seeds"), 0, "planted")
101 test.check(test.dig(p, at), "dug up")
102 test.same(world.has(p, "Glimmer seeds"), 1, "the seed back")
103 local wild = soil + vector.create(0, 1, 2)
104 world.set_block(wild - vector.create(0, 1, 0), "Dirt")
105 world.set_block(wild, "Fern")
106 test.check(test.dig(p, wild), "a wild fern picked")
107 test.same(world.has(p, "Glimmer seeds"), 1, "no seed in a wild fern")
108end)
109
110test.case("far deeper, a whole grotto opens near a player, walled with crystal and full of buds", function()
111 local p = test.player("Ada")
112 cave(p, -70)
113 local g = wait_for("grottos")
114 test.check(g ~= nil, "a grotto opened")
115 test.same(world.block(g.at), "Air", "it's dug")
116 test.same(world.block(g.at + vector.create(0, -4, 0)), "Grotto crystal", "a floor of crystal")
117 local buds = 0
118 for dx = -7, 7 do
119 for dz = -7, 7 do
120 if world.block(g.at + vector.create(dx, -3, dz)) == "Crystal bud" then
121 buds += 1
122 end
123 end
124 end
125 test.check(buds >= 8, "buds on its floor: " .. buds)
126end)
127
128test.case("the singing crystal is a relic, with its story", function()
129 local it = world.item("Singing crystal") :: any
130 test.check(it ~= nil and it.by == "crystal-grottos", "an item of the grottos'")
131 test.check(type(it.relic) == "string" and #it.relic > 20, "its story")
132end)