Ores for survival: coal, copper, iron, gold, crystal and moonsilver. Each breaks into what it holds once you have a good enough pickaxe, old chests left underground hold prizes, better the deeper they are, gravel turns up flint now and then, and deep stone a fossil shell, a relic for the Curator.
| 1 | --!strict |
| 2 | -- Mining's own tests: `potluck-server --test=mining`. |
| 3 | |
| 4 | local test = require("@potluck/test@0.7") |
| 5 | local world = require("@potluck/world@0.26") |
| 6 | |
| 7 | -- the tools creation gives pickaxes their levels; its own tests don't run it |
| 8 | world.digging("Wooden pickaxe", { hard = 2.5, level = 1 }) |
| 9 | world.digging("Stone pickaxe", { hard = 4, level = 2 }) |
| 10 | world.digging("Copper pickaxe", { hard = 5, level = 3 }) |
| 11 | world.digging("Iron pickaxe", { hard = 6.5, level = 4 }) |
| 12 | |
| 13 | -- a survival player holding `tool`, and a spot beside them with `block` |
| 14 | local function beside(tool: string, block: string, carrying: { [string]: number }?): (any, vector) |
| 15 | local c = carrying or {} |
| 16 | c[tool] = 1 |
| 17 | local p = test.player("Ada", { survival = true, carrying = c }) |
| 18 | test.hold(p, tool) |
| 19 | local x, z = p.position.x + 2, p.position.z |
| 20 | local at = vector.create(x, world.top(x, z) + 1, z) |
| 21 | world.set_block(at, block) |
| 22 | return p, at |
| 23 | end |
| 24 | |
| 25 | test.case("a wooden pickaxe can't break iron ore", function() |
| 26 | local p, at = beside("Wooden pickaxe", "Iron ore") |
| 27 | test.check(not test.dig(p, at), "it doesn't break") |
| 28 | test.same(world.block(at), "Iron ore", "still there") |
| 29 | test.same(world.has(p, "Raw iron"), 0, "no raw iron") |
| 30 | end) |
| 31 | |
| 32 | test.case("coal ore breaks into coal with a wooden pickaxe", function() |
| 33 | local p, at = beside("Wooden pickaxe", "Coal ore") |
| 34 | test.check(test.dig(p, at), "it breaks") |
| 35 | test.same(world.block(at), "Air", "gone") |
| 36 | local coal = world.has(p, "Coal") |
| 37 | test.check(coal >= 1 and coal <= 2, "1 or 2 coal, not " .. coal) |
| 38 | test.same(world.has(p, "Coal ore"), 0, "not the ore itself") |
| 39 | end) |
| 40 | |
| 41 | test.case("mining ore gives XP, the rarer the more", function() |
| 42 | local p, at = beside("Iron pickaxe", "Coal ore") |
| 43 | test.dig(p, at) |
| 44 | test.same(world.xp(p), 1, "coal") |
| 45 | world.set_block(at, "Moonsilver ore") |
| 46 | test.dig(p, at) |
| 47 | test.same(world.xp(p), 9, "and moonsilver") |
| 48 | world.set_block(at, "Stone") |
| 49 | test.dig(p, at) |
| 50 | test.same(world.xp(p), 9, "stone gives none") |
| 51 | end) |
| 52 | |
| 53 | test.case("a stone pickaxe breaks copper ore but not iron ore", function() |
| 54 | local p, at = beside("Stone pickaxe", "Copper ore") |
| 55 | test.check(test.dig(p, at), "copper breaks") |
| 56 | local copper = world.has(p, "Raw copper") |
| 57 | test.check(copper >= 1 and copper <= 3, "1 to 3 raw copper, not " .. copper) |
| 58 | world.set_block(at, "Iron ore") |
| 59 | test.check(not test.dig(p, at), "iron doesn't") |
| 60 | end) |
| 61 | |
| 62 | test.case("a copper pickaxe breaks iron ore into raw iron", function() |
| 63 | local p, at = beside("Copper pickaxe", "Iron ore") |
| 64 | test.check(test.dig(p, at), "it breaks") |
| 65 | test.same(world.has(p, "Raw iron"), 1, "raw iron") |
| 66 | world.set_block(at, "Gold ore") |
| 67 | test.check(not test.dig(p, at), "but gold needs better") |
| 68 | end) |
| 69 | |
| 70 | test.case("an iron pickaxe breaks gold, crystal and moonsilver", function() |
| 71 | local p, at = beside("Iron pickaxe", "Gold ore") |
| 72 | test.check(test.dig(p, at), "gold breaks") |
| 73 | world.set_block(at, "Crystal ore") |
| 74 | test.check(test.dig(p, at), "crystal breaks") |
| 75 | world.set_block(at, "Moonsilver ore") |
| 76 | test.check(test.dig(p, at), "moonsilver breaks") |
| 77 | test.same(world.has(p, "Raw gold"), 1, "raw gold") |
| 78 | test.same(world.has(p, "Raw moonsilver"), 1, "raw moonsilver") |
| 79 | test.check(world.has(p, "Crystal") >= 1, "crystal") |
| 80 | end) |
| 81 | |
| 82 | test.case("bare hands can't break ores, but break stone as ever", function() |
| 83 | local p = test.player("Ada", { survival = true }) |
| 84 | test.hold(p, nil) |
| 85 | local x, z = p.position.x + 2, p.position.z |
| 86 | local at = vector.create(x, world.top(x, z) + 1, z) |
| 87 | world.set_block(at, "Copper ore") |
| 88 | test.check(not test.dig(p, at), "the ore stays") |
| 89 | world.set_block(at, "Stone") |
| 90 | test.check(test.dig(p, at), "stone breaks") |
| 91 | test.same(world.has(p, "Stone"), 1, "and gives itself") |
| 92 | end) |
| 93 | |
| 94 | test.case("an old chest gives its prizes and falls apart", function() |
| 95 | local p, at = beside("Stone pickaxe", "Old chest") |
| 96 | test.use_block(p, at) |
| 97 | test.same(world.block(at), "Air", "the chest is gone") |
| 98 | local text = test.shown(p, "found") or "" |
| 99 | test.check(string.find(text, "You found ", 1, true) == 1, text) |
| 100 | local got = 0 |
| 101 | for thing, n in world.pockets(p) or {} do |
| 102 | if thing ~= "Stone pickaxe" then |
| 103 | got += n |
| 104 | end |
| 105 | end |
| 106 | test.check(got > 0, "something in the pockets") |
| 107 | end) |
| 108 | |
| 109 | test.case("with full pockets, the rest stays in the chest", function() |
| 110 | local p, at = beside("Stone pickaxe", "Old chest", { Dirt = 99 * 35 }) |
| 111 | test.use_block(p, at) |
| 112 | test.same(world.block(at), "Old chest", "the chest stays") |
| 113 | test.same(test.shown(p, "found"), "Your pockets are full.") |
| 114 | end) |
| 115 | |
| 116 | test.case("a creative player is told chests are for survival", function() |
| 117 | local p = test.player("Bo") |
| 118 | local x, z = p.position.x + 2, p.position.z |
| 119 | local at = vector.create(x, world.top(x, z) + 1, z) |
| 120 | world.set_block(at, "Old chest") |
| 121 | test.use_block(p, at) |
| 122 | test.same(world.block(at), "Old chest", "still there") |
| 123 | test.same(test.shown(p, "found"), "Old chests hold prizes for survival.") |
| 124 | end) |
| 125 | |
| 126 | test.case("gravel turns up flint now and then", function() |
| 127 | local p, at = beside("Wooden pickaxe", "Gravel") |
| 128 | local flint = 0 |
| 129 | for _ = 1, 60 do |
| 130 | world.set_block(at, "Gravel") |
| 131 | test.dig(p, at) |
| 132 | flint = world.has(p, "Flint") |
| 133 | end |
| 134 | test.check(flint >= 1 and flint < 30, "some flint, not every time: " .. flint) |
| 135 | test.check(world.has(p, "Gravel") >= 60, "and the gravel too") |
| 136 | end) |
| 137 | |
| 138 | test.case("the fossil shell is a relic, with its story", function() |
| 139 | local it = world.item("Fossil shell") :: any |
| 140 | test.check(it ~= nil, "an item") |
| 141 | test.same(it.by, "mining") |
| 142 | test.check(type(it.relic) == "string" and #it.relic > 20, "its story") |
| 143 | end) |