mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-29 14:15:47 +00:00
Small cleanup of recipe UUID handling (furnace recipes don't need UUIDs)
This commit is contained in:
parent
ca23864e4c
commit
fd33a65e3b
@ -34,10 +34,10 @@ use pocketmine\utils\UUID;
|
||||
|
||||
class CraftingManager{
|
||||
|
||||
/** @var Recipe[] */
|
||||
/** @var CraftingRecipe[] */
|
||||
public $recipes = [];
|
||||
|
||||
/** @var Recipe[][] */
|
||||
/** @var CraftingRecipe[][] */
|
||||
protected $recipeLookup = [];
|
||||
|
||||
/** @var FurnaceRecipe[] */
|
||||
@ -148,7 +148,7 @@ class CraftingManager{
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
* @return Recipe|null
|
||||
* @return CraftingRecipe|null
|
||||
*/
|
||||
public function getRecipe(UUID $id){
|
||||
$index = $id->toBinary();
|
||||
@ -183,7 +183,8 @@ class CraftingManager{
|
||||
*/
|
||||
public function registerShapedRecipe(ShapedRecipe $recipe){
|
||||
$result = $recipe->getResult();
|
||||
$this->recipes[$recipe->getId()->toBinary()] = $recipe;
|
||||
|
||||
/** @var Item[][] $ingredients */
|
||||
$ingredients = $recipe->getIngredientMap();
|
||||
$hash = "";
|
||||
foreach($ingredients as $v){
|
||||
@ -206,7 +207,6 @@ class CraftingManager{
|
||||
*/
|
||||
public function registerShapelessRecipe(ShapelessRecipe $recipe){
|
||||
$result = $recipe->getResult();
|
||||
$this->recipes[$recipe->getId()->toBinary()] = $recipe;
|
||||
$hash = "";
|
||||
$ingredients = $recipe->getIngredientList();
|
||||
usort($ingredients, [$this, "sort"]);
|
||||
@ -288,15 +288,13 @@ class CraftingManager{
|
||||
* @param Recipe $recipe
|
||||
*/
|
||||
public function registerRecipe(Recipe $recipe){
|
||||
$recipe->setId(UUID::fromData((string) ++self::$RECIPE_COUNT, (string) $recipe->getResult()->getId(), (string) $recipe->getResult()->getDamage(), (string) $recipe->getResult()->getCount(), $recipe->getResult()->getCompoundTag()));
|
||||
|
||||
if($recipe instanceof ShapedRecipe){
|
||||
$this->registerShapedRecipe($recipe);
|
||||
}elseif($recipe instanceof ShapelessRecipe){
|
||||
$this->registerShapelessRecipe($recipe);
|
||||
}elseif($recipe instanceof FurnaceRecipe){
|
||||
$this->registerFurnaceRecipe($recipe);
|
||||
if($recipe instanceof CraftingRecipe){
|
||||
$result = $recipe->getResult();
|
||||
$recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, (string) $result->getId(), (string) $result->getDamage(), (string) $result->getCount(), $result->getCompoundTag()));
|
||||
$this->recipes[$uuid->toBinary()] = $recipe;
|
||||
}
|
||||
|
||||
$recipe->registerToCraftingManager($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
39
src/pocketmine/inventory/CraftingRecipe.php
Normal file
39
src/pocketmine/inventory/CraftingRecipe.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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;
|
||||
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
interface CraftingRecipe extends Recipe{
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
*/
|
||||
public function setId(UUID $id);
|
||||
}
|
@ -29,9 +29,6 @@ use pocketmine\utils\UUID;
|
||||
|
||||
class FurnaceRecipe implements Recipe{
|
||||
|
||||
/** @var UUID|null */
|
||||
private $id = null;
|
||||
|
||||
/** @var Item */
|
||||
private $output;
|
||||
|
||||
@ -47,24 +44,6 @@ class FurnaceRecipe implements Recipe{
|
||||
$this->ingredient = clone $ingredient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
*/
|
||||
public function setId(UUID $id){
|
||||
if($this->id !== null){
|
||||
throw new \InvalidStateException("Id is already set");
|
||||
}
|
||||
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
*/
|
||||
@ -86,7 +65,7 @@ class FurnaceRecipe implements Recipe{
|
||||
return clone $this->output;
|
||||
}
|
||||
|
||||
public function registerToCraftingManager(){
|
||||
Server::getInstance()->getCraftingManager()->registerFurnaceRecipe($this);
|
||||
public function registerToCraftingManager(CraftingManager $manager){
|
||||
$manager->registerFurnaceRecipe($this);
|
||||
}
|
||||
}
|
@ -33,15 +33,5 @@ interface Recipe{
|
||||
*/
|
||||
public function getResult() : Item;
|
||||
|
||||
public function registerToCraftingManager();
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
*/
|
||||
public function setId(UUID $id);
|
||||
public function registerToCraftingManager(CraftingManager $manager);
|
||||
}
|
@ -28,7 +28,7 @@ use pocketmine\item\ItemFactory;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
class ShapedRecipe implements Recipe{
|
||||
class ShapedRecipe implements CraftingRecipe{
|
||||
/** @var Item */
|
||||
private $output;
|
||||
|
||||
@ -168,7 +168,7 @@ class ShapedRecipe implements Recipe{
|
||||
return $this->shape;
|
||||
}
|
||||
|
||||
public function registerToCraftingManager(){
|
||||
Server::getInstance()->getCraftingManager()->registerShapedRecipe($this);
|
||||
public function registerToCraftingManager(CraftingManager $manager){
|
||||
$manager->registerShapedRecipe($this);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use pocketmine\item\Item;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
class ShapelessRecipe implements Recipe{
|
||||
class ShapelessRecipe implements CraftingRecipe{
|
||||
/** @var Item */
|
||||
private $output;
|
||||
|
||||
@ -129,7 +129,7 @@ class ShapelessRecipe implements Recipe{
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function registerToCraftingManager(){
|
||||
Server::getInstance()->getCraftingManager()->registerShapelessRecipe($this);
|
||||
public function registerToCraftingManager(CraftingManager $manager){
|
||||
$manager->registerShapelessRecipe($this);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user