From 025037193903835238920787e5aaafb3fbf5ff70 Mon Sep 17 00:00:00 2001 From: InformationHunter Date: Mon, 20 Apr 2020 21:10:20 +0300 Subject: [PATCH 1/2] Fix bugs when selecting an area --- Classes/ToolRegistrator.lua | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Classes/ToolRegistrator.lua b/Classes/ToolRegistrator.lua index c9cbf01..2239601 100644 --- a/Classes/ToolRegistrator.lua +++ b/Classes/ToolRegistrator.lua @@ -69,12 +69,18 @@ function cToolRegistrator:BindAbsoluteTools() return true end + local LastRightClick = -math.huge local function OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace) local Succ, Message = GetPlayerState(a_Player).Selection:SetPos(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, "Second") if (not Succ) then return false end + if ((os.clock() - LastRightClick) < 0.005) then + return true + end + LastRightClick = os.clock() + a_Player:SendMessage(Message) return true end @@ -297,7 +303,17 @@ local function LeftClickToolsHook(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_Bloc end local State = GetPlayerState(a_Player) - return State.ToolRegistrator:UseLeftClickTool(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Player:GetEquippedItem().m_ItemType) + State.ToolRegistrator:UseLeftClickTool(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Player:GetEquippedItem().m_ItemType) +end + + + + + +local function PlayerBrokeBlockHook(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta) + if a_Player:GetEquippedItem().m_ItemType == E_ITEM_WOODEN_AXE then + a_Player:GetWorld():SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta) + end end @@ -320,6 +336,7 @@ end -- Register the hooks needed: -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, RightClickToolsHook); -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, LeftClickToolsHook); -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_ANIMATION, LeftClickToolsAnimationHook); +cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, RightClickToolsHook); +cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, LeftClickToolsHook); +cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_BROKEN_BLOCK, PlayerBrokeBlockHook); +cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_ANIMATION, LeftClickToolsAnimationHook); From 0ee2cba5ce7e27dd7825d77679656f0c6127a139 Mon Sep 17 00:00:00 2001 From: InformationHunter Date: Tue, 21 Apr 2020 16:35:25 +0300 Subject: [PATCH 2/2] Bug fix when specifying a point in a multi-block block --- Classes/ToolRegistrator.lua | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/Classes/ToolRegistrator.lua b/Classes/ToolRegistrator.lua index 2239601..7be4025 100644 --- a/Classes/ToolRegistrator.lua +++ b/Classes/ToolRegistrator.lua @@ -75,7 +75,8 @@ function cToolRegistrator:BindAbsoluteTools() if (not Succ) then return false end - + + -- Protection against the second packet when the second position is indicated if ((os.clock() - LastRightClick) < 0.005) then return true end @@ -296,29 +297,15 @@ end -local function LeftClickToolsHook(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Action) - if (a_Action ~= 0) then - -- Left click is also called for other things like throwing items - return false - end - +local function BreakingBlockHook(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta) local State = GetPlayerState(a_Player) - State.ToolRegistrator:UseLeftClickTool(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Player:GetEquippedItem().m_ItemType) + return State.ToolRegistrator:UseLeftClickTool(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Player:GetEquippedItem().m_ItemType) end -local function PlayerBrokeBlockHook(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta) - if a_Player:GetEquippedItem().m_ItemType == E_ITEM_WOODEN_AXE then - a_Player:GetWorld():SetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta) - end -end - - - - local function LeftClickToolsAnimationHook(a_Player, a_Animation) -- In 1.8.x the left click has a value of 0, while in 1.7.x it's 1 @@ -336,7 +323,6 @@ end -- Register the hooks needed: -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, RightClickToolsHook); -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, LeftClickToolsHook); -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_BROKEN_BLOCK, PlayerBrokeBlockHook); -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_ANIMATION, LeftClickToolsAnimationHook); +cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, RightClickToolsHook); +cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_BREAKING_BLOCK, BreakingBlockHook); +cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_ANIMATION, LeftClickToolsAnimationHook);