-
Notifications
You must be signed in to change notification settings - Fork 0
/
paxel.lua
136 lines (117 loc) · 3.56 KB
/
paxel.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
--
--- Medic Paxel
--
local DIG_SPEED = 0.1
local PAXEL_POWER = 50 -- currently just blocks count
local PAXEL_RETRY = 3
local PAXEL_COOLDOWN_TIME = 20
local dig_timers = {}
local function is_diggable(node)
local name = node.name
return name:find("default:") and (
name:find("cobble") or name:find("wood" ) or
name:find("leaves") or name:find("dirt" ) or
name:find("gravel") or name:find("sand" ) or
name:find("tree" ) or name:find("brick") or
name:find("glass" ) or name:find("ice" ) or
name:find("snow" )
)
or name:find("stairs:")
end
local function dig(pname, ppos, power, retry)
if power <= 1 then
hud_events.new(pname, {
quick = true,
text = "Pillar digging went too far",
color = "warning",
})
dig_timers[pname] = nil
return
end
for y = 1, 20 do
local pos = vector.offset(ppos, 0, y, 0)
local node = minetest.get_node(pos)
if node.name ~= "air" then
if is_diggable(node) then
minetest.dig_node(pos)
dig_timers[pname] = minetest.after(DIG_SPEED, dig, pname, pos, power - 1, PAXEL_RETRY)
else
hud_events.new(pname, {
quick = true,
text = "Pillar digging stopped on undiggable node",
color = "warning",
})
dig_timers[pname] = nil
end
return
end
end
if retry > 0 then
dig_timers[pname] = minetest.after(1, dig, pname, ppos, power, retry - 1)
else
hud_events.new(pname, {
quick = true,
text = "Pillar digging has nothing more to dig",
color = "warning",
})
dig_timers[pname] = nil
end
end
minetest.register_tool("tournament_mode:support_paxel", {
description = "Paxel\nRightclick bottom of pillar to dig it.\nCan't use during build time",
inventory_image = "default_tool_bronzepick.png^default_tool_bronzeshovel.png",
wield_image = "default_tool_bronzepick.png^default_tool_bronzeshovel.png",
inventory_overlay = "ctf_modebase_special_item.png",
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level = 1,
groupcaps = {
cracky = {times={[1]=4.00, [2]=1.60, [3]=0.80}, uses=0, maxlevel=2},
crumbly = {times={[1]=1.50, [2]=0.90, [3]=0.40}, uses=0, maxlevel=2},
choppy = {times={[1]=2.50, [2]=1.40, [3]=1.00}, uses=0, maxlevel=2},
},
damage_groups = {fleshy=4},
punch_attack_uses = 0,
},
groups = {pickaxe = 1, tier = 10},
sound = {breaks = "default_tool_breaks"},
on_place = function(itemstack, user, pointed_thing)
if pointed_thing and itemstack:get_wear() == 0 then
local pos = pointed_thing.under
if is_diggable(minetest.get_node(pos)) then
if not ctf_modebase.match_started then
hud_events.new(user, {
quick = true,
text = "Can't use during build time",
color = "warning",
})
return
end
local pname = user:get_player_name()
minetest.dig_node(pos)
if dig_timers[pname] then
dig_timers[pname]:cancel()
end
dig_timers[pname] = minetest.after(DIG_SPEED, dig, pname, pos, PAXEL_POWER, PAXEL_RETRY)
local dstep = math.floor(65534 / PAXEL_COOLDOWN_TIME)
ctf_modebase.update_wear.start_update(pname, "tournament_mode:support_paxel", dstep, true)
itemstack:set_wear(65534)
return itemstack
else
minetest.item_place(itemstack, user, pointed_thing)
end
end
end,
})
ctf_api.register_on_match_end(function()
for _, timer in pairs(dig_timers) do
timer:cancel()
end
dig_timers = {}
end)
minetest.register_on_leaveplayer(function(player)
local pname = player:get_player_name()
if dig_timers[pname] then
dig_timers[pname]:cancel()
end
end)