mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Fill null UUIDs in CraftingDataPacket, remove all UUID things from CraftingRecipe
This allows deleting lots of code, and additionally provides a huge reduction in the compressed size of CraftingDataPacket. Since we don't care about these UUIDs (they are only used in CraftingEventPacket, which is broken and unused in PM) we fill them with zeros instead.
This commit is contained in:
parent
a1090623a2
commit
ec332e3e60
@ -30,13 +30,8 @@ use pocketmine\network\mcpe\protocol\CraftingDataPacket;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\timings\Timings;
|
||||
use pocketmine\utils\Config;
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
class CraftingManager{
|
||||
|
||||
/** @var CraftingRecipe[] */
|
||||
protected $recipes = [];
|
||||
|
||||
/** @var ShapedRecipe[][] */
|
||||
protected $shapedRecipes = [];
|
||||
/** @var ShapelessRecipe[][] */
|
||||
@ -44,8 +39,6 @@ class CraftingManager{
|
||||
/** @var FurnaceRecipe[] */
|
||||
protected $furnaceRecipes = [];
|
||||
|
||||
private static $RECIPE_COUNT = 0;
|
||||
|
||||
/** @var BatchPacket */
|
||||
private $craftingDataCache;
|
||||
|
||||
@ -93,13 +86,16 @@ class CraftingManager{
|
||||
$pk = new CraftingDataPacket();
|
||||
$pk->cleanRecipes = true;
|
||||
|
||||
foreach($this->recipes as $recipe){
|
||||
if($recipe instanceof ShapedRecipe){
|
||||
$pk->addShapedRecipe($recipe);
|
||||
}elseif($recipe instanceof ShapelessRecipe){
|
||||
foreach($this->shapelessRecipes as $list){
|
||||
foreach($list as $recipe){
|
||||
$pk->addShapelessRecipe($recipe);
|
||||
}
|
||||
}
|
||||
foreach($this->shapedRecipes as $list){
|
||||
foreach($list as $recipe){
|
||||
$pk->addShapedRecipe($recipe);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->furnaceRecipes as $recipe){
|
||||
$pk->addFurnaceRecipe($recipe);
|
||||
@ -179,22 +175,6 @@ class CraftingManager{
|
||||
return json_encode($outputs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
* @return CraftingRecipe|null
|
||||
*/
|
||||
public function getRecipe(UUID $id) : ?CraftingRecipe{
|
||||
$index = $id->toBinary();
|
||||
return $this->recipes[$index] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Recipe[]
|
||||
*/
|
||||
public function getRecipes() : array{
|
||||
return $this->recipes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ShapelessRecipe[][]
|
||||
*/
|
||||
@ -220,8 +200,6 @@ class CraftingManager{
|
||||
* @param ShapedRecipe $recipe
|
||||
*/
|
||||
public function registerShapedRecipe(ShapedRecipe $recipe) : void{
|
||||
$recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, json_encode(self::pack($recipe->getResults()))));
|
||||
$this->recipes[$uuid->toBinary()] = $recipe;
|
||||
$this->shapedRecipes[self::hashOutputs($recipe->getResults())][] = $recipe;
|
||||
|
||||
$this->craftingDataCache = null;
|
||||
@ -231,8 +209,6 @@ class CraftingManager{
|
||||
* @param ShapelessRecipe $recipe
|
||||
*/
|
||||
public function registerShapelessRecipe(ShapelessRecipe $recipe) : void{
|
||||
$recipe->setId($uuid = UUID::fromData((string) ++self::$RECIPE_COUNT, json_encode(self::pack($recipe->getResults()))));
|
||||
$this->recipes[$uuid->toBinary()] = $recipe;
|
||||
$this->shapelessRecipes[self::hashOutputs($recipe->getResults())][] = $recipe;
|
||||
|
||||
$this->craftingDataCache = null;
|
||||
|
@ -24,20 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
interface CraftingRecipe extends Recipe{
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId() : ?UUID;
|
||||
|
||||
/**
|
||||
* @param UUID $id
|
||||
*/
|
||||
public function setId(UUID $id);
|
||||
|
||||
/**
|
||||
* Returns a list of items needed to craft this recipe. This MUST NOT include Air items or items with a zero count.
|
||||
*
|
||||
|
@ -25,12 +25,8 @@ namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
class ShapedRecipe implements CraftingRecipe{
|
||||
/** @var UUID|null */
|
||||
private $id = null;
|
||||
|
||||
/** @var string[] */
|
||||
private $shape = [];
|
||||
/** @var Item[] char => Item map */
|
||||
@ -116,21 +112,6 @@ class ShapedRecipe implements CraftingRecipe{
|
||||
return $this->getResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId() : ?UUID{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(UUID $id){
|
||||
if($this->id !== null){
|
||||
throw new \InvalidStateException("Id is already set");
|
||||
}
|
||||
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param Item $item
|
||||
|
@ -24,12 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\utils\UUID;
|
||||
|
||||
class ShapelessRecipe implements CraftingRecipe{
|
||||
/** @var UUID|null */
|
||||
private $id = null;
|
||||
|
||||
/** @var Item[] */
|
||||
private $ingredients = [];
|
||||
/** @var Item[] */
|
||||
@ -48,24 +44,6 @@ class ShapelessRecipe implements CraftingRecipe{
|
||||
$this->results = array_map(function(Item $item) : Item{ return clone $item; }, $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UUID|null
|
||||
*/
|
||||
public function getId() : ?UUID{
|
||||
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;
|
||||
}
|
||||
|
||||
public function getResults() : array{
|
||||
return array_map(function(Item $item) : Item{ return clone $item; }, $this->results);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class CraftingDataPacket extends DataPacket{
|
||||
$stream->putSlot($item);
|
||||
}
|
||||
|
||||
$stream->putUUID($recipe->getId());
|
||||
$stream->put(str_repeat("\x00", 16)); //Null UUID
|
||||
|
||||
return CraftingDataPacket::ENTRY_SHAPELESS;
|
||||
}
|
||||
@ -160,7 +160,7 @@ class CraftingDataPacket extends DataPacket{
|
||||
$stream->putSlot($item);
|
||||
}
|
||||
|
||||
$stream->putUUID($recipe->getId());
|
||||
$stream->put(str_repeat("\x00", 16)); //Null UUID
|
||||
|
||||
return CraftingDataPacket::ENTRY_SHAPED;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user