作者:ken7773
项目:PocketMine-0.13.
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;
}
作者:yungtechboy
项目:Genisy
/**
* @param Level $level
* @param Vector3 $v3
* @param bool $hate
* @param bool $reason
* @return bool|float|string
* 判断某坐标是否可以行走
* 并给出原因
*/
public function ifjump(Level $level, Vector3 $v3, $hate = false, $reason = false)
{
//boybook Y轴算法核心函数
$x = floor($v3->getX());
$y = floor($v3->getY());
$z = floor($v3->getZ());
//echo ($y." ");
if ($this->whatBlock($level, new Vector3($x, $y, $z)) == "air") {
//echo "前方空气 ";
if ($this->whatBlock($level, new Vector3($x, $y - 1, $z)) == "block" or new Vector3($x, $y - 1, $z) == "climb") {
//方块
//echo "考虑向前 ";
if ($this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "block" or $this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "half" or $this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "high") {
//上方一格被堵住了
//echo "上方卡住 \n";
if ($reason) {
return 'up!';
}
return false;
//上方卡住
} else {
//echo "GO向前走 \n";
if ($reason) {
return 'GO';
}
return $y;
//向前走
}
} elseif ($this->whatBlock($level, new Vector3($x, $y - 1, $z)) == "half") {
//半砖
//echo "下到半砖 \n";
if ($reason) {
return 'half';
}
return $y - 0.5;
//向下跳0.5格
} elseif ($this->whatBlock($level, new Vector3($x, $y - 1, $z)) == "lava") {
//岩浆
//echo "前方岩浆 \n";
if ($reason) {
return 'lava';
}
return false;
//前方岩浆
} elseif ($this->whatBlock($level, new Vector3($x, $y - 1, $z)) == "air") {
//空气
//echo "考虑向下跳 ";
if ($this->whatBlock($level, new Vector3($x, $y - 2, $z)) == "block") {
//echo "GO向下跳 \n";
if ($reason) {
return 'down';
}
return $y - 1;
//向下跳
} else {
//前方悬崖
//echo "前方悬崖 \n";
if ($reason) {
return 'fall';
}
/* if ($hate === false) {
return false;
}
else {
return $y-1; //向下跳
}*/
}
}
} elseif ($this->whatBlock($level, new Vector3($x, $y, $z)) == "half") {
//半砖
//echo "前方半砖 \n";
if ($this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "block" or $this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "half" or $this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "high") {
//上方一格被堵住了
//return false; //上方卡住
} else {
if ($reason) {
return 'halfGO';
}
return $y + 0.5;
}
} elseif ($this->whatBlock($level, new Vector3($x, $y, $z)) == "lava") {
//岩浆
//echo "前方岩浆 \n";
if ($reason) {
return 'lava';
}
return false;
} elseif ($this->whatBlock($level, new Vector3($x, $y, $z)) == "high") {
//1.5格高方块
//echo "前方栅栏 \n";
if ($reason) {
//.........这里部分代码省略.........
作者:boyboo
项目:PocketMine-M
/**
* @param Vector3 $spawn default null
*
* @return bool|Position
*/
public function getSafeSpawn($spawn = null)
{
if (!$spawn instanceof Vector3) {
$spawn = $this->getSpawn();
}
if ($spawn instanceof Vector3) {
$x = (int) round($spawn->x);
$y = (int) round($spawn->y);
$z = (int) round($spawn->z);
for (; $y > 0; --$y) {
$v = new Vector3($x, $y, $z);
$b = $this->getBlock($v->getSide(0));
if ($b === false) {
return $spawn;
} elseif (!$b instanceof Air) {
break;
}
}
for (; $y < 128; ++$y) {
$v = new Vector3($x, $y, $z);
if ($this->getBlock($v->getSide(1)) instanceof Air) {
if ($this->getBlock($v) instanceof Air) {
return new Position($x, $y, $z, $this);
}
} else {
++$y;
}
}
return new Position($x, $y, $z, $this);
}
return false;
}
作者:GoneTon
项目:WorldEditAr
public function isInside(Vector3 $v)
{
if (!$this->isValid()) {
return false;
}
return min($this->x1, $this->x2) <= $v->x and min($this->y1, $this->y2) <= $v->y and min($this->z1, $this->z2) <= $v->z and max($this->x1, $this->x2) >= $v->x and max($this->y1, $this->y2) >= $v->y and max($this->z1, $this->z2) >= $v->z and !$v instanceof Position or $v->getLevel()->getName() === $this->levelName;
}
作者:legoboy021
项目:LegionPE-Theta-Bas
/**
* @param Vector3 $v
* @param mixed $data
* @param int $id
* @param FullChunk $chunk
*/
public function __construct($v, $data, $id = -2, $chunk = null)
{
$this->data = $data;
if (!$v instanceof Vector3) {
if ($v instanceof FullChunk) {
$v->removeEntity($this);
}
throw new \RuntimeException("BadConstructCustomHuman");
}
$nbt = new Compound();
$nbt->Pos = new Enum("Motion", [new Double(0, $v->x), new Double(1, $v->y), new Double(2, $v->z)]);
$nbt->Motion = new Enum("Motion", [new Double(0, 0), new Double(1, 0), new Double(2, 0)]);
$nbt->Rotation = new Enum("Rotation", [new Float(0, $this->getDefaultYaw()), new Float(1, $this->getDefaultPitch())]);
$nbt->FallDistance = new Float("FallDistance", 0);
$nbt->Fire = new Short("Fire", 0);
$nbt->Air = new Short("Air", 0);
$nbt->OnGround = new Byte("OnGround", 1);
$nbt->Invulnerable = new Byte("Invulnerable", 1);
$nbt->Health = new Short("Health", 20);
$nbt->NameTag = $this->getDefaultName();
$nbt->Inventory = new Enum("Inventory", []);
$nbt->Inventory->setTagType(NBT::TAG_Compound);
$this->inventory = new PlayerInventory($this);
$this->setSkin($this->getDefaultSkin());
parent::__construct($chunk, $nbt);
}
作者:barnseyminesu
项目:Small-ZC-Plugin
public function isInside(Vector3 $v)
{
$out = true;
$out = ($out and $v->distance($this->centre) <= $this->radius);
if ($v instanceof Position) {
$out = ($out and $v->getLevel()->getName() === $this->centre->getLevel()->getName());
}
return $out;
}
作者:GoneTon
项目:WorldEditAr
public function isInside(Vector3 $v)
{
if (!$this->isValid()) {
return false;
}
if ($v instanceof Position and $v->getLevel()->getName() !== $this->levelName) {
return false;
}
return $v->distanceSquared($this->center) <= $this->radiusSquared;
}
作者:PepbookPv
项目:Genisy
public function onUpdate($currentTick)
{
if ($this->closed !== false) {
return false;
}
if (++$this->switchDirectionTicker === 100) {
$this->switchDirectionTicker = 0;
if (mt_rand(0, 100) < 50) {
$this->swimDirection = null;
}
}
$this->lastUpdate = $currentTick;
$this->timings->startTiming();
$hasUpdate = parent::onUpdate($currentTick);
if ($this->isAlive()) {
if ($this->y > 62 and $this->swimDirection !== null) {
$this->swimDirection->y = -0.5;
}
/*$inWater = $this->isInsideOfAir();
if(!$inWater){
//$this->motionY -= $this->gravity;
$this->swimDirection = null;
}else*/
if ($this->swimDirection !== null) {
if ($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2 <= $this->swimDirection->lengthSquared()) {
$this->motionX = $this->swimDirection->x * $this->swimSpeed;
$this->motionY = $this->swimDirection->y * $this->swimSpeed;
$this->motionZ = $this->swimDirection->z * $this->swimSpeed;
}
} else {
$this->swimDirection = $this->generateRandomDirection();
$this->swimSpeed = mt_rand(50, 100);
}
$expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
$this->move($this->motionX, $this->motionY, $this->motionZ);
if ($expectedPos->distanceSquared($this) > 0) {
$this->swimDirection = $this->generateRandomDirection();
$this->swimSpeed = mt_rand(50, 100);
}
$friction = 1 - $this->drag;
$this->motionX *= $friction;
$this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction;
$f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
$this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
$this->pitch = -atan2($f, $this->motionY) * 180 / M_PI;
if ($this->onGround) {
$this->motionY *= -0.5;
}
$this->updateMovement();
}
$this->timings->stopTiming();
return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
}
作者:GoneTon
项目:WorldEditAr
/**
* Checks whether the passed {@link Vector3} is included in this {@link Space}.<br>
* Floating point vectors are accepted.<br>
* <br>
* The contents of this function are based on <a
* href="http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html">Wolfram|MathWorld: Point-Lne Distance
* (3-Dimensional)</a>, whereas {@code X0 = $v, X1 = $this->baseCenter, X2 = $this->topCenter}.
*
* @param Vector3 $v the coordinates to check.
*
* @return bool whether <code> $v</code> is inside the space.
*/
public function isInside(Vector3 $v)
{
if (!$this->isValid()) {
return false;
}
if ($v instanceof Position and $v->getLevel()->getName() !== $this->levelName) {
return false;
}
$distSquared = $v->subtract($this->baseCenter)->cross($v->subtract($this->topCenter))->lengthSquared() / $this->topCenter->subtract($this->baseCenter)->lengthSquared();
// |---|
return $distSquared <= $this->radiusSquared;
// |(X0 - X1) x (X0 - X2)| / |X2 - X1|
}
作者:HelloWorld01
项目:ToAruArche
public static function createEffectArrow(Player $player, Vector3 $position, Vector3 $speed, $yaw, $pitch, $r, $g, $b, $critical)
{
$nbtTag = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $position->getX()), new Double("", $position->getY()), new Double("", $position->getZ())]), "Rotation" => new Enum("Rotation", [new Float("", $yaw), new Float("", $pitch)])]);
$arrow = new EffectArrow($player->chunk, $nbtTag, $r, $g, $b, $player, $critical);
$arrow->setMotion($speed);
$launchEvent = new ProjectileLaunchEvent($arrow);
Server::getInstance()->getPluginManager()->callEvent($launchEvent);
if ($launchEvent->isCancelled()) {
$arrow->kill();
return null;
} else {
return $arrow;
}
}
作者:DWW
项目:pocketmine-plugin
public function onPlayerInteract(PlayerInteractEvent $e)
{
// Implement the CompassTP thingie...
$pl = $e->getPlayer();
if (!$pl->hasPermission("toybox.compasstp")) {
return;
}
$hand = $pl->getInventory()->getItemInHand();
if ($hand->getID() != $this->item) {
return;
}
$pos = $pl->getPosition()->add(0, $pl->getEyeHeight(), 0);
$start = new Vector3($pos->getX(), $pos->getY(), $pos->getZ());
$lv = $pl->getLevel();
for ($start = new Vector3($pos->getX(), $pos->getY(), $pos->getZ()); $start->distance($pos) < 120; $pos = $pos->add($pl->getDirectionVector())) {
$block = $lv->getBlock($pos->floor());
if ($block->getId() != 0) {
break;
}
}
if ($block->getId() == 0) {
$pl->sendMessage(mc::_("Can not teleport to the void!"));
return;
}
$pos = $pos->subtract($pl->getDirectionVector());
$dist = $start->distance($pos);
if ($dist < 2.8) {
$pl->sendMessage(mc::_("Not teleporting..."));
$pl->sendMessage(mc::_("You could easily walk there!"));
return;
}
//echo "Block: ".$block->getName()." (".$block->getId().")\n";
//print_r($pos);
//echo "Distance: ".$start->distance($pos)."\n";
$pl->sendMessage(mc::_("Teleporting... %1%", intval($dist)));
$pos = $pos->add(0, 1, 0);
/*$cb = new CallbackTask([$this,"delayedTP"],[$pl->getName(),
$pos->getX(),
$pos->getY(),
$pos->getZ()]);
$this->owner->getServer()->getScheduler()->scheduleDelayedTask($cb,20);
//$pl->teleport($pos);
return;*/
$m = 5.0;
for ($f = 1.0; $f <= $m; $f++) {
$ticks = intval($f) * 5;
$x = ($pos->getX() - $start->getX()) * $f / $m + $start->getX();
$y = ($pos->getY() - $start->getY()) * $f / $m + $start->getY();
$z = ($pos->getZ() - $start->getZ()) * $f / $m + $start->getZ();
$c = new PluginCallbackTask($this->owner, [$this, "delayedTP"], [$pl->getName(), $x, $y, $z]);
$this->owner->getServer()->getScheduler()->scheduleDelayedTask($c, $ticks);
}
}
作者:ClearSkyTea
项目:ClearSk
public function onUpdate($type)
{
if ($type === Level::BLOCK_UPDATE_NORMAL) {
$faces = array_flip(array(2 => 2, 3 => 4, 4 => 5, 5 => 3));
if ($this->getSide(Vector3::getOppositeSide($faces[$this->meta % 4 + 2]))->isTransparent() === true) {
$this->getLevel()->useBreakOn($this);
return Level::BLOCK_UPDATE_NORMAL;
}
} elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
if (mt_rand(0, 2) === 1) {
if ($this->meta < 8) {
$block = clone $this;
$block->meta += 4;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
if (!$ev->isCancelled()) {
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
} else {
return Level::BLOCK_UPDATE_RANDOM;
}
}
} else {
return Level::BLOCK_UPDATE_RANDOM;
}
}
return false;
}
作者:145593107
项目:Genisy
public function onUpdate($currentTick)
{
if ($this->closed !== false) {
return false;
}
$this->lastUpdate = $currentTick;
$this->timings->startTiming();
$hasUpdate = true;
//parent::onUpdate($currentTick);
if ($this->isAlive()) {
$expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
$expBlock0 = $this->getLevel()->getBlock($expectedPos->add(0, -1, 0)->round());
$expBlock1 = $this->getLevel()->getBlock($expectedPos->add(0, 0, 0)->round());
if ($expBlock0->getId() == 0) {
$this->motionY -= $this->gravity;
//重力计算
$this->motionX = 0;
$this->motionZ = 0;
} else {
$this->motionY = 0;
}
if ($expBlock1->getId() != 0) {
$this->motionY += 0.1;
}
$this->move($this->motionX, $this->motionY, $this->motionZ);
if ($this->isFreeMoving) {
$this->motionX = 0;
$this->motionZ = 0;
$this->isFreeMoving = false;
}
/*$friction = 1 - $this->drag;
$this->motionX *= $friction;
$this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction;*/
$f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
$this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
//视角计算
//$this->pitch = (-atan2($f, $this->motionY) * 180 / M_PI);
$this->updateMovement();
}
$this->timings->stopTiming();
return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
}
作者:JungHyun345
项目:PMMP-Plugin
public function __construct(Level $level, Vector3 $pos)
{
if (!($pos instanceof Vector3 && $level instanceof Level)) {
echo "this is not Floor!\n";
}
$this->vector = $pos;
$this->x = $pos->getX();
$this->y = $pos->getY();
$this->z = $pos->getZ();
$this->level = $level;
$this->block = $level->getBlock($pos);
$this->id = $this->block->getId();
$this->data = $this->block->getDamage();
$this->height = 128;
//$this->level->getHeightMap($this->x, $this->z);
echo "max height: {$this->height}\n";
if (!($this->isElevatorBlock($this->block) || $this->isExtensionFloorBlock($this->block))) {
echo "THIS IS NOT FLOOR!\n";
}
}
作者:zzz199
项目:ImagicalMin
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
{
if ($face !== 0 && $face !== 1) {
$faces = [3 => 3, 2 => 4, 4 => 2, 5 => 1];
$this->meta = $faces[$face];
if ($this->getSide(Vector3::getOppositeSide($face))->getId() === Block::TRIPWIRE) {
$this->meta & 0x1;
}
$this->getLevel()->setBlock($block, Block::get(Block::TRIPWIRE_HOOK, $this->meta), true);
return true;
}
return false;
}
作者:TylerAndre
项目:Steadfast
/**
* @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->getHardness() / 5 + 0.3) * $this->stepLen;
if ($blastForce > 0) {
if (!isset($this->affectedBlocks[$index = PHP_INT_SIZE === 8 ? ($block->x & 0xfffffff) << 35 | ($block->y & 0x7f) << 28 | $block->z & 0xfffffff : $block->x . ":" . $block->y . ":" . $block->z])) {
$this->affectedBlocks[$index] = $block;
}
}
}
$pointerX += $vector->x;
$pointerY += $vector->y;
$pointerZ += $vector->z;
}
}
}
}
}
return true;
}
作者:AnonymousProject
项目:PocketMine-MP-Origina
public function onUpdate($currentTick)
{
if ($this->closed !== false) {
return false;
}
if ($this->getLevel()->getServer()->aiConfig["zombie"] != 2) {
return parent::onUpdate($currentTick);
}
$this->lastUpdate = $currentTick;
$this->timings->startTiming();
$hasUpdate = parent::onUpdate($currentTick);
if ($this->isAlive()) {
/* Don't use time directly
* Instead, get remainder of current time divided by 24,000
* This tells us the time of day, which is what we really need
*/
$timeOfDay = abs($this->getLevel()->getTime() % 24000);
if (0 < $timeOfDay and $timeOfDay < 13000) {
$this->setOnFire(2);
}
//僵尸起火
$p = $this->getNearestPlayer();
//找到最近的可以被仇恨的玩家
if (!$p) {
$this->hated = false;
if (++$this->moveTicker >= 100) {
$this->moveDirection = $this->generateRandomDirection();
$this->moveTicker = 0;
}
} else {
$this->hated = $p;
if ($p->distance($this) <= $this->fire_r) {
$p->setOnFire(2);
}
//点燃玩家
if (!$this->tempTicking) {
if (++$this->hateTicker >= 10 or $this->moveDirection == null) {
//每0.5秒获取僵尸前进的新方向
$this->moveDirection = $this->generateDirection($p);
$this->hateTicker = 0;
}
}
}
if ($this->tempTicking) {
//帮助僵尸寻找新的方向走出困境
if (++$this->tempTicker >= 20) {
$this->tempTicking = false;
$this->tempTicker = 0;
}
}
if ($this->hated instanceof Player) {
//攻击玩家
if ($this->hated->distance($this) < $this->attack_r) {
$this->hated->attack(2, new EntityDamageByEntityEvent($this, $this->hated, EntityDamageEvent::CAUSE_ENTITY_ATTACK, 2));
}
}
if ($this->moveDirection != null) {
if ($this->motionX ** 2 + $this->motionZ ** 2 <= $this->moveDirection->lengthSquared()) {
$motionY = $this->getVelY();
//僵尸运动计算
if ($motionY >= 0) {
$this->motionX = $this->moveDirection->x * $this->moveSpeed;
$this->motionZ = $this->moveDirection->z * $this->moveSpeed;
$this->motionY = $motionY;
} else {
$this->moveDirection = $this->generateRandomDirection();
//生成随机运动方向
$this->moveTicker = 0;
$this->tempTicking = true;
}
}
} else {
$this->moveDirection = $this->generateRandomDirection();
$this->moveTicker = 0;
}
//var_dump($this->moveDirection,$this->motionX,$this->motionZ);
$expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
if ($this->motionY == 0) {
$this->motionY -= $this->gravity;
}
//重力计算
$this->move($this->motionX, $this->motionY, $this->motionZ);
if ($expectedPos->distanceSquared($this) > 0) {
$this->moveDirection = $this->generateRandomDirection();
}
$friction = 1 - $this->drag;
$this->motionX *= $friction;
//$this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction;
$f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
$this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
//视角计算
//$this->pitch = (-atan2($f, $this->motionY) * 180 / M_PI);
$this->updateMovement();
}
$this->timings->stopTiming();
return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
}
作者:Guillaume35
项目:Katan
public function __construct(Level $level, Vector3 $start, Vector3 $direction, $yOffset = 0, $maxDistance = 0)
{
$this->level = $level;
$this->maxDistance = (int) $maxDistance;
$this->blockQueue = new \SplFixedArray(3);
$startClone = new Vector3($start->x, $start->y, $start->z);
$startClone->y += $yOffset;
$this->currentDistance = 0;
$mainDirection = 0;
$secondDirection = 0;
$thirdDirection = 0;
$mainPosition = 0;
$secondPosition = 0;
$thirdPosition = 0;
$pos = new Vector3($startClone->x, $startClone->y, $startClone->z);
$startBlock = $this->level->getBlock(new Vector3(floor($pos->x), floor($pos->y), floor($pos->z)));
if ($this->getXLength($direction) > $mainDirection) {
$this->mainFace = $this->getXFace($direction);
$mainDirection = $this->getXLength($direction);
$mainPosition = $this->getXPosition($direction, $startClone, $startBlock);
$this->secondFace = $this->getYFace($direction);
$secondDirection = $this->getYLength($direction);
$secondPosition = $this->getYPosition($direction, $startClone, $startBlock);
$this->thirdFace = $this->getZFace($direction);
$thirdDirection = $this->getZLength($direction);
$thirdPosition = $this->getZPosition($direction, $startClone, $startBlock);
}
if ($this->getYLength($direction) > $mainDirection) {
$this->mainFace = $this->getYFace($direction);
$mainDirection = $this->getYLength($direction);
$mainPosition = $this->getYPosition($direction, $startClone, $startBlock);
$this->secondFace = $this->getZFace($direction);
$secondDirection = $this->getZLength($direction);
$secondPosition = $this->getZPosition($direction, $startClone, $startBlock);
$this->thirdFace = $this->getXFace($direction);
$thirdDirection = $this->getXLength($direction);
$thirdPosition = $this->getXPosition($direction, $startClone, $startBlock);
}
if ($this->getZLength($direction) > $mainDirection) {
$this->mainFace = $this->getZFace($direction);
$mainDirection = $this->getZLength($direction);
$mainPosition = $this->getZPosition($direction, $startClone, $startBlock);
$this->secondFace = $this->getXFace($direction);
$secondDirection = $this->getXLength($direction);
$secondPosition = $this->getXPosition($direction, $startClone, $startBlock);
$this->thirdFace = $this->getYFace($direction);
$thirdDirection = $this->getYLength($direction);
$thirdPosition = $this->getYPosition($direction, $startClone, $startBlock);
}
$d = $mainPosition / $mainDirection;
$secondd = $secondPosition - $secondDirection * $d;
$thirdd = $thirdPosition - $thirdDirection * $d;
$this->secondError = floor($secondd * self::$gridSize);
$this->secondStep = round($secondDirection / $mainDirection * self::$gridSize);
$this->thirdError = floor($thirdd * self::$gridSize);
$this->thirdStep = round($thirdDirection / $mainDirection * self::$gridSize);
if ($this->secondError + $this->secondStep <= 0) {
$this->secondError = -$this->secondStep + 1;
}
if ($this->thirdError + $this->thirdStep <= 0) {
$this->thirdError = -$this->thirdStep + 1;
}
$lastBlock = $startBlock->getSide(Vector3::getOppositeSide($this->mainFace));
if ($this->secondError < 0) {
$this->secondError += self::$gridSize;
$lastBlock = $lastBlock->getSide(Vector3::getOppositeSide($this->secondFace));
}
if ($this->thirdError < 0) {
$this->thirdError += self::$gridSize;
$lastBlock = $lastBlock->getSide(Vector3::getOppositeSide($this->thirdFace));
}
$this->secondError -= self::$gridSize;
$this->thirdError -= self::$gridSize;
$this->blockQueue[0] = $lastBlock;
$this->currentBlock = -1;
$this->scan();
$startBlockFound = false;
for ($cnt = $this->currentBlock; $cnt >= 0; --$cnt) {
if ($this->blockEquals($this->blockQueue[$cnt], $startBlock)) {
$this->currentBlock = $cnt;
$startBlockFound = true;
break;
}
}
if (!$startBlockFound) {
throw new \InvalidStateException("Start block missed in BlockIterator");
}
$this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection));
}
作者:edwinyoo4
项目:MyOwnWorl
public function SkeletonRandomWalkCalc()
{
$this->dif = $this->plugin->getServer()->getDifficulty();
//$this->getLogger()->info("僵尸数量:".count($this->plugin->Skeleton));
foreach ($this->plugin->getServer()->getLevels() as $level) {
foreach ($level->getEntities() as $zo) {
if ($zo instanceof Skeleton) {
if ($this->plugin->willMove($zo)) {
if (!isset($this->plugin->Skeleton[$zo->getId()])) {
$this->plugin->Skeleton[$zo->getId()] = array('ID' => $zo->getId(), 'IsChasing' => false, 'motionx' => 0, 'motiony' => 0, 'motionz' => 0, 'hurt' => 10, 'time' => 10, 'x' => 0, 'y' => 0, 'z' => 0, 'oldv3' => $zo->getLocation(), 'yup' => 20, 'up' => 0, 'yaw' => $zo->yaw, 'pitch' => 0, 'level' => $zo->getLevel()->getName(), 'xxx' => 0, 'zzz' => 0, 'gotimer' => 10, 'swim' => 0, 'jump' => 0.01, 'canjump' => true, 'drop' => false, 'canAttack' => 0, 'shoot' => 20, 'knockBack' => false);
$zom =& $this->plugin->Skeleton[$zo->getId()];
$zom['x'] = $zo->getX();
$zom['y'] = $zo->getY();
$zom['z'] = $zo->getZ();
}
$zom =& $this->plugin->Skeleton[$zo->getId()];
if ($zom['IsChasing'] === false) {
//自由行走模式
if ($zom['gotimer'] == 0 or $zom['gotimer'] == 10) {
//限制转动幅度
$newmx = mt_rand(-5, 5) / 10;
while (abs($newmx - $zom['motionx']) >= 0.7) {
$newmx = mt_rand(-5, 5) / 10;
}
$zom['motionx'] = $newmx;
$newmz = mt_rand(-5, 5) / 10;
while (abs($newmz - $zom['motionz']) >= 0.7) {
$newmz = mt_rand(-5, 5) / 10;
}
$zom['motionz'] = $newmz;
} elseif ($zom['gotimer'] >= 20 and $zom['gotimer'] <= 24) {
$zom['motionx'] = 0;
$zom['motionz'] = 0;
//僵尸停止
}
$zom['gotimer'] += 0.5;
if ($zom['gotimer'] >= 22) {
$zom['gotimer'] = 0;
}
//重置走路计时器
//$zom['motionx'] = mt_rand(-10,10)/10;
//$zom['motionz'] = mt_rand(-10,10)/10;
$zom['yup'] = 0;
$zom['up'] = 0;
//boybook的y轴判断法
//$width = $this->width;
$pos = new Vector3($zom['x'] + $zom['motionx'], floor($zo->getY()) + 1, $zom['z'] + $zom['motionz']);
//目标坐标
$zy = $this->plugin->ifjump($zo->getLevel(), $pos);
if ($zy === false) {
//前方不可前进
$pos2 = new Vector3($zom['x'], $zom['y'], $zom['z']);
//目标坐标
if ($this->plugin->ifjump($zo->getLevel(), $pos2) === false) {
//原坐标依然是悬空
$pos2 = new Vector3($zom['x'], $zom['y'] - 1, $zom['z']);
//下降
$zom['up'] = 1;
$zom['yup'] = 0;
} else {
$zom['motionx'] = -$zom['motionx'];
$zom['motionz'] = -$zom['motionz'];
//转向180度,向身后走
$zom['up'] = 0;
}
} else {
$pos2 = new Vector3($zom['x'] + $zom['motionx'], $zy - 1, $zom['z'] + $zom['motionz']);
//目标坐标
if ($pos2->y - $zom['y'] < 0) {
$zom['up'] = 1;
} else {
$zom['up'] = 0;
}
}
if ($zom['motionx'] == 0 and $zom['motionz'] == 0) {
//僵尸停止
} else {
//转向计算
$yaw = $this->plugin->getyaw($zom['motionx'], $zom['motionz']);
//$zo->setRotation($yaw,0);
$zom['yaw'] = $yaw;
$zom['pitch'] = 0;
}
//更新僵尸坐标
if (!$zom['knockBack']) {
$zom['x'] = $pos2->getX();
$zom['z'] = $pos2->getZ();
$zom['y'] = $pos2->getY();
}
$zom['motiony'] = $pos2->getY() - $zo->getY();
//echo($zo->getY()."\n");
//var_dump($pos2);
//var_dump($zom['motiony']);
$zo->setPosition($pos2);
//echo "SetPosition \n";
}
}
}
}
}
//.........这里部分代码省略.........
作者:NewDelio
项目:PocketMine-0.13.
/**
* @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;
}