mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
Fixed item stack count and effect amplifier overflows, close #1072
This commit is contained in:
@ -40,6 +40,7 @@ use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\nbt\tag\Tag;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\Config;
|
||||
|
||||
class Item implements ItemIds, \JsonSerializable{
|
||||
@ -1009,7 +1010,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
public function nbtSerialize(int $slot = -1, string $tagName = "") : CompoundTag{
|
||||
$tag = new CompoundTag($tagName, [
|
||||
"id" => new ShortTag("id", $this->id),
|
||||
"Count" => new ByteTag("Count", $this->count),
|
||||
"Count" => new ByteTag("Count", Binary::signByte($this->count)),
|
||||
"Damage" => new ShortTag("Damage", $this->meta),
|
||||
]);
|
||||
|
||||
@ -1037,12 +1038,15 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
return Item::get(0);
|
||||
}
|
||||
|
||||
$count = Binary::unsignByte($tag->Count->getValue());
|
||||
$meta = isset($tag->Damage) ? $tag->Damage->getValue() : 0;
|
||||
|
||||
if($tag->id instanceof ShortTag){
|
||||
$item = Item::get($tag->id->getValue(), !isset($tag->Damage) ? 0 : $tag->Damage->getValue(), $tag->Count->getValue());
|
||||
$item = Item::get($tag->id->getValue(), $meta, $count);
|
||||
}elseif($tag->id instanceof StringTag){ //PC item save format
|
||||
$item = Item::fromString($tag->id->getValue());
|
||||
$item->setDamage(!isset($tag->Damage) ? 0 : $tag->Damage->getValue());
|
||||
$item->setCount($tag->Count->getValue());
|
||||
$item->setDamage($meta);
|
||||
$item->setCount($count);
|
||||
}else{
|
||||
throw new \InvalidArgumentException("Item CompoundTag ID must be an instance of StringTag or ShortTag, " . get_class($tag->id) . " given");
|
||||
}
|
||||
|
Reference in New Issue
Block a user