forked from minetest-mods/MoreMesecons
Merge branch 'master' of https://github.com/paly2/MoreMesecons
This commit is contained in:
commit
9ff6ad9ce0
@ -1 +1,2 @@
|
|||||||
mesecons
|
mesecons
|
||||||
|
vector_extras
|
||||||
|
@ -1,7 +1,43 @@
|
|||||||
local JAMMER_MAX_DISTANCE = 10
|
local JAMMER_MAX_DISTANCE = 10
|
||||||
|
|
||||||
|
-- see wireless jammer
|
||||||
|
local get = vector.get_data_from_pos
|
||||||
|
local set = vector.set_data_to_pos
|
||||||
|
local remove = vector.remove_data_from_pos
|
||||||
|
|
||||||
|
local jammers = {}
|
||||||
|
local function add_jammer(pos)
|
||||||
|
if get(jammers, pos.z,pos.y,pos.x) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
set(jammers, pos.z,pos.y,pos.x, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function remove_jammer(pos)
|
||||||
|
remove(jammers, pos.z,pos.y,pos.x)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_jammed(pos)
|
||||||
|
local pz,py,px = vector.unpack(pos)
|
||||||
|
for z,yxs in pairs(jammers) do
|
||||||
|
if math.abs(pz-z) <= JAMMER_MAX_DISTANCE then
|
||||||
|
for y,xs in pairs(yxs) do
|
||||||
|
if math.abs(py-y) <= JAMMER_MAX_DISTANCE then
|
||||||
|
for x in pairs(xs) do
|
||||||
|
if math.abs(px-x) <= JAMMER_MAX_DISTANCE
|
||||||
|
and (px-x)^2+(py-y)^2+(pz-z)^2 <= JAMMER_MAX_DISTANCE^2 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
minetest.after(0, function() -- After load all mods
|
minetest.after(0, function() -- After load all mods
|
||||||
function mesecon.turnon(pos, link) -- Overwrite mesecons function.
|
function mesecon.turnon(pos, link) -- Overwrite mesecons function.
|
||||||
local frontiers = {{pos = pos, link = link}}
|
local frontiers = {{pos = pos, link = link}}
|
||||||
|
|
||||||
local depth = 1
|
local depth = 1
|
||||||
@ -12,8 +48,8 @@ function mesecon.turnon(pos, link) -- Overwrite mesecons function.
|
|||||||
-- area not loaded, postpone action
|
-- area not loaded, postpone action
|
||||||
if not node then
|
if not node then
|
||||||
mesecon.queue:add_action(f.pos, "turnon", {link}, nil, true)
|
mesecon.queue:add_action(f.pos, "turnon", {link}, nil, true)
|
||||||
elseif minetest.find_node_near(f.pos, JAMMER_MAX_DISTANCE, {"moremesecons_jammer:jammer_on"}) then -- JAMMER
|
elseif is_jammed(f.pos) then -- JAMMER
|
||||||
break
|
return
|
||||||
elseif mesecon.is_conductor_off(node, f.link) then
|
elseif mesecon.is_conductor_off(node, f.link) then
|
||||||
local rules = mesecon.conductor_get_rules(node)
|
local rules = mesecon.conductor_get_rules(node)
|
||||||
|
|
||||||
@ -43,7 +79,7 @@ function mesecon.turnon(pos, link) -- Overwrite mesecons function.
|
|||||||
end
|
end
|
||||||
depth = depth + 1
|
depth = depth + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
mesecon.register_node("moremesecons_jammer:jammer", {
|
mesecon.register_node("moremesecons_jammer:jammer", {
|
||||||
@ -54,15 +90,21 @@ mesecon.register_node("moremesecons_jammer:jammer", {
|
|||||||
groups = {dig_immediate=2},
|
groups = {dig_immediate=2},
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_on = function(pos)
|
action_on = function(pos)
|
||||||
|
add_jammer(pos)
|
||||||
minetest.swap_node(pos, {name="moremesecons_jammer:jammer_on"})
|
minetest.swap_node(pos, {name="moremesecons_jammer:jammer_on"})
|
||||||
end }}
|
end
|
||||||
|
}},
|
||||||
},{
|
},{
|
||||||
tiles = {"moremesecons_jammer_on.png"},
|
tiles = {"moremesecons_jammer_on.png"},
|
||||||
groups = {dig_immediate=2, not_in_creative_inventory=1},
|
groups = {dig_immediate=2, not_in_creative_inventory=1},
|
||||||
mesecons = {effector = {
|
mesecons = {effector = {
|
||||||
action_off = function(pos)
|
action_off = function(pos)
|
||||||
|
remove_jammer(pos)
|
||||||
minetest.swap_node(pos, {name="moremesecons_jammer:jammer_off"})
|
minetest.swap_node(pos, {name="moremesecons_jammer:jammer_off"})
|
||||||
end }}
|
end
|
||||||
|
}},
|
||||||
|
on_destruct = remove_jammer,
|
||||||
|
on_construct = add_jammer,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
@ -70,3 +112,10 @@ minetest.register_craft({
|
|||||||
recipe = {{"group:mesecon_conductor_craftable", "default:mese", "group:mesecon_conductor_craftable"},
|
recipe = {{"group:mesecon_conductor_craftable", "default:mese", "group:mesecon_conductor_craftable"},
|
||||||
{"", "moremesecons_wireless:jammer_off", ""}}
|
{"", "moremesecons_wireless:jammer_off", ""}}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_abm({
|
||||||
|
nodenames = {"moremesecons_jammer:jammer_on"},
|
||||||
|
interval = 5,
|
||||||
|
chance = 1,
|
||||||
|
action = add_jammer
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user