mirror of
https://github.com/minetest-mods/technic.git
synced 2025-07-01 07:40:37 +02:00
Make switching station run all machines it is connected to, including those in unloaded blocks.
This commit is contained in:
@ -103,10 +103,45 @@ local mesecons = {
|
||||
}
|
||||
}
|
||||
|
||||
local run = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local eu_input = meta:get_int("HV_EU_input")
|
||||
local eu_demand = meta:get_int("HV_EU_demand")
|
||||
local enabled = meta:get_int("enabled")
|
||||
local machine_name = S("%s Forcefield Emitter"):format("HV")
|
||||
|
||||
local power_requirement = math.floor(
|
||||
4 * math.pi * math.pow(meta:get_int("range"), 2)
|
||||
) * forcefield_power_drain
|
||||
|
||||
if meta:get_int("enabled") == 0 then
|
||||
if node.name == "technic:forcefield_emitter_on" then
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
update_forcefield(pos, meta:get_int("range"), false)
|
||||
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
||||
meta:set_string("infotext", S("%s Disabled"):format(machine_name))
|
||||
return
|
||||
end
|
||||
elseif eu_input < power_requirement then
|
||||
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
||||
if node.name == "technic:forcefield_emitter_on" then
|
||||
update_forcefield(pos, meta:get_int("range"), false)
|
||||
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
||||
end
|
||||
elseif eu_input >= power_requirement then
|
||||
if node.name == "technic:forcefield_emitter_off" then
|
||||
technic.swap_node(pos, "technic:forcefield_emitter_on")
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||
end
|
||||
update_forcefield(pos, meta:get_int("range"), true)
|
||||
end
|
||||
meta:set_int("HV_EU_demand", power_requirement)
|
||||
end
|
||||
|
||||
minetest.register_node("technic:forcefield_emitter_off", {
|
||||
description = S("%s Forcefield Emitter"):format("HV"),
|
||||
tiles = {"technic_forcefield_emitter_off.png"},
|
||||
groups = {cracky = 1},
|
||||
groups = {cracky = 1, technic_machine = 1},
|
||||
on_receive_fields = forcefield_receive_fields,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -117,13 +152,14 @@ minetest.register_node("technic:forcefield_emitter_off", {
|
||||
meta:set_string("infotext", S("%s Forcefield Emitter"):format("HV"))
|
||||
set_forcefield_formspec(meta)
|
||||
end,
|
||||
mesecons = mesecons
|
||||
mesecons = mesecons,
|
||||
technic_run = run,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:forcefield_emitter_on", {
|
||||
description = S("%s Forcefield Emitter"):format("HV"),
|
||||
tiles = {"technic_forcefield_emitter_on.png"},
|
||||
groups = {cracky = 1, not_in_creative_inventory=1},
|
||||
groups = {cracky = 1, technic_machine = 1, not_in_creative_inventory=1},
|
||||
drop = "technic:forcefield_emitter_off",
|
||||
on_receive_fields = forcefield_receive_fields,
|
||||
on_construct = function(pos)
|
||||
@ -135,7 +171,9 @@ minetest.register_node("technic:forcefield_emitter_on", {
|
||||
local meta = minetest.get_meta(pos)
|
||||
update_forcefield(pos, meta:get_int("range"), false)
|
||||
end,
|
||||
mesecons = mesecons
|
||||
mesecons = mesecons,
|
||||
technic_run = run,
|
||||
technic_disabled_machine_name = "technic:forcefield_emitter",
|
||||
})
|
||||
|
||||
minetest.register_node("technic:forcefield", {
|
||||
@ -156,52 +194,11 @@ minetest.register_node("technic:forcefield", {
|
||||
},
|
||||
}},
|
||||
})
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:forcefield_emitter_on", "technic:forcefield_emitter_off"},
|
||||
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("HV_EU_input")
|
||||
local eu_demand = meta:get_int("HV_EU_demand")
|
||||
local enabled = meta:get_int("enabled")
|
||||
local machine_name = S("%s Forcefield Emitter"):format("HV")
|
||||
-- Power off automatically if no longer connected to a switching station
|
||||
technic.switching_station_timeout_count(pos, "HV")
|
||||
|
||||
local power_requirement = math.floor(
|
||||
4 * math.pi * math.pow(meta:get_int("range"), 2)
|
||||
) * forcefield_power_drain
|
||||
|
||||
if meta:get_int("enabled") == 0 then
|
||||
if node.name == "technic:forcefield_emitter_on" then
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
update_forcefield(pos, meta:get_int("range"), false)
|
||||
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
||||
meta:set_string("infotext", S("%s Disabled"):format(machine_name))
|
||||
return
|
||||
end
|
||||
elseif eu_input < power_requirement then
|
||||
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
||||
if node.name == "technic:forcefield_emitter_on" then
|
||||
update_forcefield(pos, meta:get_int("range"), false)
|
||||
technic.swap_node(pos, "technic:forcefield_emitter_off")
|
||||
end
|
||||
elseif eu_input >= power_requirement then
|
||||
if node.name == "technic:forcefield_emitter_off" then
|
||||
technic.swap_node(pos, "technic:forcefield_emitter_on")
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||
end
|
||||
update_forcefield(pos, meta:get_int("range"), true)
|
||||
end
|
||||
meta:set_int("HV_EU_demand", power_requirement)
|
||||
end
|
||||
})
|
||||
|
||||
if minetest.get_modpath("mesecons_mvps") then
|
||||
mesecon:register_mvps_stopper("technic:forcefield")
|
||||
end
|
||||
-- TODO: Register a stopper for frames
|
||||
|
||||
technic.register_machine("HV", "technic:forcefield_emitter_on", technic.receiver)
|
||||
technic.register_machine("HV", "technic:forcefield_emitter_off", technic.receiver)
|
||||
|
@ -48,60 +48,6 @@ local nodebox = {
|
||||
{ -0.303, -0.303, -0.397, 0.303, 0.303, 0.397 },
|
||||
}
|
||||
|
||||
minetest.register_node("technic:hv_nuclear_reactor_core", {
|
||||
description = S("Nuclear %s Generator Core"):format("HV"),
|
||||
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
|
||||
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
stack_max = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", S("Nuclear %s Generator Core"):format("HV"))
|
||||
meta:set_int("HV_EU_supply", 0)
|
||||
-- Signal to the switching station that this device burns some
|
||||
-- sort of fuel and needs special handling
|
||||
meta:set_int("HV_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", 6)
|
||||
end,
|
||||
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,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:hv_nuclear_reactor_core_active", {
|
||||
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
|
||||
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:hv_nuclear_reactor_core",
|
||||
drawtype="nodebox",
|
||||
light_source = 15,
|
||||
paramtype = "light",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox
|
||||
},
|
||||
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,
|
||||
})
|
||||
|
||||
local check_reactor_structure = function(pos)
|
||||
-- The reactor consists of a 9x9x9 cube structure
|
||||
-- A cross section through the middle:
|
||||
@ -188,57 +134,109 @@ local function damage_nearby_players(pos)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:hv_nuclear_reactor_core", "technic:hv_nuclear_reactor_core_active"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local machine_name = S("Nuclear %s Generator Core"):format("HV")
|
||||
local burn_time = meta:get_int("burn_time") or 0
|
||||
local run = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local machine_name = S("Nuclear %s Generator Core"):format("HV")
|
||||
local burn_time = meta:get_int("burn_time") or 0
|
||||
|
||||
if burn_time >= burn_ticks or burn_time == 0 then
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("src") then
|
||||
local srclist = inv:get_list("src")
|
||||
local correct_fuel_count = 0
|
||||
for _, srcstack in pairs(srclist) do
|
||||
if srcstack then
|
||||
if srcstack:get_name() == fuel_type then
|
||||
correct_fuel_count = correct_fuel_count + 1
|
||||
end
|
||||
if burn_time >= burn_ticks or burn_time == 0 then
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("src") then
|
||||
local srclist = inv:get_list("src")
|
||||
local correct_fuel_count = 0
|
||||
for _, srcstack in pairs(srclist) do
|
||||
if srcstack then
|
||||
if srcstack:get_name() == fuel_type then
|
||||
correct_fuel_count = correct_fuel_count + 1
|
||||
end
|
||||
end
|
||||
-- Check that the reactor is complete as well
|
||||
-- as the correct number of correct fuel
|
||||
if correct_fuel_count == 6 and
|
||||
check_reactor_structure(pos) then
|
||||
meta:set_int("burn_time", 1)
|
||||
technic.swap_node(pos, "technic:hv_nuclear_reactor_core_active")
|
||||
meta:set_int("HV_EU_supply", power_supply)
|
||||
for idx, srcstack in pairs(srclist) do
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", idx, srcstack)
|
||||
end
|
||||
return
|
||||
end
|
||||
-- Check that the reactor is complete as well
|
||||
-- as the correct number of correct fuel
|
||||
if correct_fuel_count == 6 and
|
||||
check_reactor_structure(pos) then
|
||||
meta:set_int("burn_time", 1)
|
||||
technic.swap_node(pos, "technic:hv_nuclear_reactor_core_active")
|
||||
meta:set_int("HV_EU_supply", power_supply)
|
||||
for idx, srcstack in pairs(srclist) do
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", idx, srcstack)
|
||||
end
|
||||
return
|
||||
end
|
||||
meta:set_int("HV_EU_supply", 0)
|
||||
meta:set_int("burn_time", 0)
|
||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||
technic.swap_node(pos, "technic:hv_nuclear_reactor_core")
|
||||
elseif burn_time > 0 then
|
||||
damage_nearby_players(pos)
|
||||
if not check_reactor_structure(pos) then
|
||||
explode_reactor(pos)
|
||||
end
|
||||
burn_time = burn_time + 1
|
||||
meta:set_int("burn_time", burn_time)
|
||||
local percent = math.floor(burn_time / burn_ticks * 100)
|
||||
meta:set_string("infotext", machine_name.." ("..percent.."%)")
|
||||
meta:set_int("HV_EU_supply", power_supply)
|
||||
end
|
||||
meta:set_int("HV_EU_supply", 0)
|
||||
meta:set_int("burn_time", 0)
|
||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||
technic.swap_node(pos, "technic:hv_nuclear_reactor_core")
|
||||
elseif burn_time > 0 then
|
||||
damage_nearby_players(pos)
|
||||
if not check_reactor_structure(pos) then
|
||||
explode_reactor(pos)
|
||||
end
|
||||
burn_time = burn_time + 1
|
||||
meta:set_int("burn_time", burn_time)
|
||||
local percent = math.floor(burn_time / burn_ticks * 100)
|
||||
meta:set_string("infotext", machine_name.." ("..percent.."%)")
|
||||
meta:set_int("HV_EU_supply", power_supply)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("technic:hv_nuclear_reactor_core", {
|
||||
description = S("Nuclear %s Generator Core"):format("HV"),
|
||||
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
|
||||
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
stack_max = 1,
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", S("Nuclear %s Generator Core"):format("HV"))
|
||||
meta:set_int("HV_EU_supply", 0)
|
||||
-- Signal to the switching station that this device burns some
|
||||
-- sort of fuel and needs special handling
|
||||
meta:set_int("HV_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", 6)
|
||||
end,
|
||||
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,
|
||||
technic_run = run,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:hv_nuclear_reactor_core_active", {
|
||||
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
|
||||
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:hv_nuclear_reactor_core",
|
||||
drawtype="nodebox",
|
||||
light_source = 15,
|
||||
paramtype = "light",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox
|
||||
},
|
||||
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,
|
||||
technic_run = run,
|
||||
technic_disabled_machine_name = "technic:hv_nuclear_reactor_core",
|
||||
})
|
||||
|
||||
technic.register_machine("HV", "technic:hv_nuclear_reactor_core", technic.producer)
|
||||
|
@ -126,13 +126,43 @@ local function send_items(items, pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
local run = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local size = meta:get_int("size")
|
||||
local eu_input = meta:get_int("HV_EU_input")
|
||||
local demand = 10000
|
||||
local center = get_quarry_center(pos, size)
|
||||
local dig_y = meta:get_int("dig_y")
|
||||
local machine_name = S("%s Quarry"):format("HV")
|
||||
|
||||
if meta:get_int("enabled") == 0 then
|
||||
meta:set_string("infotext", S("%s Disabled"):format(machine_name))
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
return
|
||||
end
|
||||
|
||||
if eu_input < demand then
|
||||
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
||||
elseif eu_input >= demand then
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||
|
||||
local items = quarry_dig(pos, center, size)
|
||||
send_items(items, pos, node)
|
||||
|
||||
if dig_y < pos.y - quarry_max_depth then
|
||||
meta:set_string("infotext", S("%s Finished"):format(machine_name))
|
||||
end
|
||||
end
|
||||
meta:set_int("HV_EU_demand", demand)
|
||||
end
|
||||
|
||||
minetest.register_node("technic:quarry", {
|
||||
description = S("%s Quarry"):format("HV"),
|
||||
tiles = {"technic_carbon_steel_block.png", "technic_carbon_steel_block.png",
|
||||
"technic_carbon_steel_block.png", "technic_carbon_steel_block.png",
|
||||
"technic_carbon_steel_block.png^default_tool_mesepick.png", "technic_carbon_steel_block.png"},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, tubedevice=1},
|
||||
groups = {cracky=2, tubedevice=1, technic_machine = 1},
|
||||
tube = {
|
||||
connect_sides = {top = 1},
|
||||
},
|
||||
@ -150,43 +180,7 @@ minetest.register_node("technic:quarry", {
|
||||
end,
|
||||
after_dig_node = pipeworks.scan_for_tube_objects,
|
||||
on_receive_fields = quarry_receive_fields,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:quarry"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local size = meta:get_int("size")
|
||||
local eu_input = meta:get_int("HV_EU_input")
|
||||
local demand = 10000
|
||||
local center = get_quarry_center(pos, size)
|
||||
local dig_y = meta:get_int("dig_y")
|
||||
local machine_name = S("%s Quarry"):format("HV")
|
||||
|
||||
technic.switching_station_timeout_count(pos, "HV")
|
||||
|
||||
if meta:get_int("enabled") == 0 then
|
||||
meta:set_string("infotext", S("%s Disabled"):format(machine_name))
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
return
|
||||
end
|
||||
|
||||
if eu_input < demand then
|
||||
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
||||
elseif eu_input >= demand then
|
||||
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
||||
|
||||
local items = quarry_dig(pos, center, size)
|
||||
send_items(items, pos, node)
|
||||
|
||||
if dig_y < pos.y - quarry_max_depth then
|
||||
meta:set_string("infotext", S("%s Finished"):format(machine_name))
|
||||
end
|
||||
end
|
||||
meta:set_int("HV_EU_demand", demand)
|
||||
end
|
||||
technic_run = run,
|
||||
})
|
||||
|
||||
technic.register_machine("HV", "technic:quarry", technic.receiver)
|
||||
|
Reference in New Issue
Block a user