aboutsummaryrefslogtreecommitdiff
path: root/init.lua
blob: ab755dd3f745da85a32522ba403f8245817846cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local function tp_func(y, goal)
	return function()
		local player = minetest.localplayer
		local pos = player:get_pos()

		if pos.y < y then
			return false, "Can't teleport to " .. goal .. " from this location."
		end

		pos.y = y
		player:set_pos(pos)
		return true
	end
end

local function disconnect_wrapper(func)
	return function()
		local success, msg = func()
		if success then
			minetest.after(0, minetest.disconnect)
		end
		return success, msg
	end
end

local function menu_wrapper(func)
	return function()
		local _, msg = func()
		if msg then
			minetest.display_chat_message(msg)
		end
	end
end

local end_func = tp_func(-27000, "End")
local nether_func = tp_func(-29000, "Nether")
local spawn_func = disconnect_wrapper(tp_func(-32000, "Spawn"))

minetest.register_chatcommand("end", {
	description = "Teleport to the end (works in the overworld only). This may drop you above the void, so make sure you have Fly or Jetpack enabled.",
	func = end_func,
})

minetest.register_chatcommand("nether", {
	description = "Teleport to the nether (works in the overworld or the end). This may move you into solid blocks, so make sure you have a pickaxe ready or Noclip enabled.",
	func = nether_func,
})

minetest.register_chatcommand("spawn", {
	description = "Teleport to your spawn location. This will disconnect you, you have to reconnect afterwards.",
	func = spawn_func,
})

minetest.register_cheat("End", "Exploit", menu_wrapper(end_func))
minetest.register_cheat("Nether", "Exploit", menu_wrapper(nether_func))
minetest.register_cheat("Spawn", "Exploit", menu_wrapper(spawn_func))