forked from prestidigitator/minetest-mod-wardrobe
-
Notifications
You must be signed in to change notification settings - Fork 2
/
wardrobe.lua
89 lines (75 loc) · 2.83 KB
/
wardrobe.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
local FORM_NAME = "wardrobe_wardrobeSkinForm";
local SKINS_PER_PAGE = 8;
local function showForm(player, page)
local playerName = player:get_player_name();
if not playerName or playerName == "" then return; end
local n = #wardrobe.skins;
if n <= 0 then return; end
local nPages = math.ceil(n/SKINS_PER_PAGE);
if not page or page > nPages then page = 1; end
local s = 1 + SKINS_PER_PAGE*(page-1);
local e = math.min(s+SKINS_PER_PAGE-1, n);
local fs = "size[6.8,10]" ..default.gui_bg..default.gui_bg_img;
fs = fs.."label[0,0;Change Into:]";
for i = s, e do
local slot = i-s+1;
local skin = wardrobe.skins[i];
local skinName = minetest.formspec_escape(wardrobe.skinNames[skin]);
fs = fs.."button_exit[0,"..slot..";5,1;s:"..skin..";"..skinName.."]";
fs = fs.."image[5,"..slot..";2,1;"..skin.."]";
end
fs = fs.."label[2.8,9;Page "..page.."/"..nPages.."]";
if page > 1 then
fs = fs.."button[0,9;1,1;n:p"..(page-1)..";prev]";
end
if page < nPages then
fs = fs.."button[5.8,9;1,1;n:p"..(page+1)..";next]";
end
minetest.show_formspec(playerName, FORM_NAME, fs);
end
minetest.register_on_player_receive_fields(
function(player, formName, fields)
if formName ~= FORM_NAME then return; end
local playerName = player:get_player_name();
if not playerName or playerName == "" then return; end
for fieldName in pairs(fields) do
if #fieldName > 2 then
local action = string.sub(fieldName, 1, 1);
local value = string.sub(fieldName, 3);
if action == "n" then
showForm(player, tonumber(string.sub(value, 2)));
return;
elseif action == "s" then
wardrobe.changePlayerSkin(playerName, value);
return;
end
end
end
end);
minetest.register_node(
"wardrobe:wardrobe",
{
description = "Wardrobe",
paramtype2 = "facedir",
tiles = {
"wardrobe_wardrobe_topbottom.png",
"wardrobe_wardrobe_topbottom.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_sides.png",
"wardrobe_wardrobe_front.png"
},
--inventory_image = "wardrobe_wardrobe_front.png",
sounds = default.node_sound_wood_defaults(),
groups = { choppy = 3, oddly_breakable_by_hand = 2, flammable = 3 },
on_rightclick = function(pos, node, player, itemstack, pointedThing)
showForm(player, 1);
end
});
minetest.register_craft(
{
output = "wardrobe:wardrobe",
recipe = { { "group:wood", "group:stick", "group:wood" },
{ "group:wood", "group:wool", "group:wood" },
{ "group:wood", "group:wool", "group:wood" } }
});