mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-04-01 18:20:39 +02:00
[mesecons] Update
This commit is contained in:
parent
e0a3d098f5
commit
f8fd6f05d5
@ -381,27 +381,41 @@ function mesecon.turnon(pos, link)
|
||||
|
||||
-- area not loaded, postpone action
|
||||
if not node then
|
||||
mesecon.queue:add_action(f.pos, "turnon", {link}, nil, true)
|
||||
mesecon.queue:add_action(f.pos, "turnon", {f.link}, nil, true)
|
||||
elseif mesecon.is_conductor_off(node, f.link) then
|
||||
local rules = mesecon.conductor_get_rules(node)
|
||||
|
||||
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link),
|
||||
param2 = node.param2})
|
||||
-- Success: If false, at least one neighboring node is unloaded,
|
||||
-- postpone turning on action
|
||||
local success = true
|
||||
local neighborlinks = {}
|
||||
|
||||
-- call turnon on neighbors: normal rules
|
||||
-- call turnon on neighbors
|
||||
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
|
||||
local np = vector.add(f.pos, r)
|
||||
|
||||
-- area not loaded, postpone action
|
||||
-- Neighboring node not loaded, postpone turning on current node
|
||||
-- since we can't even know if neighboring node has matching rules
|
||||
if not mesecon.get_node_force(np) then
|
||||
mesecon.queue:add_action(np, "turnon", {rulename},
|
||||
nil, true)
|
||||
success = false
|
||||
break
|
||||
else
|
||||
local links = mesecon.rules_link_rule_all(f.pos, r)
|
||||
neighborlinks[minetest.hash_node_position(np)] = mesecon.rules_link_rule_all(f.pos, r)
|
||||
end
|
||||
end
|
||||
|
||||
if success then
|
||||
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link),
|
||||
param2 = node.param2})
|
||||
|
||||
for npos, links in pairs(neighborlinks) do
|
||||
-- links = all links to node, l = each single link
|
||||
for _, l in ipairs(links) do
|
||||
table.insert(frontiers, {pos = np, link = l})
|
||||
table.insert(frontiers, {pos = minetest.get_position_from_hash(npos), link = l})
|
||||
end
|
||||
end
|
||||
else
|
||||
mesecon.queue:add_action(f.pos, "turnon", {f.link}, nil, true)
|
||||
end
|
||||
elseif mesecon.is_effector(node.name) then
|
||||
mesecon.changesignal(f.pos, node, f.link, mesecon.state.on, depth)
|
||||
@ -427,27 +441,41 @@ function mesecon.turnoff(pos, link)
|
||||
|
||||
-- area not loaded, postpone action
|
||||
if not node then
|
||||
mesecon.queue:add_action(f.pos, "turnoff", {link}, nil, true)
|
||||
mesecon.queue:add_action(f.pos, "turnoff", {f.link}, nil, true)
|
||||
elseif mesecon.is_conductor_on(node, f.link) then
|
||||
local rules = mesecon.conductor_get_rules(node)
|
||||
|
||||
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link),
|
||||
param2 = node.param2})
|
||||
-- Success: If false, at least one neighboring node is unloaded,
|
||||
-- postpone turning on action
|
||||
local success = true
|
||||
local neighborlinks = {}
|
||||
|
||||
-- call turnoff on neighbors: normal rules
|
||||
-- call turnoff on neighbors
|
||||
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
|
||||
local np = vector.add(f.pos, r)
|
||||
|
||||
-- area not loaded, postpone action
|
||||
-- Neighboring node not loaded, postpone turning off current node
|
||||
-- since we can't even know if neighboring node has matching rules
|
||||
if not mesecon.get_node_force(np) then
|
||||
mesecon.queue:add_action(np, "turnoff", {rulename},
|
||||
nil, true)
|
||||
success = false
|
||||
break
|
||||
else
|
||||
local links = mesecon.rules_link_rule_all(f.pos, r)
|
||||
neighborlinks[minetest.hash_node_position(np)] = mesecon.rules_link_rule_all(f.pos, r)
|
||||
end
|
||||
end
|
||||
|
||||
if success then
|
||||
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link),
|
||||
param2 = node.param2})
|
||||
|
||||
for npos, links in pairs(neighborlinks) do
|
||||
-- links = all links to node, l = each single link
|
||||
for _, l in ipairs(links) do
|
||||
table.insert(frontiers, {pos = np, link = l})
|
||||
table.insert(frontiers, {pos = minetest.get_position_from_hash(npos), link = l})
|
||||
end
|
||||
end
|
||||
else
|
||||
mesecon.queue:add_action(f.pos, "turnoff", {f.link}, nil, true)
|
||||
end
|
||||
elseif mesecon.is_effector(node.name) then
|
||||
mesecon.changesignal(f.pos, node, f.link, mesecon.state.off, depth)
|
||||
|
@ -87,10 +87,6 @@ end
|
||||
|
||||
|
||||
mesecon.queue:add_function("cooldown", function (pos)
|
||||
if minetest.get_item_group(minetest.get_node(pos).name, "overheat") == 0 then
|
||||
return -- node has been moved, this one does not use overheating - ignore
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local heat = meta:get_int("heat")
|
||||
|
||||
|
@ -10,24 +10,12 @@ local toggle_timer = function (pos)
|
||||
end
|
||||
|
||||
local on_timer = function (pos)
|
||||
local activate = false
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local p = player:getpos()
|
||||
local dist = ((p.x-pos.x)^2 + (p.y-pos.y)^2 + (p.z-pos.z)^2)^0.5
|
||||
if dist < 40 then
|
||||
activate = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if activate then
|
||||
local node = minetest.get_node(pos)
|
||||
if(mesecon.flipstate(pos, node) == "on") then
|
||||
mesecon.receptor_on(pos)
|
||||
else
|
||||
mesecon.receptor_off(pos)
|
||||
end
|
||||
end
|
||||
toggle_timer(pos)
|
||||
end
|
||||
|
||||
|
@ -93,9 +93,22 @@ local function receive_fields(pos, formname, fields, sender)
|
||||
end
|
||||
|
||||
local function resolve_commands(commands, pos)
|
||||
local players = minetest.get_connected_players()
|
||||
|
||||
-- No players online: remove all commands containing
|
||||
-- @nearest, @farthest and @random
|
||||
if #players == 0 then
|
||||
commands = commands:gsub("[^\r\n]+", function (line)
|
||||
if line:find("@nearest") then return "" end
|
||||
if line:find("@farthest") then return "" end
|
||||
if line:find("@random") then return "" end
|
||||
return line
|
||||
end)
|
||||
return commands
|
||||
end
|
||||
|
||||
local nearest, farthest = nil, nil
|
||||
local min_distance, max_distance = math.huge, -1
|
||||
local players = minetest.get_connected_players()
|
||||
for index, player in pairs(players) do
|
||||
local distance = vector.distance(pos, player:getpos())
|
||||
if distance < min_distance then
|
||||
|
@ -508,10 +508,15 @@ local digiline = {
|
||||
end
|
||||
}
|
||||
}
|
||||
local function on_receive_fields(pos, form_name, fields)
|
||||
local function on_receive_fields(pos, form_name, fields, sender)
|
||||
if not fields.program then
|
||||
return
|
||||
end
|
||||
local name = sender:get_player_name()
|
||||
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
|
||||
minetest.record_protection_violation(pos, name)
|
||||
return
|
||||
end
|
||||
reset(pos)
|
||||
reset_meta(pos, fields.code)
|
||||
local err = run(pos, {type="program"})
|
||||
|
@ -26,7 +26,7 @@ minetest.register_craft({
|
||||
-- GHOSTSTONE
|
||||
|
||||
minetest.register_node("mesecons_random:ghoststone", {
|
||||
description="ghoststone",
|
||||
description="Ghoststone",
|
||||
tiles = {"jeija_ghoststone.png"},
|
||||
is_ground_content = true,
|
||||
inventory_image = minetest.inventorycube("jeija_ghoststone_inv.png"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user