add drawers support for wrench (also fix a missing constants issue)

This commit is contained in:
BuckarooBanzay 2020-08-31 12:06:09 +02:00
parent 8fc58be03b
commit df25b91beb
5 changed files with 61 additions and 4 deletions

View File

@ -26,7 +26,7 @@ read_globals = {
"protector", "isprotect",
"homedecor_expect_infinite_stacks",
"monitoring"
"monitoring", "drawers"
}
files["concrete/init.lua"].ignore = { "steel_ingot" }

View File

@ -3,4 +3,4 @@ technic?
technic_chests?
technic_worldgen?
intllib?
drawers?

45
wrench/drawers.lua Normal file
View File

@ -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

View File

@ -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

View File

@ -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