-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement anvil #6418
base: minor-next
Are you sure you want to change the base?
Implement anvil #6418
Conversation
There was a problem hiding this 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
@@ -61,4 +63,8 @@ public function getFuelTime() : int{ | |||
public function isFireProof() : bool{ | |||
return $this->tier === ToolTier::NETHERITE; | |||
} | |||
|
|||
public function isValidRepairMaterial(Item $material) : bool{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't like this name, feel that the material terminology doesn't fit, instead i would name it something like canBeRepairedBy or isRepairedBy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks more like french tbh 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the name used in the wiki to refer to materials.
But just specifying, canBeRepairedBy
can lead to confusion in thinking that it can be both the materials and the tool/armour itself. Whereas what we're expecting here is just the materials
|
||
declare(strict_types=1); | ||
|
||
namespace pocketmine\block\anvil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to be placed in block namespace? Wouldn’t be better to move anvil inventory actions logic into the inventory\transaction
namespace since it’s more associated with anvil transactions rather than block itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inventory\transaction
namespace is intended for handling player's requested ones, but in this use case what we are actually doing is creating fictitious actions for the use of the anvil.
There was a problem hiding this 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.
public function getActions(Item $base, Item $material, ?string $customName) : array{ | ||
$actions = []; | ||
foreach($this->actions as $class => $_){ | ||
$action = new $class($base, $material, $customName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I really don't like this.
throw new AssumptionFailedError("Expected that baseItem are not null before executing the event"); | ||
} | ||
|
||
$ev = new PlayerUseAnvilEvent($this->source, $this->baseItem, $this->materialItem, $this->expectedResult->getResult() ?? throw new \AssertionError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be PlayerAnvilUseEvent
to match other event naming conventions
@@ -172,4 +173,8 @@ protected function serializeCompoundTag(CompoundTag $tag) : void{ | |||
$tag->setInt(self::TAG_CUSTOM_COLOR, Binary::signInt($this->customColor->toARGB())) : | |||
$tag->removeTag(self::TAG_CUSTOM_COLOR); | |||
} | |||
|
|||
public function isValidRepairMaterial(Item $material) : bool{ | |||
return in_array($material->getTypeId(), $this->armorInfo->getMaterial()->getRepairMaterials(), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use in_array :(
ItemTypeIds::fromBlockTypeId(BlockTypeIds::WARPED_PLANKS), | ||
ItemTypeIds::fromBlockTypeId(BlockTypeIds::CHERRY_PLANKS), | ||
ItemTypeIds::fromBlockTypeId(BlockTypeIds::MANGROVE_PLANKS) | ||
]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not liking this either.
There was a problem hiding this 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.
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. |
Introduction
As the title suggests, this PR implements the anvils
Relevant issues
Changes
API changes
Durable::isValidRepairMaterial
enabling everyone to implement their own verification logicrepairMaterials
toArmorMaterial
andToolTier
Item
Behavioural changes
Tests
I tested this PR by doing the following (tick all that apply):
tests/phpunit
folder)https://youtu.be/d3vcwi_45DY