From 3a8e08f723b5edcf667cedd5d7a5b4bb9d066154 Mon Sep 17 00:00:00 2001 From: AntumDeluge Date: Fri, 12 May 2017 11:47:48 -0700 Subject: [PATCH] [workbench] Update to Git commit 74dd1af & patch b964323: https://github.com/minetest-mods/workbench/tree/74dd1af https://github.com/AntumDeluge/mtmod-workbench/tree/b964323 --- README.md | 4 +- mods/tools/workbench/.luacheckrc | 8 +++ mods/tools/workbench/depends.txt | 2 +- mods/tools/workbench/init.lua | 102 ++++++++++++++++++------------- 4 files changed, 73 insertions(+), 43 deletions(-) create mode 100644 mods/tools/workbench/.luacheckrc diff --git a/README.md b/README.md index 8957ce87..fa5ac5d6 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m * [compassgps][] ([WTFPL][lic.wtfpl] / [CC0][lic.cc0] / [CC BY-SA][lic.ccbysa]) -- version: [96892a0 Git][ver.compassgps] *2015-07-31* ([patched][patch.compassgps]) * [tools_obsidian][] ([LGPL / CC BY-SA][lic.tools_obsidian]) -- version: [f77fd79][ver.tools_obsidian] *2016-03-19* * [torches][] ([LGPL / CC-BY-SA](mods/tools/torches/README.txt)) -- version: [e19c772 Git][ver.torches] *2015-11-12* - * [workbench][] ([GPL / WTFPL](mods/tools/workbench/LICENSE)) + * [workbench][] ([GPL / WTFPL](mods/tools/workbench/LICENSE)) -- version: [74dd1af Git][ver.workbench] *2017-02-07* ([patched][patch.workbench]) * transport/ * [helicopter][] ([GPL][lic.gpl2.0]) -- version: [10f1433 Git][ver.helicopter] ([patched][patch.helicopter]) *2015-07-15* * [hovercraft][] ([LGPL / CC BY-SA / CC0][lic.hovercraft]) @@ -454,6 +454,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m [ver.walking_light]: https://github.com/petermaloney/walking_light/tree/b9de302 [ver.wardrobe]: https://github.com/prestidigitator/minetest-mod-wardrobe/tree/c48b011 [ver.windmill]: https://github.com/Sokomine/windmill/tree/47b029d +[ver.workbench]: https://github.com/minetest-mods/workbench/tree/74dd1af [patch.adv_spawning]: https://github.com/AntumDeluge/mtmod-adv_spawning/tree/572688b [patch.bags]: https://github.com/AntumDeluge/mtmod-bags/tree/4363284 @@ -480,3 +481,4 @@ The game includes the mods from the default [minetest_game](https://github.com/m [patch.unifieddyes]: https://github.com/AntumDeluge/mtmod-unifieddyes/tree/df3f1b1 [patch.walking_light]: https://github.com/AntumDeluge/mtmod-walking_light/tree/00ebab8 [patch.windmill]: https://github.com/AntumDeluge/mtmod-windmill/tree/7756ab4 +[patch.workbench]: https://github.com/AntumDeluge/mtmod-workbench/tree/b964323 diff --git a/mods/tools/workbench/.luacheckrc b/mods/tools/workbench/.luacheckrc new file mode 100644 index 00000000..9e5447cc --- /dev/null +++ b/mods/tools/workbench/.luacheckrc @@ -0,0 +1,8 @@ +unused_args = false +allow_defined_top = true + +read_globals = { + "minetest", + "default", + "stairs", +} diff --git a/mods/tools/workbench/depends.txt b/mods/tools/workbench/depends.txt index 735a101a..9cb3c89e 100644 --- a/mods/tools/workbench/depends.txt +++ b/mods/tools/workbench/depends.txt @@ -1,4 +1,4 @@ default stairs xdecor? -screwdriver? +craft_guide? diff --git a/mods/tools/workbench/init.lua b/mods/tools/workbench/init.lua index 4eebee80..bc772e4b 100644 --- a/mods/tools/workbench/init.lua +++ b/mods/tools/workbench/init.lua @@ -1,8 +1,10 @@ local workbench = {} +WB = {} screwdriver = screwdriver or {} +local min, ceil = math.min, math.ceil --- Nodes allowed to be cut. --- Only the regular, solid blocks without metas or explosivity can be cut. +-- Nodes allowed to be cut +-- Only the regular, solid blocks without metas or explosivity can be cut local nodes = {} for node, def in pairs(minetest.registered_nodes) do if (def.drawtype == "normal" or def.drawtype:sub(1,5) == "glass") and @@ -13,8 +15,11 @@ for node, def in pairs(minetest.registered_nodes) do not def.on_blast and not def.allow_metadata_inventory_take and not (def.groups.not_in_creative_inventory == 1) and + not (def.groups.not_cuttable == 1) and not def.groups.wool and - not def.description:find("Ore") and + (def.tiles and type(def.tiles[1]) == "string" and not + def.tiles[1]:find("default_mineral")) and + not def.mesecons and def.description and def.description ~= "" and def.light_source == 0 @@ -23,7 +28,23 @@ for node, def in pairs(minetest.registered_nodes) do end end --- Nodeboxes definitions. +-- Optionally, you can register custom cuttable nodes in the workbench +WB.custom_nodes_register = { + -- "default:leaves", +} + +setmetatable(nodes, { + __concat = function(t1, t2) + for i=1, #t2 do + t1[#t1+1] = t2[i] + end + return t1 + end +}) + +nodes = nodes..WB.custom_nodes_register + +-- Nodeboxes definitions workbench.defs = { -- Name Yield X Y Z W H L {"nanoslab", 16, { 0, 0, 0, 8, 1, 8 }}, @@ -46,7 +67,7 @@ workbench.defs = { { 0, 8, 0, 8, 8, 8 }} } --- Tools allowed to be repaired. +-- Tools allowed to be repaired function workbench:repairable(stack) local tools = {"pick", "axe", "shovel", "sword", "hoe", "armor", "shield"} for _, t in pairs(tools) do @@ -56,13 +77,9 @@ function workbench:repairable(stack) end function workbench:get_output(inv, input, name) - if inv:is_empty("input") then - inv:set_list("forms", {}) return - end - local output = {} for _, n in pairs(self.defs) do - local count = math.min(n[2] * input:get_count(), input:get_stack_max()) + local count = min(n[2] * input:get_count(), input:get_stack_max()) local item = name.."_"..n[1] if not n[3] then item = "stairs:"..n[1].."_"..name:match(":(.*)") end output[#output+1] = item.." "..count @@ -70,11 +87,11 @@ function workbench:get_output(inv, input, name) inv:set_list("forms", output) end --- Thanks to kaeza for this function. +-- Thanks to kaeza for this function function workbench:pixelbox(size, boxes) local fixed = {} for _, box in pairs(boxes) do - -- `unpack` has been changed to `table.unpack` in newest Lua versions. + -- `unpack` has been changed to `table.unpack` in newest Lua versions local x, y, z, w, h, l = unpack(box) fixed[#fixed+1] = { (x / size) - 0.5, @@ -85,11 +102,11 @@ function workbench:pixelbox(size, boxes) ((z + l) / size) - 0.5 } end - return {type = "fixed", fixed = fixed} + return {type="fixed", fixed=fixed} end local formspecs = { - -- Main formspec. + -- Main formspec [[ label[0.9,1.23;Cut] label[0.9,2.23;Repair] box[-0.05,1;2.05,0.9;#555555] @@ -104,14 +121,14 @@ local formspecs = { list[context;tool;2,2;1,1;] list[context;hammer;3,2;1,1;] list[context;forms;4,0;4,3;] ]], - -- Crafting formspec. + -- Crafting formspec [[ image[5,1;1,1;gui_furnace_arrow_bg.png^[transformR270] button[0,0;1.5,1;back;< Back] list[current_player;craft;2,0;3,3;] list[current_player;craftpreview;6,1;1,1;] listring[current_player;main] listring[current_player;craft] ]], - -- Storage formspec. + -- Storage formspec [[ list[context;storage;0,1;8,2;] button[0,0;1.5,1;back;< Back] listring[context;storage] @@ -148,7 +165,7 @@ end function workbench.dig(pos) local inv = minetest.get_meta(pos):get_inventory() return inv:is_empty("input") and inv:is_empty("hammer") and - inv:is_empty("tool") and inv:is_empty("storage") + inv:is_empty("tool") and inv:is_empty("storage") end function workbench.timer(pos) @@ -158,10 +175,11 @@ function workbench.timer(pos) local hammer = inv:get_stack("hammer", 1) if tool:is_empty() or hammer:is_empty() or tool:get_wear() == 0 then - timer:stop() return + timer:stop() + return end - -- Tool's wearing range: 0-65535 | 0 = new condition. + -- Tool's wearing range: 0-65535 | 0 = new condition tool:add_wear(-500) hammer:add_wear(700) @@ -172,7 +190,8 @@ end function workbench.put(_, listname, _, stack) local stackname = stack:get_name() - if (listname == "tool" and stack:get_wear() > 0 and workbench:repairable(stackname)) or + if (listname == "tool" and stack:get_wear() > 0 and + workbench:repairable(stackname)) or (listname == "input" and minetest.registered_nodes[stackname.."_cube"]) or (listname == "hammer" and stackname == "xdecor:hammer") or listname == "storage" then @@ -181,18 +200,8 @@ function workbench.put(_, listname, _, stack) return 0 end -function workbench.take(_, listname, _, stack, player) - if listname == "forms" then - local inv = player:get_inventory() - if inv:room_for_item("main", stack:get_name()) then return -1 end - return 0 - end - return stack:get_count() -end - function workbench.move(_, from_list, _, to_list, _, count) - if to_list == "storage" and from_list ~= "forms" then return count end - return 0 + return (to_list == "storage" and from_list ~= "forms") and count or 0 end function workbench.on_put(pos, listname, _, stack) @@ -206,20 +215,30 @@ function workbench.on_put(pos, listname, _, stack) end end -function workbench.on_take(pos, listname, index, stack) +function workbench.on_take(pos, listname, index, stack, player) local inv = minetest.get_meta(pos):get_inventory() local input = inv:get_stack("input", 1) + local inputname = input:get_name() + local stackname = stack:get_name() if listname == "input" then - if stack:get_name() == input:get_name() then - workbench:get_output(inv, input, stack:get_name()) + if stackname == inputname then + workbench:get_output(inv, input, stackname) else inv:set_list("forms", {}) end elseif listname == "forms" then - input:take_item(math.ceil(stack:get_count() / workbench.defs[index][2])) + local fromstack = inv:get_stack(listname, index) + if not fromstack:is_empty() and fromstack:get_name() ~= stackname then + local player_inv = player:get_inventory() + if player_inv:room_for_item("main", fromstack) then + player_inv:add_item("main", fromstack) + end + end + + input:take_item(ceil(stack:get_count() / workbench.defs[index][2])) inv:set_stack("input", 1, input) - workbench:get_output(inv, input, input:get_name()) + workbench:get_output(inv, input, inputname) end end @@ -240,7 +259,6 @@ minetest.register_node(":xdecor:workbench", { on_metadata_inventory_put = workbench.on_put, on_metadata_inventory_take = workbench.on_take, allow_metadata_inventory_put = workbench.put, - allow_metadata_inventory_take = workbench.take, allow_metadata_inventory_move = workbench.move }) @@ -268,12 +286,13 @@ minetest.register_craft({ }) for _, d in pairs(workbench.defs) do -for i = 1, #nodes do +for i=1, #nodes do local node = nodes[i] local def = minetest.registered_nodes[node] if d[3] then - local groups, tiles = {}, {} + local groups = {} + local tiles groups.not_in_creative_inventory = 1 for k, v in pairs(def.groups) do @@ -293,8 +312,9 @@ for i = 1, #nodes do end if not minetest.registered_nodes["stairs:slab_"..node:match(":(.*)")] then - stairs.register_stair_and_slab(node:match(":(.*)"), node, groups, tiles, - def.description.." Stair", def.description.." Slab", def.sounds) + stairs.register_stair_and_slab(node:match(":(.*)"), node, + groups, tiles, def.description.." Stair", + def.description.." Slab", def.sounds) end minetest.register_node(":"..node.."_"..d[1], {