/** * @return bool */ public function explodeA() { if ($this->size < 0.1) { return false; } $vector = new Vector3(0, 0, 0); $vBlock = new Vector3(0, 0, 0); $mRays = intval($this->rays - 1); for ($i = 0; $i < $this->rays; ++$i) { for ($j = 0; $j < $this->rays; ++$j) { for ($k = 0; $k < $this->rays; ++$k) { if ($i === 0 or $i === $mRays or $j === 0 or $j === $mRays or $k === 0 or $k === $mRays) { $vector->setComponents($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); $vector->setComponents($vector->x / ($len = $vector->length()) * $this->stepLen, $vector->y / $len * $this->stepLen, $vector->z / $len * $this->stepLen); $pointerX = $this->source->x; $pointerY = $this->source->y; $pointerZ = $this->source->z; for ($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75) { $x = (int) $pointerX; $y = (int) $pointerY; $z = (int) $pointerZ; $vBlock->x = $pointerX >= $x ? $x : $x - 1; $vBlock->y = $pointerY >= $y ? $y : $y - 1; $vBlock->z = $pointerZ >= $z ? $z : $z - 1; if ($vBlock->y < 0 or $vBlock->y > 127) { break; } $block = $this->level->getBlock($vBlock); if ($block->getId() !== 0) { $blastForce -= ($block->getResistance() / 5 + 0.3) * $this->stepLen; if ($blastForce > 0) { if (!isset($this->affectedBlocks[$index = Level::blockHash($block->x, $block->y, $block->z)])) { $this->affectedBlocks[$index] = $block; } } } $pointerX += $vector->x; $pointerY += $vector->y; $pointerZ += $vector->z; } } } } } return true; }
private function getOptimalFlowDirections() { if ($this->temporalVector === null) { $this->temporalVector = new Vector3(0, 0, 0); } for ($j = 0; $j < 4; ++$j) { $this->flowCost[$j] = 1000; $x = $this->x; $y = $this->y; $z = $this->z; if ($j === 0) { --$x; } elseif ($j === 1) { ++$x; } elseif ($j === 2) { --$z; } elseif ($j === 3) { ++$z; } $block = $this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $z)); if (!$block->canBeFlowedInto() and !$block instanceof Liquid) { continue; } elseif ($block instanceof Liquid and $block->getDamage() === 0) { continue; } elseif ($this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y - 1, $z))->canBeFlowedInto()) { $this->flowCost[$j] = 0; } else { $this->flowCost[$j] = $this->calculateFlowCost($block, 1, $j); } } $minCost = $this->flowCost[0]; for ($i = 1; $i < 4; ++$i) { if ($this->flowCost[$i] < $minCost) { $minCost = $this->flowCost[$i]; } } for ($i = 0; $i < 4; ++$i) { $this->isOptimalFlowDirection[$i] = $this->flowCost[$i] === $minCost; } return $this->isOptimalFlowDirection; }
/** * @param Entity $entity * @param AxisAlignedBB $bb * @param boolean $entities * * @return AxisAlignedBB[] */ public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb, $entities = true) { $minX = Math::floorFloat($bb->minX); $minY = Math::floorFloat($bb->minY); $minZ = Math::floorFloat($bb->minZ); $maxX = Math::ceilFloat($bb->maxX); $maxY = Math::ceilFloat($bb->maxY); $maxZ = Math::ceilFloat($bb->maxZ); $collides = []; for ($z = $minZ; $z <= $maxZ; ++$z) { for ($x = $minX; $x <= $maxX; ++$x) { for ($y = $minY; $y <= $maxY; ++$y) { $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z)); if (!$block->canPassThrough() and $block->collidesWithBB($bb)) { $collides[] = $block->getBoundingBox(); } } } } if ($entities) { foreach ($this->getCollidingEntities($bb->grow(0.25, 0.25, 0.25), $entity) as $ent) { $collides[] = clone $ent->boundingBox; } } return $collides; }
/** * @param Vector3|Position|Location $pos * @param float $yaw * @param float $pitch * * @return bool */ public function teleport(Vector3 $pos, $yaw = null, $pitch = null) { if ($pos instanceof Location) { $yaw = $yaw === null ? $pos->yaw : $yaw; $pitch = $pitch === null ? $pos->pitch : $pitch; } $from = Position::fromObject($this, $this->level); $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level); $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to)); if ($ev->isCancelled()) { return false; } $this->ySize = 0; $pos = $ev->getTo(); $this->setMotion($this->temporalVector->setComponents(0, 0, 0)); if ($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch) !== false) { $this->resetFallDistance(); $this->onGround = true; $this->lastX = $this->x; $this->lastY = $this->y; $this->lastZ = $this->z; $this->lastYaw = $this->yaw; $this->lastPitch = $this->pitch; $this->updateMovement(); return true; } return false; }