-
Notifications
You must be signed in to change notification settings - Fork 2
/
utility.lua
79 lines (66 loc) · 2.16 KB
/
utility.lua
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
local utility = {}
function utility.is_creative(player)
if minetest.settings:get_bool("creative_mode") == true then
return true
end
local name = player:get_player_name()
if name == nil or name == "" then
return false
end
return minetest.check_player_privs(name, { creative = true })
end
function utility.is_replaceable(pos)
local node = minetest.registered_nodes[minetest.get_node(pos)]
if node == nil or node.name == "handholds_redo:holds" then return true end
return node.name == "air" or node.buildable_to
end
function utility.is_climbable(pos, level)
local def = minetest.registered_nodes[minetest.get_node(pos).name]
if def == nil then return false end
if def.groups == nil or def.groups.handholds == nil then return false end
return level >= def.groups.handholds
end
function utility.place_holds(itemstack, placer, pointed_thing)
if itemstack == nil then return end
local itemdef = itemstack:get_definition()
if itemdef == nil
or itemdef.groups == nil
or itemdef.groups.climbing_pick == nil then
return
end
if pointed_thing == nil or
pointed_thing.type ~= "node" or
pointed_thing.under.y + 1 == pointed_thing.above.y or
not utility.is_replaceable(pointed_thing.above) or
not utility.is_climbable(pointed_thing.under, itemdef.groups.climbing_pick) then
return
end
if minetest.is_protected(pointed_thing.under, placer:get_player_name()) or
minetest.is_protected(pointed_thing.above, placer:get_player_name()) then
minetest.record_protection_violation(pointed_thing.above, placer)
return
end
local rotation = minetest.dir_to_wallmounted(
vector.subtract(pointed_thing.under, pointed_thing.above)
)
minetest.set_node(pointed_thing.above, {
name = "handholds_redo:holds",
param2 = rotation
})
minetest.sound_play(
"default_dig_cracky",
{pos = pointed_thing.under, gain = 0.5, max_hear_distance = 8}
)
if not utility.is_creative(placer) then
local wdef = itemstack:get_definition()
itemstack:add_wear(256)
if itemstack:get_count() == 0 and wdef.sound and wdef.sound.breaks then
minetest.sound_play(wdef.sound.breaks, {
pos = pointed_thing.above,
gain = 0.5
})
end
end
return itemstack
end
return utility