aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods/test/crafting.lua
blob: 8964bd25a386605e4eb96bf2490190a617eb6851 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local function test_clear_craft()
	minetest.log("info", "Testing clear_craft")
	-- Clearing by output
	minetest.register_craft({
		output = "foo",
		recipe = {{"bar"}}
	})
	minetest.register_craft({
		output = "foo 4",
		recipe = {{"foo", "bar"}}
	})
	assert(#minetest.get_all_craft_recipes("foo") == 2)
	minetest.clear_craft({output="foo"})
	assert(minetest.get_all_craft_recipes("foo") == nil)
	-- Clearing by input
	minetest.register_craft({
		output = "foo 4",
		recipe = {{"foo", "bar"}}
	})
	assert(#minetest.get_all_craft_recipes("foo") == 1)
	minetest.clear_craft({recipe={{"foo", "bar"}}})
	assert(minetest.get_all_craft_recipes("foo") == nil)
end
test_clear_craft()

local function test_get_craft_result()
	minetest.log("info", "test_get_craft_result()")
	-- normal
	local input = {
		method = "normal",
		width = 2,
		items = {"", "default:coal_lump", "", "default:stick"}
	}
	minetest.log("info", "torch crafting input: "..dump(input))
	local output, decremented_input = minetest.get_craft_result(input)
	minetest.log("info", "torch crafting output: "..dump(output))
	minetest.log("info", "torch crafting decremented input: "..dump(decremented_input))
	assert(output.item)
	minetest.log("info", "torch crafting output.item:to_table(): "..dump(output.item:to_table()))
	assert(output.item:get_name() == "default:torch")
	assert(output.item:get_count() == 4)
	-- fuel
	local input = {
		method = "fuel",
		width = 1,
		items = {"default:coal_lump"}
	}
	minetest.log("info", "coal fuel input: "..dump(input))
	local output, decremented_input = minetest.get_craft_result(input)
	minetest.log("info", "coal fuel output: "..dump(output))
	minetest.log("info", "coal fuel decremented input: "..dump(decremented_input))
	assert(output.time)
	assert(output.time > 0)
	-- cook
	local input = {
		method = "cooking",
		width = 1,
		items = {"default:cobble"}
	}
	minetest.log("info", "cobble cooking input: "..dump(output))
	local output, decremented_input = minetest.get_craft_result(input)
	minetest.log("info", "cobble cooking output: "..dump(output))
	minetest.log("info", "cobble cooking decremented input: "..dump(decremented_input))
	assert(output.time)
	assert(output.time > 0)
	assert(output.item)
	minetest.log("info", "cobble cooking output.item:to_table(): "..dump(output.item:to_table()))
	assert(output.item:get_name() == "default:stone")
	assert(output.item:get_count() == 1)
end
test_get_craft_result()