本文整理汇总了PHP中pocketmine\math\Vector3::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Vector3::add方法的具体用法?PHP Vector3::add怎么用?PHP Vector3::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\math\Vector3
的用法示例。
在下文中一共展示了Vector3::add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onUpdate
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;
}
示例2: onUpdate
public function onUpdate($currentTick)
{
if ($this->closed == true || $this->dead == true || ($target = $this->target) == null || $target->dead || $this->player instanceof Player && !$this->player->spawned) {
if (!$this->closed) {
parent::close();
}
$this->dead = true;
return false;
} else {
$dis = sqrt(pow($dZ = $target->z - $this->z, 2) + pow($dX = $target->x - $this->x, 2));
if ($this->isHead) {
$bb = clone $this->getBoundingBox();
$this->timings->startTiming();
$tickDiff = max(1, $currentTick - $this->lastUpdate);
$this->lastUpdate = $currentTick;
$hasUpdate = $this->entityBaseTick($tickDiff);
if ($this->getLevel()->getFolderName() !== $target->getLevel()->getFolderName()) {
$this->teleport($target);
}
$onGround = count($this->level->getCollisionBlocks($bb->offset(0, -$this->gravity, 0))) > 0;
$x = cos($at2 = atan2($dZ, $dX)) * $this->speed;
$z = sin($at2) * $this->speed;
$y = 0;
$bb->offset(0, $this->gravity, 0);
$isJump = count($this->level->getCollisionBlocks($bb->grow(0, 0, 0)->offset($x, 1, $z))) <= 0;
if (count($this->level->getCollisionBlocks($bb->grow(0, 0, 0)->offset(0, 0, $z))) > 0) {
$z = 0;
if ($isJump) {
$y = $this->gravity;
}
}
if (count($this->level->getCollisionBlocks($bb->grow(0, 0, 0)->offset($x, 0, 0))) > 0) {
$x = 0;
if ($isJump) {
$y = $this->gravity;
}
}
if (!$this->isFallow || $dis < $this->distance) {
$x = 0;
$z = 0;
}
if ($this->isFallow && $dis > 20) {
$this->updateMove($target);
if ($target instanceof Player) {
$target->sendMessage("[MobPet] 같이가요 ");
}
return true;
} elseif (!$isJump && $target->y > $this->y - ($target instanceof Player ? 0.5 : 0)) {
if ($this->jumpTick <= 0) {
$this->jumpTick = 40;
} elseif ($this->jumpTick > 36) {
$y = $this->gravity;
}
}
if ($this->jumpTick > 0) {
$this->jumpTick--;
}
if (($n = floor($this->y) - $this->y) < $this->gravity && $n > 0) {
$y = -$n;
}
if ($y == 0 && !$onGround) {
$y = -$this->gravity;
}
$block = $this->level->getBlock($this->add($vec = new Vector3($x, $y, $z)));
if ($block->hasEntityCollision()) {
$block->addVelocityToEntity($this, $vec2 = $vec->add(0, $this->gravity, 0));
$vec->x = ($vec->x + $vec2->x / 2) / 5;
$vec->y = $vec->y + $vec2->y / 2;
$vec->z = ($vec->z + $vec2->z / 2) / 5;
}
if (count($this->level->getCollisionBlocks($bb->offset(0, -0.01, 0))) <= 0) {
$y -= 0.01;
}
$this->updateMove($vec->add(new Vector3(($this->boundingBox->minX + $this->boundingBox->maxX - $this->drag) / 2, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, ($this->boundingBox->minZ + $this->boundingBox->maxZ - $this->drag) / 2)));
$this->onGround = $onGround;
} else {
$x = cos($at2 = atan2($dZ, $dX)) * $this->distance;
$z = sin($at2) * $this->distance;
$this->updateMove($target->add(-$x, 0, -$z));
}
}
return true;
}
示例3: updateMove
public function updateMove(int $tickDiff)
{
if (!$this->isMovement()) {
return null;
}
if ($this->isKnockback()) {
$this->move($this->motionX * $tickDiff, $this->motionY, $this->motionZ * $tickDiff);
$this->motionY -= 0.15 * $tickDiff;
$this->updateMovement();
return null;
}
$before = $this->baseTarget;
$this->checkTarget();
if ($this->baseTarget instanceof Creature or $before !== $this->baseTarget) {
$x = $this->baseTarget->x - $this->x;
$y = $this->baseTarget->y - $this->y;
$z = $this->baseTarget->z - $this->z;
if ($this->stayTime > 0 || $x ** 2 + $z ** 2 < 0.7) {
$this->motionX = 0;
$this->motionZ = 0;
} else {
$diff = abs($x) + abs($z);
$this->motionX = $this->getSpeed() * 0.15 * ($x / $diff);
$this->motionZ = $this->getSpeed() * 0.15 * ($z / $diff);
}
$this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
$this->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt($x ** 2 + $z ** 2)));
}
$target = $this->mainTarget != null ? $this->mainTarget : $this->baseTarget;
if ($this->stayTime > 0) {
$this->stayTime -= 1;
} else {
$isJump = false;
$dx = $this->motionX * $tickDiff;
$dy = $this->motionY * $tickDiff;
$dz = $this->motionZ * $tickDiff;
$be = new Vector2($this->x + $dx, $this->z + $dz);
$this->move($dx, $dy, $dz);
$af = new Vector2($this->x, $this->z);
if ($be->x != $af->x || $be->y != $af->y) {
$x = 0;
$z = 0;
if ($be->x - $af->x != 0) {
$x += $be->x - $af->x > 0 ? 1 : -1;
}
if ($be->y - $af->y != 0) {
$z += $be->y - $af->y > 0 ? 1 : -1;
}
$vec = new Vector3(Math::floorFloat($be->x), (int) $this->y, Math::floorFloat($be->y));
$block = $this->level->getBlock($vec->add($x, 0, $z));
$block2 = $this->level->getBlock($vec->add($x, 1, $z));
if (!$block->canPassThrough()) {
$bb = $block2->getBoundingBox();
if ($this->motionY > -$this->gravity * 4 && ($block2->canPassThrough() || ($bb == null || $bb != null && $bb->maxY - $this->y <= 1))) {
$isJump = true;
if ($this->motionY >= 0.3) {
$this->motionY += $this->gravity;
} else {
$this->motionY = 0.3;
}
} elseif ($this->level->getBlock($vec)->getId() == Item::LADDER) {
$isJump = true;
$this->motionY = 0.15;
}
}
if (!$isJump) {
$this->moveTime -= 90 * $tickDiff;
}
}
if ($this->onGround && !$isJump) {
$this->motionY = 0;
} elseif (!$isJump) {
if ($this->motionY > -$this->gravity * 4) {
$this->motionY = -$this->gravity * 4;
} else {
$this->motionY -= $this->gravity;
}
}
}
$this->updateMovement();
return $target;
}
示例4: ZombieRandomWalk
/**
* 高密集型发包计时器
* - 发送数据包
* - 计算自由落体相关数据
* 循环间隔:1 tick
*/
public function ZombieRandomWalk()
{
foreach ($this->AIHolder->getServer()->getLevels() as $level) {
foreach ($level->getEntities() as $zo) {
if ($zo instanceof Zombie) {
if (isset($this->AIHolder->pigzombie[$zo->getId()])) {
$zom =& $this->AIHolder->pigzombie[$zo->getId()];
if ($zom['canAttack'] != 0) {
$zom['canAttack'] -= 1;
}
$pos = $zo->getLocation();
//echo ($zom['IsChasing']."\n");
//真正的自由落体 by boybook
if ($zom['drop'] !== false) {
$olddrop = $zom['drop'];
$zom['drop'] += 0.5;
$drop = $zom['drop'];
//echo $drop."\n";
$dropy = $zo->getY() - ($olddrop * 0.05 + 0.0125);
$posd0 = new Vector3(floor($zo->getX()), floor($dropy), floor($zo->getZ()));
$posd = new Vector3($zo->getX(), $dropy, $zo->getZ());
if ($this->AIHolder->whatBlock($zo->getLevel(), $posd0) == "air") {
$zo->setPosition($posd->add(0, -1, 0));
//下降
} else {
for ($i = 1; $i <= $drop; $i++) {
$posd0->y++;
if ($this->AIHolder->whatBlock($zo->getLevel(), $posd0) != "block") {
$posd->y = $posd0->y;
$zo->setPosition($posd->add(0, -1, 0));
//下降完成
$h = $zom['drop'] * $zom['drop'] / 20;
$damage = $h - 3;
//echo($h . ": " . $damage . "\n");
if ($damage > 0) {
//$zo->attack($damage, EntityDamageEvent::CAUSE_FALL);
$zo->setHealth($zo->getHealth() - $damage);
}
$zom['drop'] = false;
break;
}
}
}
} else {
$drop = 0;
}
if ($zom['IsChasing'] !== false) {
if (!$zom['knockBack']) {
//echo $zy;
$zom['up'] = 0;
if ($this->AIHolder->whatBlock($level, $pos) == "water") {
$zom['swim'] += 1;
if ($zom['swim'] >= 20) {
$zom['swim'] = 0;
}
} else {
$zom['swim'] = 0;
}
//echo("目标:".$zo->getY()." ");
//echo("原先:".$zom['oldv3']->y."\n");
if (abs($zo->getY() - $zom['oldv3']->y) == 1 and $zom['canjump'] === true) {
//var_dump("跳");
$zom['canjump'] = false;
$zom['jump'] = 0.5;
} else {
if ($zom['jump'] > 0.01) {
$zom['jump'] -= 0.1;
} else {
$zom['jump'] = 0.01;
}
}
$pk3 = new SetEntityMotionPacket();
$pk3->entities = [[$zo->getID(), $zom['xxx'] / 10, -$zom['swim'] / 100 + $zom['jump'] - $drop, $zom['zzz'] / 10]];
foreach ($zo->getViewers() as $pl) {
$pl->dataPacket($pk3);
}
$p = $this->AIHolder->getServer()->getPlayer($zom['IsChasing']);
if ($p instanceof Player) {
if ($p->distance($pos) <= 1.3) {
//僵尸的火焰点燃人类
if ($zo->fireTicks > 0) {
$p->setOnFire(1);
}
}
if ($p->distance($pos) <= 1.5) {
if ($zom['canAttack'] == 0) {
$zom['canAttack'] = 20;
//@$p->knockBack($zo, 0, $zom['xxx'] / 10, $zom['zzz'] / 10);
if ($p->isSurvival()) {
$zoDamage = $this->AIHolder->getZombieDamage($zo->getHealth());
$damage = $this->AIHolder->getPlayerDamage($p, $zoDamage);
//echo $zoDamage."-".$damage."\n";
$p->attack($damage, new EntityDamageByEntityEvent($zo, $p, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage));
}
//.........这里部分代码省略.........
示例5: handleDataPacket
//.........这里部分代码省略.........
} else {
$packet->yaw %= 360;
$packet->pitch %= 360;
if ($packet->yaw < 0) {
$packet->yaw += 360;
}
$this->setRotation($packet->yaw, $packet->pitch);
$this->newPosition = $newPos;
}
$this->forceMovement = null;
break;
case ProtocolInfo::MOB_EQUIPMENT_PACKET:
if ($this->spawned === false or !$this->isAlive()) {
break;
}
/**
* Handle hotbar slot remapping
* This is the only time and place when hotbar mapping should ever be changed.
* Changing hotbar slot mapping at will has been deprecated because it causes far too many
* issues with Windows 10 Edition Beta.
*/
$this->inventory->setHeldItemIndex($packet->selectedSlot, false, $packet->slot);
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
break;
case ProtocolInfo::USE_ITEM_PACKET:
if ($this->spawned === false or !$this->isAlive() or $this->blocked) {
break;
}
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);
$this->craftingType = self::CRAFTING_SMALL;
if ($packet->face >= 0 and $packet->face <= 5) {
//Use Block, place
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
if (!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()) {
} elseif ($this->isCreative()) {
$item = $this->inventory->getItemInHand();
if ($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true) {
break;
}
} elseif (!$this->inventory->getItemInHand()->deepEquals($packet->item)) {
$this->inventory->sendHeldItem($this);
} else {
$item = $this->inventory->getItemInHand();
$oldItem = clone $item;
if ($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this)) {
if (!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()) {
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
break;
}
}
$this->inventory->sendHeldItem($this);
if ($blockVector->distanceSquared($this) > 10000) {
break;
}
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face);
$this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY);
break;
} elseif ($packet->face === 0xff) {
if ($this->isSpectator()) {
break;
}
$aimPos = (new Vector3($packet->x / 32768, $packet->y / 32768, $packet->z / 32768))->normalize();
if ($this->isCreative()) {
示例6: handleDataPacket
//.........这里部分代码省略.........
break;
} else {
$this->server->getPluginManager()->callEvent($ev = new PlayerToggleFlightEvent($this, $packet->isFlying));
if ($ev->isCancelled()) {
$this->sendSettings();
} else {
$this->flying = $ev->isFlying();
}
break;
}
break;
case ProtocolInfo::MOB_EQUIPMENT_PACKET:
if ($this->spawned === false or !$this->isAlive()) {
break;
}
/**
* Handle hotbar slot remapping
* This is the only time and place when hotbar mapping should ever be changed.
* Changing hotbar slot mapping at will has been deprecated because it causes far too many
* issues with Windows 10 Edition Beta.
*/
$this->inventory->setHeldItemIndex($packet->selectedSlot, false, $packet->slot);
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
break;
case ProtocolInfo::USE_ITEM_PACKET:
if ($this->spawned === false or !$this->isAlive() or $this->blocked) {
break;
}
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);
$this->craftingType = self::CRAFTING_SMALL;
if ($packet->face >= 0 and $packet->face <= 5) {
//Use Block, place
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
if (!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()) {
} elseif ($this->isCreative()) {
$item = $this->inventory->getItemInHand();
if ($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true) {
break;
}
} elseif (!$this->inventory->getItemInHand()->deepEquals($packet->item)) {
$this->inventory->sendHeldItem($this);
} else {
$item = $this->inventory->getItemInHand();
$oldItem = clone $item;
//TODO: Implement adventure mode checks
if ($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this)) {
if (!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()) {
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
break;
}
}
if ($this->isOnline()) {
$this->inventory->sendHeldItem($this);
}
if ($blockVector->distanceSquared($this) > 10000) {
break;
}
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face);
$this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY);
break;
} elseif ($packet->face === -1) {
$aimPos = new Vector3(-sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI), -sin($this->pitch / 180 * M_PI), cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI));
if ($this->isCreative()) {
示例7: CreeperRandomWalk
/**
* 高密集型发包计时器
* - 发送数据包
* - 计算自由落体相关数据
* 循环间隔:1 tick
*/
public function CreeperRandomWalk()
{
foreach ($this->AIHolder->getServer()->getLevels() as $level) {
foreach ($level->getEntities() as $zo) {
if ($zo instanceof Creeper) {
if (isset($this->AIHolder->Creeper[$zo->getId()])) {
$zom =& $this->AIHolder->Creeper[$zo->getId()];
if ($zom['canAttack'] != 0) {
$zom['canAttack'] -= 1;
}
$pos = $zo->getLocation();
//echo ($zom['IsChasing']."\n");
if ($zom['boom'] == false) {
//真正的自由落体 by boybook
if ($zom['drop'] !== false) {
$olddrop = $zom['drop'];
$zom['drop'] += 0.5;
$drop = $zom['drop'];
//echo $drop."\n";
$dropy = $zo->getY() - ($olddrop * 0.05 + 0.0125);
$posd0 = new Vector3(floor($zo->getX()), floor($dropy), floor($zo->getZ()));
$posd = new Vector3($zo->getX(), $dropy, $zo->getZ());
if ($this->AIHolder->whatBlock($zo->getLevel(), $posd0) == "air") {
$zo->setPosition($posd->add(0, 1, 0));
//下降
} else {
for ($i = 1; $i <= $drop; $i++) {
$posd0->y++;
if ($this->AIHolder->whatBlock($zo->getLevel(), $posd0) != "block") {
$posd->y = $posd0->y;
//$zo->setPosition($posd); //下降完成
$h = $zom['drop'] * $zom['drop'] / 20;
$damage = $h - 3;
//echo($h . ": " . $damage . "\n");
if ($damage > 0) {
$zo->setHealth($zo->getHealth() - $damage);
}
$zom['drop'] = false;
break;
}
}
}
} else {
$drop = 0;
}
if ($zom['IsChasing'] !== false) {
//var_dump($zom['IsChasing']);
if (!$zom['knockBack']) {
//echo $zy;
$zom['up'] = 0;
if ($this->AIHolder->whatBlock($level, $pos) == "water") {
$zom['swim'] += 1;
if ($zom['swim'] >= 20) {
$zom['swim'] = 0;
}
} else {
$zom['swim'] = 0;
}
//echo("目标:".$zo->getY()." ");
//echo("原先:".$zom['oldv3']->y."\n");
if (abs($zo->getY() - $zom['oldv3']->y) == 1 and $zom['canjump'] === true) {
//var_dump("跳");
$zom['canjump'] = false;
$zom['jump'] = 0.5;
} else {
if ($zom['jump'] > 0.01) {
$zom['jump'] -= 0.1;
} else {
$zom['jump'] = 0.01;
}
}
$pk3 = new SetEntityMotionPacket();
$pk3->entities = [[$zo->getID(), $zom['xxx'] / 10, -$zom['swim'] / 100 + $zom['jump'] - $drop, $zom['zzz'] / 10]];
foreach ($zo->getViewers() as $pl) {
$pl->dataPacket($pk3);
}
$p = $this->AIHolder->getServer()->getPlayer($zom['IsChasing']);
if ($p instanceof Player) {
if ($p->distance($pos) <= 1.3) {
//苦力怕的火焰点燃人类
// if ($zo->fireTicks > 0) {
// $p->setOnFire(5);
// }
}
if ($p->distance($pos) <= 2) {
//boom
$zom['boom'] = 5;
}
if ($p->distance($pos) <= 1.5) {
if ($zom['canAttack'] == 0) {
$zom['canAttack'] = 20;
@$p->knockBack($zo, 0, $zom['xxx'] / 10, $zom['zzz'] / 10);
if ($p->isSurvival()) {
$damage = 0;
//.........这里部分代码省略.........
示例8: SkeletonRandomWalk
public function SkeletonRandomWalk()
{
foreach ($this->plugin->getServer()->getLevels() as $level) {
foreach ($level->getEntities() as $zo) {
if ($zo instanceof Skeleton) {
if (isset($this->plugin->Skeleton[$zo->getId()])) {
$zom =& $this->plugin->Skeleton[$zo->getId()];
if ($zom['canAttack'] != 0) {
$zom['canAttack'] -= 1;
}
$pos = $zo->getLocation();
//echo ($zom['IsChasing']."\n");
//真正的自由落体 by boybook
if ($zom['drop'] !== false) {
$olddrop = $zom['drop'];
$zom['drop'] += 0.5;
$drop = $zom['drop'];
//echo $drop."\n";
$dropy = $zo->getY() - ($olddrop * 0.05 + 0.0125);
$posd0 = new Vector3(floor($zo->getX()), floor($dropy), floor($zo->getZ()));
$posd = new Vector3($zo->getX(), $dropy, $zo->getZ());
if ($this->plugin->whatBlock($zo->getLevel(), $posd0) == "air") {
$zo->setPosition($posd->add(0, 1, 0));
//下降
} else {
for ($i = 1; $i <= $drop; $i++) {
$posd0->y++;
if ($this->plugin->whatBlock($zo->getLevel(), $posd0) != "block") {
$posd->y = $posd0->y;
$zo->setPosition($posd->add(0, 1, 0));
//下降完成
$h = $zom['drop'] * $zom['drop'] / 20;
$damage = $h - 3;
//echo($h . ": " . $damage . "\n");
if ($damage > 0) {
//$zo->attack($damage, EntityDamageEvent::CAUSE_FALL);
$zo->setHealth($zo->getHealth() - $damage);
}
$zom['drop'] = false;
break;
}
}
}
} else {
$drop = 0;
}
if ($zom['IsChasing'] !== false) {
if (!$zom['knockBack']) {
//echo $zy;
$zom['up'] = 0;
if ($this->plugin->whatBlock($level, $pos) == "water") {
$zom['swim'] += 1;
if ($zom['swim'] >= 20) {
$zom['swim'] = 0;
}
} else {
$zom['swim'] = 0;
}
//echo("目标:".$zo->getY()." ");
//echo("原先:".$zom['oldv3']->y."\n");
if (abs($zo->getY() - $zom['oldv3']->y) == 1 and $zom['canjump'] === true) {
//var_dump("跳");
$zom['canjump'] = false;
$zom['jump'] = 0.5;
} else {
if ($zom['jump'] > 0.01) {
$zom['jump'] -= 0.1;
} else {
$zom['jump'] = 0.01;
}
}
$pk3 = new SetEntityMotionPacket();
$pk3->entities = [[$zo->getID(), $zom['xxx'] / 10, -$zom['swim'] / 100 + $zom['jump'] - $drop, $zom['zzz'] / 10]];
foreach ($zo->getViewers() as $pl) {
$pl->dataPacket($pk3);
}
$p = $this->plugin->getServer()->getPlayer($zom['IsChasing']);
if ($p instanceof Player) {
$zom['shoot'] = $zom['shoot'] - 1;
if ($zom['shoot'] <= 0) {
//boom
$zom['shoot'] = 20;
$v3 = new Vector3($zo->getX(), $zo->getY() + 2, $zo->getZ());
$chunk = $level->getChunk($v3->x >> 4, $v3->z >> 4, true);
$posnn = new Vector3($zo->getX(), $p->getY(), $zo->getZ());
$my = $p->getY() - $zo->getY();
$d = $p->distance($posnn);
$pitch = $this->getmypitch($my, $d);
$nbt2 = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $zo->getX()), new DoubleTag("", $zo->getY()), new DoubleTag("", $zo->getZ())]), "Motion" => new EnumTag("Motion", [new DoubleTag("", -\sin($zom['yaw']) * \cos($pitch / 180 * M_PI)), new DoubleTag("", -\sin($pitch / 180 * M_PI)), new DoubleTag("", \cos($zom['yaw'] / 180 * M_PI) * \cos($pitch / 180 * M_PI))]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", $zom['yaw']), new FloatTag("", $pitch)])]);
$f = 1.5;
//$ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this), $f);
$ev = new EntityShootBowEvent($zo, new ITEM(262, 0), Entity::createEntity("Arrow", $chunk, $nbt2, $zo), $f);
}
}
}
} else {
if ($zom['up'] == 1) {
if ($zom['yup'] <= 10) {
$pk3 = new SetEntityMotionPacket();
$pk3->entities = [[$zo->getID(), $zom['motionx'] / 10, $zom['motiony'] / 10, $zom['motionz'] / 10]];
//.........这里部分代码省略.........
示例9: handleDataPacket
//.........这里部分代码省略.........
break;
}
}
} elseif ($item === null or $slot === -1 or !$item->deepEquals($packet->item)) {
// packet error or not implemented
$this->inventory->sendContents($this);
break;
} elseif ($this->isCreative()) {
$this->inventory->setHeldItemIndex($packet->selectedSlot, false);
$this->inventory->setItem($packet->selectedSlot, $item);
$this->inventory->setHeldItemSlot($packet->selectedSlot);
$this->inventory->sendHeldItem($this->getViewers());
} else {
if ($packet->selectedSlot >= 0 and $packet->selectedSlot < $this->inventory->getHotbarSize()) {
$this->inventory->setHeldItemIndex($packet->selectedSlot, false);
$this->inventory->setHeldItemSlot($slot);
$this->inventory->sendHeldItem($this->getViewers());
} else {
$this->inventory->sendContents($this);
break;
}
}
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
break;
case ProtocolInfo::USE_ITEM_PACKET:
if ($this->spawned === false or !$this->isAlive() or $this->blocked) {
break;
}
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);
$this->craftingType = 0;
if ($packet->face >= 0 and $packet->face <= 5) {
//Use Block, place
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
if (!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()) {
} elseif ($this->isCreative()) {
$item = $this->inventory->getItemInHand();
if ($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true) {
break;
}
} elseif (!$this->inventory->getItemInHand()->deepEquals($packet->item)) {
$this->inventory->sendHeldItem($this);
} else {
$item = $this->inventory->getItemInHand();
$oldItem = clone $item;
if ($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this)) {
if (!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()) {
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
break;
}
}
$this->inventory->sendHeldItem($this);
if ($blockVector->distanceSquared($this) > 10000) {
break;
}
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face);
$this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY);
break;
} elseif ($packet->face === 0xff) {
if ($this->isSpectator()) {
break;
}
$aimPos = (new Vector3($packet->x / 32768, $packet->y / 32768, $packet->z / 32768))->normalize();
if ($this->isCreative()) {
示例10: triggerLavaMixEffects
/**
* Creates fizzing sound and smoke. Used when lava flows over block or mixes with water.
*
* @param Vector3 $pos
*/
protected function triggerLavaMixEffects(Vector3 $pos)
{
$this->getLevel()->addSound(new FizzSound($pos->add(0.5, 0.5, 0.5), 2.5 + mt_rand(0, 1000) / 1000 * 0.8));
for ($i = 0; $i < 8; ++$i) {
$this->getLevel()->addParticle(new SmokeParticle($pos->add(mt_rand(0, 80) / 100, 0.5, mt_rand(0, 80) / 100)));
}
}
示例11: handleDataPacket
//.........这里部分代码省略.........
$this->inventory->sendContents($this);
break;
}
}
} elseif ($item === null or $slot === -1 or !$item->deepEquals($packet->item)) {
// packet error or not implemented
$this->inventory->sendContents($this);
break;
} elseif ($this->isCreative()) {
$this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setItem($packet->selectedSlot, $item);
$this->inventory->setHeldItemSlot($packet->selectedSlot);
} else {
if ($packet->selectedSlot >= 0 and $packet->selectedSlot < $this->inventory->getHotbarSize()) {
$this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setHeldItemSlot($slot);
} else {
$this->inventory->sendContents($this);
break;
}
}
$this->inventory->sendHeldItem($this->hasSpawned);
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
break;
case ProtocolInfo::USE_ITEM_PACKET:
if ($this->spawned === false or !$this->isAlive() or $this->blocked) {
break;
}
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);
$this->craftingType = 0;
if ($packet->face >= 0 and $packet->face <= 5) {
//Use Block, place
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
if (!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()) {
} elseif ($this->isCreative()) {
$item = $this->inventory->getItemInHand();
if ($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true) {
break;
}
} elseif (!$this->inventory->getItemInHand()->deepEquals($packet->item)) {
$this->inventory->sendHeldItem($this);
} else {
$item = $this->inventory->getItemInHand();
$oldItem = clone $item;
//TODO: Implement adventure mode checks
if ($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this)) {
if (!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()) {
$this->inventory->setItemInHand($item);
$this->inventory->sendHeldItem($this->hasSpawned);
}
break;
}
}
$this->inventory->sendHeldItem($this);
if ($blockVector->distanceSquared($this) > 10000) {
break;
}
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face);
$this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY);
break;
} elseif ($packet->face === 0xff) {
$aimPos = (new Vector3($packet->x / 32768, $packet->y / 32768, $packet->z / 32768))->normalize();
if ($this->isCreative()) {
$item = $this->inventory->getItemInHand();
} elseif (!$this->inventory->getItemInHand()->deepEquals($packet->item)) {