mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 01:51:51 +00:00
fill in CraftingManager for MaterialRepair
This commit is contained in:
parent
11135c2fd8
commit
f346799920
@ -36,7 +36,7 @@ final class AnvilHelper{
|
|||||||
*
|
*
|
||||||
* Returns null if the operation can't do anything.
|
* Returns null if the operation can't do anything.
|
||||||
*/
|
*/
|
||||||
public static function calculateResult(Player $player, Item $base, Item $material, ?string $customName = null) : ?AnvilCraftResult {
|
public static function calculateResult(Player $player, Item $base, Item $material, ?string $customName = null) : ?AnvilCraftResult{
|
||||||
|
|
||||||
$recipe = Server::getInstance()->getCraftingManager()->matchAnvilRecipe($base, $material);
|
$recipe = Server::getInstance()->getCraftingManager()->matchAnvilRecipe($base, $material);
|
||||||
if($recipe === null){
|
if($recipe === null){
|
||||||
|
67
src/crafting/AnvilCraftingManagerDataFiller.php
Normal file
67
src/crafting/AnvilCraftingManagerDataFiller.php
Normal file
@ -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.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\crafting;
|
||||||
|
|
||||||
|
use pocketmine\item\ToolTier;
|
||||||
|
use pocketmine\item\VanillaArmorMaterials;
|
||||||
|
use pocketmine\item\VanillaItems;
|
||||||
|
|
||||||
|
final class AnvilCraftingManagerDataFiller{
|
||||||
|
public static function fillData(CraftingManager $manager) : CraftingManager{
|
||||||
|
foreach([
|
||||||
|
[
|
||||||
|
VanillaItems::DIAMOND(),
|
||||||
|
[VanillaArmorMaterials::DIAMOND(), ToolTier::DIAMOND]
|
||||||
|
], [
|
||||||
|
VanillaItems::GOLD_INGOT(),
|
||||||
|
[VanillaArmorMaterials::GOLD(), ToolTier::GOLD]
|
||||||
|
], [
|
||||||
|
VanillaItems::IRON_INGOT(),
|
||||||
|
[VanillaArmorMaterials::IRON(), ToolTier::IRON]
|
||||||
|
], [
|
||||||
|
VanillaItems::NETHERITE_INGOT(),
|
||||||
|
[VanillaArmorMaterials::NETHERITE(), ToolTier::NETHERITE]
|
||||||
|
], [
|
||||||
|
VanillaItems::SCUTE(),
|
||||||
|
[VanillaArmorMaterials::TURTLE(), null]
|
||||||
|
], [
|
||||||
|
VanillaItems::LEATHER(),
|
||||||
|
[VanillaArmorMaterials::LEATHER(), null]
|
||||||
|
]
|
||||||
|
] as [$item, [$armorMaterial, $toolTier]]){
|
||||||
|
$manager->registerAnvilRecipe(new MaterialRepairRecipe(
|
||||||
|
new ArmorRecipeIngredient($armorMaterial),
|
||||||
|
new ExactRecipeIngredient($item)
|
||||||
|
));
|
||||||
|
if($toolTier !== null){
|
||||||
|
$manager->registerAnvilRecipe(new MaterialRepairRecipe(
|
||||||
|
new TieredToolRecipeIngredient($toolTier),
|
||||||
|
new ExactRecipeIngredient($item)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $manager;
|
||||||
|
}
|
||||||
|
}
|
50
src/crafting/ArmorRecipeIngredient.php
Normal file
50
src/crafting/ArmorRecipeIngredient.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?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\ArmorMaterial;
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use function spl_object_id;
|
||||||
|
|
||||||
|
class ArmorRecipeIngredient implements RecipeIngredient{
|
||||||
|
public function __construct(
|
||||||
|
private ArmorMaterial $material
|
||||||
|
){
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaterial() : ArmorMaterial{ return $this->material; }
|
||||||
|
|
||||||
|
public function accepts(Item $item) : bool{
|
||||||
|
if($item->getCount() < 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item instanceof Armor && $item->getMaterial() === $this->material;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString() : string{
|
||||||
|
return "ArmorRecipeIngredient(ArmorMaterial@" . spl_object_id($this->material) . ")";
|
||||||
|
}
|
||||||
|
}
|
@ -31,16 +31,13 @@ use pocketmine\crafting\json\RecipeIngredientData;
|
|||||||
use pocketmine\crafting\json\ShapedRecipeData;
|
use pocketmine\crafting\json\ShapedRecipeData;
|
||||||
use pocketmine\crafting\json\ShapelessRecipeData;
|
use pocketmine\crafting\json\ShapelessRecipeData;
|
||||||
use pocketmine\data\bedrock\block\BlockStateData;
|
use pocketmine\data\bedrock\block\BlockStateData;
|
||||||
use pocketmine\data\bedrock\block\BlockTypeNames;
|
|
||||||
use pocketmine\data\bedrock\item\BlockItemIdMap;
|
use pocketmine\data\bedrock\item\BlockItemIdMap;
|
||||||
use pocketmine\data\bedrock\item\ItemTypeDeserializeException;
|
use pocketmine\data\bedrock\item\ItemTypeDeserializeException;
|
||||||
use pocketmine\data\bedrock\item\ItemTypeNames;
|
|
||||||
use pocketmine\data\bedrock\item\SavedItemData;
|
use pocketmine\data\bedrock\item\SavedItemData;
|
||||||
use pocketmine\data\bedrock\item\SavedItemStackData;
|
use pocketmine\data\bedrock\item\SavedItemStackData;
|
||||||
use pocketmine\data\SavedDataLoadingException;
|
use pocketmine\data\SavedDataLoadingException;
|
||||||
use pocketmine\errorhandler\ErrorToExceptionHandler;
|
use pocketmine\errorhandler\ErrorToExceptionHandler;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\VanillaItems;
|
|
||||||
use pocketmine\nbt\LittleEndianNbtSerializer;
|
use pocketmine\nbt\LittleEndianNbtSerializer;
|
||||||
use pocketmine\utils\Filesystem;
|
use pocketmine\utils\Filesystem;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
@ -188,6 +185,7 @@ final class CraftingManagerFromDataHelper{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $data
|
* @param mixed[] $data
|
||||||
|
*
|
||||||
* @return object[]
|
* @return object[]
|
||||||
*
|
*
|
||||||
* @phpstan-template TRecipeData of object
|
* @phpstan-template TRecipeData of object
|
||||||
@ -213,7 +211,7 @@ final class CraftingManagerFromDataHelper{
|
|||||||
$result = new CraftingManager();
|
$result = new CraftingManager();
|
||||||
|
|
||||||
foreach(self::loadJsonArrayOfObjectsFile(Path::join($directoryPath, 'shapeless_crafting.json'), ShapelessRecipeData::class) as $recipe){
|
foreach(self::loadJsonArrayOfObjectsFile(Path::join($directoryPath, 'shapeless_crafting.json'), ShapelessRecipeData::class) as $recipe){
|
||||||
$recipeType = match($recipe->block){
|
$recipeType = match ($recipe->block) {
|
||||||
"crafting_table" => ShapelessRecipeType::CRAFTING,
|
"crafting_table" => ShapelessRecipeType::CRAFTING,
|
||||||
"stonecutter" => ShapelessRecipeType::STONECUTTER,
|
"stonecutter" => ShapelessRecipeType::STONECUTTER,
|
||||||
"smithing_table" => ShapelessRecipeType::SMITHING,
|
"smithing_table" => ShapelessRecipeType::SMITHING,
|
||||||
@ -274,7 +272,7 @@ final class CraftingManagerFromDataHelper{
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
foreach(self::loadJsonArrayOfObjectsFile(Path::join($directoryPath, 'smelting.json'), FurnaceRecipeData::class) as $recipe){
|
foreach(self::loadJsonArrayOfObjectsFile(Path::join($directoryPath, 'smelting.json'), FurnaceRecipeData::class) as $recipe){
|
||||||
$furnaceType = match ($recipe->block){
|
$furnaceType = match ($recipe->block) {
|
||||||
"furnace" => FurnaceType::FURNACE,
|
"furnace" => FurnaceType::FURNACE,
|
||||||
"blast_furnace" => FurnaceType::BLAST_FURNACE,
|
"blast_furnace" => FurnaceType::BLAST_FURNACE,
|
||||||
"smoker" => FurnaceType::SMOKER,
|
"smoker" => FurnaceType::SMOKER,
|
||||||
@ -336,15 +334,7 @@ final class CraftingManagerFromDataHelper{
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result->registerAnvilRecipe(new MaterialRepairRecipe(
|
$result = AnvilCraftingManagerDataFiller::fillData($result);
|
||||||
new MetaWildcardRecipeIngredient(ItemTypeNames::DIAMOND_PICKAXE),
|
|
||||||
new ExactRecipeIngredient(VanillaItems::DIAMOND())
|
|
||||||
));
|
|
||||||
|
|
||||||
$result->registerAnvilRecipe(new ItemCombineRecipe(
|
|
||||||
new MetaWildcardRecipeIngredient(ItemTypeNames::DIAMOND_PICKAXE),
|
|
||||||
new MetaWildcardRecipeIngredient(ItemTypeNames::DIAMOND_PICKAXE)
|
|
||||||
));
|
|
||||||
|
|
||||||
//TODO: smithing
|
//TODO: smithing
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class MaterialRepairRecipe implements AnvilRecipe{
|
|||||||
return new AnvilCraftResult(
|
return new AnvilCraftResult(
|
||||||
$numberRepair,
|
$numberRepair,
|
||||||
(clone $input)->setDamage(max(0, $damage)),
|
(clone $input)->setDamage(max(0, $damage)),
|
||||||
$material->pop($numberRepair)
|
(clone $material)->pop($numberRepair)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
src/crafting/TieredToolRecipeIngredient.php
Normal file
49
src/crafting/TieredToolRecipeIngredient.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?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;
|
||||||
|
use pocketmine\item\TieredTool;
|
||||||
|
use pocketmine\item\ToolTier;
|
||||||
|
|
||||||
|
class TieredToolRecipeIngredient implements RecipeIngredient{
|
||||||
|
public function __construct(
|
||||||
|
private ToolTier $tier
|
||||||
|
){
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTier() : ToolTier{ return $this->tier; }
|
||||||
|
|
||||||
|
public function accepts(Item $item) : bool{
|
||||||
|
if($item->getCount() < 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item instanceof TieredTool && $item->getTier() === $this->tier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString() : string{
|
||||||
|
return "TieredToolRecipeIngredient(" . $this->tier->name . ")";
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user