-
-
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
base: minor-next
Are you sure you want to change the base?
Changes from 36 commits
ae13dc9
16de186
fc5e5eb
c3ea0ba
2a56e41
4da34c3
6dce15d
b82de65
93db5ef
1ad80e9
5360b77
7433655
d987a65
d818686
849f9b1
348a211
2294a6f
e19d0d7
671a578
30a4edb
d88960e
f479d66
1deacda
b8da323
c41cf15
780b373
a68323a
ba55fa3
b140a79
5cd4813
275b084
f8c99c2
9e76cf7
a0b4a31
f3dfe55
6b5a891
64cae7c
7fb8f79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?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; | ||
|
|
||
| interface SmithingRecipe{ | ||
|
|
||
| public function getInput() : RecipeIngredient; | ||
|
|
||
| public function getAddition() : RecipeIngredient; | ||
|
|
||
| public function getTemplate() : RecipeIngredient; | ||
|
|
||
| /** | ||
| * @param Item[] $inputs | ||
| */ | ||
| public function getResultFor(array $inputs) : ?Item; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?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 implements SmithingRecipe{ | ||
|
|
||
| public function __construct( | ||
| private readonly RecipeIngredient $input, | ||
| private readonly RecipeIngredient $addition, | ||
| private readonly 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; | ||
| } | ||
|
|
||
| /** | ||
| * @param Item[] $inputs | ||
| */ | ||
| public function getResultFor(array $inputs) : ?Item{ | ||
| foreach($inputs as $item){ | ||
| if($this->input->accepts($item)){ | ||
| return $this->getResult()->setNamedTag($item->getNamedTag()); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| <?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\data\bedrock\ArmorTrimMaterialTypeIdMap; | ||
| use pocketmine\data\bedrock\ArmorTrimPatternTypeIdMap; | ||
| use pocketmine\item\Armor; | ||
| use pocketmine\item\ArmorTrim; | ||
| use pocketmine\item\Item; | ||
|
|
||
| class SmithingTrimRecipe implements SmithingRecipe{ | ||
|
|
||
| public function __construct( | ||
| private readonly RecipeIngredient $input, | ||
| private readonly RecipeIngredient $addition, | ||
| private readonly RecipeIngredient $template | ||
| ){} | ||
|
|
||
| public function getInput() : RecipeIngredient{ | ||
| return $this->input; | ||
| } | ||
|
|
||
| public function getAddition() : RecipeIngredient{ | ||
| return $this->addition; | ||
| } | ||
|
|
||
| public function getTemplate() : RecipeIngredient{ | ||
| return $this->template; | ||
| } | ||
|
|
||
| /** | ||
| * @param Item[] $inputs | ||
| */ | ||
| public function getResultFor(array $inputs) : ?Item{ | ||
|
dktapps marked this conversation as resolved.
|
||
| $input = $template = $addition = null; | ||
| foreach($inputs as $item){ | ||
| if($this->input->accepts($item) && $item instanceof Armor){ | ||
| $input = $item; | ||
| }elseif($this->addition->accepts($item)){ | ||
| $addition = $item; | ||
| }elseif($this->template->accepts($item)){ | ||
| $template = $item; | ||
| } | ||
| } | ||
| if($input !== null && $addition !== null && $template !== null){ | ||
| $material = ArmorTrimMaterialTypeIdMap::getInstance()->fromItem($addition); | ||
| $pattern = ArmorTrimPatternTypeIdMap::getInstance()->fromItem($template); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really don't like this. |
||
| if($material !== null && $pattern !== null){ | ||
| return (clone $input)->setTrim(new ArmorTrim($material, $pattern)); | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| <?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\data\bedrock; | ||
|
|
||
| use pocketmine\data\bedrock\ArmorTrimMaterialTypeIds as Ids; | ||
| use pocketmine\item\ArmorTrimMaterial; | ||
| use pocketmine\item\Item; | ||
| use pocketmine\item\VanillaArmorTrimMaterials as Materials; | ||
| use pocketmine\utils\AssumptionFailedError; | ||
| use pocketmine\utils\SingletonTrait; | ||
| use function array_key_exists; | ||
| use function array_values; | ||
| use function spl_object_id; | ||
|
|
||
| final class ArmorTrimMaterialTypeIdMap{ | ||
| use SingletonTrait; | ||
|
|
||
| /** | ||
| * @var ArmorTrimMaterial[] | ||
| * @phpstan-var array<string, ArmorTrimMaterial> | ||
| */ | ||
| private array $idToMaterial = []; | ||
| /** | ||
| * @var ArmorTrimMaterial[] | ||
| * @phpstan-var array<int, ArmorTrimMaterial> | ||
| */ | ||
| private array $itemToMaterial = []; | ||
| /** | ||
| * @var string[] | ||
| * @phpstan-var array<int, string> | ||
| */ | ||
| private array $materialToId = []; | ||
|
|
||
| public function __construct(){ | ||
| foreach(Materials::getAll() as $material){ | ||
| $this->register(match($material){ | ||
| Materials::AMETHYST() => Ids::AMETHYST, | ||
| Materials::COPPER() => Ids::COPPER, | ||
| Materials::DIAMOND() => Ids::DIAMOND, | ||
| Materials::EMERALD() => Ids::EMERALD, | ||
| Materials::GOLD() => Ids::GOLD, | ||
| Materials::IRON() => Ids::IRON, | ||
| Materials::LAPIS() => Ids::LAPIS, | ||
| Materials::NETHERITE() => Ids::NETHERITE, | ||
| Materials::QUARTZ() => Ids::QUARTZ, | ||
| Materials::REDSTONE() => Ids::REDSTONE, | ||
| Materials::RESIN() => Ids::RESIN, | ||
| default => throw new AssumptionFailedError("Unhandled armor trim material type") | ||
| }, $material); | ||
| } | ||
| } | ||
|
|
||
| public function register(string $stringId, ArmorTrimMaterial $material) : void{ | ||
| $this->idToMaterial[$stringId] = $material; | ||
| $this->itemToMaterial[$material->getItem()->getStateId()] = $material; | ||
| $this->materialToId[spl_object_id($material)] = $stringId; | ||
| } | ||
|
|
||
| public function fromId(string $id) : ?ArmorTrimMaterial{ | ||
| return $this->idToMaterial[$id] ?? null; | ||
| } | ||
|
|
||
| public function fromItem(Item $item) : ?ArmorTrimMaterial{ | ||
| return $this->itemToMaterial[$item->getStateId()] ?? null; | ||
| } | ||
|
|
||
| public function toId(ArmorTrimMaterial $material) : string{ | ||
| $k = spl_object_id($material); | ||
|
ipad54 marked this conversation as resolved.
|
||
| if(!array_key_exists($k, $this->materialToId)){ | ||
| throw new \InvalidArgumentException("Missing mapping for armor trim material with item" . $material->getItem()->getName() . " and color " . $material->getColor()); | ||
| } | ||
| return $this->materialToId[$k]; | ||
| } | ||
|
|
||
| /** | ||
| * @return ArmorTrimMaterial[] | ||
| * @phpstan-return list<ArmorTrimMaterial> | ||
| */ | ||
| public function getAllMaterials() : array{ | ||
| return array_values($this->idToMaterial); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.