Maciej Kasatkin
2012-10-09 eabde42244a4f541c13ee8f39b3542fb26d8af9b
commit | author | age
eabde4 1 minetest.register_alias("coal_furnace", "technic:coal_furnace")
MK 2
3 minetest.register_craft({
4     output = 'technic:coal_furnace',
5     recipe = {
6         {'default:stone', 'default:stone', 'default:stone'},
7         {'default:stone', '', 'default:stone'},
8         {'default:stone', 'default:stone', 'default:stone'},
9     }
10 })
11
12
13 coal_furnace_formspec =
14     "invsize[8,9;]"..
15     "image[1,1;1,2;technic_power_meter_bg.png]"..
16     "list[current_name;src;3,1;1,1;]"..
17     "list[current_name;dst;5,1;2,2;]"..
18     "list[current_player;main;0,5;8,4;]"..
19     "label[0,0;Coal Furnace]")
20     
21 minetest.register_node("technic:coal_furnace", {
22     description = "Coal furnace",
23     tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png",
24         "technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front.png"},
25     paramtype2 = "facedir",
26     groups = {cracky=2},
27     legacy_facedir_simple = true,
28     sounds = default.node_sound_stone_defaults(),
29     technic_power_machine=1,
30     internal_EU_buffer=0;
31     interal_EU_buffer_size=2000;
32     on_construct = function(pos)
33         local meta = minetest.env:get_meta(pos)
34         meta:set_string("formspec", coal_furnace_formspec)
35         meta:set_string("infotext", "Coal furnace")
36         local inv = meta:get_inventory()
37         inv:set_size("src", 1)
38         inv:set_size("dst", 4)
39         local EU_used  = 0
40         local furnace_is_cookin = 0
41         local cooked = nil
42         meta:set_float("internal_EU_buffer",0)
43         meta:set_float("internal_EU_buffer_size",2000)
44
45     end,
46     can_dig = function(pos,player)
47         local meta = minetest.env:get_meta(pos);
48         local inv = meta:get_inventory()
49         if not inv:is_empty("dst") then
50             return false
51         elseif not inv:is_empty("src") then
52             return false
53         end
54         return true
55     end,
56 })
57
58 minetest.register_node("technic:coal_furnace_active", {
59     description = "Coal Furnace",
60     tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png",
61         "technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front_active.png"},
62     paramtype2 = "facedir",
63     light_source = 8,
64     drop = "technic:coal_furnace",
65     groups = {cracky=2, not_in_creative_inventory=1},
66     legacy_facedir_simple = true,
67     sounds = default.node_sound_stone_defaults(),
68     internal_EU_buffer=0;
69     interal_EU_buffer_size=2000;
70     technic_power_machine=1,
71     on_construct = function(pos)
72         local meta = minetest.env:get_meta(pos)
73         meta:set_string("formspec", electric_furnace_formspec)
74         meta:set_string("infotext", "Coal furnace");
75         local inv = meta:get_inventory()
76         inv:set_size("src", 1)
77         inv:set_size("dst", 4)
78         local EU_used  = 0
79         local furnace_is_cookin = 0
80         local cooked = nil
81     end,
82     can_dig = function(pos,player)
83         local meta = minetest.env:get_meta(pos);
84         local inv = meta:get_inventory()
85         if not inv:is_empty("dst") then
86             return false
87         elseif not inv:is_empty("src") then
88             return false
89         end
90         return true
91     end,
92 })
93
94 minetest.register_abm({
95     nodenames = {"technic:coal_furnace","technic:coal_furnace_active"},
96     interval = 1,
97     chance = 1,
98     
99     action = function(pos, node, active_object_count, active_object_count_wider)
100
101         local meta = minetest.env:get_meta(pos)
102         internal_EU_buffer=meta:get_float("internal_EU_buffer")
103         internal_EU_buffer_size=meta:get_float("internal_EU_buffer")
104         local load = math.floor(internal_EU_buffer/2000 * 100)
105         meta:set_string("formspec",
106                 "invsize[8,9;]"..
107                 "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
108                         (load)..":technic_power_meter_fg.png]"..
109                 "list[current_name;src;3,1;1,1;]"..
110                 "list[current_name;dst;5,1;2,2;]"..
111                 "list[current_player;main;0,5;8,4;]"..
112                 "label[0,0;Electric Furnace]")
113
114         local inv = meta:get_inventory()
115         
116         local furnace_is_cookin = meta:get_float("furnace_is_cookin")
117         
118         
119         local srclist = inv:get_list("src")
120         local cooked=nil 
121
122         if srclist then
123          cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
124         end
125         
126         
127         if (furnace_is_cookin == 1) then
128             if internal_EU_buffer>=150 then
129             internal_EU_buffer=internal_EU_buffer-150;
130             meta:set_float("internal_EU_buffer",internal_EU_buffer)
131             meta:set_float("src_time", meta:get_float("src_time") + 3)
132             if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
133                 -- check if there's room for output in "dst" list
134                 if inv:room_for_item("dst",cooked.item) then
135                     -- Put result in "dst" list
136                     inv:add_item("dst", cooked.item)
137                     -- take stuff from "src" list
138                     srcstack = inv:get_stack("src", 1)
139                     srcstack:take_item()
140                     inv:set_stack("src", 1, srcstack)
141                 else
142                     print("Furnace inventory full!")
143                 end
144                 meta:set_string("src_time", 0)
145             end
146             end        
147         end
148         
149         
150
151         
152         if srclist then
153             cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
154             if cooked.time>0 then 
155             hacky_swap_node(pos,"technic:coal_furnace_active")
156             meta:set_string("infotext","Furnace active")
157             meta:set_string("furnace_is_cookin",1)
158             meta:set_string("src_time", 0)
159             return
160             end
161
162         end
163     
164                 hacky_swap_node(pos,"technic:coal_furnace")
165                 meta:set_string("infotext","Furnace inactive")
166                 meta:set_string("furnace_is_cookin",0)
167                 meta:set_string("src_time", 0)
168         
169     
170 end,        
171 })