From f97367b5779eec8288b362a439fe81ced0cf315c Mon Sep 17 00:00:00 2001 From: runningscissors Date: Tue, 14 Jul 2015 17:05:44 -0400 Subject: [PATCH] added multi-tier geothermal --- technic/machines/HV/geothermal.lua | 18 +++ technic/machines/HV/init.lua | 1 + technic/machines/LV/geothermal.lua | 116 +++---------------- technic/machines/LV/init.lua | 1 + technic/machines/LV/oldgeo.lua | 14 +++ technic/machines/MV/geothermal.lua | 35 ++++++ technic/machines/MV/init.lua | 1 + technic/machines/register/geothermal.lua | 139 +++++++++++++++++++++++ technic/machines/register/init.lua | 1 + 9 files changed, 223 insertions(+), 103 deletions(-) create mode 100644 technic/machines/HV/geothermal.lua create mode 100644 technic/machines/LV/oldgeo.lua create mode 100644 technic/machines/MV/geothermal.lua create mode 100644 technic/machines/register/geothermal.lua diff --git a/technic/machines/HV/geothermal.lua b/technic/machines/HV/geothermal.lua new file mode 100644 index 0000000..ec02b1f --- /dev/null +++ b/technic/machines/HV/geothermal.lua @@ -0,0 +1,18 @@ + +--- An HV geothermal EU generator +--- Using hot lava and water this device can create energy from steam + + + + +minetest.register_craft({ + output = 'technic:geothermal_hv 1', + recipe = { + {'technic:geothermal_mv', 'technic:geothermal_mv', 'technic:geothermal_mv'}, + {'technic:carbon_plate', 'technic:hv_transformer', 'technic:composite_plate'}, + {'', 'technic:hv_cable0', ''}, + } +}) + +technic.register_geothermal({tier="HV", power=100}) + diff --git a/technic/machines/HV/init.lua b/technic/machines/HV/init.lua index d7136b4..6c6637b 100644 --- a/technic/machines/HV/init.lua +++ b/technic/machines/HV/init.lua @@ -11,6 +11,7 @@ dofile(path.."/battery_box.lua") dofile(path.."/solar_array.lua") dofile(path.."/nuclear_reactor.lua") dofile(path.."/generator.lua") +dofile(path.."/geothermal.lua") -- Machines dofile(path.."/quarry.lua") diff --git a/technic/machines/LV/geothermal.lua b/technic/machines/LV/geothermal.lua index e88d3c9..bbb3186 100644 --- a/technic/machines/LV/geothermal.lua +++ b/technic/machines/LV/geothermal.lua @@ -1,111 +1,21 @@ --- A geothermal EU generator --- Using hot lava and water this device can create energy from steam --- The machine is only producing LV EUs and can thus not drive more advanced equipment --- The output is a little more than the coal burning generator (max 300EUs) -minetest.register_alias("geothermal", "technic:geothermal") -local S = technic.getter +--- A geothermal EU generator +--- Using hot lava and water this device can create energy from steam +--- The machine is only producing LV EUs and can thus not drive more advanced equipment +--- The output is a little more than the coal burning generator (max 300EUs) + minetest.register_craft({ - output = 'technic:geothermal', + output = 'technic:geothermal_lv 1', recipe = { - {'technic:granite', 'default:diamond', 'technic:granite'}, - {'technic:fine_copper_wire', 'technic:machine_casing', 'technic:fine_copper_wire'}, - {'technic:granite', 'technic:lv_cable0', 'technic:granite'}, - } + {'technic:granite', 'default:diamond', 'technic:granite'}, + {'technic:fine_copper_wire', 'technic:machine_casing', 'technic:fine_copper_wire'}, + {'technic:granite', 'technic:lv_cable0', 'technic:granite'}, + } }) -minetest.register_craftitem("technic:geothermal", { - description = S("Geothermal %s Generator"):format("LV"), -}) - -local check_node_around = function(pos) - local node = minetest.get_node(pos) - if node.name == "default:water_source" or node.name == "default:water_flowing" then return 1 end - if node.name == "default:lava_source" or node.name == "default:lava_flowing" then return 2 end - return 0 -end - -local run = function(pos, node) - local meta = minetest.get_meta(pos) - local water_nodes = 0 - local lava_nodes = 0 - local production_level = 0 - local eu_supply = 0 - - -- Correct positioning is water on one side and lava on the other. - -- The two cannot be adjacent because the lava the turns into obsidian or rock. - -- To get to 100% production stack the water and lava one extra block down as well: - -- WGL (W=Water, L=Lava, G=the generator, |=an LV cable) - -- W|L - - local positions = { - {x=pos.x+1, y=pos.y, z=pos.z}, - {x=pos.x+1, y=pos.y-1, z=pos.z}, - {x=pos.x-1, y=pos.y, z=pos.z}, - {x=pos.x-1, y=pos.y-1, z=pos.z}, - {x=pos.x, y=pos.y, z=pos.z+1}, - {x=pos.x, y=pos.y-1, z=pos.z+1}, - {x=pos.x, y=pos.y, z=pos.z-1}, - {x=pos.x, y=pos.y-1, z=pos.z-1}, - } - for _, p in pairs(positions) do - local check = check_node_around(p) - if check == 1 then water_nodes = water_nodes + 1 end - if check == 2 then lava_nodes = lava_nodes + 1 end - end - - if water_nodes == 1 and lava_nodes == 1 then production_level = 25; eu_supply = 50 end - if water_nodes == 2 and lava_nodes == 1 then production_level = 50; eu_supply = 100 end - if water_nodes == 1 and lava_nodes == 2 then production_level = 75; eu_supply = 200 end - if water_nodes == 2 and lava_nodes == 2 then production_level = 100; eu_supply = 300 end - - if production_level > 0 then - meta:set_int("LV_EU_supply", eu_supply) - end - - meta:set_string("infotext", - S("Geothermal %s Generator"):format("LV").." ("..production_level.."%)") - - if production_level > 0 and minetest.get_node(pos).name == "technic:geothermal" then - technic.swap_node (pos, "technic:geothermal_active") - return - end - if production_level == 0 then - technic.swap_node(pos, "technic:geothermal") - meta:set_int("LV_EU_supply", 0) - end -end - -minetest.register_node("technic:geothermal", { - description = S("Geothermal %s Generator"):format("LV"), - tiles = {"technic_geothermal_top.png", "technic_machine_bottom.png", "technic_geothermal_side.png", - "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, - paramtype2 = "facedir", - groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1}, - legacy_facedir_simple = true, - sounds = default.node_sound_wood_defaults(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("infotext", S("Geothermal %s Generator"):format("LV")) - meta:set_int("LV_EU_supply", 0) - end, - technic_run = run, -}) - -minetest.register_node("technic:geothermal_active", { - description = S("Geothermal %s Generator"):format("LV"), - tiles = {"technic_geothermal_top_active.png", "technic_machine_bottom.png", "technic_geothermal_side.png", - "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.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:geothermal", - technic_run = run, -}) - -technic.register_machine("LV", "technic:geothermal", technic.producer) -technic.register_machine("LV", "technic:geothermal_active", technic.producer) +technic.register_geothermal({tier="LV", power=10}) +minetest.register_alias("geothermal", "technic:geothermal_lv") +minetest.register_alias("technic:geothermal", "technic:geothermal_lv") diff --git a/technic/machines/LV/init.lua b/technic/machines/LV/init.lua index 30523c9..24d9ffc 100644 --- a/technic/machines/LV/init.lua +++ b/technic/machines/LV/init.lua @@ -13,6 +13,7 @@ dofile(path.."/solar_array.lua") dofile(path.."/geothermal.lua") dofile(path.."/water_mill.lua") dofile(path.."/generator.lua") +dofile(path.."/oldgeo.lua") -- Machines dofile(path.."/alloy_furnace.lua") diff --git a/technic/machines/LV/oldgeo.lua b/technic/machines/LV/oldgeo.lua new file mode 100644 index 0000000..57a5d4f --- /dev/null +++ b/technic/machines/LV/oldgeo.lua @@ -0,0 +1,14 @@ + + +--- old non tiered one +--- A geothermal EU generator +--- Using hot lava and water this device can create energy from steam +--- The machine is only producing LV EUs and can thus not drive more advanced equipment +--- The output is a little more than the coal burning generator (max 300EUs) + + + + + +technic.register_geothermal({tier="LV", power=10, old=true}) + diff --git a/technic/machines/MV/geothermal.lua b/technic/machines/MV/geothermal.lua new file mode 100644 index 0000000..5f2f4dd --- /dev/null +++ b/technic/machines/MV/geothermal.lua @@ -0,0 +1,35 @@ + + +--- An MV geothermal EU generator +--- Using hot lava and water this device can create energy from steam + + + +minetest.register_craft({ + output = 'technic:geothermal_mv 1', + recipe = { + {'technic:geothermal_lv', 'technic:geothermal_lv', 'technic:geothermal_lv'}, + {'technic:carbon_steel_ingot', 'technic:mv_transformer', 'technic:carbon_steel_ingot'}, + {'', 'technic:mv_cable0', ''}, + } +}) + + +minetest.register_craft({ + output = 'technic:geothermal_mv 1', + recipe = { + {'technic:geothermal', 'technic:geothermal', 'technic:geothermal'}, + {'technic:carbon_steel_ingot', 'technic:mv_transformer', 'technic:carbon_steel_ingot'}, + {'', 'technic:mv_cable0', ''}, + } +}) + + + + + + +technic.register_geothermal({tier="MV", power=30}) + +-- compatibility alias for upgrading from old versions of technic +--minetest.register_alias("technic:geothermal_mv", "technic:geothermal_mv") diff --git a/technic/machines/MV/init.lua b/technic/machines/MV/init.lua index 72a98b6..84ea5e2 100644 --- a/technic/machines/MV/init.lua +++ b/technic/machines/MV/init.lua @@ -13,6 +13,7 @@ if technic.config:get_bool("enable_wind_mill") then end dofile(path.."/generator.lua") dofile(path.."/solar_array.lua") +dofile(path.."/geothermal.lua") -- Machines dofile(path.."/alloy_furnace.lua") diff --git a/technic/machines/register/geothermal.lua b/technic/machines/register/geothermal.lua new file mode 100644 index 0000000..0cb4544 --- /dev/null +++ b/technic/machines/register/geothermal.lua @@ -0,0 +1,139 @@ +local S = technic.getter + +function technic.register_geothermal(data) + local tier = data.tier + local ltier = string.lower(tier) + + local off_name = "technic:geothermal_"..ltier + local on_name = "technic:geothermal_active_"..ltier + + local texture_name = "technic_"..ltier .. "_geothermal" + + local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1} + local description = S("Geothermal %s Generator"):format(tier) + + if data.old then + + off_name = "technic:geothermal" + on_name = "technic:geothermal_active" + groups.not_in_creative_inventory=1 + description = "Old "..description + texture_name = "technic_geothermal" + end + + + local check_node_around = function(pos) + local node = minetest.get_node(pos) + if node.name == "default:water_source" or node.name == "default:water_flowing" then return 1 end + if node.name == "default:lava_source" or node.name == "default:lava_flowing" then return 2 end + return 0 + end + + + local run = function(pos, node) + local meta = minetest.get_meta(pos) + local water_nodes = 0 + local lava_nodes = 0 + local production_level = 0 + local eu_supply = 0 + + + + + + -- Correct positioning is water on one side and lava on the other. + -- The two cannot be adjacent because the lava the turns into obsidian or rock. + -- To get to 100% production stack the water and lava one extra block down as well: + -- WGL (W=Water, L=Lava, G=the generator, |=an LV cable) + -- W|L + + local positions = { + {x=pos.x+1, y=pos.y, z=pos.z}, + {x=pos.x+1, y=pos.y-1, z=pos.z}, + {x=pos.x-1, y=pos.y, z=pos.z}, + {x=pos.x-1, y=pos.y-1, z=pos.z}, + {x=pos.x, y=pos.y, z=pos.z+1}, + {x=pos.x, y=pos.y-1, z=pos.z+1}, + {x=pos.x, y=pos.y, z=pos.z-1}, + {x=pos.x, y=pos.y-1, z=pos.z-1}, + } + for _, p in pairs(positions) do + local check = check_node_around(p) + if check == 1 then water_nodes = water_nodes + 1 end + if check == 2 then lava_nodes = lava_nodes + 1 end + end + + if water_nodes == 1 and lava_nodes == 1 then production_level = 25; eu_supply = 5 * data.power end + if water_nodes == 2 and lava_nodes == 1 then production_level = 50; eu_supply = 10 * data.power end + if water_nodes == 1 and lava_nodes == 2 then production_level = 75; eu_supply = 20 * data.power end + if water_nodes == 2 and lava_nodes == 2 then production_level = 100; eu_supply = 30 * data.power end + + if production_level > 0 then + meta:set_int(tier.."_EU_supply", eu_supply) + end + + + + meta:set_string("infotext", description.." ("..production_level.."%) "..technic.prettynum(eu_supply) .." EU") + + + + + + + + + if production_level > 0 and minetest.get_node(pos).name == off_name then + technic.swap_node (pos, on_name) + return + end + if production_level == 0 then + technic.swap_node(pos, off_name) + meta:set_int(tier.."_EU_supply", 0) + end + end + + + if data.old then + + + else + + + + end + + minetest.register_node(off_name, { + description = description, + tiles = {texture_name.."_top.png", "technic_machine_bottom.png", texture_name.."_side.png", + texture_name.."_side.png", texture_name.."_side.png", texture_name.."_side.png"}, + paramtype2 = "facedir", + groups = groups, + legacy_facedir_simple = true, + sounds = default.node_sound_wood_defaults(), + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("infotext", S("Geothermal %s Generator"):format(tier)) + meta:set_int(tier.."_EU_supply", 0) + end, + technic_run = run, + }) + + minetest.register_node(on_name, { + description = description, + tiles = {texture_name.."_top_active.png", "technic_machine_bottom.png", texture_name.."_side.png", + texture_name.."_side.png", texture_name.."_side.png", texture_name.."_side.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 = off_name, + technic_run = run, + }) + + + technic.register_machine(tier, off_name, technic.producer) + technic.register_machine(tier, on_name, technic.producer) + + +end diff --git a/technic/machines/register/init.lua b/technic/machines/register/init.lua index 1667d75..c3e51ea 100644 --- a/technic/machines/register/init.lua +++ b/technic/machines/register/init.lua @@ -9,6 +9,7 @@ dofile(path.."/battery_box.lua") -- Generators dofile(path.."/solar_array.lua") dofile(path.."/generator.lua") +dofile(path.."/geothermal.lua") -- API for machines dofile(path.."/recipes.lua")