mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 08:49:42 +00:00
Fixed wrong paths
This commit is contained in:
parent
05a42712bf
commit
dd17652aca
134
src/pocketmine/Achievement.php
Normal file
134
src/pocketmine/Achievement.php
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine;
|
||||||
|
use pocketmine\utils\TextFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the achievement list and a bit more
|
||||||
|
*/
|
||||||
|
abstract class Achievement{
|
||||||
|
/**
|
||||||
|
* @var array[]
|
||||||
|
*/
|
||||||
|
public static $list = array(
|
||||||
|
/*"openInventory" => array(
|
||||||
|
"name" => "Taking Inventory",
|
||||||
|
"requires" => array(),
|
||||||
|
),*/
|
||||||
|
"mineWood" => array(
|
||||||
|
"name" => "Getting Wood",
|
||||||
|
"requires" => array( //"openInventory",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"buildWorkBench" => array(
|
||||||
|
"name" => "Benchmarking",
|
||||||
|
"requires" => array(
|
||||||
|
"mineWood",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"buildPickaxe" => array(
|
||||||
|
"name" => "Time to Mine!",
|
||||||
|
"requires" => array(
|
||||||
|
"buildWorkBench",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"buildFurnace" => array(
|
||||||
|
"name" => "Hot Topic",
|
||||||
|
"requires" => array(
|
||||||
|
"buildPickaxe",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"acquireIron" => array(
|
||||||
|
"name" => "Acquire hardware",
|
||||||
|
"requires" => array(
|
||||||
|
"buildFurnace",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"buildHoe" => array(
|
||||||
|
"name" => "Time to Farm!",
|
||||||
|
"requires" => array(
|
||||||
|
"buildWorkBench",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"makeBread" => array(
|
||||||
|
"name" => "Bake Bread",
|
||||||
|
"requires" => array(
|
||||||
|
"buildHoe",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"bakeCake" => array(
|
||||||
|
"name" => "The Lie",
|
||||||
|
"requires" => array(
|
||||||
|
"buildHoe",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"buildBetterPickaxe" => array(
|
||||||
|
"name" => "Getting an Upgrade",
|
||||||
|
"requires" => array(
|
||||||
|
"buildPickaxe",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"buildSword" => array(
|
||||||
|
"name" => "Time to Strike!",
|
||||||
|
"requires" => array(
|
||||||
|
"buildWorkBench",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"diamonds" => array(
|
||||||
|
"name" => "DIAMONDS!",
|
||||||
|
"requires" => array(
|
||||||
|
"acquireIron",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
public static function broadcast(Player $player, $achievementId){
|
||||||
|
if(isset(Achievement::$list[$achievementId])){
|
||||||
|
if(Server::getInstance()->getConfigString("announce-player-achievements", true) === true){
|
||||||
|
Server::getInstance()->broadcastMessage($player->getDisplayName() . " has just earned the achievement " . TextFormat::GREEN . Achievement::$list[$achievementId]["name"]);
|
||||||
|
}else{
|
||||||
|
$player->sendMessage("You have just earned the achievement " . TextFormat::GREEN . Achievement::$list[$achievementId]["name"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add($achievementId, $achievementName, array $requires = array()){
|
||||||
|
if(!isset(Achievement::$list[$achievementId])){
|
||||||
|
Achievement::$list[$achievementId] = array(
|
||||||
|
"name" => $achievementName,
|
||||||
|
"requires" => $requires,
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
411
src/pocketmine/BanAPI.php
Normal file
411
src/pocketmine/BanAPI.php
Normal file
@ -0,0 +1,411 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\math\Vector2;
|
||||||
|
use pocketmine\utils\Config;
|
||||||
|
|
||||||
|
class BanAPI{
|
||||||
|
private $server;
|
||||||
|
/*
|
||||||
|
* I would use PHPDoc Template here but PHPStorm does not recognise it. - @sekjun9878
|
||||||
|
*/
|
||||||
|
/** @var Config */
|
||||||
|
private $whitelist;
|
||||||
|
/** @var Config */
|
||||||
|
private $banned;
|
||||||
|
/** @var Config */
|
||||||
|
private $ops;
|
||||||
|
/** @var Config */
|
||||||
|
private $bannedIPs;
|
||||||
|
private $cmdWhitelist = array(); //Command WhiteList
|
||||||
|
function __construct(){
|
||||||
|
$this->server = Server::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
$this->whitelist = new Config(\pocketmine\DATA . "white-list.txt", Config::ENUM); //Open whitelist list file
|
||||||
|
$this->bannedIPs = new Config(\pocketmine\DATA . "banned-ips.txt", Config::ENUM); //Open Banned IPs list file
|
||||||
|
$this->banned = new Config(\pocketmine\DATA . "banned.txt", Config::ENUM); //Open Banned Usernames list file
|
||||||
|
$this->ops = new Config(\pocketmine\DATA . "ops.txt", Config::ENUM); //Open list of OPs
|
||||||
|
$this->server->api->console->register("banip", "<add|remove|list|reload> [IP|player]", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("ban", "<add|remove|list|reload> [username]", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("kick", "<player> [reason ...]", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("whitelist", "<on|off|list|add|remove|reload> [username]", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("op", "<player>", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("deop", "<player>", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("sudo", "<player> <command>", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->alias("ban-ip", "banip add");
|
||||||
|
$this->server->api->console->alias("banlist", "ban list");
|
||||||
|
$this->server->api->console->alias("pardon", "ban remove");
|
||||||
|
$this->server->api->console->alias("pardon-ip", "banip remove");
|
||||||
|
$this->server->addHandler("console.command", array($this, "permissionsCheck"), 1); //Event handler when commands are issued. Used to check permissions of commands that go through the server.
|
||||||
|
$this->server->addHandler("player.block.break", array($this, "permissionsCheck"), 1); //Event handler for blocks
|
||||||
|
$this->server->addHandler("player.block.place", array($this, "permissionsCheck"), 1); //Event handler for blocks
|
||||||
|
$this->server->addHandler("player.flying", array($this, "permissionsCheck"), 1); //Flying Event
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $cmd Command to Whitelist
|
||||||
|
*/
|
||||||
|
public function cmdWhitelist($cmd){ //Whitelists a CMD so everyone can issue it - Even non OPs.
|
||||||
|
$this->cmdWhitelist[strtolower(trim($cmd))] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isOp($username){ //Is a player op?
|
||||||
|
$username = strtolower($username);
|
||||||
|
if($this->server->api->dhandle("op.check", $username) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->ops->exists($username)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $data
|
||||||
|
* @param string $event
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function permissionsCheck($data, $event){
|
||||||
|
switch($event){
|
||||||
|
case "player.flying": //OPs can fly around the server.
|
||||||
|
if($this->isOp($data->getName())){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "player.block.break":
|
||||||
|
case "player.block.place": //Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
|
||||||
|
if(!$this->isOp($data["player"]->getName())){
|
||||||
|
$t = new Vector2($data["target"]->x, $data["target"]->z);
|
||||||
|
$s = new Vector2(Level::getDefault()->getSpawn()->x, Level::getDefault()->getSpawn()->z);
|
||||||
|
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
case "console.command": //Checks if a command is allowed with the current user permissions.
|
||||||
|
if(isset($this->cmdWhitelist[$data["cmd"]])){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($data["issuer"] instanceof Player){
|
||||||
|
if($this->server->api->handle("console.check", $data) === true or $this->isOp($data["issuer"]->getName())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}elseif($data["issuer"] === "console" or $data["issuer"] === "rcon"){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $cmd
|
||||||
|
* @param array $params
|
||||||
|
* @param string $issuer
|
||||||
|
* @param string $alias
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||||
|
$output = "";
|
||||||
|
switch($cmd){
|
||||||
|
case "sudo":
|
||||||
|
$target = strtolower(array_shift($params));
|
||||||
|
$player = Player::get($target);
|
||||||
|
if(!($player instanceof Player)){
|
||||||
|
$output .= "Player not connected.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$this->server->api->console->run(implode(" ", $params), $player);
|
||||||
|
$output .= "Command ran as " . $player->getName() . ".\n";
|
||||||
|
break;
|
||||||
|
case "op":
|
||||||
|
$user = strtolower($params[0]);
|
||||||
|
if($user == null){
|
||||||
|
$output .= "Usage: /op <player>\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$player = Player::get($user);
|
||||||
|
if(!($player instanceof Player)){
|
||||||
|
$this->ops->set($user);
|
||||||
|
$this->ops->save();
|
||||||
|
$output .= $user . " is now op\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$this->ops->set(strtolower($player->getName()));
|
||||||
|
$this->ops->save();
|
||||||
|
$output .= $player->getName() . " is now op\n";
|
||||||
|
$player->sendMessage("You are now op.");
|
||||||
|
break;
|
||||||
|
case "deop":
|
||||||
|
$user = strtolower($params[0]);
|
||||||
|
$player = Player::get($user);
|
||||||
|
if(!($player instanceof Player)){
|
||||||
|
$this->ops->remove($user);
|
||||||
|
$this->ops->save();
|
||||||
|
$output .= $user . " is no longer op\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$this->ops->remove(strtolower($player->getName()));
|
||||||
|
$this->ops->save();
|
||||||
|
$output .= $player->getName() . " is no longer op\n";
|
||||||
|
$player->sendMessage("You are no longer op.");
|
||||||
|
break;
|
||||||
|
case "kick":
|
||||||
|
if(!isset($params[0])){
|
||||||
|
$output .= "Usage: /kick <player> [reason ...]\n";
|
||||||
|
}else{
|
||||||
|
$name = strtolower(array_shift($params));
|
||||||
|
$player = Player::get($name);
|
||||||
|
if($player === false){
|
||||||
|
$output .= "Player \"" . $name . "\" does not exist\n";
|
||||||
|
}else{
|
||||||
|
$reason = implode(" ", $params);
|
||||||
|
$reason = $reason == "" ? "No reason" : $reason;
|
||||||
|
|
||||||
|
$this->server->schedule(60, array($player, "close"), "You have been kicked: " . $reason); //Forces a kick
|
||||||
|
$player->blocked = true;
|
||||||
|
if($issuer instanceof Player){
|
||||||
|
Player::broadcastMessage($player->getName() . " has been kicked by " . $issuer->getName() . ": $reason\n");
|
||||||
|
}else{
|
||||||
|
Player::broadcastMessage($player->getName() . " has been kicked: $reason\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "whitelist":
|
||||||
|
$p = strtolower(array_shift($params));
|
||||||
|
switch($p){
|
||||||
|
case "remove":
|
||||||
|
$user = strtolower($params[0]);
|
||||||
|
$this->whitelist->remove($user);
|
||||||
|
$this->whitelist->save();
|
||||||
|
$output .= "Player \"$user\" removed from white-list\n";
|
||||||
|
break;
|
||||||
|
case "add":
|
||||||
|
$user = strtolower($params[0]);
|
||||||
|
$this->whitelist->set($user);
|
||||||
|
$this->whitelist->save();
|
||||||
|
$output .= "Player \"$user\" added to white-list\n";
|
||||||
|
break;
|
||||||
|
case "reload":
|
||||||
|
$this->whitelist = new Config(\pocketmine\DATA . "white-list.txt", Config::ENUM);
|
||||||
|
break;
|
||||||
|
case "list":
|
||||||
|
$output .= "White-list: " . implode(", ", $this->whitelist->getAll(true)) . "\n";
|
||||||
|
break;
|
||||||
|
case "on":
|
||||||
|
case "true":
|
||||||
|
case "1":
|
||||||
|
$output .= "White-list turned on\n";
|
||||||
|
$this->server->api->setProperty("white-list", true);
|
||||||
|
break;
|
||||||
|
case "off":
|
||||||
|
case "false":
|
||||||
|
case "0":
|
||||||
|
$output .= "White-list turned off\n";
|
||||||
|
$this->server->api->setProperty("white-list", false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$output .= "Usage: /whitelist <on|off|list|add|remove|reload> [username]\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "banip":
|
||||||
|
$p = strtolower(array_shift($params));
|
||||||
|
switch($p){
|
||||||
|
case "pardon":
|
||||||
|
case "remove":
|
||||||
|
$ip = strtolower($params[0]);
|
||||||
|
$this->bannedIPs->remove($ip);
|
||||||
|
$this->bannedIPs->save();
|
||||||
|
$output .= "IP \"$ip\" removed from ban list\n";
|
||||||
|
break;
|
||||||
|
case "add":
|
||||||
|
case "ban":
|
||||||
|
$ip = strtolower($params[0]);
|
||||||
|
$player = Player::get($ip);
|
||||||
|
if($player instanceof Player){
|
||||||
|
$ip = $player->getIP();
|
||||||
|
$player->kick("You are banned");
|
||||||
|
}
|
||||||
|
$this->bannedIPs->set($ip);
|
||||||
|
$this->bannedIPs->save();
|
||||||
|
$output .= "IP \"$ip\" added to ban list\n";
|
||||||
|
break;
|
||||||
|
case "reload":
|
||||||
|
$this->bannedIPs = new Config(\pocketmine\DATA . "banned-ips.txt", Config::ENUM);
|
||||||
|
break;
|
||||||
|
case "list":
|
||||||
|
$output .= "IP ban list: " . implode(", ", $this->bannedIPs->getAll(true)) . "\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$output .= "Usage: /banip <add|remove|list|reload> [IP|player]\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "ban":
|
||||||
|
$p = strtolower(array_shift($params));
|
||||||
|
switch($p){
|
||||||
|
case "pardon":
|
||||||
|
case "remove":
|
||||||
|
$user = strtolower($params[0]);
|
||||||
|
$this->banned->remove($user);
|
||||||
|
$this->banned->save();
|
||||||
|
$output .= "Player \"$user\" removed from ban list\n";
|
||||||
|
break;
|
||||||
|
case "add":
|
||||||
|
case "ban":
|
||||||
|
$user = strtolower($params[0]);
|
||||||
|
$this->banned->set($user);
|
||||||
|
$this->banned->save();
|
||||||
|
$player = Player::get($user);
|
||||||
|
if($player !== false){
|
||||||
|
$player->kick("You are banned");
|
||||||
|
}
|
||||||
|
if($issuer instanceof Player){
|
||||||
|
Player::broadcastMessage($user . " has been banned by " . $issuer->getName() . "\n");
|
||||||
|
}else{
|
||||||
|
Player::broadcastMessage($user . " has been banned\n");
|
||||||
|
}
|
||||||
|
$this->kick($user, "Banned");
|
||||||
|
$output .= "Player \"$user\" added to ban list\n";
|
||||||
|
break;
|
||||||
|
case "reload":
|
||||||
|
$this->banned = new Config(\pocketmine\DATA . "banned.txt", Config::ENUM);
|
||||||
|
break;
|
||||||
|
case "list":
|
||||||
|
$output .= "Ban list: " . implode(", ", $this->banned->getAll(true)) . "\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$output .= "Usage: /ban <add|remove|list|reload> [username]\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
*/
|
||||||
|
public function ban($username){
|
||||||
|
$this->commandHandler("ban", array("add", $username), "console", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
*/
|
||||||
|
public function pardon($username){
|
||||||
|
$this->commandHandler("ban", array("pardon", $username), "console", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $ip
|
||||||
|
*/
|
||||||
|
public function banIP($ip){
|
||||||
|
$this->commandHandler("banip", array("add", $ip), "console", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $ip
|
||||||
|
*/
|
||||||
|
public function pardonIP($ip){
|
||||||
|
$this->commandHandler("banip", array("pardon", $ip), "console", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
* @param string $reason
|
||||||
|
*/
|
||||||
|
public function kick($username, $reason = "No Reason"){
|
||||||
|
$this->commandHandler("kick", array($username, $reason), "console", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reload(){
|
||||||
|
$this->commandHandler("ban", array("reload"), "console", "");
|
||||||
|
$this->commandHandler("banip", array("reload"), "console", "");
|
||||||
|
$this->commandHandler("whitelist", array("reload"), "console", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $ip
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isIPBanned($ip){
|
||||||
|
if($this->server->api->dhandle("api.ban.ip.check", $ip) === false){
|
||||||
|
return true;
|
||||||
|
}elseif($this->bannedIPs->exists($ip, true)){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isBanned($username){
|
||||||
|
$username = strtolower($username);
|
||||||
|
if($this->server->api->dhandle("api.ban.check", $username) === false){
|
||||||
|
return true;
|
||||||
|
}elseif($this->banned->exists($username, true)){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $username
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function inWhitelist($username){
|
||||||
|
$username = strtolower($username);
|
||||||
|
if($this->isOp($username)){
|
||||||
|
return true;
|
||||||
|
}elseif($this->server->api->dhandle("api.ban.whitelist.check", $username) === false){
|
||||||
|
return true;
|
||||||
|
}elseif($this->whitelist->exists($username, true)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
352
src/pocketmine/BlockAPI.php
Normal file
352
src/pocketmine/BlockAPI.php
Normal file
@ -0,0 +1,352 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use pocketmine\Block;
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\level\Position;
|
||||||
|
|
||||||
|
class BlockAPI{
|
||||||
|
private $server;
|
||||||
|
private $scheduledUpdates = array();
|
||||||
|
public static $creative = array(
|
||||||
|
//Building
|
||||||
|
[Item::STONE, 0],
|
||||||
|
[Item::COBBLESTONE, 0],
|
||||||
|
[Item::STONE_BRICKS, 0],
|
||||||
|
[Item::STONE_BRICKS, 1],
|
||||||
|
[Item::STONE_BRICKS, 2],
|
||||||
|
[Item::MOSS_STONE, 0],
|
||||||
|
[Item::WOODEN_PLANKS, 0],
|
||||||
|
[Item::WOODEN_PLANKS, 1],
|
||||||
|
[Item::WOODEN_PLANKS, 2],
|
||||||
|
[Item::WOODEN_PLANKS, 3],
|
||||||
|
[Item::BRICKS, 0],
|
||||||
|
|
||||||
|
[Item::DIRT, 0],
|
||||||
|
[Item::GRASS, 0],
|
||||||
|
[Item::CLAY_BLOCK, 0],
|
||||||
|
[Item::SANDSTONE, 0],
|
||||||
|
[Item::SANDSTONE, 1],
|
||||||
|
[Item::SANDSTONE, 2],
|
||||||
|
[Item::SAND, 0],
|
||||||
|
[Item::GRAVEL, 0],
|
||||||
|
[Item::TRUNK, 0],
|
||||||
|
[Item::TRUNK, 1],
|
||||||
|
[Item::TRUNK, 2],
|
||||||
|
[Item::TRUNK, 3],
|
||||||
|
[Item::NETHER_BRICKS, 0],
|
||||||
|
[Item::NETHERRACK, 0],
|
||||||
|
[Item::BEDROCK, 0],
|
||||||
|
[Item::COBBLESTONE_STAIRS, 0],
|
||||||
|
[Item::OAK_WOODEN_STAIRS, 0],
|
||||||
|
[Item::SPRUCE_WOODEN_STAIRS, 0],
|
||||||
|
[Item::BIRCH_WOODEN_STAIRS, 0],
|
||||||
|
[Item::JUNGLE_WOODEN_STAIRS, 0],
|
||||||
|
[Item::BRICK_STAIRS, 0],
|
||||||
|
[Item::SANDSTONE_STAIRS, 0],
|
||||||
|
[Item::STONE_BRICK_STAIRS, 0],
|
||||||
|
[Item::NETHER_BRICKS_STAIRS, 0],
|
||||||
|
[Item::QUARTZ_STAIRS, 0],
|
||||||
|
[Item::SLAB, 0],
|
||||||
|
[Item::SLAB, 1],
|
||||||
|
[Item::WOODEN_SLAB, 0],
|
||||||
|
[Item::WOODEN_SLAB, 1],
|
||||||
|
[Item::WOODEN_SLAB, 2],
|
||||||
|
[Item::WOODEN_SLAB, 3],
|
||||||
|
[Item::SLAB, 3],
|
||||||
|
[Item::SLAB, 4],
|
||||||
|
[Item::SLAB, 5],
|
||||||
|
[Item::SLAB, 6],
|
||||||
|
[Item::QUARTZ_BLOCK, 0],
|
||||||
|
[Item::QUARTZ_BLOCK, 1],
|
||||||
|
[Item::QUARTZ_BLOCK, 2],
|
||||||
|
[Item::COAL_ORE, 0],
|
||||||
|
[Item::IRON_ORE, 0],
|
||||||
|
[Item::GOLD_ORE, 0],
|
||||||
|
[Item::DIAMOND_ORE, 0],
|
||||||
|
[Item::LAPIS_ORE, 0],
|
||||||
|
[Item::REDSTONE_ORE, 0],
|
||||||
|
[Item::OBSIDIAN, 0],
|
||||||
|
[Item::ICE, 0],
|
||||||
|
[Item::SNOW_BLOCK, 0],
|
||||||
|
|
||||||
|
//Decoration
|
||||||
|
[Item::COBBLESTONE_WALL, 0],
|
||||||
|
[Item::COBBLESTONE_WALL, 1],
|
||||||
|
[Item::GOLD_BLOCK, 0],
|
||||||
|
[Item::IRON_BLOCK, 0],
|
||||||
|
[Item::DIAMOND_BLOCK, 0],
|
||||||
|
[Item::LAPIS_BLOCK, 0],
|
||||||
|
[Item::COAL_BLOCK, 0],
|
||||||
|
[Item::SNOW_LAYER, 0],
|
||||||
|
[Item::GLASS, 0],
|
||||||
|
[Item::GLOWSTONE_BLOCK, 0],
|
||||||
|
[Item::NETHER_REACTOR, 0],
|
||||||
|
[Item::WOOL, 0],
|
||||||
|
[Item::WOOL, 7],
|
||||||
|
[Item::WOOL, 6],
|
||||||
|
[Item::WOOL, 5],
|
||||||
|
[Item::WOOL, 4],
|
||||||
|
[Item::WOOL, 3],
|
||||||
|
[Item::WOOL, 2],
|
||||||
|
[Item::WOOL, 1],
|
||||||
|
[Item::WOOL, 15],
|
||||||
|
[Item::WOOL, 14],
|
||||||
|
[Item::WOOL, 13],
|
||||||
|
[Item::WOOL, 12],
|
||||||
|
[Item::WOOL, 11],
|
||||||
|
[Item::WOOL, 10],
|
||||||
|
[Item::WOOL, 9],
|
||||||
|
[Item::WOOL, 8],
|
||||||
|
[Item::LADDER, 0],
|
||||||
|
[Item::SPONGE, 0],
|
||||||
|
[Item::GLASS_PANE, 0],
|
||||||
|
[Item::WOODEN_DOOR, 0],
|
||||||
|
[Item::TRAPDOOR, 0],
|
||||||
|
[Item::FENCE, 0],
|
||||||
|
[Item::FENCE_GATE, 0],
|
||||||
|
[Item::IRON_BARS, 0],
|
||||||
|
[Item::BED, 0],
|
||||||
|
[Item::BOOKSHELF, 0],
|
||||||
|
[Item::PAINTING, 0],
|
||||||
|
[Item::WORKBENCH, 0],
|
||||||
|
[Item::STONECUTTER, 0],
|
||||||
|
[Item::CHEST, 0],
|
||||||
|
[Item::FURNACE, 0],
|
||||||
|
[Item::DANDELION, 0],
|
||||||
|
[Item::CYAN_FLOWER, 0],
|
||||||
|
[Item::BROWN_MUSHROOM, 0],
|
||||||
|
[Item::RED_MUSHROOM, 0],
|
||||||
|
[Item::CACTUS, 0],
|
||||||
|
[Item::MELON_BLOCK, 0],
|
||||||
|
[Item::PUMPKIN, 0],
|
||||||
|
[Item::LIT_PUMPKIN, 0],
|
||||||
|
[Item::COBWEB, 0],
|
||||||
|
[Item::HAY_BALE, 0],
|
||||||
|
[Item::TALL_GRASS, 1],
|
||||||
|
[Item::TALL_GRASS, 2],
|
||||||
|
[Item::DEAD_BUSH, 0],
|
||||||
|
[Item::SAPLING, 0],
|
||||||
|
[Item::SAPLING, 1],
|
||||||
|
[Item::SAPLING, 2],
|
||||||
|
[Item::SAPLING, 3],
|
||||||
|
[Item::LEAVES, 0],
|
||||||
|
[Item::LEAVES, 1],
|
||||||
|
[Item::LEAVES, 2],
|
||||||
|
[Item::LEAVES, 3],
|
||||||
|
[Item::CAKE, 0],
|
||||||
|
[Item::SIGN, 0],
|
||||||
|
[Item::CARPET, 0],
|
||||||
|
[Item::CARPET, 7],
|
||||||
|
[Item::CARPET, 6],
|
||||||
|
[Item::CARPET, 5],
|
||||||
|
[Item::CARPET, 4],
|
||||||
|
[Item::CARPET, 3],
|
||||||
|
[Item::CARPET, 2],
|
||||||
|
[Item::CARPET, 1],
|
||||||
|
[Item::CARPET, 15],
|
||||||
|
[Item::CARPET, 14],
|
||||||
|
[Item::CARPET, 13],
|
||||||
|
[Item::CARPET, 12],
|
||||||
|
[Item::CARPET, 11],
|
||||||
|
[Item::CARPET, 10],
|
||||||
|
[Item::CARPET, 9],
|
||||||
|
[Item::CARPET, 8],
|
||||||
|
|
||||||
|
//Tools
|
||||||
|
//[Item::RAILS, 0],
|
||||||
|
//[Item::POWERED_RAILS, 0],
|
||||||
|
[Item::TORCH, 0],
|
||||||
|
[Item::BUCKET, 0],
|
||||||
|
[Item::BUCKET, 8],
|
||||||
|
[Item::BUCKET, 10],
|
||||||
|
[Item::TNT, 0],
|
||||||
|
[Item::IRON_HOE, 0],
|
||||||
|
[Item::IRON_SWORD, 0],
|
||||||
|
[Item::BOW, 0],
|
||||||
|
[Item::SHEARS, 0],
|
||||||
|
[Item::FLINT_AND_STEEL, 0],
|
||||||
|
[Item::CLOCK, 0],
|
||||||
|
[Item::COMPASS, 0],
|
||||||
|
[Item::MINECART, 0],
|
||||||
|
[Item::SPAWN_EGG, 10], //Chicken
|
||||||
|
[Item::SPAWN_EGG, 11], //Cow
|
||||||
|
[Item::SPAWN_EGG, 12], //Pig
|
||||||
|
[Item::SPAWN_EGG, 13], //Sheep
|
||||||
|
//TODO: Replace with Entity constants
|
||||||
|
|
||||||
|
|
||||||
|
//Seeds
|
||||||
|
[Item::SUGARCANE, 0],
|
||||||
|
[Item::WHEAT, 0],
|
||||||
|
[Item::SEEDS, 0],
|
||||||
|
[Item::MELON_SEEDS, 0],
|
||||||
|
[Item::PUMPKIN_SEEDS, 0],
|
||||||
|
[Item::CARROT, 0],
|
||||||
|
[Item::POTATO, 0],
|
||||||
|
[Item::BEETROOT_SEEDS, 0],
|
||||||
|
[Item::EGG, 0],
|
||||||
|
[Item::DYE, 0],
|
||||||
|
[Item::DYE, 7],
|
||||||
|
[Item::DYE, 6],
|
||||||
|
[Item::DYE, 5],
|
||||||
|
[Item::DYE, 4],
|
||||||
|
[Item::DYE, 3],
|
||||||
|
[Item::DYE, 2],
|
||||||
|
[Item::DYE, 1],
|
||||||
|
[Item::DYE, 15],
|
||||||
|
[Item::DYE, 14],
|
||||||
|
[Item::DYE, 13],
|
||||||
|
[Item::DYE, 12],
|
||||||
|
[Item::DYE, 11],
|
||||||
|
[Item::DYE, 10],
|
||||||
|
[Item::DYE, 9],
|
||||||
|
[Item::DYE, 8],
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
function __construct(){
|
||||||
|
$this->server = Server::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
$this->server->schedule(1, array($this, "blockUpdateTick"), array(), true);
|
||||||
|
$this->server->api->console->register("give", "<player> <item[:damage]> [amount]", array($this, "commandHandler"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||||
|
$output = "";
|
||||||
|
switch($cmd){
|
||||||
|
case "give":
|
||||||
|
if(!isset($params[0]) or !isset($params[1])){
|
||||||
|
$output .= "Usage: /give <player> <item[:damage]> [amount]\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$player = Player::get($params[0]);
|
||||||
|
$item = Item::fromString($params[1]);
|
||||||
|
|
||||||
|
if(!isset($params[2])){
|
||||||
|
$item->setCount($item->getMaxStackSize());
|
||||||
|
}else{
|
||||||
|
$item->setCount((int) $params[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($player instanceof Player){
|
||||||
|
if(($player->gamemode & 0x01) === 0x01){
|
||||||
|
$output .= "Player is in creative mode.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if($item->getID() == 0){
|
||||||
|
$output .= "You cannot give an air block to a player.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$player->addItem(clone $item);
|
||||||
|
$output .= "Giving " . $item->getCount() . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $player->getName() . "\n";
|
||||||
|
}else{
|
||||||
|
$output .= "Unknown player.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blockUpdateAround(Position $pos, $type = Level::BLOCK_UPDATE_NORMAL, $delay = false){
|
||||||
|
if($delay !== false){
|
||||||
|
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
|
||||||
|
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
|
||||||
|
$this->scheduleBlockUpdate($pos->getSide(2), $delay, $type);
|
||||||
|
$this->scheduleBlockUpdate($pos->getSide(3), $delay, $type);
|
||||||
|
$this->scheduleBlockUpdate($pos->getSide(4), $delay, $type);
|
||||||
|
$this->scheduleBlockUpdate($pos->getSide(5), $delay, $type);
|
||||||
|
}else{
|
||||||
|
$this->blockUpdate($pos->getSide(0), $type);
|
||||||
|
$this->blockUpdate($pos->getSide(1), $type);
|
||||||
|
$this->blockUpdate($pos->getSide(2), $type);
|
||||||
|
$this->blockUpdate($pos->getSide(3), $type);
|
||||||
|
$this->blockUpdate($pos->getSide(4), $type);
|
||||||
|
$this->blockUpdate($pos->getSide(5), $type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blockUpdate(Position $pos, $type = Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if(!($pos instanceof block\Block)){
|
||||||
|
$block = $pos->level->getBlock($pos);
|
||||||
|
}else{
|
||||||
|
$pos = new Position($pos->x, $pos->y, $pos->z, $pos->level);
|
||||||
|
$block = $pos->level->getBlock($pos);
|
||||||
|
}
|
||||||
|
if($block === false){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$level = $block->onUpdate($type);
|
||||||
|
if($level === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
$this->blockUpdateAround($block, $level);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scheduleBlockUpdate(Position $pos, $delay, $type = Level::BLOCK_UPDATE_SCHEDULED){
|
||||||
|
$type = (int) $type;
|
||||||
|
if($delay < 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$index = $pos->x . "." . $pos->y . "." . $pos->z . "." . $pos->level->getName() . "." . $type;
|
||||||
|
$delay = microtime(true) + $delay * 0.05;
|
||||||
|
if(!isset($this->scheduledUpdates[$index])){
|
||||||
|
$this->scheduledUpdates[$index] = $pos;
|
||||||
|
$this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES (" . $pos->x . ", " . $pos->y . ", " . $pos->z . ", '" . $pos->level->getName() . "', " . $type . ", " . $delay . ");");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blockUpdateTick(){
|
||||||
|
$time = microtime(true);
|
||||||
|
if(count($this->scheduledUpdates) > 0){
|
||||||
|
$update = $this->server->query("SELECT x,y,z,level,type FROM blockUpdates WHERE delay <= " . $time . ";");
|
||||||
|
if($update instanceof \SQLite3Result){
|
||||||
|
$upp = array();
|
||||||
|
while(($up = $update->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
|
$index = $up["x"] . "." . $up["y"] . "." . $up["z"] . "." . $up["level"] . "." . $up["type"];
|
||||||
|
if(isset($this->scheduledUpdates[$index])){
|
||||||
|
$upp[] = array((int) $up["type"], $this->scheduledUpdates[$index]);
|
||||||
|
unset($this->scheduledUpdates[$index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->server->query("DELETE FROM blockUpdates WHERE delay <= " . $time . ";");
|
||||||
|
foreach($upp as $b){
|
||||||
|
$this->blockUpdate($b[1], $b[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
66
src/pocketmine/LevelAPI.php
Normal file
66
src/pocketmine/LevelAPI.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
|
||||||
|
class LevelAPI{
|
||||||
|
private $server;
|
||||||
|
|
||||||
|
public function __construct(){
|
||||||
|
$this->server = Server::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
$this->server->api->console->register("save-all", "", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("save-on", "", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("save-off", "", array($this, "commandHandler"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||||
|
$output = "";
|
||||||
|
switch($cmd){
|
||||||
|
case "save-all":
|
||||||
|
$save = $this->server->saveEnabled;
|
||||||
|
$this->server->saveEnabled = true;
|
||||||
|
Level::saveAll();
|
||||||
|
$this->server->saveEnabled = $save;
|
||||||
|
break;
|
||||||
|
case "save-on":
|
||||||
|
$this->server->saveEnabled = true;
|
||||||
|
break;
|
||||||
|
case "save-off":
|
||||||
|
$this->server->saveEnabled = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct(){
|
||||||
|
Level::saveAll();
|
||||||
|
foreach(Level::getAll() as $level){
|
||||||
|
$level->unload(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
2736
src/pocketmine/Player.php
Normal file
2736
src/pocketmine/Player.php
Normal file
File diff suppressed because it is too large
Load Diff
345
src/pocketmine/PlayerAPI.php
Normal file
345
src/pocketmine/PlayerAPI.php
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use pocketmine\entity\Entity;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\level\Position;
|
||||||
|
use pocketmine\math\Vector3 as Vector3;
|
||||||
|
|
||||||
|
class PlayerAPI{
|
||||||
|
private $server;
|
||||||
|
|
||||||
|
function __construct(){
|
||||||
|
$this->server = Server::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
$this->server->schedule(20 * 15, array($this, "handle"), 1, true, "server.regeneration");
|
||||||
|
$this->server->addHandler("player.death", array($this, "handle"), 1);
|
||||||
|
$this->server->api->console->register("list", "", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("kill", "<player>", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("gamemode", "<mode> [player]", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("tp", "[target player] <destination player | w:world> OR /tp [target player] <x> <y> <z>", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("spawnpoint", "[player | w:world] [x] [y] [z]", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("spawn", "", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("ping", "", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->alias("lag", "ping");
|
||||||
|
$this->server->api->console->alias("suicide", "kill");
|
||||||
|
$this->server->api->console->alias("tppos", "tp");
|
||||||
|
$this->server->api->ban->cmdWhitelist("list");
|
||||||
|
$this->server->api->ban->cmdWhitelist("ping");
|
||||||
|
$this->server->api->ban->cmdWhitelist("spawn");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle($data, $event){
|
||||||
|
switch($event){
|
||||||
|
case "server.regeneration":
|
||||||
|
/*if($this->server->difficulty === 0){
|
||||||
|
$result = $this->server->preparedSQL->selectPlayersToHeal->execute();
|
||||||
|
if($result !== false){
|
||||||
|
while(($player = $result->fetchArray()) !== false){
|
||||||
|
if(($player = Entity::get($player["EID"])) !== false){
|
||||||
|
if($player->getHealth() <= 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$player->setHealth(min(20, $player->getHealth() + $data), "regeneration");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
break;
|
||||||
|
case "player.death":
|
||||||
|
if(is_numeric($data["cause"])){
|
||||||
|
$e = Entity::get($data["cause"]);
|
||||||
|
if($e instanceof Entity){
|
||||||
|
switch($e->class){
|
||||||
|
case ENTITY_PLAYER:
|
||||||
|
$message = " was killed by " . $e->name;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$message = " was killed";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
switch($data["cause"]){
|
||||||
|
case "cactus":
|
||||||
|
$message = " was pricked to death";
|
||||||
|
break;
|
||||||
|
case "lava":
|
||||||
|
$message = " tried to swim in lava";
|
||||||
|
break;
|
||||||
|
case "fire":
|
||||||
|
$message = " went up in flames";
|
||||||
|
break;
|
||||||
|
case "burning":
|
||||||
|
$message = " burned to death";
|
||||||
|
break;
|
||||||
|
case "suffocation":
|
||||||
|
$message = " suffocated in a wall";
|
||||||
|
break;
|
||||||
|
case "water":
|
||||||
|
$message = " drowned";
|
||||||
|
break;
|
||||||
|
case "void":
|
||||||
|
$message = " fell out of the world";
|
||||||
|
break;
|
||||||
|
case "fall":
|
||||||
|
$message = " hit the ground too hard";
|
||||||
|
break;
|
||||||
|
case "explosion":
|
||||||
|
$message = " blew up";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$message = " died";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Player::broadcastMessage($data["player"]->getName() . $message);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||||
|
$output = "";
|
||||||
|
switch($cmd){
|
||||||
|
case "spawnpoint":
|
||||||
|
if(count($params) === 0){
|
||||||
|
$output .= "Usage: /$cmd [player | w:world] [x] [y] [z]\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!($issuer instanceof Player) and count($params) < 4){
|
||||||
|
$output .= "Please run this command in-game.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($params) === 1 or count($params) === 4){
|
||||||
|
$tg = array_shift($params);
|
||||||
|
if(count($params) === 3 and substr($tg, 0, 2) === "w:"){
|
||||||
|
$target = Level::get(substr($tg, 2));
|
||||||
|
}else{
|
||||||
|
$target = Player::get($tg);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$target = $issuer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!($target instanceof Player) and !($target instanceof Level)){
|
||||||
|
$output .= "That player cannot be found.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($params) === 3){
|
||||||
|
if($target instanceof Level){
|
||||||
|
$spawn = new Vector3(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)));
|
||||||
|
}else{
|
||||||
|
$spawn = new Position(floatval(array_shift($params)), floatval(array_shift($params)), floatval(array_shift($params)), $issuer->level);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$spawn = new Position($issuer->entity->x, $issuer->entity->y, $issuer->entity->z, $issuer->entity->level);
|
||||||
|
}
|
||||||
|
|
||||||
|
$target->setSpawn($spawn);
|
||||||
|
if($target instanceof Level){
|
||||||
|
$output .= "Spawnpoint of world " . $target->getName() . " set correctly!\n";
|
||||||
|
}elseif($target !== $issuer){
|
||||||
|
$output .= "Spawnpoint of " . $target->getName() . " set correctly!\n";
|
||||||
|
}else{
|
||||||
|
$output .= "Spawnpoint set correctly!\n";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "spawn":
|
||||||
|
if(!($issuer instanceof Player)){
|
||||||
|
$output .= "Please run this command in-game.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$issuer->teleport(Level::getDefault()->getSafeSpawn());
|
||||||
|
break;
|
||||||
|
case "ping":
|
||||||
|
if(!($issuer instanceof Player)){
|
||||||
|
$output .= "Please run this command in-game.\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$output .= "ping " . round($issuer->getLag(), 2) . "ms, packet loss " . round($issuer->getPacketLoss() * 100, 2) . "%, " . round($issuer->getBandwidth() / 1024, 2) . " KB/s\n";
|
||||||
|
break;
|
||||||
|
case "gamemode":
|
||||||
|
$player = false;
|
||||||
|
$setgm = false;
|
||||||
|
$gms = array(
|
||||||
|
"0" => 0,
|
||||||
|
"survival" => 0,
|
||||||
|
"s" => 0,
|
||||||
|
"1" => 1,
|
||||||
|
"creative" => 1,
|
||||||
|
"c" => 1,
|
||||||
|
"2" => 2,
|
||||||
|
"adventure" => 2,
|
||||||
|
"a" => 2,
|
||||||
|
"3" => 3,
|
||||||
|
"view" => 3,
|
||||||
|
"viewer" => 3,
|
||||||
|
"spectator" => 3,
|
||||||
|
"v" => 3,
|
||||||
|
);
|
||||||
|
if(isset($params[1])){
|
||||||
|
if(Player::get($params[1]) instanceof Player){
|
||||||
|
$player = Player::get($params[1]);
|
||||||
|
$setgm = $params[0];
|
||||||
|
}elseif(Player::get($params[0]) instanceof Player){
|
||||||
|
$player = Player::get($params[0]);
|
||||||
|
$setgm = $params[1];
|
||||||
|
}else{
|
||||||
|
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}elseif(isset($params[0])){
|
||||||
|
if(!(Player::get($params[0]) instanceof Player)){
|
||||||
|
if($issuer instanceof Player){
|
||||||
|
$setgm = $params[0];
|
||||||
|
$player = $issuer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!($player instanceof Player) or !isset($gms[strtolower($setgm)])){
|
||||||
|
$output .= "Usage: /$cmd <mode> [player] or /$cmd [player] <mode>\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if($player->setGamemode($gms[strtolower($setgm)])){
|
||||||
|
$output .= "Gamemode of " . $player->getName() . " changed to " . $player->getGamemode() . "\n";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "tp":
|
||||||
|
if(count($params) <= 2 or substr($params[0], 0, 2) === "w:" or substr($params[1], 0, 2) === "w:"){
|
||||||
|
if((!isset($params[1]) or substr($params[0], 0, 2) === "w:") and isset($params[0]) and ($issuer instanceof Player)){
|
||||||
|
$name = $issuer->getName();
|
||||||
|
$target = implode(" ", $params);
|
||||||
|
}elseif(isset($params[1]) and isset($params[0])){
|
||||||
|
$name = array_shift($params);
|
||||||
|
$target = implode(" ", $params);
|
||||||
|
}else{
|
||||||
|
$output .= "Usage: /$cmd [target player] <destination player | w:world>\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if($this->teleport($name, $target) !== false){
|
||||||
|
$output .= "\"$name\" teleported to \"$target\"\n";
|
||||||
|
}else{
|
||||||
|
$output .= "Couldn't teleport.\n";
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(!isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0]) and ($issuer instanceof Player)){
|
||||||
|
$name = $issuer->getName();
|
||||||
|
$x = $params[0];
|
||||||
|
$y = $params[1];
|
||||||
|
$z = $params[2];
|
||||||
|
}elseif(isset($params[3]) and isset($params[2]) and isset($params[1]) and isset($params[0])){
|
||||||
|
$name = $params[0];
|
||||||
|
$x = $params[1];
|
||||||
|
$y = $params[2];
|
||||||
|
$z = $params[3];
|
||||||
|
}else{
|
||||||
|
$output .= "Usage: /$cmd [player] <x> <y> <z>\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if($this->tppos($name, $x, $y, $z)){
|
||||||
|
$output .= "\"$name\" teleported to ($x, $y, $z)\n";
|
||||||
|
}else{
|
||||||
|
$output .= "Couldn't teleport.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "kill":
|
||||||
|
case "suicide":
|
||||||
|
if(!isset($params[0]) and ($issuer instanceof Player)){
|
||||||
|
$player = $issuer;
|
||||||
|
}else{
|
||||||
|
$player = Player::get($params[0]);
|
||||||
|
}
|
||||||
|
if($player instanceof Player){
|
||||||
|
$player->harm(1000, "console", true);
|
||||||
|
$player->sendMessage("Ouch. That looks like it hurt.\n");
|
||||||
|
}else{
|
||||||
|
$output .= "Usage: /$cmd [player]\n";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "list":
|
||||||
|
$output .= "There are " . count(Player::$list) . "/" . $this->server->maxClients . " players online:\n";
|
||||||
|
if(count(Player::$list) == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
foreach(Player::$list as $c){
|
||||||
|
$output .= $c->getName() . ", ";
|
||||||
|
}
|
||||||
|
$output = substr($output, 0, -2) . "\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function teleport(&$name, &$target){
|
||||||
|
if(substr($target, 0, 2) === "w:"){
|
||||||
|
$lv = Level::get(substr($target, 2));
|
||||||
|
if($lv instanceof Level){
|
||||||
|
$origin = Player::get($name);
|
||||||
|
if($origin instanceof Player){
|
||||||
|
$name = $origin->getName();
|
||||||
|
|
||||||
|
return $origin->teleport($lv->getSafeSpawn());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$player = Player::get($target);
|
||||||
|
if($player instanceof Player and $player->spawned === true){
|
||||||
|
$target = $player->getName();
|
||||||
|
$origin = Player::get($name);
|
||||||
|
if($origin instanceof Player){
|
||||||
|
$name = $origin->getName();
|
||||||
|
|
||||||
|
return $origin->teleport($player->entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tppos(&$name, &$x, &$y, &$z){
|
||||||
|
$player = Player::get($name);
|
||||||
|
if($player instanceof Player and $player->spawned === true){
|
||||||
|
$name = $player->getName();
|
||||||
|
$x = $x{0} === "~" ? $player->x + floatval(substr($x, 1)) : floatval($x);
|
||||||
|
$y = $y{0} === "~" ? $player->y + floatval(substr($y, 1)) : floatval($y);
|
||||||
|
$z = $z{0} === "~" ? $player->z + floatval(substr($z, 1)) : floatval($z);
|
||||||
|
$player->teleport(new Vector3($x, $y, $z));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
369
src/pocketmine/PocketMine.php
Normal file
369
src/pocketmine/PocketMine.php
Normal file
@ -0,0 +1,369 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/**
|
||||||
|
* Output text to the console, can contain Minecraft-formatted text.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param bool $EOL
|
||||||
|
* @param bool $log
|
||||||
|
* @param int $level
|
||||||
|
*/
|
||||||
|
function console($message, $EOL = true, $log = true, $level = 1){
|
||||||
|
pocketmine\console($message, $EOL, $log, $level);
|
||||||
|
}
|
||||||
|
|
||||||
|
function safe_var_dump(){
|
||||||
|
static $cnt = 0;
|
||||||
|
foreach(func_get_args() as $var){
|
||||||
|
switch(true){
|
||||||
|
case is_array($var):
|
||||||
|
echo str_repeat(" ", $cnt) . "array(" . count($var) . ") {" . PHP_EOL;
|
||||||
|
foreach($var as $key => $value){
|
||||||
|
echo str_repeat(" ", $cnt + 1) . "[" . (is_integer($key) ? $key : '"' . $key . '"') . "]=>" . PHP_EOL;
|
||||||
|
++$cnt;
|
||||||
|
safe_var_dump($value);
|
||||||
|
--$cnt;
|
||||||
|
}
|
||||||
|
echo str_repeat(" ", $cnt) . "}" . PHP_EOL;
|
||||||
|
break;
|
||||||
|
case is_integer($var):
|
||||||
|
echo str_repeat(" ", $cnt) . "int(" . $var . ")" . PHP_EOL;
|
||||||
|
break;
|
||||||
|
case is_float($var):
|
||||||
|
echo str_repeat(" ", $cnt) . "float(" . $var . ")" . PHP_EOL;
|
||||||
|
break;
|
||||||
|
case is_bool($var):
|
||||||
|
echo str_repeat(" ", $cnt) . "bool(" . ($var === true ? "true" : "false") . ")" . PHP_EOL;
|
||||||
|
break;
|
||||||
|
case is_string($var):
|
||||||
|
echo str_repeat(" ", $cnt) . "string(" . strlen($var) . ") \"$var\"" . PHP_EOL;
|
||||||
|
break;
|
||||||
|
case is_resource($var):
|
||||||
|
echo str_repeat(" ", $cnt) . "resource() of type (" . get_resource_type($var) . ")" . PHP_EOL;
|
||||||
|
break;
|
||||||
|
case is_object($var):
|
||||||
|
echo str_repeat(" ", $cnt) . "object(" . get_class($var) . ")" . PHP_EOL;
|
||||||
|
break;
|
||||||
|
case is_null($var):
|
||||||
|
echo str_repeat(" ", $cnt) . "NULL" . PHP_EOL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function dummy(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace pocketmine {
|
||||||
|
use pocketmine\utils\TextFormat;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
|
use pocketmine\wizard\Installer;
|
||||||
|
|
||||||
|
const VERSION = "Alpha_1.4dev";
|
||||||
|
const API_VERSION = "1.0.0";
|
||||||
|
const CODENAME = "絶好(Zekkou)ケーキ(Cake)";
|
||||||
|
const MINECRAFT_VERSION = "v0.8.1 alpha";
|
||||||
|
const PHP_VERSION = "5.5";
|
||||||
|
|
||||||
|
@define("pocketmine\\PATH", \getcwd() . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
if(!class_exists("SplClassLoader", false)){
|
||||||
|
require_once(\pocketmine\PATH . "src/spl/SplClassLoader.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$autoloader = new \SplClassLoader();
|
||||||
|
$autoloader->add("pocketmine", array(
|
||||||
|
\pocketmine\PATH . "src"
|
||||||
|
));
|
||||||
|
$autoloader->register(true);
|
||||||
|
|
||||||
|
//Startup code. Do not look at it, it can harm you. Most of them are hacks to fix date-related bugs, or basic functions used after this
|
||||||
|
|
||||||
|
set_time_limit(0); //Who set it to 30 seconds?!?!
|
||||||
|
|
||||||
|
if(ini_get("date.timezone") == ""){ //No Timezone set
|
||||||
|
date_default_timezone_set("GMT");
|
||||||
|
if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){
|
||||||
|
$time = time();
|
||||||
|
$time -= $time % 60;
|
||||||
|
//TODO: Parse different time & date formats by region. ¬¬ world
|
||||||
|
//Example: USA
|
||||||
|
exec("time.exe /T", $hour);
|
||||||
|
$i = array_map("intval", explode(":", trim($hour[0])));
|
||||||
|
exec("date.exe /T", $date);
|
||||||
|
$j = array_map("intval", explode(substr($date[0], 2, 1), trim($date[0])));
|
||||||
|
$offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
|
||||||
|
}else{
|
||||||
|
exec("date +%s", $t);
|
||||||
|
$offset = round((intval(trim($t[0])) - time()) / 60) * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
$daylight = (int) date("I");
|
||||||
|
$d = timezone_name_from_abbr("", $offset, $daylight);
|
||||||
|
@ini_set("date.timezone", $d);
|
||||||
|
date_default_timezone_set($d);
|
||||||
|
}else{
|
||||||
|
$d = @date_default_timezone_get();
|
||||||
|
if(strpos($d, "/") === false){
|
||||||
|
$d = timezone_name_from_abbr($d);
|
||||||
|
@ini_set("date.timezone", $d);
|
||||||
|
date_default_timezone_set($d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gc_enable();
|
||||||
|
error_reporting(E_ALL | E_STRICT);
|
||||||
|
ini_set("allow_url_fopen", 1);
|
||||||
|
ini_set("display_errors", 1);
|
||||||
|
ini_set("display_startup_errors", 1);
|
||||||
|
ini_set("default_charset", "utf-8");
|
||||||
|
|
||||||
|
ini_set("memory_limit", "128M"); //Default
|
||||||
|
define("pocketmine\\START_TIME", microtime(true));
|
||||||
|
|
||||||
|
$opts = getopt("", array("enable-ansi", "disable-ansi", "data:", "plugins:", "no-wizard"));
|
||||||
|
|
||||||
|
define("pocketmine\\DATA", isset($opts["data"]) ? realpath($opts["data"]) . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR);
|
||||||
|
define("pocketmine\\PLUGIN_PATH", isset($opts["plugins"]) ? realpath($opts["plugins"]) . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
if((strpos(strtoupper(php_uname("s")), "WIN") === false or isset($opts["enable-ansi"])) and !isset($opts["disable-ansi"])){
|
||||||
|
define("pocketmine\\ANSI", true);
|
||||||
|
}else{
|
||||||
|
define("pocketmine\\ANSI", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function kill($pid){
|
||||||
|
switch(Utils::getOS()){
|
||||||
|
case "win":
|
||||||
|
exec("taskkill.exe /F /PID " . ((int) $pid) . " > NUL");
|
||||||
|
break;
|
||||||
|
case "mac":
|
||||||
|
case "linux":
|
||||||
|
default:
|
||||||
|
exec("kill -9 " . ((int) $pid) . " > /dev/null 2>&1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output text to the console, can contain Minecraft-formatted text.
|
||||||
|
*
|
||||||
|
* @param $message
|
||||||
|
* @param bool $EOL
|
||||||
|
* @param bool $log
|
||||||
|
* @param int $level
|
||||||
|
*/
|
||||||
|
function console($message, $EOL = true, $log = true, $level = 1){
|
||||||
|
if(!defined("pocketmine\\DEBUG") or \pocketmine\DEBUG >= $level){
|
||||||
|
$message .= $EOL === true ? PHP_EOL : "";
|
||||||
|
if($message{0} !== "["){
|
||||||
|
$message = "[INFO] $message";
|
||||||
|
}
|
||||||
|
$time = (\pocketmine\ANSI === true ? TextFormat::AQUA . date("H:i:s") . TextFormat::RESET : date("H:i:s")) . " ";
|
||||||
|
$replaced = TextFormat::clean(preg_replace('/\x1b\[[0-9;]*m/', "", $time . $message));
|
||||||
|
if($log === true and (!defined("LOG") or LOG === true)){
|
||||||
|
log(date("Y-m-d") . " " . $replaced, "server", false, $level);
|
||||||
|
}
|
||||||
|
if(\pocketmine\ANSI === true){
|
||||||
|
$add = "";
|
||||||
|
if(preg_match("/^\\[([a-zA-Z0-9]*)\\]/", $message, $matches) > 0){
|
||||||
|
switch($matches[1]){
|
||||||
|
case "ERROR":
|
||||||
|
case "SEVERE":
|
||||||
|
$add .= TextFormat::RED;
|
||||||
|
break;
|
||||||
|
case "TRACE":
|
||||||
|
case "INTERNAL":
|
||||||
|
case "DEBUG":
|
||||||
|
$add .= TextFormat::GRAY;
|
||||||
|
break;
|
||||||
|
case "WARNING":
|
||||||
|
$add .= TextFormat::YELLOW;
|
||||||
|
break;
|
||||||
|
case "NOTICE":
|
||||||
|
$add .= TextFormat::AQUA;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$add = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$message = TextFormat::toANSI($time . $add . $message . TextFormat::RESET);
|
||||||
|
}else{
|
||||||
|
$message = $replaced;
|
||||||
|
}
|
||||||
|
echo $message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTrace($start = 1){
|
||||||
|
$e = new \Exception();
|
||||||
|
$trace = $e->getTrace();
|
||||||
|
$messages = array();
|
||||||
|
$j = 0;
|
||||||
|
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
|
||||||
|
$params = "";
|
||||||
|
if(isset($trace[$i]["args"])){
|
||||||
|
foreach($trace[$i]["args"] as $name => $value){
|
||||||
|
$params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? $trace[$i]["file"] : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . $trace[$i]["type"] : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
function error_handler($errno, $errstr, $errfile, $errline){
|
||||||
|
if(error_reporting() === 0){ //@ error-control
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$errorConversion = array(
|
||||||
|
E_ERROR => "E_ERROR",
|
||||||
|
E_WARNING => "E_WARNING",
|
||||||
|
E_PARSE => "E_PARSE",
|
||||||
|
E_NOTICE => "E_NOTICE",
|
||||||
|
E_CORE_ERROR => "E_CORE_ERROR",
|
||||||
|
E_CORE_WARNING => "E_CORE_WARNING",
|
||||||
|
E_COMPILE_ERROR => "E_COMPILE_ERROR",
|
||||||
|
E_COMPILE_WARNING => "E_COMPILE_WARNING",
|
||||||
|
E_USER_ERROR => "E_USER_ERROR",
|
||||||
|
E_USER_WARNING => "E_USER_WARNING",
|
||||||
|
E_USER_NOTICE => "E_USER_NOTICE",
|
||||||
|
E_STRICT => "E_STRICT",
|
||||||
|
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
|
||||||
|
E_DEPRECATED => "E_DEPRECATED",
|
||||||
|
E_USER_DEPRECATED => "E_USER_DEPRECATED",
|
||||||
|
);
|
||||||
|
$type = ($errno === E_ERROR or $errno === E_WARNING or $errno === E_USER_ERROR or $errno === E_USER_WARNING) ? "ERROR" : "NOTICE";
|
||||||
|
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno;
|
||||||
|
console("[$type] A $errno error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
|
||||||
|
foreach(getTrace() as $i => $line){
|
||||||
|
console("[TRACE] $line");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function log($message, $name, $EOL = true, $level = 2, $close = false){
|
||||||
|
global $fpointers;
|
||||||
|
if((!defined("pocketmine\\DEBUG") or \pocketmine\DEBUG >= $level) and (!defined("pocketmine\\LOG") or \pocketmine\LOG === true)){
|
||||||
|
$message .= $EOL === true ? PHP_EOL : "";
|
||||||
|
if(!isset($fpointers)){
|
||||||
|
$fpointers = array();
|
||||||
|
}
|
||||||
|
if(!isset($fpointers[$name]) or $fpointers[$name] === false){
|
||||||
|
$fpointers[$name] = @fopen(\pocketmine\DATA . "/" . $name . ".log", "ab");
|
||||||
|
}
|
||||||
|
@fwrite($fpointers[$name], $message);
|
||||||
|
if($close === true){
|
||||||
|
fclose($fpointers[$name]);
|
||||||
|
unset($fpointers[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
set_error_handler("\\pocketmine\\error_handler", E_ALL);
|
||||||
|
|
||||||
|
$errors = 0;
|
||||||
|
|
||||||
|
if(version_compare("5.4.0", PHP_VERSION) > 0){
|
||||||
|
console("[ERROR] Use PHP >= 5.4.0", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(php_sapi_name() !== "cli"){
|
||||||
|
console("[ERROR] You must run PocketMine-MP using the CLI.", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!extension_loaded("sockets")){
|
||||||
|
console("[ERROR] Unable to find the Socket extension.", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!extension_loaded("pthreads")){
|
||||||
|
console("[ERROR] Unable to find the pthreads extension.", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}else{
|
||||||
|
$pthreads_version = phpversion("pthreads");
|
||||||
|
if(substr_count($pthreads_version, ".") < 2){
|
||||||
|
$pthreads_version = "0.$pthreads_version";
|
||||||
|
}
|
||||||
|
if(version_compare($pthreads_version, "2.0.4") < 0){
|
||||||
|
console("[ERROR] pthreads >= 2.0.4 is required, while you have $pthreads_version.", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!extension_loaded("curl")){
|
||||||
|
console("[ERROR] Unable to find the cURL extension.", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!extension_loaded("sqlite3")){
|
||||||
|
console("[ERROR] Unable to find the SQLite3 extension.", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!extension_loaded("yaml")){
|
||||||
|
console("[ERROR] Unable to find the YAML extension.", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!extension_loaded("zlib")){
|
||||||
|
console("[ERROR] Unable to find the Zlib extension.", true, true, 0);
|
||||||
|
++$errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($errors > 0){
|
||||||
|
console("[ERROR] Please use the installer provided on the homepage, or recompile PHP again.", true, true, 0);
|
||||||
|
exit(1); //Exit with error
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file_exists(\pocketmine\PATH . ".git/refs/heads/master")){ //Found Git information!
|
||||||
|
define("pocketmine\\GIT_COMMIT", strtolower(trim(file_get_contents(\pocketmine\PATH . ".git/refs/heads/master"))));
|
||||||
|
}else{ //Unknown :(
|
||||||
|
define("pocketmine\\GIT_COMMIT", str_repeat("00", 20));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OPCache address errors
|
||||||
|
|
||||||
|
if(!file_exists(\pocketmine\DATA . "server.properties") and !isset($opts["no-wizard"])){
|
||||||
|
new Installer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(substr(__FILE__, 0, 7) !== "phar"){
|
||||||
|
console("[WARNING] Non-packaged PocketMine-MP installation detected, do not use on production.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$server = new Server($autoloader, \pocketmine\PATH, \pocketmine\DATA, \pocketmine\PLUGIN_PATH);
|
||||||
|
$server->start();
|
||||||
|
|
||||||
|
kill(getmypid());
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
}
|
1113
src/pocketmine/Server.php
Normal file
1113
src/pocketmine/Server.php
Normal file
File diff suppressed because it is too large
Load Diff
363
src/pocketmine/ServerAPI.php
Normal file
363
src/pocketmine/ServerAPI.php
Normal file
@ -0,0 +1,363 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use pocketmine\network\query\QueryHandler;
|
||||||
|
use pocketmine\network\rcon\RCON;
|
||||||
|
use pocketmine\network\upnp\UPnP;
|
||||||
|
use pocketmine\plugin\PluginManager;
|
||||||
|
use pocketmine\utils\Config;
|
||||||
|
use pocketmine\utils\TextFormat;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
|
use pocketmine\utils\VersionString;
|
||||||
|
|
||||||
|
class ServerAPI{
|
||||||
|
public $restart = false;
|
||||||
|
private static $serverRequest = false;
|
||||||
|
private $asyncCalls = array();
|
||||||
|
private $server;
|
||||||
|
private $config;
|
||||||
|
private $apiList = array();
|
||||||
|
private $asyncCnt = 0;
|
||||||
|
private $rcon;
|
||||||
|
|
||||||
|
public $query;
|
||||||
|
|
||||||
|
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs.
|
||||||
|
|
||||||
|
/** @var ConsoleAPI */
|
||||||
|
public $console;
|
||||||
|
|
||||||
|
/** @var LevelAPI */
|
||||||
|
public $level;
|
||||||
|
|
||||||
|
/** @var BlockAPI */
|
||||||
|
public $block;
|
||||||
|
|
||||||
|
/** @var ChatAPI */
|
||||||
|
public $chat;
|
||||||
|
|
||||||
|
/** @var BanAPI */
|
||||||
|
public $ban;
|
||||||
|
|
||||||
|
/** @var TimeAPI */
|
||||||
|
public $time;
|
||||||
|
|
||||||
|
/** @var PlayerAPI */
|
||||||
|
public $player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Server
|
||||||
|
*/
|
||||||
|
public static function request(){
|
||||||
|
return self::$serverRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function start(){
|
||||||
|
return $this->run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run(){
|
||||||
|
$this->load();
|
||||||
|
|
||||||
|
return $this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load(){
|
||||||
|
@mkdir(\pocketmine\DATA . "players/", 0755);
|
||||||
|
@mkdir(\pocketmine\DATA . "worlds/", 0755);
|
||||||
|
@mkdir(\pocketmine\DATA . "plugins/", 0755);
|
||||||
|
|
||||||
|
$version = new VersionString();
|
||||||
|
console("[INFO] Starting Minecraft: PE server version " . TextFormat::AQUA . MINECRAFT_VERSION);
|
||||||
|
|
||||||
|
console("[INFO] Loading properties...");
|
||||||
|
$this->config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES, array(
|
||||||
|
"server-name" => "Minecraft: PE Server",
|
||||||
|
"description" => "Server made using PocketMine-MP",
|
||||||
|
"motd" => "Welcome @player to this server!",
|
||||||
|
"server-port" => 19132,
|
||||||
|
"server-type" => "normal",
|
||||||
|
"memory-limit" => "128M",
|
||||||
|
"last-update" => false,
|
||||||
|
"white-list" => false,
|
||||||
|
"announce-player-achievements" => true,
|
||||||
|
"spawn-protection" => 16,
|
||||||
|
"view-distance" => 8,
|
||||||
|
"max-players" => 20,
|
||||||
|
"allow-flight" => false,
|
||||||
|
"spawn-animals" => true,
|
||||||
|
"spawn-mobs" => true,
|
||||||
|
"gamemode" => 0,
|
||||||
|
"hardcore" => false,
|
||||||
|
"pvp" => true,
|
||||||
|
"difficulty" => 1,
|
||||||
|
"generator-settings" => "",
|
||||||
|
"level-name" => "world",
|
||||||
|
"level-seed" => "",
|
||||||
|
"level-type" => "DEFAULT",
|
||||||
|
"enable-query" => true,
|
||||||
|
"enable-rcon" => false,
|
||||||
|
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
|
||||||
|
"auto-save" => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->parseProperties();
|
||||||
|
|
||||||
|
//Load advanced properties
|
||||||
|
define("pocketmine\\DEBUG", $this->getProperty("debug", 1));
|
||||||
|
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false));
|
||||||
|
define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 7)); //Default rate ~448 kB/s
|
||||||
|
if(ADVANCED_CACHE == true){
|
||||||
|
console("[INFO] Advanced cache enabled");
|
||||||
|
}
|
||||||
|
if($this->getProperty("upnp-forwarding") == true){
|
||||||
|
console("[INFO] [UPnP] Trying to port forward...");
|
||||||
|
UPnP::PortForward($this->getProperty("server-port"));
|
||||||
|
}
|
||||||
|
$this->server = new Server($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed : false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0");
|
||||||
|
$this->server->api = $this;
|
||||||
|
self::$serverRequest = $this->server;
|
||||||
|
console("[INFO] This server is running PocketMine-MP version " . ($version->isDev() ? TextFormat::YELLOW : "") . VERSION . TextFormat::RESET . " \"" . CODENAME . "\" (API " . API_VERSION . ")", true, true, 0);
|
||||||
|
console("[INFO] PocketMine-MP is distributed under the LGPL License", true, true, 0);
|
||||||
|
|
||||||
|
if($this->getProperty("last-update") === false or ($this->getProperty("last-update") + 3600) < time()){
|
||||||
|
console("[INFO] Checking for new server version");
|
||||||
|
console("[INFO] Last check: " . TextFormat::AQUA . date("Y-m-d H:i:s", $this->getProperty("last-update")) . "\x1b[0m");
|
||||||
|
if($this->server->version->isDev()){
|
||||||
|
$info = json_decode(Utils::getURL("https://api.github.com/repos/PocketMine/PocketMine-MP/commits"), true);
|
||||||
|
if($info === false or !isset($info[0])){
|
||||||
|
console("[ERROR] Github API error");
|
||||||
|
}else{
|
||||||
|
$last = new \DateTime($info[0]["commit"]["committer"]["date"]);
|
||||||
|
$last = $last->getTimestamp();
|
||||||
|
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and \pocketmine\GIT_COMMIT != $info[0]["sha"]){
|
||||||
|
console("[NOTICE] " . TextFormat::YELLOW . "A new DEVELOPMENT version of PocketMine-MP has been released!");
|
||||||
|
console("[NOTICE] " . TextFormat::YELLOW . "Commit \"" . $info[0]["commit"]["message"] . "\" [" . substr($info[0]["sha"], 0, 10) . "] by " . $info[0]["commit"]["committer"]["name"]);
|
||||||
|
console("[NOTICE] " . TextFormat::YELLOW . "Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/" . $info[0]["sha"] . ".zip");
|
||||||
|
console("[NOTICE] This message will disappear after issuing the command \"/update-done\"");
|
||||||
|
}else{
|
||||||
|
$this->setProperty("last-update", time());
|
||||||
|
console("[INFO] " . TextFormat::AQUA . "This is the latest DEVELOPMENT version");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$info = json_decode(Utils::getURL("https://api.github.com/repos/PocketMine/PocketMine-MP/tags"), true);
|
||||||
|
if($info === false or !isset($info[0])){
|
||||||
|
console("[ERROR] Github API error");
|
||||||
|
}else{
|
||||||
|
$newest = new VersionString(VERSION);
|
||||||
|
$newestN = $newest->getNumber();
|
||||||
|
$update = new VersionString($info[0]["name"]);
|
||||||
|
$updateN = $update->getNumber();
|
||||||
|
if($updateN > $newestN){
|
||||||
|
console("[NOTICE] " . TextFormat::GREEN . "A new STABLE version of PocketMine-MP has been released!");
|
||||||
|
console("[NOTICE] " . TextFormat::GREEN . "Version \"" . $info[0]["name"] . "\" #" . $updateN);
|
||||||
|
console("[NOTICE] Get it at PocketMine.net or at " . $info[0]["zipball_url"]);
|
||||||
|
console("[NOTICE] This message will disappear as soon as you update");
|
||||||
|
}else{
|
||||||
|
$this->setProperty("last-update", time());
|
||||||
|
console("[INFO] " . TextFormat::AQUA . "This is the latest STABLE version");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->loadProperties();
|
||||||
|
|
||||||
|
|
||||||
|
$this->apiList[] = $this->console = new ConsoleAPI();
|
||||||
|
$this->apiList[] = $this->level = new LevelAPI();
|
||||||
|
|
||||||
|
$this->apiList[] = $this->block = new BlockAPI();
|
||||||
|
$this->apiList[] = $this->chat = new ChatAPI();
|
||||||
|
$this->apiList[] = $this->ban = new BanAPI();
|
||||||
|
$this->apiList[] = $this->player = new PlayerAPI();
|
||||||
|
$this->apiList[] = $this->time = new TimeAPI();
|
||||||
|
|
||||||
|
foreach($this->apiList as $ob){
|
||||||
|
if(is_callable(array($ob, "init"))){
|
||||||
|
$ob->init(); //Fails sometimes!!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console("[INFO] Loaded " . count(PluginManager::loadPlugins(\pocketmine\DATA . "plugins/")) . " plugin(s).");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function async(callable $callable, $params = array(), $remove = false){
|
||||||
|
$cnt = $this->asyncCnt++;
|
||||||
|
$this->asyncCalls[$cnt] = new \Async($callable, $params);
|
||||||
|
|
||||||
|
return $remove === true ? $this->getAsync($cnt) : $cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAsync($id){
|
||||||
|
if(!isset($this->asyncCalls[$id])){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$ob = $this->asyncCalls[$id];
|
||||||
|
unset($this->asyncCalls[$id]);
|
||||||
|
|
||||||
|
return $ob;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct(){
|
||||||
|
foreach($this->apiList as $i => $ob){
|
||||||
|
if(method_exists($ob, "__destruct")){
|
||||||
|
$ob->__destruct();
|
||||||
|
unset($this->apiList[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function writeProperties(){
|
||||||
|
$this->config->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
if(!(self::$serverRequest instanceof Server)){
|
||||||
|
self::$serverRequest = $this->server;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($this->getProperty("send-usage", true) !== false){
|
||||||
|
$this->server->schedule(6000, array($this, "sendUsage"), array(), true); //Send the info after 5 minutes have passed
|
||||||
|
$this->sendUsage();
|
||||||
|
}
|
||||||
|
if($this->getProperty("auto-save") === true){
|
||||||
|
$this->server->schedule(18000, array($this, "autoSave"), array(), true);
|
||||||
|
}
|
||||||
|
if(!defined("NO_THREADS") and $this->getProperty("enable-rcon") === true){
|
||||||
|
$this->rcon = new RCON($this->getProperty("rcon.password", ""), $this->getProperty("rcon.port", $this->getProperty("server-port")), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0", $this->getProperty("rcon.threads", 1), $this->getProperty("rcon.clients-per-thread", 50));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getProperty("enable-query") === true){
|
||||||
|
$this->query = new QueryHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->schedule(2, array($this, "checkTickUpdates"), array(), true);
|
||||||
|
$this->server->init();
|
||||||
|
unregister_tick_function(array($this->server, "tick"));
|
||||||
|
$this->console->__destruct();
|
||||||
|
if($this->rcon instanceof RCON){
|
||||||
|
$this->rcon->stop();
|
||||||
|
}
|
||||||
|
$this->__destruct();
|
||||||
|
if($this->getProperty("upnp-forwarding") === true){
|
||||||
|
console("[INFO] [UPnP] Removing port forward...");
|
||||||
|
UPnP::RemovePortForward($this->getProperty("server-port"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->restart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
public function asyncOperation($t, $d, $c = null){
|
||||||
|
return $this->server->asyncOperation($t, $d, $c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addHandler($e, $c, $p = 5){
|
||||||
|
return $this->server->addHandler($e, $c, $p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dhandle($e, $d){
|
||||||
|
return $this->server->handle($e, $d);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle($e, &$d){
|
||||||
|
return $this->server->handle($e, $d);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function schedule($t, $c, $d, $r = false, $e = "server.schedule"){
|
||||||
|
return $this->server->schedule($t, $c, $d, $r, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function event($e, $d){
|
||||||
|
return $this->server->event($e, $d);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function trigger($e, $d){
|
||||||
|
return $this->server->trigger($e, $d);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteEvent($id){
|
||||||
|
return $this->server->deleteEvent($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProperties(){
|
||||||
|
return $this->config->getAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getProperty($name, $default = false){
|
||||||
|
$v = getopt("", array("$name::"));
|
||||||
|
if(isset($v[$name]) !== false){ //Allow for command-line arguments
|
||||||
|
$v = $v[$name];
|
||||||
|
switch(strtolower(trim($v))){
|
||||||
|
case "":
|
||||||
|
case "on":
|
||||||
|
case "true":
|
||||||
|
case "yes":
|
||||||
|
$v = true;
|
||||||
|
break;
|
||||||
|
case "off":
|
||||||
|
case "false":
|
||||||
|
case "no":
|
||||||
|
$v = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch($name){
|
||||||
|
case "last-update":
|
||||||
|
if($v === false){
|
||||||
|
$v = time();
|
||||||
|
}else{
|
||||||
|
$v = (int) $v;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "gamemode":
|
||||||
|
case "max-players":
|
||||||
|
case "server-port":
|
||||||
|
case "debug":
|
||||||
|
case "difficulty":
|
||||||
|
$v = (int) $v;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($this->config->exists($name) ? $this->config->get($name) : $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setProperty($name, $value, $save = true){
|
||||||
|
$this->config->set($name, $value);
|
||||||
|
if($save == true){
|
||||||
|
$this->writeProperties();
|
||||||
|
}
|
||||||
|
$this->loadProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getList(){
|
||||||
|
return $this->apiList;
|
||||||
|
}
|
||||||
|
}
|
735
src/pocketmine/ServerOld.php
Normal file
735
src/pocketmine/ServerOld.php
Normal file
@ -0,0 +1,735 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PocketMine-MP is the Minecraft: PE multiplayer server software
|
||||||
|
* Homepage: http://www.pocketmine.net/
|
||||||
|
*/
|
||||||
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use pocketmine\entity\Entity;
|
||||||
|
use pocketmine\network\Packet;
|
||||||
|
use pocketmine\network\protocol\Info;
|
||||||
|
use pocketmine\network\raknet\Info as RakNetInfo;
|
||||||
|
use pocketmine\network\raknet\Packet as RakNetPacket;
|
||||||
|
use pocketmine\plugin\PluginManager;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
|
use pocketmine\utils\VersionString;
|
||||||
|
|
||||||
|
class ServerOld{
|
||||||
|
/** @var Server */
|
||||||
|
private static $instance;
|
||||||
|
|
||||||
|
public $tCnt;
|
||||||
|
public $serverID;
|
||||||
|
public $interface;
|
||||||
|
public $database;
|
||||||
|
public $version;
|
||||||
|
public $invisible;
|
||||||
|
public $tickMeasure;
|
||||||
|
public $preparedSQL;
|
||||||
|
public $spawn;
|
||||||
|
public $whitelist;
|
||||||
|
public $seed;
|
||||||
|
public $stop;
|
||||||
|
public $gamemode;
|
||||||
|
public $difficulty;
|
||||||
|
public $name;
|
||||||
|
public $maxClients;
|
||||||
|
public $eidCnt;
|
||||||
|
public $custom;
|
||||||
|
public $description;
|
||||||
|
public $motd;
|
||||||
|
public $port;
|
||||||
|
public $saveEnabled;
|
||||||
|
|
||||||
|
private $rcon;
|
||||||
|
private $query;
|
||||||
|
|
||||||
|
private $serverip;
|
||||||
|
private $evCnt;
|
||||||
|
private $handCnt;
|
||||||
|
private $events;
|
||||||
|
private $eventsID;
|
||||||
|
private $handlers;
|
||||||
|
private $serverType;
|
||||||
|
private $lastTick;
|
||||||
|
private $doTick;
|
||||||
|
private $ticks;
|
||||||
|
private $memoryStats;
|
||||||
|
private $schedule;
|
||||||
|
private $asyncThread;
|
||||||
|
private $async = array();
|
||||||
|
private $asyncID = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Server
|
||||||
|
*/
|
||||||
|
public static function getInstance(){
|
||||||
|
if(isset(self::$instance)){
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function load(){
|
||||||
|
$this->version = new VersionString();
|
||||||
|
if(defined("pocketmine\\DEBUG") and \pocketmine\DEBUG >= 0 and function_exists("cli_set_process_title")){
|
||||||
|
@cli_set_process_title("PocketMine-MP " . \pocketmine\VERSION);
|
||||||
|
}
|
||||||
|
console("[INFO] Starting Minecraft PE server on " . ($this->serverip === "0.0.0.0" ? "*" : $this->serverip) . ":" . $this->port);
|
||||||
|
define("BOOTUP_RANDOM", Utils::getRandomBytes(16));
|
||||||
|
$this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)) : $this->serverID;
|
||||||
|
$this->seed = $this->seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : $this->seed;
|
||||||
|
$this->startDatabase();
|
||||||
|
$this->api = false;
|
||||||
|
$this->tCnt = 1;
|
||||||
|
$this->events = array();
|
||||||
|
$this->eventsID = array();
|
||||||
|
$this->handlers = array();
|
||||||
|
$this->invisible = false;
|
||||||
|
$this->difficulty = 1;
|
||||||
|
$this->custom = array();
|
||||||
|
$this->evCnt = 1;
|
||||||
|
$this->handCnt = 1;
|
||||||
|
$this->eidCnt = 1;
|
||||||
|
$this->maxClients = 20;
|
||||||
|
$this->schedule = array();
|
||||||
|
$this->scheduleCnt = 1;
|
||||||
|
$this->description = "";
|
||||||
|
$this->memoryStats = array();
|
||||||
|
$this->spawn = false;
|
||||||
|
$this->saveEnabled = true;
|
||||||
|
$this->whitelist = false;
|
||||||
|
$this->tickMeasure = array_fill(0, 40, 0);
|
||||||
|
$this->setType("normal");
|
||||||
|
$this->interface = new Handler("255.255.255.255", $this->port, $this->serverip);
|
||||||
|
$this->stop = false;
|
||||||
|
$this->ticks = 0;
|
||||||
|
if(!defined("NO_THREADS")){
|
||||||
|
$this->asyncThread = new \AsyncMultipleQueue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function __construct($name, $gamemode = 0, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
||||||
|
$this->port = (int) $port;
|
||||||
|
$this->doTick = true;
|
||||||
|
$this->gamemode = (int) $gamemode;
|
||||||
|
$this->name = $name;
|
||||||
|
$this->motd = "Welcome to " . $name;
|
||||||
|
$this->serverID = false;
|
||||||
|
$this->seed = $seed;
|
||||||
|
$this->serverip = $serverip;
|
||||||
|
self::$instance = $this;
|
||||||
|
$this->load();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function getTPS(){
|
||||||
|
$v = array_values($this->tickMeasure);
|
||||||
|
$tps = 40 / ($v[39] - $v[0]);
|
||||||
|
|
||||||
|
return round($tps, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function titleTick(){
|
||||||
|
$time = microtime(true);
|
||||||
|
if(defined("pocketmine\\DEBUG") and \pocketmine\DEBUG >= 0 and \pocketmine\ANSI === true){
|
||||||
|
echo "\x1b]0;PocketMine-MP " . VERSION . " | Online " . count(Player::$list) . "/" . $this->maxClients . " | RAM " . round((memory_get_usage() / 1024) / 1024, 2) . "MB | U " . round(($this->interface->bandwidth[1] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " D " . round(($this->interface->bandwidth[0] / max(1, $time - $this->interface->bandwidth[2])) / 1024, 2) . " kB/s | TPS " . $this->getTPS() . "\x07";
|
||||||
|
}
|
||||||
|
$this->interface->bandwidth = array(0, 0, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadEvents(){
|
||||||
|
if(\pocketmine\ANSI === true){
|
||||||
|
$this->schedule(30, array($this, "titleTick"), array(), true);
|
||||||
|
}
|
||||||
|
$this->schedule(20 * 15, array($this, "checkTicks"), array(), true);
|
||||||
|
$this->schedule(20 * 60, array($this, "checkMemory"), array(), true);
|
||||||
|
$this->schedule(20 * 45, "pocketmine\\utils\\Cache::cleanup", array(), true);
|
||||||
|
$this->schedule(20, array($this, "asyncOperationChecker"), array(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkTicks(){
|
||||||
|
if($this->getTPS() < 12){
|
||||||
|
console("[WARNING] Can't keep up! Is the server overloaded?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkMemory(){
|
||||||
|
$info = $this->debugInfo();
|
||||||
|
$data = $info["memory_usage"] . "," . $info["players"] . "," . $info["entities"];
|
||||||
|
$i = count($this->memoryStats) - 1;
|
||||||
|
if($i < 0 or $this->memoryStats[$i] !== $data){
|
||||||
|
$this->memoryStats[] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startDatabase(){
|
||||||
|
$this->preparedSQL = new \stdClass();
|
||||||
|
$this->preparedSQL->entity = new \stdClass();
|
||||||
|
$this->database = new \SQLite3(":memory:", SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
|
||||||
|
$this->query("PRAGMA journal_mode = OFF;");
|
||||||
|
$this->query("PRAGMA encoding = \"UTF-8\";");
|
||||||
|
$this->query("PRAGMA secure_delete = OFF;");
|
||||||
|
$this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);");
|
||||||
|
$this->query("CREATE TABLE handlers (ID INTEGER PRIMARY KEY, name TEXT, priority NUMERIC);");
|
||||||
|
$this->query("CREATE TABLE blockUpdates (level TEXT, x INTEGER, y INTEGER, z INTEGER, type INTEGER, delay NUMERIC);");
|
||||||
|
$this->query("CREATE TABLE recipes (id INTEGER PRIMARY KEY, type NUMERIC, recipe TEXT);");
|
||||||
|
$this->query("PRAGMA synchronous = OFF;");
|
||||||
|
$this->preparedSQL->selectHandlers = $this->database->prepare("SELECT DISTINCT ID FROM handlers WHERE name = :name ORDER BY priority DESC;");
|
||||||
|
$this->preparedSQL->selectActions = $this->database->prepare("SELECT ID,code,repeat FROM actions WHERE last <= (:time - interval);");
|
||||||
|
$this->preparedSQL->updateAction = $this->database->prepare("UPDATE actions SET last = :time WHERE ID = :id;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function query($sql, $fetch = false){
|
||||||
|
$result = $this->database->query($sql) or console("[ERROR] [SQL Error] " . $this->database->lastErrorMsg() . ". Query: " . $sql, true, true, 0);
|
||||||
|
if($fetch === true and ($result instanceof \SQLite3Result)){
|
||||||
|
$result = $result->fetchArray(SQLITE3_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function debugInfo($console = false){
|
||||||
|
$info = array();
|
||||||
|
$info["tps"] = $this->getTPS();
|
||||||
|
$info["memory_usage"] = round((memory_get_usage() / 1024) / 1024, 2) . "MB";
|
||||||
|
$info["memory_peak_usage"] = round((memory_get_peak_usage() / 1024) / 1024, 2) . "MB";
|
||||||
|
$info["entities"] = count(Entity::$list);
|
||||||
|
$info["players"] = count(Player::$list);
|
||||||
|
$info["events"] = count($this->eventsID);
|
||||||
|
$info["handlers"] = $this->query("SELECT count(ID) as count FROM handlers;", true);
|
||||||
|
$info["handlers"] = $info["handlers"]["count"];
|
||||||
|
$info["actions"] = $this->query("SELECT count(ID) as count FROM actions;", true);
|
||||||
|
$info["actions"] = $info["actions"]["count"];
|
||||||
|
$info["garbage"] = gc_collect_cycles();
|
||||||
|
$this->handle("server.debug", $info);
|
||||||
|
if($console === true){
|
||||||
|
console("[DEBUG] TPS: " . $info["tps"] . ", Memory usage: " . $info["memory_usage"] . " (Peak " . $info["memory_peak_usage"] . "), Entities: " . $info["entities"] . ", Events: " . $info["events"] . ", Handlers: " . $info["handlers"] . ", Actions: " . $info["actions"] . ", Garbage: " . $info["garbage"], true, true, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $reason
|
||||||
|
*/
|
||||||
|
public function close($reason = "server stop"){
|
||||||
|
if($this->stop !== true){
|
||||||
|
if(is_int($reason)){
|
||||||
|
$reason = "signal stop";
|
||||||
|
}
|
||||||
|
if(($this->api instanceof ServerAPI) === true){
|
||||||
|
if(($this->api->chat instanceof ChatAPI) === true){
|
||||||
|
Player::broadcastMessage("Stopping server...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->stop = true;
|
||||||
|
$this->trigger("server.close", $reason);
|
||||||
|
$this->interface->close();
|
||||||
|
|
||||||
|
if(!defined("NO_THREADS")){
|
||||||
|
@$this->asyncThread->stop = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type = "normal"){
|
||||||
|
switch(trim(strtolower($type))){
|
||||||
|
case "normal":
|
||||||
|
case "demo":
|
||||||
|
$this->serverType = "MCCPP;Demo;";
|
||||||
|
break;
|
||||||
|
case "minecon":
|
||||||
|
$this->serverType = "MCCPP;MINECON;";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asyncOperation($type, array $data, callable $callable = null){
|
||||||
|
if(defined("NO_THREADS")){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$d = "";
|
||||||
|
$type = (int) $type;
|
||||||
|
switch($type){
|
||||||
|
case ASYNC_CURL_GET:
|
||||||
|
$d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
|
||||||
|
break;
|
||||||
|
case ASYNC_CURL_POST:
|
||||||
|
$d .= Utils::writeShort(strlen($data["url"])) . $data["url"] . (isset($data["timeout"]) ? Utils::writeShort($data["timeout"]) : Utils::writeShort(10));
|
||||||
|
$d .= Utils::writeShort(count($data["data"]));
|
||||||
|
foreach($data["data"] as $key => $value){
|
||||||
|
$d .= Utils::writeShort(strlen($key)) . $key . Utils::writeInt(strlen($value)) . $value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ASYNC_FUNCTION:
|
||||||
|
$params = serialize($data["arguments"]);
|
||||||
|
$d .= Utils::writeShort(strlen($data["function"])) . $data["function"] . Utils::writeInt(strlen($params)) . $params;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$ID = $this->asyncID++;
|
||||||
|
$this->async[$ID] = $callable;
|
||||||
|
$this->asyncThread->input .= Utils::writeInt($ID) . Utils::writeShort($type) . $d;
|
||||||
|
|
||||||
|
return $ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asyncOperationChecker(){
|
||||||
|
if(defined("NO_THREADS")){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(isset($this->asyncThread->output{5})){
|
||||||
|
$offset = 0;
|
||||||
|
$ID = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
|
||||||
|
$offset += 4;
|
||||||
|
$type = Utils::readShort(substr($this->asyncThread->output, $offset, 2));
|
||||||
|
$offset += 2;
|
||||||
|
$data = array();
|
||||||
|
switch($type){
|
||||||
|
case ASYNC_CURL_GET:
|
||||||
|
case ASYNC_CURL_POST:
|
||||||
|
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
|
||||||
|
$offset += 4;
|
||||||
|
$data["result"] = substr($this->asyncThread->output, $offset, $len);
|
||||||
|
$offset += $len;
|
||||||
|
break;
|
||||||
|
case ASYNC_FUNCTION:
|
||||||
|
$len = Utils::readInt(substr($this->asyncThread->output, $offset, 4));
|
||||||
|
$offset += 4;
|
||||||
|
$data["result"] = unserialize(substr($this->asyncThread->output, $offset, $len));
|
||||||
|
$offset += $len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$this->asyncThread->output = substr($this->asyncThread->output, $offset);
|
||||||
|
if(isset($this->async[$ID]) and $this->async[$ID] !== null and is_callable($this->async[$ID])){
|
||||||
|
if(is_array($this->async[$ID])){
|
||||||
|
$method = $this->async[$ID][1];
|
||||||
|
$result = $this->async[$ID][0]->$method($data, $type, $ID);
|
||||||
|
}else{
|
||||||
|
$result = $this->async[$ID]($data, $type, $ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($this->async[$ID]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $event
|
||||||
|
* @param callable $callable
|
||||||
|
* @param integer $priority
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function addHandler($event, callable $callable, $priority = 5){
|
||||||
|
if(!is_callable($callable)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$priority = (int) $priority;
|
||||||
|
$hnid = $this->handCnt++;
|
||||||
|
$this->handlers[$hnid] = $callable;
|
||||||
|
$this->query("INSERT INTO handlers (ID, name, priority) VALUES (" . $hnid . ", '" . str_replace("'", "\\'", $event) . "', " . $priority . ");");
|
||||||
|
console("[INTERNAL] New handler " . (is_array($callable) ? get_class($callable[0]) . "::" . $callable[1] : $callable) . " to special event " . $event . " (ID " . $hnid . ")", true, true, 3);
|
||||||
|
|
||||||
|
return $hnid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dhandle($e, $d){
|
||||||
|
return $this->handle($e, $d);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle($event, &$data){
|
||||||
|
$this->preparedSQL->selectHandlers->reset();
|
||||||
|
$this->preparedSQL->selectHandlers->clear();
|
||||||
|
$this->preparedSQL->selectHandlers->bindValue(":name", $event, SQLITE3_TEXT);
|
||||||
|
$handlers = $this->preparedSQL->selectHandlers->execute();
|
||||||
|
$result = null;
|
||||||
|
if($handlers instanceof \SQLite3Result){
|
||||||
|
$call = array();
|
||||||
|
while(($hn = $handlers->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
|
$call[(int) $hn["ID"]] = true;
|
||||||
|
}
|
||||||
|
$handlers->finalize();
|
||||||
|
foreach($call as $hnid => $boolean){
|
||||||
|
if($result !== false and $result !== true){
|
||||||
|
$handler = $this->handlers[$hnid];
|
||||||
|
if(is_array($handler)){
|
||||||
|
$method = $handler[1];
|
||||||
|
$result = $handler[0]->$method($data, $event);
|
||||||
|
}else{
|
||||||
|
$result = $handler($data, $event);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($result !== false){
|
||||||
|
$this->trigger($event, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function eventHandler($data, $event){
|
||||||
|
switch($event){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getGamemode(){
|
||||||
|
switch($this->gamemode){
|
||||||
|
case 0:
|
||||||
|
return "survival";
|
||||||
|
case 1:
|
||||||
|
return "creative";
|
||||||
|
case 2:
|
||||||
|
return "adventure";
|
||||||
|
case 3:
|
||||||
|
return "view";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
register_tick_function(array($this, "tick"));
|
||||||
|
declare(ticks = 5000); //Minimum TPS for main thread locks
|
||||||
|
|
||||||
|
$this->loadEvents();
|
||||||
|
register_shutdown_function(array($this, "dumpError"));
|
||||||
|
register_shutdown_function(array($this, "close"));
|
||||||
|
if(function_exists("pcntl_signal")){
|
||||||
|
pcntl_signal(SIGTERM, array($this, "close"));
|
||||||
|
pcntl_signal(SIGINT, array($this, "close"));
|
||||||
|
pcntl_signal(SIGHUP, array($this, "close"));
|
||||||
|
}
|
||||||
|
console("[INFO] Default game type: " . strtoupper($this->getGamemode()));
|
||||||
|
$this->trigger("server.start", microtime(true));
|
||||||
|
console('[INFO] Done (' . round(microtime(true) - \pocketmine\START_TIME, 3) . 's)! For help, type "help" or "?"');
|
||||||
|
$this->process();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dumpError(){
|
||||||
|
if($this->stop === true){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems
|
||||||
|
console("[SEVERE] An unrecovereable has ocurred and the server has crashed. Creating an error dump");
|
||||||
|
$dump = "```\r\n# PocketMine-MP Error Dump " . date("D M j H:i:s T Y") . "\r\n";
|
||||||
|
$er = error_get_last();
|
||||||
|
$errorConversion = array(
|
||||||
|
E_ERROR => "E_ERROR",
|
||||||
|
E_WARNING => "E_WARNING",
|
||||||
|
E_PARSE => "E_PARSE",
|
||||||
|
E_NOTICE => "E_NOTICE",
|
||||||
|
E_CORE_ERROR => "E_CORE_ERROR",
|
||||||
|
E_CORE_WARNING => "E_CORE_WARNING",
|
||||||
|
E_COMPILE_ERROR => "E_COMPILE_ERROR",
|
||||||
|
E_COMPILE_WARNING => "E_COMPILE_WARNING",
|
||||||
|
E_USER_ERROR => "E_USER_ERROR",
|
||||||
|
E_USER_WARNING => "E_USER_WARNING",
|
||||||
|
E_USER_NOTICE => "E_USER_NOTICE",
|
||||||
|
E_STRICT => "E_STRICT",
|
||||||
|
E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR",
|
||||||
|
E_DEPRECATED => "E_DEPRECATED",
|
||||||
|
E_USER_DEPRECATED => "E_USER_DEPRECATED",
|
||||||
|
);
|
||||||
|
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]] : $er["type"];
|
||||||
|
$dump .= "Error: " . var_export($er, true) . "\r\n\r\n";
|
||||||
|
if(stripos($er["file"], "plugin") !== false){
|
||||||
|
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$dump .= "Code: \r\n";
|
||||||
|
$file = @file($er["file"], FILE_IGNORE_NEW_LINES);
|
||||||
|
for($l = max(0, $er["line"] - 10); $l < $er["line"] + 10; ++$l){
|
||||||
|
$dump .= "[" . ($l + 1) . "] " . @$file[$l] . "\r\n";
|
||||||
|
}
|
||||||
|
$dump .= "\r\n\r\n";
|
||||||
|
$dump .= "Backtrace: \r\n";
|
||||||
|
foreach(getTrace() as $line){
|
||||||
|
$dump .= "$line\r\n";
|
||||||
|
}
|
||||||
|
$dump .= "\r\n\r\n";
|
||||||
|
$version = new VersionString();
|
||||||
|
$dump .= "PocketMine-MP version: " . $version . " #" . $version->getNumber() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]\r\n";
|
||||||
|
$dump .= "Git commit: " . GIT_COMMIT . "\r\n";
|
||||||
|
$dump .= "uname -a: " . php_uname("a") . "\r\n";
|
||||||
|
$dump .= "PHP Version: " . phpversion() . "\r\n";
|
||||||
|
$dump .= "Zend version: " . zend_version() . "\r\n";
|
||||||
|
$dump .= "OS : " . PHP_OS . ", " . Utils::getOS() . "\r\n";
|
||||||
|
$dump .= "Debug Info: " . var_export($this->debugInfo(false), true) . "\r\n\r\n\r\n";
|
||||||
|
global $arguments;
|
||||||
|
$dump .= "Parameters: " . var_export($arguments, true) . "\r\n\r\n\r\n";
|
||||||
|
$p = $this->api->getProperties();
|
||||||
|
if($p["rcon.password"] != ""){
|
||||||
|
$p["rcon.password"] = "******";
|
||||||
|
}
|
||||||
|
$dump .= "server.properties: " . var_export($p, true) . "\r\n\r\n\r\n";
|
||||||
|
if(class_exists("pocketmine\\plugin\\PluginManager", false)){
|
||||||
|
$dump .= "Loaded plugins:\r\n";
|
||||||
|
foreach(PluginManager::getPlugins() as $p){
|
||||||
|
$d = $p->getDescription();
|
||||||
|
$dump .= $d->getName() . " " . $d->getVersion() . " by " . implode(", ", $d->getAuthors()) . "\r\n";
|
||||||
|
}
|
||||||
|
$dump .= "\r\n\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$extensions = array();
|
||||||
|
foreach(get_loaded_extensions() as $ext){
|
||||||
|
$extensions[$ext] = phpversion($ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dump .= "Loaded Modules: " . var_export($extensions, true) . "\r\n";
|
||||||
|
$this->checkMemory();
|
||||||
|
$dump .= "Memory Usage Tracking: \r\n" . chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9))) . "\r\n";
|
||||||
|
ob_start();
|
||||||
|
phpinfo();
|
||||||
|
$dump .= "\r\nphpinfo(): \r\n" . chunk_split(base64_encode(gzdeflate(ob_get_contents(), 9))) . "\r\n";
|
||||||
|
ob_end_clean();
|
||||||
|
$dump .= "\r\n```";
|
||||||
|
$name = "Error_Dump_" . date("D_M_j-H.i.s-T_Y");
|
||||||
|
log($dump, $name, true, 0, true);
|
||||||
|
console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tick(){
|
||||||
|
$time = microtime(true);
|
||||||
|
if($this->lastTick <= ($time - 0.05)){
|
||||||
|
$this->tickMeasure[] = $this->lastTick = $time;
|
||||||
|
unset($this->tickMeasure[key($this->tickMeasure)]);
|
||||||
|
++$this->ticks;
|
||||||
|
|
||||||
|
return $this->tickerFunction($time);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function clientID($ip, $port){
|
||||||
|
return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM);
|
||||||
|
//return $ip . ":" . $port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function packetHandler(Packet $packet){
|
||||||
|
$data =& $packet;
|
||||||
|
$CID = Server::clientID($packet->ip, $packet->port);
|
||||||
|
if(isset(Player::$list[$CID])){
|
||||||
|
if($packet instanceof RakNetPacket){
|
||||||
|
Player::$list[$CID]->handlePacket($packet);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
switch($packet->pid()){
|
||||||
|
case RakNetInfo::UNCONNECTED_PING:
|
||||||
|
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
|
||||||
|
if($this->invisible === true){
|
||||||
|
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
|
||||||
|
$pk->pingID = $packet->pingID;
|
||||||
|
$pk->serverID = $this->serverID;
|
||||||
|
$pk->serverType = $this->serverType;
|
||||||
|
$pk->ip = $packet->ip;
|
||||||
|
$pk->port = $packet->port;
|
||||||
|
$this->send($pk);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!isset($this->custom["times_" . $CID])){
|
||||||
|
$this->custom["times_" . $CID] = 0;
|
||||||
|
}
|
||||||
|
$ln = 15;
|
||||||
|
if($this->description == "" or substr($this->description, -1) != " "){
|
||||||
|
$this->description .= " ";
|
||||||
|
}
|
||||||
|
$txt = substr($this->description, $this->custom["times_" . $CID], $ln);
|
||||||
|
$txt .= substr($this->description, 0, $ln - strlen($txt));
|
||||||
|
$pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
|
||||||
|
$pk->pingID = $packet->pingID;
|
||||||
|
$pk->serverID = $this->serverID;
|
||||||
|
$pk->serverType = $this->serverType . $this->name . " [" . count(Player::$list) . "/" . $this->maxClients . "] " . $txt;
|
||||||
|
$pk->ip = $packet->ip;
|
||||||
|
$pk->port = $packet->port;
|
||||||
|
$this->send($pk);
|
||||||
|
$this->custom["times_" . $CID] = ($this->custom["times_" . $CID] + 1) % strlen($this->description);
|
||||||
|
break;
|
||||||
|
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
|
||||||
|
if($packet->structure !== RakNetInfo::STRUCTURE){
|
||||||
|
console("[DEBUG] Incorrect structure #" . $packet->structure . " from " . $packet->ip . ":" . $packet->port, true, true, 2);
|
||||||
|
$pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
|
||||||
|
$pk->serverID = $this->serverID;
|
||||||
|
$pk->ip = $packet->ip;
|
||||||
|
$pk->port = $packet->port;
|
||||||
|
$this->send($pk);
|
||||||
|
}else{
|
||||||
|
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
|
||||||
|
$pk->serverID = $this->serverID;
|
||||||
|
$pk->mtuSize = strlen($packet->buffer);
|
||||||
|
$pk->ip = $packet->ip;
|
||||||
|
$pk->port = $packet->port;
|
||||||
|
$this->send($pk);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
|
||||||
|
if($this->invisible === true){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
new Player($packet->clientID, $packet->ip, $packet->port, $packet->mtuSize); //New Session!
|
||||||
|
$pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_2);
|
||||||
|
$pk->serverID = $this->serverID;
|
||||||
|
$pk->serverPort = $this->port;
|
||||||
|
$pk->mtuSize = $packet->mtuSize;
|
||||||
|
$pk->ip = $packet->ip;
|
||||||
|
$pk->port = $packet->port;
|
||||||
|
$this->send($pk);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send(Packet $packet){
|
||||||
|
return $this->interface->writePacket($packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(){
|
||||||
|
$lastLoop = 0;
|
||||||
|
while($this->stop === false){
|
||||||
|
$packet = $this->interface->readPacket();
|
||||||
|
if($packet instanceof Packet){
|
||||||
|
$this->packetHandler($packet);
|
||||||
|
$lastLoop = 0;
|
||||||
|
}
|
||||||
|
if(($ticks = $this->tick()) === 0){
|
||||||
|
++$lastLoop;
|
||||||
|
if($lastLoop < 16){
|
||||||
|
usleep(1);
|
||||||
|
}elseif($lastLoop < 128){
|
||||||
|
usleep(1000);
|
||||||
|
}elseif($lastLoop < 256){
|
||||||
|
usleep(2000);
|
||||||
|
}else{
|
||||||
|
usleep(4000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function trigger($event, $data = ""){
|
||||||
|
if(isset($this->events[$event])){
|
||||||
|
foreach($this->events[$event] as $evid => $ev){
|
||||||
|
if(!is_callable($ev)){
|
||||||
|
$this->deleteEvent($evid);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(is_array($ev)){
|
||||||
|
$method = $ev[1];
|
||||||
|
$ev[0]->$method($data, $event);
|
||||||
|
}else{
|
||||||
|
$ev($data, $event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function schedule($ticks, callable $callback, $data = array(), $repeat = false, $eventName = "server.schedule"){
|
||||||
|
if(!is_callable($callback)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$chcnt = $this->scheduleCnt++;
|
||||||
|
$this->schedule[$chcnt] = array($callback, $data, $eventName);
|
||||||
|
$this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(" . $chcnt . ", " . ($ticks / 20) . ", " . microtime(true) . ", " . (((bool) $repeat) === true ? 1 : 0) . ");");
|
||||||
|
|
||||||
|
return $chcnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tickerFunction($time){
|
||||||
|
//actions that repeat every x time will go here
|
||||||
|
$this->preparedSQL->selectActions->reset();
|
||||||
|
$this->preparedSQL->selectActions->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||||
|
$actions = $this->preparedSQL->selectActions->execute();
|
||||||
|
|
||||||
|
$actionCount = 0;
|
||||||
|
if($actions instanceof \SQLite3Result){
|
||||||
|
while(($action = $actions->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
|
$cid = $action["ID"];
|
||||||
|
$this->preparedSQL->updateAction->reset();
|
||||||
|
$this->preparedSQL->updateAction->bindValue(":time", $time, SQLITE3_FLOAT);
|
||||||
|
$this->preparedSQL->updateAction->bindValue(":id", $cid, SQLITE3_INTEGER);
|
||||||
|
$this->preparedSQL->updateAction->execute();
|
||||||
|
if(!@is_callable($this->schedule[$cid][0])){
|
||||||
|
$return = false;
|
||||||
|
}else{
|
||||||
|
++$actionCount;
|
||||||
|
$return = call_user_func($this->schedule[$cid][0], $this->schedule[$cid][1], $this->schedule[$cid][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($action["repeat"] == 0 or $return === false){
|
||||||
|
$this->query("DELETE FROM actions WHERE ID = " . $action["ID"] . ";");
|
||||||
|
$this->schedule[$cid] = null;
|
||||||
|
unset($this->schedule[$cid]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$actions->finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $actionCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function event($event, callable $func){
|
||||||
|
if(!is_callable($func)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$evid = $this->evCnt++;
|
||||||
|
if(!isset($this->events[$event])){
|
||||||
|
$this->events[$event] = array();
|
||||||
|
}
|
||||||
|
$this->events[$event][$evid] = $func;
|
||||||
|
$this->eventsID[$evid] = $event;
|
||||||
|
console("[INTERNAL] Attached " . (is_array($func) ? get_class($func[0]) . "::" . $func[1] : $func) . " to event " . $event . " (ID " . $evid . ")", true, true, 3);
|
||||||
|
|
||||||
|
return $evid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteEvent($id){
|
||||||
|
$id = (int) $id;
|
||||||
|
if(isset($this->eventsID[$id])){
|
||||||
|
$ev = $this->eventsID[$id];
|
||||||
|
$this->eventsID[$id] = null;
|
||||||
|
unset($this->eventsID[$id]);
|
||||||
|
$this->events[$ev][$id] = null;
|
||||||
|
unset($this->events[$ev][$id]);
|
||||||
|
if(count($this->events[$ev]) === 0){
|
||||||
|
unset($this->events[$ev]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
144
src/pocketmine/TimeAPI.php
Normal file
144
src/pocketmine/TimeAPI.php
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine;
|
||||||
|
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
|
||||||
|
class TimeAPI{
|
||||||
|
public static $phases = array(
|
||||||
|
"day" => 0,
|
||||||
|
"sunset" => 9500,
|
||||||
|
"night" => 10900,
|
||||||
|
"sunrise" => 17800,
|
||||||
|
);
|
||||||
|
private $server;
|
||||||
|
|
||||||
|
function __construct(){
|
||||||
|
$this->server = Server::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
$this->server->api->console->register("time", "<check|set|add> [time]", array($this, "commandHandler"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||||
|
$output = "";
|
||||||
|
switch($cmd){
|
||||||
|
case "time":
|
||||||
|
$level = false;
|
||||||
|
if($issuer instanceof Player){
|
||||||
|
$level = $issuer->level;
|
||||||
|
}
|
||||||
|
$p = strtolower(array_shift($params));
|
||||||
|
switch($p){
|
||||||
|
case "check":
|
||||||
|
$output .= "Time: " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . ")\n";
|
||||||
|
break;
|
||||||
|
case "add":
|
||||||
|
$output .= "Set the time to " . $this->add(array_shift($params), $level) . "\n";
|
||||||
|
break;
|
||||||
|
case "set":
|
||||||
|
$output .= "Set the time to " . $this->set(array_shift($params), $level) . "\n";
|
||||||
|
break;
|
||||||
|
case "sunrise":
|
||||||
|
case "day":
|
||||||
|
case "sunset":
|
||||||
|
case "night":
|
||||||
|
$output .= "Set the time to " . $this->set($p, $level) . "\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$output .= "Usage: /time <check|set|add> [time]\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function night(){
|
||||||
|
return $this->set("night");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function day(){
|
||||||
|
return $this->set("day");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sunrise(){
|
||||||
|
return $this->set("sunrise");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sunset(){
|
||||||
|
return $this->set("sunset");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($raw = false, $level = false){
|
||||||
|
if(!($level instanceof Level)){
|
||||||
|
$level = Level::getDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $raw === true ? $level->getTime() : abs($level->getTime()) % 19200;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add($time, $level = false){
|
||||||
|
if(!($level instanceof Level)){
|
||||||
|
$level = Level::getDefault();
|
||||||
|
}
|
||||||
|
$level->setTime($level->getTime() + (int) $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDate($time = false){
|
||||||
|
$time = !is_integer($time) ? $this->get(false, $time) : $time;
|
||||||
|
|
||||||
|
return str_pad(strval((floor($time / 800) + 6) % 24), 2, "0", STR_PAD_LEFT) . ":" . str_pad(strval(floor(($time % 800) / 13.33)), 2, "0", STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPhase($time = false){
|
||||||
|
$time = !is_integer($time) ? $this->get(false, $time) : $time;
|
||||||
|
if($time < TimeAPI::$phases["sunset"]){
|
||||||
|
$time = "day";
|
||||||
|
}elseif($time < TimeAPI::$phases["night"]){
|
||||||
|
$time = "sunset";
|
||||||
|
}elseif($time < TimeAPI::$phases["sunrise"]){
|
||||||
|
$time = "night";
|
||||||
|
}else{
|
||||||
|
$time = "sunrise";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set($time, $level = false){
|
||||||
|
if(!($level instanceof Level)){
|
||||||
|
$level = Level::getDefault();
|
||||||
|
}
|
||||||
|
if(is_string($time) and isset(TimeAPI::$phases[$time])){
|
||||||
|
$level->setTime(TimeAPI::$phases[$time]);
|
||||||
|
}else{
|
||||||
|
$level->setTime((int) $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $level->getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
44
src/pocketmine/block/Air.php
Normal file
44
src/pocketmine/block/Air.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Air block
|
||||||
|
*/
|
||||||
|
class Air extends Transparent{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::AIR, 0, "Air");
|
||||||
|
$this->isActivable = false;
|
||||||
|
$this->breakable = false;
|
||||||
|
$this->isFlowable = true;
|
||||||
|
$this->isTransparent = true;
|
||||||
|
$this->isReplaceable = true;
|
||||||
|
$this->isPlaceable = false;
|
||||||
|
$this->hasPhysics = false;
|
||||||
|
$this->isSolid = false;
|
||||||
|
$this->isFullBlock = true;
|
||||||
|
$this->hardness = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
141
src/pocketmine/block/Bed.php
Normal file
141
src/pocketmine/block/Bed.php
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\network\protocol\ChatPacket;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\Server;
|
||||||
|
|
||||||
|
class Bed extends Transparent{
|
||||||
|
public function __construct($type = 0){
|
||||||
|
parent::__construct(self::BED_BLOCK, $type, "Bed Block");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->hardness = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($player instanceof Player and Server::getInstance()->api->time->getPhase($this->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 & 0x08) === 0x08){ //This is the Top part of bed
|
||||||
|
$b = $this;
|
||||||
|
}else{ //Bottom Part of Bed
|
||||||
|
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
|
||||||
|
$b = $blockNorth;
|
||||||
|
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
|
||||||
|
$b = $blockSouth;
|
||||||
|
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
|
||||||
|
$b = $blockEast;
|
||||||
|
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
|
||||||
|
$b = $blockWest;
|
||||||
|
}elseif($player instanceof Player){
|
||||||
|
$pk = new ChatPacket;
|
||||||
|
$pk->message = "This bed is incomplete";
|
||||||
|
$player->dataPacket($pk);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($player instanceof Player and $player->sleepOn($b) === false){
|
||||||
|
$pk = new ChatPacket;
|
||||||
|
$pk->message = "This bed is occupied";
|
||||||
|
$player->dataPacket($pk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->isTransparent === false){
|
||||||
|
$faces = array(
|
||||||
|
0 => 3,
|
||||||
|
1 => 4,
|
||||||
|
2 => 2,
|
||||||
|
3 => 5,
|
||||||
|
);
|
||||||
|
$d = $player instanceof Player ? $player->getDirection() : 0;
|
||||||
|
$next = $this->getSide($faces[(($d + 3) % 4)]);
|
||||||
|
$downNext = $this->getSide(0);
|
||||||
|
if($next->isReplaceable === true and $downNext->isTransparent === false){
|
||||||
|
$meta = (($d + 3) % 4) & 0x03;
|
||||||
|
$this->level->setBlock($block, Block::get($this->id, $meta), true, false, true);
|
||||||
|
$this->level->setBlock($next, Block::get($this->id, $meta | 0x08), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBreak(Item $item){
|
||||||
|
$blockNorth = $this->getSide(2); //Gets the blocks around them
|
||||||
|
$blockSouth = $this->getSide(3);
|
||||||
|
$blockEast = $this->getSide(5);
|
||||||
|
$blockWest = $this->getSide(4);
|
||||||
|
|
||||||
|
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
|
||||||
|
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
|
||||||
|
$this->level->setBlock($blockNorth, new Air(), true, false, true);
|
||||||
|
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
|
||||||
|
$this->level->setBlock($blockSouth, new Air(), true, false, true);
|
||||||
|
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
|
||||||
|
$this->level->setBlock($blockEast, new Air(), true, false, true);
|
||||||
|
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
|
||||||
|
$this->level->setBlock($blockWest, new Air(), true, false, true);
|
||||||
|
}
|
||||||
|
}else{ //Bottom Part of Bed
|
||||||
|
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
|
||||||
|
$this->level->setBlock($blockNorth, new Air(), true, false, true);
|
||||||
|
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
|
||||||
|
$this->level->setBlock($blockSouth, new Air(), true, false, true);
|
||||||
|
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
|
||||||
|
$this->level->setBlock($blockEast, new Air(), true, false, true);
|
||||||
|
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
|
||||||
|
$this->level->setBlock($blockWest, new Air(), true, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::BED, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
src/pocketmine/block/Bedrock.php
Normal file
37
src/pocketmine/block/Bedrock.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Bedrock extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::BEDROCK, 0, "Bedrock");
|
||||||
|
$this->breakable = false;
|
||||||
|
$this->hardness = 18000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isBreakable(Item $item){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
94
src/pocketmine/block/Beetroot.php
Normal file
94
src/pocketmine/block/Beetroot.php
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Beetroot extends Flowable{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::BEETROOT_BLOCK, $meta, "Beetroot Block");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === self::FARMLAND){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
|
$this->meta = 0x07;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
$item->count--;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get(BEETROOT_SEEDS, 0, 1));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
if(mt_rand(0, 2) == 1){
|
||||||
|
if($this->meta < 0x07){
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
$drops = array();
|
||||||
|
if($this->meta >= 0x07){
|
||||||
|
$drops[] = array(Item::BEETROOT, 0, 1);
|
||||||
|
$drops[] = array(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3));
|
||||||
|
}else{
|
||||||
|
$drops[] = array(Item::BEETROOT_SEEDS, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $drops;
|
||||||
|
}
|
||||||
|
}
|
36
src/pocketmine/block/BirchWoodStairs.php
Normal file
36
src/pocketmine/block/BirchWoodStairs.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class BirchWoodStairs extends Stair{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array($this->id, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
543
src/pocketmine/block/Block.php
Normal file
543
src/pocketmine/block/Block.php
Normal file
@ -0,0 +1,543 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All Block classes are in here
|
||||||
|
*/
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\level\Position;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
abstract class Block extends Position{
|
||||||
|
const AIR = 0;
|
||||||
|
const STONE = 1;
|
||||||
|
const GRASS = 2;
|
||||||
|
const DIRT = 3;
|
||||||
|
const COBBLESTONE = 4;
|
||||||
|
const COBBLE = 4;
|
||||||
|
const PLANK = 5;
|
||||||
|
const PLANKS = 5;
|
||||||
|
const WOODEN_PLANK = 5;
|
||||||
|
const WOODEN_PLANKS = 5;
|
||||||
|
const SAPLING = 6;
|
||||||
|
const SAPLINGS = 6;
|
||||||
|
const BEDROCK = 7;
|
||||||
|
const WATER = 8;
|
||||||
|
const STILL_WATER = 9;
|
||||||
|
const LAVA = 10;
|
||||||
|
const STILL_LAVA = 11;
|
||||||
|
const SAND = 12;
|
||||||
|
const GRAVEL = 13;
|
||||||
|
const GOLD_ORE = 14;
|
||||||
|
const IRON_ORE = 15;
|
||||||
|
const COAL_ORE = 16;
|
||||||
|
const WOOD = 17;
|
||||||
|
const TRUNK = 17;
|
||||||
|
const LOG = 17;
|
||||||
|
const LEAVES = 18;
|
||||||
|
const LEAVE = 18;
|
||||||
|
const SPONGE = 19;
|
||||||
|
const GLASS = 20;
|
||||||
|
const LAPIS_ORE = 21;
|
||||||
|
const LAPIS_BLOCK = 22;
|
||||||
|
|
||||||
|
const SANDSTONE = 24;
|
||||||
|
|
||||||
|
const BED_BLOCK = 26;
|
||||||
|
|
||||||
|
|
||||||
|
const COBWEB = 30;
|
||||||
|
const TALL_GRASS = 31;
|
||||||
|
const BUSH = 32;
|
||||||
|
const DEAD_BUSH = 32;
|
||||||
|
const WOOL = 35;
|
||||||
|
const DANDELION = 37;
|
||||||
|
const ROSE = 38;
|
||||||
|
const CYAN_FLOWER = 38;
|
||||||
|
const BROWN_MUSHROOM = 39;
|
||||||
|
const RED_MUSHROOM = 40;
|
||||||
|
const GOLD_BLOCK = 41;
|
||||||
|
const IRON_BLOCK = 42;
|
||||||
|
const DOUBLE_SLAB = 43;
|
||||||
|
const DOUBLE_SLABS = 43;
|
||||||
|
const SLAB = 44;
|
||||||
|
const SLABS = 44;
|
||||||
|
const BRICKS = 45;
|
||||||
|
const BRICKS_BLOCK = 45;
|
||||||
|
const TNT = 46;
|
||||||
|
const BOOKSHELF = 47;
|
||||||
|
const MOSS_STONE = 48;
|
||||||
|
const MOSSY_STONE = 48;
|
||||||
|
const OBSIDIAN = 49;
|
||||||
|
const TORCH = 50;
|
||||||
|
const FIRE = 51;
|
||||||
|
|
||||||
|
const WOOD_STAIRS = 53;
|
||||||
|
const WOODEN_STAIRS = 53;
|
||||||
|
const OAK_WOOD_STAIRS = 53;
|
||||||
|
const OAK_WOODEN_STAIRS = 53;
|
||||||
|
const CHEST = 54;
|
||||||
|
|
||||||
|
const DIAMOND_ORE = 56;
|
||||||
|
const DIAMOND_BLOCK = 57;
|
||||||
|
const CRAFTING_TABLE = 58;
|
||||||
|
const WORKBENCH = 58;
|
||||||
|
const WHEAT_BLOCK = 59;
|
||||||
|
const FARMLAND = 60;
|
||||||
|
const FURNACE = 61;
|
||||||
|
const BURNING_FURNACE = 62;
|
||||||
|
const LIT_FURNACE = 62;
|
||||||
|
const SIGN_POST = 63;
|
||||||
|
const DOOR_BLOCK = 64;
|
||||||
|
const WOODEN_DOOR_BLOCK = 64;
|
||||||
|
const WOOD_DOOR_BLOCK = 64;
|
||||||
|
const LADDER = 65;
|
||||||
|
|
||||||
|
const COBBLE_STAIRS = 67;
|
||||||
|
const COBBLESTONE_STAIRS = 67;
|
||||||
|
const WALL_SIGN = 68;
|
||||||
|
|
||||||
|
const IRON_DOOR_BLOCK = 71;
|
||||||
|
|
||||||
|
const REDSTONE_ORE = 73;
|
||||||
|
const GLOWING_REDSTONE_ORE = 74;
|
||||||
|
const LIT_REDSTONE_ORE = 74;
|
||||||
|
|
||||||
|
const SNOW = 78;
|
||||||
|
const SNOW_LAYER = 78;
|
||||||
|
const ICE = 79;
|
||||||
|
const SNOW_BLOCK = 80;
|
||||||
|
const CACTUS = 81;
|
||||||
|
const CLAY_BLOCK = 82;
|
||||||
|
const REEDS = 83;
|
||||||
|
const SUGARCANE_BLOCK = 83;
|
||||||
|
|
||||||
|
const FENCE = 85;
|
||||||
|
const PUMPKIN = 86;
|
||||||
|
const NETHERRACK = 87;
|
||||||
|
const SOUL_SAND = 88;
|
||||||
|
const GLOWSTONE = 89;
|
||||||
|
const GLOWSTONE_BLOCK = 89;
|
||||||
|
|
||||||
|
|
||||||
|
const LIT_PUMPKIN = 91;
|
||||||
|
const JACK_O_LANTERN = 91;
|
||||||
|
const CAKE_BLOCK = 92;
|
||||||
|
|
||||||
|
const TRAPDOOR = 96;
|
||||||
|
|
||||||
|
const STONE_BRICKS = 98;
|
||||||
|
const STONE_BRICK = 98;
|
||||||
|
|
||||||
|
const IRON_BAR = 101;
|
||||||
|
const IRON_BARS = 101;
|
||||||
|
const GLASS_PANE = 102;
|
||||||
|
const GLASS_PANEL = 102;
|
||||||
|
const MELON_BLOCK = 103;
|
||||||
|
const PUMPKIN_STEM = 104;
|
||||||
|
const MELON_STEM = 105;
|
||||||
|
|
||||||
|
const FENCE_GATE = 107;
|
||||||
|
const BRICK_STAIRS = 108;
|
||||||
|
const STONE_BRICK_STAIRS = 109;
|
||||||
|
|
||||||
|
const NETHER_BRICKS = 112;
|
||||||
|
const NETHER_BRICK_BLOCK = 112;
|
||||||
|
|
||||||
|
const NETHER_BRICKS_STAIRS = 114;
|
||||||
|
|
||||||
|
const SANDSTONE_STAIRS = 128;
|
||||||
|
|
||||||
|
const SPRUCE_WOOD_STAIRS = 134;
|
||||||
|
const SPRUCE_WOODEN_STAIRS = 134;
|
||||||
|
const BIRCH_WOOD_STAIRS = 135;
|
||||||
|
const BIRCH_WOODEN_STAIRS = 135;
|
||||||
|
const JUNGLE_WOOD_STAIRS = 136;
|
||||||
|
const JUNGLE_WOODEN_STAIRS = 136;
|
||||||
|
|
||||||
|
const COBBLE_WALL = 139;
|
||||||
|
const STONE_WALL = 139;
|
||||||
|
const COBBLESTONE_WALL = 139;
|
||||||
|
|
||||||
|
const CARROT_BLOCK = 141;
|
||||||
|
const POTATO_BLOCK = 142;
|
||||||
|
|
||||||
|
const QUARTZ_BLOCK = 155;
|
||||||
|
const QUARTZ_STAIRS = 156;
|
||||||
|
const DOUBLE_WOOD_SLAB = 157;
|
||||||
|
const DOUBLE_WOODEN_SLAB = 157;
|
||||||
|
const DOUBLE_WOOD_SLABS = 157;
|
||||||
|
const DOUBLE_WOODEN_SLABS = 157;
|
||||||
|
const WOOD_SLAB = 158;
|
||||||
|
const WOODEN_SLAB = 158;
|
||||||
|
const WOOD_SLABS = 158;
|
||||||
|
const WOODEN_SLABS = 158;
|
||||||
|
|
||||||
|
const HAY_BALE = 170;
|
||||||
|
const CARPET = 171;
|
||||||
|
|
||||||
|
const COAL_BLOCK = 173;
|
||||||
|
|
||||||
|
const BEETROOT_BLOCK = 244;
|
||||||
|
const STONECUTTER = 245;
|
||||||
|
const GLOWING_OBSIDIAN = 246;
|
||||||
|
const NETHER_REACTOR = 247;
|
||||||
|
|
||||||
|
|
||||||
|
public static $list = array();
|
||||||
|
protected $id;
|
||||||
|
protected $meta;
|
||||||
|
protected $name;
|
||||||
|
protected $breakTime;
|
||||||
|
protected $hardness;
|
||||||
|
public $isActivable = false;
|
||||||
|
public $breakable = true;
|
||||||
|
public $isFlowable = false;
|
||||||
|
public $isSolid = true;
|
||||||
|
public $isTransparent = false;
|
||||||
|
public $isReplaceable = false;
|
||||||
|
public $isPlaceable = true;
|
||||||
|
public $level = false;
|
||||||
|
public $hasPhysics = false;
|
||||||
|
public $isLiquid = false;
|
||||||
|
public $isFullBlock = true;
|
||||||
|
public $x = 0;
|
||||||
|
public $y = 0;
|
||||||
|
public $z = 0;
|
||||||
|
|
||||||
|
public static function init(){
|
||||||
|
if(count(self::$list) === 0){
|
||||||
|
self::$list = array(
|
||||||
|
self::AIR => new Air(),
|
||||||
|
self::STONE => new Stone(),
|
||||||
|
self::GRASS => new Grass(),
|
||||||
|
self::DIRT => new Dirt(),
|
||||||
|
self::COBBLESTONE => new Cobblestone(),
|
||||||
|
self::PLANKS => new Planks(),
|
||||||
|
self::SAPLING => new Sapling(),
|
||||||
|
self::BEDROCK => new Bedrock(),
|
||||||
|
self::WATER => new Water(),
|
||||||
|
self::STILL_WATER => new StillWater(),
|
||||||
|
self::LAVA => new Lava(),
|
||||||
|
self::STILL_LAVA => new StillLava(),
|
||||||
|
self::SAND => new Sand(),
|
||||||
|
self::GRAVEL => new Gravel(),
|
||||||
|
self::GOLD_ORE => new GoldOre(),
|
||||||
|
self::IRON_ORE => new IronOre(),
|
||||||
|
self::COAL_ORE => new CoalOre(),
|
||||||
|
self::WOOD => new Wood(),
|
||||||
|
self::LEAVES => new Leaves(),
|
||||||
|
self::SPONGE => new Sponge(),
|
||||||
|
self::GLASS => new Glass(),
|
||||||
|
self::LAPIS_ORE => new LapisOre(),
|
||||||
|
self::LAPIS_BLOCK => new Lapis(),
|
||||||
|
self::SANDSTONE => new Sandstone(),
|
||||||
|
self::BED_BLOCK => new Bed(),
|
||||||
|
self::COBWEB => new Cobweb(),
|
||||||
|
self::TALL_GRASS => new TallGrass(),
|
||||||
|
self::DEAD_BUSH => new DeadBush(),
|
||||||
|
self::WOOL => new Wool(),
|
||||||
|
self::DANDELION => new Dandelion(),
|
||||||
|
self::CYAN_FLOWER => new CyanFlower(),
|
||||||
|
self::BROWN_MUSHROOM => new BrownMushroom(),
|
||||||
|
self::RED_MUSHROOM => new RedMushroom(),
|
||||||
|
self::GOLD_BLOCK => new Gold(),
|
||||||
|
self::IRON_BLOCK => new Iron(),
|
||||||
|
self::DOUBLE_SLAB => new DoubleSlab(),
|
||||||
|
self::SLAB => new Slab(),
|
||||||
|
self::BRICKS_BLOCK => new Bricks(),
|
||||||
|
self::TNT => new TNT(),
|
||||||
|
self::BOOKSHELF => new Bookshelf(),
|
||||||
|
self::MOSS_STONE => new MossStone(),
|
||||||
|
self::OBSIDIAN => new Obsidian(),
|
||||||
|
self::TORCH => new Torch(),
|
||||||
|
self::FIRE => new Fire(),
|
||||||
|
|
||||||
|
self::WOOD_STAIRS => new WoodStairs(),
|
||||||
|
self::CHEST => new Chest(),
|
||||||
|
|
||||||
|
self::DIAMOND_ORE => new DiamondOre(),
|
||||||
|
self::DIAMOND_BLOCK => new Diamond(),
|
||||||
|
self::WORKBENCH => new Workbench(),
|
||||||
|
self::WHEAT_BLOCK => new Wheat(),
|
||||||
|
self::FARMLAND => new Farmland(),
|
||||||
|
self::FURNACE => new Furnace(),
|
||||||
|
self::BURNING_FURNACE => new BurningFurnace(),
|
||||||
|
self::SIGN_POST => new SignPost(),
|
||||||
|
self::WOOD_DOOR_BLOCK => new WoodDoor(),
|
||||||
|
self::LADDER => new Ladder(),
|
||||||
|
|
||||||
|
self::COBBLESTONE_STAIRS => new CobblestoneStairs(),
|
||||||
|
self::WALL_SIGN => new WallSign(),
|
||||||
|
|
||||||
|
self::IRON_DOOR_BLOCK => new IronDoor(),
|
||||||
|
self::REDSTONE_ORE => new RedstoneOre(),
|
||||||
|
self::GLOWING_REDSTONE_ORE => new GlowingRedstoneOre(),
|
||||||
|
|
||||||
|
self::SNOW_LAYER => new SnowLayer(),
|
||||||
|
self::ICE => new Ice(),
|
||||||
|
self::SNOW_BLOCK => new Snow(),
|
||||||
|
self::CACTUS => new Cactus(),
|
||||||
|
self::CLAY_BLOCK => new Clay(),
|
||||||
|
self::SUGARCANE_BLOCK => new Sugarcane(),
|
||||||
|
|
||||||
|
self::FENCE => new Fence(),
|
||||||
|
self::PUMPKIN => new Pumpkin(),
|
||||||
|
self::NETHERRACK => new Netherrack(),
|
||||||
|
self::SOUL_SAND => new SoulSand(),
|
||||||
|
self::GLOWSTONE_BLOCK => new Glowstone(),
|
||||||
|
|
||||||
|
self::LIT_PUMPKIN => new LitPumpkin(),
|
||||||
|
self::CAKE_BLOCK => new Cake(),
|
||||||
|
|
||||||
|
self::TRAPDOOR => new Trapdoor(),
|
||||||
|
|
||||||
|
self::STONE_BRICKS => new StoneBricks(),
|
||||||
|
|
||||||
|
self::IRON_BARS => new IronBars(),
|
||||||
|
self::GLASS_PANE => new GlassPane(),
|
||||||
|
self::MELON_BLOCK => new Melon(),
|
||||||
|
self::PUMPKIN_STEM => new PumpkinStem(),
|
||||||
|
self::MELON_STEM => new MelonStem(),
|
||||||
|
|
||||||
|
self::FENCE_GATE => new FenceGate(),
|
||||||
|
self::BRICK_STAIRS => new BrickStairs(),
|
||||||
|
self::STONE_BRICK_STAIRS => new StoneBrickStairs(),
|
||||||
|
|
||||||
|
self::NETHER_BRICKS => new NetherBrick(),
|
||||||
|
|
||||||
|
self::NETHER_BRICKS_STAIRS => new NetherBrickStairs(),
|
||||||
|
|
||||||
|
self::SANDSTONE_STAIRS => new SandstoneStairs(),
|
||||||
|
|
||||||
|
self::SPRUCE_WOOD_STAIRS => new SpruceWoodStairs(),
|
||||||
|
self::BIRCH_WOOD_STAIRS => new BirchWoodStairs(),
|
||||||
|
self::JUNGLE_WOOD_STAIRS => new JungleWoodStairs(),
|
||||||
|
self::STONE_WALL => new StoneWall(),
|
||||||
|
|
||||||
|
self::CARROT_BLOCK => new Carrot(),
|
||||||
|
self::POTATO_BLOCK => new Potato(),
|
||||||
|
|
||||||
|
self::QUARTZ_BLOCK => new Quartz(),
|
||||||
|
self::QUARTZ_STAIRS => new QuartzStairs(),
|
||||||
|
self::DOUBLE_WOOD_SLAB => new DoubleWoodSlab(),
|
||||||
|
self::WOOD_SLAB => new WoodSlab(),
|
||||||
|
|
||||||
|
self::HAY_BALE => new HayBale(),
|
||||||
|
self::CARPET => new Carpet(),
|
||||||
|
|
||||||
|
self::COAL_BLOCK => new Coal(),
|
||||||
|
|
||||||
|
self::BEETROOT_BLOCK => new Beetroot(),
|
||||||
|
self::STONECUTTER => new Stonecutter(),
|
||||||
|
self::GLOWING_OBSIDIAN => new GlowingObsidian(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @param int $meta
|
||||||
|
* @param Position $pos
|
||||||
|
*
|
||||||
|
* @return Block
|
||||||
|
*/
|
||||||
|
public static function get($id, $meta = 0, Position $pos = null){
|
||||||
|
if(isset(self::$list[$id])){
|
||||||
|
$block = clone self::$list[$id];
|
||||||
|
$block->setMetadata($meta);
|
||||||
|
}else{
|
||||||
|
$block = new Generic($id, $meta);
|
||||||
|
}
|
||||||
|
if($pos instanceof Position){
|
||||||
|
$block->position($pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @param int $meta
|
||||||
|
* @param string $name
|
||||||
|
*/
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
$this->id = (int) $id;
|
||||||
|
$this->meta = (int) $meta;
|
||||||
|
$this->name = $name;
|
||||||
|
$this->breakTime = 0.20;
|
||||||
|
$this->hardness = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
final public function getHardness(){
|
||||||
|
return $this->hardness;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
final public function getName(){
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
final public function getID(){
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
final public function getMetadata(){
|
||||||
|
return $this->meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $meta
|
||||||
|
*/
|
||||||
|
final public function setMetadata($meta){
|
||||||
|
$this->meta = $meta & 0x0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the block position to a new Position object
|
||||||
|
*
|
||||||
|
* @param Position $v
|
||||||
|
*/
|
||||||
|
final public function position(Position $v){
|
||||||
|
$this->level = $v->level;
|
||||||
|
$this->x = (int) $v->x;
|
||||||
|
$this->y = (int) $v->y;
|
||||||
|
$this->z = (int) $v->z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of Item objects to be dropped
|
||||||
|
*
|
||||||
|
* @param Item $item
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if(!isset(self::$list[$this->id])){ //Unknown blocks
|
||||||
|
return array();
|
||||||
|
}else{
|
||||||
|
return array(
|
||||||
|
array($this->id, $this->meta, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the seconds that this block takes to be broken using an specific Item
|
||||||
|
*
|
||||||
|
* @param Item $item
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
return $this->breakTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Block on the side $side, works like Vector3::side()
|
||||||
|
*
|
||||||
|
* @param int $side
|
||||||
|
*
|
||||||
|
* @return Block
|
||||||
|
*/
|
||||||
|
public function getSide($side){
|
||||||
|
$v = parent::getSide($side);
|
||||||
|
if($this->level instanceof Level){
|
||||||
|
return $this->level->getBlock($v);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
final public function __toString(){
|
||||||
|
return "Block " . $this->name . " (" . $this->id . ":" . $this->meta . ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the item can be broken with an specific Item
|
||||||
|
*
|
||||||
|
* @param Item $item
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
abstract function isBreakable(Item $item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do the actions needed so the block is broken with the Item
|
||||||
|
*
|
||||||
|
* @param Item $item
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
abstract function onBreak(Item $item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Places the Block, using block space and block target, and side. Returns if the block has been placed.
|
||||||
|
*
|
||||||
|
* @param Item $item
|
||||||
|
* @param Block $block
|
||||||
|
* @param Block $target
|
||||||
|
* @param int $face
|
||||||
|
* @param float $fx
|
||||||
|
* @param float $fy
|
||||||
|
* @param float $fz
|
||||||
|
* @param Player $player = null
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
abstract function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do actions when activated by Item. Returns if it has done anything
|
||||||
|
*
|
||||||
|
* @param Item $item
|
||||||
|
* @param Player $player
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
abstract function onActivate(Item $item, Player $player = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fires a block update on the Block
|
||||||
|
*
|
||||||
|
* @param int $type
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
abstract function onUpdate($type);
|
||||||
|
}
|
31
src/pocketmine/block/Bookshelf.php
Normal file
31
src/pocketmine/block/Bookshelf.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Bookshelf extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::BOOKSHELF, 0, "Bookshelf");
|
||||||
|
$this->hardness = 7.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
src/pocketmine/block/BrickStairs.php
Normal file
30
src/pocketmine/block/BrickStairs.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class BrickStairs extends Stair{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::BRICK_STAIRS, $meta, "Brick Stairs");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
src/pocketmine/block/Bricks.php
Normal file
58
src/pocketmine/block/Bricks.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Bricks extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::BRICKS_BLOCK, 0, "Bricks");
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.4;
|
||||||
|
case 4:
|
||||||
|
return 0.5;
|
||||||
|
case 3:
|
||||||
|
return 0.75;
|
||||||
|
case 2:
|
||||||
|
return 0.25;
|
||||||
|
case 1:
|
||||||
|
return 1.5;
|
||||||
|
default:
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::BRICKS_BLOCK, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
src/pocketmine/block/BrownMushroom.php
Normal file
58
src/pocketmine/block/BrownMushroom.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class BrownMushroom extends Flowable{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::BROWN_MUSHROOM, 0, "Brown Mushroom");
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->isTransparent === false){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
131
src/pocketmine/block/BurningFurnace.php
Normal file
131
src/pocketmine/block/BurningFurnace.php
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\nbt\NBT;
|
||||||
|
use pocketmine\nbt\tag\Compound;
|
||||||
|
use pocketmine\nbt\tag\Enum;
|
||||||
|
use pocketmine\nbt\tag\Int;
|
||||||
|
use pocketmine\nbt\tag\String;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\tile\Furnace;
|
||||||
|
use pocketmine\tile\Tile;
|
||||||
|
|
||||||
|
class BurningFurnace extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::BURNING_FURNACE, $meta, "Burning Furnace");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 17.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$faces = array(
|
||||||
|
0 => 4,
|
||||||
|
1 => 2,
|
||||||
|
2 => 5,
|
||||||
|
3 => 3,
|
||||||
|
);
|
||||||
|
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
$nbt = new Compound(false, array(
|
||||||
|
new Enum("Items", array()),
|
||||||
|
new String("id", Tile::FURNACE),
|
||||||
|
new Int("x", $this->x),
|
||||||
|
new Int("y", $this->y),
|
||||||
|
new Int("z", $this->z)
|
||||||
|
));
|
||||||
|
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||||
|
new Furnace($this->level, $nbt);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBreak(Item $item){
|
||||||
|
$this->level->setBlock($this, new Air(), true, true, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($player instanceof Player){
|
||||||
|
$t = $this->level->getTile($this);
|
||||||
|
$furnace = false;
|
||||||
|
if($t instanceof Furnace){
|
||||||
|
$furnace = $t;
|
||||||
|
}else{
|
||||||
|
$nbt = new Compound(false, array(
|
||||||
|
new Enum("Items", array()),
|
||||||
|
new String("id", Tile::FURNACE),
|
||||||
|
new Int("x", $this->x),
|
||||||
|
new Int("y", $this->y),
|
||||||
|
new Int("z", $this->z)
|
||||||
|
));
|
||||||
|
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||||
|
$furnace = new Furnace($this->level, $nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(($player->getGamemode() & 0x01) === 0x01){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$furnace->openInventory($player);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.7;
|
||||||
|
case 4:
|
||||||
|
return 0.9;
|
||||||
|
case 3:
|
||||||
|
return 1.35;
|
||||||
|
case 2:
|
||||||
|
return 0.45;
|
||||||
|
case 1:
|
||||||
|
return 2.65;
|
||||||
|
default:
|
||||||
|
return 17.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
$drops = array();
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
$drops[] = array(Item::FURNACE, 0, 1);
|
||||||
|
}
|
||||||
|
$t = $this->level->getTile($this);
|
||||||
|
if($t instanceof Furnace){
|
||||||
|
for($s = 0; $s < Furnace::SLOTS; ++$s){
|
||||||
|
$slot = $t->getSlot($s);
|
||||||
|
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
|
||||||
|
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->getCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $drops;
|
||||||
|
}
|
||||||
|
}
|
92
src/pocketmine/block/Cactus.php
Normal file
92
src/pocketmine/block/Cactus.php
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\math\Vector3 as Vector3;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\Server;
|
||||||
|
|
||||||
|
class Cactus extends Transparent{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::CACTUS, $meta, "Cactus");
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->hardness = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){ //Replace with common break method
|
||||||
|
$this->level->setBlock($this, new Air(), false);
|
||||||
|
Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
if($this->getSide(0)->getID() !== self::CACTUS){
|
||||||
|
if($this->meta == 0x0F){
|
||||||
|
for($y = 1; $y < 3; ++$y){
|
||||||
|
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||||
|
if($b->getID() === self::AIR){
|
||||||
|
$this->level->setBlock($b, new Cactus(), true, false, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->meta = 0;
|
||||||
|
$this->level->setBlock($this, $this, false);
|
||||||
|
}else{
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === self::SAND or $down->getID() === self::CACTUS){
|
||||||
|
$block0 = $this->getSide(2);
|
||||||
|
$block1 = $this->getSide(3);
|
||||||
|
$block2 = $this->getSide(4);
|
||||||
|
$block3 = $this->getSide(5);
|
||||||
|
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array($this->id, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
80
src/pocketmine/block/Cake.php
Normal file
80
src/pocketmine/block/Cake.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Cake extends Transparent{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::CAKE_BLOCK, 0, "Cake Block");
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->meta = $meta & 0x07;
|
||||||
|
$this->hardness = 2.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() !== self::AIR){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
|
$this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($player instanceof Player and $player->getHealth() < 20){
|
||||||
|
++$this->meta;
|
||||||
|
$player->heal(3, "cake");
|
||||||
|
if($this->meta >= 0x06){
|
||||||
|
$this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
}else{
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
80
src/pocketmine/block/Carpet.php
Normal file
80
src/pocketmine/block/Carpet.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Carpet extends Flowable{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::CARPET, $meta, "Carpet");
|
||||||
|
$names = array(
|
||||||
|
0 => "White Carpet",
|
||||||
|
1 => "Orange Carpet",
|
||||||
|
2 => "Magenta Carpet",
|
||||||
|
3 => "Light Blue Carpet",
|
||||||
|
4 => "Yellow Carpet",
|
||||||
|
5 => "Lime Carpet",
|
||||||
|
6 => "Pink Carpet",
|
||||||
|
7 => "Gray Carpet",
|
||||||
|
8 => "Light Gray Carpet",
|
||||||
|
9 => "Cyan Carpet",
|
||||||
|
10 => "Purple Carpet",
|
||||||
|
11 => "Blue Carpet",
|
||||||
|
12 => "Brown Carpet",
|
||||||
|
13 => "Green Carpet",
|
||||||
|
14 => "Red Carpet",
|
||||||
|
15 => "Black Carpet",
|
||||||
|
);
|
||||||
|
$this->name = $names[$this->meta];
|
||||||
|
$this->hardness = 0;
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->isSolid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() !== self::AIR){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id, $this->meta, 1));
|
||||||
|
$this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
93
src/pocketmine/block/Carrot.php
Normal file
93
src/pocketmine/block/Carrot.php
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Carrot extends Flowable{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::CARROT_BLOCK, $meta, "Carrot Block");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === self::FARMLAND){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
|
$this->meta = 0x07;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
$item->count--;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get(CARROT, 0, 1));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
if(mt_rand(0, 2) == 1){
|
||||||
|
if($this->meta < 0x07){
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
$drops = array();
|
||||||
|
if($this->meta >= 0x07){
|
||||||
|
$drops[] = array(Item::CARROT, 0, mt_rand(1, 4));
|
||||||
|
}else{
|
||||||
|
$drops[] = array(Item::CARROT, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $drops;
|
||||||
|
}
|
||||||
|
}
|
149
src/pocketmine/block/Chest.php
Normal file
149
src/pocketmine/block/Chest.php
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\nbt\NBT;
|
||||||
|
use pocketmine\nbt\tag\Compound;
|
||||||
|
use pocketmine\nbt\tag\Enum;
|
||||||
|
use pocketmine\nbt\tag\Int;
|
||||||
|
use pocketmine\nbt\tag\String;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\tile\Chest as TileChest;
|
||||||
|
use pocketmine\tile\Tile;
|
||||||
|
|
||||||
|
class Chest extends Transparent{
|
||||||
|
|
||||||
|
const SLOTS = 27;
|
||||||
|
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::CHEST, $meta, "Chest");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$faces = array(
|
||||||
|
0 => 4,
|
||||||
|
1 => 2,
|
||||||
|
2 => 5,
|
||||||
|
3 => 3,
|
||||||
|
);
|
||||||
|
|
||||||
|
$chest = false;
|
||||||
|
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
|
||||||
|
|
||||||
|
for($side = 2; $side <= 5; ++$side){
|
||||||
|
if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){
|
||||||
|
continue;
|
||||||
|
}elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$c = $this->getSide($side);
|
||||||
|
if(($c instanceof TileChest) and $c->getMetadata() === $this->meta){
|
||||||
|
if((($tile = $this->level->getTile($c)) instanceof TileChest) and !$tile->isPaired()){
|
||||||
|
$chest = $tile;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
$nbt = new Compound(false, array(
|
||||||
|
new Enum("Items", array()),
|
||||||
|
new String("id", Tile::CHEST),
|
||||||
|
new Int("x", $this->x),
|
||||||
|
new Int("y", $this->y),
|
||||||
|
new Int("z", $this->z)
|
||||||
|
));
|
||||||
|
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||||
|
$tile = new TileChest($this->level, $nbt);
|
||||||
|
|
||||||
|
if($chest instanceof TileChest){
|
||||||
|
$chest->pairWith($tile);
|
||||||
|
$tile->pairWith($chest);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBreak(Item $item){
|
||||||
|
$t = $this->level->getTile($this);
|
||||||
|
if($t instanceof TileChest){
|
||||||
|
$t->unpair();
|
||||||
|
}
|
||||||
|
$this->level->setBlock($this, new Air(), true, true, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($player instanceof Player){
|
||||||
|
$top = $this->getSide(1);
|
||||||
|
if($top->isTransparent !== true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$t = $this->level->getTile($this);
|
||||||
|
$chest = false;
|
||||||
|
if($t instanceof TileChest){
|
||||||
|
$chest = $t;
|
||||||
|
}else{
|
||||||
|
$nbt = new Compound(false, array(
|
||||||
|
new Enum("Items", array()),
|
||||||
|
new String("id", Tile::CHEST),
|
||||||
|
new Int("x", $this->x),
|
||||||
|
new Int("y", $this->y),
|
||||||
|
new Int("z", $this->z)
|
||||||
|
));
|
||||||
|
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||||
|
$chest = new TileChest($this->level, $nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(($player->gamemode & 0x01) === 0x01){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$chest->openInventory($player);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
$drops = array(
|
||||||
|
array($this->id, 0, 1),
|
||||||
|
);
|
||||||
|
$t = $this->level->getTile($this);
|
||||||
|
if($t instanceof Chest){
|
||||||
|
for($s = 0; $s < Chest::SLOTS; ++$s){
|
||||||
|
$slot = $t->getSlot($s);
|
||||||
|
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
|
||||||
|
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->getCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $drops;
|
||||||
|
}
|
||||||
|
}
|
37
src/pocketmine/block/Clay.php
Normal file
37
src/pocketmine/block/Clay.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Clay extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::CLAY_BLOCK, 0, "Clay Block");
|
||||||
|
$this->hardness = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::CLAY, 0, 4),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
58
src/pocketmine/block/Coal.php
Normal file
58
src/pocketmine/block/Coal.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Coal extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::COAL_BLOCK, 0, "Coal Block");
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.95;
|
||||||
|
case 4:
|
||||||
|
return 1.25;
|
||||||
|
case 3:
|
||||||
|
return 1.9;
|
||||||
|
case 2:
|
||||||
|
return 0.65;
|
||||||
|
case 1:
|
||||||
|
return 3.75;
|
||||||
|
default:
|
||||||
|
return 25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::COAL_BLOCK, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
59
src/pocketmine/block/CoalOre.php
Normal file
59
src/pocketmine/block/CoalOre.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class CoalOre extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::COAL_ORE, 0, "Coal Ore");
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.6;
|
||||||
|
case 4:
|
||||||
|
return 0.75;
|
||||||
|
case 3:
|
||||||
|
return 1.15;
|
||||||
|
case 2:
|
||||||
|
return 0.4;
|
||||||
|
case 1:
|
||||||
|
return 2.25;
|
||||||
|
default:
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::COAL, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
src/pocketmine/block/Cobblestone.php
Normal file
58
src/pocketmine/block/Cobblestone.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Cobblestone extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::COBBLESTONE, 0, "Cobblestone");
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.4;
|
||||||
|
case 4:
|
||||||
|
return 0.5;
|
||||||
|
case 3:
|
||||||
|
return 0.75;
|
||||||
|
case 2:
|
||||||
|
return 0.25;
|
||||||
|
case 1:
|
||||||
|
return 1.5;
|
||||||
|
default:
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::COBBLESTONE, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
src/pocketmine/block/CobblestoneStairs.php
Normal file
30
src/pocketmine/block/CobblestoneStairs.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class CobblestoneStairs extends Stair{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
src/pocketmine/block/Cobweb.php
Normal file
37
src/pocketmine/block/Cobweb.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Cobweb extends Flowable{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::COBWEB, 0, "Cobweb");
|
||||||
|
$this->isSolid = true;
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->hardness = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
58
src/pocketmine/block/CyanFlower.php
Normal file
58
src/pocketmine/block/CyanFlower.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class CyanFlower extends Flowable{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::CYAN_FLOWER, 0, "Cyan Flower");
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
58
src/pocketmine/block/Dandelion.php
Normal file
58
src/pocketmine/block/Dandelion.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Dandelion extends Flowable{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::DANDELION, 0, "Dandelion");
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
45
src/pocketmine/block/DeadBush.php
Normal file
45
src/pocketmine/block/DeadBush.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
|
||||||
|
class DeadBush extends Flowable{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::DEAD_BUSH, 0, "Dead Bush");
|
||||||
|
//$this->isReplaceable = true;
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
src/pocketmine/block/Diamond.php
Normal file
52
src/pocketmine/block/Diamond.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Diamond extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::DIAMOND_BLOCK, 0, "Diamond Block");
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.95;
|
||||||
|
case 4:
|
||||||
|
return 1.25;
|
||||||
|
default:
|
||||||
|
return 25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 4){
|
||||||
|
return array(
|
||||||
|
array(Item::DIAMOND_BLOCK, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
src/pocketmine/block/DiamondOre.php
Normal file
52
src/pocketmine/block/DiamondOre.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class DiamondOre extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::DIAMOND_ORE, 0, "Diamond Ore");
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.6;
|
||||||
|
case 4:
|
||||||
|
return 0.75;
|
||||||
|
default:
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 4){
|
||||||
|
return array(
|
||||||
|
array(Item::DIAMOND, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
44
src/pocketmine/block/Dirt.php
Normal file
44
src/pocketmine/block/Dirt.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Dirt extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::DIRT, 0, "Dirt");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 2.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($item->isHoe()){
|
||||||
|
$item->useOn($this);
|
||||||
|
$this->level->setBlock($this, Block::get(Item::FARMLAND, 0), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
138
src/pocketmine/block/Door.php
Normal file
138
src/pocketmine/block/Door.php
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\network\protocol\LevelEventPacket;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
|
||||||
|
abstract class Door extends Transparent{
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
parent::__construct($id, $meta, $name);
|
||||||
|
$this->isSolid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
|
$this->level->setBlock($this, new Air(), false);
|
||||||
|
if($this->getSide(1) instanceof Door){
|
||||||
|
$this->level->setBlock($this->getSide(1), new Air(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
if($face === 1){
|
||||||
|
$blockUp = $this->getSide(1);
|
||||||
|
$blockDown = $this->getSide(0);
|
||||||
|
if($blockUp->isReplaceable === false or $blockDown->isTransparent === true){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$direction = $player instanceof Player ? $player->getDirection() : 0;
|
||||||
|
$face = array(
|
||||||
|
0 => 3,
|
||||||
|
1 => 4,
|
||||||
|
2 => 2,
|
||||||
|
3 => 5,
|
||||||
|
);
|
||||||
|
$next = $this->getSide($face[(($direction + 2) % 4)]);
|
||||||
|
$next2 = $this->getSide($face[$direction]);
|
||||||
|
$metaUp = 0x08;
|
||||||
|
if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge
|
||||||
|
$metaUp |= 0x01;
|
||||||
|
}
|
||||||
|
$this->level->setBlock($blockUp, Block::get($this->id, $metaUp), true, false, true); //Top
|
||||||
|
|
||||||
|
$this->meta = $player->getDirection() & 0x03;
|
||||||
|
$this->level->setBlock($block, $this, true, false, true); //Bottom
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBreak(Item $item){
|
||||||
|
if(($this->meta & 0x08) === 0x08){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === $this->id){
|
||||||
|
$this->level->setBlock($down, new Air(), true, false, true);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$up = $this->getSide(1);
|
||||||
|
if($up->getID() === $this->id){
|
||||||
|
$this->level->setBlock($up, new Air(), true, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if(($this->meta & 0x08) === 0x08){ //Top
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === $this->id){
|
||||||
|
$meta = $down->getMetadata() ^ 0x04;
|
||||||
|
$this->level->setBlock($down, Block::get($this->id, $meta), true, false, true);
|
||||||
|
$players = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||||
|
if($player instanceof Player){
|
||||||
|
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;
|
||||||
|
Player::broadcastPacket($players, $pk);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
$this->meta ^= 0x04;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
$players = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||||
|
if($player instanceof Player){
|
||||||
|
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;
|
||||||
|
Player::broadcastPacket($players, $pk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
69
src/pocketmine/block/DoubleSlab.php
Normal file
69
src/pocketmine/block/DoubleSlab.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class DoubleSlab extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::DOUBLE_SLAB, $meta, "Double Slab");
|
||||||
|
$names = array(
|
||||||
|
0 => "Stone",
|
||||||
|
1 => "Sandstone",
|
||||||
|
2 => "Wooden",
|
||||||
|
3 => "Cobblestone",
|
||||||
|
4 => "Brick",
|
||||||
|
5 => "Stone Brick",
|
||||||
|
6 => "Quartz",
|
||||||
|
);
|
||||||
|
$this->name = "Double " . $names[$this->meta & 0x07] . " Slab";
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.4;
|
||||||
|
case 4:
|
||||||
|
return 0.5;
|
||||||
|
case 3:
|
||||||
|
return 0.75;
|
||||||
|
case 2:
|
||||||
|
return 0.25;
|
||||||
|
case 1:
|
||||||
|
return 1.5;
|
||||||
|
default:
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::SLAB, $this->meta & 0x07, 2),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
62
src/pocketmine/block/DoubleWoodSlab.php
Normal file
62
src/pocketmine/block/DoubleWoodSlab.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class DoubleWoodSlab extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::DOUBLE_WOOD_SLAB, $meta, "Double Wooden Slab");
|
||||||
|
$names = array(
|
||||||
|
0 => "Oak",
|
||||||
|
1 => "Spruce",
|
||||||
|
2 => "Birch",
|
||||||
|
3 => "Jungle",
|
||||||
|
);
|
||||||
|
$this->name = "Double " . $names[$this->meta & 0x07] . " Wooden Slab";
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isAxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.4;
|
||||||
|
case 4:
|
||||||
|
return 0.5;
|
||||||
|
case 3:
|
||||||
|
return 0.75;
|
||||||
|
case 2:
|
||||||
|
return 0.25;
|
||||||
|
case 1:
|
||||||
|
return 1.5;
|
||||||
|
default:
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::WOOD_SLAB, $this->meta & 0x07, 2),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
42
src/pocketmine/block/Fallable.php
Normal file
42
src/pocketmine/block/Fallable.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\Server;
|
||||||
|
|
||||||
|
class Fallable extends Solid{
|
||||||
|
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
parent::__construct($id, $meta, $name);
|
||||||
|
$this->hasPhysics = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||||
|
Server::getInstance()->api->block->blockUpdate(clone $this, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
37
src/pocketmine/block/Farmland.php
Normal file
37
src/pocketmine/block/Farmland.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Farmland extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::FARMLAND, $meta, "Farmland");
|
||||||
|
$this->hardness = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::DIRT, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
32
src/pocketmine/block/Fence.php
Normal file
32
src/pocketmine/block/Fence.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Fence extends Transparent{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::FENCE, 0, "Fence");
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
75
src/pocketmine/block/FenceGate.php
Normal file
75
src/pocketmine/block/FenceGate.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class FenceGate extends Transparent{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::FENCE_GATE, $meta, "Fence Gate");
|
||||||
|
$this->isActivable = true;
|
||||||
|
if(($this->meta & 0x04) === 0x04){
|
||||||
|
$this->isFullBlock = true;
|
||||||
|
}else{
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
}
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$faces = array(
|
||||||
|
0 => 3,
|
||||||
|
1 => 0,
|
||||||
|
2 => 1,
|
||||||
|
3 => 2,
|
||||||
|
);
|
||||||
|
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03;
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array($this->id, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
$faces = array(
|
||||||
|
0 => 3,
|
||||||
|
1 => 0,
|
||||||
|
2 => 1,
|
||||||
|
3 => 2,
|
||||||
|
);
|
||||||
|
$this->meta = ($faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03) | ((~$this->meta) & 0x04);
|
||||||
|
if(($this->meta & 0x04) === 0x04){
|
||||||
|
$this->isFullBlock = true;
|
||||||
|
}else{
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
}
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
62
src/pocketmine/block/Fire.php
Normal file
62
src/pocketmine/block/Fire.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
|
||||||
|
class Fire extends Flowable{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::FIRE, $meta, "Fire");
|
||||||
|
$this->isReplaceable = true;
|
||||||
|
$this->breakable = false;
|
||||||
|
$this->isFullBlock = true;
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
for($s = 0; $s <= 5; ++$s){
|
||||||
|
$side = $this->getSide($s);
|
||||||
|
if($side->getID() !== self::AIR and !($side instanceof Liquid)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
if($this->getSide(0)->getID() !== self::NETHERRACK){
|
||||||
|
$this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
src/pocketmine/block/Flowable.php
Normal file
32
src/pocketmine/block/Flowable.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Flowable extends Transparent{
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
parent::__construct($id, $meta, $name);
|
||||||
|
$this->isFlowable = true;
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->isSolid = false;
|
||||||
|
}
|
||||||
|
}
|
32
src/pocketmine/block/Furnace.php
Normal file
32
src/pocketmine/block/Furnace.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Furnace extends BurningFurnace{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct($meta);
|
||||||
|
$this->id = self::FURNACE;
|
||||||
|
$this->name = "Furnace";
|
||||||
|
$this->isActivable = true;
|
||||||
|
}
|
||||||
|
}
|
79
src/pocketmine/block/Generic.php
Normal file
79
src/pocketmine/block/Generic.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\Server;
|
||||||
|
|
||||||
|
class Generic extends Block{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @param int $meta
|
||||||
|
* @param string $name
|
||||||
|
*/
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
parent::__construct($id, $meta, $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
return $this->level->setBlock($this, $this, true, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isBreakable(Item $item){
|
||||||
|
return $this->breakable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBreak(Item $item){
|
||||||
|
return $this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($this->hasPhysics === true and $type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === self::AIR or ($down instanceof Liquid)){
|
||||||
|
$data = array(
|
||||||
|
"x" => $this->x + 0.5,
|
||||||
|
"y" => $this->y + 0.5,
|
||||||
|
"z" => $this->z + 0.5,
|
||||||
|
"Tile" => $this->id,
|
||||||
|
);
|
||||||
|
$server = Server::getInstance();
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
//TODO
|
||||||
|
//$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
|
||||||
|
//$e->spawnToAll();
|
||||||
|
$server->api->block->blockUpdateAround(clone $this, Level::BLOCK_UPDATE_NORMAL, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
return $this->isActivable;
|
||||||
|
}
|
||||||
|
}
|
35
src/pocketmine/block/Glass.php
Normal file
35
src/pocketmine/block/Glass.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Glass extends Transparent{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::GLASS, 0, "Glass");
|
||||||
|
$this->hardness = 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
32
src/pocketmine/block/GlassPane.php
Normal file
32
src/pocketmine/block/GlassPane.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class GlassPane extends Transparent{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::GLASS_PANE, 0, "Glass Pane");
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->isSolid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
src/pocketmine/block/GlowingObsidian.php
Normal file
30
src/pocketmine/block/GlowingObsidian.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class GlowingObsidian extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::GLOWING_OBSIDIAN, $meta, "Glowing Obsidian");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
65
src/pocketmine/block/GlowingRedstoneOre.php
Normal file
65
src/pocketmine/block/GlowingRedstoneOre.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
|
||||||
|
class GlowingRedstoneOre extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_SCHEDULED or $type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
$this->level->setBlock($this, Block::get(Item::REDSTONE_ORE, $this->meta), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_WEAK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.6;
|
||||||
|
case 4:
|
||||||
|
return 0.75;
|
||||||
|
default:
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 4){
|
||||||
|
return array(
|
||||||
|
array(Item::REDSTONE_DUST, 0, mt_rand(4, 5)),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
src/pocketmine/block/Glowstone.php
Normal file
37
src/pocketmine/block/Glowstone.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Glowstone extends Transparent{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::GLOWSTONE_BLOCK, 0, "Glowstone");
|
||||||
|
$this->hardness = 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
52
src/pocketmine/block/Gold.php
Normal file
52
src/pocketmine/block/Gold.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Gold extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::GOLD_BLOCK, 0, "Gold Block");
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.6;
|
||||||
|
case 4:
|
||||||
|
return 0.75;
|
||||||
|
default:
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 4){
|
||||||
|
return array(
|
||||||
|
array(Item::GOLD_BLOCK, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
src/pocketmine/block/GoldOre.php
Normal file
52
src/pocketmine/block/GoldOre.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class GoldOre extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::GOLD_ORE, 0, "Gold Ore");
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.6;
|
||||||
|
case 4:
|
||||||
|
return 0.75;
|
||||||
|
default:
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 4){
|
||||||
|
return array(
|
||||||
|
array(Item::GOLD_ORE, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
src/pocketmine/block/Grass.php
Normal file
57
src/pocketmine/block/Grass.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\generator\object\TallGrass;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\utils\Random;
|
||||||
|
|
||||||
|
class Grass extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::GRASS, 0, "Grass");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::DIRT, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){
|
||||||
|
$item->count--;
|
||||||
|
TallGrass::growGrass($this->level, $this, new Random(), 8, 2);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}elseif($item->isHoe()){
|
||||||
|
$item->useOn($this);
|
||||||
|
$this->level->setBlock($this, new Farmland());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
44
src/pocketmine/block/Gravel.php
Normal file
44
src/pocketmine/block/Gravel.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Gravel extends Fallable{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::GRAVEL, 0, "Gravel");
|
||||||
|
$this->hardness = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if(mt_rand(1, 10) === 1){
|
||||||
|
return array(
|
||||||
|
array(Item::FLINT, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
array(Item::GRAVEL, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
55
src/pocketmine/block/HayBale.php
Normal file
55
src/pocketmine/block/HayBale.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class HayBale extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::HAY_BALE, $meta, "Hay Bale");
|
||||||
|
$this->hardness = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$faces = array(
|
||||||
|
0 => 0,
|
||||||
|
1 => 0,
|
||||||
|
2 => 0b1000,
|
||||||
|
3 => 0b1000,
|
||||||
|
4 => 0b0100,
|
||||||
|
5 => 0b0100,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->meta = ($this->meta & 0x03) | $faces[$face];
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array($this->id, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
src/pocketmine/block/Ice.php
Normal file
58
src/pocketmine/block/Ice.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Ice extends Transparent{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::ICE, 0, "Ice");
|
||||||
|
$this->hardness = 2.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBreak(Item $item){
|
||||||
|
$this->level->setBlock($this, new Water(), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.1;
|
||||||
|
case 4:
|
||||||
|
return 0.15;
|
||||||
|
case 3:
|
||||||
|
return 0.2;
|
||||||
|
case 2:
|
||||||
|
return 0.1;
|
||||||
|
case 1:
|
||||||
|
return 0.4;
|
||||||
|
default:
|
||||||
|
return 0.75;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
54
src/pocketmine/block/Iron.php
Normal file
54
src/pocketmine/block/Iron.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Iron extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::IRON_BLOCK, 0, "Iron Block");
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.95;
|
||||||
|
case 4:
|
||||||
|
return 1.25;
|
||||||
|
case 3:
|
||||||
|
return 1.9;
|
||||||
|
default:
|
||||||
|
return 25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 3){
|
||||||
|
return array(
|
||||||
|
array(Item::IRON_BLOCK, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
src/pocketmine/block/IronBars.php
Normal file
32
src/pocketmine/block/IronBars.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class IronBars extends Transparent{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::IRON_BARS, 0, "Iron Bars");
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->isSolid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
src/pocketmine/block/IronDoor.php
Normal file
59
src/pocketmine/block/IronDoor.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class IronDoor extends Door{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::IRON_DOOR_BLOCK, $meta, "Iron Door Block");
|
||||||
|
//$this->isActivable = true;
|
||||||
|
$this->hardness = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.95;
|
||||||
|
case 4:
|
||||||
|
return 1.25;
|
||||||
|
case 3:
|
||||||
|
return 1.9;
|
||||||
|
case 2:
|
||||||
|
return 0.65;
|
||||||
|
case 1:
|
||||||
|
return 3.75;
|
||||||
|
default:
|
||||||
|
return 25;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::IRON_DOOR, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
src/pocketmine/block/IronOre.php
Normal file
54
src/pocketmine/block/IronOre.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class IronOre extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::IRON_ORE, 0, "Iron Ore");
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.6;
|
||||||
|
case 4:
|
||||||
|
return 0.75;
|
||||||
|
case 3:
|
||||||
|
return 1.15;
|
||||||
|
default:
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 3){
|
||||||
|
return array(
|
||||||
|
array(Item::IRON_ORE, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
src/pocketmine/block/JungleWoodStairs.php
Normal file
36
src/pocketmine/block/JungleWoodStairs.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class JungleWoodStairs extends Stair{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::JUNGLE_WOOD_STAIRS, $meta, "Jungle Wood Stairs");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array($this->id, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
72
src/pocketmine/block/Ladder.php
Normal file
72
src/pocketmine/block/Ladder.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Ladder extends Transparent{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::LADDER, $meta, "Ladder");
|
||||||
|
$this->isSolid = false;
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->hardness = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
if($target->isTransparent === false){
|
||||||
|
$faces = array(
|
||||||
|
2 => 2,
|
||||||
|
3 => 3,
|
||||||
|
4 => 4,
|
||||||
|
5 => 5,
|
||||||
|
);
|
||||||
|
if(isset($faces[$face])){
|
||||||
|
$this->meta = $faces[$face];
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
/*if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
|
Server::getInstance()->api->entity->drop($this, Item::get(LADDER, 0, 1));
|
||||||
|
$this->level->setBlock($this, new Air(), true, true, true);
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array($this->id, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
55
src/pocketmine/block/Lapis.php
Normal file
55
src/pocketmine/block/Lapis.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Lapis extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::LAPIS_BLOCK, 0, "Lapis Block");
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.6;
|
||||||
|
case 4:
|
||||||
|
return 0.75;
|
||||||
|
case 3:
|
||||||
|
return 1.15;
|
||||||
|
default:
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 3){
|
||||||
|
return array(
|
||||||
|
array(Item::LAPIS_BLOCK, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
56
src/pocketmine/block/LapisOre.php
Normal file
56
src/pocketmine/block/LapisOre.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class LapisOre extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::LAPIS_ORE, 0, "Lapis Ore");
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.6;
|
||||||
|
case 4:
|
||||||
|
return 0.75;
|
||||||
|
case 3:
|
||||||
|
return 1.15;
|
||||||
|
default:
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 3){
|
||||||
|
return array(
|
||||||
|
array(Item::DYE, 4, mt_rand(4, 8)),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
154
src/pocketmine/block/Lava.php
Normal file
154
src/pocketmine/block/Lava.php
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\level\Position;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\Server;
|
||||||
|
|
||||||
|
class Lava extends Liquid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::LAVA, $meta, "Lava");
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||||
|
Server::getInstance()->api->block->scheduleBlockUpdate(clone $this, 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSourceCount(){
|
||||||
|
$count = 0;
|
||||||
|
for($side = 2; $side <= 5; ++$side){
|
||||||
|
if($this->getSide($side) instanceof Lava){
|
||||||
|
$b = $this->getSide($side);
|
||||||
|
$level = $b->meta & 0x07;
|
||||||
|
if($level == 0x00){
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkWater(){
|
||||||
|
for($side = 1; $side <= 5; ++$side){
|
||||||
|
$b = $this->getSide($side);
|
||||||
|
if($b instanceof Water){
|
||||||
|
$level = $this->meta & 0x07;
|
||||||
|
if($level == 0x00){
|
||||||
|
$this->level->setBlock($this, new Obsidian(), false, false, true);
|
||||||
|
}else{
|
||||||
|
$this->level->setBlock($this, new Cobblestone(), false, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFrom(){
|
||||||
|
for($side = 0; $side <= 5; ++$side){
|
||||||
|
$b = $this->getSide($side);
|
||||||
|
if($b instanceof Lava){
|
||||||
|
$tlevel = $b->meta & 0x07;
|
||||||
|
$level = $this->meta & 0x07;
|
||||||
|
if(($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01) || ($tlevel == 6 && $level == 7)){
|
||||||
|
return $b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
//return false;
|
||||||
|
$newId = $this->id;
|
||||||
|
$level = $this->meta & 0x07;
|
||||||
|
if($type !== Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->checkWater()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$falling = $this->meta >> 3;
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
|
||||||
|
$from = $this->getFrom();
|
||||||
|
if($from !== null || $level == 0x00){
|
||||||
|
if($level !== 0x07){
|
||||||
|
if($down instanceof Air || $down instanceof Lava){
|
||||||
|
$this->level->setBlock($down, new Lava(0x01), false, false, true);
|
||||||
|
Server::getInstance()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
}else{
|
||||||
|
for($side = 2; $side <= 5; ++$side){
|
||||||
|
$b = $this->getSide($side);
|
||||||
|
if($b instanceof Lava){
|
||||||
|
|
||||||
|
}elseif($b->isFlowable === true){
|
||||||
|
$this->level->setBlock($b, new Lava(min($level + 2, 7)), false, false, true);
|
||||||
|
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//Extend Remove for Left Lavas
|
||||||
|
for($side = 2; $side <= 5; ++$side){
|
||||||
|
$sb = $this->getSide($side);
|
||||||
|
if($sb instanceof Lava){
|
||||||
|
$tlevel = $sb->meta & 0x07;
|
||||||
|
if($tlevel != 0x00){
|
||||||
|
for($s = 0; $s <= 5; $s++){
|
||||||
|
$ssb = $sb->getSide($s);
|
||||||
|
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
}
|
||||||
|
$this->level->setBlock($sb, new Air(), false, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$b = $this->getSide(0)->getSide($side);
|
||||||
|
if($b instanceof Lava){
|
||||||
|
$tlevel = $b->meta & 0x07;
|
||||||
|
if($tlevel != 0x00){
|
||||||
|
for($s = 0; $s <= 5; $s++){
|
||||||
|
$ssb = $sb->getSide($s);
|
||||||
|
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
}
|
||||||
|
$this->level->setBlock($b, new Air(), false, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
163
src/pocketmine/block/Leaves.php
Normal file
163
src/pocketmine/block/Leaves.php
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Leaves extends Transparent{
|
||||||
|
const OAK = 0;
|
||||||
|
const SPRUCE = 1;
|
||||||
|
const BIRCH = 2;
|
||||||
|
const JUNGLE = 3;
|
||||||
|
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::LEAVES, $meta, "Leaves");
|
||||||
|
$names = array(
|
||||||
|
self::OAK => "Oak Leaves",
|
||||||
|
self::SPRUCE => "Spruce Leaves",
|
||||||
|
self::BIRCH => "Birch Leaves",
|
||||||
|
self::JUNGLE => "Jungle Leaves",
|
||||||
|
);
|
||||||
|
$this->name = $names[$this->meta & 0x03];
|
||||||
|
$this->hardness = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null){
|
||||||
|
++$check;
|
||||||
|
$index = $pos->x . "." . $pos->y . "." . $pos->z;
|
||||||
|
if(isset($visited[$index])){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($pos->getID() === self::WOOD){
|
||||||
|
return true;
|
||||||
|
}elseif($pos->getID() === self::LEAVES and $distance < 3){
|
||||||
|
$visited[$index] = true;
|
||||||
|
$down = $pos->getSide(0)->getID();
|
||||||
|
if($down === Item::WOOD){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if($fromSide === null){
|
||||||
|
for($side = 2; $side <= 5; ++$side){
|
||||||
|
if($this->findLog($pos->getSide($side), $visited, $distance + 1, $check, $side) === true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{ //No more loops
|
||||||
|
switch($fromSide){
|
||||||
|
case 2:
|
||||||
|
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if(($this->meta & 0b00001100) === 0){
|
||||||
|
$this->meta |= 0x08;
|
||||||
|
$this->level->setBlock($this, $this, false, false, true);
|
||||||
|
}
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
if(($this->meta & 0b00001100) === 0x08){
|
||||||
|
$this->meta &= 0x03;
|
||||||
|
$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 Air(), false, false, true);
|
||||||
|
if(mt_rand(1, 20) === 1){ //Saplings
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get(Item::SAPLING, $this->meta & 0x03, 1));
|
||||||
|
}
|
||||||
|
if(($this->meta & 0x03) === self::OAK and mt_rand(1, 200) === 1){ //Apples
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get(Item::APPLE, 0, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$this->meta |= 0x04;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
$drops = array();
|
||||||
|
if($item->isShears()){
|
||||||
|
$drops[] = array(Item::LEAVES, $this->meta & 0x03, 1);
|
||||||
|
}else{
|
||||||
|
if(mt_rand(1, 20) === 1){ //Saplings
|
||||||
|
$drops[] = array(Item::SAPLING, $this->meta & 0x03, 1);
|
||||||
|
}
|
||||||
|
if(($this->meta & 0x03) === self::OAK and mt_rand(1, 200) === 1){ //Apples
|
||||||
|
$drops[] = array(Item::APPLE, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $drops;
|
||||||
|
}
|
||||||
|
}
|
34
src/pocketmine/block/Liquid.php
Normal file
34
src/pocketmine/block/Liquid.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Liquid extends Transparent{
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
parent::__construct($id, $meta, $name);
|
||||||
|
$this->isLiquid = true;
|
||||||
|
$this->breakable = false;
|
||||||
|
$this->isReplaceable = true;
|
||||||
|
$this->isSolid = false;
|
||||||
|
$this->isFullBlock = true;
|
||||||
|
}
|
||||||
|
}
|
45
src/pocketmine/block/LitPumpkin.php
Normal file
45
src/pocketmine/block/LitPumpkin.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class LitPumpkin extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::LIT_PUMPKIN, "Jack o'Lantern");
|
||||||
|
$this->hardness = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$faces = array(
|
||||||
|
0 => 4,
|
||||||
|
1 => 2,
|
||||||
|
2 => 5,
|
||||||
|
3 => 3,
|
||||||
|
);
|
||||||
|
$this->meta = $faces[$player->getDirection()];
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
37
src/pocketmine/block/Melon.php
Normal file
37
src/pocketmine/block/Melon.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Melon extends Transparent{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::MELON_BLOCK, 0, "Melon Block");
|
||||||
|
$this->hardness = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::MELON_SLICE, 0, mt_rand(3, 7)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
102
src/pocketmine/block/MelonStem.php
Normal file
102
src/pocketmine/block/MelonStem.php
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class MelonStem extends Flowable{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::MELON_STEM, $meta, "Melon Stem");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === self::FARMLAND){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get(MELON_SEEDS, 0, mt_rand(0, 2)));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
if(mt_rand(0, 2) == 1){
|
||||||
|
if($this->meta < 0x07){
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}else{
|
||||||
|
for($side = 2; $side <= 5; ++$side){
|
||||||
|
$b = $this->getSide($side);
|
||||||
|
if($b->getID() === self::MELON_BLOCK){
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$side = $this->getSide(mt_rand(2, 5));
|
||||||
|
$d = $side->getSide(0);
|
||||||
|
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
|
||||||
|
$this->level->setBlock($side, new Melon(), true, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
|
$this->meta = 0x07;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
if(($player->gamemode & 0x01) === 0){
|
||||||
|
$item->count--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::MELON_SEEDS, 0, mt_rand(0, 2)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
59
src/pocketmine/block/MossStone.php
Normal file
59
src/pocketmine/block/MossStone.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class MossStone extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::MOSS_STONE, $meta, "Moss Stone");
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.4;
|
||||||
|
case 4:
|
||||||
|
return 0.5;
|
||||||
|
case 3:
|
||||||
|
return 0.75;
|
||||||
|
case 2:
|
||||||
|
return 0.25;
|
||||||
|
case 1:
|
||||||
|
return 1.5;
|
||||||
|
default:
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::MOSS_STONE, $this->meta, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
59
src/pocketmine/block/NetherBrick.php
Normal file
59
src/pocketmine/block/NetherBrick.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class NetherBrick extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::NETHER_BRICKS, 0, "Nether Bricks");
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.4;
|
||||||
|
case 4:
|
||||||
|
return 0.5;
|
||||||
|
case 3:
|
||||||
|
return 0.75;
|
||||||
|
case 2:
|
||||||
|
return 0.25;
|
||||||
|
case 1:
|
||||||
|
return 1.5;
|
||||||
|
default:
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::NETHER_BRICKS, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
src/pocketmine/block/NetherBrickStairs.php
Normal file
30
src/pocketmine/block/NetherBrickStairs.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class NetherBrickStairs extends Stair{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::NETHER_BRICKS_STAIRS, $meta, "Nether Bricks Stairs");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
31
src/pocketmine/block/NetherReactor.php
Normal file
31
src/pocketmine/block/NetherReactor.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class NetherReactor extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::NETHER_REACTOR, $meta, "Nether Reactor");
|
||||||
|
$this->isActivable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
src/pocketmine/block/Netherrack.php
Normal file
59
src/pocketmine/block/Netherrack.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Netherrack extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::NETHERRACK, 0, "Netherrack");
|
||||||
|
$this->hardness = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.1;
|
||||||
|
case 4:
|
||||||
|
return 0.1;
|
||||||
|
case 3:
|
||||||
|
return 0.15;
|
||||||
|
case 2:
|
||||||
|
return 0.05;
|
||||||
|
case 1:
|
||||||
|
return 0.3;
|
||||||
|
default:
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::NETHERRACK, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
src/pocketmine/block/Obsidian.php
Normal file
50
src/pocketmine/block/Obsidian.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Obsidian extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::OBSIDIAN, 0, "Obsidian");
|
||||||
|
$this->hardness = 6000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
|
||||||
|
if($item->isPickaxe() >= 5){
|
||||||
|
return 9.4;
|
||||||
|
}else{
|
||||||
|
return 250;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 5){
|
||||||
|
return array(
|
||||||
|
array(Item::OBSIDIAN, 0, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
src/pocketmine/block/Planks.php
Normal file
38
src/pocketmine/block/Planks.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Planks extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::PLANKS, $meta, "Wooden Planks");
|
||||||
|
$names = array(
|
||||||
|
Wood::OAK => "Oak Wooden Planks",
|
||||||
|
Wood::SPRUCE => "Spruce Wooden Planks",
|
||||||
|
Wood::BIRCH => "Birch Wooden Planks",
|
||||||
|
Wood::JUNGLE => "Jungle Wooden Planks",
|
||||||
|
);
|
||||||
|
$this->name = $names[$this->meta & 0x03];
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
95
src/pocketmine/block/Potato.php
Normal file
95
src/pocketmine/block/Potato.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Potato extends Flowable{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::POTATO_BLOCK, $meta, "Potato Block");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === self::FARMLAND){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
|
$this->meta = 0x07;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
if(($player->gamemode & 0x01) === 0){
|
||||||
|
$item->count--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get(POTATO, 0, 1));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
if(mt_rand(0, 2) == 1){
|
||||||
|
if($this->meta < 0x07){
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
$drops = array();
|
||||||
|
if($this->meta >= 0x07){
|
||||||
|
$drops[] = array(Item::POTATO, 0, mt_rand(1, 4));
|
||||||
|
}else{
|
||||||
|
$drops[] = array(Item::POTATO, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $drops;
|
||||||
|
}
|
||||||
|
}
|
31
src/pocketmine/block/Pumpkin.php
Normal file
31
src/pocketmine/block/Pumpkin.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Pumpkin extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::PUMPKIN, "Pumpkin");
|
||||||
|
$this->hardness = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
102
src/pocketmine/block/PumpkinStem.php
Normal file
102
src/pocketmine/block/PumpkinStem.php
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class PumpkinStem extends Flowable{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::PUMPKIN_STEM, $meta, "Pumpkin Stem");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === self::FARMLAND){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
|
if(mt_rand(0, 2) == 1){
|
||||||
|
if($this->meta < 0x07){
|
||||||
|
++$this->meta;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}else{
|
||||||
|
for($side = 2; $side <= 5; ++$side){
|
||||||
|
$b = $this->getSide($side);
|
||||||
|
if($b->getID() === self::PUMPKIN){
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$side = $this->getSide(mt_rand(2, 5));
|
||||||
|
$d = $side->getSide(0);
|
||||||
|
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
|
||||||
|
$this->level->setBlock($side, new Pumpkin(), true, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
|
$this->meta = 0x07;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
if(($player->gamemode & 0x01) === 0){
|
||||||
|
$item->count--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
65
src/pocketmine/block/Quartz.php
Normal file
65
src/pocketmine/block/Quartz.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Quartz extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::QUARTZ_BLOCK, $meta, "Quartz Block");
|
||||||
|
$names = array(
|
||||||
|
0 => "Quartz Block",
|
||||||
|
1 => "Chiseled Quartz Block",
|
||||||
|
2 => "Quartz Pillar",
|
||||||
|
3 => "Quartz Pillar",
|
||||||
|
);
|
||||||
|
$this->name = $names[$this->meta & 0x03];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.15;
|
||||||
|
case 4:
|
||||||
|
return 0.2;
|
||||||
|
case 3:
|
||||||
|
return 0.3;
|
||||||
|
case 2:
|
||||||
|
return 0.1;
|
||||||
|
case 1:
|
||||||
|
return 0.6;
|
||||||
|
default:
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::QUARTZ_BLOCK, $this->meta & 0x03, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
src/pocketmine/block/QuartzStairs.php
Normal file
30
src/pocketmine/block/QuartzStairs.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class QuartzStairs extends Stair{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::QUARTZ_STAIRS, $meta, "Quartz Stairs");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
src/pocketmine/block/RedMushroom.php
Normal file
58
src/pocketmine/block/RedMushroom.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class RedMushroom extends Flowable{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::RED_MUSHROOM, 0, "Red Mushroom");
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
|
$this->level->setBlock($this, new Air(), false);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->isTransparent === false){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
52
src/pocketmine/block/RedstoneOre.php
Normal file
52
src/pocketmine/block/RedstoneOre.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
|
||||||
|
class RedstoneOre extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::REDSTONE_ORE, 0, "Redstone Ore");
|
||||||
|
$this->hardness = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL or $type === Level::BLOCK_UPDATE_TOUCH){
|
||||||
|
$this->level->setBlock($this, Block::get(Item::GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_WEAK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 2){
|
||||||
|
return array(
|
||||||
|
array(Item::REDSTONE_DUST, 0, mt_rand(4, 5)),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
src/pocketmine/block/Sand.php
Normal file
31
src/pocketmine/block/Sand.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Sand extends Fallable{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::SAND, 0, "Sand");
|
||||||
|
$this->hardness = 2.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
66
src/pocketmine/block/Sandstone.php
Normal file
66
src/pocketmine/block/Sandstone.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
|
class Sandstone extends Solid{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::SANDSTONE, $meta, "Sandstone");
|
||||||
|
$names = array(
|
||||||
|
0 => "Sandstone",
|
||||||
|
1 => "Chiseled Sandstone",
|
||||||
|
2 => "Smooth Sandstone",
|
||||||
|
);
|
||||||
|
$this->name = $names[$this->meta & 0x03];
|
||||||
|
$this->hardness = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.15;
|
||||||
|
case 4:
|
||||||
|
return 0.2;
|
||||||
|
case 3:
|
||||||
|
return 0.3;
|
||||||
|
case 2:
|
||||||
|
return 0.1;
|
||||||
|
case 1:
|
||||||
|
return 0.6;
|
||||||
|
default:
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array(Item::SANDSTONE, $this->meta & 0x03, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
src/pocketmine/block/SandstoneStairs.php
Normal file
30
src/pocketmine/block/SandstoneStairs.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class SandstoneStairs extends Stair{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::SANDSTONE_STAIRS, $meta, "Sandstone Stairs");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
106
src/pocketmine/block/Sapling.php
Normal file
106
src/pocketmine/block/Sapling.php
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\generator\object\Tree;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
use pocketmine\utils\Random;
|
||||||
|
|
||||||
|
class Sapling extends Flowable{
|
||||||
|
const OAK = 0;
|
||||||
|
const SPRUCE = 1;
|
||||||
|
const BIRCH = 2;
|
||||||
|
const JUNGLE = 3;
|
||||||
|
const BURN_TIME = 5;
|
||||||
|
|
||||||
|
public function __construct($meta = Sapling::OAK){
|
||||||
|
parent::__construct(self::SAPLING, $meta, "Sapling");
|
||||||
|
$this->isActivable = true;
|
||||||
|
$names = array(
|
||||||
|
0 => "Oak Sapling",
|
||||||
|
1 => "Spruce Sapling",
|
||||||
|
2 => "Birch Sapling",
|
||||||
|
3 => "Jungle Sapling",
|
||||||
|
);
|
||||||
|
$this->name = $names[$this->meta & 0x03];
|
||||||
|
$this->hardness = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::FARMLAND){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onActivate(Item $item, Player $player = null){
|
||||||
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
|
Tree::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||||
|
if(($player->gamemode & 0x01) === 0){
|
||||||
|
$item->count--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
|
$this->level->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth
|
||||||
|
if(mt_rand(1, 7) === 1){
|
||||||
|
if(($this->meta & 0x08) === 0x08){
|
||||||
|
Tree::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||||
|
}else{
|
||||||
|
$this->meta |= 0x08;
|
||||||
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array($this->id, $this->meta & 0x03, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
85
src/pocketmine/block/SignPost.php
Normal file
85
src/pocketmine/block/SignPost.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class SignPost extends Transparent{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::SIGN_POST, $meta, "Sign Post");
|
||||||
|
$this->isSolid = false;
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->hardness = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
if($face !== 0){
|
||||||
|
$faces = array(
|
||||||
|
2 => 2,
|
||||||
|
3 => 3,
|
||||||
|
4 => 4,
|
||||||
|
5 => 5,
|
||||||
|
);
|
||||||
|
if(!isset($faces[$face])){
|
||||||
|
$this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
|
||||||
|
$this->level->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
$this->meta = $faces[$face];
|
||||||
|
$this->level->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
|
//TODO
|
||||||
|
//Server::getInstance()->api->entity->drop($this, Item::get(SIGN, 0, 1));
|
||||||
|
$this->level->setBlock($this, new Air(), true, true, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onBreak(Item $item){
|
||||||
|
$this->level->setBlock($this, new Air(), true, true, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
return array(
|
||||||
|
array(Item::SIGN, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
125
src/pocketmine/block/Slab.php
Normal file
125
src/pocketmine/block/Slab.php
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class Slab extends Transparent{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::SLAB, $meta, "Slab");
|
||||||
|
$names = array(
|
||||||
|
0 => "Stone",
|
||||||
|
1 => "Sandstone",
|
||||||
|
2 => "Wooden",
|
||||||
|
3 => "Cobblestone",
|
||||||
|
4 => "Brick",
|
||||||
|
5 => "Stone Brick",
|
||||||
|
6 => "Quartz",
|
||||||
|
7 => "",
|
||||||
|
);
|
||||||
|
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab";
|
||||||
|
if(($this->meta & 0x08) === 0x08){
|
||||||
|
$this->isFullBlock = true;
|
||||||
|
}else{
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
}
|
||||||
|
$this->hardness = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$this->meta &= 0x07;
|
||||||
|
if($face === 0){
|
||||||
|
if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
|
$this->level->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
|
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
$this->meta |= 0x08;
|
||||||
|
}
|
||||||
|
}elseif($face === 1){
|
||||||
|
if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
|
$this->level->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
|
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}elseif(!($player instanceof Player) or !$player->inBlock($block)){
|
||||||
|
if($block->getID() === self::SLAB){
|
||||||
|
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
|
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
if($fy > 0.5){
|
||||||
|
$this->meta |= 0x08;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($block->getID() === self::SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBreakTime(Item $item){
|
||||||
|
|
||||||
|
switch($item->isPickaxe()){
|
||||||
|
case 5:
|
||||||
|
return 0.4;
|
||||||
|
case 4:
|
||||||
|
return 0.5;
|
||||||
|
case 3:
|
||||||
|
return 0.75;
|
||||||
|
case 2:
|
||||||
|
return 0.25;
|
||||||
|
case 1:
|
||||||
|
return 1.5;
|
||||||
|
default:
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isPickaxe() >= 1){
|
||||||
|
return array(
|
||||||
|
array($this->id, $this->meta & 0x07, 1),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
src/pocketmine/block/Snow.php
Normal file
31
src/pocketmine/block/Snow.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Snow extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::SNOW_BLOCK, 0, "Snow Block");
|
||||||
|
$this->hardness = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
69
src/pocketmine/block/SnowLayer.php
Normal file
69
src/pocketmine/block/SnowLayer.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\item\Item;
|
||||||
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
class SnowLayer extends Flowable{
|
||||||
|
public function __construct($meta = 0){
|
||||||
|
parent::__construct(self::SNOW_LAYER, $meta, "Snow Layer");
|
||||||
|
$this->isReplaceable = true;
|
||||||
|
$this->isSolid = false;
|
||||||
|
$this->isFullBlock = false;
|
||||||
|
$this->hardness = 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
|
$down = $this->getSide(0);
|
||||||
|
if($down instanceof Solid){
|
||||||
|
$this->level->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onUpdate($type){
|
||||||
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
|
$this->level->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDrops(Item $item){
|
||||||
|
if($item->isShovel() !== false){
|
||||||
|
return array(
|
||||||
|
array(Item::SNOWBALL, 0, 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
32
src/pocketmine/block/Solid.php
Normal file
32
src/pocketmine/block/Solid.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Solid extends Generic{
|
||||||
|
|
||||||
|
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||||
|
parent::__construct($id, $meta, $name);
|
||||||
|
$this->isSolid = true;
|
||||||
|
$this->isFullBlock = true;
|
||||||
|
}
|
||||||
|
}
|
31
src/pocketmine/block/SoulSand.php
Normal file
31
src/pocketmine/block/SoulSand.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class SoulSand extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::SOUL_SAND, 0, "Soul Sand");
|
||||||
|
$this->hardness = 2.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
31
src/pocketmine/block/Sponge.php
Normal file
31
src/pocketmine/block/Sponge.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
|
||||||
|
class Sponge extends Solid{
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct(self::SPONGE, "Sponge");
|
||||||
|
$this->hardness = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user