realtest_mt5/mods/workbench/init.lua

102 lines
3.7 KiB
Lua
Raw Normal View History

2020-03-30 22:41:58 +02:00
-- init.lua
-- workbench minetest mod, by darkrose
-- Copyright (C) Lisa Milne 2012 <lisa@ltmnet.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Lesser General Public License as
-- published by the Free Software Foundation, either version 2.1 of the
-- License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public
-- License along with this program. If not, see
-- <http://www.gnu.org/licenses/>
if not minetest.settings:get_bool("creative_mode") then
2020-03-30 22:41:58 +02:00
minetest.register_on_joinplayer(function(player)
-- make the craft guide available
if( minetest.get_modpath('unified_inventory')) then
return;
end
player:get_inventory():set_width("craft", 2)
player:get_inventory():set_size("craft", 2*2)
player:set_inventory_formspec("size[8,7.5]"
.."list[current_player;main;0,3.5;8,4;]"
.."list[current_player;craft;3,0.5;2,2;]"
2020-03-31 01:08:35 +02:00
.."listring[]"
2020-03-30 22:41:58 +02:00
.."image[5,1;1,1;workbench_craftarrow.png]"
2020-03-31 23:24:07 +02:00
.."list[current_player;craftpreview;6,1;1,1;]"
.."image_button[2,1;1,1;craftguide_book.png;__realtest_craftguide;]"
.."tooltip[__realtest_craftguide;Crafting guide]")
2020-03-30 22:41:58 +02:00
end)
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;]"..
2020-03-31 01:08:35 +02:00
"listring[]"..
2020-03-30 22:41:58 +02:00
"image[5,2;1,1;workbench_craftarrow.png]"..
2020-03-31 23:24:07 +02:00
"list[current_name;craftpreview;6,2;1,1;]"..
"image_button[1,2;1,1;craftguide_book.png;__realtest_craftguide;]"..
"tooltip[__realtest_craftguide;Crafting guide]"
2020-03-30 22:41:58 +02:00
--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",
tiles = {"trees_"..tree.name:remove_modname_prefix().."_trunk_top.png^workbench_top.png",
"trees_"..tree.name:remove_modname_prefix().."_trunk_top.png",
"trees_"..tree.name:remove_modname_prefix().."_trunk.png^workbench_side.png"},
groups = {oddly_breakable_by_hand=3, dig_immediate=2},
sounds = default.node_sound_wood_defaults(),
paramtype = "light",
on_construct = function(pos, node)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
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.get_meta(pos);
2020-03-30 22:41:58 +02:00
local inv = meta:get_inventory()
if inv:is_empty("craft") then
return true
end
return false
end,
2020-03-31 23:24:07 +02:00
on_receive_fields = function(pos, formname, fields, sender)
if fields.__realtest_craftguide and sender and sender:is_player() then
realtest_craftguide.show(sender:get_player_name())
end
end,
2020-03-30 22:41:58 +02:00
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(),
recipe = {
{tree.name.."_log", tree.name.."_log"},
{tree.name.."_log", tree.name.."_log"}
}
})
end