Merge branch 'release/3.1'

This commit is contained in:
Dylan K. Taylor 2018-07-17 10:13:00 +01:00
commit 1f023bdcef
4 changed files with 33 additions and 28 deletions

View File

@ -2537,13 +2537,9 @@ class Server{
} }
if(($this->tickCounter & 0b111111111) === 0){ if(($this->tickCounter & 0b111111111) === 0){
try{ $this->getPluginManager()->callEvent($this->queryRegenerateTask = new QueryRegenerateEvent($this, 5));
$this->getPluginManager()->callEvent($this->queryRegenerateTask = new QueryRegenerateEvent($this, 5)); if($this->queryHandler !== null){
if($this->queryHandler !== null){ $this->queryHandler->regenerateInfo();
$this->queryHandler->regenerateInfo();
}
}catch(\Throwable $e){
$this->logger->logException($e);
} }
} }

View File

@ -196,7 +196,10 @@ class Item implements ItemIds, \JsonSerializable{
* @param string $name * @param string $name
*/ */
public function __construct(int $id, int $meta = 0, string $name = "Unknown"){ public function __construct(int $id, int $meta = 0, string $name = "Unknown"){
$this->id = $id & 0xffff; if($id < -0x8000 or $id > 0x7fff){ //signed short range
throw new \InvalidArgumentException("ID must be in range " . -0x8000 . " - " . 0x7fff);
}
$this->id = $id;
$this->setDamage($meta); $this->setDamage($meta);
$this->name = $name; $this->name = $name;
} }
@ -916,7 +919,7 @@ class Item implements ItemIds, \JsonSerializable{
*/ */
public function nbtSerialize(int $slot = -1, string $tagName = "") : CompoundTag{ public function nbtSerialize(int $slot = -1, string $tagName = "") : CompoundTag{
$result = new CompoundTag($tagName, [ $result = new CompoundTag($tagName, [
new ShortTag("id", Binary::signShort($this->id)), new ShortTag("id", $this->id),
new ByteTag("Count", Binary::signByte($this->count)), new ByteTag("Count", Binary::signByte($this->count)),
new ShortTag("Damage", $this->meta) new ShortTag("Damage", $this->meta)
]); ]);
@ -951,7 +954,7 @@ class Item implements ItemIds, \JsonSerializable{
$idTag = $tag->getTag("id"); $idTag = $tag->getTag("id");
if($idTag instanceof ShortTag){ if($idTag instanceof ShortTag){
$item = ItemFactory::get(Binary::unsignShort($idTag->getValue()), $meta, $count); $item = ItemFactory::get($idTag->getValue(), $meta, $count);
}elseif($idTag instanceof StringTag){ //PC item save format }elseif($idTag instanceof StringTag){ //PC item save format
$item = ItemFactory::fromString($idTag->getValue()); $item = ItemFactory::fromString($idTag->getValue());
$item->setDamage($meta); $item->setDamage($meta);

View File

@ -281,7 +281,7 @@ class ItemFactory{
throw new \RuntimeException("Trying to overwrite an already registered item"); throw new \RuntimeException("Trying to overwrite an already registered item");
} }
self::$list[$id] = clone $item; self::$list[self::getListOffset($id)] = clone $item;
} }
/** /**
@ -302,10 +302,10 @@ class ItemFactory{
try{ try{
/** @var Item|null $listed */ /** @var Item|null $listed */
$listed = self::$list[$id]; $listed = self::$list[self::getListOffset($id)];
if($listed !== null){ if($listed !== null){
$item = clone $listed; $item = clone $listed;
}elseif($id < 256){ }elseif($id < 256){ //intentionally includes negatives, for extended block IDs
/* Blocks must have a damage value 0-15, but items can have damage value -1 to indicate that they are /* Blocks must have a damage value 0-15, but items can have damage value -1 to indicate that they are
* crafting ingredients with any-damage. */ * crafting ingredients with any-damage. */
$item = new ItemBlock($id, $meta); $item = new ItemBlock($id, $meta);
@ -353,13 +353,13 @@ class ItemFactory{
if(!isset($b[1])){ if(!isset($b[1])){
$meta = 0; $meta = 0;
}elseif(is_numeric($b[1])){ }elseif(is_numeric($b[1])){
$meta = $b[1] & 0xFFFF; $meta = $b[1];
}else{ }else{
throw new \InvalidArgumentException("Unable to parse \"" . $b[1] . "\" from \"" . $str . "\" as a valid meta value"); throw new \InvalidArgumentException("Unable to parse \"" . $b[1] . "\" from \"" . $str . "\" as a valid meta value");
} }
if(is_numeric($b[0])){ if(is_numeric($b[0])){
$item = self::get(((int) $b[0]) & 0xFFFF, $meta); $item = self::get((int) $b[0], $meta);
}elseif(defined(ItemIds::class . "::" . strtoupper($b[0]))){ }elseif(defined(ItemIds::class . "::" . strtoupper($b[0]))){
$item = self::get(constant(ItemIds::class . "::" . strtoupper($b[0])), $meta); $item = self::get(constant(ItemIds::class . "::" . strtoupper($b[0])), $meta);
}else{ }else{
@ -380,6 +380,13 @@ class ItemFactory{
if($id < 256){ if($id < 256){
return BlockFactory::isRegistered($id); return BlockFactory::isRegistered($id);
} }
return self::$list[$id] !== null; return self::$list[self::getListOffset($id)] !== null;
}
private static function getListOffset(int $id) : int{
if($id < -0x8000 or $id > 0x7fff){
throw new \InvalidArgumentException("ID must be in range " . -0x8000 . " - " . 0x7fff);
}
return $id & 0xffff;
} }
} }

View File

@ -2943,20 +2943,19 @@ class Level implements ChunkManager, Metadatable{
} }
if($populate){ if($populate){
if(!isset($this->chunkPopulationQueue[$index])){ $this->chunkPopulationQueue[$index] = true;
$this->chunkPopulationQueue[$index] = true; for($xx = -1; $xx <= 1; ++$xx){
for($xx = -1; $xx <= 1; ++$xx){ for($zz = -1; $zz <= 1; ++$zz){
for($zz = -1; $zz <= 1; ++$zz){ $this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)] = true;
$this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)] = true;
}
} }
$task = new PopulationTask($this, $chunk);
$workerId = $this->server->getAsyncPool()->selectWorker();
if(!isset($this->generatorRegisteredWorkers[$workerId])){
$this->registerGeneratorToWorker($workerId);
}
$this->server->getAsyncPool()->submitTaskToWorker($task, $workerId);
} }
$task = new PopulationTask($this, $chunk);
$workerId = $this->server->getAsyncPool()->selectWorker();
if(!isset($this->generatorRegisteredWorkers[$workerId])){
$this->registerGeneratorToWorker($workerId);
}
$this->server->getAsyncPool()->submitTaskToWorker($task, $workerId);
} }
Timings::$populationTimer->stopTiming(); Timings::$populationTimer->stopTiming();