Fixed item stack count and effect amplifier overflows, close #1072

This commit is contained in:
Dylan K. Taylor
2017-06-17 12:22:38 +01:00
parent 1bae973502
commit e3b3f60c66
3 changed files with 40 additions and 11 deletions

View File

@ -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");
}