Skip to content

Implemented Crossbow#6928

Open
alvin0319 wants to merge 17 commits intopmmp:minor-nextfrom
alvin0319:feat/crossbow
Open

Implemented Crossbow#6928
alvin0319 wants to merge 17 commits intopmmp:minor-nextfrom
alvin0319:feat/crossbow

Conversation

@alvin0319
Copy link
Contributor

This PR implements crossbow item with two additional vanilla enchantments for crossbow.

Related issues & PRs

Fixes #6864

This PR includes logics from dragonfly.

Changes

API changes

  • Introduced Chargeable interface: Implemented by items that can be charged. (e.g., crossbow)
  • Added VanillaEnchantments::QUICK_CHARGE() and VanillaEnchantments::MULTISHOT().
  • Added EntityShootCrossbowEvent.
  • Added CrossbowLoadSound and CrossbowShootSound.

Behavioural changes

  • Player::releaseHeldItem() now handles Chargeable items when player is using an item.

Backwards compatibility

No breaking changes.

Follow-up

  • Implement support for loading and shooting Firework Rockets.

Tests

Manual playtest have been done, attaching video below.

Screen_Recording_20251205_202837_Minecraft.mp4

@alvin0319 alvin0319 requested a review from a team as a code owner December 5, 2025 13:39
@remminiscent
Copy link
Contributor

exact system i had in mind. great work.

@kostamax27
Copy link
Contributor

kostamax27 commented Dec 5, 2025

https://minecraft.fandom.com/wiki/Enchanting#Summary_of_enchantments

Enchantment Primary / Secondary
Quick Charge Primary
Multishot Primary
Piercing Primary
Unbreaking Secondary
Mending Secondary
Curse of Vanishing Secondary

@kostamax27
Copy link
Contributor

Oops. Unbreaking in Primary...

@alvin0319
Copy link
Contributor Author

I reverted that since ItemEnchantmentTagRegistry covers CROSSBOW in WEAPON

@kostamax27
Copy link
Contributor

sound.mp4

@alvin0319
Copy link
Contributor Author

sound.mp4

I'm not sure what it means? is it some kind of sound desync?

@kostamax27
Copy link
Contributor

sound.mp4

I'm not sure what it means? is it some kind of sound desync?

A similar issue exists on dragonfly - but it’s even worse there. The server keeps spamming the crossbow sound, and it’s not just me who hears it; nearby players hear it as well.

@alvin0319
Copy link
Contributor Author

sound.mp4

I'm not sure what it means? is it some kind of sound desync?

A similar issue exists on dragonfly - but it’s even worse there. The server keeps spamming the crossbow sound, and it’s not just me who hears it; nearby players hear it as well.

Can you try with latest commit, it should fix that temporary (although I don't like this fix, need to find proper solution)

@kostamax27
Copy link
Contributor

In the video, you can see my inputs in the bottom-left corner, but I'll outline the steps just in case:

  1. Equip the crossbow.
  2. Charge the crossbow (hold right mouse button) and click the left mouse button.
sound.mp4

@alvin0319
Copy link
Contributor Author

In the video, you can see my inputs in the bottom-left corner, but I'll outline the steps just in case:

  1. Equip the crossbow.
  2. Charge the crossbow (hold right mouse button) and click the left mouse button.

sound.mp4

I can't reproduce it in current environment where I have no PC client to test... and sound should be fixed with latest commit. Can you verify you are using latest commit using /version command?

@kostamax27
Copy link
Contributor

In the video, you can see my inputs in the bottom-left corner, but I'll outline the steps just in case:

  1. Equip the crossbow.
  2. Charge the crossbow (hold right mouse button) and click the left mouse button.

sound.mp4

I can't reproduce it in current environment where I have no PC client to test... and sound should be fixed with latest commit. Can you verify you are using latest commit using /version command?

Command output | This server is running PocketMine-MP
Command output | Server version: 5.37.4+dev (git hash: 31ec74ea561df94ed3dfa1a5261a724d0fe51417)
Command output | Compatible Minecraft version: 1.21.124 (protocol version: 860)
Command output | PHP version: 8.4.12
Command output | PHP JIT: enabled (CRTO: 1255)
Command output | Operating system: linux

@kostamax27
Copy link
Contributor

I have no PC client to test.

sound-mobile.mp4

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.

I don't think the network actions for crossbow loading are handled correctly.
My gut instinct is that:

  • left-click-air should begin loading the crossbow
  • continue use should finish loading when the use duration >= the required load duration
  • release should only be used if the player aborts loading the crossbow

@dktapps dktapps added Category: Gameplay Related to Minecraft gameplay experience Status: Waiting on Author Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Dec 8, 2025
@alvin0319
Copy link
Contributor Author

Here's BDS's MITM packet log.txt for those who are interested in, I'll be digging into this more in coming weekend.

@kostamax27
Copy link
Contributor

First, I want to point out that CompletedUsingItemPacket truly has no effect on the behavior.
I managed to achieve the "vanilla" crossbow behavior by doing the following:

  1. Remove: $player->setUsingItem(false);
    from Crossbow::onReleaseUsing.
  2. In Crossbow::continueUsing, when $useDuration >= $chargeDuration, replace return true;
    with:
    return $player->releaseHeldItem();

I understand this isn’t the correct or intended approach, but hopefully it gives you an idea in the right direction.

vanilla.mp4
pmmp.mp4

@dktapps dktapps changed the base branch from stable to minor-next December 19, 2025 20:23
@alvin0319
Copy link
Contributor Author

I have pushed commits that address your comments, it seems this approach does better job than the original though.

@dktapps
Copy link
Member

dktapps commented Dec 24, 2025

I have pushed commits that address your comments, it seems this approach does better job than the original though.

Not too sure about that. The issue is that the player may release the crossbow before the time is up, aborting the load, but the server might not get the action until after the crossbow is already loaded server-side. That then leads to the crossbow being unexpectedly loaded when the client's connection catches up. I mentioned this previously and also in #6958.

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.

Implement Crossbows

4 participants