-
Notifications
You must be signed in to change notification settings - Fork 25
feat: implemented smithing table missing recipes #48
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
NaySurGithub
wants to merge
4
commits into
altayofficial:dev
Choose a base branch
from
NaySurGithub:feat/smithing_table
base: dev
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5cd9ffe
Implemented smithing table
NaySurGithub cf12af9
Moved ArmorTrimRegistry to data/bedrock/item
NaySurGithub 5f47e00
Renamed ArmorTrimRegistry to ArmorTrimIdMap
NaySurGithub 577ad72
Renamed ArmorTrimRegistry references to ArmorTrimIdMap
NaySurGithub 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
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,67 @@ | ||
| <?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. | ||
| * | ||
| * Original work by the PocketMine Team. | ||
| * https://www.pocketmine.net/ | ||
| * | ||
| * @author Altay Team | ||
| * @link https://github.com/altayofficial | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace pocketmine\crafting; | ||
|
|
||
| use pocketmine\utils\AssumptionFailedError; | ||
|
|
||
| /** | ||
| * Represents the smithing table's armor trim recipe. This only exists so the client knows which items are valid in | ||
| * each smithing table slot and to advertise the recipe in the recipe book - the actual result item (which depends on | ||
| * the specific pattern and material used) is computed by {@link \pocketmine\inventory\transaction\SmithingTrimTransaction} | ||
| * rather than through the generic recipe matching system, since getResultsFor()/matchesCraftingGrid() aren't called. | ||
| */ | ||
| final class SmithingTrimRecipe implements CraftingRecipe{ | ||
|
|
||
| public function __construct( | ||
| private RecipeIngredient $base, | ||
| private RecipeIngredient $addition, | ||
| private RecipeIngredient $template | ||
| ){} | ||
|
|
||
| public function getBase() : RecipeIngredient{ | ||
| return $this->base; | ||
| } | ||
|
|
||
| public function getAddition() : RecipeIngredient{ | ||
| return $this->addition; | ||
| } | ||
|
|
||
| public function getTemplate() : RecipeIngredient{ | ||
| return $this->template; | ||
| } | ||
|
|
||
| public function getIngredientList() : array{ | ||
| return [$this->base, $this->addition, $this->template]; | ||
| } | ||
|
|
||
| public function getResultsFor(CraftingGrid $grid) : array{ | ||
| throw new AssumptionFailedError("Armor trim results are computed by SmithingTrimTransaction, not through the generic recipe system"); | ||
| } | ||
|
|
||
| public function matchesCraftingGrid(CraftingGrid $grid) : bool{ | ||
| return false; | ||
| } | ||
| } |
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,84 @@ | ||
| <?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. | ||
| * | ||
| * Original work by the PocketMine Team. | ||
| * https://www.pocketmine.net/ | ||
| * | ||
| * @author Altay Team | ||
| * @link https://github.com/altayofficial | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace pocketmine\data\bedrock\item; | ||
|
|
||
| use pocketmine\crafting\CraftingManagerFromDataHelper; | ||
| use pocketmine\data\bedrock\BedrockDataFiles; | ||
| use pocketmine\data\SavedDataLoadingException; | ||
| use pocketmine\item\Item; | ||
| use pocketmine\utils\Filesystem; | ||
| use pocketmine\utils\SingletonTrait; | ||
| use function is_array; | ||
| use function is_string; | ||
| use function json_decode; | ||
|
|
||
| /** | ||
| * Maps smithing templates to trim pattern IDs, and trim-eligible ingredients (ingots, crystals, etc.) to trim material | ||
| * IDs, as used by the smithing table's armor trim recipe. | ||
| */ | ||
| final class ArmorTrimIdMap{ | ||
| use SingletonTrait; | ||
|
|
||
| /** @var array<int, string> typeId => patternId */ | ||
| private array $patterns = []; | ||
| /** @var array<int, string> typeId => materialId */ | ||
| private array $materials = []; | ||
|
|
||
| private function __construct(){ | ||
| $data = json_decode(Filesystem::fileGetContents(BedrockDataFiles::TRIM_DATA_JSON), true); | ||
| if(!is_array($data) || !isset($data["patterns"], $data["materials"]) || !is_array($data["patterns"]) || !is_array($data["materials"])){ | ||
| throw new SavedDataLoadingException(BedrockDataFiles::TRIM_DATA_JSON . " should contain patterns and materials lists"); | ||
| } | ||
|
|
||
| foreach($data["patterns"] as $pattern){ | ||
| if(!is_array($pattern) || !isset($pattern["itemName"], $pattern["patternId"]) || !is_string($pattern["itemName"]) || !is_string($pattern["patternId"])){ | ||
| throw new SavedDataLoadingException("Invalid trim pattern entry"); | ||
| } | ||
| $item = CraftingManagerFromDataHelper::deserializeItemStackFromFields($pattern["itemName"], null, 1, null, null); | ||
| if($item !== null){ | ||
| $this->patterns[$item->getTypeId()] = $pattern["patternId"]; | ||
| } | ||
| } | ||
|
|
||
| foreach($data["materials"] as $material){ | ||
| if(!is_array($material) || !isset($material["itemName"], $material["materialId"]) || !is_string($material["itemName"]) || !is_string($material["materialId"])){ | ||
| throw new SavedDataLoadingException("Invalid trim material entry"); | ||
| } | ||
| $item = CraftingManagerFromDataHelper::deserializeItemStackFromFields($material["itemName"], null, 1, null, null); | ||
| if($item !== null){ | ||
| $this->materials[$item->getTypeId()] = $material["materialId"]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public function getPatternId(Item $template) : ?string{ | ||
| return $this->patterns[$template->getTypeId()] ?? null; | ||
| } | ||
|
|
||
| public function getMaterialId(Item $ingredient) : ?string{ | ||
| return $this->materials[$ingredient->getTypeId()] ?? null; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
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.
When upgrading damaged, enchanted, named, unbreakable, or trimmed diamond equipment, this static
ShapelessRecipeproduces the pristine JSON result instead of inheriting the base stack's data.CraftingTransaction::getExpectedResultsFor()only invokes this recipe and the container-specific transfer helper, so the client's correctly inherited netherite output will fail the exact-output validation and the upgrade will be rejected; smithing transforms need a dynamic result derived from the base item.Useful? React with 👍 / 👎.