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
vector_extras

View File

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

View File

@ -4,7 +4,7 @@ local wireless_rids = {}
local register = function(pos)
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)
vector.set_data_to_pos(wireless_rids, pos.z,pos.y,pos.x, #wireless)
end