本文整理汇总了PHP中pocketmine\entity\Entity::createEntity方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::createEntity方法的具体用法?PHP Entity::createEntity怎么用?PHP Entity::createEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\entity\Entity
的用法示例。
在下文中一共展示了Entity::createEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attackEntity
public function attackEntity(Entity $player)
{
if ($this->attackDelay > 25 && mt_rand(1, 12) < 3 && $this->distanceSquared($player) <= 40) {
$this->attackDelay = 0;
$f = 1.5;
$yaw = $this->yaw + mt_rand(-180, 180) / 10;
$pitch = $this->pitch + mt_rand(-90, 90) / 10;
$nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $this->x), new Double("", $this->y + 1.62), new Double("", $this->z)]), "Motion" => new Enum("Motion", [new Double("", -sin($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI) * $f), new Double("", -sin($pitch / 180 * M_PI) * $f), new Double("", cos($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI) * $f)]), "Rotation" => new Enum("Rotation", [new Float("", $yaw), new Float("", $pitch)])]);
/** @var Projectile $arrow */
$arrow = Entity::createEntity("Arrow", $this->chunk, $nbt, $this);
$ev = new EntityShootBowEvent($this, Item::get(Item::ARROW, 0, 1), $arrow, $f);
$this->server->getPluginManager()->callEvent($ev);
$projectile = $ev->getProjectile();
if ($ev->isCancelled()) {
$ev->getProjectile()->kill();
} elseif ($projectile instanceof Projectile) {
$this->server->getPluginManager()->callEvent($launch = new ProjectileLaunchEvent($projectile));
if ($launch->isCancelled()) {
$projectile->kill();
} else {
$projectile->spawnToAll();
$this->level->addSound(new LaunchSound($this), $this->getViewers());
}
}
}
}
示例2: attackEntity
public function attackEntity(Entity $player)
{
if ($this->attackDelay > 30 && mt_rand(1, 32) < 4 && $this->distanceSquared($player) <= 200) {
$this->attackDelay = 0;
$f = 2;
$yaw = $this->yaw + mt_rand(-220, 220) / 10;
$pitch = $this->pitch + mt_rand(-120, 120) / 10;
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + -sin($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI) * 2), new DoubleTag("", $this->y + 2), new DoubleTag("", $this->z + cos($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI) * 2)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI)), new DoubleTag("", -sin($pitch / 180 * M_PI) * $f), new DoubleTag("", cos($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI))]), "Rotation" => new ListTag("Rotation", [new FloatTag("", $yaw), new FloatTag("", $pitch)])]);
$fireball = Entity::createEntity("FireBall", $this->chunk, $nbt, $this);
if ($fireball instanceof FireBall) {
$fireball->setExplode(true);
}
$fireball->setMotion($fireball->getMotion()->multiply($f));
$ev = new EntityShootBowEvent($this, Item::get(Item::ARROW, 0, 1), $fireball, $f);
$this->server->getPluginManager()->callEvent($ev);
$projectile = $ev->getProjectile();
if ($ev->isCancelled()) {
$projectile->kill();
} elseif ($projectile instanceof Projectile) {
$this->server->getPluginManager()->callEvent($launch = new ProjectileLaunchEvent($projectile));
if ($launch->isCancelled()) {
$projectile->kill();
} else {
$projectile->spawnToAll();
$this->level->addSound(new LaunchSound($this), $this->getViewers());
}
}
}
}
示例3: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
$entity = null;
$chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
if (!$chunk instanceof FullChunk) {
return false;
}
$nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
$entity = Entity::createEntity($this->meta, $chunk, $nbt);
if ($entity instanceof Entity) {
if ($player->isSurvival()) {
--$this->count;
}
$entity->spawnToAll();
return true;
}
return false;
}
示例4: burstArrow
public function burstArrow(Player $player)
{
if ($player->getInventory()->getItemInHand()->getId() === Item::BOW) {
$bow = $player->getInventory()->getItemInHand();
$nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $player->x), new Double("", $player->y + $player->getEyeHeight()), new Double("", $player->z)]), "Motion" => new Enum("Motion", [new Double("", -\sin($player->yaw / 180 * M_PI) * \cos($player->pitch / 180 * M_PI)), new Double("", -\sin($player->pitch / 180 * M_PI)), new Double("", \cos($player->yaw / 180 * M_PI) * \cos($player->pitch / 180 * M_PI))]), "Rotation" => new Enum("Rotation", [new Float("", $player->yaw), new Float("", $player->pitch)])]);
$ev = new EntityShootBowEvent($player, $bow, Entity::createEntity("Arrow", $player->chunk, $nbt, $player), 1.5);
$this->getServer()->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
$ev->getProjectile()->kill();
} else {
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
if ($ev->getProjectile() instanceof Projectile) {
$this->getServer()->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile()));
if ($projectileEv->isCancelled()) {
$ev->getProjectile()->kill();
} else {
$this->object_hash[spl_object_hash($ev->getProjectile())] = 1;
$ev->getProjectile()->spawnToAll();
}
} else {
$this->object_hash[spl_object_hash($ev->getProjectile())] = 1;
$ev->getProjectile()->spawnToAll();
}
}
}
}
示例5: onBreak
public function onBreak(Item $item)
{
if ($this->getRandomExperience($item) > 0) {
Entity::createEntity("ExperienceOrb", $this->level->getChunk($this->x >> 4, $this->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $this->x), new Double("", $this->y), new Double("", $this->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]))->spawnToAll();
}
return parent::onBreak($item);
}
示例6: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
if ($target->getId() == Block::MONSTER_SPAWNER) {
return true;
} else {
$entity = null;
$chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
if (!$chunk instanceof FullChunk) {
return false;
}
$nbt = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
if ($this->hasCustomName()) {
$nbt->CustomName = new StringTag("CustomName", $this->getCustomName());
}
$entity = Entity::createEntity($this->meta, $chunk, $nbt);
if ($entity instanceof Entity) {
if ($player->isSurvival()) {
--$this->count;
}
$entity->spawnToAll();
return true;
}
}
return false;
}
示例7: attackEntity
public function attackEntity(Entity $player)
{
if ($this->attackDelay > 23 && mt_rand(1, 32) < 4 && $this->distanceSquared($player) <= 55) {
$this->attackDelay = 0;
$f = 1.2;
$yaw = $this->yaw + mt_rand(-220, 220) / 10;
$pitch = $this->pitch + mt_rand(-120, 120) / 10;
$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + -sin($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI) * 0.5), new DoubleTag("", $this->y + 1), new DoubleTag("", $this->z + cos($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI) * 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI)), new DoubleTag("", -sin($pitch / 180 * M_PI)), new DoubleTag("", cos($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI))]), "Rotation" => new ListTag("Rotation", [new FloatTag("", $yaw), new FloatTag("", $pitch)])]);
/** @var Projectile $snowball */
$snowball = Entity::createEntity("Snowball", $this->chunk, $nbt, $this);
$snowball->setMotion($snowball->getMotion()->multiply($f));
$property = (new \ReflectionClass($snowball))->getProperty("damage");
$property->setAccessible(true);
$property->setValue($snowball, 2);
$ev = new EntityShootBowEvent($this, Item::get(Item::ARROW, 0, 1), $snowball, $f);
$this->server->getPluginManager()->callEvent($ev);
$projectile = $ev->getProjectile();
if ($ev->isCancelled()) {
$projectile->kill();
} elseif ($projectile instanceof Projectile) {
$this->server->getPluginManager()->callEvent($launch = new ProjectileLaunchEvent($projectile));
if ($launch->isCancelled()) {
$projectile->kill();
} else {
$projectile->spawnToAll();
$this->level->addSound(new LaunchSound($this), $this->getViewers());
}
}
}
}
示例8: prime
public function prime()
{
$this->meta = 1;
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = Entity::createEntity("PrimedTNT", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + 0.5), new DoubleTag("", $this->y), new DoubleTag("", $this->z + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($mot) * 0.02), new DoubleTag("", 0.2), new DoubleTag("", -cos($mot) * 0.02)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 80)]));
$tnt->spawnToAll();
$this->level->addSound(new TNTPrimeSound($this));
}
示例9: dropExpOrb__api200
public static function dropExpOrb__api200(Position $source, $exp = 1, Vector3 $motion = \null, $delay = 40)
{
$motion = $motion === \null ? new Vector3(\lcg_value() * 0.2 - 0.1, 0.4, \lcg_value() * 0.2 - 0.1) : $motion;
$entity = Entity::createEntity("ExperienceOrb", $source->getLevel()->getChunk($source->getX() >> 4, $source->getZ() >> 4, \true), new \pocketmine\nbt\tag\CompoundTag("", ["Pos" => new \pocketmine\nbt\tag\ListTag("Pos", [new \pocketmine\nbt\tag\DoubleTag("", $source->getX()), new \pocketmine\nbt\tag\DoubleTag("", $source->getY()), new \pocketmine\nbt\tag\DoubleTag("", $source->getZ())]), "Motion" => new \pocketmine\nbt\tag\ListTag("Motion", [new \pocketmine\nbt\tag\DoubleTag("", $motion->x), new \pocketmine\nbt\tag\DoubleTag("", $motion->y), new \pocketmine\nbt\tag\DoubleTag("", $motion->z)]), "Rotation" => new \pocketmine\nbt\tag\ListTag("Rotation", [new \pocketmine\nbt\tag\FloatTag("", \lcg_value() * 360), new \pocketmine\nbt\tag\FloatTag("", 0)]), "Health" => new \pocketmine\nbt\tag\ShortTag("Health", 20), "PickupDelay" => new \pocketmine\nbt\tag\ShortTag("PickupDelay", $delay)]));
if ($entity instanceof ExperienceOrb) {
$entity->setExp($exp);
}
$entity->spawnToAll();
}
示例10: onUpdate
public function onUpdate($type)
{
if ($type === Level::BLOCK_UPDATE_NORMAL) {
$down = $this->getSide(Vector3::SIDE_DOWN);
if ($down->getId() === self::AIR or $down instanceof Liquid) {
$fall = Entity::createEntity("FallingSand", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $this->x + 0.5), new Double("", $this->y), new Double("", $this->z + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)]), "TileID" => new Int("TileID", $this->getId()), "Data" => new Byte("Data", $this->getDamage())]));
$fall->spawnToAll();
}
}
}
示例11: onActivate
public function onActivate(Item $item, Player $player = null)
{
if ($item->getId() === Item::FLINT_STEEL) {
$item->useOn($this);
$this->getLevel()->setBlock($this, new Air(), true);
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = Entity::createEntity("PrimedTNT", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + 0.5), new DoubleTag("", $this->y), new DoubleTag("", $this->z + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($mot) * 0.02), new DoubleTag("", 0.2), new DoubleTag("", -cos($mot) * 0.02)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 80)]));
$tnt->spawnToAll();
return true;
}
return false;
}
示例12: prime
public function prime(Player $player = null)
{
$this->meta = 1;
if ($player != null and $player->isCreative()) {
$dropItem = false;
} else {
$dropItem = true;
}
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = Entity::createEntity("PrimedTNT", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + 0.5), new DoubleTag("", $this->y), new DoubleTag("", $this->z + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($mot) * 0.02), new DoubleTag("", 0.2), new DoubleTag("", -cos($mot) * 0.02)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 80)]), $dropItem);
$tnt->spawnToAll();
$this->level->addSound(new TNTPrimeSound($this));
}
示例13: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
$realPos = $block->getSide($face);
$boat = Entity::createEntity("Boat", $player->getLevel()->getChunk($realPos->x >> 4, $realPos->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->x), new Double("", $realPos->y), new Double("", $realPos->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
$boat->spawnToAll();
--$this->count;
if ($this->count <= 0) {
$player->getInventory()->setItemInHand(Item::get(Item::AIR));
return true;
}
$player->getInventory()->setItemInHand($this);
return true;
}
示例14: place
public function place(BlockPlaceEvent $place)
{
$block = $place->getBlock();
$player = $place->getPlayer();
if ($block->getId() === 46) {
$place->setCancelled();
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = Entity::createEntity("PrimedTNT", $block->getLevel()->getChunk($block->x >> 4, $block->z >> 4), new Compound("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->x + 0.5), new DoubleTag("", $block->y), new DoubleTag("", $block->z + 0.5)]), "Motion" => new EnumTag("Motion", [new DoubleTag("", -sin($mot) * 0.02), new DoubleTag("", 0.2), new DoubleTag("", -cos($mot) * 0.02)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]), "Fuse" => new ByteTag("Fuse", 100)]));
$tnt->spawnToAll();
$player->getLevel()->addSound(new AnviluseSound($player), array($player));
return true;
}
}
示例15: launch
public function launch(Player $player)
{
$nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $player->x), new Double("", $player->y + $player->getEyeHeight()), new Double("", $player->z)]), "Motion" => new Enum("Motion", [new Double("", -sin($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI)), new Double("", -sin($player->pitch / 180 * M_PI)), new Double("", cos($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI))]), "Rotation" => new Enum("Rotation", [new Float("", $player->yaw), new Float("", $player->pitch)]), "Data" => new Byte("Data", $this->getDamage())]);
$f = $this->f;
$launched = Entity::createEntity($this->getEntityName(), $player->chunk, $nbt, $player);
$launched->setMotion($launched->getMotion()->multiply($f));
if ($launched instanceof Projectile) {
$player->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($launched));
if ($projectileEv->isCancelled()) {
$launched->kill();
} else {
$launched->spawnToAll();
$player->level->addSound(new LaunchSound($player), $player->getViewers());
}
} else {
$launched->spawnToAll();
}
return true;
}