Finally, I can spawn AGAIN!

This commit is contained in:
Shoghi Cervantes 2014-03-11 20:45:53 +01:00
parent b4df7c9456
commit b3a2d3164f
207 changed files with 1407 additions and 1253 deletions

View File

@ -176,7 +176,7 @@ $explosion->explode();
public function getDrops(){ public function getDrops(){
if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){ if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){
$inv = array(); $inv = array();
for($i = 0; $i < PLAYER_SURVIVAL_SLOTS; ++$i){ for($i = 0; $i < Player::SURVIVAL_SLOTS; ++$i){
$slot = $this->player->getSlot($i); $slot = $this->player->getSlot($i);
$this->player->setSlot($i, Item\Item::get(AIR, 0, 0)); $this->player->setSlot($i, Item\Item::get(AIR, 0, 0));
if($slot->getID() !== AIR and $slot->getCount() > 0){ if($slot->getID() !== AIR and $slot->getCount() > 0){

View File

@ -21,7 +21,9 @@
namespace PocketMine; namespace PocketMine;
use PocketMine\Utils\Config as Config; use PocketMine\Level\Level;
use PocketMine\Math\Vector2;
use PocketMine\Utils\Config;
class BanAPI{ class BanAPI{
private $server; private $server;
@ -103,7 +105,7 @@ class BanAPI{
case "player.block.place": //Spawn protection detection. Allows OPs to place/break blocks in the spawn area. case "player.block.place": //Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
if(!$this->isOp($data["player"]->getUsername())){ if(!$this->isOp($data["player"]->getUsername())){
$t = new Vector2($data["target"]->x, $data["target"]->z); $t = new Vector2($data["target"]->x, $data["target"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->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){ if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
return false; return false;
} }
@ -255,7 +257,7 @@ class BanAPI{
$ip = strtolower($params[0]); $ip = strtolower($params[0]);
$player = Player::get($ip); $player = Player::get($ip);
if($player instanceof Player){ if($player instanceof Player){
$ip = $player->ip; $ip = $player->getIP();
$player->close("banned"); $player->close("banned");
} }
$this->bannedIPs->set($ip); $this->bannedIPs->set($ip);

View File

@ -21,15 +21,15 @@
namespace PocketMine; namespace PocketMine;
use PocketMine\Block\Block as Block; use PocketMine\Level\Level;
use PocketMine\Block\GenericBlock as GenericBlock; use PocketMine\Block\Block;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Position as Position; use PocketMine\Level\Position;
use PocketMine\NBT\Tag\Compound as Compound; use PocketMine\NBT\Tag\Compound;
use PocketMine\NBT\Tag\Int as Int; use PocketMine\NBT\Tag\Int;
use PocketMine\NBT\Tag\String as String; use PocketMine\NBT\Tag\String;
use PocketMine\Network\Protocol\UpdateBlockPacket as UpdateBlockPacket; use PocketMine\Network\Protocol\UpdateBlockPacket;
use PocketMine\Tile\Sign as Sign; use PocketMine\Tile\Sign;
class BlockAPI{ class BlockAPI{
private $server; private $server;
@ -388,7 +388,7 @@ class BlockAPI{
return $this->cancelAction($block, $player); return $this->cancelAction($block, $player);
} }
} }
$this->blockUpdate($target, BLOCK_UPDATE_TOUCH); $this->blockUpdate($target, Level::BLOCK_UPDATE_TOUCH);
if($target->isActivable === true){ if($target->isActivable === true){
if($this->server->api->dhandle("player.block.activate", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== false and $target->onActivate($item, $player) === true){ if($this->server->api->dhandle("player.block.activate", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== false and $target->onActivate($item, $player) === true){
@ -469,7 +469,7 @@ class BlockAPI{
return false; return false;
} }
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){ public function blockUpdateAround(Position $pos, $type = Level::BLOCK_UPDATE_NORMAL, $delay = false){
if($delay !== false){ if($delay !== false){
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
@ -487,7 +487,7 @@ class BlockAPI{
} }
} }
public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){ public function blockUpdate(Position $pos, $type = Level::BLOCK_UPDATE_NORMAL){
if(!($pos instanceof Block)){ if(!($pos instanceof Block)){
$block = $pos->level->getBlock($pos); $block = $pos->level->getBlock($pos);
} else{ } else{
@ -499,14 +499,14 @@ class BlockAPI{
} }
$level = $block->onUpdate($type); $level = $block->onUpdate($type);
if($level === BLOCK_UPDATE_NORMAL){ if($level === Level::BLOCK_UPDATE_NORMAL){
$this->blockUpdateAround($block, $level); $this->blockUpdateAround($block, $level);
} }
return $level; return $level;
} }
public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){ public function scheduleBlockUpdate(Position $pos, $delay, $type = Level::BLOCK_UPDATE_SCHEDULED){
$type = (int) $type; $type = (int) $type;
if($delay < 0){ if($delay < 0){
return false; return false;

View File

@ -21,7 +21,8 @@
namespace PocketMine; namespace PocketMine;
use PocketMine\Utils\TextFormat as TextFormat; use PocketMine\Level\Level;
use PocketMine\Utils\TextFormat;
class ConsoleAPI{ class ConsoleAPI{
private $loop, $server, $event, $help, $cmds, $alias; private $loop, $server, $event, $help, $cmds, $alias;
@ -207,7 +208,7 @@ class ConsoleAPI{
break; break;
case "w": case "w":
case "world": case "world":
$p = ($issuer instanceof Player) ? $issuer->level->getName() : $this->server->api->level->getDefault()->getName(); $p = ($issuer instanceof Player) ? $issuer->level->getName() : Level::getDefault()->getName();
$params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1); $params = substr_replace($params, $p, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1);
$offsetshift -= strlen($selector[0]) - strlen($p) + 1; $offsetshift -= strlen($selector[0]) - strlen($p) + 1;
break; break;

View File

@ -21,44 +21,13 @@
namespace PocketMine; namespace PocketMine;
use PocketMine\Level\Generator\Flat as Flat; use PocketMine\Level\Level;
use PocketMine\Level\Generator\Normal as Normal;
use PocketMine\Level\Level as Level;
use PocketMine\Level\LevelImport as LevelImport;
use PocketMine\Level\Position as Position;
use PocketMine\Level\WorldGenerator as WorldGenerator;
use PocketMine\NBT\Tag\Byte as Byte;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Enum as Enum;
use PocketMine\NBT\Tag\Int as Int;
use PocketMine\NBT\Tag\Short as Short;
use PocketMine\NBT\Tag\String as String;
use PocketMine\PMF\LevelFormat as LevelFormat;
use PocketMine\Tile\Chest as Chest;
use PocketMine\Tile\Furnace as Furnace;
use PocketMine\Tile\Sign as Sign;
use PocketMine\Tile\Tile as Tile;
use PocketMine\Utils\Config as Config;
use PocketMine\Utils\Utils as Utils;
class LevelAPI{ class LevelAPI{
private $server, $levels, $default; private $server;
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->levels = array();
}
public function get($name){
if(isset($this->levels[$name])){
return $this->levels[$name];
}
return false;
}
public function getDefault(){
return $this->levels[$this->default];
} }
public function init(){ public function init(){
@ -66,12 +35,6 @@ class LevelAPI{
$this->server->api->console->register("save-all", "", array($this, "commandHandler")); $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-on", "", array($this, "commandHandler"));
$this->server->api->console->register("save-off", "", array($this, "commandHandler")); $this->server->api->console->register("save-off", "", array($this, "commandHandler"));
$this->default = $this->server->api->getProperty("level-name");
if($this->loadLevel($this->default) === false){
$this->generateLevel($this->default, $this->server->seed);
$this->loadLevel($this->default);
}
$this->server->spawn = $this->getDefault()->getSafeSpawn();
} }
public function commandHandler($cmd, $params, $issuer, $alias){ public function commandHandler($cmd, $params, $issuer, $alias){
@ -80,7 +43,7 @@ class LevelAPI{
case "save-all": case "save-all":
$save = $this->server->saveEnabled; $save = $this->server->saveEnabled;
$this->server->saveEnabled = true; $this->server->saveEnabled = true;
$this->saveAll(); Level::saveAll();
$this->server->saveEnabled = $save; $this->server->saveEnabled = $save;
break; break;
case "save-on": case "save-on":
@ -93,220 +56,22 @@ class LevelAPI{
if(!isset($params[0]) and ($issuer instanceof Player)){ if(!isset($params[0]) and ($issuer instanceof Player)){
$output .= "Seed: " . $issuer->level->getSeed() . "\n"; $output .= "Seed: " . $issuer->level->getSeed() . "\n";
} elseif(isset($params[0])){ } elseif(isset($params[0])){
if(($lv = $this->server->api->level->get(trim(implode(" ", $params)))) !== false){ if(($lv = Level::get(trim(implode(" ", $params)))) !== false){
$output .= "Seed: " . $lv->getSeed() . "\n"; $output .= "Seed: " . $lv->getSeed() . "\n";
} }
} else{ } else{
$output .= "Seed: " . $this->server->api->level->getDefault()->getSeed() . "\n"; $output .= "Seed: " . Level::getDefault()->getSeed() . "\n";
} }
} }
return $output; return $output;
} }
public function generateLevel($name, $seed = false, $generator = false){
if($name == "" or $this->levelExists($name)){
return false;
}
$options = array();
if($this->server->api->getProperty("generator-settings") !== false and trim($this->server->api->getProperty("generator-settings")) != ""){
$options["preset"] = $this->server->api->getProperty("generator-settings");
}
if($generator !== false and class_exists($generator)){
$generator = new $generator($options);
} else{
if(strtoupper($this->server->api->getProperty("level-type")) == "FLAT"){
$generator = new Flat($options);
} else{
$generator = new Normal($options);
}
}
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);
$gen->generate();
$gen->close();
return true;
}
public function levelExists($name){
if($name === ""){
return false;
}
$path = \PocketMine\DATA . "worlds/" . $name . "/";
if($this->get($name) === false and !file_exists($path . "level.pmf")){
$level = new LevelImport($path);
if($level->import() === false){
return false;
}
}
return true;
}
public function unloadLevel(Level $level, $force = false){
$name = $level->getName();
if($name === $this->default and $force !== true){
return false;
}
console("[INFO] Unloading level \"" . $name . "\"");
$level->nextSave = PHP_INT_MAX;
$level->save();
foreach($level->getPlayers() as $player){
$player->teleport($this->server->spawn);
}
$level->close();
unset($this->levels[$name]);
return true;
}
public function loadLevel($name){
if($this->get($name) !== false){
return true;
} elseif($this->levelExists($name) === false){
console("[NOTICE] Level \"" . $name . "\" not found");
return false;
}
$path = \PocketMine\DATA . "worlds/" . $name . "/";
console("[INFO] Preparing level \"" . $name . "\"");
$level = new LevelFormat($path . "level.pmf");
if(!$level->isLoaded){
console("[ERROR] Could not load level \"" . $name . "\"");
return false;
}
//$entities = new Config($path."entities.yml", Config::YAML);
if(file_exists($path . "tileEntities.yml")){
@rename($path . "tileEntities.yml", $path . "tiles.yml");
}
$blockUpdates = new Config($path . "bupdates.yml", Config::YAML);
$this->levels[$name] = new Level($level, $name);
/*foreach($entities->getAll() as $entity){
if(!isset($entity["id"])){
break;
}
if($entity["id"] === 64){ //Item Drop
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, $entity["Item"]["id"], array(
"meta" => $entity["Item"]["Damage"],
"stack" => $entity["Item"]["Count"],
"x" => $entity["Pos"][0],
"y" => $entity["Pos"][1],
"z" => $entity["Pos"][2],
"yaw" => $entity["Rotation"][0],
"pitch" => $entity["Rotation"][1],
));
}elseif($entity["id"] === FALLING_SAND){
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity);
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]);
}elseif($entity["id"] === OBJECT_PAINTING or $entity["id"] === OBJECT_ARROW){ //Painting
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity);
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth(1);
}else{
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity);
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]);
}
}*/
if(file_exists($path . "tiles.yml")){
$tiles = new Config($path . "tiles.yml", Config::YAML);
foreach($tiles->getAll() as $tile){
if(!isset($tile["id"])){
continue;
}
$this->levels[$name]->loadChunk($tile["x"] >> 4, $tile["z"] >> 4);
$nbt = new Compound(false, array());
foreach($tile as $index => $data){
switch($index){
case "Items":
$tag = new Enum("Items", array());
$tag->setTagType(NBT::TAG_Compound);
foreach($data as $slot => $fields){
$tag[(int) $slot] = new Compound(false, array(
"Count" => new Byte("Count", $fields["Count"]),
"Slot" => new Short("Slot", $fields["Slot"]),
"Damage" => new Short("Damage", $fields["Damage"]),
"id" => new String("id", $fields["id"])
));
}
$nbt["Items"] = $tag;
break;
case "id":
case "Text1":
case "Text2":
case "Text3":
case "Text4":
$nbt[$index] = new String($index, $data);
break;
case "x":
case "y":
case "z":
case "pairx":
case "pairz":
$nbt[$index] = new Int($index, $data);
break;
case "BurnTime":
case "CookTime":
case "MaxTime":
$nbt[$index] = new Short($index, $data);
break;
}
}
switch($tile["id"]){
case Tile::FURNACE:
new Furnace($this->levels[$name], $nbt);
break;
case Tile::CHEST:
new Chest($this->levels[$name], $nbt);
break;
case Tile::SIGN:
new Sign($this->levels[$name], $nbt);
break;
}
}
unlink($path . "tiles.yml");
$this->levels[$name]->save(true, true);
}
foreach($blockUpdates->getAll() as $bupdate){
$this->server->api->block->scheduleBlockUpdate(new Position((int) $bupdate["x"], (int) $bupdate["y"], (int) $bupdate["z"], $this->levels[$name]), (float) $bupdate["delay"], (int) $bupdate["type"]);
}
return true;
}
public function handle($data, $event){
switch($event){
}
}
public function saveAll(){
foreach($this->levels as $level){
$level->save();
}
}
public function __destruct(){ public function __destruct(){
$this->saveAll(); Level::saveAll();
foreach($this->levels as $level){ foreach(Level::getAll() as $level){
$this->unloadLevel($level, true); $level->unload(true);
} }
} }
public function getSpawn(){
return $this->server->spawn;
}
public function getAll(){
return $this->levels;
}
} }

View File

@ -21,62 +21,74 @@
namespace PocketMine; namespace PocketMine;
use PocketMine\Entity\RealHuman as RealHuman; use PocketMine\Level\Level;
use PocketMine\Event\Event as Event; use PocketMine\Entity\RealHuman;
use PocketMine\Event\EventHandler as EventHandler; use PocketMine\Event;
use PocketMine\Event\Server\DataPacketReceiveEvent as DataPacketReceiveEvent; use PocketMine\Event\EventHandler;
use PocketMine\Event\Server\DataPacketSendEvent as DataPacketSendEvent; use PocketMine\Event\Server\DataPacketReceiveEvent;
use PocketMine\Item\Item as Item; use PocketMine\Event\Server\DataPacketSendEvent;
use PocketMine\Level\Position as Position; use PocketMine\Item\Item;
use PocketMine\Level\Position;
use PocketMine\Math\Vector3 as Vector3; use PocketMine\Math\Vector3 as Vector3;
use PocketMine\NBT\NBT as NBT; use PocketMine\NBT\NBT;
use PocketMine\NBT\Tag\Byte as Byte; use PocketMine\NBT\Tag\Byte;
use PocketMine\NBT\Tag\Compound as Compound; use PocketMine\NBT\Tag\Compound;
use PocketMine\NBT\Tag\Double as Double; use PocketMine\NBT\Tag\Double;
use PocketMine\NBT\Tag\Enum as Enum; use PocketMine\NBT\Tag\Enum;
use PocketMine\NBT\Tag\Float as Float; use PocketMine\NBT\Tag\Float;
use PocketMine\NBT\Tag\Int as Int; use PocketMine\NBT\Tag\Int;
use PocketMine\NBT\Tag\Short as Short; use PocketMine\NBT\Tag\Short;
use PocketMine\NBT\Tag\String as String; use PocketMine\NBT\Tag\String;
use PocketMine\Network\Protocol\AdventureSettingsPacket as AdventureSettingsPacket; use PocketMine\Network\Protocol\AdventureSettingsPacket;
use PocketMine\Network\Protocol\AnimatePacket as AnimatePacket; use PocketMine\Network\Protocol\AnimatePacket;
use PocketMine\Network\Protocol\ChunkDataPacket as ChunkDataPacket; use PocketMine\Network\Protocol\ChunkDataPacket;
use PocketMine\Network\Protocol\ContainerClosePacket as ContainerClosePacket; use PocketMine\Network\Protocol\ContainerClosePacket;
use PocketMine\Network\Protocol\ContainerSetContentPacket as ContainerSetContentPacket; use PocketMine\Network\Protocol\ContainerSetContentPacket;
use PocketMine\Network\Protocol\ContainerSetDataPacket as ContainerSetDataPacket; use PocketMine\Network\Protocol\ContainerSetDataPacket;
use PocketMine\Network\Protocol\ContainerSetSlotPacket as ContainerSetSlotPacket; use PocketMine\Network\Protocol\ContainerSetSlotPacket;
use PocketMine\Network\Protocol\DataPacket as DataPacket; use PocketMine\Network\Protocol\DataPacket;
use PocketMine\Network\Protocol\DisconnectPacket as DisconnectPacket; use PocketMine\Network\Protocol\DisconnectPacket;
use PocketMine\Network\Protocol\EntityEventPacket as EntityEventPacket; use PocketMine\Network\Protocol\EntityEventPacket;
use PocketMine\Network\Protocol\Info as ProtocolInfo; use PocketMine\Network\Protocol\Info as ProtocolInfo;
use PocketMine\Network\Protocol\LoginStatusPacket as LoginStatusPacket; use PocketMine\Network\Protocol\LoginStatusPacket;
use PocketMine\Network\Protocol\MessagePacket as MessagePacket; use PocketMine\Network\Protocol\MessagePacket;
use PocketMine\Network\Protocol\PongPacket as PongPacket; use PocketMine\Network\Protocol\PongPacket;
use PocketMine\Network\Protocol\ServerHandshakePacket as ServerHandshakePacket; use PocketMine\Network\Protocol\ServerHandshakePacket;
use PocketMine\Network\Protocol\SetEntityDataPacket as SetEntityDataPacket; use PocketMine\Network\Protocol\SetEntityDataPacket;
use PocketMine\Network\Protocol\SetSpawnPositionPacket as SetSpawnPositionPacket; use PocketMine\Network\Protocol\SetSpawnPositionPacket;
use PocketMine\Network\Protocol\SetTimePacket as SetTimePacket; use PocketMine\Network\Protocol\SetTimePacket;
use PocketMine\Network\Protocol\StartGamePacket as StartGamePacket; use PocketMine\Network\Protocol\StartGamePacket;
use PocketMine\Network\Protocol\TakeItemEntityPacket as TakeItemEntityPacket; use PocketMine\Network\Protocol\TakeItemEntityPacket;
use PocketMine\Network\Protocol\TileEventPacket as TileEventPacket; use PocketMine\Network\Protocol\TileEventPacket;
use PocketMine\Network\Protocol\UnknownPacket as UnknownPacket; use PocketMine\Network\Protocol\UnknownPacket;
use PocketMine\Network\Protocol\UpdateBlockPacket as UpdateBlockPacket; use PocketMine\Network\Protocol\UpdateBlockPacket;
use PocketMine\Network\RakNet\Info as Info; use PocketMine\Network\RakNet\Info;
use PocketMine\Network\RakNet\Packet as Packet; use PocketMine\Network\RakNet\Packet;
use PocketMine\PMF\LevelFormat as LevelFormat; use PocketMine\PMF\LevelFormat;
use PocketMine\Recipes\Crafting as Crafting; use PocketMine\Recipes\Crafting;
use PocketMine\Tile\Chest as Chest; use PocketMine\Tile\Chest;
use PocketMine\Tile\Furnace as Furnace; use PocketMine\Tile\Furnace;
use PocketMine\Tile\Sign as Sign; use PocketMine\Tile\Sign;
use PocketMine\Tile\Spawnable as Spawnable; use PocketMine\Tile\Spawnable;
use PocketMine\Tile\Tile as Tile; use PocketMine\Tile\Tile;
use PocketMine\Utils\Config as Config; use PocketMine\Utils\Config;
use PocketMine\Utils\TextFormat as TextFormat; use PocketMine\Utils\TextFormat;
use PocketMine\Utils\Utils as Utils; use PocketMine\Utils\Utils;
/**
* Main class that handles networking, recovery, and packet sending to the server part
* TODO: Move reliability layer
*
* Class Player
* @package PocketMine
*/
class Player extends RealHuman{ class Player extends RealHuman{
public static $list = array(); public static $list = array();
const MAX_QUEUE = 2048;
const SURVIVAL_SLOTS = 36;
const CREATIVE_SLOTS = 112; //????
private $recoveryQueue = array(); private $recoveryQueue = array();
private $receiveQueue = array(); private $receiveQueue = array();
private $resendQueue = array(); private $resendQueue = array();
@ -166,17 +178,18 @@ class Player extends RealHuman{
$server = ServerAPI::request(); $server = ServerAPI::request();
$iname = strtolower($name); $iname = strtolower($name);
if(!file_exists(\PocketMine\DATA . "players/" . $iname . ".dat")){ if(!file_exists(\PocketMine\DATA . "players/" . $iname . ".dat")){
$spawn = Level::getDefault()->getSafeSpawn();
$nbt = new Compound(false, array( $nbt = new Compound(false, array(
"Pos" => new Enum("Pos", array( "Pos" => new Enum("Pos", array(
0 => new Double(0, $server->spawn->x), 0 => new Double(0, $spawn->x),
1 => new Double(1, $server->spawn->y), 1 => new Double(1, $spawn->y),
2 => new Double(2, $server->spawn->z) 2 => new Double(2, $spawn->z)
)), )),
"Level" => new String("Level", $server->spawn->level->getName()), "Level" => new String("Level", Level::getDefault()->getName()),
"SpawnLevel" => new String("SpawnLevel", $server->spawn->level->getName()), "SpawnLevel" => new String("SpawnLevel", Level::getDefault()->getName()),
"SpawnX" => new Int("SpawnX", (int) $server->spawn->x), "SpawnX" => new Int("SpawnX", (int) $spawn->x),
"SpawnY" => new Int("SpawnY", (int) $server->spawn->y), "SpawnY" => new Int("SpawnY", (int) $spawn->y),
"SpawnZ" => new Int("SpawnZ", (int) $server->spawn->z), "SpawnZ" => new Int("SpawnZ", (int) $spawn->z),
"SpawnForced" => new Byte("SpawnForced", 1), //TODO "SpawnForced" => new Byte("SpawnForced", 1), //TODO
"Inventory" => new Enum("Inventory", array()), "Inventory" => new Enum("Inventory", array()),
"Achievements" => new Compound("Achievements", array()), "Achievements" => new Compound("Achievements", array()),
@ -363,10 +376,10 @@ class Player extends RealHuman{
Player::$list[$this->CID] = $this; Player::$list[$this->CID] = $this;
$this->ip = $ip; $this->ip = $ip;
$this->port = $port; $this->port = $port;
$this->spawnPosition = $this->server->spawn; $this->spawnPosition = Level::getDefault()->getSafeSpawn();
$this->timeout = microtime(true) + 20; $this->timeout = microtime(true) + 20;
$this->gamemode = $this->server->gamemode; $this->gamemode = $this->server->gamemode;
$this->level = $this->server->api->level->getDefault(); $this->level = Level::getDefault();
$this->viewDistance = (int) $this->server->api->getProperty("view-distance"); $this->viewDistance = (int) $this->server->api->getProperty("view-distance");
$this->slot = 0; $this->slot = 0;
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1); $this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
@ -384,7 +397,9 @@ class Player extends RealHuman{
} }
/** /**
* @param Vector3 $pos * Sets the spawnpoint of the player (and the compass direction) to a Vector3, or set it on another world with a Position object
*
* @param Vector3|Position $pos
*/ */
public function setSpawn(Vector3 $pos){ public function setSpawn(Vector3 $pos){
if(!($pos instanceof Position)){ if(!($pos instanceof Position)){
@ -942,39 +957,37 @@ class Player extends RealHuman{
} }
switch($item->getID()){ switch($item->getID()){
case WORKBENCH: case Item::WORKBENCH:
$this->grantAchievement("buildWorkBench"); $this->grantAchievement("buildWorkBench");
break; break;
case WOODEN_PICKAXE: case Item::WOODEN_PICKAXE:
$this->grantAchievement("buildPickaxe"); $this->grantAchievement("buildPickaxe");
break; break;
case FURNACE: case Item::FURNACE:
$this->grantAchievement("buildFurnace"); $this->grantAchievement("buildFurnace");
break; break;
case WOODEN_HOE: case Item::WOODEN_HOE:
$this->grantAchievement("buildHoe"); $this->grantAchievement("buildHoe");
break; break;
case BREAD: case Item::BREAD:
$this->grantAchievement("makeBread"); $this->grantAchievement("makeBread");
break; break;
case CAKE: case Item::CAKE:
$this->grantAchievement("bakeCake"); $this->grantAchievement("bakeCake");
$this->addItem(Item::get(Item::BUCKET, 0, 3));
break; break;
case STONE_PICKAXE: case Item::STONE_PICKAXE:
case GOLD_PICKAXE: case Item::GOLD_PICKAXE:
case IRON_PICKAXE: case Item::IRON_PICKAXE:
case DIAMOND_PICKAXE: case Item::DIAMOND_PICKAXE:
$this->grantAchievement("buildBetterPickaxe"); $this->grantAchievement("buildBetterPickaxe");
break; break;
case WOODEN_SWORD: case Item::WOODEN_SWORD:
$this->grantAchievement("buildSword"); $this->grantAchievement("buildSword");
break; break;
case DIAMOND: case Item::DIAMOND:
$this->grantAchievement("diamond"); $this->grantAchievement("diamond");
break; break;
case CAKE:
$this->addItem(Item::get(BUCKET, 0, 3));
break;
} }
} }
@ -1062,11 +1075,11 @@ class Player extends RealHuman{
return false; return false;
} }
ksort($this->received); ksort($this->received);
if(($cnt = count($this->received)) > PLAYER_MAX_QUEUE){ if(($cnt = count($this->received)) > self::MAX_QUEUE){
foreach($this->received as $c => $t){ foreach($this->received as $c => $t){
unset($this->received[$c]); unset($this->received[$c]);
--$cnt; --$cnt;
if($cnt <= PLAYER_MAX_QUEUE){ if($cnt <= self::MAX_QUEUE){
break; break;
} }
} }
@ -1220,7 +1233,7 @@ class Player extends RealHuman{
return; return;
} }
if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === Event::DENY){ if(EventHandler::callEvent(new Event\Server\DataPacketReceiveEvent($this, $packet)) === Event\Event::DENY){
return; return;
} }
@ -1313,8 +1326,8 @@ class Player extends RealHuman{
$nbt = Player::getOffline($this->username); $nbt = Player::getOffline($this->username);
$nbt->NameTag = $this->username; $nbt->NameTag = $this->username;
$this->gamemode = $nbt->playerGameType & 0x03; $this->gamemode = $nbt->playerGameType & 0x03;
if(($this->level = $this->server->api->level->get($nbt->Level)) === false){ if(($this->level = Level::get($nbt->Level)) === false){
$this->level = $this->server->api->level->getDefault(); $this->level = Level::getDefault();
$nbt->Level = $this->level->getName(); $nbt->Level = $this->level->getName();
$nbt->Pos[0] = $this->level->getSpawn()->x; $nbt->Pos[0] = $this->level->getSpawn()->x;
$nbt->Pos[1] = $this->level->getSpawn()->y; $nbt->Pos[1] = $this->level->getSpawn()->y;
@ -1334,7 +1347,7 @@ class Player extends RealHuman{
} }
$this->achievements = array(); $this->achievements = array();
foreach($nbt->Achievements->getValue() as $achievement){ foreach($nbt->Achievements as $achievement){
$this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false; $this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
} }
@ -1365,7 +1378,7 @@ class Player extends RealHuman{
$this->dataPacket($pk); $this->dataPacket($pk);
if(($level = $this->server->api->level->get($this->namedtag->SpawnLevel)) !== false){ if(($level = Level::get($this->namedtag->SpawnLevel)) !== false){
$this->spawnPosition = new Position($this->namedtag->SpawnX, $this->namedtag->SpawnY, $this->namedtag->SpawnZ, $level); $this->spawnPosition = new Position($this->namedtag->SpawnX, $this->namedtag->SpawnY, $this->namedtag->SpawnZ, $level);
$pk = new SetSpawnPositionPacket; $pk = new SetSpawnPositionPacket;
@ -1478,7 +1491,7 @@ class Player extends RealHuman{
$item = $this->getSlot($packet->slot); $item = $this->getSlot($packet->slot);
} }
if($packet->slot === false or EventHandler::callEvent(new PlayerEquipmentChangeEvent($this, $item, $packet->slot, 0)) === Event::DENY){ if($packet->slot === false or EventHandler::callEvent(new Event\Player\PlayerEquipmentChangeEvent($this, $item, $packet->slot, 0)) === Event\Event::DENY){
$this->sendInventorySlot($packet->slot); $this->sendInventorySlot($packet->slot);
} else{ } else{
$this->setEquipmentSlot(0, $packet->slot); $this->setEquipmentSlot(0, $packet->slot);
@ -2262,7 +2275,7 @@ class Player extends RealHuman{
return false; return false;
} }
if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === Event::DENY){ if(EventHandler::callEvent(new Event\Server\DataPacketSendEvent($this, $packet)) === Event\Event::DENY){
return array(); return array();
} }
$packet->encode(); $packet->encode();
@ -2280,8 +2293,7 @@ class Player extends RealHuman{
} }
/** /**
* @param integer $id * @param DataPacket $packet
* @param array $data
* *
* @return array|bool * @return array|bool
*/ */
@ -2290,7 +2302,7 @@ class Player extends RealHuman{
return false; return false;
} }
if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === Event::DENY){ if(EventHandler::callEvent(new Event\Server\DataPacketSendEvent($this, $packet)) === Event\Event::DENY){
return; return;
} }

View File

@ -21,9 +21,9 @@
namespace PocketMine; namespace PocketMine;
use PocketMine\Entity\Entity as Entity; use PocketMine\Entity\Entity;
use PocketMine\Level\Level as Level; use PocketMine\Level\Level;
use PocketMine\Level\Position as Position; use PocketMine\Level\Position;
use PocketMine\Math\Vector3 as Vector3; use PocketMine\Math\Vector3 as Vector3;
class PlayerAPI{ class PlayerAPI{
@ -139,7 +139,7 @@ class PlayerAPI{
if(count($params) === 1 or count($params) === 4){ if(count($params) === 1 or count($params) === 4){
$tg = array_shift($params); $tg = array_shift($params);
if(count($params) === 3 and substr($tg, 0, 2) === "w:"){ if(count($params) === 3 and substr($tg, 0, 2) === "w:"){
$target = $this->server->api->level->get(substr($tg, 2)); $target = Level::get(substr($tg, 2));
} else{ } else{
$target = Player::get($tg); $target = Player::get($tg);
} }
@ -176,7 +176,7 @@ class PlayerAPI{
$output .= "Please run this command in-game.\n"; $output .= "Please run this command in-game.\n";
break; break;
} }
$issuer->teleport($this->server->spawn); $issuer->teleport(Level::getDefault()->getSafeSpawn());
break; break;
case "ping": case "ping":
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
@ -302,7 +302,7 @@ class PlayerAPI{
public function teleport(&$name, &$target){ public function teleport(&$name, &$target){
if(substr($target, 0, 2) === "w:"){ if(substr($target, 0, 2) === "w:"){
$lv = $this->server->api->level->get(substr($target, 2)); $lv = Level::get(substr($target, 2));
if($lv instanceof Level){ if($lv instanceof Level){
$origin = Player::get($name); $origin = Player::get($name);
if($origin instanceof Player){ if($origin instanceof Player){

View File

@ -21,11 +21,11 @@
namespace PocketMine; namespace PocketMine;
use PocketMine\Network\Protocol\Info as Info; use PocketMine\Network\Protocol\Info;
use PocketMine\PMF\Plugin as PMFPlugin; use PocketMine\PMF\Plugin as PMFPlugin;
use PocketMine\Utils\Config as Config; use PocketMine\Utils\Config;
use PocketMine\Utils\TextFormat as TextFormat; use PocketMine\Utils\TextFormat;
use PocketMine\Utils\Utils as Utils; use PocketMine\Utils\Utils;
class PluginAPI extends \stdClass{ class PluginAPI extends \stdClass{
private $server; private $server;

View File

@ -19,13 +19,21 @@
* *
*/ */
namespace{ namespace {
/**
* 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){ function console($message, $EOL = true, $log = true, $level = 1){
return PocketMine\console($message, $EOL, $log, $level); PocketMine\console($message, $EOL, $log, $level);
} }
} }
namespace PocketMine{ namespace PocketMine {
const VERSION = "Alpha_1.4dev"; const VERSION = "Alpha_1.4dev";
const API_VERSION = "1.0.0"; const API_VERSION = "1.0.0";
const CODENAME = "絶好(Zekkou)ケーキ(Cake)"; const CODENAME = "絶好(Zekkou)ケーキ(Cake)";
@ -38,28 +46,28 @@ namespace PocketMine{
$className = array_pop($path); $className = array_pop($path);
if(count($path) > 0){ if(count($path) > 0){
$path = implode(DIRECTORY_SEPARATOR, array_map("strtolower", $path)) . DIRECTORY_SEPARATOR; $path = implode(DIRECTORY_SEPARATOR, array_map("strtolower", $path)) . DIRECTORY_SEPARATOR;
}else{ } else{
$path = ""; $path = "";
} }
$fPath = \PocketMine\PATH . "src" . DIRECTORY_SEPARATOR . "PocketMine" . DIRECTORY_SEPARATOR . $path . $className . ".php"; $fPath = \PocketMine\PATH . "src" . DIRECTORY_SEPARATOR . "PocketMine" . DIRECTORY_SEPARATOR . $path . $className . ".php";
if(file_exists($fPath)){ if(file_exists($fPath)){
require_once($fPath); require_once($fPath);
} }
}else{ //Try plugin } else{ //Try plugin
$className = array_pop($path); $className = array_pop($path);
if(count($path) > 0){ if(count($path) > 0){
$path = implode(DIRECTORY_SEPARATOR, array_map("strtolower", $path)) . DIRECTORY_SEPARATOR; $path = implode(DIRECTORY_SEPARATOR, array_map("strtolower", $path)) . DIRECTORY_SEPARATOR;
}else{ } else{
$path = ""; $path = "";
} }
$fPath = \PocketMine\PATH . "plugins". DIRECTORY_SEPARATOR . $parent . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR . $path . $className . ".php"; $fPath = \PocketMine\PATH . "plugins" . DIRECTORY_SEPARATOR . $parent . DIRECTORY_SEPARATOR . "src" . DIRECTORY_SEPARATOR . $path . $className . ".php";
if(file_exists($fPath)){ if(file_exists($fPath)){
require_once($fPath); require_once($fPath);
} }
} }
}); });
define("PocketMine\PATH", \getcwd() . DIRECTORY_SEPARATOR); define("PocketMine\\PATH", \getcwd() . DIRECTORY_SEPARATOR);
//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 //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
@ -67,7 +75,7 @@ namespace PocketMine{
if(ini_get("date.timezone") == ""){ //No Timezone set if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT"); date_default_timezone_set("GMT");
if(strpos(" ".strtoupper(php_uname("s")), " WIN") !== false){ if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){
$time = time(); $time = time();
$time -= $time % 60; $time -= $time % 60;
//TODO: Parse different time & date formats by region. ¬¬ world //TODO: Parse different time & date formats by region. ¬¬ world
@ -77,7 +85,7 @@ namespace PocketMine{
exec("date.exe /T", $date); exec("date.exe /T", $date);
$j = array_map("intval", explode(substr($date[0], 2, 1), trim($date[0]))); $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; $offset = round((mktime($i[0], $i[1], 0, $j[1], $j[0], $j[2]) - $time) / 60) * 60;
}else{ } else{
exec("date +%s", $t); exec("date +%s", $t);
$offset = round((intval(trim($t[0])) - time()) / 60) * 60; $offset = round((intval(trim($t[0])) - time()) / 60) * 60;
} }
@ -86,7 +94,7 @@ namespace PocketMine{
$d = timezone_name_from_abbr("", $offset, $daylight); $d = timezone_name_from_abbr("", $offset, $daylight);
@ini_set("date.timezone", $d); @ini_set("date.timezone", $d);
date_default_timezone_set($d); date_default_timezone_set($d);
}else{ } else{
$d = @date_default_timezone_get(); $d = @date_default_timezone_get();
if(strpos($d, "/") === false){ if(strpos($d, "/") === false){
$d = timezone_name_from_abbr($d); $d = timezone_name_from_abbr($d);
@ -103,15 +111,15 @@ namespace PocketMine{
ini_set("default_charset", "utf-8"); ini_set("default_charset", "utf-8");
ini_set("memory_limit", "128M"); //Default ini_set("memory_limit", "128M"); //Default
define("PocketMine\START_TIME", microtime(true)); define("PocketMine\\START_TIME", microtime(true));
$opts = getopt("", array("enable-ansi", "disable-ansi", "data-path:", "no-wizard")); $opts = getopt("", array("enable-ansi", "disable-ansi", "data-path:", "no-wizard"));
define("PocketMine\DATA", isset($opts["data-path"]) ? realpath($opts["data-path"]) . DIRECTORY_SEPARATOR : PATH); define("PocketMine\\DATA", isset($opts["data-path"]) ? realpath($opts["data-path"]) . DIRECTORY_SEPARATOR : \PocketMine\PATH);
if((strpos(strtoupper(php_uname("s")), "WIN") or isset($opts["enable-ansi"])) and !isset($opts["disable-ansi"])){ if((strpos(strtoupper(php_uname("s")), "WIN") or isset($opts["enable-ansi"])) and !isset($opts["disable-ansi"])){
define("PocketMine\ANSI", true); define("PocketMine\\ANSI", true);
}else{ } else{
define("PocketMine\ANSI", false); define("PocketMine\\ANSI", false);
} }
function dummy(){ function dummy(){
@ -121,33 +129,33 @@ namespace PocketMine{
function safe_var_dump($var, $cnt = 0){ function safe_var_dump($var, $cnt = 0){
switch(true){ switch(true){
case is_array($var): case is_array($var):
echo str_repeat(" ", $cnt)."array(".count($var).") {".PHP_EOL; echo str_repeat(" ", $cnt) . "array(" . count($var) . ") {" . PHP_EOL;
foreach($var as $key => $value){ foreach($var as $key => $value){
echo str_repeat(" ", $cnt + 1)."[".(is_integer($key) ? $key:'"'.$key.'"')."]=>".PHP_EOL; echo str_repeat(" ", $cnt + 1) . "[" . (is_integer($key) ? $key : '"' . $key . '"') . "]=>" . PHP_EOL;
safe_var_dump($value, $cnt + 1); safe_var_dump($value, $cnt + 1);
} }
echo str_repeat(" ", $cnt)."}".PHP_EOL; echo str_repeat(" ", $cnt) . "}" . PHP_EOL;
break; break;
case is_integer($var): case is_integer($var):
echo str_repeat(" ", $cnt)."int(".$var.")".PHP_EOL; echo str_repeat(" ", $cnt) . "int(" . $var . ")" . PHP_EOL;
break; break;
case is_float($var): case is_float($var):
echo str_repeat(" ", $cnt)."float(".$var.")".PHP_EOL; echo str_repeat(" ", $cnt) . "float(" . $var . ")" . PHP_EOL;
break; break;
case is_bool($var): case is_bool($var):
echo str_repeat(" ", $cnt)."bool(".($var === true ? "true":"false").")".PHP_EOL; echo str_repeat(" ", $cnt) . "bool(" . ($var === true ? "true" : "false") . ")" . PHP_EOL;
break; break;
case is_string($var): case is_string($var):
echo str_repeat(" ", $cnt)."string(".strlen($var).") \"$var\"".PHP_EOL; echo str_repeat(" ", $cnt) . "string(" . strlen($var) . ") \"$var\"" . PHP_EOL;
break; break;
case is_resource($var): case is_resource($var):
echo str_repeat(" ", $cnt)."resource() of type (".get_resource_type($var).")".PHP_EOL; echo str_repeat(" ", $cnt) . "resource() of type (" . get_resource_type($var) . ")" . PHP_EOL;
break; break;
case is_object($var): case is_object($var):
echo str_repeat(" ", $cnt)."object(".get_class($var).")".PHP_EOL; echo str_repeat(" ", $cnt) . "object(" . get_class($var) . ")" . PHP_EOL;
break; break;
case is_null($var): case is_null($var):
echo str_repeat(" ", $cnt)."NULL".PHP_EOL; echo str_repeat(" ", $cnt) . "NULL" . PHP_EOL;
break; break;
} }
} }
@ -155,12 +163,12 @@ namespace PocketMine{
function kill($pid){ function kill($pid){
switch(Utils\Utils::getOS()){ switch(Utils\Utils::getOS()){
case "win": case "win":
exec("taskkill.exe /F /PID ".((int) $pid)." > NUL"); exec("taskkill.exe /F /PID " . ((int) $pid) . " > NUL");
break; break;
case "mac": case "mac":
case "linux": case "linux":
default: default:
exec("kill -9 ".((int) $pid)." > /dev/null 2>&1"); exec("kill -9 " . ((int) $pid) . " > /dev/null 2>&1");
} }
} }
@ -174,34 +182,43 @@ namespace PocketMine{
} }
$var = null; $var = null;
unset($var); unset($var);
}elseif(is_array($var)){ } elseif(is_array($var)){
foreach($var as $i => $v){ foreach($var as $i => $v){
hard_unset($var[$i]); hard_unset($var[$i]);
} }
$var = null; $var = null;
unset($var); unset($var);
}else{ } else{
$var = null; $var = null;
unset($var); unset($var);
} }
} }
/**
* 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){ function console($message, $EOL = true, $log = true, $level = 1){
if(!defined("DEBUG") or DEBUG >= $level){ if(!defined("PocketMine\\DEBUG") or \PocketMine\DEBUG >= $level){
$message .= $EOL === true ? PHP_EOL:""; $message .= $EOL === true ? PHP_EOL : "";
$time = (ANSI === true ? Utils\TextFormat::AQUA . date("H:i:s") . Utils\TextFormat::RESET:date("H:i:s")) . " "; $time = (\PocketMine\ANSI === true ? Utils\TextFormat::AQUA . date("H:i:s") . Utils\TextFormat::RESET : date("H:i:s")) . " ";
$replaced = Utils\TextFormat::clean(preg_replace('/\x1b\[[0-9;]*m/', "", $time . $message)); $replaced = Utils\TextFormat::clean(preg_replace('/\x1b\[[0-9;]*m/', "", $time . $message));
if($log === true and (!defined("LOG") or LOG === true)){ if($log === true and (!defined("LOG") or LOG === true)){
log(date("Y-m-d")." ".$replaced, "console", false, $level); log(date("Y-m-d") . " " . $replaced, "console", false, $level);
} }
if(ANSI === true){ if(\PocketMine\ANSI === true){
$add = ""; $add = "";
if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){ if(preg_match("/\\[([a-zA-Z0-9]*)\\]/", $message, $matches) > 0){
switch($matches[1]){ switch($matches[1]){
case "ERROR": case "ERROR":
case "SEVERE": case "SEVERE":
$add .= Utils\TextFormat::RED; $add .= Utils\TextFormat::RED;
break; break;
case "TRACE":
case "INTERNAL": case "INTERNAL":
case "DEBUG": case "DEBUG":
$add .= Utils\TextFormat::GRAY; $add .= Utils\TextFormat::GRAY;
@ -218,7 +235,7 @@ namespace PocketMine{
} }
} }
$message = Utils\TextFormat::toANSI($time . $add . $message . Utils\TextFormat::RESET); $message = Utils\TextFormat::toANSI($time . $add . $message . Utils\TextFormat::RESET);
}else{ } else{
$message = $replaced; $message = $replaced;
} }
echo $message; echo $message;
@ -234,11 +251,12 @@ namespace PocketMine{
$params = ""; $params = "";
if(isset($trace[$i]["args"])){ if(isset($trace[$i]["args"])){
foreach($trace[$i]["args"] as $name => $value){ 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)).", "; $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).")"; $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; return $messages;
} }
@ -263,23 +281,25 @@ namespace PocketMine{
E_DEPRECATED => "E_DEPRECATED", E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED",
); );
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno]:$errno; $type = ($errno === E_ERROR or $errno === E_WARNING or $errno === E_USER_ERROR or $errno === E_USER_WARNING) ? "ERROR" : "NOTICE";
console("[ERROR] A ".$errno." error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0); $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){ foreach(getTrace() as $i => $line){
console("[TRACE] $line"); console("[TRACE] $line");
} }
return true; return true;
} }
function log($message, $name, $EOL = true, $level = 2, $close = false){ function log($message, $name, $EOL = true, $level = 2, $close = false){
global $fpointers; global $fpointers;
if((!defined("DEBUG") or DEBUG >= $level) and (!defined("LOG") or LOG === true)){ if((!defined("PocketMine\\DEBUG") or \PocketMine\DEBUG >= $level) and (!defined("PocketMine\\LOG") or LOG === true)){
$message .= $EOL === true ? PHP_EOL:""; $message .= $EOL === true ? PHP_EOL : "";
if(!isset($fpointers)){ if(!isset($fpointers)){
$fpointers = array(); $fpointers = array();
} }
if(!isset($fpointers[$name]) or $fpointers[$name] === false){ if(!isset($fpointers[$name]) or $fpointers[$name] === false){
$fpointers[$name] = @fopen(\PocketMine\DATA."/".$name.".log", "ab"); $fpointers[$name] = @fopen(\PocketMine\DATA . "/" . $name . ".log", "ab");
} }
@fwrite($fpointers[$name], $message); @fwrite($fpointers[$name], $message);
if($close === true){ if($close === true){
@ -290,7 +310,7 @@ namespace PocketMine{
} }
set_error_handler("\PocketMine\\error_handler", E_ALL); set_error_handler("\\PocketMine\\error_handler", E_ALL);
$errors = 0; $errors = 0;
@ -304,15 +324,15 @@ namespace PocketMine{
++$errors; ++$errors;
} }
if(!extension_loaded("sockets") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "sockets." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("sockets")){
console("[ERROR] Unable to find the Socket extension.", true, true, 0); console("[ERROR] Unable to find the Socket extension.", true, true, 0);
++$errors; ++$errors;
} }
if(!extension_loaded("pthreads") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "pthreads." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("pthreads")){
console("[ERROR] Unable to find the pthreads extension.", true, true, 0); console("[ERROR] Unable to find the pthreads extension.", true, true, 0);
++$errors; ++$errors;
}else{ } else{
$pthreads_version = phpversion("pthreads"); $pthreads_version = phpversion("pthreads");
if(substr_count($pthreads_version, ".") < 2){ if(substr_count($pthreads_version, ".") < 2){
$pthreads_version = "0.$pthreads_version"; $pthreads_version = "0.$pthreads_version";
@ -323,22 +343,22 @@ namespace PocketMine{
} }
} }
if(!extension_loaded("curl") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "curl." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("curl")){
console("[ERROR] Unable to find the cURL extension.", true, true, 0); console("[ERROR] Unable to find the cURL extension.", true, true, 0);
++$errors; ++$errors;
} }
if(!extension_loaded("sqlite3") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "sqlite3." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("sqlite3")){
console("[ERROR] Unable to find the SQLite3 extension.", true, true, 0); console("[ERROR] Unable to find the SQLite3 extension.", true, true, 0);
++$errors; ++$errors;
} }
if(!extension_loaded("yaml") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "yaml." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("yaml")){
console("[ERROR] Unable to find the YAML extension.", true, true, 0); console("[ERROR] Unable to find the YAML extension.", true, true, 0);
++$errors; ++$errors;
} }
if(!extension_loaded("zlib") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "zlib." . PHP_SHLIB_SUFFIX) === false){ if(!extension_loaded("zlib")){
console("[ERROR] Unable to find the Zlib extension.", true, true, 0); console("[ERROR] Unable to find the Zlib extension.", true, true, 0);
++$errors; ++$errors;
} }
@ -350,8 +370,8 @@ namespace PocketMine{
$gitsha1 = false; $gitsha1 = false;
if(file_exists(\PocketMine\PATH . ".git/refs/heads/master")){ //Found Git information! 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")))); define("PocketMine\GIT_COMMIT", strtolower(trim(file_get_contents(\PocketMine\PATH . ".git/refs/heads/master"))));
}else{ //Unknown :( } else{ //Unknown :(
define("PocketMine\GIT_COMMIT", str_repeat("00", 20)); define("PocketMine\GIT_COMMIT", str_repeat("00", 20));
} }
@ -363,10 +383,12 @@ namespace PocketMine{
$installer = new Wizard\Installer(); $installer = new Wizard\Installer();
} }
$server = new ServerAPI(); if(!defined("PARENT_API_EXISTENT")){
$server->start(); $server = new ServerAPI();
$server->start();
kill(getmypid()); //Fix for ConsoleAPI being blocked kill(getmypid()); //Fix for ConsoleAPI being blocked
exit(0); exit(0);
}
} }

View File

@ -25,14 +25,14 @@
*/ */
namespace PocketMine; namespace PocketMine;
use PocketMine\Entity\Entity as Entity; use PocketMine\Entity\Entity;
use PocketMine\Network\Handler as Handler; use PocketMine\Network\Handler;
use PocketMine\Network\Packet as Packet; use PocketMine\Network\Packet;
use PocketMine\Network\Protocol\Info as Info; use PocketMine\Network\Protocol\Info;
use PocketMine\Network\RakNet\Info as RakNetInfo; use PocketMine\Network\RakNet\Info as RakNetInfo;
use PocketMine\Network\RakNet\Packet as RakNetPacket; use PocketMine\Network\RakNet\Packet as RakNetPacket;
use PocketMine\Utils\Utils as Utils; use PocketMine\Utils\Utils;
use PocketMine\Utils\VersionString as VersionString; use PocketMine\Utils\VersionString;
class Server{ class Server{
public $tCnt; public $tCnt;
@ -46,7 +46,7 @@ class Server{
private function load(){ private function load(){
$this->version = new VersionString(); $this->version = new VersionString();
if(defined("DEBUG") and DEBUG >= 0){ if(defined("PocketMine\\DEBUG") and \PocketMine\DEBUG >= 0){
@cli_set_process_title("PocketMine-MP " . \PocketMine\VERSION); @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); console("[INFO] Starting Minecraft PE server on " . ($this->serverip === "0.0.0.0" ? "*" : $this->serverip) . ":" . $this->port);
@ -107,7 +107,7 @@ class Server{
public function titleTick(){ public function titleTick(){
$time = microtime(true); $time = microtime(true);
if(defined("DEBUG") and DEBUG >= 0 and ANSI === true){ if(defined("PocketMine\\DEBUG") and \PocketMine\DEBUG >= 0 and 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"; 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); $this->interface->bandwidth = array(0, 0, $time);
@ -482,7 +482,7 @@ class Server{
ob_end_clean(); ob_end_clean();
$dump .= "\r\n```"; $dump .= "\r\n```";
$name = "Error_Dump_" . date("D_M_j-H.i.s-T_Y"); $name = "Error_Dump_" . date("D_M_j-H.i.s-T_Y");
logg($dump, $name, true, 0, true); 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); console("[SEVERE] Please submit the \"{$name}.log\" file to the Bug Reporting page. Give as much info as you can.", true, true, 0);
} }

View File

@ -21,20 +21,21 @@
namespace PocketMine; namespace PocketMine;
use PocketMine\Block\Block as Block; use PocketMine\Block\Block;
use PocketMine\Entity\Entity as Entity; use PocketMine\Entity\Entity;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Network\Protocol\Info as Info; use PocketMine\Level\Level;
use PocketMine\Network\Query\QueryHandler as QueryHandler; use PocketMine\Network\Protocol\Info;
use PocketMine\Network\RCON\RCON as RCON; use PocketMine\Network\Query\QueryHandler;
use PocketMine\Network\UPnP\PortForward as PortForward; use PocketMine\Network\RCON\RCON;
use PocketMine\Network\UPnP\RemovePortForward as RemovePortForward; use PocketMine\Network\UPnP\PortForward;
use PocketMine\Recipes\Crafting as Crafting; use PocketMine\Network\UPnP\RemovePortForward;
use PocketMine\Tile\Tile as Tile; use PocketMine\Recipes\Crafting;
use PocketMine\Utils\Config as Config; use PocketMine\Tile\Tile;
use PocketMine\Utils\TextFormat as TextFormat; use PocketMine\Utils\Config;
use PocketMine\Utils\Utils as Utils; use PocketMine\Utils\TextFormat;
use PocketMine\Utils\VersionString as VersionString; use PocketMine\Utils\Utils;
use PocketMine\Utils\VersionString;
class ServerAPI{ class ServerAPI{
public $restart = false; public $restart = false;
@ -112,22 +113,14 @@ class ServerAPI{
@mkdir(\PocketMine\DATA . "worlds/", 0755); @mkdir(\PocketMine\DATA . "worlds/", 0755);
@mkdir(\PocketMine\DATA . "plugins/", 0755); @mkdir(\PocketMine\DATA . "plugins/", 0755);
//Init all the events
foreach(get_declared_classes() as $class){
if(is_subclass_of($class, "Event") and property_exists($class, "handlers") and property_exists($class, "handlerPriority")){
$class::unregisterAll();
}
}
$version = new VersionString(); $version = new VersionString();
console("[INFO] Starting Minecraft PE server version " . TextFormat::AQUA . MINECRAFT_VERSION); console("[INFO] Starting Minecraft: PE server version " . TextFormat::AQUA . MINECRAFT_VERSION);
console("[INFO] Loading properties..."); console("[INFO] Loading properties...");
$this->config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES, array( $this->config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES, array(
"server-name" => "Minecraft: PE Server", "server-name" => "Minecraft: PE Server",
"description" => "Server made using PocketMine-MP", "description" => "Server made using PocketMine-MP",
"motd" => "Welcome @player to this server!", "motd" => "Welcome @player to this server!",
"server-ip" => "",
"server-port" => 19132, "server-port" => 19132,
"server-type" => "normal", "server-type" => "normal",
"memory-limit" => "128M", "memory-limit" => "128M",
@ -157,7 +150,7 @@ class ServerAPI{
$this->parseProperties(); $this->parseProperties();
//Load advanced properties //Load advanced properties
define("DEBUG", $this->getProperty("debug", 1)); define("PocketMine\\DEBUG", $this->getProperty("debug", 1));
define("ADVANCED_CACHE", $this->getProperty("enable-advanced-cache", false)); 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 define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 7)); //Default rate ~448 kB/s
if(ADVANCED_CACHE == true){ if(ADVANCED_CACHE == true){
@ -188,7 +181,7 @@ class ServerAPI{
console("[NOTICE] " . TextFormat::YELLOW . "A new DEVELOPMENT version of PocketMine-MP has been released!"); 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 . "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] " . 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 dissapear after issuing the command \"/update-done\""); console("[NOTICE] This message will disappear after issuing the command \"/update-done\"");
} else{ } else{
$this->setProperty("last-update", time()); $this->setProperty("last-update", time());
console("[INFO] " . TextFormat::AQUA . "This is the latest DEVELOPMENT version"); console("[INFO] " . TextFormat::AQUA . "This is the latest DEVELOPMENT version");
@ -207,7 +200,7 @@ class ServerAPI{
console("[NOTICE] " . TextFormat::GREEN . "A new STABLE version of PocketMine-MP has been released!"); 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] " . TextFormat::GREEN . "Version \"" . $info[0]["name"] . "\" #" . $updateN);
console("[NOTICE] Get it at PocketMine.net or at " . $info[0]["zipball_url"]); console("[NOTICE] Get it at PocketMine.net or at " . $info[0]["zipball_url"]);
console("[NOTICE] This message will dissapear as soon as you update"); console("[NOTICE] This message will disappear as soon as you update");
} else{ } else{
$this->setProperty("last-update", time()); $this->setProperty("last-update", time());
console("[INFO] " . TextFormat::AQUA . "This is the latest STABLE version"); console("[INFO] " . TextFormat::AQUA . "This is the latest STABLE version");
@ -218,8 +211,10 @@ class ServerAPI{
$this->loadProperties(); $this->loadProperties();
$this->apiList[] = $this->console = new ConsoleAPI(); $this->apiList[] = $this->console = new ConsoleAPI();
$this->apiList[] = $this->level = new LevelAPI(); $this->apiList[] = $this->level = new LevelAPI();
$this->apiList[] = $this->block = new BlockAPI(); $this->apiList[] = $this->block = new BlockAPI();
$this->apiList[] = $this->chat = new ChatAPI(); $this->apiList[] = $this->chat = new ChatAPI();
$this->apiList[] = $this->ban = new BanAPI(); $this->apiList[] = $this->ban = new BanAPI();
@ -239,7 +234,7 @@ class ServerAPI{
public function checkTickUpdates(){ public function checkTickUpdates(){
//Update entities that need update //Update entities that need update
if(count(Entity::$needUpdate) > 0){ if(count(Entity::$needUpdate) > 0){
foreach(EntityEntity::$needUpdate as $id => $entity){ foreach(Entity::$needUpdate as $id => $entity){
if($entity->onUpdate() === false){ if($entity->onUpdate() === false){
unset(Entity::$needUpdate[$id]); unset(Entity::$needUpdate[$id]);
} }
@ -276,7 +271,7 @@ class ServerAPI{
public function autoSave(){ public function autoSave(){
console("[DEBUG] Saving....", true, true, 2); console("[DEBUG] Saving....", true, true, 2);
$this->server->api->level->saveAll(); Level::saveAll();
} }
public function sendUsage(){ public function sendUsage(){
@ -377,6 +372,12 @@ class ServerAPI{
self::$serverRequest = $this->server; self::$serverRequest = $this->server;
} }
Block::init();
Item::init();
Crafting::init();
Level::init();
if($this->getProperty("send-usage", true) !== false){ 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->server->schedule(6000, array($this, "sendUsage"), array(), true); //Send the info after 5 minutes have passed
$this->sendUsage(); $this->sendUsage();
@ -392,10 +393,6 @@ class ServerAPI{
$this->query = new QueryHandler(); $this->query = new QueryHandler();
} }
Block::init();
Item::init();
Crafting::init();
$this->schedule(2, array($this, "checkTickUpdates"), array(), true); $this->schedule(2, array($this, "checkTickUpdates"), array(), true);
$this->server->init(); $this->server->init();
unregister_tick_function(array($this->server, "tick")); unregister_tick_function(array($this->server, "tick"));

View File

@ -91,7 +91,7 @@ class TimeAPI{
public function get($raw = false, $level = false){ public function get($raw = false, $level = false){
if(!($level instanceof Level)){ if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault(); $level = Level::getDefault();
} }
return $raw === true ? $level->getTime() : abs($level->getTime()) % 19200; return $raw === true ? $level->getTime() : abs($level->getTime()) % 19200;
@ -99,7 +99,7 @@ class TimeAPI{
public function add($time, $level = false){ public function add($time, $level = false){
if(!($level instanceof Level)){ if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault(); $level = Level::getDefault();
} }
$level->setTime($level->getTime() + (int) $time); $level->setTime($level->getTime() + (int) $time);
} }
@ -127,7 +127,7 @@ class TimeAPI{
public function set($time, $level = false){ public function set($time, $level = false){
if(!($level instanceof Level)){ if(!($level instanceof Level)){
$level = $this->server->api->level->getDefault(); $level = Level::getDefault();
} }
if(is_string($time) and isset(TimeAPI::$phases[$time])){ if(is_string($time) and isset(TimeAPI::$phases[$time])){
$level->setTime(TimeAPI::$phases[$time]); $level->setTime(TimeAPI::$phases[$time]);

View File

@ -21,10 +21,10 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\Network\Protocol\ChatPacket as ChatPacket;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Network\Protocol\ChatPacket;
use PocketMine\ServerAPI;
class Bed extends Transparent{ class Bed extends Transparent{
public function __construct($type = 0){ public function __construct($type = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Bedrock extends Solid{ class Bedrock extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Beetroot extends Flowable{ class Beetroot extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -57,24 +58,24 @@ class Beetroot extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get(BEETROOT_SEEDS, 0, 1)); //ServerAPI::request()->api->entity->drop($this, Item::get(BEETROOT_SEEDS, 0, 1));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} else{ } else{
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class BirchWoodStairs extends Stair{ class BirchWoodStairs extends Stair{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -23,11 +23,12 @@
* All Block classes are in here * All Block classes are in here
*/ */
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item;
use PocketMine\Level\Level;
use PocketMine\Level\Position;
use PocketMine\Player;
use PocketMine; use PocketMine;
use PocketMine\Player as Player;
use PocketMine\Item\Item as Item;
use PocketMine\Level\Position as Position;
use PocketMine\Level\Level as Level;
abstract class Block extends Position{ abstract class Block extends Position{
const AIR = 0; const AIR = 0;
@ -435,8 +436,8 @@ abstract class Block extends Position{
/** /**
* Returns an array of Item objects to be dropped * Returns an array of Item objects to be dropped
* *
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return array * @return array
*/ */
@ -453,8 +454,8 @@ abstract class Block extends Position{
/** /**
* Returns the seconds that this block takes to be broken using an specific Item * Returns the seconds that this block takes to be broken using an specific Item
* *
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return float * @return float
*/ */
@ -490,8 +491,8 @@ abstract class Block extends Position{
/** /**
* Returns if the item can be broken with an specific Item * Returns if the item can be broken with an specific Item
* *
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return bool * @return bool
*/ */
@ -500,8 +501,8 @@ abstract class Block extends Position{
/** /**
* Do the actions needed so the block is broken with the Item * Do the actions needed so the block is broken with the Item
* *
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return mixed * @return mixed
*/ */
@ -510,14 +511,14 @@ abstract class Block extends Position{
/** /**
* Places the Block, using block space and block target, and side. Returns if the block has been placed. * Places the Block, using block space and block target, and side. Returns if the block has been placed.
* *
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* @param Block $block * @param Block $block
* @param Block $target * @param Block $target
* @param int $face * @param int $face
* @param float $fx * @param float $fx
* @param float $fy * @param float $fy
* @param float $fz * @param float $fz
* *
* @return bool * @return bool
*/ */
@ -526,8 +527,8 @@ abstract class Block extends Position{
/** /**
* Do actions when activated by Item. Returns if it has done anything * Do actions when activated by Item. Returns if it has done anything
* *
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return bool * @return bool
*/ */

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Bricks extends Solid{ class Bricks extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class BrownMushroom extends Flowable{ class BrownMushroom extends Flowable{
public function __construct(){ public function __construct(){
@ -31,13 +32,13 @@ class BrownMushroom extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get($this->id)); //ServerAPI::request()->api->entity->drop($this, Item::get($this->id));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -21,14 +21,14 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Enum as Enum;
use PocketMine\NBT\Tag\Int as Int;
use PocketMine\NBT\Tag\String as String;
use PocketMine\Tile\Furnace as Furnace;
use PocketMine\Tile\Tile as Tile;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\NBT\Tag\Compound;
use PocketMine\NBT\Tag\Enum;
use PocketMine\NBT\Tag\Int;
use PocketMine\NBT\Tag\String;
use PocketMine\Tile\Furnace;
use PocketMine\Tile\Tile;
class BurningFurnace extends Solid{ class BurningFurnace extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -21,10 +21,11 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\ServerAPI;
use PocketMine\Level\Level;
class Cactus extends Transparent{ class Cactus extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -34,15 +35,15 @@ class Cactus extends Transparent{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){ //Replace with common break method if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){ //Replace with common break method
$this->level->setBlock($this, new Air(), false); $this->level->setBlock($this, new Air(), false);
ServerAPI::request()->api->entity->drop($this, Item::get($this->id)); ServerAPI::request()->api->entity->drop($this, Item::get($this->id));
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== self::CACTUS){ if($this->getSide(0)->getID() !== self::CACTUS){
if($this->meta == 0x0F){ if($this->meta == 0x0F){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
@ -59,7 +60,7 @@ class Cactus extends Transparent{
$this->level->setBlock($this, $this, false); $this->level->setBlock($this, $this, false);
} }
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Cake extends Transparent{ class Cake extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -45,11 +46,11 @@ class Cake extends Transparent{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
$this->level->setBlock($this, new Air(), true, false, true); $this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Carpet extends Flowable{ class Carpet extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -63,13 +64,13 @@ class Carpet extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get($this->id, $this->meta, 1)); //ServerAPI::request()->api->entity->drop($this, Item::get($this->id, $this->meta, 1));
$this->level->setBlock($this, new Air(), true, false, true); $this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Carrot extends Flowable{ class Carrot extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -57,24 +58,24 @@ class Carrot extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get(CARROT, 0, 1)); //ServerAPI::request()->api->entity->drop($this, Item::get(CARROT, 0, 1));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} else{ } else{
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} }

View File

@ -21,14 +21,14 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Enum as Enum;
use PocketMine\NBT\Tag\Int as Int;
use PocketMine\NBT\Tag\String as String;
use PocketMine\Tile\Chest as TileChest;
use PocketMine\Tile\Tile as Tile;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\NBT\Tag\Compound;
use PocketMine\NBT\Tag\Enum;
use PocketMine\NBT\Tag\Int;
use PocketMine\NBT\Tag\String;
use PocketMine\Tile\Chest as TileChest;
use PocketMine\Tile\Tile;
class Chest extends Transparent{ class Chest extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Clay extends Solid{ class Clay extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Coal extends Solid{ class Coal extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class CoalOre extends Solid{ class CoalOre extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Cobblestone extends Solid{ class Cobblestone extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Cobweb extends Flowable{ class Cobweb extends Flowable{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class CyanFlower extends Flowable{ class CyanFlower extends Flowable{
public function __construct(){ public function __construct(){
@ -42,13 +43,13 @@ class CyanFlower extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get($this->id)); //ServerAPI::request()->api->entity->drop($this, Item::get($this->id));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Dandelion extends Flowable{ class Dandelion extends Flowable{
public function __construct(){ public function __construct(){
@ -42,13 +43,13 @@ class Dandelion extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get($this->id)); //ServerAPI::request()->api->entity->drop($this, Item::get($this->id));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,6 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Level\Level;
class DeadBush extends Flowable{ class DeadBush extends Flowable{
public function __construct(){ public function __construct(){
@ -31,11 +32,11 @@ class DeadBush extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Diamond extends Solid{ class Diamond extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class DiamondOre extends Solid{ class DiamondOre extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Dirt extends Solid{ class Dirt extends Solid{
public function __construct(){ public function __construct(){

View File

@ -21,10 +21,11 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\Network\Protocol\LevelEventPacket as LevelEventPacket;
use PocketMine\Player as Player;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Network\Protocol\LevelEventPacket;
use PocketMine\Player;
use PocketMine\Level\Level;
abstract class Door extends Transparent{ abstract class Door extends Transparent{
@ -34,14 +35,14 @@ abstract class Door extends Transparent{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
$this->level->setBlock($this, new Air(), false); $this->level->setBlock($this, new Air(), false);
if($this->getSide(1) instanceof Door){ if($this->getSide(1) instanceof Door){
$this->level->setBlock($this->getSide(1), new Air(), false); $this->level->setBlock($this->getSide(1), new Air(), false);
} }
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class DoubleSlab extends Solid{ class DoubleSlab extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class DoubleWoodSlab extends Solid{ class DoubleWoodSlab extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -21,9 +21,10 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\ServerAPI;
use PocketMine\Level\Level;
class Fallable extends Solid{ class Fallable extends Solid{
@ -34,7 +35,7 @@ class Fallable extends Solid{
public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->blockUpdate(clone $this, Level::BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Farmland extends Solid{ class Farmland extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class FenceGate extends Transparent{ class FenceGate extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Fire extends Flowable{ class Fire extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -38,7 +39,7 @@ class Fire extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
for($s = 0; $s <= 5; ++$s){ for($s = 0; $s <= 5; ++$s){
$side = $this->getSide($s); $side = $this->getSide($s);
if($side->getID() !== self::AIR and !($side instanceof Liquid)){ if($side->getID() !== self::AIR and !($side instanceof Liquid)){
@ -47,12 +48,12 @@ class Fire extends Flowable{
} }
$this->level->setBlock($this, new Air(), true, false, true); $this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== self::NETHERRACK){ if($this->getSide(0)->getID() !== self::NETHERRACK){
$this->level->setBlock($this, new Air(), true, false, true); $this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -21,10 +21,10 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Player as Player;
use PocketMine\Item\Item as Item;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\ServerAPI;
use PocketMine\Level\Level;
class Generic extends Block{ class Generic extends Block{
@ -50,7 +50,7 @@ class Generic extends Block{
} }
public function onUpdate($type){ public function onUpdate($type){
if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){ if($this->hasPhysics === true and $type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === self::AIR or ($down instanceof Liquid)){ if($down->getID() === self::AIR or ($down instanceof Liquid)){
$data = array( $data = array(
@ -64,7 +64,7 @@ class Generic extends Block{
//TODO //TODO
//$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data); //$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
//$e->spawnToAll(); //$e->spawnToAll();
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1); $server->api->block->blockUpdateAround(clone $this, Level::BLOCK_UPDATE_NORMAL, 1);
} }
return false; return false;

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Glass extends Transparent{ class Glass extends Transparent{
public function __construct(){ public function __construct(){

View File

@ -21,10 +21,9 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\Level\Position as Position;
use PocketMine\Utils\Utils as Utils;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Level\Level;
class GlowingRedstoneOre extends Solid{ class GlowingRedstoneOre extends Solid{
public function __construct(){ public function __construct(){
@ -33,10 +32,10 @@ class GlowingRedstoneOre extends Solid{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_SCHEDULED or $type === BLOCK_UPDATE_RANDOM){ if($type === Level::BLOCK_UPDATE_SCHEDULED or $type === Level::BLOCK_UPDATE_RANDOM){
$this->level->setBlock($this, Block::get(REDSTONE_ORE, $this->meta), false, false, true); $this->level->setBlock($this, Block::get(REDSTONE_ORE, $this->meta), false, false, true);
return BLOCK_UPDATE_WEAK; return Level::BLOCK_UPDATE_WEAK;
} }
return false; return false;

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Glowstone extends Transparent{ class Glowstone extends Transparent{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Gold extends Solid{ class Gold extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class GoldOre extends Solid{ class GoldOre extends Solid{
public function __construct(){ public function __construct(){

View File

@ -21,10 +21,10 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\Level\Generator\Object\TallGrass as TallGrass;
use PocketMine\Utils\Random as Random;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Level\Generator\Object\TallGrass;
use PocketMine\Utils\Random;
class Grass extends Solid{ class Grass extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Gravel extends Fallable{ class Gravel extends Fallable{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class HayBale extends Solid{ class HayBale extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Ice extends Transparent{ class Ice extends Transparent{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Iron extends Solid{ class Iron extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class IronDoor extends Door{ class IronDoor extends Door{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class IronOre extends Solid{ class IronOre extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class JungleWoodStairs extends Stair{ class JungleWoodStairs extends Stair{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Ladder extends Transparent{ class Ladder extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -52,11 +53,11 @@ class Ladder extends Transparent{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
/*if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method /*if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, Item::get(LADDER, 0, 1)); ServerAPI::request()->api->entity->drop($this, Item::get(LADDER, 0, 1));
$this->level->setBlock($this, new Air(), true, true, true); $this->level->setBlock($this, new Air(), true, true, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
}*/ }*/
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Lapis extends Solid{ class Lapis extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class LapisOre extends Solid{ class LapisOre extends Solid{
public function __construct(){ public function __construct(){

View File

@ -21,10 +21,11 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\Level\Position as Position;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Level\Position;
use PocketMine\ServerAPI;
use PocketMine\Level\Level;
class Lava extends Liquid{ class Lava extends Liquid{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -34,7 +35,7 @@ class Lava extends Liquid{
public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, Level::BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }
@ -87,7 +88,7 @@ class Lava extends Liquid{
//return false; //return false;
$newId = $this->id; $newId = $this->id;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if($type !== BLOCK_UPDATE_NORMAL){ if($type !== Level::BLOCK_UPDATE_NORMAL){
return false; return false;
} }
@ -103,7 +104,7 @@ class Lava extends Liquid{
if($level !== 0x07){ if($level !== 0x07){
if($down instanceof Air || $down instanceof Lava){ if($down instanceof Air || $down instanceof Lava){
$this->level->setBlock($down, new Lava(0x01), false, false, true); $this->level->setBlock($down, new Lava(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
} else{ } else{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
@ -111,7 +112,7 @@ class Lava extends Liquid{
} elseif($b->isFlowable === true){ } elseif($b->isFlowable === true){
$this->level->setBlock($b, new Lava(min($level + 2, 7)), false, false, true); $this->level->setBlock($b, new Lava(min($level + 2, 7)), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
} }
} }
} }
@ -125,7 +126,7 @@ class Lava extends Liquid{
if($tlevel != 0x00){ if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){ for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($sb, new Air(), false, false, true); $this->level->setBlock($sb, new Air(), false, false, true);
} }
@ -136,12 +137,12 @@ class Lava extends Liquid{
if($tlevel != 0x00){ if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){ for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($b, new Air(), false, false, true); $this->level->setBlock($b, new Air(), false, false, true);
} }
} }
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); //ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);

View File

@ -21,9 +21,10 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\ServerAPI;
use PocketMine\Level\Level;
class Leaves extends Transparent{ class Leaves extends Transparent{
const OAK = 0; const OAK = 0;
@ -109,12 +110,12 @@ class Leaves extends Transparent{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if(($this->meta & 0b00001100) === 0){ if(($this->meta & 0b00001100) === 0){
$this->meta |= 0x08; $this->meta |= 0x08;
$this->level->setBlock($this, $this, false, false, true); $this->level->setBlock($this, $this, false, false, true);
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(($this->meta & 0b00001100) === 0x08){ if(($this->meta & 0b00001100) === 0x08){
$this->meta &= 0x03; $this->meta &= 0x03;
$visited = array(); $visited = array();
@ -132,7 +133,7 @@ class Leaves extends Transparent{
ServerAPI::request()->api->entity->drop($this, Item::get(APPLE, 0, 1)); ServerAPI::request()->api->entity->drop($this, Item::get(APPLE, 0, 1));
} }
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class LitPumpkin extends Solid{ class LitPumpkin extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Melon extends Transparent{ class Melon extends Transparent{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class MelonStem extends Flowable{ class MelonStem extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -43,26 +44,26 @@ class MelonStem extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get(MELON_SEEDS, 0, mt_rand(0, 2))); //ServerAPI::request()->api->entity->drop($this, Item::get(MELON_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} else{ } else{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b->getID() === self::MELON_BLOCK){ if($b->getID() === self::MELON_BLOCK){
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} }
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
@ -73,7 +74,7 @@ class MelonStem extends Flowable{
} }
} }
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
return false; return false;

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class MossStone extends Solid{ class MossStone extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class NetherBrick extends Solid{ class NetherBrick extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Netherrack extends Solid{ class Netherrack extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Obsidian extends Solid{ class Obsidian extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Potato extends Flowable{ class Potato extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -57,24 +58,24 @@ class Potato extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get(POTATO, 0, 1)); //ServerAPI::request()->api->entity->drop($this, Item::get(POTATO, 0, 1));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} else{ } else{
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class PumpkinStem extends Flowable{ class PumpkinStem extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -43,26 +44,26 @@ class PumpkinStem extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get(PUMPKIN_SEEDS, 0, mt_rand(0, 2))); //ServerAPI::request()->api->entity->drop($this, Item::get(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} else{ } else{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b->getID() === self::PUMPKIN){ if($b->getID() === self::PUMPKIN){
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} }
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
@ -73,7 +74,7 @@ class PumpkinStem extends Flowable{
} }
} }
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
return false; return false;

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Quartz extends Solid{ class Quartz extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class RedMushroom extends Flowable{ class RedMushroom extends Flowable{
public function __construct(){ public function __construct(){
@ -31,13 +32,13 @@ class RedMushroom extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get($this->id)); //ServerAPI::request()->api->entity->drop($this, Item::get($this->id));
$this->level->setBlock($this, new Air(), false); $this->level->setBlock($this, new Air(), false);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class RedstoneOre extends Solid{ class RedstoneOre extends Solid{
public function __construct(){ public function __construct(){
@ -31,10 +32,10 @@ class RedstoneOre extends Solid{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){ if($type === Level::BLOCK_UPDATE_NORMAL or $type === Level::BLOCK_UPDATE_TOUCH){
$this->level->setBlock($this, Block::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true); $this->level->setBlock($this, Block::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
return BLOCK_UPDATE_WEAK; return Level::BLOCK_UPDATE_WEAK;
} }
return false; return false;

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Sandstone extends Solid{ class Sandstone extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -21,10 +21,11 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\Level\Generator\Object\Tree as Tree;
use PocketMine\Utils\Random as Random;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Level\Generator\Object\Tree;
use PocketMine\Utils\Random;
use PocketMine\Level\Level;
class Sapling extends Flowable{ class Sapling extends Flowable{
const OAK = 0; const OAK = 0;
@ -71,15 +72,15 @@ class Sapling extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get($this->id)); //ServerAPI::request()->api->entity->drop($this, Item::get($this->id));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ //Growth } elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth
if(mt_rand(1, 7) === 1){ if(mt_rand(1, 7) === 1){
if(($this->meta & 0x08) === 0x08){ if(($this->meta & 0x08) === 0x08){
Tree::growTree($this->level, $this, new Random(), $this->meta & 0x03); Tree::growTree($this->level, $this, new Random(), $this->meta & 0x03);
@ -87,10 +88,10 @@ class Sapling extends Flowable{
$this->meta |= 0x08; $this->meta |= 0x08;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} else{ } else{
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class SignPost extends Transparent{ class SignPost extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -57,13 +58,13 @@ class SignPost extends Transparent{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get(SIGN, 0, 1)); //ServerAPI::request()->api->entity->drop($this, Item::get(SIGN, 0, 1));
$this->level->setBlock($this, new Air(), true, true, true); $this->level->setBlock($this, new Air(), true, true, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Slab extends Transparent{ class Slab extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class SnowLayer extends Flowable{ class SnowLayer extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -45,11 +46,11 @@ class SnowLayer extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
$this->level->setBlock($this, new Air(), true, false, true); $this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class SpruceWoodStairs extends Stair{ class SpruceWoodStairs extends Stair{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Stair extends Transparent{ class Stair extends Transparent{

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Stone extends Solid{ class Stone extends Solid{
public function __construct(){ public function __construct(){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class StoneBricks extends Solid{ class StoneBricks extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Stonecutter extends Solid{ class Stonecutter extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -21,9 +21,10 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Level\Level;
class Sugarcane extends Flowable{ class Sugarcane extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -61,16 +62,16 @@ class Sugarcane extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->isTransparent === true and $down->getID() !== self::SUGARCANE_BLOCK){ //Replace with common break method if($down->isTransparent === true and $down->getID() !== self::SUGARCANE_BLOCK){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get(SUGARCANE)); //ServerAPI::request()->api->entity->drop($this, Item::get(SUGARCANE));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){ if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){
if($this->meta === 0x0F){ if($this->meta === 0x0F){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
@ -87,7 +88,7 @@ class Sugarcane extends Flowable{
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
} }
return BLOCK_UPDATE_RANDOM; return Level::BLOCK_UPDATE_RANDOM;
} }
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class TNT extends Solid{ class TNT extends Solid{
public function __construct(){ public function __construct(){

View File

@ -21,8 +21,9 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\Level\Level;
class TallGrass extends Flowable{ class TallGrass extends Flowable{
public function __construct($meta = 1){ public function __construct($meta = 1){
@ -38,11 +39,11 @@ class TallGrass extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Torch extends Flowable{ class Torch extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -31,7 +32,7 @@ class Torch extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
$side = $this->getMetadata(); $side = $this->getMetadata();
$faces = array( $faces = array(
1 => 4, 1 => 4,
@ -48,7 +49,7 @@ class Torch extends Flowable{
//ServerAPI::request()->api->entity->drop($this, Item::get($this->id, 0, 1)); //ServerAPI::request()->api->entity->drop($this, Item::get($this->id, 0, 1));
$this->level->setBlock($this, new Air(), true, false, true); $this->level->setBlock($this, new Air(), true, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} }

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Trapdoor extends Transparent{ class Trapdoor extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -21,9 +21,10 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine\Item\Item as Item;
use PocketMine\ServerAPI as ServerAPI;
use PocketMine; use PocketMine;
use PocketMine\Item\Item;
use PocketMine\ServerAPI;
use PocketMine\Level\Level;
class Water extends Liquid{ class Water extends Liquid{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -33,7 +34,7 @@ class Water extends Liquid{
public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, Level::BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }
@ -93,7 +94,7 @@ class Water extends Liquid{
//return false; //return false;
$newId = $this->id; $newId = $this->id;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if($type !== BLOCK_UPDATE_NORMAL){ if($type !== Level::BLOCK_UPDATE_NORMAL){
return false; return false;
} }
@ -108,7 +109,7 @@ class Water extends Liquid{
if($level !== 0x07){ if($level !== 0x07){
if($down instanceof Air || $down instanceof Water){ if($down instanceof Air || $down instanceof Water){
$this->level->setBlock($down, new Water(0x01), false, false, true); $this->level->setBlock($down, new Water(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
} else{ } else{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
@ -118,7 +119,7 @@ class Water extends Liquid{
} }
} elseif($b->isFlowable === true){ } elseif($b->isFlowable === true){
$this->level->setBlock($b, new Water($level + 1), false, false, true); $this->level->setBlock($b, new Water($level + 1), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
} }
} }
} }
@ -132,7 +133,7 @@ class Water extends Liquid{
if($tlevel != 0x00){ if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){ for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($sb, new Air(), false, false, true); $this->level->setBlock($sb, new Air(), false, false, true);
} }
@ -143,12 +144,12 @@ class Water extends Liquid{
if($tlevel != 0x00){ if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){ for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($b, new Air(), false, false, true); $this->level->setBlock($b, new Air(), false, false, true);
} }
} }
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); //ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
} }
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
} }

View File

@ -22,7 +22,8 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
use PocketMine\Level\Level;
class Wheat extends Flowable{ class Wheat extends Flowable{
public function __construct($meta = 0){ public function __construct($meta = 0){
@ -57,15 +58,15 @@ class Wheat extends Flowable{
} }
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if($this->getSide(0)->isTransparent === true){ //Replace with common break method
//TODO //TODO
//ServerAPI::request()->api->entity->drop($this, Item::get(WHEAT_SEEDS, 0, 1)); //ServerAPI::request()->api->entity->drop($this, Item::get(WHEAT_SEEDS, 0, 1));
$this->level->setBlock($this, new Air(), false, false, true); $this->level->setBlock($this, new Air(), false, false, true);
return BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
} elseif($type === BLOCK_UPDATE_RANDOM){ } elseif($type === Level::BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){ if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){ if($this->meta < 0x07){
++$this->meta; ++$this->meta;

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Wood extends Solid{ class Wood extends Solid{
const OAK = 0; const OAK = 0;

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class WoodDoor extends Door{ class WoodDoor extends Door{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class WoodSlab extends Transparent{ class WoodSlab extends Transparent{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class WoodStairs extends Stair{ class WoodStairs extends Stair{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -22,7 +22,7 @@
namespace PocketMine\Block; namespace PocketMine\Block;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
class Workbench extends Solid{ class Workbench extends Solid{
public function __construct($meta = 0){ public function __construct($meta = 0){

View File

@ -29,21 +29,6 @@ const VIEW = 3;
const VIEWER = 3; const VIEWER = 3;
//Players
const PLAYER_MAX_QUEUE = 1024;
const PLAYER_SURVIVAL_SLOTS = 36;
const PLAYER_CREATIVE_SLOTS = 112;
//Block Updates
const BLOCK_UPDATE_NORMAL = 1;
const BLOCK_UPDATE_RANDOM = 2;
const BLOCK_UPDATE_SCHEDULED = 3;
const BLOCK_UPDATE_WEAK = 4;
const BLOCK_UPDATE_TOUCH = 5;
//Entities //Entities
const ENTITY_PLAYER = 1; const ENTITY_PLAYER = 1;

View File

@ -24,23 +24,23 @@
*/ */
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine\Event\Entity\EntityLevelChangeEvent as EntityLevelChangeEvent;
use PocketMine\Event\Entity\EntityMotionEvent as EntityMotionEvent;
use PocketMine\Event\Entity\EntityMoveEvent as EntityMoveEvent;
use PocketMine\Event\Event as Event;
use PocketMine\Event\EventHandler as EventHandler;
use PocketMine\Level\Level as Level;
use PocketMine\Level\Position as Position;
use PocketMine\Math\AxisAlignedBB as AxisAlignedBB;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\Network\Protocol\MoveEntityPacket_PosRot as MoveEntityPacket_PosRot;
use PocketMine\Network\Protocol\MovePlayerPacket as MovePlayerPacket;
use PocketMine\Network\Protocol\RemoveEntityPacket as RemoveEntityPacket;
use PocketMine\Network\Protocol\SetEntityMotionPacket as SetEntityMotionPacket;
use PocketMine\Player as Player;
use PocketMine\PMF\LevelFormat as LevelFormat;
use PocketMine; use PocketMine;
use PocketMine\Event\Entity\EntityLevelChangeEvent;
use PocketMine\Event\Entity\EntityMotionEvent;
use PocketMine\Event\Entity\EntityMoveEvent;
use PocketMine\Event\Event;
use PocketMine\Event\EventHandler;
use PocketMine\Level\Level;
use PocketMine\Level\Position;
use PocketMine\Math\AxisAlignedBB;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\NBT\Tag\Compound;
use PocketMine\Network\Protocol\MoveEntityPacket_PosRot;
use PocketMine\Network\Protocol\MovePlayerPacket;
use PocketMine\Network\Protocol\RemoveEntityPacket;
use PocketMine\Network\Protocol\SetEntityMotionPacket;
use PocketMine\Player;
use PocketMine\PMF\LevelFormat;
abstract class Entity extends Position{ abstract class Entity extends Position{
public static $entityCount = 1; public static $entityCount = 1;

View File

@ -21,21 +21,22 @@
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine\Event\Entity\EntityArmorChangeEvent as EntityArmorChangeEvent;
use PocketMine\Event\Entity\EntityInventoryChangeEvent as EntityInventoryChangeEvent;
use PocketMine\Event\Event as Event;
use PocketMine\Event\EventHandler as EventHandler;
use PocketMine\Item\Item as Item;
use PocketMine\NBT\Tag\Byte as Byte;
use PocketMine\NBT\Tag\Compound as Compound;
use PocketMine\NBT\Tag\Short as Short;
use PocketMine\Network\Protocol\AddPlayerPacket as AddPlayerPacket;
use PocketMine\Network\Protocol\ContainerSetContentPacket as ContainerSetContentPacket;
use PocketMine\Network\Protocol\PlayerEquipmentPacket as PlayerEquipmentPacket;
use PocketMine\Network\Protocol\RemovePlayerPacket as RemovePlayerPacket;
use PocketMine\Network\Protocol\SetEntityMotionPacket as SetEntityMotionPacket;
use PocketMine\Player;
use PocketMine; use PocketMine;
use PocketMine\Event\Entity\EntityArmorChangeEvent;
use PocketMine\Event\Entity\EntityInventoryChangeEvent;
use PocketMine\Event\Event;
use PocketMine\Event\EventHandler;
use PocketMine\Item\Item;
use PocketMine\NBT\Tag\Byte;
use PocketMine\NBT\Tag\Compound;
use PocketMine\NBT\Tag\Short;
use PocketMine\Network\Protocol\AddPlayerPacket;
use PocketMine\Network\Protocol\ContainerSetContentPacket;
use PocketMine\Network\Protocol\PlayerEquipmentPacket;
use PocketMine\Network\Protocol\RemovePlayerPacket;
use PocketMine\Network\Protocol\SetEntityMotionPacket;
use PocketMine\Player;
use PocketMine\Network;
class Human extends Creature implements ProjectileSource, InventorySource{ class Human extends Creature implements ProjectileSource, InventorySource{
@ -51,13 +52,13 @@ class Human extends Creature implements ProjectileSource, InventorySource{
} }
$this->hotbar = array(-1, -1, -1, -1, -1, -1, -1, -1, -1); $this->hotbar = array(-1, -1, -1, -1, -1, -1, -1, -1, -1);
$this->armor = array( $this->armor = array(
0 => Item::get(AIR, 0, 0), 0 => Item::get(Item::AIR, 0, 0),
1 => Item::get(AIR, 0, 0), 1 => Item::get(Item::AIR, 0, 0),
2 => Item::get(AIR, 0, 0), 2 => Item::get(Item::AIR, 0, 0),
3 => Item::get(AIR, 0, 0) 3 => Item::get(Item::AIR, 0, 0)
); );
foreach($nbt->Inventory as $item){ foreach($this->namedtag->Inventory as $item){
if($item->Slot >= 0 and $item->Slot < 9){ //Hotbar if($item->Slot >= 0 and $item->Slot < 9){ //Hotbar
$this->hotbar[$item->Slot] = isset($item->TrueSlot) ? $item->TrueSlot : -1; $this->hotbar[$item->Slot] = isset($item->TrueSlot) ? $item->TrueSlot : -1;
} elseif($item->Slot >= 100 and $item->Slot < 104){ //Armor } elseif($item->Slot >= 100 and $item->Slot < 104){ //Armor
@ -98,7 +99,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
} }
//Normal inventory //Normal inventory
$slotCount = (($this->gamemode & 0x01) === 0 ? PLAYER_SURVIVAL_SLOTS : PLAYER_CREATIVE_SLOTS) + 9; $slotCount = (($this->gamemode & 0x01) === 0 ? Player::SURVIVAL_SLOTS : Player::CREATIVE_SLOTS) + 9;
for($slot = 9; $slot < $slotCount; ++$slot){ for($slot = 9; $slot < $slotCount; ++$slot){
$item = $this->getSlot($slot); $item = $this->getSlot($slot);
$this->namedtag->Inventory[$slot] = new Compound(false, array( $this->namedtag->Inventory[$slot] = new Compound(false, array(
@ -218,15 +219,15 @@ class Human extends Creature implements ProjectileSource, InventorySource{
public function sendArmor(Player $player = null){ public function sendArmor(Player $player = null){
$slots = array(); $slots = array();
for($i = 0; $i < 4; ++$i){ for($i = 0; $i < 4; ++$i){
if(isset($this->armor[$i]) and ($this->armor[$i] instanceof Item) and $this->armor[$i]->getID() > AIR){ if(isset($this->armor[$i]) and ($this->armor[$i] instanceof Item) and $this->armor[$i]->getID() > Item::AIR){
$slots[$i] = $this->armor[$i]->getID() !== AIR ? $this->armor[$i]->getID() - 256 : 0; $slots[$i] = $this->armor[$i]->getID() !== Item::AIR ? $this->armor[$i]->getID() - 256 : 0;
} else{ } else{
$this->armor[$i] = Item::get(AIR, 0, 0); $this->armor[$i] = Item::get(Item::AIR, 0, 0);
$slots[$i] = 255; $slots[$i] = 255;
} }
} }
if($player instanceof Player){ if($player instanceof Player){
$pk = new Netowrk\Protocol\PlayerArmorEquipmentPacket; $pk = new Network\Protocol\PlayerArmorEquipmentPacket;
$pk->eid = $this->id; $pk->eid = $this->id;
$pk->slots = $slots; $pk->slots = $slots;
$player->dataPacket($pk); $player->dataPacket($pk);
@ -385,7 +386,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
public function getSlot($slot){ public function getSlot($slot){
$slot = (int) $slot; $slot = (int) $slot;
if(!isset($this->inventory[$slot])){ if(!isset($this->inventory[$slot])){
$this->inventory[$slot] = Item::get(AIR, 0, 0); $this->inventory[$slot] = Item::get(Item::AIR, 0, 0);
} }
return $this->inventory[$slot]; return $this->inventory[$slot];

View File

@ -22,7 +22,7 @@
namespace PocketMine\Entity; namespace PocketMine\Entity;
use PocketMine; use PocketMine;
use PocketMine\Item\Item as Item; use PocketMine\Item\Item;
interface InventorySource{ interface InventorySource{

Some files were not shown because too many files have changed in this diff Show More