-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implemented smithing table functionality #6202
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
Open
HimmelKreis4865
wants to merge
36
commits into
pmmp:minor-next
Choose a base branch
from
HimmelKreis4865:smithing-table
base: minor-next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ae13dc9
add basic smithing table requirements
HimmelKreis4865 16de186
Merge branch 'pmmp:stable' into smithing-table
HimmelKreis4865 fc5e5eb
fixed remaining problems
HimmelKreis4865 c3ea0ba
phpstan stop crying
HimmelKreis4865 2a56e41
why are headers missing?
HimmelKreis4865 4da34c3
updated version with all fixes except for save ids - they must be fixed
HimmelKreis4865 6dce15d
oops (save ids still not working)
HimmelKreis4865 b82de65
oops
HimmelKreis4865 93db5ef
fixes all big remaining issues
HimmelKreis4865 1ad80e9
Merge remote-tracking branch 'origin/minor-next' into working-smithing
HimmelKreis4865 5360b77
cs style fixes
HimmelKreis4865 7433655
resolved some more problems
HimmelKreis4865 d987a65
made materials & patterns customizable
HimmelKreis4865 d818686
Merge branch 'minor-next' of https://github.com/pmmp/PocketMine-MP in…
ipad54 849f9b1
Code overhaul
ipad54 348a211
Update src/inventory/transaction/SmithingTransaction.php
ipad54 2294a6f
CS
ipad54 e19d0d7
Make trim constants private
ipad54 671a578
Merge branch 'smithing-table' of https://github.com/HimmelKreis4865/P…
ipad54 30a4edb
Don't use match
ipad54 d88960e
Use readonly where possible
ipad54 f479d66
Fix CS
ipad54 1deacda
Revert "Don't use match"
ipad54 b8da323
Fix tests
ipad54 c41cf15
Changes for review
ipad54 780b373
Declare all offset constants together
ipad54 a68323a
Merge branch 'minor-next' of https://github.com/pmmp/PocketMine-MP in…
ipad54 ba55fa3
Merge branch 'minor-next' of https://github.com/pmmp/PocketMine-MP in…
ipad54 b140a79
Merge branch 'minor-next' into smithing-table
dktapps 5cd4813
Merge branch 'smithing-table' of https://github.com/HimmelKreis4865/P…
ipad54 275b084
Merge branch 'minor-next' of https://github.com/pmmp/PocketMine-MP in…
ipad54 f8c99c2
Added resin material
ipad54 9e76cf7
Fix grammar
ipad54 a0b4a31
Fix PHPStan
ipad54 f3dfe55
CS
ipad54 6b5a891
Merge branch 'minor-next' into smithing-table
dktapps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * | ||
| * ____ _ _ __ __ _ __ __ ____ | ||
| * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
| * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
| * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
| * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * @author PocketMine Team | ||
| * @link http://www.pocketmine.net/ | ||
| * | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace pocketmine\crafting; | ||
|
|
||
| use pocketmine\item\Item; | ||
|
|
||
| abstract class SmithingRecipe{ | ||
HimmelKreis4865 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| abstract public function getInput() : RecipeIngredient; | ||
|
|
||
| abstract public function getAddition() : RecipeIngredient; | ||
|
|
||
| abstract public function getTemplate() : RecipeIngredient; | ||
|
|
||
| abstract public function constructOutput(Item $input, Item $addition, Item $template) : ?Item; | ||
HimmelKreis4865 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * | ||
| * ____ _ _ __ __ _ __ __ ____ | ||
| * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
| * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
| * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
| * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * @author PocketMine Team | ||
| * @link http://www.pocketmine.net/ | ||
| * | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace pocketmine\crafting; | ||
|
|
||
| use pocketmine\item\Item; | ||
|
|
||
| class SmithingTransformRecipe extends SmithingRecipe{ | ||
|
|
||
| public function __construct( | ||
| private RecipeIngredient $input, | ||
| private RecipeIngredient $addition, | ||
| private RecipeIngredient $template, | ||
| private Item $result | ||
| ){ | ||
| $this->result = clone $this->result; | ||
| } | ||
|
|
||
| public function getInput() : RecipeIngredient{ | ||
| return $this->input; | ||
| } | ||
|
|
||
| public function getAddition() : RecipeIngredient{ | ||
| return $this->addition; | ||
| } | ||
|
|
||
| public function getTemplate() : RecipeIngredient{ | ||
| return $this->template; | ||
| } | ||
|
|
||
| public function getResult() : Item{ | ||
| return clone $this->result; | ||
| } | ||
|
|
||
| public function constructOutput(Item $input, Item $addition, Item $template) : ?Item{ | ||
| return $this->getResult()->setNamedTag($input->getNamedTag()); | ||
ShockedPlot7560 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * | ||
| * ____ _ _ __ __ _ __ __ ____ | ||
| * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
| * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
| * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
| * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * @author PocketMine Team | ||
| * @link http://www.pocketmine.net/ | ||
| * | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace pocketmine\crafting; | ||
|
|
||
| use pocketmine\item\Armor; | ||
| use pocketmine\item\ArmorTrim; | ||
| use pocketmine\item\ArmorTrimMaterial; | ||
| use pocketmine\item\ArmorTrimPattern; | ||
| use pocketmine\item\Item; | ||
|
|
||
| class SmithingTrimRecipe extends SmithingRecipe{ | ||
|
|
||
| public function __construct( | ||
| private RecipeIngredient $input, | ||
| private RecipeIngredient $addition, | ||
| private RecipeIngredient $template){ | ||
| } | ||
|
|
||
| public function getInput() : RecipeIngredient{ | ||
| return $this->input; | ||
| } | ||
|
|
||
| public function getAddition() : RecipeIngredient{ | ||
| return $this->addition; | ||
| } | ||
|
|
||
| public function getTemplate() : RecipeIngredient{ | ||
| return $this->template; | ||
| } | ||
|
|
||
| public function constructOutput(Item $input, Item $addition, Item $template) : ?Item{ | ||
| if(!$input instanceof Armor){ | ||
| return null; | ||
| } | ||
| if(($material = ArmorTrimMaterial::fromItem($addition)) === null || ($pattern = ArmorTrimPattern::fromItem($template)) === null){ | ||
| return null; | ||
| } | ||
| return $input->setTrim(new ArmorTrim($material, $pattern)); | ||
HimmelKreis4865 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * | ||
| * ____ _ _ __ __ _ __ __ ____ | ||
| * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
| * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
| * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
| * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * @author PocketMine Team | ||
| * @link http://www.pocketmine.net/ | ||
| * | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace pocketmine\inventory\transaction; | ||
|
|
||
| use pocketmine\item\Armor; | ||
| use pocketmine\item\Item; | ||
| use pocketmine\item\ItemTypeIds; | ||
| use pocketmine\item\TieredTool; | ||
| use pocketmine\Server; | ||
| use function count; | ||
|
|
||
| class SmithingTransaction extends InventoryTransaction{ | ||
|
|
||
| public function validate() : void{ | ||
| if(count($this->actions) < 1){ | ||
| throw new TransactionValidationException("Transaction must have at least one action to be executable"); | ||
| } | ||
|
|
||
| /** @var Item[] $inputs */ | ||
| $inputs = []; | ||
| /** @var Item[] $outputs */ | ||
ipad54 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $outputs = []; | ||
| $this->matchItems($outputs, $inputs); | ||
|
|
||
| if(($inputCount = count($inputs)) !== 3){ | ||
| throw new TransactionValidationException("Expected 3 input items, got $inputCount"); | ||
| } | ||
| if(($outputCount = count($outputs)) !== 1){ | ||
| throw new TransactionValidationException("Expected 1 output item, but received $outputCount"); | ||
| } | ||
|
|
||
| $input = $addition = $template = null; | ||
| foreach($inputs as $item){ | ||
| switch(true){ | ||
HimmelKreis4865 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| case $item instanceof Armor || $item instanceof TieredTool: | ||
| $input = $item; | ||
| break; | ||
| case $item->getTypeId() >= ItemTypeIds::NETHERITE_UPGRADE_SMITHING_TEMPLATE && $item->getTypeId() <= ItemTypeIds::SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE: | ||
HimmelKreis4865 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $template = $item; | ||
| break; | ||
| default: | ||
| $addition = $item; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if($input === null || $addition === null || $template === null){ | ||
| throw new TransactionValidationException("The given inputs are no valid smithing ingredients"); | ||
HimmelKreis4865 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| $craftingManager = Server::getInstance()->getCraftingManager(); | ||
| $recipe = $craftingManager->matchSmithingRecipe($input, $addition, $template); | ||
|
|
||
| if(($output = $recipe?->constructOutput($input, $addition, $template)) === null){ | ||
HimmelKreis4865 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| throw new TransactionValidationException("Could find a matching output item for the given inputs"); | ||
ipad54 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if(!$output->equalsExact($outputs[0])){ | ||
| throw new TransactionValidationException("Invalid output item"); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.