mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
CraftingManager: Reduce footprint of recipe keys
this was using json before, which is horribly inefficient. This saved about 200 KB of memory on initial startup (which isn't much, but for more complex recipes, it might have been significantly worse.
This commit is contained in:
parent
c2558573e2
commit
dee2062b1b
@ -24,9 +24,11 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\crafting;
|
namespace pocketmine\crafting;
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\nbt\LittleEndianNbtSerializer;
|
||||||
|
use pocketmine\nbt\TreeRoot;
|
||||||
|
use pocketmine\utils\BinaryStream;
|
||||||
use pocketmine\utils\DestructorCallbackTrait;
|
use pocketmine\utils\DestructorCallbackTrait;
|
||||||
use pocketmine\utils\ObjectSet;
|
use pocketmine\utils\ObjectSet;
|
||||||
use function json_encode;
|
|
||||||
use function usort;
|
use function usort;
|
||||||
|
|
||||||
class CraftingManager{
|
class CraftingManager{
|
||||||
@ -108,12 +110,16 @@ class CraftingManager{
|
|||||||
private static function hashOutputs(array $outputs) : string{
|
private static function hashOutputs(array $outputs) : string{
|
||||||
$outputs = self::pack($outputs);
|
$outputs = self::pack($outputs);
|
||||||
usort($outputs, [self::class, "sort"]);
|
usort($outputs, [self::class, "sort"]);
|
||||||
|
$result = new BinaryStream();
|
||||||
foreach($outputs as $o){
|
foreach($outputs as $o){
|
||||||
//this reduces accuracy of hash, but it's necessary to deal with recipe book shift-clicking stupidity
|
//count is not written because the outputs might be from multiple repetitions of a single recipe
|
||||||
$o->setCount(1);
|
//this reduces the accuracy of the hash, but it won't matter in most cases.
|
||||||
|
$result->putVarInt($o->getId());
|
||||||
|
$result->putVarInt($o->getMeta());
|
||||||
|
$result->put((new LittleEndianNbtSerializer())->write(new TreeRoot($o->getNamedTag())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return json_encode($outputs);
|
return $result->getBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user