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

Implement anvil #6418

Open
wants to merge 12 commits into
base: minor-next
Choose a base branch
from
Prev Previous commit
Next Next commit
fix PHPstan
ShockedPlot7560 committed Aug 10, 2024

Verified

This commit was signed with the committer’s verified signature.
justjanne Janne Mareike Koschinski
commit 804731d87fb384173020b7a8d5564af1125ab024
12 changes: 8 additions & 4 deletions src/inventory/transaction/AnvilTransaction.php
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@
class AnvilTransaction extends InventoryTransaction{
private ?Item $baseItem = null;
private ?Item $materialItem = null;
private ?Item $resultItem = null;

public function __construct(
Player $source,
@@ -59,13 +58,16 @@ private function validateFiniteResources(int $xpSpent) : void{

private function validateInputs(Item $base, Item $material, Item $expectedOutput) : ?AnvilResult {
$calculAttempt = AnvilHelper::calculateResult($this->source, $base, $material, $this->customName);
if($calculAttempt->getResult() === null || !$calculAttempt->getResult()->equalsExact($expectedOutput)){
if($calculAttempt === null){
return null;
}
$result = $calculAttempt->getResult();
if($result === null || !$result->equalsExact($expectedOutput)){
return null;
}

$this->baseItem = $base;
$this->materialItem = $material;
$this->resultItem = $expectedOutput;

return $calculAttempt;
}
@@ -120,7 +122,9 @@ protected function callExecuteEvent() : bool{
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(), $this->customName, $this->expectedResult->getRepairCost());
$ev = new PlayerUseAnvilEvent($this->source, $this->baseItem, $this->materialItem, $this->expectedResult->getResult() ?? throw new \AssertionError(
Copy link
Member

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

"Expected that the expected result is not null"
), $this->customName, $this->expectedResult->getRepairCost());
$ev->call();
return !$ev->isCancelled();
}