BetBetter Crafting Table
This commit is contained in:
parent
72899985e0
commit
7e243db34a
@ -26,6 +26,23 @@ minetest.register_on_joinplayer(function(player)
|
||||
.."list[current_player;craftpreview;6,1;1,1;]")
|
||||
end)
|
||||
|
||||
--
|
||||
--Helper Functions
|
||||
--
|
||||
local update_craft_table = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_stack("craftpreview", 1, minetest.get_craft_result({method = "normal", items = inv:get_list("craft"), width = 3}).item)
|
||||
end
|
||||
|
||||
local CRAFTING_FORMSPEC = "size[9,9]"..
|
||||
"list[current_player;main;0,5;8,4;]"..
|
||||
"list[current_name;craft;2,1;3,3;]"..
|
||||
"image[5,2;1,1;workbench_craftarrow.png]"..
|
||||
"list[current_name;craftpreview;6,2;1,1;]"
|
||||
|
||||
--Node Registry
|
||||
|
||||
for _, tree in pairs(realtest.registered_trees) do
|
||||
minetest.register_node("workbench:work_bench_"..tree.name:remove_modname_prefix(), {
|
||||
description = tree.description .. " Workbench",
|
||||
@ -35,128 +52,26 @@ for _, tree in pairs(realtest.registered_trees) do
|
||||
groups = {oddly_breakable_by_hand=3, dig_immediate=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
paramtype = "light",
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"size[8,9]"..
|
||||
"list[current_name;table;1,1;3,3;]"..
|
||||
"image[4,1.6;2,2;workbench_craftarrow.png]"..
|
||||
"list[current_name;dst;6,2;1,1;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
meta:set_string("infotext", "WorkBench")
|
||||
on_construct = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("table", 9)
|
||||
inv:set_size("dst", 1)
|
||||
inv:set_size("craft", 9)
|
||||
inv:set_width("craft", 3)
|
||||
inv:set_size("craftresult", 1)
|
||||
inv:set_size("craftpreview", 1)
|
||||
meta:set_string("formspec", CRAFTING_FORMSPEC)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
if inv:is_empty("table") and inv:is_empty("dst") then
|
||||
if inv:is_empty("craft") then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if to_list == "dst" then
|
||||
return 0
|
||||
end
|
||||
return count
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if listname == "dst" then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
return stack:get_count()
|
||||
end,
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index,
|
||||
to_list, to_index, count, player)
|
||||
minetest.node_metadata_inventory_move_allow_all(
|
||||
pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if to_list == "table" or from_list == "table" then
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local tablelist = inv:get_list("table")
|
||||
local crafted = nil
|
||||
|
||||
if tablelist then
|
||||
crafted = minetest.get_craft_result({method = "normal", width = 3, items = tablelist})
|
||||
end
|
||||
|
||||
if crafted then
|
||||
inv:set_stack("dst", 1, crafted.item)
|
||||
else
|
||||
inv:set_stack("dst", 1, nil)
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if listname == "table" then
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local tablelist = inv:get_list("table")
|
||||
local crafted = nil
|
||||
|
||||
if tablelist then
|
||||
crafted = minetest.get_craft_result({method = "normal", width = 3, items = tablelist})
|
||||
end
|
||||
|
||||
if crafted then
|
||||
inv:set_stack("dst", 1, crafted.item)
|
||||
else
|
||||
inv:set_stack("dst", 1, nil)
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, count, player)
|
||||
if listname == "table" then
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local tablelist = inv:get_list("table")
|
||||
local crafted = nil
|
||||
|
||||
if tablelist then
|
||||
crafted = minetest.get_craft_result({method = "normal", width = 3, items = tablelist})
|
||||
end
|
||||
|
||||
if crafted then
|
||||
inv:set_stack("dst", 1, crafted.item)
|
||||
else
|
||||
inv:set_stack("dst", 1, nil)
|
||||
end
|
||||
elseif listname == "dst" then
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local tablelist = inv:get_list("table")
|
||||
local crafted = nil
|
||||
local table_dec = nil
|
||||
|
||||
if tablelist then
|
||||
crafted,table_dec = minetest.get_craft_result({method = "normal", width = 3, items = tablelist})
|
||||
end
|
||||
|
||||
if table_dec then
|
||||
inv:set_list("table", table_dec.items)
|
||||
else
|
||||
inv:set_list("table", nil)
|
||||
end
|
||||
|
||||
local tablelist = inv:get_list("table")
|
||||
|
||||
if tablelist then
|
||||
crafted,table_dec = minetest.get_craft_result({method = "normal", width = 3, items = tablelist})
|
||||
end
|
||||
|
||||
if crafted then
|
||||
inv:set_stack("dst", 1, crafted.item)
|
||||
else
|
||||
inv:set_stack("dst", 1, nil)
|
||||
end
|
||||
end
|
||||
return post
|
||||
end,
|
||||
on_metadata_inventory_take = update_craft_table,
|
||||
on_metadata_inventory_move = update_craft_table,
|
||||
on_metadata_inventory_put = update_craft_table,
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "workbench:work_bench_"..tree.name:remove_modname_prefix(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user