diff --git a/mods/ENTITIES/mcl_mobs/mount.lua b/mods/ENTITIES/mcl_mobs/mount.lua index 8c4a6aa5..e327b2a6 100644 --- a/mods/ENTITIES/mcl_mobs/mount.lua +++ b/mods/ENTITIES/mcl_mobs/mount.lua @@ -175,7 +175,7 @@ function mobs.detach(player, offset) minetest.after(0.1, function(name, pos) local player = minetest.get_player_by_name(name) if player then - player:set_pos(pos) + mcl_anticheat.set_pos(player, pos) end end, player:get_player_name(), pos) end diff --git a/mods/ENVIRONMENT/mcl_void_damage/init.lua b/mods/ENVIRONMENT/mcl_void_damage/init.lua index 205198a4..8d22af66 100644 --- a/mods/ENVIRONMENT/mcl_void_damage/init.lua +++ b/mods/ENVIRONMENT/mcl_void_damage/init.lua @@ -66,7 +66,7 @@ minetest.register_globalstep(function(dtime) -- If damage is disabled, we can't kill players. -- So we just teleport the player back to spawn. local spawn = mcl_spawn.get_player_spawn_pos(player) - player:set_pos(spawn) + mcl_anticheat.set_pos(player, spawn) mcl_worlds.dimension_change(player, mcl_worlds.pos_to_dimension(spawn)) minetest.chat_send_player(player:get_player_name(), S("The void is off-limits to you!")) elseif enable_damage and not is_immortal then diff --git a/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua b/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua index 669edbcb..5cbc1949 100644 --- a/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua @@ -349,7 +349,7 @@ function mesecon.mvps_move_objects(pos, dir, nodestack) local nn = minetest.get_node(np) if not ((not minetest.registered_nodes[nn.name]) or minetest.registered_nodes[nn.name].walkable) then - obj:set_pos(np) + mcl_anticheat.set_pos(obj, np) end end end diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index 33c38c6c..ec8b6bce 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -128,7 +128,7 @@ local function lay_down(player, pos, bed_pos, state, skip) mcl_beds.pos[name] = nil mcl_beds.bed_pos[name] = nil if p then - player:set_pos(p) + mcl_anticheat.set_pos(player, p) end -- skip here to prevent sending player specific changes (used for leaving players) @@ -183,7 +183,7 @@ local function lay_down(player, pos, bed_pos, state, skip) player:get_meta():set_string("mcl_beds:sleeping", "true") playerphysics.add_physics_factor(player, "speed", "mcl_beds:sleeping", 0) playerphysics.add_physics_factor(player, "jump", "mcl_beds:sleeping", 0) - player:set_pos(bed_center) + mcl_anticheat.set_pos(player, bed_center) mcl_player.player_attached[name] = true hud_flags.wielditem = false mcl_player.player_set_animation(player, "lay" , 0) diff --git a/mods/ITEMS/mcl_end/chorus_plant.lua b/mods/ITEMS/mcl_end/chorus_plant.lua index 1363debf..18468d9f 100644 --- a/mods/ITEMS/mcl_end/chorus_plant.lua +++ b/mods/ITEMS/mcl_end/chorus_plant.lua @@ -515,7 +515,7 @@ local random_teleport = function(player) if streak >= 2 then -- JACKPOT! Now we can teleport. local goal = {x=tpos.x, y=tpos.y-1.5, z=tpos.z} - player:set_pos(goal) + mcl_anticheat.set_pos(player, goal) minetest.sound_play({name="mcl_end_teleport", gain=0.8}, {pos=goal, max_hear_distance=16}, true) return true end diff --git a/mods/ITEMS/mcl_portals/portal_end.lua b/mods/ITEMS/mcl_portals/portal_end.lua index 04599353..095e515e 100644 --- a/mods/ITEMS/mcl_portals/portal_end.lua +++ b/mods/ITEMS/mcl_portals/portal_end.lua @@ -211,7 +211,7 @@ function mcl_portals.end_teleport(obj, pos) end -- Teleport - obj:set_pos(target) + mcl_anticheat.set_pos(obj, target) if obj:is_player() then -- Look towards the main End island diff --git a/mods/ITEMS/mcl_portals/portal_nether.lua b/mods/ITEMS/mcl_portals/portal_nether.lua index 7e23a9f7..ca133cbc 100644 --- a/mods/ITEMS/mcl_portals/portal_nether.lua +++ b/mods/ITEMS/mcl_portals/portal_nether.lua @@ -699,7 +699,7 @@ local function teleport_no_delay(obj, pos) mcl_portals.nether_portal_cooloff[obj] = true -- Teleport - obj:set_pos(target) + mcl_anticheat.set_pos(obj, target) if is_player then mcl_worlds.dimension_change(obj, mcl_worlds.pos_to_dimension(target)) diff --git a/mods/ITEMS/mcl_throwing/init.lua b/mods/ITEMS/mcl_throwing/init.lua index 5fe34b45..9e88774e 100644 --- a/mods/ITEMS/mcl_throwing/init.lua +++ b/mods/ITEMS/mcl_throwing/init.lua @@ -364,7 +364,7 @@ local pearl_on_step = function(self, dtime) local oldpos = player:get_pos() -- Teleport and hurt player - player:set_pos(telepos) + mcl_anticheat.set_pos(player, telepos) player:set_hp(player:get_hp() - 5, { type = "fall", from = "mod" }) -- 5% chance to spawn endermite at the player's origin diff --git a/mods/MISC/findbiome/init.lua b/mods/MISC/findbiome/init.lua index ce7fd979..74fc3f2e 100644 --- a/mods/MISC/findbiome/init.lua +++ b/mods/MISC/findbiome/init.lua @@ -259,7 +259,7 @@ do if param == "default" then local biome_pos = find_default_biome() if biome_pos then - player:set_pos(biome_pos) + mcl_anticheat.set_pos(player, biome_pos) return true, S("Biome found at @1.", minetest.pos_to_string(biome_pos)) else return false, S("No biome found!") diff --git a/mods/PLAYER/mcl_anticheat/init.lua b/mods/PLAYER/mcl_anticheat/init.lua new file mode 100644 index 00000000..38ed58f0 --- /dev/null +++ b/mods/PLAYER/mcl_anticheat/init.lua @@ -0,0 +1,35 @@ +local MAX_TP_DOWN = 100 + +mcl_anticheat = { + positions = {} +} + +function mcl_anticheat.set_pos(player, pos) + player:set_pos(pos) + + if player:is_player() then + mcl_anticheat.positions[player] = pos + end +end + +minetest.register_on_joinplayer(function(player) + mcl_anticheat.positions[player] = player:get_pos() +end) + +minetest.register_on_leaveplayer(function(player) + mcl_anticheat.positions[player] = nil +end) + +minetest.register_globalstep(function() + for _, player in pairs(minetest.get_connected_players()) do + local pos = player:get_pos() + local old_pos = mcl_anticheat.positions[player] + + if old_pos.y - pos.y > MAX_TP_DOWN and not player:get_attach() then + player:set_pos(old_pos) + else + mcl_anticheat.positions[player] = pos + end + end + +end) diff --git a/mods/PLAYER/mcl_anticheat/mod.conf b/mods/PLAYER/mcl_anticheat/mod.conf new file mode 100644 index 00000000..bbdbd86e --- /dev/null +++ b/mods/PLAYER/mcl_anticheat/mod.conf @@ -0,0 +1,2 @@ +name = mcl_anticheat +author = Fleckenstein diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index 6a3d543d..73d35440 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -490,7 +490,7 @@ end mcl_spawn.spawn = function(player) local pos, in_bed = mcl_spawn.get_player_spawn_pos(player) - player:set_pos(pos) + mcl_anticheat.set_pos(player, pos) return in_bed or success end