A furnace smelts raw metal into ingots, logs into charcoal, sand into glass and cobblestone into stone, and cooks bread, roasted carrots, baked potatoes, fried eggs, fish and meat, burning coal, charcoal, embers, logs or planks. A campfire cooks with no fuel, and its light keeps Gloomlings away. A cooking pot over a fire cooks pies, stews, porridge and honey cake, and new dishes from recipe cards. Make them all at a workbench.
| 1 | --!strict |
| 2 | -- The furnace creation's own tests: `potluck-server --test=furnace`. |
| 3 | |
| 4 | local test = require("@potluck/test@0.4") |
| 5 | local world = require("@potluck/world@0.22") |
| 6 | |
| 7 | -- a survival player beside a `block` they've put down |
| 8 | local function beside(block: string, carrying: { [string]: number }): (any, vector) |
| 9 | carrying[block] = 1 |
| 10 | local p = test.player("Ada", { survival = true, carrying = carrying }) |
| 11 | local x, z = p.position.x + 2, p.position.z |
| 12 | local at = vector.create(x, world.top(x, z) + 1, z) |
| 13 | test.place(p, at, block) |
| 14 | return p, at |
| 15 | end |
| 16 | |
| 17 | -- answers the question in front of them with the choice that says `what` |
| 18 | local function pick(p, what: string) |
| 19 | local q = test.asked(p) |
| 20 | test.check(q ~= nil, "a question") |
| 21 | for i, c in q.choices do |
| 22 | if c == what then |
| 23 | test.answer(p, i) |
| 24 | return |
| 25 | end |
| 26 | end |
| 27 | error("no choice " .. what .. " in " .. table.concat(q.choices, ", ")) |
| 28 | end |
| 29 | |
| 30 | test.case("its blocks are in the world", function() |
| 31 | for _, name in { "Furnace", "Lit furnace", "Campfire", "Cooking pot" } do |
| 32 | test.check(pcall(world.kind, name), name) |
| 33 | end |
| 34 | end) |
| 35 | |
| 36 | test.case("a furnace smelts raw iron into ingots, burning coal", function() |
| 37 | local p, at = beside("Furnace", { ["Raw iron"] = 3, Coal = 2 }) |
| 38 | test.use_block(p, at) |
| 39 | pick(p, "Smelt Raw iron") |
| 40 | test.same(world.has(p, "Raw iron"), 0, "all three went in") |
| 41 | test.same(world.has(p, "Coal"), 1, "one coal smelts eight") |
| 42 | test.same(world.block(at), "Lit furnace", "it lit up") |
| 43 | test.wait(16) |
| 44 | test.same(world.block(at), "Furnace", "and went out when it was done") |
| 45 | test.use_block(p, at) |
| 46 | test.same(world.has(p, "Iron ingot"), 3, "the ingots, taken on using it") |
| 47 | test.same(world.xp(p), 3, "and an XP for each") |
| 48 | local q = test.asked(p) |
| 49 | test.check(q ~= nil and string.find(q.text, "You took 3 Iron ingot", 1, true) ~= nil, q and q.text or "") |
| 50 | end) |
| 51 | |
| 52 | test.case("with no fuel, nothing goes in", function() |
| 53 | local p, at = beside("Furnace", { ["Raw copper"] = 2 }) |
| 54 | test.use_block(p, at) |
| 55 | pick(p, "Smelt Raw copper") |
| 56 | local q = test.asked(p) |
| 57 | test.check(q ~= nil and string.find(q.text, "needs fuel", 1, true) ~= nil, q and q.text or "") |
| 58 | test.same(world.has(p, "Raw copper"), 2, "nothing taken") |
| 59 | test.same(world.block(at), "Furnace", "not lit") |
| 60 | end) |
| 61 | |
| 62 | test.case("logs burn into charcoal, and planks will do for fuel", function() |
| 63 | local p, at = beside("Furnace", { ["Oak log"] = 1, Planks = 1 }) |
| 64 | test.use_block(p, at) |
| 65 | pick(p, "Smelt Oak log") |
| 66 | test.same(world.has(p, "Planks"), 0, "the planks burn") |
| 67 | test.wait(6) |
| 68 | test.use_block(p, at) |
| 69 | test.same(world.has(p, "Charcoal"), 1) |
| 70 | end) |
| 71 | |
| 72 | test.case("a campfire cooks with no fuel", function() |
| 73 | local p, at = beside("Campfire", { Carrots = 2, Wheat = 3 }) |
| 74 | test.use_block(p, at) |
| 75 | pick(p, "Cook Carrots") |
| 76 | test.same(world.has(p, "Carrots"), 0) |
| 77 | test.wait(11) |
| 78 | test.use_block(p, at) |
| 79 | test.same(world.has(p, "Roasted carrots"), 2) |
| 80 | pick(p, "Cook Wheat") |
| 81 | test.wait(6) |
| 82 | test.use_block(p, at) |
| 83 | test.same(world.has(p, "Bread"), 1, "three wheat make a loaf") |
| 84 | end) |
| 85 | |
| 86 | test.case("a campfire can't smelt", function() |
| 87 | local p, at = beside("Campfire", { ["Raw iron"] = 1, Carrots = 1 }) |
| 88 | test.use_block(p, at) |
| 89 | local q = test.asked(p) |
| 90 | test.check(q ~= nil, "a question") |
| 91 | for _, c in q.choices do |
| 92 | test.check(string.find(c, "Smelt", 1, true) == nil, c) |
| 93 | end |
| 94 | end) |
| 95 | |
| 96 | test.case("breaking a furnace gives back what was in it", function() |
| 97 | local p, at = beside("Furnace", { ["Raw gold"] = 4, Coal = 1, ["Stone pickaxe"] = 1 }) |
| 98 | test.use_block(p, at) |
| 99 | pick(p, "Smelt Raw gold") |
| 100 | test.wait(6) |
| 101 | test.hold(p, "Stone pickaxe") |
| 102 | test.check(test.dig(p, at), "it breaks") |
| 103 | test.same(world.has(p, "Furnace"), 1, "a lit furnace breaks into a furnace") |
| 104 | test.same(world.has(p, "Raw gold") + world.has(p, "Gold ingot"), 4, "all the gold back, smelted or not") |
| 105 | test.check(world.has(p, "Gold ingot") >= 1, "one was done") |
| 106 | end) |
| 107 | |
| 108 | test.case("in creative, it says what it's for", function() |
| 109 | local p = test.player("Cy") |
| 110 | local x, z = p.position.x + 2, p.position.z |
| 111 | local at = vector.create(x, world.top(x, z) + 1, z) |
| 112 | world.set_block(at, "Furnace") |
| 113 | test.use_block(p, at) |
| 114 | local q = test.asked(p) |
| 115 | test.check(q ~= nil and string.find(q.text, "In survival", 1, true) ~= nil, "a word on what it does") |
| 116 | end) |
| 117 | |
| 118 | test.case("a cooking pot over a campfire cooks porridge, and gives the bucket back", function() |
| 119 | local p, at = beside("Cooking pot", { Wheat = 4, ["Milk bucket"] = 1, Campfire = 1 }) |
| 120 | test.use_block(p, at) |
| 121 | local q = test.asked(p) |
| 122 | test.check(q ~= nil and string.find(q.text, "cold", 1, true) ~= nil, "a cold pot says so") |
| 123 | test.answer(p, 1) |
| 124 | test.place(p, at + vector.create(1, 0, 0), "Campfire") |
| 125 | test.use_block(p, at) |
| 126 | -- a dish shows only when all it takes is in this world (what other |
| 127 | -- creations make may be, by now): no pies without eggs |
| 128 | q = test.asked(p) |
| 129 | if not pcall(world.kind, "Egg") then |
| 130 | test.check(q ~= nil and table.find(q.choices, "2 Berry pie") == nil, "no pie without eggs") |
| 131 | end |
| 132 | pick(p, "2 Porridge") |
| 133 | test.same(world.has(p, "Porridge"), 2, "two bowls") |
| 134 | test.same(world.has(p, "Wheat"), 2, "two wheat used") |
| 135 | test.same(world.has(p, "Bucket"), 1, "the bucket back") |
| 136 | test.same(world.has(p, "Milk bucket"), 0, "and the milk gone") |
| 137 | end) |
| 138 |