|
| 1 | +require("mineunit") |
| 2 | + |
| 3 | +mineunit("core") |
| 4 | +mineunit("player") |
| 5 | +mineunit("server") |
| 6 | + |
| 7 | +describe("Chests API", function() |
| 8 | + |
| 9 | + fixture("default") |
| 10 | + fixture("digilines") |
| 11 | + --fixture("pipeworks") |
| 12 | + |
| 13 | + sourcefile("init") |
| 14 | + |
| 15 | + -- Our player Sam will be helping, he promised to place some nodes |
| 16 | + local Sam = Player("Sam") |
| 17 | + |
| 18 | + -- Construct test world with CNC machines |
| 19 | + setup(function() |
| 20 | + world.clear() |
| 21 | + mineunit:set_current_modname("my_mod_name") |
| 22 | + mineunit:execute_on_joinplayer(Sam) |
| 23 | + end) |
| 24 | + |
| 25 | + teardown(function() |
| 26 | + mineunit:restore_current_modname() |
| 27 | + end) |
| 28 | + |
| 29 | + it("registered builtin chests", function() |
| 30 | + local materials = {"iron", "copper", "silver", "gold", "mithril"} |
| 31 | + local types = {"", "_locked", "_protected"} |
| 32 | + local failed = {} |
| 33 | + for _,m in ipairs(materials) do |
| 34 | + for _,t in ipairs(types) do |
| 35 | + local name = "technic:"..m..t.."_chest" |
| 36 | + if type(minetest.registered_nodes[name]) ~= "table" then |
| 37 | + table.insert(failed, name) |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | + if #failed > 0 then |
| 42 | + error("Builtin chest(s) not registered: "..table.concat(failed,", ")) |
| 43 | + end |
| 44 | + end) |
| 45 | + |
| 46 | + it("default builtin descriptions", function() |
| 47 | + local materials = {"iron", "copper", "silver", "gold", "mithril"} |
| 48 | + local types = {"", "_locked", "_protected"} |
| 49 | + local failed = {} |
| 50 | + for _,m in ipairs(materials) do |
| 51 | + for _,t in ipairs(types) do |
| 52 | + local name = "technic:"..m..t.."_chest" |
| 53 | + local description |
| 54 | + if t == "_locked" then |
| 55 | + description = ("%s Locked Chest"):format(m:sub(1,1):upper() .. m:sub(2)) |
| 56 | + elseif t == "_protected" then |
| 57 | + description = ("%s Protected Chest"):format(m:sub(1,1):upper() .. m:sub(2)) |
| 58 | + else |
| 59 | + description = ("%s Chest"):format(m:sub(1,1):upper() .. m:sub(2)) |
| 60 | + end |
| 61 | + assert.equals(description, minetest.registered_nodes[name].description) |
| 62 | + end |
| 63 | + end |
| 64 | + end) |
| 65 | + |
| 66 | + it("registers chest", function() |
| 67 | + technic.chests.register_chest("my_mod_name:my_special", { |
| 68 | + description = "My Special", |
| 69 | + texture_prefix = "my_mod_name_my_special", |
| 70 | + width = 15, |
| 71 | + height = 6, |
| 72 | + sort = true, |
| 73 | + infotext = true, |
| 74 | + autosort = true, |
| 75 | + quickmove = true, |
| 76 | + digilines = true, |
| 77 | + }) |
| 78 | + -- Verify node registration |
| 79 | + assert.is_table(minetest.registered_nodes["my_mod_name:my_special"]) |
| 80 | + -- Try to place it |
| 81 | + world.place_node({x=-99,y=-999,z=-9999}, {name = "my_mod_name:my_special", param2 = 0}, Sam) |
| 82 | + end) |
| 83 | + |
| 84 | + it("registers locked chest", function() |
| 85 | + technic.chests.register_chest("my_mod_name:my_locked_special", { |
| 86 | + description = "My Special", |
| 87 | + texture_prefix = "my_mod_name_my_special", |
| 88 | + width = 15, |
| 89 | + height = 6, |
| 90 | + sort = true, |
| 91 | + infotext = true, |
| 92 | + autosort = true, |
| 93 | + quickmove = true, |
| 94 | + digilines = true, |
| 95 | + locked = true |
| 96 | + }) |
| 97 | + -- Verify node registration |
| 98 | + assert.is_table(minetest.registered_nodes["my_mod_name:my_locked_special"]) |
| 99 | + -- Try to place it |
| 100 | + world.place_node({x=-99,y=-999,z=-9998}, {name = "my_mod_name:my_locked_special", param2 = 0}, Sam) |
| 101 | + end) |
| 102 | + |
| 103 | + it("registers protected chest", function() |
| 104 | + technic.chests.register_chest("my_mod_name:my_protected_special", { |
| 105 | + description = "My Special", |
| 106 | + texture_prefix = "my_mod_name_my_special", |
| 107 | + width = 15, |
| 108 | + height = 6, |
| 109 | + sort = true, |
| 110 | + infotext = true, |
| 111 | + autosort = true, |
| 112 | + quickmove = true, |
| 113 | + digilines = true, |
| 114 | + protected = true |
| 115 | + }) |
| 116 | + -- Verify node registration |
| 117 | + assert.is_table(minetest.registered_nodes["my_mod_name:my_protected_special"]) |
| 118 | + -- Try to place it |
| 119 | + world.place_node({x=-99,y=-999,z=-9997}, {name = "my_mod_name:my_protected_special", param2 = 0}, Sam) |
| 120 | + end) |
| 121 | + |
| 122 | +end) |
0 commit comments