Skip to content

Conversation

@ShockedPlot7560
Copy link
Member

Introduction

As the title suggests, this PR implements the anvils

Relevant issues

Changes

API changes

  • Introduce a new Durable::isValidRepairMaterial enabling everyone to implement their own verification logic
  • Add repairMaterials to ArmorMaterial and ToolTier
  • Add repairCost functions in Item

Behavioural changes

  • Anvil works

Tests

I tested this PR by doing the following (tick all that apply):

  • Writing PHPUnit tests (commit these in the tests/phpunit folder)
  • Playtesting using a Minecraft client (provide screenshots or a video)
  • Writing a test plugin (provide the code and sample output)
  • Other (provide details)

https://youtu.be/d3vcwi_45DY

@ShockedPlot7560 ShockedPlot7560 added Category: Gameplay Related to Minecraft gameplay experience Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Aug 10, 2024
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.

Just a quick overview

github-actions[bot]
github-actions bot previously approved these changes Aug 19, 2024
github-actions[bot]
github-actions bot previously approved these changes Aug 19, 2024
github-actions[bot]
github-actions bot previously approved these changes Aug 19, 2024
@ShockedPlot7560 ShockedPlot7560 requested a review from a team as a code owner November 18, 2024 13:52
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Nov 18, 2024
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.

My gut reaction to this is: I don't like the code.

I don't think we should be using custom actions for this since the actions are only usable with specific types of transactions. By the way other stuff has been done, different AnvilTransaction classes should be implemented.

I'm also not liking the logic of some of the item comparisons being limited to checking type IDs. Plugins will likely want to implement more complex logic, like using tags or NBT checking.

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 think it would also probably be preferable to have more events, e.g. PlayerItemRenameEvent, PlayerItemRepairEvent, PlayerItemCombineEvent (not sure about this last one). (That being said, if there were transaction types for this instead of actions, it would be a good amount nicer).

Doesn't make much sense to make plugins do complex logic to figure out the action type when we can just tell them directly.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2024

This PR has been marked as "Waiting on Author", but we haven't seen any activity in 7 days.

If there is no further activity, it will be closed in 28 days.

Note for maintainers: Adding an assignee to the PR will prevent it from being marked as stale.

@github-actions github-actions bot added the Stale label Dec 6, 2024
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Mar 22, 2025
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Mar 23, 2025
}else{
$newBlock = $anvilBlock->setDamage($newDamage);
}
$world->setBlock($inventory->getHolder(), $newBlock);
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to be able to cancel this

@dktapps dktapps requested a review from Copilot June 11, 2025 23:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements anvil functionality by adding new API methods for repair material validation, XP cost calculation, and enhanced anvil behavior. Key changes include new tests for anvil crafting, extended item repair cost handling, and integration of anvil recipes into the crafting manager.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/phpunit/crafting/* Added tests covering material repair and item self-combination recipes for anvils
src/network/mcpe/handler/ItemStackRequestExecutor.php Integrated AnvilTransaction support and optional anvil crafting action handling
src/item/Item.php Introduced anvil repair cost management with appropriate tag serialization
src/inventory/transaction/AnvilTransaction.php Added a new transaction type to validate, execute, and trigger anvil events
src/crafting/* Added new recipe types (MaterialRepairRecipe, ItemSelfCombineRecipe, etc.) and updated the crafting manager for anvil recipes
src/block/utils/AnvilHelper.php Encapsulated anvil result calculation logic with XP cost filtering

@ShockedPlot7560
Copy link
Member Author

ShockedPlot7560 commented Nov 5, 2025

Here is a TODO list to complete this PR for me:

  • Add an event to be able to cancel the anvil damage
  • Add an event or adjust events to be able to change the custom name of an item
  • Clear and precise unit tests for anvil crafting recipes
  • Validate in game the gameplay
  • Validate Anvil cost with unit tests & in game
  • Include book combinaison

pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Nov 5, 2025
@kostamax27
Copy link
Contributor

Here is a TODO list to complete this PR for me:

How about an event for canceling or changing an item’s name?

Possible uses: the server doesn’t allow colored names, censorship, etc.

@ShockedPlot7560
Copy link
Member Author

You already have PlayerUseAnvilEvent to cancel this but you can't change anything yep

@JkqzDev
Copy link

JkqzDev commented Nov 6, 2025

Here is a TODO list to complete this PR for me:

  • Add an event to be able to cancel the anvil damage
  • Add an event or adjust events to be able to change the custom name of an item
  • Clear and precise unit tests for anvil crafting recipes
  • Validate in game the gameplay
  • Validate Anvil cost with unit tests & in game

I have tested this fork and with the changes you have made I think that the combinations of items with books still do not work.
I have added it in my fork but I don't know if it is to your taste: https://github.com/RequiemPvP/PocketMine-MP/blob/dbbb4f8fb1af2ef45a77fcc495715bae9bd94aef/src/crafting/AnvilCraftingManagerDataFiller.php#L76

@ShockedPlot7560
Copy link
Member Author

Thank you @JkqzDev.
From what I can see, your implementation looks good, but it raises me one question.
Can any items really be combined with an enchanted book for Minecraft Bedrock?

@JkqzDev
Copy link

JkqzDev commented Nov 7, 2025

Thank you @JkqzDev. From what I can see, your implementation looks good, but it raises me one question. Can any items really be combined with an enchanted book for Minecraft Bedrock?

Good question @ShockedPlot7560
When I implemented it, I also had the same question, but I think this answers the question: https://github.com/RequiemPvP/PocketMine-MP/blob/dbbb4f8fb1af2ef45a77fcc495715bae9bd94aef/src/crafting/ItemCombineRecipe.php#L53
I'm not sure if it actually works the way it's supposed to.

@dktapps
Copy link
Member

dktapps commented Nov 7, 2025

Makes sense to me, though it might be worth checking if there are any primary vs secondary restrictions

pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Nov 7, 2025
@JkqzDev
Copy link

JkqzDev commented Nov 7, 2025

@ShockedPlot7560 I remember that I sent you a message about a problem that happened with Anvil: the xp cost that appeared in the UI was not always the real cost.

@ShockedPlot7560
Copy link
Member Author

It was part of the unit tests which currently failed a lot

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.

9 participants