mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2025-01-09 17:30:24 +01:00
Wireless: avoid inserting numerous times same wireless in wireless table
This commit is contained in:
parent
b403e6e9ab
commit
5422017493
@ -23,13 +23,14 @@ local function remove_wireless(pos)
|
|||||||
if not owner or owner == "" then
|
if not owner or owner == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
remove(wireless_meta.owners, pos.z,pos.y,pos.x)
|
||||||
if not wireless[owner] or not next(wireless[owner]) then
|
if not wireless[owner] or not next(wireless[owner]) then
|
||||||
wireless[owner] = nil
|
wireless[owner] = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local channel = get(wireless_meta.channels, pos.z,pos.y,pos.x)
|
local channel = get(wireless_meta.channels, pos.z,pos.y,pos.x)
|
||||||
if not channel or channel == "" or not wireless[owner][channel] then
|
if not channel or channel == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -41,7 +42,6 @@ local function remove_wireless(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
remove(wireless_meta.owners, pos.z,pos.y,pos.x)
|
|
||||||
remove(wireless_meta.channels, pos.z,pos.y,pos.x)
|
remove(wireless_meta.channels, pos.z,pos.y,pos.x)
|
||||||
remove(wireless_meta.ids, pos.z,pos.y,pos.x)
|
remove(wireless_meta.ids, pos.z,pos.y,pos.x)
|
||||||
end
|
end
|
||||||
@ -94,9 +94,15 @@ function set_channel(pos, channel)
|
|||||||
if not wireless[owner][channel] then
|
if not wireless[owner][channel] then
|
||||||
wireless[owner][channel] = {}
|
wireless[owner][channel] = {}
|
||||||
end
|
end
|
||||||
table.insert(wireless[owner][channel], pos)
|
|
||||||
meta:set_int("id", #wireless[owner][channel])
|
local id = get(wireless_meta.ids, pos.z,pos.y,pos.x)
|
||||||
set(wireless_meta.ids, pos.z,pos.y,pos.x, #wireless[owner][channel])
|
if id then
|
||||||
|
wireless[owner][channel][id] = pos
|
||||||
|
else
|
||||||
|
table.insert(wireless[owner][channel], pos)
|
||||||
|
meta:set_int("id", #wireless[owner][channel])
|
||||||
|
set(wireless_meta.ids, pos.z,pos.y,pos.x, #wireless[owner][channel])
|
||||||
|
end
|
||||||
|
|
||||||
meta:set_string("infotext", "Wireless owned by " .. owner .. " on channel " .. channel)
|
meta:set_string("infotext", "Wireless owned by " .. owner .. " on channel " .. channel)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user