mirror of
https://github.com/minetest-mods/technic.git
synced 2025-07-04 09:10:38 +02:00
Make switching station run all machines it is connected to, including those in unloaded blocks.
This commit is contained in:
@ -125,6 +125,44 @@ local function form_handler(pos, formname, fields, sender)
|
||||
return
|
||||
end
|
||||
|
||||
-- Action code performing the transformation
|
||||
local run = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local eu_input = meta:get_int("LV_EU_input")
|
||||
local machine_name = S("%s CNC Machine"):format("LV")
|
||||
local machine_node = "technic:cnc"
|
||||
local demand = 450
|
||||
|
||||
local result = meta:get_string("cnc_product")
|
||||
if inv:is_empty("src") or
|
||||
(not minetest.registered_nodes[result]) or
|
||||
(not inv:room_for_item("dst", result)) then
|
||||
technic.swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||
meta:set_string("cnc_product", "")
|
||||
meta:set_int("LV_EU_demand", 0)
|
||||
return
|
||||
end
|
||||
|
||||
if eu_input < demand then
|
||||
technic.swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
||||
elseif eu_input >= demand then
|
||||
technic.swap_node(pos, machine_node.."_active")
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||
meta:set_int("src_time", meta:get_int("src_time") + 1)
|
||||
if meta:get_int("src_time") >= 3 then -- 3 ticks per output
|
||||
meta:set_int("src_time", 0)
|
||||
srcstack = inv:get_stack("src", 1)
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
inv:add_item("dst", result.." "..meta:get_int("cnc_multiplier"))
|
||||
end
|
||||
end
|
||||
meta:set_int("LV_EU_demand", demand)
|
||||
end
|
||||
|
||||
-- The actual block inactive state
|
||||
minetest.register_node("technic:cnc", {
|
||||
description = S("%s CNC Machine"):format("LV"),
|
||||
@ -139,7 +177,7 @@ minetest.register_node("technic:cnc", {
|
||||
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
||||
},
|
||||
},
|
||||
groups = {cracky=2},
|
||||
groups = {cracky=2, technic_machine=1},
|
||||
legacy_facedir_simple = true,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -155,6 +193,7 @@ minetest.register_node("technic:cnc", {
|
||||
allow_metadata_inventory_take = technic.machine_inventory_take,
|
||||
allow_metadata_inventory_move = technic.machine_inventory_move,
|
||||
on_receive_fields = form_handler,
|
||||
technic_run = run,
|
||||
})
|
||||
|
||||
-- Active state block
|
||||
@ -164,61 +203,17 @@ minetest.register_node("technic:cnc_active", {
|
||||
"technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"},
|
||||
paramtype2 = "facedir",
|
||||
drop = "technic:cnc",
|
||||
groups = {cracky=2, not_in_creative_inventory=1},
|
||||
groups = {cracky=2, technic_machine=1, not_in_creative_inventory=1},
|
||||
legacy_facedir_simple = true,
|
||||
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,
|
||||
on_receive_fields = form_handler,
|
||||
technic_run = run,
|
||||
technic_disabled_machine_name = "technic:cnc",
|
||||
})
|
||||
|
||||
-- Action code performing the transformation
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:cnc","technic:cnc_active"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local eu_input = meta:get_int("LV_EU_input")
|
||||
local machine_name = S("%s CNC Machine"):format("LV")
|
||||
local machine_node = "technic:cnc"
|
||||
local demand = 450
|
||||
|
||||
-- Power off automatically if no longer connected to a switching station
|
||||
technic.switching_station_timeout_count(pos, "LV")
|
||||
|
||||
local result = meta:get_string("cnc_product")
|
||||
if inv:is_empty("src") or
|
||||
(not minetest.registered_nodes[result]) or
|
||||
(not inv:room_for_item("dst", result)) then
|
||||
technic.swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||
meta:set_string("cnc_product", "")
|
||||
meta:set_int("LV_EU_demand", 0)
|
||||
return
|
||||
end
|
||||
|
||||
if eu_input < demand then
|
||||
technic.swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
||||
elseif eu_input >= demand then
|
||||
technic.swap_node(pos, machine_node.."_active")
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||
meta:set_int("src_time", meta:get_int("src_time") + 1)
|
||||
if meta:get_int("src_time") >= 3 then -- 3 ticks per output
|
||||
meta:set_int("src_time", 0)
|
||||
srcstack = inv:get_stack("src", 1)
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
inv:add_item("dst", result.." "..meta:get_int("cnc_multiplier"))
|
||||
end
|
||||
end
|
||||
meta:set_int("LV_EU_demand", demand)
|
||||
end
|
||||
})
|
||||
|
||||
technic.register_machine("LV", "technic:cnc", technic.receiver)
|
||||
technic.register_machine("LV", "technic:cnc_active", technic.receiver)
|
||||
|
||||
|
@ -20,19 +20,78 @@ 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},
|
||||
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,
|
||||
end,
|
||||
technic_run = run,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:geothermal_active", {
|
||||
@ -44,71 +103,9 @@ minetest.register_node("technic:geothermal_active", {
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "technic:geothermal",
|
||||
technic_run = run,
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:geothermal","technic:geothermal_active"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
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
|
||||
})
|
||||
|
||||
technic.register_machine("LV", "technic:geothermal", technic.producer)
|
||||
technic.register_machine("LV", "technic:geothermal_active", technic.producer)
|
||||
|
||||
|
@ -36,11 +36,51 @@ local function play_track(pos, track)
|
||||
{pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,})
|
||||
end
|
||||
|
||||
local run = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local eu_input = meta:get_int("LV_EU_input")
|
||||
local machine_name = S("%s Music Player"):format("LV")
|
||||
local machine_node = "technic:music_player"
|
||||
local demand = 150
|
||||
|
||||
local current_track = meta:get_int("current_track")
|
||||
local pos_hash = minetest.hash_node_position(pos)
|
||||
local music_handle = music_handles[pos_hash]
|
||||
|
||||
-- Setup meta data if it does not exist.
|
||||
if not eu_input then
|
||||
meta:set_int("LV_EU_demand", demand)
|
||||
meta:set_int("LV_EU_input", 0)
|
||||
return
|
||||
end
|
||||
|
||||
if meta:get_int("active") == 0 then
|
||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||
meta:set_int("LV_EU_demand", 0)
|
||||
return
|
||||
end
|
||||
|
||||
if eu_input < demand then
|
||||
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
||||
if music_handle then
|
||||
minetest.sound_stop(music_handle)
|
||||
music_handle = nil
|
||||
end
|
||||
elseif eu_input >= demand then
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||
if not music_handle then
|
||||
music_handle = play_track(pos, current_track)
|
||||
end
|
||||
end
|
||||
music_handles[pos_hash] = music_handle
|
||||
meta:set_int("LV_EU_demand", demand)
|
||||
end
|
||||
|
||||
minetest.register_node("technic:music_player", {
|
||||
description = S("%s Music Player"):format("LV"),
|
||||
tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png",
|
||||
"technic_music_player_side.png", "technic_music_player_side.png", "technic_music_player_side.png"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
||||
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -95,54 +135,7 @@ minetest.register_node("technic:music_player", {
|
||||
end
|
||||
music_handles[pos_hash] = music_handle
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:music_player"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local eu_input = meta:get_int("LV_EU_input")
|
||||
local machine_name = S("%s Music Player"):format("LV")
|
||||
local machine_node = "technic:music_player"
|
||||
local demand = 150
|
||||
|
||||
local current_track = meta:get_int("current_track")
|
||||
local pos_hash = minetest.hash_node_position(pos)
|
||||
local music_handle = music_handles[pos_hash]
|
||||
|
||||
-- Setup meta data if it does not exist.
|
||||
if not eu_input then
|
||||
meta:set_int("LV_EU_demand", demand)
|
||||
meta:set_int("LV_EU_input", 0)
|
||||
return
|
||||
end
|
||||
|
||||
-- Power off automatically if no longer connected to a switching station
|
||||
technic.switching_station_timeout_count(pos, "LV")
|
||||
|
||||
if meta:get_int("active") == 0 then
|
||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||
meta:set_int("LV_EU_demand", 0)
|
||||
return
|
||||
end
|
||||
|
||||
if eu_input < demand then
|
||||
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
||||
if music_handle then
|
||||
minetest.sound_stop(music_handle)
|
||||
music_handle = nil
|
||||
end
|
||||
elseif eu_input >= demand then
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||
if not music_handle then
|
||||
music_handle = play_track(pos, current_track)
|
||||
end
|
||||
end
|
||||
music_handles[pos_hash] = music_handle
|
||||
meta:set_int("LV_EU_demand", demand)
|
||||
end
|
||||
technic_run = run,
|
||||
})
|
||||
|
||||
technic.register_machine("LV", "technic:music_player", technic.receiver)
|
||||
|
@ -4,10 +4,38 @@
|
||||
|
||||
local S = technic.getter
|
||||
|
||||
local run = function(pos, node)
|
||||
-- The action here is to make the solar panel prodice power
|
||||
-- Power is dependent on the light level and the height above ground
|
||||
-- There are many ways to cheat by using other light sources like lamps.
|
||||
-- As there is no way to determine if light is sunlight that is just a shame.
|
||||
-- To take care of some of it solar panels do not work outside daylight hours or if
|
||||
-- built below 0m
|
||||
local pos1 = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local machine_name = S("Small Solar %s Generator"):format("LV")
|
||||
|
||||
local light = minetest.get_node_light(pos1, nil)
|
||||
local time_of_day = minetest.get_timeofday()
|
||||
local meta = minetest.get_meta(pos)
|
||||
if light == nil then light = 0 end
|
||||
-- turn on panel only during day time and if sufficient light
|
||||
-- I know this is counter intuitive when cheating by using other light sources underground.
|
||||
if light >= 12 and time_of_day >= 0.24 and time_of_day <= 0.76 and pos.y > -10 then
|
||||
local charge_to_give = math.floor((light + pos1.y) * 3)
|
||||
charge_to_give = math.max(charge_to_give, 0)
|
||||
charge_to_give = math.min(charge_to_give, 200)
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name).." ("..charge_to_give.."EU)")
|
||||
meta:set_int("LV_EU_supply", charge_to_give)
|
||||
else
|
||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("technic:solar_panel", {
|
||||
tiles = {"technic_solar_panel_top.png", "technic_solar_panel_bottom.png", "technic_solar_panel_side.png",
|
||||
"technic_solar_panel_side.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
||||
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
description = S("Small Solar %s Generator"):format("LV"),
|
||||
active = false,
|
||||
@ -23,6 +51,7 @@ minetest.register_node("technic:solar_panel", {
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
meta:set_string("infotext", S("Small Solar %s Generator"):format("LV"))
|
||||
end,
|
||||
technic_run = run,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -34,40 +63,5 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:solar_panel"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
-- The action here is to make the solar panel prodice power
|
||||
-- Power is dependent on the light level and the height above ground
|
||||
-- 130m and above is optimal as it would be above cloud level.
|
||||
-- Height gives 1/4 of the effect, light 3/4. Max. effect is 26EU.
|
||||
-- There are many ways to cheat by using other light sources like lamps.
|
||||
-- As there is no way to determine if light is sunlight that is just a shame.
|
||||
-- To take care of some of it solar panels do not work outside daylight hours or if
|
||||
-- built below -10m
|
||||
local pos1 = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local machine_name = S("Small Solar %s Generator"):format("LV")
|
||||
|
||||
local light = minetest.get_node_light(pos1, nil)
|
||||
local time_of_day = minetest.get_timeofday()
|
||||
local meta = minetest.get_meta(pos)
|
||||
if light == nil then light = 0 end
|
||||
-- turn on panel only during day time and if sufficient light
|
||||
-- I know this is counter intuitive when cheating by using other light sources underground.
|
||||
if light >= 12 and time_of_day >= 0.24 and time_of_day <= 0.76 and pos.y > -10 then
|
||||
local charge_to_give = math.floor((light + pos1.y) * 3)
|
||||
charge_to_give = math.max(charge_to_give, 0)
|
||||
charge_to_give = math.min(charge_to_give, 200)
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name).." ("..charge_to_give.."EU)")
|
||||
meta:set_int("LV_EU_supply", charge_to_give)
|
||||
else
|
||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
technic.register_machine("LV", "technic:solar_panel", technic.producer)
|
||||
|
||||
|
@ -15,34 +15,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node("technic:water_mill", {
|
||||
description = S("Hydro %s Generator"):format("LV"),
|
||||
tiles = {"technic_water_mill_top.png", "technic_machine_bottom.png",
|
||||
"technic_water_mill_side.png", "technic_water_mill_side.png",
|
||||
"technic_water_mill_side.png", "technic_water_mill_side.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", S("Hydro %s Generator"):format("LV"))
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:water_mill_active", {
|
||||
description = S("Hydro %s Generator"):format("LV"),
|
||||
tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png",
|
||||
"technic_water_mill_side.png", "technic_water_mill_side.png",
|
||||
"technic_water_mill_side.png", "technic_water_mill_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:water_mill",
|
||||
})
|
||||
|
||||
local function check_node_around_mill(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "default:water_flowing" or
|
||||
@ -52,52 +24,78 @@ local function check_node_around_mill(pos)
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:water_mill", "technic:water_mill_active"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local water_nodes = 0
|
||||
local lava_nodes = 0
|
||||
local production_level = 0
|
||||
local eu_supply = 0
|
||||
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
|
||||
|
||||
local positions = {
|
||||
{x=pos.x+1, y=pos.y, z=pos.z},
|
||||
{x=pos.x-1, y=pos.y, z=pos.z},
|
||||
{x=pos.x, y=pos.y, z=pos.z+1},
|
||||
{x=pos.x, y=pos.y, z=pos.z-1},
|
||||
}
|
||||
local positions = {
|
||||
{x=pos.x+1, y=pos.y, z=pos.z},
|
||||
{x=pos.x-1, y=pos.y, z=pos.z},
|
||||
{x=pos.x, y=pos.y, z=pos.z+1},
|
||||
{x=pos.x, y=pos.y, z=pos.z-1},
|
||||
}
|
||||
|
||||
for _, p in pairs(positions) do
|
||||
local check = check_node_around_mill(p)
|
||||
if check then
|
||||
water_nodes = water_nodes + 1
|
||||
end
|
||||
end
|
||||
|
||||
production_level = 25 * water_nodes
|
||||
eu_supply = 30 * water_nodes
|
||||
|
||||
if production_level > 0 then
|
||||
meta:set_int("LV_EU_supply", eu_supply)
|
||||
end
|
||||
|
||||
meta:set_string("infotext",
|
||||
S("Hydro %s Generator"):format("LV").." ("..production_level.."%)")
|
||||
|
||||
if production_level > 0 and
|
||||
minetest.get_node(pos).name == "technic:water_mill" then
|
||||
technic.swap_node (pos, "technic:water_mill_active")
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
return
|
||||
end
|
||||
if production_level == 0 then
|
||||
technic.swap_node(pos, "technic:water_mill")
|
||||
for _, p in pairs(positions) do
|
||||
local check = check_node_around_mill(p)
|
||||
if check then
|
||||
water_nodes = water_nodes + 1
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
production_level = 25 * water_nodes
|
||||
eu_supply = 30 * water_nodes
|
||||
|
||||
if production_level > 0 then
|
||||
meta:set_int("LV_EU_supply", eu_supply)
|
||||
end
|
||||
|
||||
meta:set_string("infotext",
|
||||
S("Hydro %s Generator"):format("LV").." ("..production_level.."%)")
|
||||
|
||||
if production_level > 0 and
|
||||
minetest.get_node(pos).name == "technic:water_mill" then
|
||||
technic.swap_node (pos, "technic:water_mill_active")
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
return
|
||||
end
|
||||
if production_level == 0 then
|
||||
technic.swap_node(pos, "technic:water_mill")
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("technic:water_mill", {
|
||||
description = S("Hydro %s Generator"):format("LV"),
|
||||
tiles = {"technic_water_mill_top.png", "technic_machine_bottom.png",
|
||||
"technic_water_mill_side.png", "technic_water_mill_side.png",
|
||||
"technic_water_mill_side.png", "technic_water_mill_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("Hydro %s Generator"):format("LV"))
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
end,
|
||||
technic_run,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:water_mill_active", {
|
||||
description = S("Hydro %s Generator"):format("LV"),
|
||||
tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png",
|
||||
"technic_water_mill_side.png", "technic_water_mill_side.png",
|
||||
"technic_water_mill_side.png", "technic_water_mill_side.png"},
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1, not_in_creative_inventory=1},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop = "technic:water_mill",
|
||||
technic_run,
|
||||
technic_disabled_machine_name = "technic:water_mill",
|
||||
})
|
||||
|
||||
technic.register_machine("LV", "technic:water_mill", technic.producer)
|
||||
technic.register_machine("LV", "technic:water_mill_active", technic.producer)
|
||||
|
Reference in New Issue
Block a user