2013-10-30 18:45:32 +01:00
|
|
|
local S = technic.getter
|
|
|
|
|
2013-12-01 18:45:45 +01:00
|
|
|
local tube = {
|
|
|
|
insert_object = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2013-12-03 21:30:09 +01:00
|
|
|
return inv:add_item("src", stack)
|
2013-12-01 18:45:45 +01:00
|
|
|
end,
|
|
|
|
can_insert = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:room_for_item("src", stack)
|
|
|
|
end,
|
|
|
|
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
|
|
|
|
}
|
|
|
|
|
2013-07-23 14:43:14 +02:00
|
|
|
function technic.register_generator(data)
|
|
|
|
local tier = data.tier
|
|
|
|
local ltier = string.lower(tier)
|
2013-12-03 21:30:09 +01:00
|
|
|
|
2014-07-11 11:00:46 +02:00
|
|
|
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1}
|
|
|
|
local active_groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1, not_in_creative_inventory=1}
|
2013-12-01 18:45:45 +01:00
|
|
|
if data.tube then
|
|
|
|
groups.tubedevice = 1
|
|
|
|
groups.tubedevice_receiver = 1
|
|
|
|
active_groups.tubedevice = 1
|
|
|
|
active_groups.tubedevice_receiver = 1
|
|
|
|
end
|
2013-12-03 21:30:09 +01:00
|
|
|
|
2013-07-23 14:43:14 +02:00
|
|
|
local generator_formspec =
|
|
|
|
"invsize[8,9;]"..
|
Rationalise machine terminology
All electrically-powered machines now consistently indicate their
tier (supply voltage) in their names. As this implies that they are
electrically powered, the furnaces no longer have "Electric" in their
names. The fuel-fired equivalents of electric machines, which exist
for alloy furnace and furnace, now say "Fuel-Fired" to distinguish them.
(The fuel-fired alloy furnace used to say "Coal", which was inaccurate
because it uses any fuel. The fuel-fired furnace, from the default mod,
used to just be called "Furnace", which is ambiguous.)
Electric power generators now consistently indicate their tier and have
the word "Generator" in their names. This makes their purpose much
clearer, and makes obvious craft guide searches produce useful results.
The fuel-fired generators, previously just (ambiguously) called
"Generator", are now explicitly "Fuel-Fired".
2014-06-20 17:58:52 +02:00
|
|
|
"label[0,0;"..S("Fuel-Fired %s Generator"):format(tier).."]"..
|
2013-07-23 14:43:14 +02:00
|
|
|
"list[current_name;src;3,1;1,1;]"..
|
|
|
|
"image[4,1;1,1;default_furnace_fire_bg.png]"..
|
|
|
|
"list[current_player;main;0,5;8,4;]"
|
|
|
|
|
Rationalise machine terminology
All electrically-powered machines now consistently indicate their
tier (supply voltage) in their names. As this implies that they are
electrically powered, the furnaces no longer have "Electric" in their
names. The fuel-fired equivalents of electric machines, which exist
for alloy furnace and furnace, now say "Fuel-Fired" to distinguish them.
(The fuel-fired alloy furnace used to say "Coal", which was inaccurate
because it uses any fuel. The fuel-fired furnace, from the default mod,
used to just be called "Furnace", which is ambiguous.)
Electric power generators now consistently indicate their tier and have
the word "Generator" in their names. This makes their purpose much
clearer, and makes obvious craft guide searches produce useful results.
The fuel-fired generators, previously just (ambiguously) called
"Generator", are now explicitly "Fuel-Fired".
2014-06-20 17:58:52 +02:00
|
|
|
local desc = S("Fuel-Fired %s Generator"):format(tier)
|
2014-07-11 11:00:46 +02:00
|
|
|
|
|
|
|
local run = function(pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local burn_time = meta:get_int("burn_time")
|
|
|
|
local burn_totaltime = meta:get_int("burn_totaltime")
|
|
|
|
-- If more to burn and the energy produced was used: produce some more
|
|
|
|
if burn_time > 0 then
|
|
|
|
meta:set_int(tier.."_EU_supply", data.supply)
|
|
|
|
burn_time = burn_time - 1
|
|
|
|
meta:set_int("burn_time", burn_time)
|
|
|
|
end
|
|
|
|
-- Burn another piece of fuel
|
|
|
|
if burn_time == 0 then
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if not inv:is_empty("src") then
|
|
|
|
local fuellist = inv:get_list("src")
|
|
|
|
local fuel = minetest.get_craft_result(
|
|
|
|
{method = "fuel", width = 1,
|
|
|
|
items = fuellist})
|
|
|
|
if not fuel or fuel.time == 0 then
|
|
|
|
meta:set_string("infotext", S("%s Out Of Fuel"):format(desc))
|
|
|
|
technic.swap_node(pos, "technic:"..ltier.."_generator")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
meta:set_int("burn_time", fuel.time)
|
|
|
|
meta:set_int("burn_totaltime", fuel.time)
|
|
|
|
local stack = inv:get_stack("src", 1)
|
|
|
|
stack:take_item()
|
|
|
|
inv:set_stack("src", 1, stack)
|
|
|
|
technic.swap_node(pos, "technic:"..ltier.."_generator_active")
|
|
|
|
meta:set_int(tier.."_EU_supply", data.supply)
|
|
|
|
else
|
|
|
|
technic.swap_node(pos, "technic:"..ltier.."_generator")
|
|
|
|
meta:set_int(tier.."_EU_supply", 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if burn_totaltime == 0 then burn_totaltime = 1 end
|
|
|
|
local percent = math.floor((burn_time / burn_totaltime) * 100)
|
|
|
|
meta:set_string("infotext", desc.." ("..percent.."%)")
|
|
|
|
meta:set_string("formspec",
|
|
|
|
"size[8, 9]"..
|
|
|
|
"label[0, 0;"..minetest.formspec_escape(desc).."]"..
|
|
|
|
"list[current_name;src;3, 1;1, 1;]"..
|
|
|
|
"image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:"..
|
|
|
|
(percent)..":default_furnace_fire_fg.png]"..
|
|
|
|
"list[current_player;main;0, 5;8, 4;]")
|
|
|
|
end
|
|
|
|
|
2013-10-28 19:37:40 +01:00
|
|
|
minetest.register_node("technic:"..ltier.."_generator", {
|
2013-07-23 14:43:14 +02:00
|
|
|
description = desc,
|
|
|
|
tiles = {"technic_"..ltier.."_generator_top.png", "technic_machine_bottom.png",
|
|
|
|
"technic_"..ltier.."_generator_side.png", "technic_"..ltier.."_generator_side.png",
|
|
|
|
"technic_"..ltier.."_generator_side.png", "technic_"..ltier.."_generator_front.png"},
|
|
|
|
paramtype2 = "facedir",
|
2013-12-01 18:45:45 +01:00
|
|
|
groups = groups,
|
2013-07-23 14:43:14 +02:00
|
|
|
legacy_facedir_simple = true,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2013-12-01 18:45:45 +01:00
|
|
|
tube = data.tube and tube or nil,
|
2013-07-23 14:43:14 +02:00
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("infotext", desc)
|
|
|
|
meta:set_int(data.tier.."_EU_supply", 0)
|
|
|
|
meta:set_int("burn_time", 0)
|
2013-12-01 18:45:45 +01:00
|
|
|
meta:set_int("tube_time", 0)
|
2013-07-23 14:43:14 +02:00
|
|
|
meta:set_string("formspec", generator_formspec)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("src", 1)
|
|
|
|
end,
|
2013-11-27 18:28:56 +01:00
|
|
|
can_dig = technic.machine_can_dig,
|
|
|
|
allow_metadata_inventory_put = technic.machine_inventory_put,
|
|
|
|
allow_metadata_inventory_take = technic.machine_inventory_take,
|
|
|
|
allow_metadata_inventory_move = technic.machine_inventory_move,
|
2014-07-11 11:00:46 +02:00
|
|
|
technic_run = run,
|
2013-07-23 14:43:14 +02:00
|
|
|
})
|
2013-11-27 18:28:56 +01:00
|
|
|
|
2013-07-23 14:43:14 +02:00
|
|
|
minetest.register_node("technic:"..ltier.."_generator_active", {
|
|
|
|
description = desc,
|
|
|
|
tiles = {"technic_"..ltier.."_generator_top.png", "technic_machine_bottom.png",
|
|
|
|
"technic_"..ltier.."_generator_side.png", "technic_"..ltier.."_generator_side.png",
|
|
|
|
"technic_"..ltier.."_generator_side.png", "technic_"..ltier.."_generator_front_active.png"},
|
|
|
|
paramtype2 = "facedir",
|
2013-12-01 18:45:45 +01:00
|
|
|
groups = active_groups,
|
2013-07-23 14:43:14 +02:00
|
|
|
legacy_facedir_simple = true,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2013-12-01 18:45:45 +01:00
|
|
|
tube = data.tube and tube or nil,
|
2013-07-23 14:43:14 +02:00
|
|
|
drop = "technic:"..ltier.."_generator",
|
2013-11-27 18:28:56 +01:00
|
|
|
can_dig = technic.machine_can_dig,
|
|
|
|
allow_metadata_inventory_put = technic.machine_inventory_put,
|
|
|
|
allow_metadata_inventory_take = technic.machine_inventory_take,
|
|
|
|
allow_metadata_inventory_move = technic.machine_inventory_move,
|
2014-07-11 11:00:46 +02:00
|
|
|
technic_run = run,
|
2014-07-12 09:50:50 +02:00
|
|
|
technic_on_disable = function(pos, node)
|
|
|
|
local timer = minetest.get_node_timer(pos)
|
|
|
|
timer:start(1)
|
|
|
|
end,
|
|
|
|
on_timer = function(pos, node)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
|
|
|
-- Connected back?
|
|
|
|
if meta:get_int(tier.."_EU_timeout") > 0 then return end
|
|
|
|
|
|
|
|
local burn_time = meta:get_int("burn_time") or 0
|
|
|
|
|
|
|
|
if burn_time <= 0 then
|
|
|
|
meta:set_int(tier.."_EU_supply", 0)
|
|
|
|
meta:set_int("burn_time", 0)
|
|
|
|
technic.swap_node(pos, "technic:"..ltier.."_generator")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local burn_totaltime = meta:get_int("burn_totaltime") or 0
|
|
|
|
if burn_totaltime == 0 then burn_totaltime = 1 end
|
|
|
|
burn_time = burn_time - 1
|
|
|
|
meta:set_int("burn_time", burn_time)
|
|
|
|
local percent = math.floor(burn_time / burn_totaltime * 100)
|
|
|
|
meta:set_string("formspec",
|
|
|
|
"size[8, 9]"..
|
|
|
|
"label[0, 0;"..minetest.formspec_escape(desc).."]"..
|
|
|
|
"list[current_name;src;3, 1;1, 1;]"..
|
|
|
|
"image[4, 1;1, 1;default_furnace_fire_bg.png^[lowpart:"..
|
|
|
|
(percent)..":default_furnace_fire_fg.png]"..
|
|
|
|
"list[current_player;main;0, 5;8, 4;]")
|
|
|
|
local timer = minetest.get_node_timer(pos)
|
|
|
|
timer:start(1)
|
|
|
|
end,
|
2013-07-23 14:43:14 +02:00
|
|
|
})
|
2014-07-11 11:00:46 +02:00
|
|
|
|
2013-11-27 22:56:09 +01:00
|
|
|
technic.register_machine(tier, "technic:"..ltier.."_generator", technic.producer)
|
|
|
|
technic.register_machine(tier, "technic:"..ltier.."_generator_active", technic.producer)
|
2013-07-23 14:43:14 +02:00
|
|
|
end
|
2013-10-30 18:45:32 +01:00
|
|
|
|