From b24120a86383a8d12bb3326e844eb9c5b168178a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 13 Mar 2014 10:48:33 +0100 Subject: [PATCH] Updated all undefined constants/classes, place resent packets to the recovery queue for NACK --- src/PocketMine/BlockAPI.php | 1 - src/PocketMine/Player.php | 47 ++++++------ src/PocketMine/PluginAPI.php | 4 +- src/PocketMine/PocketMine.php | 2 +- src/PocketMine/Server.php | 2 +- src/PocketMine/ServerAPI.php | 9 +-- src/PocketMine/block/Bed.php | 2 +- src/PocketMine/block/Bricks.php | 2 +- src/PocketMine/block/BurningFurnace.php | 4 +- src/PocketMine/block/Carrot.php | 4 +- src/PocketMine/block/Chest.php | 9 ++- src/PocketMine/block/Coal.php | 2 +- src/PocketMine/block/CoalOre.php | 2 +- src/PocketMine/block/Cobblestone.php | 2 +- src/PocketMine/block/Diamond.php | 2 +- src/PocketMine/block/DiamondOre.php | 2 +- src/PocketMine/block/Dirt.php | 2 +- src/PocketMine/block/DoubleSlab.php | 2 +- src/PocketMine/block/DoubleWoodSlab.php | 2 +- src/PocketMine/block/Farmland.php | 2 +- src/PocketMine/block/GlowingRedstoneOre.php | 2 +- src/PocketMine/block/Gold.php | 2 +- src/PocketMine/block/GoldOre.php | 2 +- src/PocketMine/block/Grass.php | 2 +- src/PocketMine/block/Gravel.php | 2 +- src/PocketMine/block/Iron.php | 2 +- src/PocketMine/block/IronOre.php | 2 +- src/PocketMine/block/Lapis.php | 2 +- src/PocketMine/block/Lava.php | 8 +- src/PocketMine/block/Leaves.php | 10 +-- src/PocketMine/block/MossStone.php | 2 +- src/PocketMine/block/NetherBrick.php | 2 +- src/PocketMine/block/Netherrack.php | 2 +- src/PocketMine/block/Obsidian.php | 2 +- src/PocketMine/block/Potato.php | 4 +- src/PocketMine/block/Quartz.php | 2 +- src/PocketMine/block/RedstoneOre.php | 4 +- src/PocketMine/block/Sandstone.php | 2 +- src/PocketMine/block/SignPost.php | 4 +- src/PocketMine/block/Slab.php | 10 +-- src/PocketMine/block/Stone.php | 2 +- src/PocketMine/block/StoneBricks.php | 2 +- src/PocketMine/block/Sugarcane.php | 4 +- src/PocketMine/block/Water.php | 11 +-- src/PocketMine/block/WoodSlab.php | 10 +-- src/PocketMine/entity/Entity.php | 25 ++++++- src/PocketMine/entity/Human.php | 8 +- src/PocketMine/entity/Tameable.php | 2 +- src/PocketMine/item/Bucket.php | 9 ++- src/PocketMine/item/FlintSteel.php | 3 +- src/PocketMine/item/Item.php | 1 + src/PocketMine/item/Painting.php | 1 + src/PocketMine/item/SpawnEgg.php | 11 ++- src/PocketMine/level/Explosion.php | 11 +-- src/PocketMine/level/Level.php | 11 ++- src/PocketMine/level/LevelImport.php | 1 + src/PocketMine/level/Position.php | 44 ++++++++--- src/PocketMine/level/generator/Flat.php | 18 ++--- .../level/generator/noise/Simplex.php | 12 +-- .../level/generator/object/BigTree.php | 2 +- .../level/generator/object/TallGrass.php | 3 +- .../level/generator/populator/Pond.php | 2 +- .../level/generator/populator/TallGrass.php | 3 + src/PocketMine/math/Vector3.php | 61 +++++++--------- src/PocketMine/nbt/tag/Byte_Array.php | 2 +- src/PocketMine/nbt/tag/NamedTag.php | 4 + src/PocketMine/network/Handler.php | 4 +- src/PocketMine/network/UDPSocket.php | 2 +- src/PocketMine/network/upnp/PortForward.php | 71 ------------------ .../network/upnp/RemovePortForward.php | 46 ------------ src/PocketMine/network/upnp/UPnP.php | 73 +++++++++++++++++++ src/PocketMine/pmf/Plugin.php | 2 +- src/PocketMine/tile/Chest.php | 2 + src/PocketMine/tile/Furnace.php | 14 ++-- src/PocketMine/tile/Sign.php | 1 + src/PocketMine/tile/Spawnable.php | 1 + src/PocketMine/tile/Tile.php | 2 +- src/PocketMine/utils/Config.php | 5 +- src/PocketMine/utils/Utils.php | 2 +- src/PocketMine/wizard/Installer.php | 11 +-- 80 files changed, 347 insertions(+), 324 deletions(-) delete mode 100644 src/PocketMine/network/upnp/PortForward.php delete mode 100644 src/PocketMine/network/upnp/RemovePortForward.php create mode 100644 src/PocketMine/network/upnp/UPnP.php diff --git a/src/PocketMine/BlockAPI.php b/src/PocketMine/BlockAPI.php index d9a23338a..134700898 100644 --- a/src/PocketMine/BlockAPI.php +++ b/src/PocketMine/BlockAPI.php @@ -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], diff --git a/src/PocketMine/Player.php b/src/PocketMine/Player.php index b43217173..556e3fc6d 100644 --- a/src/PocketMine/Player.php +++ b/src/PocketMine/Player.php @@ -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()); diff --git a/src/PocketMine/PluginAPI.php b/src/PocketMine/PluginAPI.php index f183b5657..49c79d45a 100644 --- a/src/PocketMine/PluginAPI.php +++ b/src/PocketMine/PluginAPI.php @@ -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; diff --git a/src/PocketMine/PocketMine.php b/src/PocketMine/PocketMine.php index d9d5c3f35..e00aa6858 100644 --- a/src/PocketMine/PocketMine.php +++ b/src/PocketMine/PocketMine.php @@ -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(); diff --git a/src/PocketMine/Server.php b/src/PocketMine/Server.php index e85641fab..185f11171 100644 --- a/src/PocketMine/Server.php +++ b/src/PocketMine/Server.php @@ -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(); } diff --git a/src/PocketMine/ServerAPI.php b/src/PocketMine/ServerAPI.php index c7eb34b0d..091350263 100644 --- a/src/PocketMine/ServerAPI.php +++ b/src/PocketMine/ServerAPI.php @@ -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; diff --git a/src/PocketMine/block/Bed.php b/src/PocketMine/block/Bed.php index 230da2ef7..8b03ad773 100644 --- a/src/PocketMine/block/Bed.php +++ b/src/PocketMine/block/Bed.php @@ -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), ); } diff --git a/src/PocketMine/block/Bricks.php b/src/PocketMine/block/Bricks.php index cfdd03cfe..e909c996f 100644 --- a/src/PocketMine/block/Bricks.php +++ b/src/PocketMine/block/Bricks.php @@ -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(); diff --git a/src/PocketMine/block/BurningFurnace.php b/src/PocketMine/block/BurningFurnace.php index 49ba0b167..f63995f70 100644 --- a/src/PocketMine/block/BurningFurnace.php +++ b/src/PocketMine/block/BurningFurnace.php @@ -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); } diff --git a/src/PocketMine/block/Carrot.php b/src/PocketMine/block/Carrot.php index 97910dd8f..f0b0e6123 100644 --- a/src/PocketMine/block/Carrot.php +++ b/src/PocketMine/block/Carrot.php @@ -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; diff --git a/src/PocketMine/block/Chest.php b/src/PocketMine/block/Chest.php index e0f9dcaeb..8e90f23c9 100644 --- a/src/PocketMine/block/Chest.php +++ b/src/PocketMine/block/Chest.php @@ -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()); } } diff --git a/src/PocketMine/block/Coal.php b/src/PocketMine/block/Coal.php index 8a77adcda..a99a1efa3 100644 --- a/src/PocketMine/block/Coal.php +++ b/src/PocketMine/block/Coal.php @@ -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(); diff --git a/src/PocketMine/block/CoalOre.php b/src/PocketMine/block/CoalOre.php index 0d3f7c310..74a5e2d55 100644 --- a/src/PocketMine/block/CoalOre.php +++ b/src/PocketMine/block/CoalOre.php @@ -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(); diff --git a/src/PocketMine/block/Cobblestone.php b/src/PocketMine/block/Cobblestone.php index 2c7c1ed63..888eaa87f 100644 --- a/src/PocketMine/block/Cobblestone.php +++ b/src/PocketMine/block/Cobblestone.php @@ -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(); diff --git a/src/PocketMine/block/Diamond.php b/src/PocketMine/block/Diamond.php index 941bada44..47fe81a1c 100644 --- a/src/PocketMine/block/Diamond.php +++ b/src/PocketMine/block/Diamond.php @@ -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(); diff --git a/src/PocketMine/block/DiamondOre.php b/src/PocketMine/block/DiamondOre.php index 312a6e82c..d99450827 100644 --- a/src/PocketMine/block/DiamondOre.php +++ b/src/PocketMine/block/DiamondOre.php @@ -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(); diff --git a/src/PocketMine/block/Dirt.php b/src/PocketMine/block/Dirt.php index 1f940f9ce..654ee8274 100644 --- a/src/PocketMine/block/Dirt.php +++ b/src/PocketMine/block/Dirt.php @@ -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; } diff --git a/src/PocketMine/block/DoubleSlab.php b/src/PocketMine/block/DoubleSlab.php index 8fca926c5..1b33ec5f7 100644 --- a/src/PocketMine/block/DoubleSlab.php +++ b/src/PocketMine/block/DoubleSlab.php @@ -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(); diff --git a/src/PocketMine/block/DoubleWoodSlab.php b/src/PocketMine/block/DoubleWoodSlab.php index 6b6b09146..3caafd9e4 100644 --- a/src/PocketMine/block/DoubleWoodSlab.php +++ b/src/PocketMine/block/DoubleWoodSlab.php @@ -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), ); } diff --git a/src/PocketMine/block/Farmland.php b/src/PocketMine/block/Farmland.php index 191a04329..892e11bdb 100644 --- a/src/PocketMine/block/Farmland.php +++ b/src/PocketMine/block/Farmland.php @@ -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), ); } } \ No newline at end of file diff --git a/src/PocketMine/block/GlowingRedstoneOre.php b/src/PocketMine/block/GlowingRedstoneOre.php index dd4884d8a..b9873138d 100644 --- a/src/PocketMine/block/GlowingRedstoneOre.php +++ b/src/PocketMine/block/GlowingRedstoneOre.php @@ -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; } diff --git a/src/PocketMine/block/Gold.php b/src/PocketMine/block/Gold.php index 8a21f9e97..d993fa27d 100644 --- a/src/PocketMine/block/Gold.php +++ b/src/PocketMine/block/Gold.php @@ -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(); diff --git a/src/PocketMine/block/GoldOre.php b/src/PocketMine/block/GoldOre.php index 2ee7e08db..e1906ad59 100644 --- a/src/PocketMine/block/GoldOre.php +++ b/src/PocketMine/block/GoldOre.php @@ -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(); diff --git a/src/PocketMine/block/Grass.php b/src/PocketMine/block/Grass.php index 75d2b16e4..b92f7c225 100644 --- a/src/PocketMine/block/Grass.php +++ b/src/PocketMine/block/Grass.php @@ -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), ); } diff --git a/src/PocketMine/block/Gravel.php b/src/PocketMine/block/Gravel.php index 8bf43fb39..dd3d17aee 100644 --- a/src/PocketMine/block/Gravel.php +++ b/src/PocketMine/block/Gravel.php @@ -38,7 +38,7 @@ class Gravel extends Fallable{ } return array( - array(GRAVEL, 0, 1), + array(Item::GRAVEL, 0, 1), ); } diff --git a/src/PocketMine/block/Iron.php b/src/PocketMine/block/Iron.php index a543e8ff0..58371167e 100644 --- a/src/PocketMine/block/Iron.php +++ b/src/PocketMine/block/Iron.php @@ -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(); diff --git a/src/PocketMine/block/IronOre.php b/src/PocketMine/block/IronOre.php index eda3dca02..514bdca45 100644 --- a/src/PocketMine/block/IronOre.php +++ b/src/PocketMine/block/IronOre.php @@ -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(); diff --git a/src/PocketMine/block/Lapis.php b/src/PocketMine/block/Lapis.php index 029c6abda..31571ff53 100644 --- a/src/PocketMine/block/Lapis.php +++ b/src/PocketMine/block/Lapis.php @@ -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(); diff --git a/src/PocketMine/block/Lava.php b/src/PocketMine/block/Lava.php index aaa3613a7..c4afb5c31 100644 --- a/src/PocketMine/block/Lava.php +++ b/src/PocketMine/block/Lava.php @@ -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); diff --git a/src/PocketMine/block/Leaves.php b/src/PocketMine/block/Leaves.php index 558ef7f0a..9c3013464 100644 --- a/src/PocketMine/block/Leaves.php +++ b/src/PocketMine/block/Leaves.php @@ -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); } } diff --git a/src/PocketMine/block/MossStone.php b/src/PocketMine/block/MossStone.php index e60ff2224..049ec5750 100644 --- a/src/PocketMine/block/MossStone.php +++ b/src/PocketMine/block/MossStone.php @@ -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(); diff --git a/src/PocketMine/block/NetherBrick.php b/src/PocketMine/block/NetherBrick.php index 64c50c709..4d4735448 100644 --- a/src/PocketMine/block/NetherBrick.php +++ b/src/PocketMine/block/NetherBrick.php @@ -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(); diff --git a/src/PocketMine/block/Netherrack.php b/src/PocketMine/block/Netherrack.php index 72b77acac..236073606 100644 --- a/src/PocketMine/block/Netherrack.php +++ b/src/PocketMine/block/Netherrack.php @@ -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(); diff --git a/src/PocketMine/block/Obsidian.php b/src/PocketMine/block/Obsidian.php index 86fd3711c..8f97f3717 100644 --- a/src/PocketMine/block/Obsidian.php +++ b/src/PocketMine/block/Obsidian.php @@ -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(); diff --git a/src/PocketMine/block/Potato.php b/src/PocketMine/block/Potato.php index ae9fe163a..596e0954f 100644 --- a/src/PocketMine/block/Potato.php +++ b/src/PocketMine/block/Potato.php @@ -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; diff --git a/src/PocketMine/block/Quartz.php b/src/PocketMine/block/Quartz.php index 93211f9e5..05d2e2cc5 100644 --- a/src/PocketMine/block/Quartz.php +++ b/src/PocketMine/block/Quartz.php @@ -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(); diff --git a/src/PocketMine/block/RedstoneOre.php b/src/PocketMine/block/RedstoneOre.php index b76724d1b..b03abdc1a 100644 --- a/src/PocketMine/block/RedstoneOre.php +++ b/src/PocketMine/block/RedstoneOre.php @@ -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(); diff --git a/src/PocketMine/block/Sandstone.php b/src/PocketMine/block/Sandstone.php index 12ffa5129..fcefae259 100644 --- a/src/PocketMine/block/Sandstone.php +++ b/src/PocketMine/block/Sandstone.php @@ -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(); diff --git a/src/PocketMine/block/SignPost.php b/src/PocketMine/block/SignPost.php index 1a927bfa4..00aff45ea 100644 --- a/src/PocketMine/block/SignPost.php +++ b/src/PocketMine/block/SignPost.php @@ -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; } diff --git a/src/PocketMine/block/Slab.php b/src/PocketMine/block/Slab.php index b1632c658..ef2cfac58 100644 --- a/src/PocketMine/block/Slab.php +++ b/src/PocketMine/block/Slab.php @@ -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; } diff --git a/src/PocketMine/block/Stone.php b/src/PocketMine/block/Stone.php index 1e057053d..3d8dba5b7 100644 --- a/src/PocketMine/block/Stone.php +++ b/src/PocketMine/block/Stone.php @@ -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(); diff --git a/src/PocketMine/block/StoneBricks.php b/src/PocketMine/block/StoneBricks.php index bc799bcf5..04a9c8842 100644 --- a/src/PocketMine/block/StoneBricks.php +++ b/src/PocketMine/block/StoneBricks.php @@ -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(); diff --git a/src/PocketMine/block/Sugarcane.php b/src/PocketMine/block/Sugarcane.php index 7d82f3caf..9d0fd03a4 100644 --- a/src/PocketMine/block/Sugarcane.php +++ b/src/PocketMine/block/Sugarcane.php @@ -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)); diff --git a/src/PocketMine/block/Water.php b/src/PocketMine/block/Water.php index 355862ff7..be823710c 100644 --- a/src/PocketMine/block/Water.php +++ b/src/PocketMine/block/Water.php @@ -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); } diff --git a/src/PocketMine/block/WoodSlab.php b/src/PocketMine/block/WoodSlab.php index b344a0b1b..bd85c76fc 100644 --- a/src/PocketMine/block/WoodSlab.php +++ b/src/PocketMine/block/WoodSlab.php @@ -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; } diff --git a/src/PocketMine/entity/Entity.php b/src/PocketMine/entity/Entity.php index ca2cdc3d1..f2ddc4ac7 100644 --- a/src/PocketMine/entity/Entity.php +++ b/src/PocketMine/entity/Entity.php @@ -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){ diff --git a/src/PocketMine/entity/Human.php b/src/PocketMine/entity/Human.php index d84525f20..ef5c06c74 100644 --- a/src/PocketMine/entity/Human.php +++ b/src/PocketMine/entity/Human.php @@ -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; } diff --git a/src/PocketMine/entity/Tameable.php b/src/PocketMine/entity/Tameable.php index c95d21c11..f1e18e590 100644 --- a/src/PocketMine/entity/Tameable.php +++ b/src/PocketMine/entity/Tameable.php @@ -23,6 +23,6 @@ namespace PocketMine\Entity; use PocketMine; -interface TameableEntity{ +interface Tameable{ } \ No newline at end of file diff --git a/src/PocketMine/item/Bucket.php b/src/PocketMine/item/Bucket.php index 04d54cada..6ac86b0bc 100644 --- a/src/PocketMine/item/Bucket.php +++ b/src/PocketMine/item/Bucket.php @@ -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){ diff --git a/src/PocketMine/item/FlintSteel.php b/src/PocketMine/item/FlintSteel.php index f12311616..802f9e04e 100644 --- a/src/PocketMine/item/FlintSteel.php +++ b/src/PocketMine/item/FlintSteel.php @@ -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)){ diff --git a/src/PocketMine/item/Item.php b/src/PocketMine/item/Item.php index 6caa6173c..127524145 100644 --- a/src/PocketMine/item/Item.php +++ b/src/PocketMine/item/Item.php @@ -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 diff --git a/src/PocketMine/item/Painting.php b/src/PocketMine/item/Painting.php index 7732a7dfe..b843332c3 100644 --- a/src/PocketMine/item/Painting.php +++ b/src/PocketMine/item/Painting.php @@ -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){ diff --git a/src/PocketMine/item/SpawnEgg.php b/src/PocketMine/item/SpawnEgg.php index deefd36ab..86c342417 100644 --- a/src/PocketMine/item/SpawnEgg.php +++ b/src/PocketMine/item/SpawnEgg.php @@ -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, diff --git a/src/PocketMine/level/Explosion.php b/src/PocketMine/level/Explosion.php index 2fa043522..c5a22600d 100644 --- a/src/PocketMine/level/Explosion.php +++ b/src/PocketMine/level/Explosion.php @@ -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; diff --git a/src/PocketMine/level/Level.php b/src/PocketMine/level/Level.php index 25e8a7734..017c5c7e9 100644 --- a/src/PocketMine/level/Level.php +++ b/src/PocketMine/level/Level.php @@ -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){ diff --git a/src/PocketMine/level/LevelImport.php b/src/PocketMine/level/LevelImport.php index 718e67f21..8a74c52df 100644 --- a/src/PocketMine/level/LevelImport.php +++ b/src/PocketMine/level/LevelImport.php @@ -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; diff --git a/src/PocketMine/level/Position.php b/src/PocketMine/level/Position.php index c7c8a9d2a..c85aefc87 100644 --- a/src/PocketMine/level/Position.php +++ b/src/PocketMine/level/Position.php @@ -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(){ diff --git a/src/PocketMine/level/generator/Flat.php b/src/PocketMine/level/generator/Flat.php index 1fa204738..97348d496 100644 --- a/src/PocketMine/level/generator/Flat.php +++ b/src/PocketMine/level/generator/Flat.php @@ -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(); } diff --git a/src/PocketMine/level/generator/noise/Simplex.php b/src/PocketMine/level/generator/noise/Simplex.php index ec40ee822..9168d5421 100644 --- a/src/PocketMine/level/generator/noise/Simplex.php +++ b/src/PocketMine/level/generator/noise/Simplex.php @@ -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; diff --git a/src/PocketMine/level/generator/object/BigTree.php b/src/PocketMine/level/generator/object/BigTree.php index cfe0ee1e2..109d8b4b8 100644 --- a/src/PocketMine/level/generator/object/BigTree.php +++ b/src/PocketMine/level/generator/object/BigTree.php @@ -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)); diff --git a/src/PocketMine/level/generator/object/TallGrass.php b/src/PocketMine/level/generator/object/TallGrass.php index e5723cb69..65adae9b6 100644 --- a/src/PocketMine/level/generator/object/TallGrass.php +++ b/src/PocketMine/level/generator/object/TallGrass.php @@ -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){ diff --git a/src/PocketMine/level/generator/populator/Pond.php b/src/PocketMine/level/generator/populator/Pond.php index 25edcbf10..36c7df538 100644 --- a/src/PocketMine/level/generator/populator/Pond.php +++ b/src/PocketMine/level/generator/populator/Pond.php @@ -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); } diff --git a/src/PocketMine/level/generator/populator/TallGrass.php b/src/PocketMine/level/generator/populator/TallGrass.php index 587c364f1..09d7c4216 100644 --- a/src/PocketMine/level/generator/populator/TallGrass.php +++ b/src/PocketMine/level/generator/populator/TallGrass.php @@ -29,6 +29,9 @@ use PocketMine\Utils\Random; use PocketMine; class TallGrass extends Populator{ + /** + * @var Level + */ private $level; private $randomAmount; private $baseAmount; diff --git a/src/PocketMine/math/Vector3.php b/src/PocketMine/math/Vector3.php index b2976691b..81c2543a4 100644 --- a/src/PocketMine/math/Vector3.php +++ b/src/PocketMine/math/Vector3.php @@ -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 diff --git a/src/PocketMine/nbt/tag/Byte_Array.php b/src/PocketMine/nbt/tag/Byte_Array.php index 33e393b01..79bfdc8a7 100644 --- a/src/PocketMine/nbt/tag/Byte_Array.php +++ b/src/PocketMine/nbt/tag/Byte_Array.php @@ -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){ diff --git a/src/PocketMine/nbt/tag/NamedTag.php b/src/PocketMine/nbt/tag/NamedTag.php index b533b409e..46209e403 100644 --- a/src/PocketMine/nbt/tag/NamedTag.php +++ b/src/PocketMine/nbt/tag/NamedTag.php @@ -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){ diff --git a/src/PocketMine/network/Handler.php b/src/PocketMine/network/Handler.php index 9dd567c49..2054973e6 100644 --- a/src/PocketMine/network/Handler.php +++ b/src/PocketMine/network/Handler.php @@ -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; diff --git a/src/PocketMine/network/UDPSocket.php b/src/PocketMine/network/UDPSocket.php index 874f22c94..58c7d0c85 100644 --- a/src/PocketMine/network/UDPSocket.php +++ b/src/PocketMine/network/UDPSocket.php @@ -48,7 +48,7 @@ class UDPSocket{ } public function close($error = 125){ - return @socket_close($this->sock); + socket_close($this->sock); } public function block(){ diff --git a/src/PocketMine/network/upnp/PortForward.php b/src/PocketMine/network/upnp/PortForward.php deleted file mode 100644 index 2dbd1a4b6..000000000 --- a/src/PocketMine/network/upnp/PortForward.php +++ /dev/null @@ -1,71 +0,0 @@ -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; -} \ No newline at end of file diff --git a/src/PocketMine/network/upnp/RemovePortForward.php b/src/PocketMine/network/upnp/RemovePortForward.php deleted file mode 100644 index 642e7d201..000000000 --- a/src/PocketMine/network/upnp/RemovePortForward.php +++ /dev/null @@ -1,46 +0,0 @@ -StaticPortMappingCollection)){ - return false; - } - $com->StaticPortMappingCollection->Remove($port, "UDP"); - } catch(Exception $e){ - return false; - } - - return true; -} \ No newline at end of file diff --git a/src/PocketMine/network/upnp/UPnP.php b/src/PocketMine/network/upnp/UPnP.php new file mode 100644 index 000000000..0af94d015 --- /dev/null +++ b/src/PocketMine/network/upnp/UPnP.php @@ -0,0 +1,73 @@ +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; + } +} \ No newline at end of file diff --git a/src/PocketMine/pmf/Plugin.php b/src/PocketMine/pmf/Plugin.php index 7c4e6a4d5..4ea778372 100644 --- a/src/PocketMine/pmf/Plugin.php +++ b/src/PocketMine/pmf/Plugin.php @@ -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)); diff --git a/src/PocketMine/tile/Chest.php b/src/PocketMine/tile/Chest.php index 424f734b2..f0b6ca920 100644 --- a/src/PocketMine/tile/Chest.php +++ b/src/PocketMine/tile/Chest.php @@ -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; diff --git a/src/PocketMine/tile/Furnace.php b/src/PocketMine/tile/Furnace.php index 1ef3e4e5e..eb9ba8471 100644 --- a/src/PocketMine/tile/Furnace.php +++ b/src/PocketMine/tile/Furnace.php @@ -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; diff --git a/src/PocketMine/tile/Sign.php b/src/PocketMine/tile/Sign.php index 4604d0dd3..ddfa03c05 100644 --- a/src/PocketMine/tile/Sign.php +++ b/src/PocketMine/tile/Sign.php @@ -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{ diff --git a/src/PocketMine/tile/Spawnable.php b/src/PocketMine/tile/Spawnable.php index 70ec50c46..b5d24c170 100644 --- a/src/PocketMine/tile/Spawnable.php +++ b/src/PocketMine/tile/Spawnable.php @@ -22,6 +22,7 @@ namespace PocketMine\Tile; use PocketMine; +use PocketMine\Player; abstract class Spawnable extends Tile{ public abstract function spawnTo(Player $player); diff --git a/src/PocketMine/tile/Tile.php b/src/PocketMine/tile/Tile.php index c5dbba01a..e51a5df44 100644 --- a/src/PocketMine/tile/Tile.php +++ b/src/PocketMine/tile/Tile.php @@ -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); } } diff --git a/src/PocketMine/utils/Config.php b/src/PocketMine/utils/Config.php index d7afcceaf..054fc0deb 100644 --- a/src/PocketMine/utils/Config.php +++ b/src/PocketMine/utils/Config.php @@ -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){ diff --git a/src/PocketMine/utils/Utils.php b/src/PocketMine/utils/Utils.php index ea98d87d0..28249eb6c 100644 --- a/src/PocketMine/utils/Utils.php +++ b/src/PocketMine/utils/Utils.php @@ -365,7 +365,7 @@ class Utils{ } if($types === true){ $m[$bottom] = array($r, $type); - } else{ + }else{ $m[$bottom] = $r; } $b = ord($value{$offset}); diff --git a/src/PocketMine/wizard/Installer.php b/src/PocketMine/wizard/Installer.php index 1257ee04c..40cb99ecb 100644 --- a/src/PocketMine/wizard/Installer.php +++ b/src/PocketMine/wizard/Installer.php @@ -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): ";