David Leal
2020-06-12 a8daa417c485ee20716ec050d4c676b5c91af773
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({
78f16c 73     label = "Machines: run coal alloy furnace",
ee0765 74     nodenames = {"technic:coal_alloy_furnace", "technic:coal_alloy_furnace_active"},
S 75     interval = 1,
76     chance = 1,
77     action = function(pos, node, active_object_count, active_object_count_wider)
78         local meta = minetest.get_meta(pos)
79         local inv    = meta:get_inventory()
a8daa4 80
d55ecc 81         if inv:get_size("src") == 1 then -- Old furnace -> convert it
N 82             inv:set_size("src", 2)
83             inv:set_stack("src", 2, inv:get_stack("src2", 1))
84             inv:set_size("src2", 0)
85         end
ee0765 86
S 87         for i, name in pairs({
88                 "fuel_totaltime",
89                 "fuel_time",
90                 "src_totaltime",
91                 "src_time"}) do
92             if not meta:get_float(name) then
93                 meta:set_float(name, 0.0)
94             end
95         end
96
97         -- Get what to cook if anything
d55ecc 98         local result = technic.get_recipe("alloy", inv:get_list("src"))
ee0765 99
S 100         local was_active = false
101
102         if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
103             was_active = true
104             meta:set_int("fuel_time", meta:get_int("fuel_time") + 1)
d55ecc 105             if result then
ee0765 106                 meta:set_int("src_time", meta:get_int("src_time") + 1)
d55ecc 107                 if meta:get_int("src_time") >= result.time then
ee0765 108                     meta:set_int("src_time", 0)
d55ecc 109                     local result_stack = ItemStack(result.output)
N 110                     if inv:room_for_item("dst", result_stack) then
111                         inv:set_list("src", result.new_input)
112                         inv:add_item("dst", result_stack)
113                     end
ee0765 114                 end
S 115             else
116                 meta:set_int("src_time", 0)
117             end
118         end
119
120         if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
121             local percent = math.floor(meta:get_float("fuel_time") /
122                     meta:get_float("fuel_totaltime") * 100)
be2f30 123             meta:set_string("infotext", S("%s Active"):format(machine_name).." ("..percent.."%)")
f3d8b4 124             technic.swap_node(pos, "technic:coal_alloy_furnace_active")
ee0765 125             meta:set_string("formspec",
S 126                     "size[8,9]"..
be2f30 127                     "label[0,0;"..machine_name.."]"..
ee0765 128                     "image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
be2f30 129                     (100 - percent)..":default_furnace_fire_fg.png]"..
ee0765 130                     "list[current_name;fuel;2,3;1,1;]"..
d55ecc 131                     "list[current_name;src;2,1;2,1;]"..
ee0765 132                     "list[current_name;dst;5,1;2,2;]"..
d732c8 133                     "list[current_player;main;0,5;8,4;]"..
E 134                     "listring[current_name;dst]"..
135                     "listring[current_player;main]"..
136                     "listring[current_name;src]"..
137                     "listring[current_player;main]"..
138                     "listring[current_name;fuel]"..
139                     "listring[current_player;main]")
ee0765 140             return
S 141         end
142
d55ecc 143         local recipe = technic.get_recipe("alloy", inv:get_list("src"))
ee0765 144
d55ecc 145         if not recipe then
ee0765 146             if was_active then
d55ecc 147                 meta:set_string("infotext", S("%s is empty"):format(machine_name))
f3d8b4 148                 technic.swap_node(pos, "technic:coal_alloy_furnace")
ee0765 149                 meta:set_string("formspec", formspec)
S 150             end
151             return
152         end
153
154         -- Next take a hard look at the fuel situation
155         local fuel = nil
9290e6 156         local afterfuel
ee0765 157         local fuellist = inv:get_list("fuel")
S 158
159         if fuellist then
9290e6 160             fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
ee0765 161         end
S 162
163         if fuel.time <= 0 then
be2f30 164             meta:set_string("infotext", S("%s Out Of Fuel"):format(machine_name))
f3d8b4 165             technic.swap_node(pos, "technic:coal_alloy_furnace")
ee0765 166             meta:set_string("formspec", formspec)
S 167             return
168         end
169
170         meta:set_string("fuel_totaltime", fuel.time)
171         meta:set_string("fuel_time", 0)
172
9290e6 173         inv:set_stack("fuel", 1, afterfuel.items[1])
ee0765 174     end,
S 175 })
176