Rename mod: walls → hades_walls
[minetest_hades/hades_revisited.git] / mods / gluncarp / machines.lua
blob368585c6fd91de96e079ec9e57ed37057a3fb68d
1 local S = minetest.get_translator("gluncarp")
2 local F = minetest.formspec_escape
4 local colors = {
5 "black",
6 "blue",
7 "brown",
8 "cyan",
9 "dark_green",
10 "dark_grey",
11 "green",
12 "grey",
13 "magenta",
14 "orange",
15 "pink",
16 "red",
17 "violet",
18 "white",
19 "yellow",
20 "blackgold",
23 minetest.register_node("gluncarp:machine", {
24 description = S("Carpet Workstation"),
25 _tt_help = S("Turns cloth to carpets"),
26 tiles = {
27 "gluncarp_machine_top.png",
28 "gluncarp_machine_bottom.png",
29 "gluncarp_machine_side2.png",
30 "gluncarp_machine_side1.png",
31 "gluncarp_machine_back.png",
32 "gluncarp_machine_front.png"
34 drawtype = "nodebox",
35 paramtype = "light",
36 paramtype2 = "facedir",
37 is_ground_content = false,
38 groups = {oddly_breakable_by_hand=2, choppy=3},
39 node_box = {
40 type = "fixed",
41 fixed = {
42 {-0.5, -0.5, -0.125, 0.5, -0.375, 0.125},
43 {-0.5, 0.375, 0.0625, 0.5, 0.4375, 0.125},
44 {0.4375, -0.375, -0.125, 0.5, 0.375, -0.0625},
45 {-0.5, -0.375, -0.125, -0.4375, 0.375, -0.0625},
46 {0.21875, -0.375, -0.03125, 0.28125, 0.5, 0.03125},
47 {-0.28125, -0.375, -0.03125, -0.21875, 0.5, 0.03125},
48 {-0.03125, -0.4375, -0.03125, 0.03125, 0.5, 0.03125},
49 {-0.3125, -0.3125, -0.03125, 0.3125, 0.3125, 0.03125},
50 {-0.5, -0.5, -0.25, 0.5, -0.4375, 0.25},
51 {0.4375, -0.4375, 0.0625, 0.5, 0.4375, 0.125},
52 {-0.5, -0.4375, 0.0625, -0.4375, 0.4375, 0.125},
53 {-0.5, 0.375, -0.125, 0.5, 0.4375, -0.0625},
54 {-0.5, 0.375, -0.125, -0.375, 0.4375, 0.125},
55 {0.375, 0.375, -0.125, 0.5, 0.4375, 0.125},
56 {0.21875, 0.375, -0.0625, 0.28125, 0.4375, 0.0625},
57 {-0.03125, 0.375, -0.0625, 0.03125, 0.4375, 0.0625},
58 {-0.28125, 0.375, -0.0625, -0.21875, 0.4375, 0.0625},
61 selection_box = {
62 type = 'fixed',
63 fixed = {
64 {-0.5, -0.5, -0.25, 0.5, 0.5, 0.25}
67 sounds = hades_sounds.node_sound_wood_defaults(),
69 after_place_node = function(pos, placer)
70 local meta = minetest.get_meta(pos);
71 meta:set_string("owner", (placer:get_player_name() or ""));
72 meta:set_string("infotext", S("Carpet workstation (owned by @1)", placer:get_player_name() or ""));
73 end,
75 on_rotate = "simple",
77 can_dig = function(pos,player)
78 local meta = minetest.get_meta(pos);
79 local inv = meta:get_inventory()
80 if not inv:is_empty("wool") then
81 return false
82 elseif not inv:is_empty("res") then
83 return false
84 end
85 return true
86 end,
88 on_construct = function(pos)
89 local meta = minetest.get_meta(pos)
90 meta:set_string("formspec", "size[10,6;]"..
91 "bgcolor[#00000000;neither]"..
92 "background9[6,6;10,6;gluncarp_background.png;true;6]"..
93 "list[current_name;wool;3,0.5;1,1;]"..
94 "list[current_name;res;6,0.5;1,1;]"..
95 "label[3,0;"..F(S("Cloth:")).."]"..
96 "label[6,0;"..F(S("Output:")).."]"..
98 "label[4.5,0;"..F(S("Craft:")).."]"..
99 "image_button[4.5,0.5;1,1;gluncarp_mach1.png;carpet; ]"..
101 "list[current_player;main;0,2;10,4;]"..
102 "listring[current_player;main]"..
103 "listring[current_name;wool]"..
104 "listring[current_player;main]"..
105 "listring[current_name;res]")
106 meta:set_string("infotext", S("Carpet workstation"))
107 local inv = meta:get_inventory()
108 -- Input slot (called "wool" for historic reasons only)
109 inv:set_size("wool", 1)
110 inv:set_size("res", 1)
111 end,
113 on_receive_fields = function(pos, formname, fields, sender)
114 local meta = minetest.get_meta(pos)
115 local inv = meta:get_inventory()
117 if not fields["carpet"] then
118 return
121 local count, material
122 if fields["carpet"] then
123 if inv:is_empty("wool") then
124 return
128 local clothstack = inv:get_stack("wool", 1)
129 local clothname = clothstack:get_name()
130 local resstack = inv:get_stack("res", 1)
131 ----------------------------------------------------------------------
132 --Register Items
133 ----------------------------------------------------------------------
134 for col=1,#colors do
135 local color = colors[col]
136 if clothname == "cloth:"..color then
137 material = color
138 count = 4
139 elseif clothname == "gluncarp:wool_"..color then
140 material = color
141 count = 4
142 elseif clothname == "hades_stairs:slab_"..color then
143 material = color
144 count = 2
145 elseif clothname == "hades_stairs:stair_"..color then
146 material = color
147 count = 3
148 elseif clothname == "hades_stairs:stair_in_"..color then
149 material = color
150 count = 4
151 elseif clothname == "hades_stairs:stair_out_"..color then
152 material = color
153 count = 4
156 ----------------------------------------------------------------------
157 if material then
158 local output_item = "gluncarp:"..material
159 if not inv:is_empty("res") then
160 if resstack:get_name() ~= output_item then
161 return
162 elseif resstack:get_count() == resstack:get_stack_max() then
163 return
166 local success = false
167 for i = 0, count-1 do
168 local result = inv:add_item("res", output_item)
169 if result ~= nil then
170 success = true
173 if success then
174 clothstack:take_item()
175 inv:set_stack("wool", 1, clothstack)
177 end
178 end,
182 --Craft
184 minetest.register_craft({
185 output = 'gluncarp:machine',
186 recipe = {
187 {'group:wood', 'group:stick', 'group:wood'},
188 {'hades_farming:string', 'hades_farming:string', 'hades_farming:string'},
189 {'group:wood', "group:stick", 'group:wood'},