Пример #1
0
 public function onUpdate($type)
 {
     if ($type === BLOCK_UPDATE_NORMAL) {
         $down = $this->getSide(0);
         if ($down->getID() !== SAND and $down->getID() !== CACTUS) {
             //Replace with common break method
             $this->level->setBlock($this, new AirBlock(), false);
             ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
             return BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === BLOCK_UPDATE_RANDOM) {
         if ($this->getSide(0)->getID() !== CACTUS) {
             if ($this->meta == 0xf) {
                 for ($y = 1; $y < 3; ++$y) {
                     $b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
                     if ($b->getID() === AIR) {
                         $this->level->setBlock($b, new CactusBlock(), true, false, true);
                         break;
                     }
                 }
                 $this->meta = 0;
                 $this->level->setBlock($this, $this, false);
             } else {
                 ++$this->meta;
                 $this->level->setBlock($this, $this, false);
             }
             return BLOCK_UPDATE_RANDOM;
         }
     }
     return false;
 }
Пример #2
0
 public function onUpdate($type)
 {
     if ($type === BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent === true) {
             //Replace with common break method
             ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
             $this->level->setBlock($this, new AirBlock(), false, false, true);
             return BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === BLOCK_UPDATE_RANDOM) {
         //Growth
         if (mt_rand(1, 7) === 1) {
             if (($this->meta & 0x8) === 0x8) {
                 TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x3);
             } else {
                 $this->meta |= 0x8;
                 $this->level->setBlock($this, $this, true, false, true);
                 return BLOCK_UPDATE_RANDOM;
             }
         } else {
             return BLOCK_UPDATE_RANDOM;
         }
     }
     return false;
 }
 public function __construct(ServerAPI $api, $server = false)
 {
     $this->api = $api;
     $this->server = ServerAPI::request();
     $this->sessions = array();
     SimpleAuthAPI::set($this);
 }
Пример #4
0
 public function onUpdate($type)
 {
     if ($type === BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent === true) {
             //Replace with common break method
             ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
             $this->level->setBlock($this, new AirBlock(), false, false, true);
             return BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === BLOCK_UPDATE_RANDOM) {
         if (mt_rand(0, 2) == 1) {
             if ($this->meta < 0x7) {
                 ++$this->meta;
                 $this->level->setBlock($this, $this, true, false, true);
                 return BLOCK_UPDATE_RANDOM;
             } else {
                 for ($side = 2; $side <= 5; ++$side) {
                     $b = $this->getSide($side);
                     if ($b->getID() === MELON_BLOCK) {
                         return BLOCK_UPDATE_RANDOM;
                     }
                 }
                 $side = $this->getSide(mt_rand(2, 5));
                 $d = $side->getSide(0);
                 if ($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)) {
                     $this->level->setBlock($side, new MelonBlock(), true, false, true);
                 }
             }
         }
         return BLOCK_UPDATE_RANDOM;
     }
     return false;
 }
Пример #5
0
 function __construct()
 {
     $this->help = array();
     $this->cmds = array();
     $this->alias = array();
     $this->server = ServerAPI::request();
     $this->last = microtime(true);
 }
Пример #6
0
 public function onUpdate($type)
 {
     if ($type === BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent === true) {
             //Replace with common break method
             ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
             $this->level->setBlock($this, new AirBlock(), false);
             return BLOCK_UPDATE_NORMAL;
         }
     }
     return false;
 }
Пример #7
0
 public function onActivate(Item $item, Player $player)
 {
     if ($item->getID() === FLINT_STEEL) {
         if (($player->gamemode & 0x1) === 0) {
             $item->useOn($this);
         }
         $data = array("x" => $this->x + 0.5, "y" => $this->y + 0.5, "z" => $this->z + 0.5, "power" => 4, "fuse" => 20 * 4);
         $this->level->setBlock($this, new AirBlock(), false, false, true);
         $e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
         ServerAPI::request()->api->entity->spawnToAll($e);
         return true;
     }
     return false;
 }
Пример #8
0
 public function onUpdate($type)
 {
     if ($type === BLOCK_UPDATE_NORMAL) {
         $side = $this->getMetadata();
         $faces = array(1 => 4, 2 => 5, 3 => 2, 4 => 3, 5 => 0, 6 => 0, 0 => 0);
         if ($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)) {
             //Replace with common break method
             ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
             $this->level->setBlock($this, new AirBlock(), true, false, true);
             return BLOCK_UPDATE_NORMAL;
         }
     }
     return false;
 }
Пример #9
0
 public function check()
 {
     for ($n = 0; $n < $this->threads; ++$n) {
         if ($this->workers[$n]->isTerminated() === true) {
             $this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
         } elseif ($this->workers[$n]->isWaiting()) {
             if ($this->workers[$n]->response !== "") {
                 console($this->workers[$n]->response);
                 $this->workers[$n]->notify();
             } else {
                 $this->workers[$n]->response = ServerAPI::request()->api->console->run($this->workers[$n]->cmd, "rcon");
                 $this->workers[$n]->notify();
             }
         }
     }
 }
Пример #10
0
 /**
  * @param integer $type
  *
  * @return boolean
  */
 public function onUpdate($type)
 {
     if ($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL) {
         $down = $this->getSide(0);
         if ($down->getID() === AIR or $down instanceof LiquidBlock) {
             $data = array("x" => $this->x + 0.5, "y" => $this->y + 0.5, "z" => $this->z + 0.5, "Tile" => $this->id);
             $server = ServerAPI::request();
             $this->level->setBlock($this, new AirBlock(), false, false, true);
             $e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
             $server->api->entity->spawnToAll($e);
             $server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
         }
         return false;
     }
     return false;
 }
Пример #11
0
 public function getDrops(Item $item, Player $player)
 {
     $drops = array();
     if ($item->isPickaxe() >= 1) {
         $drops[] = array(FURNACE, 0, 1);
     }
     $t = ServerAPI::request()->api->tile->get($this);
     if ($t !== false and $t->class === TILE_FURNACE) {
         for ($s = 0; $s < FURNACE_SLOTS; ++$s) {
             $slot = $t->getSlot($s);
             if ($slot->getID() > AIR and $slot->count > 0) {
                 $drops[] = array($slot->getID(), $slot->getMetadata(), $slot->count);
             }
         }
     }
     return $drops;
 }
Пример #12
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->isTransparent === false and $face > 1 and $block->isSolid === false) {
         $server = ServerAPI::request();
         $faces = array(2 => 1, 3 => 3, 4 => 0, 5 => 2);
         $motives = array(array("Kebab", 1, 1), array("Aztec", 1, 1), array("Alban", 1, 1), array("Aztec2", 1, 1), array("Bomb", 1, 1), array("Plant", 1, 1), array("Wasteland", 1, 1), array("Wanderer", 1, 2), array("Graham", 1, 2), array("Pool", 2, 1), array("Courbet", 2, 1), array("Sunset", 2, 1), array("Sea", 2, 1), array("Creebet", 2, 1), array("Match", 2, 2), array("Bust", 2, 2), array("Stage", 2, 2), array("Void", 2, 2), array("SkullAndRoses", 2, 2), array("Fighters", 4, 2), array("Skeleton", 4, 3), array("DonkeyKong", 4, 3), array("Pointer", 4, 4), array("Pigscene", 4, 4), array("Flaming Skull", 4, 4));
         $motive = $motives[mt_rand(0, count($motives) - 1)];
         $data = array("x" => $target->x, "y" => $target->y, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]);
         $e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data);
         $server->api->entity->spawnToAll($e);
         if (($player->gamemode & 0x1) === 0x0) {
             $player->removeItem($this->getID(), $this->getMetadata(), 1, false);
         }
         return true;
     }
     return false;
 }
Пример #13
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     switch ($this->meta) {
         case MOB_CHICKEN:
         case MOB_SHEEP:
         case MOB_COW:
         case MOB_PIG:
             $data = array("x" => $block->x + 0.5, "y" => $block->y, "z" => $block->z + 0.5);
             $e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
             ServerAPI::request()->api->entity->spawnToAll($e);
             if (($player->gamemode & 0x1) === 0) {
                 --$this->count;
             }
             return true;
             break;
     }
     return false;
 }
Пример #14
0
 public static function grantAchievement(Player $player, $achievementId)
 {
     if (isset(self::$achievements[$achievementId]) and !self::hasAchievement($player, $achievementId)) {
         foreach (self::$achievements[$achievementId]["requires"] as $requerimentId) {
             if (!self::hasAchievement($player, $requerimentId)) {
                 return false;
             }
         }
         if (ServerAPI::request()->api->dhandle("achievement.grant", array("player" => $player, "achievementId" => $achievementId)) !== false) {
             $player->achievements[$achievementId] = true;
             self::broadcastAchievement($player, $achievementId);
             return true;
         } else {
             return false;
         }
     }
     return false;
 }
Пример #15
0
 public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name)
 {
     $this->server = ServerAPI::request();
     $this->level = $level;
     $this->level->level = $this;
     $this->entities = $entities;
     $this->tiles = $tiles;
     $this->blockUpdates = $blockUpdates;
     $this->startTime = $this->time = (int) $this->level->getData("time");
     $this->nextSave = $this->startCheck = microtime(true);
     $this->nextSave += 90;
     $this->stopTime = false;
     $this->server->schedule(15, array($this, "checkThings"), array(), true);
     $this->server->schedule(20 * 13, array($this, "checkTime"), array(), true);
     $this->name = $name;
     $this->usedChunks = array();
     $this->changedBlocks = array();
     $this->changedCount = array();
 }
Пример #16
0
 function __construct(Level $level, $id, $class, $x, $y, $z, $data = array())
 {
     $this->server = ServerAPI::request();
     $this->level = $level;
     $this->normal = true;
     $this->class = $class;
     $this->data = $data;
     $this->closed = false;
     if ($class === false) {
         $this->closed = true;
     }
     $this->name = "";
     $this->lastUpdate = microtime(true);
     $this->scheduledUpdate = false;
     $this->id = (int) $id;
     $this->x = (int) $x;
     $this->y = (int) $y;
     $this->z = (int) $z;
     $this->server->query("INSERT OR REPLACE INTO tiles (ID, level, class, x, y, z) VALUES (" . $this->id . ", '" . $this->level->getName() . "', '" . $this->class . "', " . $this->x . ", " . $this->y . ", " . $this->z . ");");
     switch ($this->class) {
         case TILE_CHEST:
         case TILE_SIGN:
             $this->server->query("UPDATE tiles SET spawnable = 1 WHERE ID = " . $this->id . ";");
             break;
         case TILE_FURNACE:
             if (!isset($this->data["BurnTime"]) or $this->data["BurnTime"] < 0) {
                 $this->data["BurnTime"] = 0;
             }
             if (!isset($this->data["CookTime"]) or $this->data["CookTime"] < 0 or $this->data["BurnTime"] === 0 and $this->data["CookTime"] > 0) {
                 $this->data["CookTime"] = 0;
             }
             if (!isset($this->data["MaxTime"])) {
                 $this->data["MaxTime"] = $this->data["BurnTime"];
                 $this->data["BurnTicks"] = 0;
             }
             if ($this->data["BurnTime"] > 0) {
                 $this->update();
             }
             break;
     }
 }
Пример #17
0
 public function __construct()
 {
     console("[INFO] Starting GS4 status listener");
     $this->server = ServerAPI::request();
     $addr = ($ip = $this->server->api->getProperty("server-ip")) != "" ? $ip : "0.0.0.0";
     $port = $this->server->api->getProperty("server-port");
     console("[INFO] Setting query port to {$port}");
     /*
     The Query protocol is built on top of the existing Minecraft PE UDP network stack.
     Because the 0xFE packet does not exist in the MCPE protocol,
     we can identify	Query packets and remove them from the packet queue.
     
     Then, the Query class handles itself sending the packets in raw form, because
     packets can conflict with the MCPE ones.
     */
     $this->server->schedule(20 * 30, array($this, "regenerateToken"), array(), true);
     $this->regenerateToken();
     $this->lastToken = $this->token;
     $this->regenerateInfo();
     console("[INFO] Query running on {$addr}:{$port}");
 }
Пример #18
0
 public function onActivate(Item $item, Player $player)
 {
     if (ServerAPI::request()->api->time->getPhase($player->level) !== "night") {
         $pk = new ChatPacket();
         $pk->message = "You can only sleep at night";
         $player->dataPacket($pk);
         return true;
     }
     $blockNorth = $this->getSide(2);
     //Gets the blocks around them
     $blockSouth = $this->getSide(3);
     $blockEast = $this->getSide(5);
     $blockWest = $this->getSide(4);
     if (($this->meta & 0x8) === 0x8) {
         //This is the Top part of bed
         $b = $this;
     } else {
         //Bottom Part of Bed
         if ($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x8) === 0x8) {
             $b = $blockNorth;
         } elseif ($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x8) === 0x8) {
             $b = $blockSouth;
         } elseif ($blockEast->getID() === $this->id and ($blockEast->meta & 0x8) === 0x8) {
             $b = $blockEast;
         } elseif ($blockWest->getID() === $this->id and ($blockWest->meta & 0x8) === 0x8) {
             $b = $blockWest;
         } else {
             $pk = new ChatPacket();
             $pk->message = "This bed is incomplete";
             $player->dataPacket($pk);
             return true;
         }
     }
     if ($player->sleepOn($b) === false) {
         $pk = new ChatPacket();
         $pk->message = "This bed is occupied";
         $player->dataPacket($pk);
     }
     return true;
 }
Пример #19
0
 public function onUpdate($type)
 {
     if ($type === BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent === true) {
             //Replace with common break method
             ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(BEETROOT_SEEDS, 0, 1));
             $this->level->setBlock($this, new AirBlock(), false, false, true);
             return BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === BLOCK_UPDATE_RANDOM) {
         if (mt_rand(0, 2) == 1) {
             if ($this->meta < 0x7) {
                 ++$this->meta;
                 $this->level->setBlock($this, $this, true, false, true);
                 return BLOCK_UPDATE_RANDOM;
             }
         } else {
             return BLOCK_UPDATE_RANDOM;
         }
     }
     return false;
 }
 public function packetDispatcher(&$packet, $event)
 {
     if ($event !== "server.noauthpacket") {
         return;
     }
     switch ($packet["pid"]) {
         case 0x2:
             //Ping External
             foreach ($this->config->get("servers") as $server) {
                 ServerAPI::request()->send(0x1d, array($packet["data"][0], Utils::readLong("13p13p"), RAKNET_MAGIC, $packet["ip"] . ";" . $packet["port"]), false, $server["server"], $server["port"]);
             }
             break;
         case 0x1d:
             //Ping Internal
             if ($packet["data"][1] !== Utils::readLong("13p13p")) {
                 break;
             }
             $data = explode(";", $packet["data"][3]);
             ServerAPI::request()->packetHandler(array("pid" => 0x2, "data" => array(0 => $data[0], 1 => RAKNET_MAGIC), "raw" => "", "ip" => $data[0], "port" => (int) $data[1]));
             return false;
     }
 }
Пример #21
0
 public function __construct(ServerAPI $api, $server = false)
 {
     $this->api = $api;
     $this->interval = array();
     $this->server = ServerAPI::request();
 }
Пример #22
0
 /**
  * 更新 token
  * @param unknown $userId
  * @param unknown $avatar
  * @return boolean|array
  */
 public function refresh()
 {
     $userId = intval($this->input['userId']);
     $userName = trim($this->input['userName']);
     $func = $this->settings['rc_func']['refresh'];
     $app_id = intval($this->input['app_id']);
     $portraitUri = $this->input['avatar'];
     if (!$userId || !$userName || !$app_id) {
         return false;
     }
     if (!$portraitUri) {
         return false;
     }
     //查询是否有appSecret
     $RCinfo = $this->getRCinfo($app_id);
     $data = array('userId' => $userId, 'name' => $userName, 'portraitUri' => $portraitUri);
     $server = new ServerAPI($RCinfo['production_app_key'], $RCinfo['production_app_secret'], $func, $data);
     $res = $server->request();
     $result = (array) json_decode($res);
     if ($result['code'] != 200) {
         return false;
     }
     $info = array('user_id' => $userId);
     $this->addItem($info);
     $this->output();
 }
Пример #23
0
 public function explode()
 {
     $server = ServerAPI::request();
     if ($this->size < 0.1 or $server->api->dhandle("entity.explosion", array("level" => $this->level, "source" => $this->source, "size" => $this->size)) === false) {
         return false;
     }
     $mRays = $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 = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1);
                     //($i / $mRays) * 2 - 1
                     $vector = $vector->normalize()->multiply($this->stepLen);
                     $pointer = clone $this->source;
                     for ($blastForce = $this->size * (mt_rand(700, 1300) / 1000); $blastForce > 0; $blastForce -= $this->stepLen * 0.75) {
                         $vBlock = $pointer->floor();
                         $blockID = $this->level->level->getBlockID($vBlock->x, $vBlock->y, $vBlock->z);
                         if ($blockID > 0) {
                             $block = BlockAPI::get($blockID, 0);
                             $block->x = $vBlock->x;
                             $block->y = $vBlock->y;
                             $block->z = $vBlock->z;
                             $blastForce -= ($block->getHardness() / 5 + 0.3) * $this->stepLen;
                             if ($blastForce > 0) {
                                 $index = ($block->x << 15) + ($block->z << 7) + $block->y;
                                 if (!isset($this->affectedBlocks[$index])) {
                                     $this->affectedBlocks[$index] = $block;
                                 }
                             }
                         }
                         $pointer = $pointer->add($vector);
                     }
                 }
             }
         }
     }
     $send = array();
     $source = $this->source->floor();
     $radius = 2 * $this->size;
     foreach ($server->api->entity->getRadius($this->source, $radius) as $entity) {
         $impact = (1 - $this->source->distance($entity) / $radius) * 0.5;
         //placeholder, 0.7 should be exposure
         $damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
         $entity->harm($damage, "explosion");
     }
     foreach ($this->affectedBlocks as $block) {
         if ($block instanceof TNTBlock) {
             $data = array("x" => $block->x + 0.5, "y" => $block->y + 0.5, "z" => $block->z + 0.5, "power" => 4, "fuse" => mt_rand(10, 30));
             $e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
             $server->api->entity->spawnToAll($e);
         } elseif (mt_rand(0, 10000) < 1 / $this->size * 10000) {
             if (isset(self::$specialDrops[$block->getID()])) {
                 $server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0));
             } else {
                 $server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
             }
         }
         $this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
         $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
     }
     $pk = new ExplodePacket();
     $pk->x = $this->source->x;
     $pk->y = $this->source->y;
     $pk->z = $this->source->z;
     $pk->radius = $this->size;
     $pk->records = $send;
     $server->api->player->broadcastPacket($this->level->players, $pk);
 }
Пример #24
0
 /**
  * @param Item $item
  * @param Player $player
  *
  * @return boolean
  */
 public function onActivate(Item $item, Player $player)
 {
     if (($this->meta & 0x8) === 0x8) {
         //Top
         $down = $this->getSide(0);
         if ($down->getID() === $this->id) {
             $meta = $down->getMetadata() ^ 0x4;
             $this->level->setBlock($down, BlockAPI::get($this->id, $meta), true, false, true);
             $players = ServerAPI::request()->api->player->getAll($this->level);
             unset($players[$player->CID]);
             $pk = new LevelEventPacket();
             $pk->x = $this->x;
             $pk->y = $this->y;
             $pk->z = $this->z;
             $pk->evid = 1003;
             $pk->data = 0;
             ServerAPI::request()->api->player->broadcastPacket($players, $pk);
             return true;
         }
         return false;
     } else {
         $this->meta ^= 0x4;
         $this->level->setBlock($this, $this, true, false, true);
         $players = ServerAPI::request()->api->player->getAll($this->level);
         unset($players[$player->CID]);
         $pk = new LevelEventPacket();
         $pk->x = $this->x;
         $pk->y = $this->y;
         $pk->z = $this->z;
         $pk->evid = 1003;
         $pk->data = 0;
         ServerAPI::request()->api->player->broadcastPacket($players, $pk);
     }
     return true;
 }
Пример #25
0
 function __construct()
 {
     $this->tiles = array();
     $this->server = ServerAPI::request();
 }
Пример #26
0
 public function __construct()
 {
     $this->server = ServerAPI::request();
     $this->levels = array();
 }
Пример #27
0
 function __construct()
 {
     $this->server = ServerAPI::request();
 }
Пример #28
0
 function __construct(Level $level, $eid, $class, $type = 0, $data = array())
 {
     $this->level = $level;
     $this->fallY = false;
     $this->fallStart = false;
     $this->server = ServerAPI::request();
     $this->eid = (int) $eid;
     $this->type = (int) $type;
     $this->class = (int) $class;
     $this->player = false;
     $this->attach = false;
     $this->data = $data;
     $this->status = 0;
     $this->health = 20;
     $this->dmgcounter = array(0, 0, 0);
     $this->air = 300;
     $this->fire = 0;
     $this->crouched = false;
     $this->invincible = false;
     $this->lastUpdate = $this->spawntime = microtime(true);
     $this->dead = false;
     $this->closed = false;
     $this->isStatic = false;
     $this->name = "";
     $this->tickCounter = 0;
     $this->server->query("INSERT OR REPLACE INTO entities (EID, level, type, class, health, hasUpdate) VALUES (" . $this->eid . ", '" . $this->level->getName() . "', " . $this->type . ", " . $this->class . ", " . $this->health . ", 0);");
     $this->x = isset($this->data["x"]) ? (double) $this->data["x"] : 0;
     $this->y = isset($this->data["y"]) ? (double) $this->data["y"] : 0;
     $this->z = isset($this->data["z"]) ? (double) $this->data["z"] : 0;
     $this->speedX = isset($this->data["speedX"]) ? (double) $this->data["speedX"] : 0;
     $this->speedY = isset($this->data["speedY"]) ? (double) $this->data["speedY"] : 0;
     $this->speedZ = isset($this->data["speedZ"]) ? (double) $this->data["speedZ"] : 0;
     $this->speed = 0;
     $this->yaw = isset($this->data["yaw"]) ? (double) $this->data["yaw"] : 0;
     $this->pitch = isset($this->data["pitch"]) ? (double) $this->data["pitch"] : 0;
     $this->position = array("level" => $this->level, "x" => &$this->x, "y" => &$this->y, "z" => &$this->z, "yaw" => &$this->yaw, "pitch" => &$this->pitch);
     switch ($this->class) {
         case ENTITY_PLAYER:
             $this->player = $this->data["player"];
             $this->setHealth($this->health, "generic");
             $this->size = 1.2;
             break;
         case ENTITY_ITEM:
             if (isset($data["item"]) and $data["item"] instanceof Item) {
                 $this->meta = $this->data["item"]->getMetadata();
                 $this->stack = $this->data["item"]->count;
             } else {
                 $this->meta = (int) $this->data["meta"];
                 $this->stack = (int) $this->data["stack"];
             }
             $this->setHealth(5, "generic");
             $this->server->schedule(6010, array($this, "update"));
             //Despawn
             $this->update();
             $this->size = 0.75;
             break;
         case ENTITY_MOB:
             $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
             $this->update();
             //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
             $this->size = 1;
             break;
         case ENTITY_FALLING:
             $this->setHealth(PHP_INT_MAX, "generic");
             $this->update();
             $this->size = 0.98;
             break;
         case ENTITY_OBJECT:
             $this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x;
             $this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y;
             $this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z;
             $this->setHealth(1, "generic");
             //$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
             $this->size = 1;
             if ($this->type === OBJECT_PAINTING) {
                 $this->isStatic = true;
             } elseif ($this->type === OBJECT_PRIMEDTNT) {
                 if (!isset($this->data["fuse"])) {
                     $this->data["fuse"] = 0;
                 }
                 $this->setHealth(10000000, "generic");
                 $this->server->schedule(5, array($this, "updateFuse"), array(), true);
                 $this->update();
             } elseif ($this->type === OBJECT_ARROW) {
                 $this->server->schedule(1210, array($this, "update"));
                 //Despawn
                 $this->update();
             }
             break;
     }
     $this->updateLast();
     $this->updatePosition();
     if ($this->y < 0 and $this->class !== ENTITY_PLAYER) {
         $this->close();
     }
 }
Пример #29
0
 public function onUpdate($type)
 {
     //return false;
     $newId = $this->id;
     $level = $this->meta & 0x7;
     if ($type !== BLOCK_UPDATE_NORMAL) {
         return false;
     }
     if ($this->checkWater()) {
         return;
     }
     $falling = $this->meta >> 3;
     $down = $this->getSide(0);
     $from = $this->getFrom();
     if ($from !== null || $level == 0x0) {
         if ($level !== 0x7) {
             if ($down instanceof AirBlock || $down instanceof LavaBlock) {
                 $this->level->setBlock($down, new LavaBlock(0x1), false, false, true);
                 ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
             } else {
                 for ($side = 2; $side <= 5; ++$side) {
                     $b = $this->getSide($side);
                     if ($b instanceof LavaBlock) {
                     } elseif ($b->isFlowable === true) {
                         $this->level->setBlock($b, new LavaBlock(min($level + 2, 7)), false, false, true);
                         ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
                     }
                 }
             }
         }
     } else {
         //Extend Remove for Left Lavas
         for ($side = 2; $side <= 5; ++$side) {
             $sb = $this->getSide($side);
             if ($sb instanceof LavaBlock) {
                 $tlevel = $sb->meta & 0x7;
                 if ($tlevel != 0x0) {
                     for ($s = 0; $s <= 5; $s++) {
                         $ssb = $sb->getSide($s);
                         ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
                     }
                     $this->level->setBlock($sb, new AirBlock(), false, false, true);
                 }
             }
             $b = $this->getSide(0)->getSide($side);
             if ($b instanceof LavaBlock) {
                 $tlevel = $b->meta & 0x7;
                 if ($tlevel != 0x0) {
                     for ($s = 0; $s <= 5; $s++) {
                         $ssb = $sb->getSide($s);
                         ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
                     }
                     $this->level->setBlock($b, new AirBlock(), false, false, true);
                 }
             }
             //ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
         }
         $this->level->setBlock($this, new AirBlock(), false, false, true);
     }
     return false;
 }
Пример #30
0
 public function onUpdate($type)
 {
     if ($type === BLOCK_UPDATE_NORMAL) {
         if (($this->meta & 0b1100) === 0) {
             $this->meta |= 0x8;
             $this->level->setBlock($this, $this, false, false, true);
             return BLOCK_UPDATE_RANDOM;
         }
     } elseif ($type === BLOCK_UPDATE_RANDOM) {
         if (($this->meta & 0b1100) === 0x8) {
             $this->meta &= 0x3;
             $visited = array();
             $check = 0;
             if ($this->findLog($this, $visited, 0, $check) === true) {
                 $this->level->setBlock($this, $this, false, false, true);
             } else {
                 $this->level->setBlock($this, new AirBlock(), false, false, true);
                 if (mt_rand(1, 20) === 1) {
                     //Saplings
                     ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x3, 1));
                 }
                 if (($this->meta & 0x3) === LeavesBlock::OAK and mt_rand(1, 200) === 1) {
                     //Apples
                     ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
                 }
                 return BLOCK_UPDATE_NORMAL;
             }
         }
     }
     return false;
 }