From: pagliaccio Date: Tue, 23 Jul 2013 12:43:14 +0000 (+0200) Subject: Add MV and HV generators and make coal dust a fuel X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=704925aa7b2dc78dd7af86b71e0a95a64b3afce1;p=zefram%2Fminetest%2Ftechnic.git Add MV and HV generators and make coal dust a fuel --- diff --git a/technic/legacy.lua b/technic/legacy.lua index e6f7eb3..37fb1d5 100644 --- a/technic/legacy.lua +++ b/technic/legacy.lua @@ -22,6 +22,8 @@ technic.legacy_nodenames = { ["technic:lv_cable"] = "technic:lv_cable0", ["technic:mv_cable"] = "technic:mv_cable0", ["technic:mv_battery_box"] = "technic:mv_battery_box0", + ["technic:generator"] = "technic:lv_generator", + ["technic:generator_active"] = "technic:lv_generator_active", } for old, new in pairs(technic.legacy_nodenames) do diff --git a/technic/machines/HV/generator.lua b/technic/machines/HV/generator.lua new file mode 100644 index 0000000..d73b68a --- /dev/null +++ b/technic/machines/HV/generator.lua @@ -0,0 +1,14 @@ + +minetest.register_alias("hv_generator", "technic:hv_generator") + +minetest.register_craft({ + output = 'technic:hv_generator', + recipe = { + {'technic:stainless_steel_ingot', 'technic:mv_generator', 'technic:stainless_steel_ingot'}, + {'pipeworks:tube_000000', 'technic:hv_transformer', 'pipeworks:tube_000000'}, + {'technic:stainless_steel_ingot', 'technic:hv_cable', 'technic:stainless_steel_ingot'}, + } +}) + +technic.register_generator({tier="HV", supply=1200}) + diff --git a/technic/machines/HV/init.lua b/technic/machines/HV/init.lua index dc80673..908daed 100644 --- a/technic/machines/HV/init.lua +++ b/technic/machines/HV/init.lua @@ -9,4 +9,5 @@ dofile(path.."/forcefield.lua") dofile(path.."/battery_box.lua") dofile(path.."/solar_array.lua") dofile(path.."/nuclear_reactor.lua") +dofile(path.."/generator.lua") diff --git a/technic/machines/LV/generator.lua b/technic/machines/LV/generator.lua index 3358f67..eae7951 100644 --- a/technic/machines/LV/generator.lua +++ b/technic/machines/LV/generator.lua @@ -3,11 +3,10 @@ -- Inefficient and expensive in fuel (200EU per tick) -- Also only allows for LV machinery to run. -minetest.register_alias("generator", "technic:generator") -minetest.register_alias("generator", "technic:generator_active") +minetest.register_alias("lv_generator", "technic:lv_generator") minetest.register_craft({ - output = 'technic:generator', + output = 'technic:lv_generator', recipe = { {'default:stone', 'default:stone', 'default:stone'}, {'default:stone', '', 'default:stone'}, @@ -15,125 +14,5 @@ minetest.register_craft({ } }) -local generator_formspec = - "invsize[8,9;]".. - "label[0,0;Generator]".. - "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;]" - - -minetest.register_node("technic:generator", { - description = "Electric Generator", - tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png", - "technic_generator_side.png", "technic_generator_side.png", "technic_generator_front.png"}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("infotext", "Electric Generator") - meta:set_int("LV_EU_supply", 0) - -- Signal to the switching station that this device burns some - -- sort of fuel and needs special handling - meta:set_int("LV_EU_from_fuel", 1) - meta:set_int("burn_time", 0) - meta:set_string("formspec", generator_formspec) - local inv = meta:get_inventory() - inv:set_size("src", 1) - end, - can_dig = function(pos,player) - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") then - minetest.chat_send_player(player:get_player_name(), - "Machine cannot be removed because it is not empty"); - return false - else - return true - end - end, -}) - -minetest.register_node("technic:generator_active", { - description = "Electric Generator", - tiles = {"technic_generator_top.png", "technic_machine_bottom.png", - "technic_generator_side.png", "technic_generator_side.png", - "technic_generator_side.png", "technic_generator_front_active.png"}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, - not_in_creative_inventory=1}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - drop = "technic:generator", - can_dig = function(pos,player) - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("src") then - minetest.chat_send_player(player:get_player_name(), - "Machine cannot be removed because it is not empty"); - return false - else - return true - end - end, -}) - -minetest.register_abm({ - nodenames = {"technic:generator", "technic:generator_active"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - 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("LV_EU_supply", 200) -- Give 200EUs - 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") - fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) - if not fuel or fuel.time == 0 then - meta:set_string("infotext", "Generator out of fuel") - hacky_swap_node(pos, "technic: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) - hacky_swap_node(pos, "technic:generator_active") - meta:set_int("LV_EU_supply", 200) -- Give 200EUs - else - hacky_swap_node(pos, "technic:generator") - meta:set_int("LV_EU_supply", 0) - end - end - - local percent = math.floor((burn_time / burn_totaltime) * 100) - meta:set_string("infotext", "Electric Generator ("..percent.."%)") - meta:set_string("formspec", - "size[8,9]".. - "label[0,0;Generator]".. - "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 -}) - -technic.register_machine("LV", "technic:generator", technic.producer) -technic.register_machine("LV", "technic:generator_active", technic.producer) +technic.register_generator({tier="LV", supply=200}) diff --git a/technic/machines/LV/init.lua b/technic/machines/LV/init.lua index 291b0bd..dc47087 100644 --- a/technic/machines/LV/init.lua +++ b/technic/machines/LV/init.lua @@ -20,4 +20,3 @@ dofile(path.."/cnc_api.lua") dofile(path.."/cnc_nodes.lua") dofile(path.."/extractor.lua") dofile(path.."/compressor.lua") - diff --git a/technic/machines/MV/generator.lua b/technic/machines/MV/generator.lua new file mode 100644 index 0000000..973bbd2 --- /dev/null +++ b/technic/machines/MV/generator.lua @@ -0,0 +1,14 @@ + +minetest.register_alias("generator_mv", "technic:generator_mv") + +minetest.register_craft({ + output = 'technic:mv_generator', + recipe = { + {'technic:stainless_steel_ingot', 'technic:lv_generator', 'technic:stainless_steel_ingot'}, + {'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'}, + {'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'}, + } +}) + +technic.register_generator({tier="MV", supply=600}) + diff --git a/technic/machines/MV/init.lua b/technic/machines/MV/init.lua index af0f556..92d1da9 100644 --- a/technic/machines/MV/init.lua +++ b/technic/machines/MV/init.lua @@ -13,6 +13,7 @@ dofile(path.."/tool_workshop.lua") if technic.config:get_bool("enable_wind_mill") then dofile(path.."/wind_mill.lua") end +dofile(path.."/generator.lua") -- The power radiator supplies appliances with inductive coupled power: -- Lighting and associated textures is taken directly from VanessaE's homedecor and made electric. diff --git a/technic/machines/register/generator.lua b/technic/machines/register/generator.lua new file mode 100644 index 0000000..622da8b --- /dev/null +++ b/technic/machines/register/generator.lua @@ -0,0 +1,118 @@ + +function technic.register_generator(data) + local tier = data.tier + local ltier = string.lower(tier) + + local generator_formspec = + "invsize[8,9;]".. + "label[0,0;Generator]".. + "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;]" + + local desc = tier.." Generator" + minetest.register_node("technic:generator_"..ltier, { + 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", + groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + 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) + meta:set_string("formspec", generator_formspec) + local inv = meta:get_inventory() + inv:set_size("src", 1) + end, + can_dig = function(pos, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if not inv:is_empty("src") then + minetest.chat_send_player(player:get_player_name(), + "Machine cannot be removed because it is not empty") + return false + else + return true + end + end, + }) + 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", + groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, + not_in_creative_inventory=1}, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + drop = "technic:"..ltier.."_generator", + can_dig = function(pos, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if not inv:is_empty("src") then + minetest.chat_send_player(player:get_player_name(), + "Machine cannot be removed because it is not empty") + return false + else + return true + end + end, + }) + minetest.register_abm({ + nodenames = {"technic:"..ltier.."_generator", "technic:"..ltier.."_generator_active"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + 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(data.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") + fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + if not fuel or fuel.time == 0 then + meta:set_string("infotext", "Generator out of fuel") + hacky_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) + hacky_swap_node(pos, "technic:"..ltier.."_generator_active") + meta:set_int(data.tier.."_EU_supply", data.supply) + else + hacky_swap_node(pos, "technic:"..ltier.."_generator") + meta:set_int(data.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;Generator]".. + "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 + }) + technic.register_machine(data.tier, "technic:"..ltier.."_generator", technic.producer) + technic.register_machine(data.tier, "technic:"..ltier.."_generator", technic.producer) +end diff --git a/technic/machines/register/grinder_recipes.lua b/technic/machines/register/grinder_recipes.lua index 09ab060..4f30f08 100644 --- a/technic/machines/register/grinder_recipes.lua +++ b/technic/machines/register/grinder_recipes.lua @@ -93,4 +93,8 @@ register_dust("Stainless Steel", "technic:stainless_steel_ingot") register_dust("Talinite", "glooptest:talinite_ingot") register_dust("Tin", "moreores:tin_ingot") register_dust("Zinc", "technic:zinc_ingot") - +minetest.register_craft({ + type = "fuel", + recipe = "technic:coal_dust", + burntime = 50, +}) diff --git a/technic/machines/register/init.lua b/technic/machines/register/init.lua index d3af184..673b265 100644 --- a/technic/machines/register/init.lua +++ b/technic/machines/register/init.lua @@ -8,4 +8,5 @@ dofile(path.."/electric_furnace.lua") dofile(path.."/grinder.lua") dofile(path.."/grinder_recipes.lua") dofile(path.."/solar_array.lua") +dofile(path.."/generator.lua") diff --git a/technic/textures/technic_generator_front.png b/technic/textures/technic_generator_front.png deleted file mode 100644 index 2d64844..0000000 Binary files a/technic/textures/technic_generator_front.png and /dev/null differ diff --git a/technic/textures/technic_generator_front_active.png b/technic/textures/technic_generator_front_active.png deleted file mode 100644 index 4e57ca0..0000000 Binary files a/technic/textures/technic_generator_front_active.png and /dev/null differ diff --git a/technic/textures/technic_generator_side.png b/technic/textures/technic_generator_side.png deleted file mode 100644 index 5cbcbef..0000000 Binary files a/technic/textures/technic_generator_side.png and /dev/null differ diff --git a/technic/textures/technic_generator_top.png b/technic/textures/technic_generator_top.png deleted file mode 100644 index e2f3db3..0000000 Binary files a/technic/textures/technic_generator_top.png and /dev/null differ diff --git a/technic/textures/technic_hv_generator_front.png b/technic/textures/technic_hv_generator_front.png new file mode 100644 index 0000000..6a14686 Binary files /dev/null and b/technic/textures/technic_hv_generator_front.png differ diff --git a/technic/textures/technic_hv_generator_front_active.png b/technic/textures/technic_hv_generator_front_active.png new file mode 100644 index 0000000..d92c699 Binary files /dev/null and b/technic/textures/technic_hv_generator_front_active.png differ diff --git a/technic/textures/technic_hv_generator_side.png b/technic/textures/technic_hv_generator_side.png new file mode 100644 index 0000000..3073e0f Binary files /dev/null and b/technic/textures/technic_hv_generator_side.png differ diff --git a/technic/textures/technic_hv_generator_top.png b/technic/textures/technic_hv_generator_top.png new file mode 100644 index 0000000..646168c Binary files /dev/null and b/technic/textures/technic_hv_generator_top.png differ diff --git a/technic/textures/technic_lv_generator_front.png b/technic/textures/technic_lv_generator_front.png new file mode 100644 index 0000000..2d64844 Binary files /dev/null and b/technic/textures/technic_lv_generator_front.png differ diff --git a/technic/textures/technic_lv_generator_front_active.png b/technic/textures/technic_lv_generator_front_active.png new file mode 100644 index 0000000..4e57ca0 Binary files /dev/null and b/technic/textures/technic_lv_generator_front_active.png differ diff --git a/technic/textures/technic_lv_generator_side.png b/technic/textures/technic_lv_generator_side.png new file mode 100644 index 0000000..5cbcbef Binary files /dev/null and b/technic/textures/technic_lv_generator_side.png differ diff --git a/technic/textures/technic_lv_generator_top.png b/technic/textures/technic_lv_generator_top.png new file mode 100644 index 0000000..e2f3db3 Binary files /dev/null and b/technic/textures/technic_lv_generator_top.png differ diff --git a/technic/textures/technic_mv_generator_front.png b/technic/textures/technic_mv_generator_front.png new file mode 100644 index 0000000..570e0c5 Binary files /dev/null and b/technic/textures/technic_mv_generator_front.png differ diff --git a/technic/textures/technic_mv_generator_front_active.png b/technic/textures/technic_mv_generator_front_active.png new file mode 100644 index 0000000..3006a17 Binary files /dev/null and b/technic/textures/technic_mv_generator_front_active.png differ diff --git a/technic/textures/technic_mv_generator_side.png b/technic/textures/technic_mv_generator_side.png new file mode 100644 index 0000000..21c0d41 Binary files /dev/null and b/technic/textures/technic_mv_generator_side.png differ diff --git a/technic/textures/technic_mv_generator_top.png b/technic/textures/technic_mv_generator_top.png new file mode 100644 index 0000000..7afa5a1 Binary files /dev/null and b/technic/textures/technic_mv_generator_top.png differ