From df25b91beb6c4bd04be045e23402a230a9797a5b Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Mon, 31 Aug 2020 12:06:09 +0200 Subject: [PATCH] add drawers support for wrench (also fix a missing constants issue) --- .luacheckrc | 2 +- wrench/depends.txt | 2 +- wrench/drawers.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ wrench/init.lua | 14 +++++++++++++- wrench/support.lua | 2 +- 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 wrench/drawers.lua diff --git a/.luacheckrc b/.luacheckrc index 4891133..5cfcb06 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -26,7 +26,7 @@ read_globals = { "protector", "isprotect", "homedecor_expect_infinite_stacks", - "monitoring" + "monitoring", "drawers" } files["concrete/init.lua"].ignore = { "steel_ingot" } diff --git a/wrench/depends.txt b/wrench/depends.txt index a681af3..25c5256 100644 --- a/wrench/depends.txt +++ b/wrench/depends.txt @@ -3,4 +3,4 @@ technic? technic_chests? technic_worldgen? intllib? - +drawers? diff --git a/wrench/drawers.lua b/wrench/drawers.lua new file mode 100644 index 0000000..3249326 --- /dev/null +++ b/wrench/drawers.lua @@ -0,0 +1,45 @@ +if not minetest.get_modpath("drawers") then + return +end + +local INT, STRING = + wrench.META_TYPE_INT, + wrench.META_TYPE_STRING + +-- assemble definitions for type 1,2 and 4 +for _, drawer_type in ipairs({1,2,4}) do + + local def = { + lists = {"upgrades"}, + metas = {}, + after_place = drawers.spawn_visuals + } + + for i=1,drawer_type do + + local suffix + if drawer_type == 1 then + -- no suffix for base type + suffix = "" + else + -- index as suffix + suffix = i + end + + def.metas["name" .. suffix] = STRING + def.metas["count" .. suffix] = INT + def.metas["max_count" .. suffix] = INT + def.metas["base_stack_max" .. suffix] = INT + def.metas["entity_infotext" .. suffix] = STRING + def.metas["stack_max_factor" .. suffix] = INT + def.metas["meta_itemstack" .. suffix] = INT + def.metas["itemstack_wear" .. suffix] = INT + end + + wrench:register_node("drawers:wood" .. drawer_type, def) + wrench:register_node("drawers:acacia_wood" .. drawer_type, def) + wrench:register_node("drawers:aspen_wood" .. drawer_type, def) + wrench:register_node("drawers:junglewood" .. drawer_type, def) + wrench:register_node("drawers:pine_wood" .. drawer_type, def) + +end diff --git a/wrench/init.lua b/wrench/init.lua index adb80c9..3d1dc8e 100644 --- a/wrench/init.lua +++ b/wrench/init.lua @@ -18,6 +18,7 @@ wrench = {} local modpath = minetest.get_modpath(minetest.get_current_modname()) dofile(modpath.."/support.lua") dofile(modpath.."/technic.lua") +dofile(modpath.."/drawers.lua") -- Boilerplate to support localized strings if intllib mod is installed. local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end @@ -79,7 +80,18 @@ for name, info in pairs(wrench.registered_nodes) do newdef.groups.not_in_creative_inventory = 1 newdef.on_construct = nil newdef.on_destruct = nil - newdef.after_place_node = restore + newdef.after_place_node = function(pos, placer, itemstack) + + -- call restoration function with on_plcae callbacks + local new_stack = restore(pos, placer, itemstack) + + if type(info.after_place) == "function" then + -- call custom after_place function + info.after_place(pos) + end + + return new_stack + end minetest.register_node(":"..get_pickup_name(name), newdef) end end diff --git a/wrench/support.lua b/wrench/support.lua index 78ffa03..4c1a371 100644 --- a/wrench/support.lua +++ b/wrench/support.lua @@ -17,6 +17,7 @@ Syntax: wrench.META_TYPE_FLOAT = 1 wrench.META_TYPE_STRING = 2 +wrench.META_TYPE_INT = 3 local STRING, FLOAT = wrench.META_TYPE_STRING, @@ -68,4 +69,3 @@ function wrench:register_node(name, def) self.registered_nodes[name] = def end end -