Updated all undefined constants/classes, place resent packets to the recovery queue for NACK

This commit is contained in:
Shoghi Cervantes 2014-03-13 10:48:33 +01:00
parent 3c3b346fd3
commit b24120a863
80 changed files with 347 additions and 324 deletions

View File

@ -34,7 +34,6 @@ use PocketMine\Tile\Sign;
class BlockAPI{
private $server;
private $scheduledUpdates = array();
private $randomUpdates = array();
public static $creative = array(
//Building
[Item::STONE, 0],

View File

@ -466,6 +466,14 @@ class Player extends RealHuman{
}
}
/**
* Sends, if available, the next ordered chunk to the client
*
* @param bool $force
* @param null $ev
*
* @return bool|void
*/
public function getNextChunk($force = false, $ev = null){
if($this->connected === false){
return false;
@ -739,10 +747,10 @@ class Player extends RealHuman{
//$this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack);
}
switch($data["entity"]->type){
case WOOD:
case Item::WOOD:
$this->grantAchievement("mineWood");
break;
case DIAMOND:
case Item::DIAMOND:
$this->grantAchievement("diamond");
break;
}
@ -940,12 +948,12 @@ class Player extends RealHuman{
$s = $this->getSlot($slot);
$s->setCount($s->getCount() - $item->getCount());
if($s->getCount() <= 0){
$this->setSlot($slot, Item::get(AIR, 0, 0));
$this->setSlot($slot, Item::get(Item::AIR, 0, 0));
}
}
foreach($craft as $slot => $item){
$s = $this->getSlot($slot);
if($s->getCount() <= 0 or $s->getID() === AIR){
if($s->getCount() <= 0 or $s->getID() === Item::AIR){
$this->setSlot($slot, Item::get($item->getID(), $item->getMetadata(), $item->getCount()));
} else{
$this->setSlot($slot, Item::get($item->getID(), $item->getMetadata(), $s->getCount() + $item->getCount()));
@ -1162,11 +1170,8 @@ class Player extends RealHuman{
$this->packetStats[1]++;
$this->lag[] = microtime(true) - $data->sendtime;
$data->sendtime = microtime(true);
$cnt = $this->send($data);
if(isset($this->chunkCount[$count])){
unset($this->chunkCount[$count]);
$this->chunkCount[$cnt[0]] = true;
}
$this->send($data);
$this->recoveryQueue[$count] = $data;
}
}
}
@ -1698,27 +1703,27 @@ class Player extends RealHuman{
for($i = 0; $i < 4; ++$i){
$s = $packet->slots[$i];
if($s === 0 or $s === 255){
$s = Item::get(AIR, 0, 0);
$s = Item::get(Item::AIR, 0, 0);
} else{
$s = Item::get($s + 256, 0, 1);
}
$slot = $this->getArmorSlot($i);
if($slot->getID() !== AIR and $s->getID() === AIR){
if($this->setArmorSlot($i, Item::get(AIR, 0, 0)) === false){
if($slot->getID() !== Item::AIR and $s->getID() === Item::AIR){
if($this->setArmorSlot($i, Item::get(Item::AIR, 0, 0)) === false){
$this->sendArmor();
$this->sendInventory();
} else{
$this->addItem($slot);
$packet->slots[$i] = 255;
}
} elseif($s->getID() !== AIR and $slot->getID() === AIR and ($sl = $this->hasItem($s->getID())) !== false){
} elseif($s->getID() !== Item::AIR and $slot->getID() === Item::AIR and ($sl = $this->hasItem($s->getID())) !== false){
if($this->setArmorSlot($i, $this->getSlot($sl)) === false){
$this->sendArmor();
$this->sendInventory();
} else{
$this->setSlot($sl, Item::get(AIR, 0, 0));
$this->setSlot($sl, Item::get(Item::AIR, 0, 0));
}
} elseif($s->getID() !== AIR and $slot->getID() !== AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false){
} elseif($s->getID() !== Item::AIR and $slot->getID() !== Item::AIR and ($slot->getID() !== $s->getID() or $slot->getMetadata() !== $s->getMetadata()) and ($sl = $this->hasItem($s->getID())) !== false){
if($this->setArmorSlot($i, $this->getSlot($sl)) === false){
$this->sendArmor();
$this->sendInventory();
@ -2002,18 +2007,18 @@ class Player extends RealHuman{
if($packet->windowid === 0){
$craft = false;
$slot = $this->getSlot($packet->slot);
if($slot->getCount() >= $packet->item->getCount() and (($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()) or ($packet->item->getID() === AIR and $packet->item->getCount() === 0)) and !isset($this->craftingItems[$packet->slot])){ //Crafting recipe
if($slot->getCount() >= $packet->item->getCount() and (($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()) or ($packet->item->getID() === Item::AIR and $packet->item->getCount() === 0)) and !isset($this->craftingItems[$packet->slot])){ //Crafting recipe
$use = Item::get($slot->getID(), $slot->getMetadata(), $slot->getCount() - $packet->item->getCount());
$this->craftingItems[$packet->slot] = $use;
$craft = true;
} elseif($slot->getCount() <= $packet->item->getCount() and ($slot->getID() === AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))){ //Crafting final
} elseif($slot->getCount() <= $packet->item->getCount() and ($slot->getID() === Item::AIR or ($slot->getID() === $packet->item->getID() and $slot->getMetadata() === $packet->item->getMetadata()))){ //Crafting final
$craftItem = Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount() - $slot->getCount());
if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0;
}
$this->toCraft[$packet->slot] = $craftItem;
$craft = true;
} elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->getCount() > 0 and $slot->getID() > AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())){ //Crafting final
} elseif(((count($this->toCraft) === 1 and isset($this->toCraft[-1])) or count($this->toCraft) === 0) and $slot->getCount() > 0 and $slot->getID() > Item::AIR and ($slot->getID() !== $packet->item->getID() or $slot->getMetadata() !== $packet->item->getMetadata())){ //Crafting final
$craftItem = Item::get($packet->item->getID(), $packet->item->getMetadata(), $packet->item->getCount());
if(count($this->toCraft) === 0){
$this->toCraft[-1] = 0;
@ -2078,7 +2083,7 @@ class Player extends RealHuman{
$this->dataPacket($pk);
break;
}
if($item->getID() !== AIR and $slot->getID() == $item->getID()){
if($item->getID() !== Item::AIR and $slot->getID() == $item->getID()){
if($slot->getCount() < $item->getCount()){
$it = clone $item;
$it->setCount($item->getCount() - $slot->getCount());
@ -2134,13 +2139,13 @@ class Player extends RealHuman{
if($tile instanceof Furnace and $packet->slot == 2){
switch($slot->getID()){
case IRON_INGOT:
case Item::IRON_INGOT:
$this->grantAchievement("acquireIron");
break;
}
}
if($item->getID() !== AIR and $slot->getID() == $item->getID()){
if($item->getID() !== Item::AIR and $slot->getID() == $item->getID()){
if($slot->getCount() < $item->getCount()){
$it = clone $item;
$it->setCount($item->getCount() - $slot->getCount());

View File

@ -52,8 +52,8 @@ class PluginAPI extends \stdClass{
break;
case "version":
$output = "PocketMine-MP " . VERSION . "" . CODENAME . "」 API #" . API_VERSION . " for Minecraft: PE " . MINECRAFT_VERSION . " protocol #" . Info::CURRENT_PROTOCOL;
if(GIT_COMMIT !== str_repeat("00", 20)){
$output .= " (git " . GIT_COMMIT . ")";
if(\PocketMine\GIT_COMMIT !== str_repeat("00", 20)){
$output .= " (git " . \PocketMine\GIT_COMMIT . ")";
}
$output .= "\n";
break;

View File

@ -293,7 +293,7 @@ namespace PocketMine {
function log($message, $name, $EOL = true, $level = 2, $close = false){
global $fpointers;
if((!defined("PocketMine\\DEBUG") or \PocketMine\DEBUG >= $level) and (!defined("PocketMine\\LOG") or LOG === true)){
if((!defined("PocketMine\\DEBUG") or \PocketMine\DEBUG >= $level) and (!defined("PocketMine\\LOG") or \PocketMine\LOG === true)){
$message .= $EOL === true ? PHP_EOL : "";
if(!isset($fpointers)){
$fpointers = array();

View File

@ -399,7 +399,7 @@ class Server{
}
console("[INFO] Default game type: " . strtoupper($this->getGamemode()));
$this->trigger("server.start", microtime(true));
console('[INFO] Done (' . round(microtime(true) - START_TIME, 3) . 's)! For help, type "help" or "?"');
console('[INFO] Done (' . round(microtime(true) - \PocketMine\START_TIME, 3) . 's)! For help, type "help" or "?"');
$this->process();
}

View File

@ -28,8 +28,7 @@ use PocketMine\Level\Level;
use PocketMine\Network\Protocol\Info;
use PocketMine\Network\Query\QueryHandler;
use PocketMine\Network\RCON\RCON;
use PocketMine\Network\UPnP\PortForward;
use PocketMine\Network\UPnP\RemovePortForward;
use PocketMine\Network\UPnP\UPnP;
use PocketMine\Recipes\Crafting;
use PocketMine\Tile\Tile;
use PocketMine\Utils\Config;
@ -153,7 +152,7 @@ class ServerAPI{
}
if($this->getProperty("upnp-forwarding") == true){
console("[INFO] [UPnP] Trying to port forward...");
PortForward($this->getProperty("server-port"));
UPnP::PortForward($this->getProperty("server-port"));
}
$this->server = new Server($this->getProperty("server-name"), $this->getProperty("gamemode"), ($seed = $this->getProperty("level-seed")) != "" ? (int) $seed : false, $this->getProperty("server-port"), ($ip = $this->getProperty("server-ip")) != "" ? $ip : "0.0.0.0");
$this->server->api = $this;
@ -171,7 +170,7 @@ class ServerAPI{
} else{
$last = new \DateTime($info[0]["commit"]["committer"]["date"]);
$last = $last->getTimestamp();
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and GIT_COMMIT != $info[0]["sha"]){
if($last >= $this->getProperty("last-update") and $this->getProperty("last-update") !== false and \PocketMine\GIT_COMMIT != $info[0]["sha"]){
console("[NOTICE] " . TextFormat::YELLOW . "A new DEVELOPMENT version of PocketMine-MP has been released!");
console("[NOTICE] " . TextFormat::YELLOW . "Commit \"" . $info[0]["commit"]["message"] . "\" [" . substr($info[0]["sha"], 0, 10) . "] by " . $info[0]["commit"]["committer"]["name"]);
console("[NOTICE] " . TextFormat::YELLOW . "Get it at PocketMine.net or at https://github.com/PocketMine/PocketMine-MP/archive/" . $info[0]["sha"] . ".zip");
@ -397,7 +396,7 @@ class ServerAPI{
$this->__destruct();
if($this->getProperty("upnp-forwarding") === true){
console("[INFO] [UPnP] Removing port forward...");
RemovePortForward($this->getProperty("server-port"));
UPnP::RemovePortForward($this->getProperty("server-port"));
}
return $this->restart;

View File

@ -134,7 +134,7 @@ class Bed extends Transparent{
public function getDrops(Item $item, PocketMine\Player $player){
return array(
array(BED, 0, 1),
array(Item::BED, 0, 1),
);
}

View File

@ -53,7 +53,7 @@ class Bricks extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(BRICKS_BLOCK, 0, 1),
array(Item::BRICKS_BLOCK, 0, 1),
);
} else{
return array();

View File

@ -54,7 +54,7 @@ class BurningFurnace extends Solid{
new Int("y", $this->y),
new Int("z", $this->z)
));
$nbt->Items->setTagType(NBT::Tag_Compound);
$nbt->Items->setTagType(NBT::TAG_Compound);
new Furnace($this->level, $nbt);
return true;
@ -80,7 +80,7 @@ class BurningFurnace extends Solid{
new Int("y", $this->y),
new Int("z", $this->z)
));
$nbt->Items->setTagType(NBT::Tag_Compound);
$nbt->Items->setTagType(NBT::TAG_Compound);
$furnace = new Furnace($this->level, $nbt);
}

View File

@ -85,9 +85,9 @@ class Carrot extends Flowable{
public function getDrops(Item $item, PocketMine\Player $player){
$drops = array();
if($this->meta >= 0x07){
$drops[] = array(CARROT, 0, mt_rand(1, 4));
$drops[] = array(Item::CARROT, 0, mt_rand(1, 4));
} else{
$drops[] = array(CARROT, 0, 1);
$drops[] = array(Item::CARROT, 0, 1);
}
return $drops;

View File

@ -32,6 +32,9 @@ use PocketMine;
use PocketMine\NBT\NBT;
class Chest extends Transparent{
const SLOTS = 27;
public function __construct($meta = 0){
parent::__construct(self::CHEST, $meta, "Chest");
$this->isActivable = true;
@ -72,7 +75,7 @@ class Chest extends Transparent{
new Int("y", $this->y),
new Int("z", $this->z)
));
$nbt->Items->setTagType(NBT::Tag_Compound);
$nbt->Items->setTagType(NBT::TAG_Compound);
$tile = new TileChest($this->level, $nbt);
if($chest instanceof TileChest){
@ -111,7 +114,7 @@ class Chest extends Transparent{
new Int("y", $this->y),
new Int("z", $this->z)
));
$nbt->Items->setTagType(NBT::Tag_Compound);
$nbt->Items->setTagType(NBT::TAG_Compound);
$chest = new TileChest($this->level, $nbt);
}
@ -133,7 +136,7 @@ class Chest extends Transparent{
if($t instanceof Chest){
for($s = 0; $s < Chest::SLOTS; ++$s){
$slot = $t->getSlot($s);
if($slot->getID() > AIR and $slot->getCount() > 0){
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
$drops[] = array($slot->getID(), $slot->getMetadata(), $slot->getCount());
}
}

View File

@ -53,7 +53,7 @@ class Coal extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COAL_BLOCK, 0, 1),
array(Item::COAL_BLOCK, 0, 1),
);
} else{
return array();

View File

@ -53,7 +53,7 @@ class CoalOre extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COAL, 0, 1),
array(Item::COAL, 0, 1),
);
} else{
return array();

View File

@ -53,7 +53,7 @@ class Cobblestone extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COBBLESTONE, 0, 1),
array(Item::COBBLESTONE, 0, 1),
);
} else{
return array();

View File

@ -47,7 +47,7 @@ class Diamond extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 4){
return array(
array(DIAMOND_BLOCK, 0, 1),
array(Item::DIAMOND_BLOCK, 0, 1),
);
} else{
return array();

View File

@ -47,7 +47,7 @@ class DiamondOre extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 4){
return array(
array(DIAMOND, 0, 1),
array(Item::DIAMOND, 0, 1),
);
} else{
return array();

View File

@ -36,7 +36,7 @@ class Dirt extends Solid{
if(($player->gamemode & 0x01) === 0){
$item->useOn($this);
}
$this->level->setBlock($this, Block::get(FARMLAND, 0), true, false, true);
$this->level->setBlock($this, Block::get(Item::FARMLAND, 0), true, false, true);
return true;
}

View File

@ -63,7 +63,7 @@ class DoubleSlab extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(SLAB, $this->meta & 0x07, 2),
array(Item::SLAB, $this->meta & 0x07, 2),
);
} else{
return array();

View File

@ -59,7 +59,7 @@ class DoubleWoodSlab extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
return array(
array(WOOD_SLAB, $this->meta & 0x07, 2),
array(Item::WOOD_SLAB, $this->meta & 0x07, 2),
);
}

View File

@ -32,7 +32,7 @@ class Farmland extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
return array(
array(DIRT, 0, 1),
array(Item::DIRT, 0, 1),
);
}
}

View File

@ -33,7 +33,7 @@ class GlowingRedstoneOre extends Solid{
public function onUpdate($type){
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(Item::REDSTONE_ORE, $this->meta), false, false, true);
return Level::BLOCK_UPDATE_WEAK;
}

View File

@ -47,7 +47,7 @@ class Gold extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 4){
return array(
array(GOLD_BLOCK, 0, 1),
array(Item::GOLD_BLOCK, 0, 1),
);
} else{
return array();

View File

@ -47,7 +47,7 @@ class GoldOre extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 4){
return array(
array(GOLD_ORE, 0, 1),
array(Item::GOLD_ORE, 0, 1),
);
} else{
return array();

View File

@ -35,7 +35,7 @@ class Grass extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
return array(
array(DIRT, 0, 1),
array(Item::DIRT, 0, 1),
);
}

View File

@ -38,7 +38,7 @@ class Gravel extends Fallable{
}
return array(
array(GRAVEL, 0, 1),
array(Item::GRAVEL, 0, 1),
);
}

View File

@ -49,7 +49,7 @@ class Iron extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 3){
return array(
array(IRON_BLOCK, 0, 1),
array(Item::IRON_BLOCK, 0, 1),
);
} else{
return array();

View File

@ -49,7 +49,7 @@ class IronOre extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 3){
return array(
array(IRON_ORE, 0, 1),
array(Item::IRON_ORE, 0, 1),
);
} else{
return array();

View File

@ -49,7 +49,7 @@ class Lapis extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 3){
return array(
array(LAPIS_BLOCK, 0, 1),
array(Item::LAPIS_BLOCK, 0, 1),
);
} else{
return array();

View File

@ -112,7 +112,7 @@ class Lava extends Liquid{
} elseif($b->isFlowable === 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, Level::BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
}
}
}
@ -126,7 +126,7 @@ class Lava extends Liquid{
if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($sb, new Air(), false, false, true);
}
@ -137,12 +137,12 @@ class Lava extends Liquid{
if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($b, new Air(), false, false, true);
}
}
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
//ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($this, new Air(), false, false, true);

View File

@ -55,7 +55,7 @@ class Leaves extends Transparent{
} elseif($pos->getID() === self::LEAVES and $distance < 3){
$visited[$index] = true;
$down = $pos->getSide(0)->getID();
if($down === WOOD){
if($down === Item::WOOD){
return true;
}
if($fromSide === null){
@ -126,11 +126,11 @@ class Leaves extends Transparent{
$this->level->setBlock($this, new Air(), false, false, true);
if(mt_rand(1, 20) === 1){ //Saplings
//TODO
ServerAPI::request()->api->entity->drop($this, Item::get(SAPLING, $this->meta & 0x03, 1));
//ServerAPI::request()->api->entity->drop($this, Item::get(Item::SAPLING, $this->meta & 0x03, 1));
}
if(($this->meta & 0x03) === self::OAK and mt_rand(1, 200) === 1){ //Apples
//TODO
ServerAPI::request()->api->entity->drop($this, Item::get(APPLE, 0, 1));
//ServerAPI::request()->api->entity->drop($this, Item::get(Item::APPLE, 0, 1));
}
return Level::BLOCK_UPDATE_NORMAL;
@ -149,13 +149,13 @@ class Leaves extends Transparent{
public function getDrops(Item $item, PocketMine\Player $player){
$drops = array();
if($item->isShears()){
$drops[] = array(LEAVES, $this->meta & 0x03, 1);
$drops[] = array(Item::LEAVES, $this->meta & 0x03, 1);
} else{
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = array(Item::SAPLING, $this->meta & 0x03, 1);
}
if(($this->meta & 0x03) === self::OAK and mt_rand(1, 200) === 1){ //Apples
$drops[] = array(APPLE, 0, 1);
$drops[] = array(Item::APPLE, 0, 1);
}
}

View File

@ -53,7 +53,7 @@ class MossStone extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(MOSS_STONE, $this->meta, 1),
array(Item::MOSS_STONE, $this->meta, 1),
);
} else{
return array();

View File

@ -53,7 +53,7 @@ class NetherBrick extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(NETHER_BRICKS, 0, 1),
array(Item::NETHER_BRICKS, 0, 1),
);
} else{
return array();

View File

@ -53,7 +53,7 @@ class Netherrack extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(NETHERRACK, 0, 1),
array(Item::NETHERRACK, 0, 1),
);
} else{
return array();

View File

@ -44,7 +44,7 @@ class Obsidian extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 5){
return array(
array(OBSIDIAN, 0, 1),
array(Item::OBSIDIAN, 0, 1),
);
} else{
return array();

View File

@ -85,9 +85,9 @@ class Potato extends Flowable{
public function getDrops(Item $item, PocketMine\Player $player){
$drops = array();
if($this->meta >= 0x07){
$drops[] = array(POTATO, 0, mt_rand(1, 4));
$drops[] = array(Item::POTATO, 0, mt_rand(1, 4));
} else{
$drops[] = array(POTATO, 0, 1);
$drops[] = array(Item::POTATO, 0, 1);
}
return $drops;

View File

@ -59,7 +59,7 @@ class Quartz extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(QUARTZ_BLOCK, $this->meta & 0x03, 1),
array(Item::QUARTZ_BLOCK, $this->meta & 0x03, 1),
);
} else{
return array();

View File

@ -33,7 +33,7 @@ class RedstoneOre extends Solid{
public function onUpdate($type){
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(Item::GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
return Level::BLOCK_UPDATE_WEAK;
}
@ -44,7 +44,7 @@ class RedstoneOre extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 2){
return array(
array(Redstone\REDSTONE_DUST, 0, mt_rand(4, 5)),
array(Item::REDSTONE_DUST, 0, mt_rand(4, 5)),
);
} else{
return array();

View File

@ -59,7 +59,7 @@ class Sandstone extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(SANDSTONE, $this->meta & 0x03, 1),
array(Item::SANDSTONE, $this->meta & 0x03, 1),
);
} else{
return array();

View File

@ -43,12 +43,12 @@ class SignPost extends Transparent{
);
if(!isset($faces[$face])){
$this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
$this->level->setBlock($block, Block::get(SIGN_POST, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true, false, true);
return true;
} else{
$this->meta = $faces[$face];
$this->level->setBlock($block, Block::get(WALL_SIGN, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true, false, true);
return true;
}

View File

@ -50,11 +50,11 @@ class Slab extends Transparent{
$this->meta &= 0x07;
if($face === 0){
if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
return true;
} elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
return true;
} else{
@ -62,18 +62,18 @@ class Slab extends Transparent{
}
} elseif($face === 1){
if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
return true;
} elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}
} elseif(!$player->inBlock($block)){
if($block->getID() === self::SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block::get(DOUBLE_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
return true;
}

View File

@ -53,7 +53,7 @@ class Stone extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(COBBLESTONE, 0, 1),
array(Item::COBBLESTONE, 0, 1),
);
} else{
return array();

View File

@ -60,7 +60,7 @@ class StoneBricks extends Solid{
public function getDrops(Item $item, PocketMine\Player $player){
if($item->isPickaxe() >= 1){
return array(
array(STONE_BRICKS, $this->meta & 0x03, 1),
array(Item::STONE_BRICKS, $this->meta & 0x03, 1),
);
} else{
return array();

View File

@ -34,12 +34,12 @@ class Sugarcane extends Flowable{
public function getDrops(Item $item, PocketMine\Player $player){
return array(
array(SUGARCANE, 0, 1),
array(Item::SUGARCANE, 0, 1),
);
}
public function onActivate(Item $item, PocketMine\Player $player){
if($item->getID() === self::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){
for($y = 1; $y < 3; ++$y){
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));

View File

@ -25,6 +25,7 @@ use PocketMine\Item\Item;
use PocketMine\Level\Level;
use PocketMine\ServerAPI;
use PocketMine;
use PocketMine\Level\Position;
class Water extends Liquid{
public function __construct($meta = 0){
@ -109,7 +110,7 @@ class Water extends Liquid{
if($level !== 0x07){
if($down instanceof Air || $down instanceof Water){
$this->level->setBlock($down, new Water(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($down, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
} else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
@ -119,7 +120,7 @@ class Water extends Liquid{
}
} elseif($b->isFlowable === 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, Level::BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
}
}
@ -133,7 +134,7 @@ class Water extends Liquid{
if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($sb, new Air(), false, false, true);
}
@ -144,12 +145,12 @@ class Water extends Liquid{
if($tlevel != 0x00){
for($s = 0; $s <= 5; $s++){
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($b, new Air(), false, false, true);
}
}
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
//ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($this, new Air(), false, false, true);
}

View File

@ -46,11 +46,11 @@ class WoodSlab extends Transparent{
$this->meta &= 0x07;
if($face === 0){
if($target->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
$this->level->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
} elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
} else{
@ -58,18 +58,18 @@ class WoodSlab extends Transparent{
}
} elseif($face === 1){
if($target->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($target, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
$this->level->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
} elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}
} elseif(!$player->inBlock($block)){
if($block->getID() === self::WOOD_SLAB){
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
$this->level->setBlock($block, Block::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
$this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
return true;
}

View File

@ -34,6 +34,7 @@ use PocketMine\Level\Position;
use PocketMine\Math\AxisAlignedBB;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\NBT\Tag\Compound;
use PocketMine\Network;
use PocketMine\Network\Protocol\MoveEntityPacket_PosRot;
use PocketMine\Network\Protocol\MovePlayerPacket;
use PocketMine\Network\Protocol\RemoveEntityPacket;
@ -270,6 +271,24 @@ abstract class Entity extends Position{
}
}
public function getDirection(){
$rotation = ($this->yaw - 90) % 360;
if($rotation < 0) {
$rotation += 360.0;
}
if((0 <= $rotation and $rotation < 45) or (315 <= $rotation and $rotation < 360)){
return 2; //North
}elseif(45 <= $rotation and $rotation < 135){
return 3; //East
}elseif(135 <= $rotation and $rotation < 225){
return 0; //South
}elseif(225 <= $rotation and $rotation < 315){
return 1; //West
}else{
return null;
}
}
public function extinguish(){
$this->fireTicks = 0;
}
@ -281,7 +300,7 @@ abstract class Entity extends Position{
protected function updateFallState($distanceThisTick, $onGround){
if($onGround === true){
if($this->fallDistance > 0){
if($this instanceof EntityLiving){
if($this instanceof Living){
//TODO
}
@ -347,7 +366,7 @@ abstract class Entity extends Position{
$this->level->entities[$this->id] = $this;
if($this instanceof Player){
$this->chunksLoaded = array();
$pk = new SetTimePacket;
$pk = new Network\Protocol\SetTimePacket;
$pk->time = $this->level->getTime();
$pk->started = $this->level->stopTime == false;
$this->dataPacket($pk);
@ -455,7 +474,7 @@ abstract class Entity extends Position{
return $this->level;
}
public function teleport(Position $pos, $yaw = false, $pitch = false){
public function teleport(Vector3 $pos, $yaw = false, $pitch = false){
$this->setMotion(new Vector3(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw === false ? $this->yaw : $yaw, $pitch === false ? $this->pitch : $pitch) !== false){
if($this instanceof Player){

View File

@ -210,7 +210,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
public function getArmorSlot($slot){
$slot = (int) $slot;
if(!isset($this->armor[$slot])){
$this->armor[$slot] = Item::get(AIR, 0, 0);
$this->armor[$slot] = Item::get(Item::AIR, 0, 0);
}
return $this->armor[$slot];
@ -292,7 +292,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
while($item->getCount() > 0){
$add = 0;
foreach($inv as $s => $i){
if($i->getID() === AIR){
if($i->getID() === Item::AIR){
$add = min($i->getMaxStackSize(), $item->getCount());
$inv[$s] = clone $item;
$inv[$s]->setCount($add);
@ -320,7 +320,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
while($item->getCount() > 0){
$add = 0;
foreach($this->inventory as $s => $i){
if($i->getID() === AIR){
if($i->getID() === Item::AIR){
$add = min($i->getMaxStackSize(), $item->getCount());
$i2 = clone $item;
$i2->setCount($add);
@ -360,7 +360,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{
$i->setCount($i->getCount() - $item->getCount());
$this->setSlot($s, $i);
} else{
$this->setSlot($s, Item::get(AIR, 0, 0));
$this->setSlot($s, Item::get(Item::AIR, 0, 0));
}
break;
}

View File

@ -23,6 +23,6 @@ namespace PocketMine\Entity;
use PocketMine;
interface TameableEntity{
interface Tameable{
}

View File

@ -28,6 +28,7 @@ use PocketMine\Block\Liquid;
use PocketMine\Block\Water;
use PocketMine\Level\Level;
use PocketMine;
use PocketMine\Player;
class Bucket extends Item{
public function __construct($meta = 0, $count = 1){
@ -37,16 +38,16 @@ class Bucket extends Item{
}
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($this->meta === AIR){
if($this->meta === Item::AIR){
if($target instanceof Liquid){
$level->setBlock($target, new Air(), true, false, true);
if(($player->gamemode & 0x01) === 0){
$this->meta = ($target instanceof Water) ? WATER : LAVA;
$this->meta = ($target instanceof Water) ? Item::WATER : Item::LAVA;
}
return true;
}
} elseif($this->meta === WATER){
} elseif($this->meta === Item::WATER){
//Support Make Non-Support Water to Support Water
if($block->getID() === self::AIR || ($block instanceof Water && ($block->getMetadata() & 0x07) != 0x00)){
$water = new Water();
@ -58,7 +59,7 @@ class Bucket extends Item{
return true;
}
} elseif($this->meta === LAVA){
} elseif($this->meta === Item::LAVA){
if($block->getID() === self::AIR){
$level->setBlock($block, new Lava(), true, false, true);
if(($player->gamemode & 0x01) === 0){

View File

@ -26,6 +26,7 @@ use PocketMine\Block\Fire;
use PocketMine\Block\Solid;
use PocketMine\Level\Level;
use PocketMine;
use PocketMine\Player;
class FlintSteel extends Item{
public function __construct($meta = 0, $count = 1){
@ -36,7 +37,7 @@ class FlintSteel extends Item{
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0));
$player->setSlot($player->slot, new Item(Item::AIR, 0, 0));
}
if($block->getID() === self::AIR and ($target instanceof Solid)){

View File

@ -31,6 +31,7 @@ use PocketMine\Level\Level;
use PocketMine\Recipes\Fuel;
use PocketMine\Recipes\Smelt;
use PocketMine;
use PocketMine\Player;
class Item{
//All Block IDs are here too

View File

@ -25,6 +25,7 @@ use PocketMine\Block\Block;
use PocketMine\Level\Level;
use PocketMine\ServerAPI;
use PocketMine;
use PocketMine\Player;
class Painting extends Item{
public function __construct($meta = 0, $count = 1){

View File

@ -21,8 +21,10 @@
namespace PocketMine\Item;
use PocketMine\Entity;
use PocketMine\Block\Block;
use PocketMine\Level\Level;
use PocketMine\Player;
use PocketMine;
class SpawnEgg extends Item{
@ -34,10 +36,11 @@ class SpawnEgg extends Item{
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
switch($this->meta){
case Entity\CHICKEN:
case Entity\SHEEP:
case Entity\COW:
case Entity\PIG:
//TODO: use entity constants
case 10:
case 11:
case 12:
case 13:
$data = array(
"x" => $block->x + 0.5,
"y" => $block->y,

View File

@ -28,14 +28,15 @@ use PocketMine\Network\Protocol\ExplodePacket;
use PocketMine\Player;
use PocketMine\ServerAPI;
use PocketMine;
use PocketMine\Item\Item;
class Explosion{
public static $specialDrops = array(
GRASS => DIRT,
STONE => COBBLESTONE,
COAL_ORE => COAL,
DIAMOND_ORE => DIAMOND,
REDSTONE_ORE => REDSTONE,
Item::GRASS => Item::DIRT,
Item::STONE => Item::COBBLESTONE,
Item::COAL_ORE => Item::COAL,
Item::DIAMOND_ORE => Item::DIAMOND,
Item::REDSTONE_ORE => Item::REDSTONE,
);
private $rays = 16; //Rays
public $level;

View File

@ -416,7 +416,7 @@ class Level{
}
$now = microtime(true);
if($this->stopTime == true){
return;
} else{
$time = $this->startTime + ($now - $this->startCheck) * 20;
}
@ -864,8 +864,13 @@ class Level{
return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this);
}
public function getSafeSpawn($spawn = false){
if($spawn === false){
/**
* @param Vector3 $spawn default null
*
* @return bool|Position
*/
public function getSafeSpawn($spawn = null){
if(!($spawn instanceof Vector3)){
$spawn = $this->getSpawn();
}
if($spawn instanceof Vector3){

View File

@ -24,6 +24,7 @@ namespace PocketMine\Level;
use PocketMine\PMF\LevelFormat;
use PocketMine\Utils\Config;
use PocketMine;
use PocketMine\NBT\NBT;
class LevelImport{
private $path;

View File

@ -31,27 +31,47 @@ class Position extends Vector3{
*/
public $level = null;
/**
* @param int $x
* @param int $y
* @param int $z
* @param Level $level
*/
public function __construct($x = 0, $y = 0, $z = 0, Level $level){
if(($x instanceof Vector3) === true){
$this->__construct($x->x, $x->y, $x->z, $level);
} else{
$this->x = $x;
$this->y = $y;
$this->z = $z;
}
$this->x = $x;
$this->y = $y;
$this->z = $z;
$this->level = $level;
}
public function getSide($side){
return new Position(parent::getSide($side), 0, 0, $this->level);
public static function fromObject(Vector3 $pos, Level $level){
return new Position($pos->x, $pos->y, $pos->z, $level);
}
public function distance($x = 0, $y = 0, $z = 0){
if(($x instanceof Position) and $x->level !== $this->level){
/**
* Returns a side Vector
*
* @param $side
*
* @return Position
*/
public function getSide($side){
return Position::fromObject(parent::getSide($side), $this->level);
}
/**
* Returns the distance between two points or objects
*
* @param Vector3 $pos
*
* @return float
*/
public function distance(Vector3 $pos){
if(($pos instanceof Position) and $pos->level !== $this->level){
return PHP_INT_MAX;
}
return parent::distance($x, $y, $z);
return parent::distance($pos);
}
public function __toString(){

View File

@ -58,14 +58,14 @@ class Flat extends Generator{
if(isset($this->options["decoration"])){
$ores = new Ore();
$ores->setOreTypes(array(
new Object\Ore\Type(new CoalOre(), 20, 16, 0, 128),
new Object\Ore\Type(New IronOre(), 20, 8, 0, 64),
new Object\Ore\Type(new RedstoneOre(), 8, 7, 0, 16),
new Object\Ore\Type(new LapisOre(), 1, 6, 0, 32),
new Object\Ore\Type(new GoldOre(), 2, 8, 0, 32),
new Object\Ore\Type(new DiamondOre(), 1, 7, 0, 16),
new Object\Ore\Type(new Dirt(), 20, 32, 0, 128),
new Object\Ore\Type(new Gravel(), 10, 16, 0, 128),
new Object\OreType(new CoalOre(), 20, 16, 0, 128),
new Object\OreType(New IronOre(), 20, 8, 0, 64),
new Object\OreType(new RedstoneOre(), 8, 7, 0, 16),
new Object\OreType(new LapisOre(), 1, 6, 0, 32),
new Object\OreType(new GoldOre(), 2, 8, 0, 32),
new Object\OreType(new DiamondOre(), 1, 7, 0, 16),
new Object\OreType(new Dirt(), 20, 32, 0, 128),
new Object\OreType(new Gravel(), 10, 16, 0, 128),
));
$this->populators[] = $ores;
}
@ -97,7 +97,7 @@ class Flat extends Generator{
$this->floorLevel = $y;
for(; $y < 0xFF; ++$y){
$this->structure[$y] = new Block\Special\Air();
$this->structure[$y] = new PocketMine\Block\Air();
}

View File

@ -306,14 +306,14 @@ class Simplex extends Perlin{
* Computes and returns the 4D simplex noise for the given coordinates in
* 4D space
*
* @param x X coordinate
* @param y Y coordinate
* @param z Z coordinate
* @param w W coordinate
* @param float $x X coordinate
* @param float $y Y coordinate
* @param float $z Z coordinate
* @param float $w W coordinate
*
* @return Noise at given location, from range -1 to 1
* @return float Noise at given location, from range -1 to 1
*/
/*public function getNoise4D(x, y, z, w){
/*public function getNoise4D($x, $y, $z, $w){
x += offsetX;
y += offsetY;
z += offsetZ;

View File

@ -50,7 +50,7 @@ class BigTree extends Tree{
$leaves = $this->getLeafGroupPoints($level, $pos);
foreach($leaves as $leafGroup){
$groupX = $leafGroup->getBlockX();
$groupY = $leafGrou->getBlockY();
$groupY = $leafGroup->getBlockY();
$groupZ = $leafGroup->getBlockZ();
for($yy = $groupY; $yy < $groupY + $this->leafDistanceLimit; ++$yy){
$this->generateGroupLayer($level, $groupX, $yy, $groupZ, $this->getLeafGroupLayerSize($yy - $groupY));

View File

@ -22,9 +22,10 @@
namespace PocketMine\Level\Generator\Object;
use PocketMine\Block\Block;
use PocketMine\Level;
use PocketMine\Level\Level;
use PocketMine;
use PocketMine\Math\Vector3 as Vector3;
use PocketMine\Utils\Random;
class TallGrass{
public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){

View File

@ -39,7 +39,7 @@ class Pond extends Populator{
$random->nextRange(0, 128),
$random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16)
);
$pond = new Level\Genenerator\Object\Pond($random, new Water());
$pond = new PocketMine\Level\Generator\Object\Pond($random, new Water());
if($pond->canPlaceObject($level, $v)){
$pond->placeObject($level, $v);
}

View File

@ -29,6 +29,9 @@ use PocketMine\Utils\Random;
use PocketMine;
class TallGrass extends Populator{
/**
* @var Level
*/
private $level;
private $randomAmount;
private $baseAmount;

View File

@ -22,10 +22,11 @@
namespace PocketMine\Math;
use PocketMine;
use PocketMine\Math\Vector3 as MathVector3;
class Vector3{
public $x, $y, $z;
public $x;
public $y;
public $z;
public function __construct($x = 0, $y = 0, $z = 0){
$this->x = $x;
@ -78,15 +79,15 @@ class Vector3{
}
public function add($x = 0, $y = 0, $z = 0){
if(($x instanceof MathVector3) === true){
if(($x instanceof Vector3) === true){
return $this->add($x->x, $x->y, $x->z);
} else{
return new MathVector3($this->x + $x, $this->y + $y, $this->z + $z);
return new Vector3($this->x + $x, $this->y + $y, $this->z + $z);
}
}
public function subtract($x = 0, $y = 0, $z = 0){
if(($x instanceof MathVector3) === true){
if(($x instanceof Vector3) === true){
return $this->add(-$x->x, -$x->y, -$x->z);
} else{
return $this->add(-$x, -$y, -$z);
@ -94,66 +95,58 @@ class Vector3{
}
public function multiply($number){
return new MathVector3($this->x * $number, $this->y * $number, $this->z * $number);
return new Vector3($this->x * $number, $this->y * $number, $this->z * $number);
}
public function divide($number){
return new MathVector3($this->x / $number, $this->y / $number, $this->z / $number);
return new Vector3($this->x / $number, $this->y / $number, $this->z / $number);
}
public function ceil(){
return new MathVector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
return new Vector3((int) ($this->x + 1), (int) ($this->y + 1), (int) ($this->z + 1));
}
public function floor(){
return new MathVector3((int) $this->x, (int) $this->y, (int) $this->z);
return new Vector3((int) $this->x, (int) $this->y, (int) $this->z);
}
public function round(){
return new MathVector3(round($this->x), round($this->y), round($this->z));
return new Vector3(round($this->x), round($this->y), round($this->z));
}
public function abs(){
return new MathVector3(abs($this->x), abs($this->y), abs($this->z));
return new Vector3(abs($this->x), abs($this->y), abs($this->z));
}
public function getSide($side){
switch((int) $side){
case 0:
return new MathVector3($this->x, $this->y - 1, $this->z);
return new Vector3($this->x, $this->y - 1, $this->z);
case 1:
return new MathVector3($this->x, $this->y + 1, $this->z);
return new Vector3($this->x, $this->y + 1, $this->z);
case 2:
return new MathVector3($this->x, $this->y, $this->z - 1);
return new Vector3($this->x, $this->y, $this->z - 1);
case 3:
return new MathVector3($this->x, $this->y, $this->z + 1);
return new Vector3($this->x, $this->y, $this->z + 1);
case 4:
return new MathVector3($this->x - 1, $this->y, $this->z);
return new Vector3($this->x - 1, $this->y, $this->z);
case 5:
return new MathVector3($this->x + 1, $this->y, $this->z);
return new Vector3($this->x + 1, $this->y, $this->z);
default:
return $this;
}
}
public function distance($x = 0, $y = 0, $z = 0){
if(($x instanceof MathVector3) === true){
return sqrt($this->distanceSquared($x->x, $x->y, $x->z));
} else{
return sqrt($this->distanceSquared($x, $y, $z));
}
public function distance(Vector3 $pos){
return sqrt($this->distanceSquared($pos));
}
public function distanceSquared($x = 0, $y = 0, $z = 0){
if(($x instanceof MathVector3) === true){
return $this->distanceSquared($x->x, $x->y, $x->z);
} else{
return pow($this->x - $x, 2) + pow($this->y - $y, 2) + pow($this->z - $z, 2);
}
public function distanceSquared(Vector3 $pos){
return pow($this->x - $pos->x, 2) + pow($this->y - $pos->y, 2) + pow($this->z - $pos->z, 2);
}
public function maxPlainDistance($x = 0, $z = 0){
if(($x instanceof MathVector3) === true){
if(($x instanceof Vector3) === true){
return $this->maxPlainDistance($x->x, $x->z);
} else{
return max(abs($this->x - $x), abs($this->z - $z));
@ -174,15 +167,15 @@ class Vector3{
return $this->divide($len);
}
return new MathVector3(0, 0, 0);
return new Vector3(0, 0, 0);
}
public function dot(MathVector3 $v){
public function dot(Vector3 $v){
return $this->x * $v->x + $this->y * $v->y + $this->z * $v->z;
}
public function cross(MathVector3 $v){
return new MathVector3(
public function cross(Vector3 $v){
return new Vector3(
$this->y * $v->z - $this->z * $v->y,
$this->z * $v->x - $this->x * $v->z,
$this->x * $v->y - $this->y * $v->x

View File

@ -31,7 +31,7 @@ class Byte_Array extends NamedTag{
}
public function read(NBT $nbt){
$this->value = $nbt->get($this->getInt());
$this->value = $nbt->get($nbt->getInt());
}
public function write(NBT $nbt){

View File

@ -27,6 +27,10 @@ abstract class NamedTag extends Tag{
protected $name;
/**
* @param string $name
* @param bool|float|double|int|byte|short|array|Compound|Enum|string $value
*/
public function __construct($name = "", $value = false){
$this->name = $name;
if($value !== false){

View File

@ -51,7 +51,7 @@ class Handler{
}
public function close(){
return $this->socket->close(false);
$this->socket->close(false);
}
public function readPacket(){
@ -87,7 +87,7 @@ class Handler{
}
ServerAPI::request()->api->query->handle($packet);
} else{
$packet = new Packet();
$packet = new Packet($pid);
$packet->ip = $source;
$packet->port = $port;
$packet->buffer =& $buffer;

View File

@ -48,7 +48,7 @@ class UDPSocket{
}
public function close($error = 125){
return @socket_close($this->sock);
socket_close($this->sock);
}
public function block(){

View File

@ -1,71 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/**
* UPnP port forwarding support. Only for Windows
*/
namespace PocketMine\Network\UPnP;
use PocketMine;
use PocketMine\Utils\Utils;
function PortForward($port){
if(Utils::$online === false){
return false;
}
if(Utils::getOS() != "win" or !class_exists("COM")){
return false;
}
$port = (int) $port;
$myLocalIP = gethostbyname(trim(`hostname`));
try{
$com = new COM("HNetCfg.NATUPnP");
if($com === false or !is_object($com->StaticPortMappingCollection)){
return false;
}
$com->StaticPortMappingCollection->Add($port, "UDP", $port, $myLocalIP, true, "PocketMine-MP");
} catch(Exception $e){
return false;
}
return true;
}
function RemovePortForward($port){
if(Utils::$online === false){
return false;
}
if(Utils::getOS() != "win" or !class_exists("COM")){
return false;
}
$port = (int) $port;
try{
$com = new COM("HNetCfg.NATUPnP") or false;
if($com === false or !is_object($com->StaticPortMappingCollection)){
return false;
}
$com->StaticPortMappingCollection->Remove($port, "UDP");
} catch(Exception $e){
return false;
}
return true;
}

View File

@ -1,46 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace PocketMine\Network\UPnP;
use PocketMine;
use PocketMine\Utils\Utils;
function RemovePortForward($port){
if(Utils::$online === false){
return false;
}
if(Utils::getOS() != "win" or !class_exists("COM")){
return false;
}
$port = (int) $port;
try{
$com = new COM("HNetCfg.NATUPnP") or false;
if($com === false or !is_object($com->StaticPortMappingCollection)){
return false;
}
$com->StaticPortMappingCollection->Remove($port, "UDP");
} catch(Exception $e){
return false;
}
return true;
}

View File

@ -0,0 +1,73 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/**
* UPnP port forwarding support. Only for Windows
*/
namespace PocketMine\Network\UPnP;
use PocketMine;
use PocketMine\Utils\Utils;
abstract class UPnP{
public static function PortForward($port){
if(Utils::$online === false){
return false;
}
if(Utils::getOS() != "win" or !class_exists("COM")){
return false;
}
$port = (int) $port;
$myLocalIP = gethostbyname(trim(`hostname`));
try{
$com = new \COM("HNetCfg.NATUPnP");
if($com === false or !is_object($com->StaticPortMappingCollection)){
return false;
}
$com->StaticPortMappingCollection->Add($port, "UDP", $port, $myLocalIP, true, "PocketMine-MP");
} catch(\Exception $e){
return false;
}
return true;
}
public static function RemovePortForward($port){
if(Utils::$online === false){
return false;
}
if(Utils::getOS() != "win" or !class_exists("COM")){
return false;
}
$port = (int) $port;
try{
$com = new \COM("HNetCfg.NATUPnP") or false;
if($com === false or !is_object($com->StaticPortMappingCollection)){
return false;
}
$com->StaticPortMappingCollection->Remove($port, "UDP");
} catch(\Exception $e){
return false;
}
return true;
}
}

View File

@ -45,7 +45,7 @@ class Plugin extends PMF{
}
$this->seek(5);
$this->pluginData["fversion"] = ord($this->read(1));
if($this->pluginData["fversion"] > PMFPlugin::VERSION){
if($this->pluginData["fversion"] > self::VERSION){
return false;
}
$this->pluginData["name"] = $this->read(Utils::readShort($this->read(2), false));

View File

@ -28,6 +28,8 @@ use PocketMine\NBT\Tag\Int;
use PocketMine\NBT\Tag\String;
use PocketMine\Network\Protocol\EntityDataPacket;
use PocketMine;
use PocketMine\Player;
use PocketMine\NBT\NBT;
class Chest extends Spawnable{
use Container;

View File

@ -61,19 +61,19 @@ class Furnace extends Tile{
$raw = $this->getSlot(0);
$product = $this->getSlot(2);
$smelt = $raw->getSmeltItem();
$canSmelt = ($smelt !== false and $raw->getCount() > 0 and (($product->getID() === $smelt->getID() and $product->getMetadata() === $smelt->getMetadata() and $product->getCount() < $product->getMaxStackSize()) or $product->getID() === AIR));
$canSmelt = ($smelt !== false and $raw->getCount() > 0 and (($product->getID() === $smelt->getID() and $product->getMetadata() === $smelt->getMetadata() and $product->getCount() < $product->getMaxStackSize()) or $product->getID() === Item::AIR));
if($this->namedtag->BurnTime <= 0 and $canSmelt and $fuel->getFuelTime() !== false and $fuel->getCount() > 0){
$this->lastUpdate = microtime(true);
$this->namedtag->MaxTime = $this->namedtag->BurnTime = floor($fuel->getFuelTime() * 20);
$this->namedtag->BurnTicks = 0;
$fuel->setCount($fuel->getCount() - 1);
if($fuel->getCount() === 0){
$fuel = Item::get(AIR, 0, 0);
$fuel = Item::get(Item::AIR, 0, 0);
}
$this->setSlot(1, $fuel, false);
$current = $this->level->getBlock($this);
if($current->getID() === FURNACE){
$this->level->setBlock($this, Block::get(BURNING_FURNACE, $current->getMetadata()), true, false, true);
if($current->getID() === Item::FURNACE){
$this->level->setBlock($this, Block::get(Item::BURNING_FURNACE, $current->getMetadata()), true, false, true);
}
}
if($this->namedtag->BurnTime > 0){
@ -87,7 +87,7 @@ class Furnace extends Tile{
$this->setSlot(2, $product, false);
$raw->setCount($raw->getCount() - 1);
if($raw->getCount() === 0){
$raw = Item::get(AIR, 0, 0);
$raw = Item::get(Item::AIR, 0, 0);
}
$this->setSlot(0, $raw, false);
$this->namedtag->CookTime -= 200;
@ -102,8 +102,8 @@ class Furnace extends Tile{
$ret = true;
} else{
$current = $this->level->getBlock($this);
if($current->getID() === BURNING_FURNACE){
$this->level->setBlock($this, Block::get(FURNACE, $current->getMetadata()), true, false, true);
if($current->getID() === Item::BURNING_FURNACE){
$this->level->setBlock($this, Block::get(Item::FURNACE, $current->getMetadata()), true, false, true);
}
$this->namedtag->CookTime = 0;
$this->namedtag->BurnTime = 0;

View File

@ -28,6 +28,7 @@ use PocketMine\NBT\Tag\Int;
use PocketMine\NBT\Tag\String;
use PocketMine\Network\Protocol\EntityDataPacket;
use PocketMine;
use PocketMine\Player;
class Sign extends Spawnable{

View File

@ -22,6 +22,7 @@
namespace PocketMine\Tile;
use PocketMine;
use PocketMine\Player;
abstract class Spawnable extends Tile{
public abstract function spawnTo(Player $player);

View File

@ -102,7 +102,7 @@ abstract class Tile extends Position{
unset($this->level->tiles[$this->id]);
unset($this->level->chunkTiles[$this->chunkIndex][$this->id]);
unset(Tile::$list[$this->id]);
$this->server->api->dhandle("tile.remove", $t);
$this->server->api->dhandle("tile.remove", $this);
}
}

View File

@ -75,7 +75,7 @@ class Config{
);
/**
* @param $file Path of the file to be loaded
* @param string $file Path of the file to be loaded
* @param int $type Config type to load, -1 by default (detect)
* @param array $default Array with the default values, will be set if not existent
* @param null &$correct Sets correct to true if everything has been loaded correctly
@ -182,6 +182,7 @@ class Config{
*/
public function save(){
if($this->correct === true){
$content = null;
switch($this->type){
case Config::PROPERTIES:
case Config::CNF:
@ -257,7 +258,7 @@ class Config{
}
/**
* @param $k key to be set
* @param string $k key to be set
* @param bool $v value to set key
*/
public function set($k, $v = true){

View File

@ -365,7 +365,7 @@ class Utils{
}
if($types === true){
$m[$bottom] = array($r, $type);
} else{
}else{
$m[$bottom] = $r;
}
$b = ord($value{$offset});

View File

@ -27,6 +27,7 @@ namespace PocketMine\Wizard;
use PocketMine;
use PocketMine\Utils\Utils;
use PocketMine\Utils\Config;
class Installer{
const DEFAULT_NAME = "Minecraft: PE Server";
@ -35,7 +36,7 @@ class Installer{
const DEFAULT_PLAYERS = 20;
const DEFAULT_GAMEMODE = 0;
private $lang, $config;
private $lang;
public function __construct(){
echo "[*] PocketMine-MP set-up wizard\n";
@ -90,7 +91,7 @@ LICENSE;
}
private function generateBaseConfig(){
$config = new UtilsConfig(\PocketMine\DATA . "server.properties", UtilsConfig::PROPERTIES);
$config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES);
echo "[?] " . $this->lang->name_your_server . " (" . self::DEFAULT_NAME . "): ";
$config->set("server-name", $this->getInput(self::DEFAULT_NAME));
echo "[*] " . $this->lang->port_warning . "\n";
@ -130,13 +131,13 @@ LICENSE;
if($op === ""){
echo "[!] " . $this->lang->op_warning . "\n";
} else{
$ops = new UtilsConfig(\PocketMine\DATA . "ops.txt", UtilsConfig::ENUM);
$ops = new Config(\PocketMine\DATA . "ops.txt", Config::ENUM);
$ops->set($op, true);
$ops->save();
}
echo "[*] " . $this->lang->whitelist_info . "\n";
echo "[?] " . $this->lang->whitelist_enable . " (y/N): ";
$config = new UtilsConfig(\PocketMine\DATA . "server.properties", UtilsConfig::PROPERTIES);
$config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES);
if(strtolower($this->getInput("n")) === "y"){
echo "[!] " . $this->lang->whitelist_warning . "\n";
$config->set("white-list", true);
@ -147,7 +148,7 @@ LICENSE;
}
private function networkFunctions(){
$config = new UtilsConfig(\PocketMine\DATA . "server.properties", UtilsConfig::PROPERTIES);
$config = new Config(\PocketMine\DATA . "server.properties", Config::PROPERTIES);
echo "[!] " . $this->lang->query_warning1 . "\n";
echo "[!] " . $this->lang->query_warning2 . "\n";
echo "[?] " . $this->lang->query_disable . " (y/N): ";