Restrict item meta values to max signed short value, closes #1101

This commit is contained in:
Dylan K. Taylor 2017-10-03 12:35:08 +01:00
parent f7ee78233b
commit 7dc5dc3a9f

View File

@ -200,7 +200,7 @@ class Item implements ItemIds, \JsonSerializable{
*/
public function __construct(int $id, int $meta = 0, string $name = "Unknown"){
$this->id = $id & 0xffff;
$this->meta = $meta !== -1 ? $meta & 0xffff : -1;
$this->setDamage($meta);
$this->name = $name;
if(!isset($this->block) and $this->id <= 0xff){
$this->block = BlockFactory::get($this->id, $this->meta);
@ -738,7 +738,7 @@ class Item implements ItemIds, \JsonSerializable{
* @return $this
*/
public function setDamage(int $meta){
$this->meta = $meta !== -1 ? $meta & 0xFFFF : -1;
$this->meta = $meta !== -1 ? $meta & 0x7FFF : -1;
return $this;
}