aboutsummaryrefslogtreecommitdiff
path: root/clientmods/world/init.lua
blob: 8ce5849c8205b339d7974df14177887a1d346796 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
minetest.register_chatcommand("findnodes", {
	description = "Scan for one or multible nodes in a radius around you",
	param = "<radius> <node1>[,<node2>...]",
	func = function(param)
		local radius = tonumber(param:split(" ")[1])
		local nodes = param:split(" ")[2]:split(",")
		local pos = minetest.localplayer:get_pos()
		local fpos = minetest.find_node_near(pos, radius, nodes, true)
		if fpos then
			return true, "Found " .. table.concat(nodes, " or ") .. " at " .. minetest.pos_to_string(fpos)
		end
		return false, "None of " .. table.concat(nodes, " or ") .. " found in a radius of " .. tostring(radius)
	end,
}) 

minetest.register_chatcommand("place", {
	params = "<X>,<Y>,<Z>",
	description = "Place wielded item",
	func = function(param)
		local success, pos = minetest.parse_relative_pos(param)
		if success then
			minetest.place_node(pos)
			return true, "Node placed at " .. minetest.pos_to_string(pos)
		end
		return false, pos
	end,
})

minetest.register_chatcommand("dig", {
	params = "<X>,<Y>,<Z>",
	description = "Dig node",
	func = function(param)
		local success, pos = minetest.parse_relative_pos(param)
		if success then
			minetest.dig_node(pos)
			return true, "Node at " .. minetest.pos_to_string(pos) .. " dug"
		end
		return false, pos
	end,
})

local etime = 0

minetest.register_globalstep(function(dtime)
	etime = etime + dtime
	if etime < 1 then return end
	local player = minetest.localplayer
	if not player then return end
	local pos = player:get_pos()
	local item = player:get_wielded_item()
	local def = minetest.get_item_def(item:get_name())
	if item:get_count() > 0 and def.node_placement_prediction ~= "" then
		if minetest.settings:get_bool("scaffold") then
			minetest.place_node(vector.add(pos, {x = 0, y = -0.6, z = 0}))
		elseif minetest.settings:get_bool("highway_z") then
			local z = pos.z
			local positions = {
				{x = 0, y = 0, z = z},
				{x = 1, y = 0, z = z},
				{x = 2, y = 1, z = z},
				{x = -2, y = 1, z = z},
				{x = -2, y = 0, z = z},
				{x = -1, y = 0, z = z},
				{x = 2, y = 0, z = z}
			}
			for i, p in pairs(positions) do
				minetest.place_node(p)
			end
		elseif minetest.settings:get_bool("destroy_liquids") then
			local positions = minetest.find_nodes_near(pos, 5, {"mcl_core:water_source", "mcl_core:water_floating"}, true)
			for _, p in pairs(positions) do
				minetest.place_node(p)
			end
		elseif minetest.settings:get_bool("placeoncobble") then
			local positions = minetest.find_nodes_near_under_air(pos, 5, "mcl_core:cobble", true)
			for i, p in pairs(positions) do
				if i > 8 then break end
				minetest.place_node(vector.add(p, {x = 0, y = 1, z = 0}))
			end
		end
	end
	if minetest.settings:get_bool("fucker") then
		local p = minetest.find_node_near(pos, 5, "group:bed", true)
		if p then
			minetest.dig_node(p)
		end
	end
end) 

minetest.register_cheat("Scaffold", "World", "scaffold")
minetest.register_cheat("HighwayZ", "World", "highway_z")
minetest.register_cheat("Fucker", "World", "fucker")
minetest.register_cheat("BlockWater", "World", "destroy_liquids")
minetest.register_cheat("PlaceOnCobble", "World", "placeoncobble")