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