]> git.lizzy.rs Git - Crafter.git/blob - mods/utility/furnace.lua
Beds that respawn players to them
[Crafter.git] / mods / utility / furnace.lua
1 --[[
2 Mechanic ideology
3
4 spawn 3 entities - cook fuel output
5
6 detect on x or z axis
7
8 use recipe cook time
9
10 then pass output to cooked entity
11
12 when player hits entity then drop item towards player
13
14 when cooking have fire and smoke on cooking item
15
16 ]]--
17
18 --furnace class
19 minetest.register_craftitem("utility:nothing", {
20         description = "Nothing",
21         inventory_image = "wood.png",
22 })
23
24 local furnace = {}
25 --gap = 0.55
26 local fuel_height = 0.75
27 local cook_height = 1.3
28 local output_height = 1.85
29
30 --furnace
31 function furnace.get_hotbar_bg(x,y)
32         local out = ""
33         for i=0,7,1 do
34                 out = out .."image["..x+i..","..y..";1,1;gui_furnace_arrow_bg.png]"
35         end
36         return(out)
37 end
38
39 function furnace.get_inventory_drops(pos, inventory, drops)
40         local inv = minetest.get_meta(pos):get_inventory()
41         local n = #drops
42         for i = 1, inv:get_size(inventory) do
43                 local stack = inv:get_stack(inventory, i)
44                 if stack:get_count() > 0 then
45                         drops[n+1] = stack:to_table()
46                         n = n + 1
47                 end
48         end
49 end
50 --local aftercooked
51 --cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
52 --cookable = cooked.time ~= 0
53 --
54 -- Node definitions
55 --
56
57 local function furnace_setup(pos)
58         local obj = minetest.add_entity(vector.new(pos.x,pos.y+fuel_height,pos.z), "utility:fuel")
59         obj:get_luaentity().set_item(obj:get_luaentity(),"utility:nothing")
60         local obj = minetest.add_entity(vector.new(pos.x,pos.y+cook_height,pos.z), "utility:cook")
61         obj:get_luaentity().set_item(obj:get_luaentity(),"utility:nothing")
62         local obj = minetest.add_entity(vector.new(pos.x,pos.y+output_height,pos.z), "utility:output")
63         obj:get_luaentity().set_item(obj:get_luaentity(),"utility:nothing")
64 end
65
66 local function furnace_remove(pos)
67         for _,object in ipairs(minetest.get_objects_inside_radius(vector.new(pos.x,pos.y+fuel_height,pos.z), 0.1)) do
68                 if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "utility:fuel" then
69                         local pos = object:getpos()
70                         local item = object:get_luaentity().itemstring
71                         if item ~= "utility:nothing" then
72                                 local obj = minetest.add_item(pos,item)
73                                 obj:get_luaentity().collection_timer = 2                                
74                         end
75                         object:remove()
76                 end
77         end
78         for _,object in ipairs(minetest.get_objects_inside_radius(vector.new(pos.x,pos.y+cook_height,pos.z), 0.1)) do
79                 if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "utility:cook" then
80                         local pos = object:getpos()
81                         local item = object:get_luaentity().itemstring
82                         if item ~= "utility:nothing" then
83                                 local obj = minetest.add_item(pos,item)
84                                 obj:get_luaentity().collection_timer = 2
85                         end
86                         object:remove()
87                 end
88         end
89         for _,object in ipairs(minetest.get_objects_inside_radius(vector.new(pos.x,pos.y+output_height,pos.z), 0.1)) do
90                 if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "utility:output" then
91                         local pos = object:getpos()
92                         local item = object:get_luaentity().itemstring
93                         if item ~= "utility:nothing" then
94                                 local obj = minetest.add_item(pos,item)
95                                 obj:get_luaentity().collection_timer = 2
96                         end
97                         object:remove()
98                 end
99         end
100 end
101
102 minetest.register_node("utility:furnace", {
103         description = "Furnace",
104         tiles = {
105                 "furnace_top.png", "furnace_bottom.png",
106                 "furnace_side.png", "furnace_side.png",
107                 "furnace_side.png", "furnace_front.png"
108         },
109         paramtype2 = "facedir",
110         groups = {stone=2},
111         legacy_facedir_simple = true,
112         is_ground_content = false,
113         sounds = main.stoneSound(),
114         on_construct = function(pos)
115                 furnace_setup(pos)
116         end,
117         on_destruct = function(pos)
118                 furnace_remove(pos)
119         end,
120 })
121
122 minetest.register_craft({
123         output = "utility:furnace",
124         recipe = {
125                 {"main:stone", "main:stone", "main:stone"},
126                 {"main:stone", "",           "main:stone"},
127                 {"main:stone", "main:stone", "main:stone"},
128         }
129 })
130
131 --------------------------------------------------------------------------------------------------
132 --[[
133
134 minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) --check if cookable
135
136 minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) --check if fuel
137
138 space in between = 0.55
139
140 ]]--
141
142
143 --fuel entity
144 minetest.register_entity("utility:fuel", {
145         initial_properties = {
146                 hp_max = 1,
147                 physical = true,
148                 collide_with_objects = false,
149                 collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
150                 visual = "wielditem",
151                 visual_size = {x = 0.6, y = 0.6},
152                 textures = {""},
153                 spritediv = {x = 1, y = 1},
154                 initial_sprite_basepos = {x = 0, y = 0},
155                 is_visible = false,
156                 pointable = true,
157         },
158
159         itemstring = "",
160         count = 0,
161         cooking = false,
162         cook_timer = false,
163         fuel_timer = 0,
164
165         set_item = function(self, item)
166                 local stack = ItemStack(item or self.itemstring)
167                 self.itemstring = stack:to_string()
168                 --if self.itemstring == "" then
169                         -- item not yet known
170                 --      return
171                 --end
172                 
173                 local count = stack:get_count()
174                 self.count = count
175
176                 -- Backwards compatibility: old clients use the texture
177                 -- to get the type of the item
178                 local itemname = stack:is_known() and stack:get_name() or "unknown"
179
180                 local max_count = stack:get_stack_max()
181                 local size = 0.25
182                 local coll_height = size * 0.75
183                 local def = minetest.registered_nodes[itemname]
184                 --local glow = def and def.light_source
185
186                 self.object:set_properties({
187                         is_visible = true,
188                         visual = "wielditem",
189                         textures = {itemname},
190                         visual_size = {x = size, y = size},
191                         --collisionbox = {-size, -coll_height, -size,
192                         --      size, coll_height, size},
193                         selectionbox = {-size, -size, -size, size, size, size},
194                         automatic_rotate = math.pi * 0.5 * 0.2 / size,
195                         wield_item = self.itemstring,
196                         glow = glow,
197                 })
198         end,
199
200         get_staticdata = function(self)
201                 return minetest.serialize({
202                         itemstring = self.itemstring,
203                         count = self.count,                     
204                 })
205         end,
206
207         on_activate = function(self, staticdata, dtime_s)
208                 if string.sub(staticdata, 1, string.len("return")) == "return" then
209                         local data = minetest.deserialize(staticdata)
210                         if data and type(data) == "table" then
211                                 self.itemstring = data.itemstring
212                                 self.count = data.count
213                         end
214                 else
215                         self.itemstring = staticdata
216                 end
217                 self.object:set_armor_groups({immortal = 1})
218                 self.object:set_velocity({x = 0, y = 0, z = 0})
219                 self.object:set_acceleration({x = 0, y = 0, z = 0})
220                 self:set_item()
221         end,
222         
223         on_rightclick = function(self, clicker)
224                 
225                 if not clicker or not clicker:is_player() then
226                         return
227                 end
228                 
229                 local stack = clicker:get_wielded_item()
230                 
231                 local item = stack:get_name()
232                 local count = stack:get_count()
233                 if stack:get_name() == "utility:nothing" then
234                         count = 0
235                 end
236                 
237                 --shoot out existing item
238                 if self.itemstring ~= item.." "..count and self.itemstring ~= "utility:nothing" then
239                         local pos = self.object:getpos()
240                         local pos2 = clicker:getpos()
241                         pos2.y = pos2.y + 1.25
242                         local obj = minetest.add_item(pos,self.itemstring)
243                         local dir = vector.subtract(pos2,pos)
244                         vector.multiply(dir,5)
245                         
246                         if obj then
247                                 obj:setvelocity(vector.new(dir.x,dir.y+3.5,dir.z))
248                                 obj:get_luaentity().collection_timer = 2
249                         else
250                                 print("ERROR FURNACE RELEASED NON ITEM")
251                         end
252                 end
253                 
254                 if (item == "" or item == "hand:player") then
255                         self.set_item(self,"utility:nothing")
256                         self.object:set_nametag_attributes({
257                                 color = "red",
258                                 text = "",
259                         })
260                         return
261                 end
262                                 
263                 self.set_item(self, item.." "..count)
264                 
265                 self.object:set_nametag_attributes({
266                         color = "red",
267                         text = minetest.registered_items[item].description.." "..count,
268                 })
269                 
270                 stack = stack:clear()
271                 clicker:set_wielded_item("")
272         end,
273         
274         on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
275                 if not puncher or not puncher:is_player() then
276                         return
277                 end
278                 
279                 if self.itemstring == "utility:nothing" then
280                         return
281                 end
282                 
283                 local pos = self.object:getpos()
284                 local pos2 = puncher:getpos()
285                 pos2.y = pos2.y + 1.25
286                                 
287                 local obj = minetest.add_item(pos,self.itemstring)
288                 local dir = vector.subtract(pos2,pos)
289                 vector.multiply(dir,5)
290                 
291                 self.set_item(self,"utility:nothing")
292                 self.object:set_nametag_attributes({
293                         color = "red",
294                         text = "",
295                 })
296                 
297                 if obj then
298                         obj:setvelocity(vector.new(dir.x,dir.y+3.5,dir.z))
299                         obj:get_luaentity().collection_timer = 2
300                 else
301                         print("ERROR FURNACE RELEASED NON ITEM")
302                 end
303         end,
304
305         check_cook = function(self)
306                 local pos = self.object:getpos()
307                 --check the cook timer
308                 for _,object in ipairs(minetest.get_objects_inside_radius(vector.new(pos.x,pos.y+0.55,pos.z), 0.1)) do
309                         if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "utility:cook" then
310                                 local item = object:get_luaentity().itemstring
311                                 return(minetest.get_craft_result({method = "cooking", width = 1, items = {ItemStack(item)}}).time)
312                         end
313                 end
314         end,
315         
316         cook_item = function(self)
317                 local pos = self.object:getpos()
318                 for _,object in ipairs(minetest.get_objects_inside_radius(vector.new(pos.x,pos.y+0.55,pos.z), 0.1)) do
319                         if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "utility:cook" then
320                                 local item = ItemStack(object:get_luaentity().itemstring)
321                                 if not item then
322                                         return
323                                 end
324                                 local count = object:get_luaentity().count
325                                 local output = minetest.get_craft_result({method = "cooking", width = 1, items = {ItemStack(item)}}).item
326                                 local outputitem =  output:get_name()
327                                 local outputcount = output:get_count()
328                                 
329                                 
330                                 local itemname = item:get_name()
331                                 
332                                 count = count - 1
333                                 
334                                 object:get_luaentity().count = count
335                                 
336                                 local pos = self.object:getpos()
337                                 
338                                 --add to output
339                                 for _,object2 in ipairs(minetest.get_objects_inside_radius(vector.new(pos.x,pos.y+1.10,pos.z), 0.1)) do
340                                         if not object2:is_player() and object2:get_luaentity() and object2:get_luaentity().name == "utility:output" then
341                                                 local goal_item = ItemStack(object2:get_luaentity().itemstring)
342                                                 local goal_item_name = goal_item:get_name()
343                                                 local goal_item_count = goal_item:get_count()
344                                                 
345                                                 --cancel out if player took item
346                                                 if outputitem == "" then
347                                                         return
348                                                 end
349                                                 
350                                                 --add item to output or throw existing item out if not matched
351                                                 if goal_item_name ~= outputitem and goal_item_name ~= "utility:nothing" then
352                                                         local pos2 = object2:get_pos()
353                                                         local obj = minetest.add_item(pos2,object2:get_luaentity().itemstring)
354                                                         local dir = vector.new(math.random(-3,3),math.random(3,6),math.random(-3,3))
355                                                         --dir = vector.multiply(dir,2)
356                                                                                                                 
357                                                         if obj then
358                                                                 obj:setvelocity(vector.new(dir.x,dir.y,dir.z))
359                                                                 obj:get_luaentity().collection_timer = 2
360                                                         else
361                                                                 print("ERROR FURNACE RELEASED NON ITEM")
362                                                         end
363                                                         object2:get_luaentity().count = 0
364                                                 end
365                                                 
366                                                 object2:get_luaentity().count =  object2:get_luaentity().count + outputcount
367                                                 object2:get_luaentity().set_item(object2:get_luaentity(), outputitem.." "..object2:get_luaentity().count)
368                                                 object2:set_nametag_attributes({
369                                                         color = "blue",
370                                                         text = outputitem.." "..object2:get_luaentity().count,
371                                                 })
372                                                 
373                                         end
374                                 end
375                                 
376                                 --update count and nametag
377                                 if object:get_luaentity().count == 0 then
378                                         object:get_luaentity().set_item(object:get_luaentity(), "utility:nothing")
379                                         object:set_nametag_attributes({
380                                                 color = "blue",
381                                                 text = "",
382                                         })
383                                 else
384                                         object:get_luaentity().set_item(object:get_luaentity(), itemname.." "..count)
385                                         object:set_nametag_attributes({
386                                                 color = "blue",
387                                                 text = itemname.." "..count,
388                                         })
389                                 end
390                         end
391                 end
392         end,
393         
394         spawn_particles = function(self,time)
395                 --print("time:"..time)
396                 local pos = self.object:getpos()
397                 minetest.add_particlespawner({
398                         amount = math.floor(100*time),
399                         time = time,
400                         minpos = vector.new(pos.x-0.3,pos.y-0.3,pos.z-0.3),
401                         maxpos = vector.new(pos.x+0.3,pos.y+0.3,pos.z+0.3),
402                         minvel = {x=0, y=0.2, z=0},
403                         maxvel = {x=0, y=0.7, z=0},
404                         minacc = {x=0, y=0, z=0},
405                         maxacc = {x=0, y=0, z=0},
406                         minexptime = 1.1,
407                         maxexptime = 1.5,
408                         minsize = 1,
409                         maxsize = 2,
410                         collisiondetection = false,
411                         vertical = true,
412                         texture = "flame.png",
413                 })
414                 
415                 
416                 minetest.add_particlespawner({
417                         amount = math.floor(50*time),
418                         time = time,
419                         minpos = vector.new(pos.x-0.3,pos.y+0.3,pos.z-0.3),
420                         maxpos = vector.new(pos.x+0.3,pos.y+0.6,pos.z+0.3),
421                         minvel = {x=0, y=0.2, z=0},
422                         maxvel = {x=0, y=0.7, z=0},
423                         minacc = {x=0, y=0, z=0},
424                         maxacc = {x=0, y=0, z=0},
425                         minexptime = 1.1,
426                         maxexptime = 1.5,
427                         minsize = 1,
428                         maxsize = 2,
429                         collisiondetection = false,
430                         vertical = false,
431                         texture = "smoke.png",
432                 })
433         end,
434         
435         
436         
437         --check if item is in the input then cook if so
438         on_step = function(self, dtime)
439                 if self.cooking == true then
440                         self.cooking_timer = self.cooking_timer - dtime
441                         if self.cooking_timer < 0 then
442                                 self.cooking_timer = 0
443                                 self.cook_item(self)
444                                 self.cooking = false
445                         end                                     
446                 end
447                 
448                 --check to start cooking countdown
449                 if self.cooking == false then
450                         local stack = ItemStack(self.itemstring)
451                         local fuel = minetest.get_craft_result({method =  "fuel", width = 1, items = {stack}}).time
452                         if fuel ~= 0 then
453                                 local cookie = self.check_cook(self)
454                                 if cookie ~= 0 then
455                                         --print("starting timer")
456                                         self.spawn_particles(self,fuel)
457                                         self.cooking_timer = cookie
458                                         self.cooking = true
459                                         --set up the fuel timer
460                                         if self.fuel_timer == 0 then
461                                                 self.fuel_timer = fuel
462                                         end
463                                 end
464                         end
465                 end
466                 
467                 --deplete fuel
468                 if self.fuel_timer >= 0 then
469                         self.fuel_timer = self.fuel_timer - dtime
470                         --print(self.fuel_timer)
471                 elseif self.fuel_timer < 0 then
472                         if ItemStack(self.itemstring):get_name() == "utility:nothing" then
473                                 return
474                         end
475                         if self.cooking == false then
476                                 return
477                         end
478                         self.count = self.count - 1
479                         
480                         local count = self.count
481                         local itemname = ItemStack(self.itemstring):get_name()
482                         
483                         if self.count == 0 then
484                                 self.set_item(self, "utility:nothing")
485                                 self.object:set_nametag_attributes({
486                                         color = "red",
487                                         text = "",
488                                 })
489                         else
490                                 self.set_item(self, itemname.." "..count)
491                                 self.object:set_nametag_attributes({
492                                         color = "red",
493                                         text = itemname.." "..count,
494                                 })
495                         end
496                         
497                         if self.count == 0 then 
498                                 return
499                         end
500                         
501                         --reset timer
502                         if self.cooking == true then
503                                 --print("resetting timer")
504                                 local time = minetest.get_craft_result({method =  "fuel", width = 1, items = {ItemStack(self.itemstring)}}).time
505                                 self.fuel_timer = time
506                         end
507                 end
508         end,    
509 })
510
511 ----------------------------------------------------------------------------
512 --cook entity
513 minetest.register_entity("utility:cook", {
514         initial_properties = {
515                 hp_max = 1,
516                 physical = true,
517                 collide_with_objects = false,
518                 collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
519                 visual = "wielditem",
520                 visual_size = {x = 0.6, y = 0.6},
521                 textures = {""},
522                 spritediv = {x = 1, y = 1},
523                 initial_sprite_basepos = {x = 0, y = 0},
524                 is_visible = false,
525                 pointable = true,
526         },
527
528         itemstring = "",
529         count = 0,
530
531         set_item = function(self, item)
532                 local stack = ItemStack(item or self.itemstring)
533                 self.itemstring = stack:to_string()
534                 --if self.itemstring == "" then
535                         -- item not yet known
536                 --      return
537                 --end
538                 
539                 local count = stack:get_count()
540                 if stack:get_name() == "utility:nothing" then
541                         count = 0
542                 end
543                 self.count = count
544
545                 -- Backwards compatibility: old clients use the texture
546                 -- to get the type of the item
547                 local itemname = stack:is_known() and stack:get_name() or "unknown"
548
549                 local max_count = stack:get_stack_max()
550                 local size = 0.25
551                 local coll_height = size * 0.75
552                 local def = minetest.registered_nodes[itemname]
553                 --local glow = def and def.light_source
554
555                 self.object:set_properties({
556                         is_visible = true,
557                         visual = "wielditem",
558                         textures = {itemname},
559                         visual_size = {x = size, y = size},
560                         --collisionbox = {-size, -coll_height, -size,
561                         --      size, coll_height, size},
562                         selectionbox = {-size, -size, -size, size, size, size},
563                         automatic_rotate = math.pi * 0.5 * 0.2 / size,
564                         wield_item = self.itemstring,
565                         glow = glow,
566                 })
567         end,
568
569         get_staticdata = function(self)
570                 return minetest.serialize({
571                         itemstring = self.itemstring,
572                         count = self.count,                     
573                 })
574         end,
575
576         on_activate = function(self, staticdata, dtime_s)
577                 if string.sub(staticdata, 1, string.len("return")) == "return" then
578                         local data = minetest.deserialize(staticdata)
579                         if data and type(data) == "table" then
580                                 self.itemstring = data.itemstring
581                                 self.count = data.count
582                         end
583                 else
584                         self.itemstring = staticdata
585                 end
586                 self.object:set_armor_groups({immortal = 1})
587                 self.object:set_velocity({x = 0, y = 0, z = 0})
588                 self.object:set_acceleration({x = 0, y = 0, z = 0})
589                 self:set_item()
590         end,
591         
592         on_rightclick = function(self, clicker)
593                 
594                 if not clicker or not clicker:is_player() then
595                         return
596                 end
597                 
598                 local stack = clicker:get_wielded_item()
599                 
600                 local item = stack:get_name()
601                 local count = stack:get_count()
602                 
603                 --shoot out existing item
604                 if self.itemstring ~= item.." "..count and self.itemstring ~= "utility:nothing" then
605                         local pos = self.object:getpos()
606                         local pos2 = clicker:getpos()
607                         pos2.y = pos2.y + 1.25
608                         local obj = minetest.add_item(pos,self.itemstring)
609                         local dir = vector.subtract(pos2,pos)
610                         vector.multiply(dir,5)
611                         
612                         if obj then
613                                 obj:setvelocity(vector.new(dir.x,dir.y+3.5,dir.z))
614                                 obj:get_luaentity().collection_timer = 2
615                         else
616                                 print("ERROR FURNACE RELEASED NON ITEM")
617                         end
618                 end
619                 
620                 if (item == "" or item == "hand:player") then
621                         self.set_item(self,"utility:nothing")
622                         self.object:set_nametag_attributes({
623                                 color = "blue",
624                                 text = "",
625                         })
626                         return
627                 end
628                                 
629                 self.set_item(self, item.." "..count)
630                 
631                 self.object:set_nametag_attributes({
632                         color = "blue",
633                         text = minetest.registered_items[item].description.." "..count,
634                 })
635                 
636                 stack = stack:clear()
637                 clicker:set_wielded_item("")
638         end,
639         
640         on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
641                 if not puncher or not puncher:is_player() then
642                         return
643                 end
644                 
645                 if self.itemstring == "utility:nothing" then
646                         return
647                 end
648                 
649                 local pos = self.object:getpos()
650                 local pos2 = puncher:getpos()
651                 pos2.y = pos2.y + 1.25
652                                 
653                 local obj = minetest.add_item(pos,self.itemstring)
654                 local dir = vector.subtract(pos2,pos)
655                 vector.multiply(dir,5)
656                 
657                 self.set_item(self,"utility:nothing")
658                 self.object:set_nametag_attributes({
659                         color = "blue",
660                         text = "",
661                 })
662                 
663                 if obj then
664                         obj:setvelocity(vector.new(dir.x,dir.y+3.5,dir.z))
665                         obj:get_luaentity().collection_timer = 2
666                 else
667                         print("ERROR FURNACE RELEASED NON ITEM")
668                 end
669         end,
670
671
672         on_step = function(self, dtime)
673                 --set glow if cooking
674                 --local glow = def and def.light_source
675         end,
676 })
677 ----------------------------------------------------------------------------
678 --ouput entity
679 minetest.register_entity("utility:output", {
680         initial_properties = {
681                 hp_max = 1,
682                 physical = true,
683                 collide_with_objects = false,
684                 collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
685                 visual = "wielditem",
686                 visual_size = {x = 0.6, y = 0.6},
687                 textures = {""},
688                 spritediv = {x = 1, y = 1},
689                 initial_sprite_basepos = {x = 0, y = 0},
690                 is_visible = false,
691                 pointable = true,
692         },
693
694         itemstring = "",
695         count = 0,
696
697         set_item = function(self, item)
698                 local stack = ItemStack(item or self.itemstring)
699                 self.itemstring = stack:to_string()
700                 --if self.itemstring == "" then
701                         -- item not yet known
702                 --      return
703                 --end
704                 
705                 local count = stack:get_count()
706                 if stack:get_name() == "utility:nothing" then
707                         count = 0
708                 end
709                 self.count = count
710
711                 -- Backwards compatibility: old clients use the texture
712                 -- to get the type of the item
713                 local itemname = stack:is_known() and stack:get_name() or "unknown"
714
715                 local max_count = stack:get_stack_max()
716                 local size = 0.25
717                 local coll_height = size * 0.75
718                 local def = minetest.registered_nodes[itemname]
719                 --local glow = def and def.light_source
720
721                 self.object:set_properties({
722                         is_visible = true,
723                         visual = "wielditem",
724                         textures = {itemname},
725                         visual_size = {x = size, y = size},
726                         --collisionbox = {-size, -coll_height, -size,
727                         --      size, coll_height, size},
728                         selectionbox = {-size, -size, -size, size, size, size},
729                         automatic_rotate = math.pi * 0.5 * 0.2 / size,
730                         wield_item = self.itemstring,
731                         glow = glow,
732                 })
733         end,
734
735         get_staticdata = function(self)
736                 return minetest.serialize({
737                         itemstring = self.itemstring,
738                         count = self.count,                     
739                 })
740         end,
741
742         on_activate = function(self, staticdata, dtime_s)
743                 if string.sub(staticdata, 1, string.len("return")) == "return" then
744                         local data = minetest.deserialize(staticdata)
745                         if data and type(data) == "table" then
746                                 self.itemstring = data.itemstring
747                                 self.count = data.count
748                         end
749                 else
750                         self.itemstring = staticdata
751                 end
752                 self.object:set_armor_groups({immortal = 1})
753                 self.object:set_velocity({x = 0, y = 0, z = 0})
754                 self.object:set_acceleration({x = 0, y = 0, z = 0})
755                 self:set_item()
756         end,
757                 
758         on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
759                 if not puncher or not puncher:is_player() then
760                         return
761                 end
762                 
763                 if self.itemstring == "utility:nothing" then
764                         return
765                 end
766                 
767                 self.count = 0
768                 
769                 local pos = self.object:getpos()
770                 local pos2 = puncher:getpos()
771                 pos2.y = pos2.y + 1.25
772                                 
773                 local obj = minetest.add_item(pos,self.itemstring)
774                 local dir = vector.subtract(pos2,pos)
775                 vector.multiply(dir,5)
776                 
777                 self.set_item(self,"utility:nothing")
778                 self.object:set_nametag_attributes({
779                         color = "blue",
780                         text = "",
781                 })
782                 
783                 if obj then
784                         obj:setvelocity(vector.new(dir.x,dir.y+3.5,dir.z))
785                         obj:get_luaentity().collection_timer = 2
786                 else
787                         print("ERROR FURNACE RELEASED NON ITEM")
788                 end
789         end,
790
791
792         on_step = function(self, dtime)
793                 --set glow if cooking
794                 --local glow = def and def.light_source
795         end,
796 })
797
798
799 minetest.register_craft({
800         output = "utility:furnace",
801         recipe = {
802                 {"main:cobble", "main:cobble", "main:cobble"},
803                 {"main:cobble", "", "main:cobble"},
804                 {"main:cobble", "main:cobble", "main:cobble"},
805         },
806 })