Fix a bug for wireless and teleporter

This commit is contained in:
palige 2015-09-02 12:46:07 +02:00
parent b44d0d2fbc
commit 71ddb8be2a
3 changed files with 10 additions and 7 deletions

View File

@ -1 +1,2 @@
mesecons mesecons
vector_extras

View File

@ -1,11 +1,12 @@
local teleporters = {} local teleporters = {}
local teleporters_rids = {}
local register = function(pos) local register = function(pos)
local meta = minetest.env:get_meta(pos) local RID = vector.get_data_from_pos(teleporters_rids, pos.z,pos.y,pos.x)
local RID = meta:get_int("RID") if not RID then
if teleporters[RID] == nil then
table.insert(teleporters, pos) table.insert(teleporters, pos)
meta:set_int("RID", #teleporters) vector.set_data_to_pos(teleporters_rids, pos.z,pos.y,pos.x, #teleporters)
end end
end end
@ -65,9 +66,10 @@ minetest.register_node("moremesecons_teleporter:teleporter", {
register(pos) register(pos)
end, end,
on_destruct = function(pos) on_destruct = function(pos)
local RID = minetest.get_meta(pos):get_int("RID") local RID = vector.get_data_from_pos(teleporters_rids, pos.z,pos.y,pos.x)
if RID then if RID then
table.remove(teleporters, RID) table.remove(teleporters, RID)
vector.remove_data_from_pos(teleporters_rids, pos.z,pos.y,pos.x)
end end
end, end,
}) })

View File

@ -4,7 +4,7 @@ local wireless_rids = {}
local register = function(pos) local register = function(pos)
local RID = vector.get_data_from_pos(wireless_rids, pos.z,pos.y,pos.x) local RID = vector.get_data_from_pos(wireless_rids, pos.z,pos.y,pos.x)
if wireless[RID] == nil then if not RID then
table.insert(wireless, pos) table.insert(wireless, pos)
vector.set_data_to_pos(wireless_rids, pos.z,pos.y,pos.x, #wireless) vector.set_data_to_pos(wireless_rids, pos.z,pos.y,pos.x, #wireless)
end end