diff options
author | LNJ <git@lnj.li> | 2017-04-17 16:04:16 +0200 |
---|---|---|
committer | LNJ <git@lnj.li> | 2017-06-03 17:06:12 +0200 |
commit | f3dafb5b6a82255a795972637377320f64c019b9 (patch) | |
tree | cb47078e207b244f8427a4dd54f429417c45ee12 /lua/api.lua | |
parent | 1f0fdf832b5a24ee80df01b0f08a0902bad8e978 (diff) |
Add Drawer Upgradesorigin/drawer-upgrades
Yey, they're finally there! :)
This will add steel, gold, obsidian and diamond upgrades for MTG
and iron, gold, obsidian, diamond and emerald upgrades for MCL2.
You can add them to a drawer by rightclicking it and adding them to
the new drawer's upgrade inventory.
Diffstat (limited to 'lua/api.lua')
-rwxr-xr-x | lua/api.lua | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/lua/api.lua b/lua/api.lua index 9d54f53..736a8fb 100755 --- a/lua/api.lua +++ b/lua/api.lua @@ -37,6 +37,14 @@ drawers.node_box_simple = { {-0.4375, -0.5, -0.5, 0.4375, -0.4375, -0.4375}, } +drawers.drawer_formspec = "size[9,7]" .. + "list[context;upgrades;2,0.5;5,1;]" .. + "list[current_player;main;0,3;9,4;]" .. + drawers.gui_bg .. + drawers.gui_bg_img .. + drawers.gui_slots .. + drawers.get_upgrade_slots_bg(2, 0.5) + -- construct drawer function drawers.drawer_on_construct(pos) local node = core.get_node(pos) @@ -66,7 +74,14 @@ function drawers.drawer_on_construct(pos) i = i + 1 end + -- spawn all visuals drawers.spawn_visuals(pos) + + -- create drawer upgrade inventory + meta:get_inventory():set_size("upgrades", 5) + + -- set the formspec + meta:set_string("formspec", drawers.drawer_formspec) end -- destruct drawer @@ -113,17 +128,55 @@ function drawers.drawer_on_dig(pos, node, player) k = k + 1 end + -- drop all drawer upgrades + local upgrades = meta:get_inventory():get_list("upgrades") + if upgrades then + for _,itemStack in pairs(upgrades) do + if itemStack:get_count() > 0 then + local rndpos = drawers.randomize_pos(pos) + core.add_item(rndpos, itemStack:get_name()) + end + end + end + -- remove node core.node_dig(pos, node, player) end +function drawers.drawer_allow_metadata_inventory_put(pos, listname, index, stack, player) + if listname ~= "upgrades" then + return 0 + end + if stack:get_count() > 1 then + return 0 + end + if core.get_item_group(stack:get_name(), "drawer_upgrade") < 1 then + return 0 + end + return 1 +end + +function drawers.add_drawer_upgrade(pos, listname, index, stack, player) + -- only do anything if adding to upgrades + if listname ~= "upgrades" then return end + + drawers.update_drawer_upgrades(pos) +end + +function drawers.remove_drawer_upgrade(pos, listname, index, stack, player) + -- only do anything if adding to upgrades + if listname ~= "upgrades" then return end + + drawers.update_drawer_upgrades(pos) +end + function drawers.drawer_insert_object(pos, node, stack, direction) local drawer_visuals = drawers.drawer_visuals[core.serialize(pos)] if not drawer_visuals then return stack end local leftover = stack for _, visual in pairs(drawer_visuals) do - leftover = visual.try_insert_stack(visual, leftover, true) + leftover = visual:try_insert_stack(leftover, true) end return leftover end @@ -144,6 +197,9 @@ function drawers.register_drawer(name, def) def.on_construct = drawers.drawer_on_construct def.on_destruct = drawers.drawer_on_destruct def.on_dig = drawers.drawer_on_dig + def.allow_metadata_inventory_put = drawers.drawer_allow_metadata_inventory_put + def.on_metadata_inventory_put = drawers.add_drawer_upgrade + def.on_metadata_inventory_take = drawers.remove_drawer_upgrade if minetest.get_modpath("screwdriver") and screwdriver then def.on_rotate = def.on_rotate or screwdriver.disallow @@ -231,3 +287,26 @@ function drawers.register_drawer(name, def) end end end + +function drawers.register_drawer_upgrade(name, def) + def.groups = def.groups or {} + def.groups.drawer_upgrade = def.groups.drawer_upgrade or 100 + def.inventory_image = def.inventory_image or "drawers_upgrade_template.png" + def.stack_max = 1 + + local recipe_item = def.recipe_item or "air" + def.recipe_item = nil + + core.register_craftitem(name, def) + + if not def.no_craft then + core.register_craft({ + output = name, + recipe = { + {recipe_item, "group:stick", recipe_item}, + {"group:stick", "drawers:upgrade_template", "group:stick"}, + {recipe_item, "group:stick", recipe_item} + } + }) + end +end |