Disable treespawning on mapgen
[minetest_hades.git] / mods / default / prismafurnance.lua
blob353e69c47585b3e6a8f5c72ae436ed3fc0e50425
1 Prismafurnance={}
2 function default.get_pfurnace_active_formspec(pos, percent)
3 local formspec =
4 "size[8,9]"..
5 "image[2,2;1,1;default_pfurnace_fire_bg.png^[lowpart:"..
6 (100-percent)..":default_pfurnace_fire_fg.png]"..
7 "list[current_name;fuel;2,3;1,1;]"..
8 "list[current_name;src;2,1;1,1;]"..
9 "list[current_name;dst;5,1;2,2;]"..
10 "list[current_player;main;0,5;8,4;]"..
11 "background[-0.5,-0.65;9,10.35;".."pfurnace.png".."]"..
12 "listcolors[#001100;#006600;#ffffff;#006600;#ffffff]"
13 return formspec
14 end
17 default.pfurnace_inactive_formspec =
18 "size[8,9]"..
19 "image[2,2;1,1;default_pfurnace_fire_bg.png]"..
20 "list[current_name;fuel;2,3;1,1;]"..
21 "list[current_name;src;2,1;1,1;]"..
22 "list[current_name;dst;5,1;2,2;]"..
23 "list[current_player;main;0,5;8,4;]"..
24 "background[-0.5,-0.65;9,10.35;".."pfurnace.png".."]"..
25 "listcolors[#001100;#006600;#ffffff;#006600;#ffffff]"
28 minetest.register_node("default:pfurnace", {
29 description = "Prisma Furnace",
30 tiles = {"default_pfurnace_top.png", "default_pfurnace_bottom.png", "default_pfurnace_side.png",
31 "default_pfurnace_side.png", "default_pfurnace_side.png", "default_pfurnace_front.png"},
32 paramtype2 = "facedir",
33 groups = {cracky=2},
34 legacy_facedir_simple = true,
35 is_ground_content = false,
36 sounds = default.node_sound_stone_defaults(),
37 on_construct = function(pos)
38 local meta = minetest.get_meta(pos)
39 meta:set_string("formspec", default.pfurnace_inactive_formspec)
40 meta:set_string("infotext", "Prisma-Furnace")
41 local inv = meta:get_inventory()
42 inv:set_size("fuel", 1)
43 inv:set_size("src", 1)
44 inv:set_size("dst", 4)
45 end,
46 can_dig = function(pos,player)
47 local meta = minetest.get_meta(pos);
48 local inv = meta:get_inventory()
49 if not inv:is_empty("fuel") then
50 return false
51 elseif not inv:is_empty("dst") then
52 return false
53 elseif not inv:is_empty("src") then
54 return false
55 end
56 return true
57 end,
58 allow_metadata_inventory_put = function(pos, listname, index, stack, player)
59 local meta = minetest.get_meta(pos)
60 local inv = meta:get_inventory()
61 if listname == "fuel" then
62 if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
63 if inv:is_empty("src") then
64 meta:set_string("infotext","Prisma-Furnace is empty")
65 end
66 return stack:get_count()
67 else
68 return 0
69 end
70 elseif listname == "src" then
71 return stack:get_count()
72 elseif listname == "dst" then
73 return 0
74 end
75 end,
76 allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
77 local meta = minetest.get_meta(pos)
78 local inv = meta:get_inventory()
79 local stack = inv:get_stack(from_list, from_index)
80 if to_list == "fuel" then
81 if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
82 if inv:is_empty("src") then
83 meta:set_string("infotext","Prisma-Furnace is empty")
84 end
85 return count
86 else
87 return 0
88 end
89 elseif to_list == "src" then
90 return count
91 elseif to_list == "dst" then
92 return 0
93 end
94 end,
98 minetest.register_node("default:pfurnace_active", {
99 description = "Prisma Furnace",
100 tiles = {
101 "default_pfurnace_top.png",
102 "default_pfurnace_bottom.png",
103 "default_pfurnace_side.png",
104 "default_pfurnace_side.png",
105 "default_pfurnace_side.png",
107 image = "default_pfurnace_front_active.png",
108 backface_culling = false,
109 animation = {
110 type = "vertical_frames",
111 aspect_w = 16,
112 aspect_h = 16,
113 length = 1.5
117 paramtype2 = "facedir",
118 light_source = 8,
119 drop = "default:pfurnace",
120 groups = {cracky=2, not_in_creative_inventory=1,hot=1},
121 legacy_facedir_simple = true,
122 is_ground_content = false,
123 sounds = default.node_sound_stone_defaults(),
124 on_construct = function(pos)
125 local meta = minetest.get_meta(pos)
126 meta:set_string("formspec", default.pfurnace_inactive_formspec)
127 meta:set_string("infotext", "Prisma-Furnace");
128 local inv = meta:get_inventory()
129 inv:set_size("fuel", 1)
130 inv:set_size("src", 1)
131 inv:set_size("dst", 4)
132 end,
133 can_dig = function(pos,player)
134 local meta = minetest.get_meta(pos);
135 local inv = meta:get_inventory()
136 if not inv:is_empty("fuel") then
137 return false
138 elseif not inv:is_empty("dst") then
139 return false
140 elseif not inv:is_empty("src") then
141 return false
143 return true
144 end,
145 allow_metadata_inventory_put = function(pos, listname, index, stack, player)
146 local meta = minetest.get_meta(pos)
147 local inv = meta:get_inventory()
148 if listname == "fuel" then
149 if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
150 if inv:is_empty("src") then
151 meta:set_string("infotext","Prisma-Furnace is empty")
153 return stack:get_count()
154 else
155 return 0
157 elseif listname == "src" then
158 return stack:get_count()
159 elseif listname == "dst" then
160 return 0
162 end,
163 allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
164 local meta = minetest.get_meta(pos)
165 local inv = meta:get_inventory()
166 local stack = inv:get_stack(from_list, from_index)
167 if to_list == "fuel" then
168 if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
169 if inv:is_empty("src") then
170 meta:set_string("infotext","Prisma-Furnace is empty")
172 return count
173 else
174 return 0
176 elseif to_list == "src" then
177 return count
178 elseif to_list == "dst" then
179 return 0
181 end,
185 local function swap_node(pos,name)
186 local node = minetest.get_node(pos)
187 if node.name == name then
188 return
190 node.name = name
191 minetest.swap_node(pos,node)
195 minetest.register_abm({
196 nodenames = {"default:pfurnace","default:pfurnace_active"},
197 interval = 1.0,
198 chance = 1,
199 action = function(pos, node, active_object_count, active_object_count_wider)
200 local meta = minetest.get_meta(pos)
201 for i, name in ipairs({
202 "fuel_totaltime",
203 "fuel_time",
204 "src_totaltime",
205 "src_time"
206 }) do
207 if meta:get_string(name) == "" then
208 meta:set_float(name, 0.0)
213 local inv = meta:get_inventory()
216 local srclist = inv:get_list("src")
217 local cooked = nil
218 local aftercooked
221 if srclist then
222 cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
226 local was_active = false
229 if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
230 was_active = true
231 meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
232 meta:set_float("src_time", meta:get_float("src_time") + 4.25)
233 if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
234 -- check if there's room for output in "dst" list
235 if inv:room_for_item("dst",cooked.item) then
236 -- Put result in "dst" list
237 inv:add_item("dst", cooked.item)
238 -- take stuff from "src" list
239 inv:set_stack("src", 1, aftercooked.items[1])
240 else
241 --print("Could not insert '"..cooked.item:to_string().."'")
243 meta:set_string("src_time", 0)
248 if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
249 local percent = math.floor(meta:get_float("fuel_time") /
250 meta:get_float("fuel_totaltime") * 100)
251 meta:set_string("infotext","Prisma-Furnace active: "..percent.."%")
252 swap_node(pos,"default:pfurnace_active")
253 --sound (brandon reese (adventuretest))
254 if meta:get_int("sound_played") == nil or ( os.time() - meta:get_int("sound_played") ) >= 4 then
255 minetest.sound_play("default_furnace",{pos=pos})
256 meta:set_string("sound_played",os.time())
258 --endsound
259 meta:set_string("formspec",default.get_pfurnace_active_formspec(pos, percent))
260 return
264 local fuel = nil
265 local afterfuel
266 local cooked = nil
267 local fuellist = inv:get_list("fuel")
268 local srclist = inv:get_list("src")
271 if srclist then
272 cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
274 if fuellist then
275 fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
279 if not fuel or fuel.time <= 0 then
280 meta:set_string("infotext","Prisma-Furnace out of fuel")
281 swap_node(pos,"default:pfurnace")
282 meta:set_string("formspec", default.pfurnace_inactive_formspec)
283 return
287 if cooked.item:is_empty() then
288 if was_active then
289 meta:set_string("infotext","Prisma-Furnace is empty")
290 swap_node(pos,"default:pfurnace")
291 meta:set_string("formspec", default.pfurnace_inactive_formspec)
293 return
297 meta:set_string("fuel_totaltime", fuel.time)
298 meta:set_string("fuel_time", 0)
301 inv:set_stack("fuel", 1, afterfuel.items[1])
302 end,
305 minetest.register_craft({
306 output = 'default:pfurnace',
307 recipe = {
308 {'default:obsidian', 'default:obsidian', 'default:obsidian'},
309 {'default:steel_ingot', 'travelnet:prismatic_gem', 'default:obsidian'},
310 {'default:obsidian', 'default:obsidian', 'default:obsidian'},