Made block and item factory lists private to stop people doing stupid things with them

This commit is contained in:
Dylan K. Taylor
2017-08-29 10:52:50 +01:00
parent 9902d29734
commit 6abef6b22d
4 changed files with 20 additions and 17 deletions

View File

@ -272,7 +272,7 @@ class Level implements ChunkManager, Metadatable{
* @throws \Exception
*/
public function __construct(Server $server, string $name, string $path, string $provider){
$this->blockStates = BlockFactory::$fullList;
$this->blockStates = BlockFactory::getBlockStatesArray();
$this->levelId = static::$levelIdCounter++;
$this->blockMetadata = new BlockMetadataStore($this);
$this->server = $server;
@ -304,19 +304,12 @@ class Level implements ChunkManager, Metadatable{
$this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", true);
$this->cacheChunks = (bool) $this->server->getProperty("chunk-sending.cache-chunks", false);
$this->randomTickBlocks = \SplFixedArray::fromArray(array_filter(BlockFactory::$list->toArray(), function(Block $block = null){
return $block !== null and $block->ticksRandomly();
}));
$this->randomTickBlocks->setSize(256);
$dontTickBlocks = $this->server->getProperty("chunk-ticking.disable-block-ticking", []);
foreach($dontTickBlocks as $id){
try{
if(isset($this->randomTickBlocks[$id])){
$this->randomTickBlocks[$id] = null;
}
}catch(\RuntimeException $e){
//index out of bounds
$this->randomTickBlocks = new \SplFixedArray(256);
foreach($this->randomTickBlocks as $id => $null){
$block = BlockFactory::get($id); //Make sure it's a copy
if(!isset($dontTickBlocks[$id]) and $block->ticksRandomly()){
$this->randomTickBlocks[$id] = $block;
}
}