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

Implemented a proper way to handle items cooldown #6405

Open
wants to merge 9 commits into
base: minor-next
Choose a base branch
from

Conversation

ipad54
Copy link
Contributor

@ipad54 ipad54 commented Jul 17, 2024

Introduction

This PR implements a proper way to handle item coodowns. These changes are necessary to make goat horns PR (and later shields) work correctly.

Changes

API changes

Added Item::getCooldownTag() : ?string to identify item cooldown group
Added ItemCooldownTags that stores a list of vanilla cooldown groups.

Behaviour changes

Item cooldowns are now synchronized with client via PlayerStartItemCooldownPacket.
Item cooldown tags are now used to store item cooldowns. If item doesn't have such, stateId will be used.

Relevant issues

#5232

Tests

Tested with goat horns PR.
Screenshot_20240717_142451_com mojang minecraftpe

@IvanCraft623
Copy link
Member

pocketmine in server-side is applying the cooldown to the items with the same stateId, while through PlayerStartItemCooldownPacket the cooldown is applied to all items with the same name.

This means for example that for example when using a goat horn, the server is applying cooldown to an specific variant of the item, while the client is applying cooldown for all goat horns.

So we have a mismatch here.

@IvanCraft623 IvanCraft623 added Category: Gameplay Related to Minecraft gameplay experience Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Aug 8, 2024
@IvanCraft623
Copy link
Member

Also i'm not sure if vanilla sends PlayerStartItemCooldownPacket to tell clients about cooldown.

@ipad54
Copy link
Contributor Author

ipad54 commented Aug 10, 2024

Also i'm not sure if vanilla sends PlayerStartItemCooldownPacket to tell clients about cooldown.

From my tests in BDS vanilla sends PlayerStartItemCooldownPacket for all new items that have cooldown (shields and goat hoarns). However, it doesn't send this packet for old items that were added back in MCPE days (chorus fruits and ender pearls). They have their cooldown implemented client-side. I think we can skip this and send the packet for all items?

@ipad54
Copy link
Contributor Author

ipad54 commented Aug 10, 2024

pocketmine in server-side is applying the cooldown to the items with the same stateId, while through PlayerStartItemCooldownPacket the cooldown is applied to all items with the same name.

This means for example that for example when using a goat horn, the server is applying cooldown to an specific variant of the item, while the client is applying cooldown for all goat horns.

So we have a mismatch here.

It looks like vanilla bothers only about item type. Would it be correct to change the logic in pocketmine to use typeId to store cooldown?

@dktapps
Copy link
Member

dktapps commented Aug 10, 2024

There's no direct link between PM item types and Minecraft item IDs. In some cases multiple IDs are flattened under the same item in PM, and in other cases a single ID is split into several PM-side items. Basically you can't rely on either typeID or stateID for this.

Possibly a better approach might be to introduce a "cooldown tag". PM would start a cooldown using the item's cooldown tag if it has one. Then any other items with the same cooldown tag can't be used until the cooldown expires.

@ipad54 ipad54 changed the title Implemented item cooldown synchronization with client Implemented a proper way to handle items cooldown Aug 13, 2024
Copy link
Member

@ShockedPlot7560 ShockedPlot7560 left a comment

Choose a reason for hiding this comment

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

Looks ok to me

@ShockedPlot7560 ShockedPlot7560 requested a review from a team August 21, 2024 08:49
Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

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

See review comments.

Copy link
Member

@IvanCraft623 IvanCraft623 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your constribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Gameplay Related to Minecraft gameplay experience Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants