1
0
Fork 0
MineClone2/mods/bookex/init.lua

40 lines
1.2 KiB
Lua
Raw Normal View History

2015-06-29 17:55:56 +00:00
local function deepcopy ( t )
local nt = { };
for k, v in pairs(t) do
if (type(v) == "table") then
nt[k] = deepcopy(v);
else
nt[k] = v;
end
end
return nt;
end
2017-01-31 22:32:56 +00:00
local newbook = deepcopy(minetest.registered_items["mcl_core:book"]);
2015-06-29 17:55:56 +00:00
newbook.on_use = function ( itemstack, user, pointed_thing )
local text = itemstack:get_metadata();
local formspec = "size[8,9]"..
"background[-0.5,-0.5;9,10;book_bg.png]"..
"textarea[0.5,0.25;7.5,9.25;text;;"..minetest.formspec_escape(text).."]"..
"button_exit[3,8.25;2,1;ok;Exit]";
2017-01-31 22:32:56 +00:00
minetest.show_formspec(user:get_player_name(), "mcl_core:book", formspec);
2015-06-29 17:55:56 +00:00
end
2017-01-31 22:32:56 +00:00
minetest.register_craftitem(":mcl_core:book", newbook);
2015-06-29 17:55:56 +00:00
minetest.register_on_player_receive_fields(function ( player, formname, fields )
2017-01-31 22:32:56 +00:00
if ((formname == "mcl_core:book") and fields and fields.text) then
2015-06-29 17:55:56 +00:00
local stack = player:get_wielded_item();
2017-01-31 22:32:56 +00:00
if (stack:get_name() and (stack:get_name() == "mcl_core:book")) then
2015-06-29 17:55:56 +00:00
local t = stack:to_table();
t.metadata = fields.text;
player:set_wielded_item(ItemStack(t));
end
end
end);