est31
2015-06-18 a793747d92d9b1d93153c7fb4e0c82fe90624c78
commit | author | age
ee0765 1
7c4b70 2 -- Fuel driven alloy furnace. This uses no EUs:
ee0765 3
be2f30 4 local S = technic.getter
ee0765 5
S 6 minetest.register_craft({
7     output = 'technic:coal_alloy_furnace',
8     recipe = {
9         {'default:brick', 'default:brick', 'default:brick'},
10         {'default:brick', '',              'default:brick'},
11         {'default:brick', 'default:brick', 'default:brick'},
12     }
13 })
14
611c77 15 local machine_name = S("Fuel-Fired Alloy Furnace")
Z 16 local formspec =
17     "size[8,9]"..
18     "label[0,0;"..machine_name.."]"..
19     "image[2,2;1,1;default_furnace_fire_bg.png]"..
20     "list[current_name;fuel;2,3;1,1;]"..
21     "list[current_name;src;2,1;2,1;]"..
22     "list[current_name;dst;5,1;2,2;]"..
d732c8 23     "list[current_player;main;0,5;8,4;]"..
E 24     "listring[current_name;dst]"..
25     "listring[current_player;main]"..
26     "listring[current_name;src]"..
27     "listring[current_player;main]"..
28     "listring[current_name;fuel]"..
29     "listring[current_player;main]"
611c77 30
ee0765 31 minetest.register_node("technic:coal_alloy_furnace", {
611c77 32     description = machine_name,
0809dd 33     tiles = {"technic_coal_alloy_furnace_top.png",  "technic_coal_alloy_furnace_bottom.png",
S 34              "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png",
35              "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front.png"},
ee0765 36     paramtype2 = "facedir",
S 37     groups = {cracky=2},
38     legacy_facedir_simple = true,
39     sounds = default.node_sound_stone_defaults(),
40     on_construct = function(pos)
a41390 41         local meta = minetest.get_meta(pos)
611c77 42         meta:set_string("formspec", formspec)
Z 43         meta:set_string("infotext", machine_name)
ee0765 44         local inv = meta:get_inventory()
S 45         inv:set_size("fuel", 1)
d55ecc 46         inv:set_size("src", 2)
ee0765 47         inv:set_size("dst", 4)
S 48     end,
0809dd 49     can_dig = technic.machine_can_dig,
S 50     allow_metadata_inventory_put = technic.machine_inventory_put,
51     allow_metadata_inventory_take = technic.machine_inventory_take,
52     allow_metadata_inventory_move = technic.machine_inventory_move,
ee0765 53 })
S 54
55 minetest.register_node("technic:coal_alloy_furnace_active", {
611c77 56     description = machine_name,
0809dd 57     tiles = {"technic_coal_alloy_furnace_top.png",  "technic_coal_alloy_furnace_bottom.png",
S 58              "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png",
59              "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front_active.png"},
ee0765 60     paramtype2 = "facedir",
S 61     light_source = 8,
62     drop = "technic:coal_alloy_furnace",
63     groups = {cracky=2, not_in_creative_inventory=1},
64     legacy_facedir_simple = true,
65     sounds = default.node_sound_stone_defaults(),
0809dd 66     can_dig = technic.machine_can_dig,
S 67     allow_metadata_inventory_put = technic.machine_inventory_put,
68     allow_metadata_inventory_take = technic.machine_inventory_take,
69     allow_metadata_inventory_move = technic.machine_inventory_move,
ee0765 70 })
S 71
72 minetest.register_abm({
73     nodenames = {"technic:coal_alloy_furnace", "technic:coal_alloy_furnace_active"},
74     interval = 1,
75     chance = 1,
76     action = function(pos, node, active_object_count, active_object_count_wider)
77         local meta = minetest.get_meta(pos)
78         local inv    = meta:get_inventory()
d55ecc 79         
N 80         if inv:get_size("src") == 1 then -- Old furnace -> convert it
81             inv:set_size("src", 2)
82             inv:set_stack("src", 2, inv:get_stack("src2", 1))
83             inv:set_size("src2", 0)
84         end
85         
ee0765 86         local recipe = nil
S 87
88         for i, name in pairs({
89                 "fuel_totaltime",
90                 "fuel_time",
91                 "src_totaltime",
92                 "src_time"}) do
93             if not meta:get_float(name) then
94                 meta:set_float(name, 0.0)
95             end
96         end
97
98         -- Get what to cook if anything
d55ecc 99         local result = technic.get_recipe("alloy", inv:get_list("src"))
ee0765 100
S 101         local was_active = false
102
103         if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
104             was_active = true
105             meta:set_int("fuel_time", meta:get_int("fuel_time") + 1)
d55ecc 106             if result then
ee0765 107                 meta:set_int("src_time", meta:get_int("src_time") + 1)
d55ecc 108                 if meta:get_int("src_time") >= result.time then
ee0765 109                     meta:set_int("src_time", 0)
d55ecc 110                     local result_stack = ItemStack(result.output)
N 111                     if inv:room_for_item("dst", result_stack) then
112                         inv:set_list("src", result.new_input)
113                         inv:add_item("dst", result_stack)
114                     end
ee0765 115                 end
S 116             else
117                 meta:set_int("src_time", 0)
118             end
119         end
120
121         if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
122             local percent = math.floor(meta:get_float("fuel_time") /
123                     meta:get_float("fuel_totaltime") * 100)
be2f30 124             meta:set_string("infotext", S("%s Active"):format(machine_name).." ("..percent.."%)")
f3d8b4 125             technic.swap_node(pos, "technic:coal_alloy_furnace_active")
ee0765 126             meta:set_string("formspec",
S 127                     "size[8,9]"..
be2f30 128                     "label[0,0;"..machine_name.."]"..
ee0765 129                     "image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
be2f30 130                     (100 - percent)..":default_furnace_fire_fg.png]"..
ee0765 131                     "list[current_name;fuel;2,3;1,1;]"..
d55ecc 132                     "list[current_name;src;2,1;2,1;]"..
ee0765 133                     "list[current_name;dst;5,1;2,2;]"..
d732c8 134                     "list[current_player;main;0,5;8,4;]"..
E 135                     "listring[current_name;dst]"..
136                     "listring[current_player;main]"..
137                     "listring[current_name;src]"..
138                     "listring[current_player;main]"..
139                     "listring[current_name;fuel]"..
140                     "listring[current_player;main]")
ee0765 141             return
S 142         end
143
d55ecc 144         local recipe = technic.get_recipe("alloy", inv:get_list("src"))
ee0765 145
d55ecc 146         if not recipe then
ee0765 147             if was_active then
d55ecc 148                 meta:set_string("infotext", S("%s is empty"):format(machine_name))
f3d8b4 149                 technic.swap_node(pos, "technic:coal_alloy_furnace")
ee0765 150                 meta:set_string("formspec", formspec)
S 151             end
152             return
153         end
154
155         -- Next take a hard look at the fuel situation
156         local fuel = nil
9290e6 157         local afterfuel
ee0765 158         local fuellist = inv:get_list("fuel")
S 159
160         if fuellist then
9290e6 161             fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
ee0765 162         end
S 163
164         if fuel.time <= 0 then
be2f30 165             meta:set_string("infotext", S("%s Out Of Fuel"):format(machine_name))
f3d8b4 166             technic.swap_node(pos, "technic:coal_alloy_furnace")
ee0765 167             meta:set_string("formspec", formspec)
S 168             return
169         end
170
171         meta:set_string("fuel_totaltime", fuel.time)
172         meta:set_string("fuel_time", 0)
173
9290e6 174         inv:set_stack("fuel", 1, afterfuel.items[1])
ee0765 175     end,
S 176 })
177