-
Notifications
You must be signed in to change notification settings - Fork 4
/
hooks.lua
62 lines (43 loc) · 1.71 KB
/
hooks.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
-- hooks.lua
-- Contains the hook functions
function OnPlayerBreakingBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta)
-- Check if the user should only be allowed to use survival with this plugin
if (g_Config.SurvivalOnly and not a_Player:IsGameModeSurvival()) then
return false
end
-- Check if the blockface is correct
if (a_BlockFace == BLOCK_FACE_NONE) then
return false
end
-- Check if you may only use an axe, and if that is true check if the equipped item is an axe
local EquippedItem = a_Player:GetEquippedItem()
if (g_Config.AxeRequired and not ItemCategory.IsAxe(EquippedItem.m_ItemType)) then
return false
end
-- Check if the block that is about to be broken is wood
local World = a_Player:GetWorld()
local BlockType = World:GetBlock(a_BlockX, a_BlockY, a_BlockZ)
if (not ItemCategory.IsWood(BlockType)) then
return false
end
local BlockMeta = World:GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)
-- Initialize the collection class
local Collection = g_CollectionClass(a_Player, BlockType, BlockMeta)
-- Go through each block above the current block until the block ID is different.
for PosY = a_BlockY, World:GetHeight(a_BlockX, a_BlockZ), 1 do
if (World:GetBlock(a_BlockX, PosY, a_BlockZ) ~= BlockType) then
break;
end
if (World:GetBlockMeta(a_BlockX, PosY, a_BlockZ) ~= BlockMeta) then
break;
end
World:SetBlock(a_BlockX, PosY, a_BlockZ, E_BLOCK_AIR, 0)
Collection:NextBlock(a_BlockX, PosY, a_BlockZ)
end
Collection:Finish()
if (g_Config.ReplantSapling) then
if (math.random() < g_Config.ReplantSaplingRate) then
World:SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_SAPLING, GetSaplingMeta(BlockType, BlockMeta))
end
end
end