示例#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(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;
 }
示例#3
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;
 }
示例#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($this->id));
             $this->level->setBlock($this, new AirBlock(), false);
             return BLOCK_UPDATE_NORMAL;
         }
     }
     return false;
 }
示例#5
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;
 }
示例#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(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;
 }
示例#7
0
 public final function getSmeltItem()
 {
     if (!isset(SmeltingData::$product[$this->id])) {
         return false;
     }
     if (isset(SmeltingData::$product[$this->id][0]) and !is_array(SmeltingData::$product[$this->id][0])) {
         return BlockAPI::getItem(SmeltingData::$product[$this->id][0], SmeltingData::$product[$this->id][1]);
     }
     if (!isset(SmeltingData::$product[$this->id][$this->meta])) {
         return false;
     }
     return BlockAPI::getItem(SmeltingData::$product[$this->id][$this->meta][0], SmeltingData::$product[$this->id][$this->meta][1]);
 }
 public function confiscateItems()
 {
     $players = $this->api->player->getAll();
     if (count($players) == 0) {
         return;
     }
     $air = BlockAPI::getItem(Air, 0, 0);
     foreach ($players as $player) {
         foreach ($player->inventory as $s => $item) {
             if ($item->getID() !== Air) {
                 $player->inventory[$s] = $air;
             }
         }
         $player->armor = array($air, $air, $air, $air);
         $player->sendInventorySlot();
         $player->sendArmor($player);
     }
 }
 private function startTransaction($username, $shopInfo, $c)
 {
     if (!file_exists("./plugins/PocketMoney/config.yml")) {
         $this->api->chat->sendTo(false, "[ChestShop][Error]PocketMoney plugin has not been loaded.", $username);
         console("[ChestShop][Error]PocketMoney plugin has not been loaded.");
         return;
     }
     $buyerMoney = $this->api->dhandle("money.player.get", array('username' => $username));
     if ($buyerMoney === false) {
         return;
     }
     if ($buyerMoney < $shopInfo['price']) {
         $this->api->chat->sendTo(false, "[ChestShop]Your money is not enough.", $username);
         return;
     }
     $chest = $this->api->tile->get(new Position($c->x, $c->y, $c->z, $c->level));
     $saleNum = 0;
     for ($i = 0; $i < CHEST_SLOTS; $i++) {
         $item = $chest->getSlot($i);
         if ($item->getID() === $shopInfo['productID']) {
             $saleNum += $item->count;
         }
     }
     if ($saleNum < $shopInfo['saleNum']) {
         $this->api->chat->sendTo(false, "[ChestShop]The stock is not enough.", $username);
         $this->api->chat->sendTo(false, "[ChestShop]Please notify the owner of the lack.", $username);
         return;
     }
     $cmd = "give";
     $params = array($username, $shopInfo['productID'], $shopInfo['saleNum']);
     $issuer = $this->api->player->get($username);
     $alias = false;
     $this->api->block->commandHandler($cmd, $params, $issuer, $alias);
     $tmpNum = $shopInfo['saleNum'];
     for ($i = 0; $i < CHEST_SLOTS; $i++) {
         $item = $chest->getSlot($i);
         if ($item->getID() === $shopInfo['productID']) {
             if ($item->count <= $tmpNum) {
                 $chest->setSlot($i, BlockAPI::getItem(AIR, 0, 0));
                 $tmpNum -= $item->count;
             } else {
                 $count = $item->count - $tmpNum;
                 $chest->setSlot($i, BlockAPI::getItem($item->getID(), 0, $count));
                 break;
             }
         }
     }
     $this->api->dhandle("money.handle", array('username' => $username, 'method' => 'grant', 'amount' => -$shopInfo['price']));
     $this->api->dhandle("money.handle", array('username' => $shopInfo['shopOwner'], 'method' => 'grant', 'amount' => $shopInfo['price']));
     $this->api->chat->sendTo(false, "[ChestShop]Completed the transaction.", $username);
     return;
 }
示例#10
0
 protected function getSlot()
 {
     $id = $this->getShort();
     $cnt = $this->getByte();
     return BlockAPI::getItem($id, $this->getShort(), $cnt);
 }
示例#11
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;
 }
示例#12
0
 public function spawn($player)
 {
     if (!$player instanceof Player) {
         $player = $this->server->api->player->get($player);
     }
     if ($player->eid === $this->eid or $this->closed !== false or $player->level !== $this->level and $this->class !== ENTITY_PLAYER) {
         return false;
     }
     switch ($this->class) {
         case ENTITY_PLAYER:
             if ($this->player->connected !== true or $this->player->spawned === false) {
                 return false;
             }
             $pk = new AddPlayerPacket();
             $pk->clientID = 0;
             //$this->player->clientID;
             $pk->username = $this->player->username;
             $pk->eid = $this->eid;
             $pk->x = $this->x;
             $pk->y = $this->y;
             $pk->z = $this->z;
             $pk->yaw = 0;
             $pk->pitch = 0;
             $pk->unknown1 = 0;
             $pk->unknown2 = 0;
             $pk->metadata = $this->getMetadata();
             $player->dataPacket($pk);
             $pk = new SetEntityMotionPacket();
             $pk->eid = $this->eid;
             $pk->speedX = $this->speedX;
             $pk->speedY = $this->speedY;
             $pk->speedZ = $this->speedZ;
             $player->dataPacket($pk);
             $pk = new PlayerEquipmentPacket();
             $pk->eid = $this->eid;
             $pk->item = $this->player->getSlot($this->player->slot)->getID();
             $pk->meta = $this->player->getSlot($this->player->slot)->getMetadata();
             $pk->slot = 0;
             $player->dataPacket($pk);
             $this->player->sendArmor($player);
             break;
         case ENTITY_ITEM:
             $pk = new AddItemEntityPacket();
             $pk->eid = $this->eid;
             $pk->x = $this->x;
             $pk->y = $this->y;
             $pk->z = $this->z;
             $pk->yaw = $this->yaw;
             $pk->pitch = $this->pitch;
             $pk->roll = 0;
             $pk->item = BlockAPI::getItem($this->type, $this->meta, $this->stack);
             $pk->metadata = $this->getMetadata();
             $player->dataPacket($pk);
             $pk = new SetEntityMotionPacket();
             $pk->eid = $this->eid;
             $pk->speedX = $this->speedX;
             $pk->speedY = $this->speedY;
             $pk->speedZ = $this->speedZ;
             $player->dataPacket($pk);
             break;
         case ENTITY_MOB:
             $pk = new AddMobPacket();
             $pk->eid = $this->eid;
             $pk->type = $this->type;
             $pk->x = $this->x;
             $pk->y = $this->y;
             $pk->z = $this->z;
             $pk->yaw = $this->yaw;
             $pk->pitch = $this->pitch;
             $pk->metadata = $this->getMetadata();
             $player->dataPacket($pk);
             $pk = new SetEntityMotionPacket();
             $pk->eid = $this->eid;
             $pk->speedX = $this->speedX;
             $pk->speedY = $this->speedY;
             $pk->speedZ = $this->speedZ;
             $player->dataPacket($pk);
             break;
         case ENTITY_OBJECT:
             if ($this->type === OBJECT_PAINTING) {
                 $pk = new AddPaintingPacket();
                 $pk->eid = $this->eid;
                 $pk->x = (int) $this->x;
                 $pk->y = (int) $this->y;
                 $pk->z = (int) $this->z;
                 $pk->direction = $this->getDirection();
                 $pk->title = $this->data["Motive"];
                 $player->dataPacket($pk);
             } elseif ($this->type === OBJECT_PRIMEDTNT) {
                 $pk = new AddEntityPacket();
                 $pk->eid = $this->eid;
                 $pk->type = $this->type;
                 $pk->x = $this->x;
                 $pk->y = $this->y;
                 $pk->z = $this->z;
                 $pk->did = 0;
                 $player->dataPacket($pk);
                 $pk = new SetEntityMotionPacket();
                 $pk->eid = $this->eid;
                 $pk->speedX = $this->speedX;
                 $pk->speedY = $this->speedY;
                 $pk->speedZ = $this->speedZ;
                 $player->dataPacket($pk);
             } elseif ($this->type === OBJECT_ARROW) {
                 $pk = new AddEntityPacket();
                 $pk->eid = $this->eid;
                 $pk->type = $this->type;
                 $pk->x = $this->x;
                 $pk->y = $this->y;
                 $pk->z = $this->z;
                 $pk->did = 0;
                 $player->dataPacket($pk);
                 $pk = new SetEntityMotionPacket();
                 $pk->eid = $this->eid;
                 $pk->speedX = $this->speedX;
                 $pk->speedY = $this->speedY;
                 $pk->speedZ = $this->speedZ;
                 $player->dataPacket($pk);
             }
             break;
         case ENTITY_FALLING:
             $pk = new AddEntityPacket();
             $pk->eid = $this->eid;
             $pk->type = $this->type;
             $pk->x = $this->x;
             $pk->y = $this->y;
             $pk->z = $this->z;
             $pk->did = -$this->data["Tile"];
             $player->dataPacket($pk);
             $pk = new SetEntityMotionPacket();
             $pk->eid = $this->eid;
             $pk->speedX = $this->speedX;
             $pk->speedY = $this->speedY;
             $pk->speedZ = $this->speedZ;
             $player->dataPacket($pk);
             break;
     }
 }
示例#13
0
 public function command($cmd, $params, $issuer, $alias)
 {
     $output = "";
     if ($alias !== false) {
         $cmd = $alias;
     }
     if ($cmd[0] === "/") {
         $cmd = substr($cmd, 1);
     }
     switch ($cmd) {
         case "paste":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $this->W_paste($session["clipboard"], $issuer->entity, $output);
             break;
         case "copy":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $count = $this->countBlocks($session["selection"], $startX, $startY, $startZ);
             if ($count > $session["block-limit"] and $session["block-limit"] > 0) {
                 $output .= "Block limit of " . $session["block-limit"] . " exceeded, tried to copy {$count} block(s).\n";
                 break;
             }
             $blocks = $this->W_copy($session["selection"], $output);
             if (count($blocks) > 0) {
                 $offset = array($startX - $issuer->entity->x - 0.5, $startY - $issuer->entity->y, $startZ - $issuer->entity->z - 0.5);
                 $session["clipboard"] = array($offset, $blocks);
             }
             break;
         case "cut":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $count = $this->countBlocks($session["selection"], $startX, $startY, $startZ);
             if ($count > $session["block-limit"] and $session["block-limit"] > 0) {
                 $output .= "Block limit of " . $session["block-limit"] . " exceeded, tried to cut {$count} block(s).\n";
                 break;
             }
             $blocks = $this->W_cut($session["selection"], $output);
             if (count($blocks) > 0) {
                 $offset = array($startX - $issuer->entity->x - 0.5, $startY - $issuer->entity->y, $startZ - $issuer->entity->z - 0.5);
                 $session["clipboard"] = array($offset, $blocks);
             }
             break;
         case "toggleeditwand":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $session["wand-usage"] = $session["wand-usage"] == true ? false : true;
             $output .= "Wand Item is now " . ($session["wand-usage"] === true ? "enabled" : "disabled") . ".\n";
             break;
         case "wand":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             if ($issuer->hasItem($this->config->get("wand-item"))) {
                 $output .= "You already have the wand item.\n";
                 break;
             } elseif ($issuer->gamemode === CREATIVE) {
                 $output .= "You are on creative mode.\n";
             } else {
                 $this->api->entity->drop(new Position($issuer->entity->x - 0.5, $issuer->entity->y, $issuer->entity->z - 0.5, $issuer->entity->level), BlockAPI::getItem($this->config->get("wand-item")));
             }
             $output .= "Break a block to set the #1 position, place for the #1.\n";
             break;
         case "desel":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $session["selection"] = array(false, false);
             $output = "Selection cleared.\n";
             break;
         case "limit":
             if (!isset($params[0]) or trim($params[0]) === "") {
                 $output .= "Usage: //limit <limit>\n";
                 break;
             }
             $limit = intval($params[0]);
             if ($limit < 0) {
                 $limit = -1;
             }
             if ($this->config->get("block-limit") > 0) {
                 $limit = $limit === -1 ? $this->config->get("block-limit") : min($this->config->get("block-limit"), $limit);
             }
             $this->session($issuer)["block-limit"] = $limit;
             $output .= "Block limit set to " . ($limit === -1 ? "infinite" : $limit) . " block(s).\n";
             break;
         case "pos1":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $this->setPosition1($this->session($issuer), new Position($issuer->entity->x - 0.5, $issuer->entity->y, $issuer->entity->z - 0.5, $issuer->entity->level), $output);
             break;
         case "pos2":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $this->setPosition2($this->session($issuer), new Position($issuer->entity->x - 0.5, $issuer->entity->y, $issuer->entity->z - 0.5, $issuer->entity->level), $output);
             break;
         case "hsphere":
             $filled = false;
         case "sphere":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             if (!isset($filled)) {
                 $filled = true;
             }
             if (!isset($params[1]) or $params[1] == "") {
                 $output .= "Usage: //{$cmd} <block> <radius>.\n";
                 break;
             }
             $radius = abs(floatval($params[1]));
             $session =& $this->session($issuer);
             $items = BlockAPI::fromString($params[0], true);
             foreach ($items as $item) {
                 if ($item->getID() > 0xff) {
                     $output .= "Incorrect block.\n";
                     return $output;
                 }
             }
             $this->W_sphere(new Position($issuer->entity->x - 0.5, $issuer->entity->y, $issuer->entity->z - 0.5, $issuer->entity->level), $items, $radius, $radius, $radius, $filled, $output);
             break;
         case "set":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $count = $this->countBlocks($session["selection"]);
             if ($count > $session["block-limit"] and $session["block-limit"] > 0) {
                 $output .= "Block limit of " . $session["block-limit"] . " exceeded, tried to change {$count} block(s).\n";
                 break;
             }
             $items = BlockAPI::fromString($params[0], true);
             foreach ($items as $item) {
                 if ($item->getID() > 0xff) {
                     $output .= "Incorrect block.\n";
                     return $output;
                 }
             }
             $this->W_set($session["selection"], $items, $output);
             break;
         case "replace":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $count = $this->countBlocks($session["selection"]);
             if ($count > $session["block-limit"] and $session["block-limit"] > 0) {
                 $output .= "Block limit of " . $session["block-limit"] . " exceeded, tried to change {$count} block(s).\n";
                 break;
             }
             $item1 = BlockAPI::fromString($params[0]);
             if ($item1->getID() > 0xff) {
                 $output .= "Incorrect target block.\n";
                 break;
             }
             $items2 = BlockAPI::fromString($params[1], true);
             foreach ($items2 as $item) {
                 if ($item->getID() > 0xff) {
                     $output .= "Incorrect replacement block.\n";
                     return $output;
                 }
             }
             $this->W_replace($session["selection"], $item1, $items2, $output);
             break;
         default:
         case "help":
             $output .= "Commands: //cut, //copy, //paste, //sphere, //hsphere, //desel, //limit, //pos1, //pos2, //set, //replace, //help, //wand, /toggleeditwand\n";
             break;
     }
     return $output;
 }
示例#14
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);
 }
示例#15
0
 public function getSlot($s)
 {
     $i = $this->getSlotIndex($s);
     if ($i === false or $i < 0) {
         return BlockAPI::getItem(AIR, 0, 0);
     } else {
         return BlockAPI::getItem($this->data["Items"][$i]["id"], $this->data["Items"][$i]["Damage"], $this->data["Items"][$i]["Count"]);
     }
 }
示例#16
0
 public function playerBlockAction(Player $player, Vector3 $vector, $face, $fx, $fy, $fz)
 {
     if ($face < 0 or $face > 5) {
         return false;
     }
     $target = $player->level->getBlock($vector);
     $block = $target->getSide($face);
     $item = $player->getSlot($player->slot);
     if ($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true) {
         //If no block exists or not allowed in CREATIVE
         if ($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true) {
             $this->cancelAction($target, $player);
             return $this->cancelAction($block, $player);
         }
     }
     if ($this->server->api->dhandle("player.block.touch", array("type" => "place", "player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false) {
         if ($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true) {
             return $this->cancelAction($block, $player);
         }
     }
     $this->blockUpdate($target, BLOCK_UPDATE_TOUCH);
     if ($target->isActivable === true) {
         if ($this->server->api->dhandle("player.block.activate", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== false and $target->onActivate($item, $player) === true) {
             return false;
         }
     }
     if (($player->gamemode & 0x2) === 0x2) {
         //Adventure mode!!
         if ($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true) {
             return $this->cancelAction($block, $player, false);
         }
     }
     if ($block->y > 127 or $block->y < 0) {
         return false;
     }
     if ($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true) {
         if ($item->count <= 0) {
             $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
         }
         return false;
     }
     if ($item->isPlaceable()) {
         $hand = $item->getBlock();
         $hand->position($block);
     } elseif ($block->getID() === FIRE) {
         $player->level->setBlock($block, new AirBlock(), true, false, true);
         return false;
     } else {
         return $this->cancelAction($block, $player, false);
     }
     if (!($block->isReplaceable === true or $hand->getID() === SLAB and $block->getID() === SLAB)) {
         return $this->cancelAction($block, $player, false);
     }
     if ($target->isReplaceable === true) {
         $block = $target;
         $hand->position($block);
         //$face = -1;
     }
     if ($hand->isSolid === true and $player->entity->inBlock($block)) {
         return $this->cancelAction($block, $player, false);
         //Entity in block
     }
     if ($this->server->api->dhandle("player.block.place", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false) {
         return $this->cancelAction($block, $player);
     } elseif ($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false) {
         return $this->cancelAction($block, $player, false);
     }
     if ($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN) {
         $t = $this->server->api->tile->addSign($player->level, $block->x, $block->y, $block->z);
         $t->data["creator"] = $player->username;
     }
     if (($player->gamemode & 0x1) === 0x0) {
         --$item->count;
         if ($item->count <= 0) {
             $player->setSlot($player->slot, BlockAPI::getItem(AIR, 0, 0), false);
         }
     }
     return false;
 }