small fixes

* prevent teleport spamming
* correct node placing
This commit is contained in:
OgelGames 2020-01-12 21:53:34 +11:00
parent e5739954a1
commit 8c8266d48c

View File

@ -1,5 +1,7 @@
local C = telemosaic.config local C = telemosaic.config
local recent_teleports = {}
local function hash_pos(pos) local function hash_pos(pos)
return math.floor(pos.x + 0.5) .. ':' .. return math.floor(pos.x + 0.5) .. ':' ..
math.floor(pos.y + 0.5) .. ':' .. math.floor(pos.y + 0.5) .. ':' ..
@ -104,7 +106,7 @@ local function extender_dig(digpos, oldnode, oldmetadata, digger)
if dist > C.beacon_range + extended then if dist > C.beacon_range + extended then
-- downgrade :-( -- downgrade :-(
swap_beacon(pos, "_err") swap_beacon(pos, "_err")
end end
end end
end end
@ -156,6 +158,13 @@ end
-- teleports the player with given telemosaic pos -- teleports the player with given telemosaic pos
function do_teleport(pos, player) function do_teleport(pos, player)
-- prevent teleport spamming
local player_name = player:get_player_name()
if recent_teleports[player_name] then
return
end
if is_err_beacon(pos) then if is_err_beacon(pos) then
return return
end end
@ -212,6 +221,14 @@ function do_teleport(pos, player)
texture = "telemosaic_particle_arrival.png", texture = "telemosaic_particle_arrival.png",
glow = 15, glow = 15,
}) })
-- prevent teleport spamming
recent_teleports[player_name] = true
minetest.after(1,
function(name)
recent_teleports[name] = nil
end,
player_name)
else else
-- beacon is in error, one way or another. -- beacon is in error, one way or another.
-- but don't swap it out - we won't get it back otherwise! -- but don't swap it out - we won't get it back otherwise!
@ -254,18 +271,16 @@ local function beacon_rightclick(pos, node, player, itemstack, pointed_thing)
count = 1, wear = 0, count = 1, wear = 0,
}) })
end end
elseif is_protected_beacon(pos, player) then elseif player:get_player_control().sneak then
return -- normal place
else local def = minetest.registered_nodes[itemstack:get_name()]
if player:get_player_control().sneak then if def then
if itemstack:get_definition().type == "node" then return def.on_place(itemstack, player, pointed_thing)
-- normal place end
return minetest.item_place_node(itemstack, player, pointed_thing)
end elseif not is_protected_beacon(pos, player) then
else -- teleport when right-clicked
-- teleport when right-clicked do_teleport(pos, player)
do_teleport(pos, player)
end
end end
return itemstack return itemstack
end end