Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs when selecting an area #140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix bugs when selecting an area #140

wants to merge 2 commits into from

Conversation

ruqeg
Copy link

@ruqeg ruqeg commented Apr 20, 2020

  • The output of information on indicating the second position will be displayed once
  • There will be no friezes when selecting the first position Use PLAYER_BREAKING_BLOCK then PLAYER_LEFT_CLICK (better when working with multi-block structures)

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment here explaining why this is necessary would be useful (multiple packets come through in a single tick?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment here explaining why this is necessary would be useful (multiple packets come through in a single tick?)

In some cases, when the second position is indicated, the client sends 2 packets

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check the a_BlockFace parameter? It's possible we can filter out the second packet if a_BlockFace is BLOCK_FACE_NONE.

Also, wouldn't it make more sense to put the check before setting the selection? Now the selection still gets set twice, but the second time the player isn't notified.

Copy link
Author

@ruqeg ruqeg May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check the a_BlockFace parameter? It's possible we can filter out the second packet if a_BlockFace is BLOCK_FACE_NONE.

Also, wouldn't it make more sense to put the check before setting the selection? Now the selection still gets set twice, but the second time the player isn't notified.

The problem is that we catch 3 packages, 2 of them are normal, and the third with BLOCK_FACE_NONE. Even with checking for BLOCK_FACE_NONE, 2 messages are displayed. Example:

  1. Normal
  2. BLOCK_FACE_NONE
  3. Normal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I guess the os.clock() method is the simplest way to avoid this. It's also somewhat forwards compatible if Mojang decide to change the number of packets again.

Classes/ToolRegistrator.lua Outdated Show resolved Hide resolved
@bearbin
Copy link
Member

bearbin commented Apr 21, 2020 via email

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will be enough for breaking multi-block structures, such as doors or beds.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will be enough for breaking multi-block structures, such as doors or beds.

PLAYER_LEFT_CLICK will not be enough for breaking multi-block structures too. But thanks to PLAYER_BROKEN_BLOCK we will not have friezes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any freezes with the original code, so I have no idea what you're trying to fix

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we care about multi-block structures, should we should use PLAYER_BREAKING_BLOCK?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any freezes with the original code, so I have no idea what you're trying to fix

Oh, maybe i put it wrong. When you select the first point (left button of the mouse), the person stops abruptly (I think it is connected with the fact that all player actions in this packet are canceled). Friezes are not permanent, only when specifying a point

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, now I see it too. When trying to select the first point while moving, the movement is stopped and the player is jerked back.

However, I think this needs a fix in Cuberite itself, rather than hacking the plugin - it seems the client doesn't like something Cuberite sends as a reaction to the rejected blockbreak.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you're right. I put everything back in place and left a bug fix when specifying the second point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants