remove position parameters from BlockFactory::get() and BlockFactory::fromFullBlock()

This commit is contained in:
Dylan K. Taylor 2019-08-24 17:19:27 +01:00
parent c9cd6ee038
commit 6a4ae4cb94
4 changed files with 19 additions and 27 deletions

View File

@ -51,7 +51,6 @@ use pocketmine\block\utils\TreeType;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemIds; use pocketmine\item\ItemIds;
use pocketmine\item\ToolTier; use pocketmine\item\ToolTier;
use pocketmine\world\Position;
use function array_fill; use function array_fill;
use function array_filter; use function array_filter;
use function get_class; use function get_class;
@ -832,11 +831,10 @@ class BlockFactory{
* *
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param Position $pos
* *
* @return Block * @return Block
*/ */
public static function get(int $id, int $meta = 0, ?Position $pos = null) : Block{ public static function get(int $id, int $meta = 0) : Block{
if($meta < 0 or $meta > 0xf){ if($meta < 0 or $meta > 0xf){
throw new \InvalidArgumentException("Block meta value $meta is out of bounds"); throw new \InvalidArgumentException("Block meta value $meta is out of bounds");
} }
@ -856,15 +854,11 @@ class BlockFactory{
$block = new UnknownBlock(new BID($id, $meta)); $block = new UnknownBlock(new BID($id, $meta));
} }
if($pos !== null){
$block->position($pos->getWorld(), $pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ());
}
return $block; return $block;
} }
public static function fromFullBlock(int $fullState, ?Position $pos = null) : Block{ public static function fromFullBlock(int $fullState) : Block{
return self::get($fullState >> 4, $fullState & 0xf, $pos); return self::get($fullState >> 4, $fullState & 0xf);
} }
/** /**

View File

@ -41,7 +41,6 @@ use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\IntTag;
use pocketmine\timings\Timings; use pocketmine\timings\Timings;
use pocketmine\world\Position;
use pocketmine\world\World; use pocketmine\world\World;
use function assert; use function assert;
use function atan2; use function atan2;
@ -84,7 +83,7 @@ abstract class Projectile extends Entity{
$blockData = null; $blockData = null;
if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){ if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){
$blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->getWorld()); $blockPos = new Vector3($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"));
}else{ }else{
break; break;
} }
@ -101,7 +100,8 @@ abstract class Projectile extends Entity{
break; break;
} }
$this->blockHit = BlockFactory::get($blockId, $blockData, $blockPos); $this->blockHit = BlockFactory::get($blockId, $blockData);
$this->blockHit->position($this->getWorld(), $blockPos->getFloorX(), $blockPos->getFloorY(), $blockPos->getFloorZ());
}while(false); }while(false);
} }

View File

@ -95,7 +95,6 @@ class Explosion{
} }
$vector = new Vector3(0, 0, 0); $vector = new Vector3(0, 0, 0);
$vBlock = new Position(0, 0, 0, $this->world);
$currentChunk = null; $currentChunk = null;
$currentSubChunk = null; $currentSubChunk = null;
@ -115,21 +114,23 @@ class Explosion{
$x = (int) $pointerX; $x = (int) $pointerX;
$y = (int) $pointerY; $y = (int) $pointerY;
$z = (int) $pointerZ; $z = (int) $pointerZ;
$vBlock->x = $pointerX >= $x ? $x : $x - 1; $vBlockX = $pointerX >= $x ? $x : $x - 1;
$vBlock->y = $pointerY >= $y ? $y : $y - 1; $vBlockY = $pointerY >= $y ? $y : $y - 1;
$vBlock->z = $pointerZ >= $z ? $z : $z - 1; $vBlockZ = $pointerZ >= $z ? $z : $z - 1;
if(!$this->subChunkHandler->moveTo($vBlock->x, $vBlock->y, $vBlock->z, false)){ if(!$this->subChunkHandler->moveTo($vBlockX, $vBlockY, $vBlockZ, false)){
continue; continue;
} }
$state = $this->subChunkHandler->currentSubChunk->getFullBlock($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f); $state = $this->subChunkHandler->currentSubChunk->getFullBlock($vBlockX & 0x0f, $vBlockY & 0x0f, $vBlockZ & 0x0f);
if($state !== 0){ if($state !== 0){
$blastForce -= (BlockFactory::$blastResistance[$state] / 5 + 0.3) * $this->stepLen; $blastForce -= (BlockFactory::$blastResistance[$state] / 5 + 0.3) * $this->stepLen;
if($blastForce > 0){ if($blastForce > 0){
if(!isset($this->affectedBlocks[$index = World::blockHash($vBlock->x, $vBlock->y, $vBlock->z)])){ if(!isset($this->affectedBlocks[$index = World::blockHash($vBlockX, $vBlockY, $vBlockZ)])){
$this->affectedBlocks[$index] = BlockFactory::fromFullBlock($state, $vBlock); $_block = BlockFactory::fromFullBlock($state);
$_block->position($this->world, $vBlockX, $vBlockY, $vBlockZ);
$this->affectedBlocks[$index] = $_block;
} }
} }
} }

View File

@ -996,11 +996,8 @@ class World implements ChunkManager{
if(isset($this->randomTickBlocks[$state])){ if(isset($this->randomTickBlocks[$state])){
/** @var Block $block */ /** @var Block $block */
$block = BlockFactory::fromFullBlock($state, $this->temporalPosition->setComponents( $block = BlockFactory::fromFullBlock($state);
$chunkX * 16 + $x, $block->position($this, $chunkX * 16 + $x, ($Y << 4) + $y, $chunkZ * 16 + $z);
($Y << 4) + $y,
$chunkZ * 16 + $z
));
$block->onRandomTick(); $block->onRandomTick();
} }
} }