diff --git a/src/PocketMine/Achievement.php b/src/PocketMine/Achievement.php index 29e99e9c6..c52337289 100644 --- a/src/PocketMine/Achievement.php +++ b/src/PocketMine/Achievement.php @@ -98,13 +98,10 @@ abstract class Achievement{ public static function broadcast(Player $player, $achievementId){ if(isset(Achievement::$list[$achievementId])){ - $result = ServerAPI::request()->api->dhandle("achievement.broadcast", array("player" => $player, "achievementId" => $achievementId)); - if($result !== false and $result !== true){ - if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){ - ServerAPI::request()->api->chat->broadcast($player->getUsername() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]); - } else{ - $player->sendChat("You have just earned the achievement " . Achievement::$list[$achievementId]["name"]); - } + if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){ + ServerAPI::request()->api->chat->broadcast($player->getUsername() . " has just earned the achievement " . Achievement::$list[$achievementId]["name"]); + }else{ + $player->sendChat("You have just earned the achievement " . Achievement::$list[$achievementId]["name"]); } return true; diff --git a/src/PocketMine/BlockAPI.php b/src/PocketMine/BlockAPI.php index 134700898..107f5f739 100644 --- a/src/PocketMine/BlockAPI.php +++ b/src/PocketMine/BlockAPI.php @@ -25,11 +25,6 @@ use PocketMine\Block; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\Level\Position; -use PocketMine\NBT\Tag\Compound; -use PocketMine\NBT\Tag\Int; -use PocketMine\NBT\Tag\String; -use PocketMine\Network\Protocol\UpdateBlockPacket; -use PocketMine\Tile\Sign; class BlockAPI{ private $server; @@ -249,7 +244,7 @@ class BlockAPI{ break; } $player = Player::get($params[0]); - $item = BlockAPI::fromString($params[1]); + $item = Item::fromString($params[1]); if(!isset($params[2])){ $item->setCount($item->getMaxStackSize()); @@ -266,7 +261,7 @@ class BlockAPI{ $output .= "You cannot give an air block to a player.\n"; break; } - $player->addItem($item); + $player->addItem(clone $item); $output .= "Giving " . $item->getCount() . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $player->getUsername() . "\n"; } else{ $output .= "Unknown player.\n"; @@ -278,169 +273,6 @@ class BlockAPI{ return $output; } - private function cancelAction(Block\Block $block, Player $player, $send = true){ - $pk = new UpdateBlockPacket; - $pk->x = $block->x; - $pk->y = $block->y; - $pk->z = $block->z; - $pk->block = $block->getID(); - $pk->meta = $block->getMetadata(); - $player->dataPacket($pk); - if($send === true){ - $player->sendInventorySlot($player->slot); - } - - return false; - } - - public function playerBlockBreak(Player $player, Math\Vector3 $vector){ - - $target = $player->level->getBlock($vector); - $item = $player->getSlot($player->slot); - - if($this->server->api->dhandle("player.block.touch", array("type" => "break", "player" => $player, "target" => $target, "item" => $item)) === false){ - if($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){ - return $this->cancelAction($target, $player, false); - } - } - - if((!$target->isBreakable($item, $player) and $this->server->api->dhandle("player.block.break.invalid", array("player" => $player, "target" => $target, "item" => $item)) !== true) or ($player->gamemode & 0x02) === 0x02 or (($player->lastBreak - $player->getLag() / 1000) + $target->getBreakTime($item, $player) - 0.2) >= microtime(true)){ - if($this->server->api->dhandle("player.block.break.bypass", array("player" => $player, "target" => $target, "item" => $item)) !== true){ - return $this->cancelAction($target, $player, false); - } - } - $player->lastBreak = microtime(true); - - if($this->server->api->dhandle("player.block.break", array("player" => $player, "target" => $target, "item" => $item)) !== false){ - $drops = $target->getDrops($item, $player); - if($target->onBreak($item, $player) === false){ - return $this->cancelAction($target, $player, false); - } - if(($player->gamemode & 0x01) === 0 and $item->useOn($target) and $item->getMetadata() >= $item->getMaxDurability()){ - $player->setSlot($player->slot, new Item(Item::AIR, 0, 0)); - } - } else{ - return $this->cancelAction($target, $player, false); - } - - - if(($player->gamemode & 0x01) === 0x00 and count($drops) > 0){ - foreach($drops as $drop){ - echo "I dropped something\n"; - //$this->server->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), Item::get($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2])); - } - } - - return false; - } - - public function playerBlockAction(Player $player, Math\Vector3 $vector, $face, $fx, $fy, $fz){ - if($face < 0 or $face > 5){ - return false; - } - - $target = $player->level->getBlock($vector); - $block = $target->getSide($face); - if(($player->getGamemode() & 0x01) === 0){ - $item = $player->getSlot($player->slot); - } else{ - $item = Item::get(BlockAPI::$creative[$player->slot][0], BlockAPI::$creative[$player->slot][1], 1); - } - - if($target->getID() === Item::AIR and $this->server->api->dhandle("player.block.place.invalid", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ //If no block exists or not allowed in CREATIVE - if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ - $this->cancelAction($target, $player); - - return $this->cancelAction($block, $player); - } - } - - if($this->server->api->dhandle("player.block.touch", array("type" => "place", "player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false){ - if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ - return $this->cancelAction($block, $player); - } - } - $this->blockUpdate($target, Level::BLOCK_UPDATE_TOUCH); - - if($target->isActivable === true){ - if($this->server->api->dhandle("player.block.activate", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== false and $target->onActivate($item, $player) === true){ - return false; - } - } - - if(($player->gamemode & 0x02) === 0x02){ //Adventure mode!! - if($this->server->api->dhandle("player.block.place.bypass", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) !== true){ - return $this->cancelAction($block, $player, false); - } - } - - if($block->y > 127 or $block->y < 0){ - return false; - } - - if($item->isActivable === true and $item->onActivate($player->level, $player, $block, $target, $face, $fx, $fy, $fz) === true){ - if($item->getCount() <= 0){ - $player->setSlot($player->slot, Item::get(Item::AIR, 0, 0)); - } - - return false; - } - - if($item->isPlaceable()){ - $hand = $item->getBlock(); - $hand->position($block); - } elseif($block->getID() === Item::FIRE){ - $player->level->setBlock($block, new Block\Air(), true, false, true); - - return false; - } else{ - return $this->cancelAction($block, $player, false); - } - - if(!($block->isReplaceable === true or ($hand->getID() === Item::SLAB and $block->getID() === Item::SLAB))){ - return $this->cancelAction($block, $player, false); - } - - if($target->isReplaceable === true){ - $block = $target; - $hand->position($block); - //$face = -1; - } - - //Implement using Bounding Boxes - /*if($hand->isSolid === true and $player->inBlock($block)){ - return $this->cancelAction($block, $player, false); //Entity in block - }*/ - - if($this->server->api->dhandle("player.block.place", array("player" => $player, "block" => $block, "target" => $target, "item" => $item)) === false){ - return $this->cancelAction($block, $player); - } elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){ - return $this->cancelAction($block, $player, false); - } - if($hand->getID() === Item::SIGN_POST or $hand->getID() === Item::WALL_SIGN){ - new Sign($player->level, new Compound(false, array( - new String("id", Tile\Tile::SIGN), - new Int("x", $block->x), - new Int("y", $block->y), - new Int("z", $block->z), - new String("Text1", ""), - new String("Text2", ""), - new String("Text3", ""), - new String("Text4", ""), - new String("creator", $player->getUsername()) - ))); - } - - if(($player->getGamemode() & 0x01) === 0){ - $item->setCount($item->getCount() - 1); - if($item->getCount() <= 0){ - $player->setSlot($player->slot, Item::get(Item::AIR, 0, 0)); - } - } - - return false; - } - public function blockUpdateAround(Position $pos, $type = Level::BLOCK_UPDATE_NORMAL, $delay = false){ if($delay !== false){ $this->scheduleBlockUpdate($pos->getSide(0), $delay, $type); diff --git a/src/PocketMine/Player.php b/src/PocketMine/Player.php index a61c494bf..3e7a2ce6e 100644 --- a/src/PocketMine/Player.php +++ b/src/PocketMine/Player.php @@ -22,8 +22,8 @@ namespace PocketMine; use PocketMine\Entity\RealHuman; -use PocketMine\Event\EventHandler; use PocketMine\Event; +use PocketMine\Event\EventHandler; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\Level\Position; @@ -1025,7 +1025,6 @@ class Player extends RealHuman{ return false; } - $inv =& $this->inventory; if(($this->gamemode & 0x01) === ($gm & 0x01)){ $this->gamemode = $gm; $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ".\n"); @@ -1035,9 +1034,7 @@ class Player extends RealHuman{ $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ", you've to do a forced reconnect.\n"); $this->server->schedule(30, array($this, "close"), "gamemode change"); //Forces a kick } - $this->inventory = $inv; $this->sendSettings(); - $this->sendInventory(); return true; } @@ -1479,10 +1476,10 @@ class Player extends RealHuman{ if($packet->slot === 0x28 or $packet->slot === 0){ //0 for 0.8.0 compatibility $packet->slot = -1; //Air } else{ - $packet->slot -= 9; + $packet->slot -= 9; //Get real block slot } - if(($this->gamemode & 0x01) === 1){ + if(($this->gamemode & 0x01) === 1){ //Creative mode match $packet->slot = false; foreach(BlockAPI::$creative as $i => $d){ if($d[0] === $packet->item and $d[1] === $packet->meta){ @@ -1491,13 +1488,13 @@ class Player extends RealHuman{ break; } } - } else{ + }else{ $item = $this->getSlot($packet->slot); } - if($packet->slot === false or EventHandler::callEvent(new Event\Player\PlayerEquipmentChangeEvent($this, $item, $packet->slot, 0)) === Event\Event::DENY){ + if($packet->slot === false or EventHandler::callEvent(new Event\Player\PlayerItemHeldEvent($this, $item, $packet->slot, 0)) === Event\Event::DENY){ $this->sendInventorySlot($packet->slot); - } else{ + }elseif($item instanceof Item){ $this->setEquipmentSlot(0, $packet->slot); $this->setCurrentEquipmentSlot(0); if(($this->gamemode & 0x01) === 0){ @@ -1507,6 +1504,7 @@ class Player extends RealHuman{ } } } + if($this->inAction === true){ $this->inAction = false; //$this->entity->updateMetadata(); @@ -1541,21 +1539,6 @@ class Player extends RealHuman{ $this->craftingItems = array(); $this->toCraft = array(); $packet->eid = $this->id; - $data = array(); - $data["eid"] = $packet->eid; - $data["player"] = $this; - $data["face"] = $packet->face; - $data["x"] = $packet->x; - $data["y"] = $packet->y; - $data["z"] = $packet->z; - $data["item"] = $packet->item; - $data["meta"] = $packet->meta; - $data["fx"] = $packet->fx; - $data["fy"] = $packet->fy; - $data["fz"] = $packet->fz; - $data["posX"] = $packet->posX; - $data["posY"] = $packet->posY; - $data["posZ"] = $packet->posZ; if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place if($this->inAction === true){ @@ -1563,16 +1546,23 @@ class Player extends RealHuman{ //$this->entity->updateMetadata(); } - if($this->blocked === true or $blockVector->distance($this) > 10){ + if($blockVector->distance($this) > 10){ - } elseif(($this->gamemode & 0x01) === 1 and isset(BlockAPI::$creative[$this->slot]) and $packet->item === BlockAPI::$creative[$this->slot][0] and $packet->meta === BlockAPI::$creative[$this->slot][1]){ - $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz); - break; - } elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){ + }elseif(($this->gamemode & 0x01) === 1 and isset(BlockAPI::$creative[$this->slot]) and $packet->item === BlockAPI::$creative[$this->slot][0] and $packet->meta === BlockAPI::$creative[$this->slot][1]){ + $item = Item::get(BlockAPI::$creative[$this->slot][0], BlockAPI::$creative[$this->slot][1], 1); + if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){ + break; + } + }elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){ $this->sendInventorySlot($this->slot); - } else{ - $this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz); - break; + }else{ + $item = clone $this->getSlot($this->slot); + //TODO: Implement adventure mode checks + if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){ + $this->setSlot($this->slot, $item); + $this->sendInventorySlot($this->slot); + break; + } } $target = $this->level->getBlock($blockVector); $block = $target->getSide($packet->face); @@ -1676,22 +1666,36 @@ class Player extends RealHuman{ } break;*/ case ProtocolInfo::REMOVE_BLOCK_PACKET: - $blockVector = new Vector3($packet->x, $packet->y, $packet->z); - if($this->spawned === false or $this->blocked === true or $this->distance($blockVector) > 8){ - $target = $this->level->getBlock($blockVector); - - $pk = new UpdateBlockPacket; - $pk->x = $target->x; - $pk->y = $target->y; - $pk->z = $target->z; - $pk->block = $target->getID(); - $pk->meta = $target->getMetadata(); - $this->dataPacket($pk); + if($this->spawned === false or $this->blocked === true){ break; } $this->craftingItems = array(); $this->toCraft = array(); - $this->server->api->block->playerBlockBreak($this, $blockVector); + + $vector = new Vector3($packet->x, $packet->y, $packet->z); + + + if(($this->gamemode & 0x01) === 1){ + $item = Item::get(BlockAPI::$creative[$this->slot][0], BlockAPI::$creative[$this->slot][1], 1); + }else{ + $item = clone $this->getSlot($this->slot); + } + + if(($drops = $this->level->useBreakOn($vector, $item)) !== true){ + if(($this->gamemode & 0x01) === 0){ + //TODO: drop items + $this->setSlot($this->slot, $item); + } + break; + } + $target = $this->level->getBlock($vector); + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getMetadata(); + $this->directDataPacket($pk); break; case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: if($this->spawned === false or $this->blocked === true){ @@ -1716,14 +1720,14 @@ class Player extends RealHuman{ $this->addItem($slot); $packet->slots[$i] = 255; } - } elseif($s->getID() !== Item::AIR and $slot->getID() === Item::AIR and ($sl = $this->hasItem($s->getID())) !== false){ + }elseif($s->getID() !== Item::AIR and $slot->getID() === Item::AIR and ($sl = $this->hasItem($s, false)) !== false){ if($this->setArmorSlot($i, $this->getSlot($sl)) === false){ $this->sendArmor(); $this->sendInventory(); } else{ $this->setSlot($sl, Item::get(Item::AIR, 0, 0)); } - } 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){ + }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, false)) !== false){ if($this->setArmorSlot($i, $this->getSlot($sl)) === false){ $this->sendArmor(); $this->sendInventory(); diff --git a/src/PocketMine/block/Bed.php b/src/PocketMine/block/Bed.php index 8b03ad773..5138ad882 100644 --- a/src/PocketMine/block/Bed.php +++ b/src/PocketMine/block/Bed.php @@ -21,10 +21,10 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Network\Protocol\ChatPacket; use PocketMine\ServerAPI; -use PocketMine; class Bed extends Transparent{ public function __construct($type = 0){ @@ -34,8 +34,8 @@ class Bed extends Transparent{ $this->hardness = 1; } - public function onActivate(Item $item, PocketMine\Player $player){ - if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){ + public function onActivate(Item $item, PocketMine\Player $player = null){ + if($player instanceof PocketMine\Player and ServerAPI::request()->api->time->getPhase($this->level) !== "night"){ $pk = new ChatPacket; $pk->message = "You can only sleep at night"; $player->dataPacket($pk); @@ -49,16 +49,16 @@ class Bed extends Transparent{ $blockWest = $this->getSide(4); if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed $b = $this; - } else{ //Bottom Part of Bed + }else{ //Bottom Part of Bed if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ $b = $blockNorth; - } elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ + }elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ $b = $blockSouth; - } elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ + }elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ $b = $blockEast; - } elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ + }elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ $b = $blockWest; - } else{ + }elseif($player instanceof PocketMine\Player){ $pk = new ChatPacket; $pk->message = "This bed is incomplete"; $player->dataPacket($pk); @@ -67,7 +67,7 @@ class Bed extends Transparent{ } } - if($player->sleepOn($b) === false){ + if($player instanceof PocketMine\Player and $player->sleepOn($b) === false){ $pk = new ChatPacket; $pk->message = "This bed is occupied"; $player->dataPacket($pk); @@ -76,7 +76,7 @@ class Bed extends Transparent{ return true; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->isTransparent === false){ $faces = array( @@ -85,7 +85,7 @@ class Bed extends Transparent{ 2 => 2, 3 => 5, ); - $d = $player->getDirection(); + $d = $player instanceof PocketMine\Player ? $player->getDirection() : 0; $next = $this->getSide($faces[(($d + 3) % 4)]); $downNext = $this->getSide(0); if($next->isReplaceable === true and $downNext->isTransparent === false){ @@ -100,7 +100,7 @@ class Bed extends Transparent{ return false; } - public function onBreak(Item $item, PocketMine\Player $player){ + public function onBreak(Item $item){ $blockNorth = $this->getSide(2); //Gets the blocks around them $blockSouth = $this->getSide(3); $blockEast = $this->getSide(5); @@ -109,21 +109,21 @@ class Bed extends Transparent{ if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right $this->level->setBlock($blockNorth, new Air(), true, false, true); - } elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){ + }elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){ $this->level->setBlock($blockSouth, new Air(), true, false, true); - } elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){ + }elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){ $this->level->setBlock($blockEast, new Air(), true, false, true); - } elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){ + }elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){ $this->level->setBlock($blockWest, new Air(), true, false, true); } - } else{ //Bottom Part of Bed + }else{ //Bottom Part of Bed if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){ $this->level->setBlock($blockNorth, new Air(), true, false, true); - } elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ + }elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){ $this->level->setBlock($blockSouth, new Air(), true, false, true); - } elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ + }elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){ $this->level->setBlock($blockEast, new Air(), true, false, true); - } elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ + }elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){ $this->level->setBlock($blockWest, new Air(), true, false, true); } } @@ -132,7 +132,7 @@ class Bed extends Transparent{ return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::BED, 0, 1), ); diff --git a/src/PocketMine/block/Bedrock.php b/src/PocketMine/block/Bedrock.php index c82cd86ad..235ef02ae 100644 --- a/src/PocketMine/block/Bedrock.php +++ b/src/PocketMine/block/Bedrock.php @@ -31,11 +31,7 @@ class Bedrock extends Solid{ $this->hardness = 18000000; } - public function isBreakable(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return true; - } - + public function isBreakable(Item $item){ return false; } diff --git a/src/PocketMine/block/Beetroot.php b/src/PocketMine/block/Beetroot.php index 3660acb9d..335e47944 100644 --- a/src/PocketMine/block/Beetroot.php +++ b/src/PocketMine/block/Beetroot.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Beetroot extends Flowable{ public function __construct($meta = 0){ @@ -32,7 +32,7 @@ class Beetroot extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::FARMLAND){ $this->level->setBlock($block, $this, true, false, true); @@ -43,13 +43,11 @@ class Beetroot extends Flowable{ return false; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta = 0x07; $this->level->setBlock($this, $this, true, false, true); - if(($player->gamemode & 0x01) === 0){ - $item->count--; - } + $item->count--; return true; } @@ -66,7 +64,7 @@ class Beetroot extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 2) == 1){ if($this->meta < 0x07){ ++$this->meta; @@ -74,7 +72,7 @@ class Beetroot extends Flowable{ return Level::BLOCK_UPDATE_RANDOM; } - } else{ + }else{ return Level::BLOCK_UPDATE_RANDOM; } } @@ -82,12 +80,12 @@ class Beetroot extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ $drops = array(); if($this->meta >= 0x07){ $drops[] = array(Item::BEETROOT, 0, 1); $drops[] = array(Item::BEETROOT_SEEDS, 0, mt_rand(0, 3)); - } else{ + }else{ $drops[] = array(Item::BEETROOT_SEEDS, 0, 1); } diff --git a/src/PocketMine/block/BirchWoodStairs.php b/src/PocketMine/block/BirchWoodStairs.php index 865ebbd8f..2b46501d9 100644 --- a/src/PocketMine/block/BirchWoodStairs.php +++ b/src/PocketMine/block/BirchWoodStairs.php @@ -29,7 +29,7 @@ class BirchWoodStairs extends Stair{ parent::__construct(self::BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs"); } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Block.php b/src/PocketMine/block/Block.php index 88f8c5b9a..914a09a2e 100644 --- a/src/PocketMine/block/Block.php +++ b/src/PocketMine/block/Block.php @@ -24,11 +24,10 @@ */ namespace PocketMine\Block; -use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\Level\Position; -use PocketMine\Player; +use PocketMine; abstract class Block extends Position{ const AIR = 0; @@ -368,7 +367,7 @@ abstract class Block extends Position{ if(isset(self::$list[$id])){ $block = clone self::$list[$id]; $block->setMetadata($meta); - } else{ + }else{ $block = new Generic($id, $meta); } if($pos instanceof Position){ @@ -441,15 +440,14 @@ abstract class Block extends Position{ /** * Returns an array of Item objects to be dropped * - * @param Item $item - * @param Player $player + * @param Item $item * * @return array */ - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if(!isset(self::$list[$this->id])){ //Unknown blocks return array(); - } else{ + }else{ return array( array($this->id, $this->meta, 1), ); @@ -459,16 +457,11 @@ abstract class Block extends Position{ /** * Returns the seconds that this block takes to be broken using an specific Item * - * @param Item $item - * @param Player $player + * @param Item $item * * @return float */ - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.15; - } - + public function getBreakTime(Item $item){ return $this->breakTime; } @@ -498,48 +491,46 @@ abstract class Block extends Position{ /** * Returns if the item can be broken with an specific Item * - * @param Item $item - * @param Player $player + * @param Item $item * * @return bool */ - abstract function isBreakable(Item $item, PocketMine\Player $player); + abstract function isBreakable(Item $item); /** * Do the actions needed so the block is broken with the Item * - * @param Item $item - * @param Player $player + * @param Item $item * * @return mixed */ - abstract function onBreak(Item $item, PocketMine\Player $player); + abstract function onBreak(Item $item); /** * Places the Block, using block space and block target, and side. Returns if the block has been placed. * - * @param Item $item - * @param Player $player - * @param Block $block - * @param Block $target - * @param int $face - * @param float $fx - * @param float $fy - * @param float $fz + * @param Item $item + * @param Block $block + * @param Block $target + * @param int $face + * @param float $fx + * @param float $fy + * @param float $fz + * @param \PocketMine\Player $player = null * * @return bool */ - abstract function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz); + abstract function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null); /** * Do actions when activated by Item. Returns if it has done anything * - * @param Item $item - * @param Player $player + * @param Item $item + * @param \PocketMine\Player $player * * @return bool */ - abstract function onActivate(Item $item, PocketMine\Player $player); + abstract function onActivate(Item $item, PocketMine\Player $player = null); /** * Fires a block update on the Block diff --git a/src/PocketMine/block/Bricks.php b/src/PocketMine/block/Bricks.php index e909c996f..7d23f21e0 100644 --- a/src/PocketMine/block/Bricks.php +++ b/src/PocketMine/block/Bricks.php @@ -30,10 +30,7 @@ class Bricks extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.4; @@ -50,12 +47,12 @@ class Bricks extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::BRICKS_BLOCK, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/BrownMushroom.php b/src/PocketMine/block/BrownMushroom.php index 15fcbf422..a81a8039f 100644 --- a/src/PocketMine/block/BrownMushroom.php +++ b/src/PocketMine/block/BrownMushroom.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class BrownMushroom extends Flowable{ public function __construct(){ @@ -45,7 +45,7 @@ class BrownMushroom extends Flowable{ return false; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->isTransparent === false){ $this->level->setBlock($block, $this, true, false, true); diff --git a/src/PocketMine/block/BurningFurnace.php b/src/PocketMine/block/BurningFurnace.php index f63995f70..97f13aa32 100644 --- a/src/PocketMine/block/BurningFurnace.php +++ b/src/PocketMine/block/BurningFurnace.php @@ -22,14 +22,14 @@ namespace PocketMine\Block; use PocketMine\Item\Item; +use PocketMine; +use PocketMine\NBT\NBT; use PocketMine\NBT\Tag\Compound; use PocketMine\NBT\Tag\Enum; use PocketMine\NBT\Tag\Int; use PocketMine\NBT\Tag\String; use PocketMine\Tile\Furnace; use PocketMine\Tile\Tile; -use PocketMine; -use PocketMine\NBT\NBT; class BurningFurnace extends Solid{ public function __construct($meta = 0){ @@ -38,14 +38,14 @@ class BurningFurnace extends Solid{ $this->hardness = 17.5; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $faces = array( 0 => 4, 1 => 2, 2 => 5, 3 => 3, ); - $this->meta = $faces[$player->getDirection()]; + $this->meta = $faces[$player instanceof PocketMine\Player ? $player->getDirection() : 0]; $this->level->setBlock($block, $this, true, false, true); $nbt = new Compound(false, array( new Enum("Items", array()), @@ -60,43 +60,41 @@ class BurningFurnace extends Solid{ return true; } - public function onBreak(Item $item, PocketMine\Player $player){ + public function onBreak(Item $item){ $this->level->setBlock($this, new Air(), true, true, true); return true; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ + if($player instanceof PocketMine\Player){ + $t = $this->level->getTile($this); + $furnace = false; + if($t instanceof Furnace){ + $furnace = $t; + }else{ + $nbt = new Compound(false, array( + new Enum("Items", array()), + new String("id", Tile::FURNACE), + new Int("x", $this->x), + new Int("y", $this->y), + new Int("z", $this->z) + )); + $nbt->Items->setTagType(NBT::TAG_Compound); + $furnace = new Furnace($this->level, $nbt); + } - $t = $this->level->getTile($this); - $furnace = false; - if($t instanceof Furnace){ - $furnace = $t; - } else{ - $nbt = new Compound(false, array( - new Enum("Items", array()), - new String("id", Tile::FURNACE), - new Int("x", $this->x), - new Int("y", $this->y), - new Int("z", $this->z) - )); - $nbt->Items->setTagType(NBT::TAG_Compound); - $furnace = new Furnace($this->level, $nbt); + if(($player->getGamemode() & 0x01) === 0x01){ + return true; + } + + $furnace->openInventory($player); } - if(($player->gamemode & 0x01) === 0x01){ - return true; - } - - $furnace->openInventory($player); - return true; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.7; @@ -113,7 +111,7 @@ class BurningFurnace extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ $drops = array(); if($item->isPickaxe() >= 1){ $drops[] = array(Item::FURNACE, 0, 1); diff --git a/src/PocketMine/block/Cactus.php b/src/PocketMine/block/Cactus.php index f910c896c..52dc1c782 100644 --- a/src/PocketMine/block/Cactus.php +++ b/src/PocketMine/block/Cactus.php @@ -21,11 +21,11 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\Math\Vector3 as Vector3; use PocketMine\ServerAPI; -use PocketMine; class Cactus extends Transparent{ public function __construct($meta = 0){ @@ -43,7 +43,7 @@ class Cactus extends Transparent{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if($this->getSide(0)->getID() !== self::CACTUS){ if($this->meta == 0x0F){ for($y = 1; $y < 3; ++$y){ @@ -55,7 +55,7 @@ class Cactus extends Transparent{ } $this->meta = 0; $this->level->setBlock($this, $this, false); - } else{ + }else{ ++$this->meta; $this->level->setBlock($this, $this, false); } @@ -67,7 +67,7 @@ class Cactus extends Transparent{ return false; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::SAND or $down->getID() === self::CACTUS){ $block0 = $this->getSide(2); @@ -84,7 +84,7 @@ class Cactus extends Transparent{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Cake.php b/src/PocketMine/block/Cake.php index ccefa425f..5ce39baf9 100644 --- a/src/PocketMine/block/Cake.php +++ b/src/PocketMine/block/Cake.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Cake extends Transparent{ public function __construct($meta = 0){ @@ -34,7 +34,7 @@ class Cake extends Transparent{ $this->hardness = 2.5; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() !== self::AIR){ $this->level->setBlock($block, $this, true, false, true); @@ -57,17 +57,17 @@ class Cake extends Transparent{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array(); } - public function onActivate(Item $item, PocketMine\Player $player){ - if($player->getHealth() < 20){ + public function onActivate(Item $item, PocketMine\Player $player = null){ + if($player instanceof PocketMine\Player and $player->getHealth() < 20){ ++$this->meta; $player->heal(3, "cake"); if($this->meta >= 0x06){ $this->level->setBlock($this, new Air(), true, false, true); - } else{ + }else{ $this->level->setBlock($this, $this, true, false, true); } diff --git a/src/PocketMine/block/Carpet.php b/src/PocketMine/block/Carpet.php index d71f3d385..8e00c774c 100644 --- a/src/PocketMine/block/Carpet.php +++ b/src/PocketMine/block/Carpet.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Carpet extends Flowable{ public function __construct($meta = 0){ @@ -52,7 +52,7 @@ class Carpet extends Flowable{ $this->isSolid = true; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() !== self::AIR){ $this->level->setBlock($block, $this, true, false, true); diff --git a/src/PocketMine/block/Carrot.php b/src/PocketMine/block/Carrot.php index f0b0e6123..dc5a99a8d 100644 --- a/src/PocketMine/block/Carrot.php +++ b/src/PocketMine/block/Carrot.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Carrot extends Flowable{ public function __construct($meta = 0){ @@ -32,7 +32,7 @@ class Carrot extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::FARMLAND){ $this->level->setBlock($block, $this, true, false, true); @@ -43,13 +43,11 @@ class Carrot extends Flowable{ return false; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta = 0x07; $this->level->setBlock($this, $this, true, false, true); - if(($player->gamemode & 0x01) === 0){ - $item->count--; - } + $item->count--; return true; } @@ -66,7 +64,7 @@ class Carrot extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 2) == 1){ if($this->meta < 0x07){ ++$this->meta; @@ -74,7 +72,7 @@ class Carrot extends Flowable{ return Level::BLOCK_UPDATE_RANDOM; } - } else{ + }else{ return Level::BLOCK_UPDATE_RANDOM; } } @@ -82,11 +80,11 @@ class Carrot extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ $drops = array(); if($this->meta >= 0x07){ $drops[] = array(Item::CARROT, 0, mt_rand(1, 4)); - } else{ + }else{ $drops[] = array(Item::CARROT, 0, 1); } diff --git a/src/PocketMine/block/Chest.php b/src/PocketMine/block/Chest.php index 8e90f23c9..2f4b5bd17 100644 --- a/src/PocketMine/block/Chest.php +++ b/src/PocketMine/block/Chest.php @@ -22,14 +22,14 @@ namespace PocketMine\Block; use PocketMine\Item\Item; +use PocketMine; +use PocketMine\NBT\NBT; use PocketMine\NBT\Tag\Compound; use PocketMine\NBT\Tag\Enum; use PocketMine\NBT\Tag\Int; use PocketMine\NBT\Tag\String; use PocketMine\Tile\Chest as TileChest; use PocketMine\Tile\Tile; -use PocketMine; -use PocketMine\NBT\NBT; class Chest extends Transparent{ @@ -41,7 +41,7 @@ class Chest extends Transparent{ $this->hardness = 15; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $faces = array( 0 => 4, 1 => 2, @@ -50,12 +50,12 @@ class Chest extends Transparent{ ); $chest = false; - $this->meta = $faces[$player->getDirection()]; + $this->meta = $faces[$player instanceof PocketMine\Player ? $player->getDirection() : 0]; for($side = 2; $side <= 5; ++$side){ if(($this->meta === 4 or $this->meta === 5) and ($side === 4 or $side === 5)){ continue; - } elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){ + }elseif(($this->meta === 3 or $this->meta === 2) and ($side === 2 or $side === 3)){ continue; } $c = $this->getSide($side); @@ -86,7 +86,7 @@ class Chest extends Transparent{ return true; } - public function onBreak(Item $item, PocketMine\Player $player){ + public function onBreak(Item $item){ $t = $this->level->getTile($this); if($t instanceof TileChest){ $t->unpair(); @@ -96,39 +96,41 @@ class Chest extends Transparent{ return true; } - public function onActivate(Item $item, PocketMine\Player $player){ - $top = $this->getSide(1); - if($top->isTransparent !== true){ - return true; + public function onActivate(Item $item, PocketMine\Player $player = null){ + if($player instanceof PocketMine\Player){ + $top = $this->getSide(1); + if($top->isTransparent !== true){ + return true; + } + + $t = $this->level->getTile($this); + $chest = false; + if($t instanceof TileChest){ + $chest = $t; + }else{ + $nbt = new Compound(false, array( + new Enum("Items", array()), + new String("id", Tile::CHEST), + new Int("x", $this->x), + new Int("y", $this->y), + new Int("z", $this->z) + )); + $nbt->Items->setTagType(NBT::TAG_Compound); + $chest = new TileChest($this->level, $nbt); + } + + + if(($player->gamemode & 0x01) === 0x01){ + return true; + } + + $chest->openInventory($player); } - $t = $this->level->getTile($this); - $chest = false; - if($t instanceof TileChest){ - $chest = $t; - } else{ - $nbt = new Compound(false, array( - new Enum("Items", array()), - new String("id", Tile::CHEST), - new Int("x", $this->x), - new Int("y", $this->y), - new Int("z", $this->z) - )); - $nbt->Items->setTagType(NBT::TAG_Compound); - $chest = new TileChest($this->level, $nbt); - } - - - if(($player->gamemode & 0x01) === 0x01){ - return true; - } - - $chest->openInventory($player); - return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ $drops = array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Clay.php b/src/PocketMine/block/Clay.php index e024285f6..4d3ab2677 100644 --- a/src/PocketMine/block/Clay.php +++ b/src/PocketMine/block/Clay.php @@ -30,7 +30,7 @@ class Clay extends Solid{ $this->hardness = 3; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::CLAY, 0, 4), ); diff --git a/src/PocketMine/block/Coal.php b/src/PocketMine/block/Coal.php index a99a1efa3..e92df27f1 100644 --- a/src/PocketMine/block/Coal.php +++ b/src/PocketMine/block/Coal.php @@ -30,10 +30,7 @@ class Coal extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.95; @@ -50,12 +47,12 @@ class Coal extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::COAL_BLOCK, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/CoalOre.php b/src/PocketMine/block/CoalOre.php index 74a5e2d55..9b9acfdec 100644 --- a/src/PocketMine/block/CoalOre.php +++ b/src/PocketMine/block/CoalOre.php @@ -30,10 +30,7 @@ class CoalOre extends Solid{ $this->hardness = 15; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.6; @@ -50,12 +47,12 @@ class CoalOre extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::COAL, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Cobblestone.php b/src/PocketMine/block/Cobblestone.php index 888eaa87f..31b6e50b5 100644 --- a/src/PocketMine/block/Cobblestone.php +++ b/src/PocketMine/block/Cobblestone.php @@ -30,10 +30,7 @@ class Cobblestone extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.4; @@ -50,12 +47,12 @@ class Cobblestone extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::COBBLESTONE, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Cobweb.php b/src/PocketMine/block/Cobweb.php index 4ae5d5c47..deca060ed 100644 --- a/src/PocketMine/block/Cobweb.php +++ b/src/PocketMine/block/Cobweb.php @@ -32,7 +32,7 @@ class Cobweb extends Flowable{ $this->hardness = 25; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array(); } } \ No newline at end of file diff --git a/src/PocketMine/block/CyanFlower.php b/src/PocketMine/block/CyanFlower.php index 785093611..628b69b5a 100644 --- a/src/PocketMine/block/CyanFlower.php +++ b/src/PocketMine/block/CyanFlower.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class CyanFlower extends Flowable{ public function __construct(){ @@ -31,7 +31,7 @@ class CyanFlower extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ $this->level->setBlock($block, $this, true, false, true); diff --git a/src/PocketMine/block/Dandelion.php b/src/PocketMine/block/Dandelion.php index 4599bb858..6b91921b3 100644 --- a/src/PocketMine/block/Dandelion.php +++ b/src/PocketMine/block/Dandelion.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Dandelion extends Flowable{ public function __construct(){ @@ -31,7 +31,7 @@ class Dandelion extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ $this->level->setBlock($block, $this, true, false, true); diff --git a/src/PocketMine/block/Diamond.php b/src/PocketMine/block/Diamond.php index 47fe81a1c..957a502d8 100644 --- a/src/PocketMine/block/Diamond.php +++ b/src/PocketMine/block/Diamond.php @@ -30,10 +30,7 @@ class Diamond extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.95; @@ -44,12 +41,12 @@ class Diamond extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 4){ return array( array(Item::DIAMOND_BLOCK, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/DiamondOre.php b/src/PocketMine/block/DiamondOre.php index d99450827..a4ee68393 100644 --- a/src/PocketMine/block/DiamondOre.php +++ b/src/PocketMine/block/DiamondOre.php @@ -30,10 +30,7 @@ class DiamondOre extends Solid{ $this->hardness = 15; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.6; @@ -44,12 +41,12 @@ class DiamondOre extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 4){ return array( array(Item::DIAMOND, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Dirt.php b/src/PocketMine/block/Dirt.php index 654ee8274..7ce9bccf6 100644 --- a/src/PocketMine/block/Dirt.php +++ b/src/PocketMine/block/Dirt.php @@ -31,11 +31,9 @@ class Dirt extends Solid{ $this->hardness = 2.5; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->isHoe()){ - if(($player->gamemode & 0x01) === 0){ - $item->useOn($this); - } + $item->useOn($this); $this->level->setBlock($this, Block::get(Item::FARMLAND, 0), true, false, true); return true; diff --git a/src/PocketMine/block/Door.php b/src/PocketMine/block/Door.php index 823ac2078..2df766354 100644 --- a/src/PocketMine/block/Door.php +++ b/src/PocketMine/block/Door.php @@ -21,11 +21,11 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\Network\Protocol\LevelEventPacket; use PocketMine\Player; -use PocketMine; abstract class Door extends Transparent{ @@ -49,14 +49,14 @@ abstract class Door extends Transparent{ return false; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ if($face === 1){ $blockUp = $this->getSide(1); $blockDown = $this->getSide(0); if($blockUp->isReplaceable === false or $blockDown->isTransparent === true){ return false; } - $direction = $player->getDirection(); + $direction = $player instanceof Player ? $player->getDirection() : 0; $face = array( 0 => 3, 1 => 4, @@ -71,7 +71,7 @@ abstract class Door extends Transparent{ } $this->level->setBlock($blockUp, Block::get($this->id, $metaUp), true, false, true); //Top - $this->meta = $direction & 0x03; + $this->meta = $player->getDirection() & 0x03; $this->level->setBlock($block, $this, true, false, true); //Bottom return true; } @@ -79,13 +79,13 @@ abstract class Door extends Transparent{ return false; } - public function onBreak(Item $item, PocketMine\Player $player){ + public function onBreak(Item $item){ if(($this->meta & 0x08) === 0x08){ $down = $this->getSide(0); if($down->getID() === $this->id){ $this->level->setBlock($down, new Air(), true, false, true); } - } else{ + }else{ $up = $this->getSide(1); if($up->getID() === $this->id){ $this->level->setBlock($up, new Air(), true, false, true); @@ -96,14 +96,16 @@ abstract class Door extends Transparent{ return true; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if(($this->meta & 0x08) === 0x08){ //Top $down = $this->getSide(0); if($down->getID() === $this->id){ $meta = $down->getMetadata() ^ 0x04; $this->level->setBlock($down, Block::get($this->id, $meta), true, false, true); $players = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4); - unset($players[$player->CID]); + if($player instanceof Player){ + unset($players[$player->CID]); + } $pk = new LevelEventPacket; $pk->x = $this->x; $pk->y = $this->y; @@ -116,11 +118,13 @@ abstract class Door extends Transparent{ } return false; - } else{ + }else{ $this->meta ^= 0x04; $this->level->setBlock($this, $this, true, false, true); $players = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4); - unset($players[$player->CID]); + if($player instanceof Player){ + unset($players[$player->CID]); + } $pk = new LevelEventPacket; $pk->x = $this->x; $pk->y = $this->y; diff --git a/src/PocketMine/block/DoubleSlab.php b/src/PocketMine/block/DoubleSlab.php index 1b33ec5f7..71fe7e84e 100644 --- a/src/PocketMine/block/DoubleSlab.php +++ b/src/PocketMine/block/DoubleSlab.php @@ -40,10 +40,7 @@ class DoubleSlab extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.4; @@ -60,12 +57,12 @@ class DoubleSlab extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::SLAB, $this->meta & 0x07, 2), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/DoubleWoodSlab.php b/src/PocketMine/block/DoubleWoodSlab.php index 3caafd9e4..8cb1bc393 100644 --- a/src/PocketMine/block/DoubleWoodSlab.php +++ b/src/PocketMine/block/DoubleWoodSlab.php @@ -37,10 +37,7 @@ class DoubleWoodSlab extends Solid{ $this->hardness = 15; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isAxe()){ case 5: return 0.4; @@ -57,7 +54,7 @@ class DoubleWoodSlab extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::WOOD_SLAB, $this->meta & 0x07, 2), ); diff --git a/src/PocketMine/block/Fallable.php b/src/PocketMine/block/Fallable.php index 5fb2b766f..5854e53f7 100644 --- a/src/PocketMine/block/Fallable.php +++ b/src/PocketMine/block/Fallable.php @@ -21,10 +21,10 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\ServerAPI; -use PocketMine; class Fallable extends Solid{ @@ -33,7 +33,7 @@ class Fallable extends Solid{ $this->hasPhysics = true; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $ret = $this->level->setBlock($this, $this, true, false, true); ServerAPI::request()->api->block->blockUpdate(clone $this, Level::BLOCK_UPDATE_NORMAL); diff --git a/src/PocketMine/block/Farmland.php b/src/PocketMine/block/Farmland.php index 892e11bdb..e44fc4b2a 100644 --- a/src/PocketMine/block/Farmland.php +++ b/src/PocketMine/block/Farmland.php @@ -30,7 +30,7 @@ class Farmland extends Solid{ $this->hardness = 3; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::DIRT, 0, 1), ); diff --git a/src/PocketMine/block/FenceGate.php b/src/PocketMine/block/FenceGate.php index ccf093c02..635fe2276 100644 --- a/src/PocketMine/block/FenceGate.php +++ b/src/PocketMine/block/FenceGate.php @@ -30,42 +30,42 @@ class FenceGate extends Transparent{ $this->isActivable = true; if(($this->meta & 0x04) === 0x04){ $this->isFullBlock = true; - } else{ + }else{ $this->isFullBlock = false; } $this->hardness = 15; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $faces = array( 0 => 3, 1 => 0, 2 => 1, 3 => 2, ); - $this->meta = $faces[$player->getDirection()] & 0x03; + $this->meta = $faces[$player instanceof PocketMine\Player ? $player->getDirection() : 0] & 0x03; $this->level->setBlock($block, $this, true, false, true); return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ $faces = array( 0 => 3, 1 => 0, 2 => 1, 3 => 2, ); - $this->meta = ($faces[$player->getDirection()] & 0x03) | ((~$this->meta) & 0x04); + $this->meta = ($faces[$player instanceof PocketMine\Player ? $player->getDirection() : 0] & 0x03) | ((~$this->meta) & 0x04); if(($this->meta & 0x04) === 0x04){ $this->isFullBlock = true; - } else{ + }else{ $this->isFullBlock = false; } $this->level->setBlock($this, $this, true, false, true); diff --git a/src/PocketMine/block/Fire.php b/src/PocketMine/block/Fire.php index d5471a133..0bc2466b3 100644 --- a/src/PocketMine/block/Fire.php +++ b/src/PocketMine/block/Fire.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Fire extends Flowable{ public function __construct($meta = 0){ @@ -34,7 +34,7 @@ class Fire extends Flowable{ $this->hardness = 0; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array(); } @@ -49,7 +49,7 @@ class Fire extends Flowable{ $this->level->setBlock($this, new Air(), true, false, true); return Level::BLOCK_UPDATE_NORMAL; - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if($this->getSide(0)->getID() !== self::NETHERRACK){ $this->level->setBlock($this, new Air(), true, false, true); diff --git a/src/PocketMine/block/Generic.php b/src/PocketMine/block/Generic.php index f17d07105..9baf4db34 100644 --- a/src/PocketMine/block/Generic.php +++ b/src/PocketMine/block/Generic.php @@ -21,10 +21,10 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\ServerAPI; -use PocketMine; class Generic extends Block{ @@ -37,15 +37,15 @@ class Generic extends Block{ parent::__construct($id, $meta, $name); } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ return $this->level->setBlock($this, $this, true, false, true); } - public function isBreakable(Item $item, PocketMine\Player $player){ + public function isBreakable(Item $item){ return $this->breakable; } - public function onBreak(Item $item, PocketMine\Player $player){ + public function onBreak(Item $item){ return $this->level->setBlock($this, new Air(), true, false, true); } @@ -73,7 +73,7 @@ class Generic extends Block{ return false; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ return $this->isActivable; } } \ No newline at end of file diff --git a/src/PocketMine/block/Glass.php b/src/PocketMine/block/Glass.php index 20acc7373..c5a41c623 100644 --- a/src/PocketMine/block/Glass.php +++ b/src/PocketMine/block/Glass.php @@ -30,7 +30,7 @@ class Glass extends Transparent{ $this->hardness = 1.5; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array(); } } \ No newline at end of file diff --git a/src/PocketMine/block/GlowingRedstoneOre.php b/src/PocketMine/block/GlowingRedstoneOre.php index b9873138d..604894ac6 100644 --- a/src/PocketMine/block/GlowingRedstoneOre.php +++ b/src/PocketMine/block/GlowingRedstoneOre.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class GlowingRedstoneOre extends Solid{ public function __construct(){ @@ -42,10 +42,7 @@ class GlowingRedstoneOre extends Solid{ } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.6; @@ -56,12 +53,12 @@ class GlowingRedstoneOre extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 4){ return array( array(Item::REDSTONE_DUST, 0, mt_rand(4, 5)), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Glowstone.php b/src/PocketMine/block/Glowstone.php index cb936332f..8fa33bdf5 100644 --- a/src/PocketMine/block/Glowstone.php +++ b/src/PocketMine/block/Glowstone.php @@ -30,7 +30,7 @@ class Glowstone extends Transparent{ $this->hardness = 1.5; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::GLOWSTONE_DUST, 0, mt_rand(2, 4)), ); diff --git a/src/PocketMine/block/Gold.php b/src/PocketMine/block/Gold.php index d993fa27d..4153bda6f 100644 --- a/src/PocketMine/block/Gold.php +++ b/src/PocketMine/block/Gold.php @@ -30,10 +30,7 @@ class Gold extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.6; @@ -44,12 +41,12 @@ class Gold extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 4){ return array( array(Item::GOLD_BLOCK, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/GoldOre.php b/src/PocketMine/block/GoldOre.php index e1906ad59..ee0bb35ac 100644 --- a/src/PocketMine/block/GoldOre.php +++ b/src/PocketMine/block/GoldOre.php @@ -30,10 +30,7 @@ class GoldOre extends Solid{ $this->hardness = 15; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.6; @@ -44,12 +41,12 @@ class GoldOre extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 4){ return array( array(Item::GOLD_ORE, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Grass.php b/src/PocketMine/block/Grass.php index b92f7c225..0da1929e4 100644 --- a/src/PocketMine/block/Grass.php +++ b/src/PocketMine/block/Grass.php @@ -21,10 +21,10 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Generator\Object\TallGrass; use PocketMine\Utils\Random; -use PocketMine; class Grass extends Solid{ public function __construct(){ @@ -33,24 +33,20 @@ class Grass extends Solid{ $this->hardness = 3; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::DIRT, 0, 1), ); } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ - if(($player->gamemode & 0x01) === 0){ - $item->count--; - } + $item->count--; TallGrass::growGrass($this->level, $this, new Random(), 8, 2); return true; - } elseif($item->isHoe()){ - if(($player->gamemode & 0x01) === 0){ - $item->useOn($this); - } + }elseif($item->isHoe()){ + $item->useOn($this); $this->level->setBlock($this, new Farmland()); return true; diff --git a/src/PocketMine/block/Gravel.php b/src/PocketMine/block/Gravel.php index dd3d17aee..5c9db8c3b 100644 --- a/src/PocketMine/block/Gravel.php +++ b/src/PocketMine/block/Gravel.php @@ -30,7 +30,7 @@ class Gravel extends Fallable{ $this->hardness = 3; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if(mt_rand(1, 10) === 1){ return array( array(Item::FLINT, 0, 1), diff --git a/src/PocketMine/block/HayBale.php b/src/PocketMine/block/HayBale.php index 2c90a8ed8..e6669938d 100644 --- a/src/PocketMine/block/HayBale.php +++ b/src/PocketMine/block/HayBale.php @@ -30,7 +30,7 @@ class HayBale extends Solid{ $this->hardness = 10; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $faces = array( 0 => 0, 1 => 0, @@ -46,7 +46,7 @@ class HayBale extends Solid{ return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Ice.php b/src/PocketMine/block/Ice.php index bf09dab80..ae93d55b3 100644 --- a/src/PocketMine/block/Ice.php +++ b/src/PocketMine/block/Ice.php @@ -30,20 +30,13 @@ class Ice extends Transparent{ $this->hardness = 2.5; } - public function onBreak(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0){ - $this->level->setBlock($this, new Water(), true, false, true); - } else{ - $this->level->setBlock($this, new Air(), true, false, true); - } + public function onBreak(Item $item){ + $this->level->setBlock($this, new Water(), true, false, true); return true; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.1; @@ -60,7 +53,7 @@ class Ice extends Transparent{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array(); } } \ No newline at end of file diff --git a/src/PocketMine/block/Iron.php b/src/PocketMine/block/Iron.php index 58371167e..482d9b72a 100644 --- a/src/PocketMine/block/Iron.php +++ b/src/PocketMine/block/Iron.php @@ -30,10 +30,7 @@ class Iron extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.95; @@ -46,12 +43,12 @@ class Iron extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 3){ return array( array(Item::IRON_BLOCK, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/IronDoor.php b/src/PocketMine/block/IronDoor.php index 933c0d7de..c7d6b3f00 100644 --- a/src/PocketMine/block/IronDoor.php +++ b/src/PocketMine/block/IronDoor.php @@ -31,10 +31,7 @@ class IronDoor extends Door{ $this->hardness = 25; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.95; @@ -51,12 +48,12 @@ class IronDoor extends Door{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::IRON_DOOR, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/IronOre.php b/src/PocketMine/block/IronOre.php index 514bdca45..a5f97985f 100644 --- a/src/PocketMine/block/IronOre.php +++ b/src/PocketMine/block/IronOre.php @@ -30,10 +30,7 @@ class IronOre extends Solid{ $this->hardness = 15; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.6; @@ -46,12 +43,12 @@ class IronOre extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 3){ return array( array(Item::IRON_ORE, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/JungleWoodStairs.php b/src/PocketMine/block/JungleWoodStairs.php index 7ffc525fa..f822384cb 100644 --- a/src/PocketMine/block/JungleWoodStairs.php +++ b/src/PocketMine/block/JungleWoodStairs.php @@ -29,7 +29,7 @@ class JungleWoodStairs extends Stair{ parent::__construct(self::JUNGLE_WOOD_STAIRS, $meta, "Jungle Wood Stairs"); } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Ladder.php b/src/PocketMine/block/Ladder.php index c9442e59e..a5996cb0d 100644 --- a/src/PocketMine/block/Ladder.php +++ b/src/PocketMine/block/Ladder.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Ladder extends Transparent{ public function __construct($meta = 0){ @@ -33,7 +33,7 @@ class Ladder extends Transparent{ $this->hardness = 2; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ if($target->isTransparent === false){ $faces = array( 2 => 2, @@ -64,7 +64,7 @@ class Ladder extends Transparent{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Lapis.php b/src/PocketMine/block/Lapis.php index 31571ff53..cf7896edb 100644 --- a/src/PocketMine/block/Lapis.php +++ b/src/PocketMine/block/Lapis.php @@ -30,10 +30,7 @@ class Lapis extends Solid{ $this->hardness = 15; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ switch($item->isPickaxe()){ case 5: return 0.6; @@ -46,12 +43,12 @@ class Lapis extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 3){ return array( array(Item::LAPIS_BLOCK, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/LapisOre.php b/src/PocketMine/block/LapisOre.php index 36b9d0bab..20d55fc7f 100644 --- a/src/PocketMine/block/LapisOre.php +++ b/src/PocketMine/block/LapisOre.php @@ -30,10 +30,8 @@ class LapisOre extends Solid{ $this->hardness = 15; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.6; @@ -46,12 +44,12 @@ class LapisOre extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 3){ return array( array(Item::DYE, 4, mt_rand(4, 8)), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Lava.php b/src/PocketMine/block/Lava.php index c4afb5c31..f90dff027 100644 --- a/src/PocketMine/block/Lava.php +++ b/src/PocketMine/block/Lava.php @@ -21,11 +21,11 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\Level\Position; use PocketMine\ServerAPI; -use PocketMine; class Lava extends Liquid{ public function __construct($meta = 0){ @@ -33,7 +33,7 @@ class Lava extends Liquid{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $ret = $this->level->setBlock($this, $this, true, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, Level::BLOCK_UPDATE_NORMAL); @@ -62,7 +62,7 @@ class Lava extends Liquid{ $level = $this->meta & 0x07; if($level == 0x00){ $this->level->setBlock($this, new Obsidian(), false, false, true); - } else{ + }else{ $this->level->setBlock($this, new Cobblestone(), false, false, true); } } @@ -105,19 +105,19 @@ class Lava extends Liquid{ if($down instanceof Air || $down instanceof Lava){ $this->level->setBlock($down, new Lava(0x01), false, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL); - } else{ + }else{ for($side = 2; $side <= 5; ++$side){ $b = $this->getSide($side); if($b instanceof Lava){ - } elseif($b->isFlowable === true){ + }elseif($b->isFlowable === true){ $this->level->setBlock($b, new Lava(min($level + 2, 7)), false, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 40, Level::BLOCK_UPDATE_NORMAL); } } } } - } else{ + }else{ //Extend Remove for Left Lavas for($side = 2; $side <= 5; ++$side){ $sb = $this->getSide($side); diff --git a/src/PocketMine/block/Leaves.php b/src/PocketMine/block/Leaves.php index 9c3013464..f3585a172 100644 --- a/src/PocketMine/block/Leaves.php +++ b/src/PocketMine/block/Leaves.php @@ -21,10 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine\ServerAPI; -use PocketMine; class Leaves extends Transparent{ const OAK = 0; @@ -52,7 +51,7 @@ class Leaves extends Transparent{ } if($pos->getID() === self::WOOD){ return true; - } elseif($pos->getID() === self::LEAVES and $distance < 3){ + }elseif($pos->getID() === self::LEAVES and $distance < 3){ $visited[$index] = true; $down = $pos->getSide(0)->getID(); if($down === Item::WOOD){ @@ -64,41 +63,41 @@ class Leaves extends Transparent{ return true; } } - } else{ //No more loops + }else{ //No more loops switch($fromSide){ case 2: if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){ return true; - } elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ + }elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ return true; - } elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ + }elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ return true; } break; case 3: if($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){ return true; - } elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ + }elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ return true; - } elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ + }elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ return true; } break; case 4: if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){ return true; - } elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){ + }elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){ return true; - } elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ + }elseif($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true){ return true; } break; case 5: if($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true){ return true; - } elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){ + }elseif($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true){ return true; - } elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ + }elseif($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true){ return true; } break; @@ -115,14 +114,14 @@ class Leaves extends Transparent{ $this->meta |= 0x08; $this->level->setBlock($this, $this, false, false, true); } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if(($this->meta & 0b00001100) === 0x08){ $this->meta &= 0x03; $visited = array(); $check = 0; if($this->findLog($this, $visited, 0, $check) === true){ $this->level->setBlock($this, $this, false, false, true); - } else{ + }else{ $this->level->setBlock($this, new Air(), false, false, true); if(mt_rand(1, 20) === 1){ //Saplings //TODO @@ -141,16 +140,16 @@ class Leaves extends Transparent{ return false; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $this->meta |= 0x04; $this->level->setBlock($this, $this, true, false, true); } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ $drops = array(); if($item->isShears()){ $drops[] = array(Item::LEAVES, $this->meta & 0x03, 1); - } else{ + }else{ if(mt_rand(1, 20) === 1){ //Saplings $drops[] = array(Item::SAPLING, $this->meta & 0x03, 1); } diff --git a/src/PocketMine/block/LitPumpkin.php b/src/PocketMine/block/LitPumpkin.php index aa78210a6..8b448a365 100644 --- a/src/PocketMine/block/LitPumpkin.php +++ b/src/PocketMine/block/LitPumpkin.php @@ -30,7 +30,7 @@ class LitPumpkin extends Solid{ $this->hardness = 5; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $faces = array( 0 => 4, 1 => 2, diff --git a/src/PocketMine/block/Melon.php b/src/PocketMine/block/Melon.php index ec21c0dbe..9989341ff 100644 --- a/src/PocketMine/block/Melon.php +++ b/src/PocketMine/block/Melon.php @@ -30,7 +30,7 @@ class Melon extends Transparent{ $this->hardness = 5; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::MELON_SLICE, 0, mt_rand(3, 7)), ); diff --git a/src/PocketMine/block/MelonStem.php b/src/PocketMine/block/MelonStem.php index 0d3c2c486..bd9d37c04 100644 --- a/src/PocketMine/block/MelonStem.php +++ b/src/PocketMine/block/MelonStem.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class MelonStem extends Flowable{ public function __construct($meta = 0){ @@ -32,7 +32,7 @@ class MelonStem extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::FARMLAND){ $this->level->setBlock($block, $this, true, false, true); @@ -52,14 +52,14 @@ class MelonStem extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 2) == 1){ if($this->meta < 0x07){ ++$this->meta; $this->level->setBlock($this, $this, true, false, true); return Level::BLOCK_UPDATE_RANDOM; - } else{ + }else{ for($side = 2; $side <= 5; ++$side){ $b = $this->getSide($side); if($b->getID() === self::MELON_BLOCK){ @@ -80,7 +80,7 @@ class MelonStem extends Flowable{ return false; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta = 0x07; $this->level->setBlock($this, $this, true, false, true); @@ -94,7 +94,7 @@ class MelonStem extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::MELON_SEEDS, 0, mt_rand(0, 2)), ); diff --git a/src/PocketMine/block/MossStone.php b/src/PocketMine/block/MossStone.php index 049ec5750..cdf6fa7e3 100644 --- a/src/PocketMine/block/MossStone.php +++ b/src/PocketMine/block/MossStone.php @@ -30,10 +30,8 @@ class MossStone extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.4; @@ -50,12 +48,12 @@ class MossStone extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::MOSS_STONE, $this->meta, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/NetherBrick.php b/src/PocketMine/block/NetherBrick.php index 4d4735448..e30ff2bfe 100644 --- a/src/PocketMine/block/NetherBrick.php +++ b/src/PocketMine/block/NetherBrick.php @@ -30,10 +30,8 @@ class NetherBrick extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.4; @@ -50,12 +48,12 @@ class NetherBrick extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::NETHER_BRICKS, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Netherrack.php b/src/PocketMine/block/Netherrack.php index 236073606..19c2ffa90 100644 --- a/src/PocketMine/block/Netherrack.php +++ b/src/PocketMine/block/Netherrack.php @@ -30,10 +30,8 @@ class Netherrack extends Solid{ $this->hardness = 2; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.1; @@ -50,12 +48,12 @@ class Netherrack extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::NETHERRACK, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Obsidian.php b/src/PocketMine/block/Obsidian.php index 8f97f3717..caaf8a817 100644 --- a/src/PocketMine/block/Obsidian.php +++ b/src/PocketMine/block/Obsidian.php @@ -30,23 +30,21 @@ class Obsidian extends Solid{ $this->hardness = 6000; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + if($item->isPickaxe() >= 5){ return 9.4; - } else{ + }else{ return 250; } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 5){ return array( array(Item::OBSIDIAN, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Potato.php b/src/PocketMine/block/Potato.php index 596e0954f..b5206b20f 100644 --- a/src/PocketMine/block/Potato.php +++ b/src/PocketMine/block/Potato.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Potato extends Flowable{ public function __construct($meta = 0){ @@ -32,7 +32,7 @@ class Potato extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::FARMLAND){ $this->level->setBlock($block, $this, true, false, true); @@ -43,7 +43,7 @@ class Potato extends Flowable{ return false; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta = 0x07; $this->level->setBlock($this, $this, true, false, true); @@ -66,7 +66,7 @@ class Potato extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 2) == 1){ if($this->meta < 0x07){ ++$this->meta; @@ -74,7 +74,7 @@ class Potato extends Flowable{ return Level::BLOCK_UPDATE_RANDOM; } - } else{ + }else{ return Level::BLOCK_UPDATE_RANDOM; } } @@ -82,11 +82,11 @@ class Potato extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ $drops = array(); if($this->meta >= 0x07){ $drops[] = array(Item::POTATO, 0, mt_rand(1, 4)); - } else{ + }else{ $drops[] = array(Item::POTATO, 0, 1); } diff --git a/src/PocketMine/block/PumpkinStem.php b/src/PocketMine/block/PumpkinStem.php index 8099f2f6c..43bad40a2 100644 --- a/src/PocketMine/block/PumpkinStem.php +++ b/src/PocketMine/block/PumpkinStem.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class PumpkinStem extends Flowable{ public function __construct($meta = 0){ @@ -32,7 +32,7 @@ class PumpkinStem extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::FARMLAND){ $this->level->setBlock($block, $this, true, false, true); @@ -52,14 +52,14 @@ class PumpkinStem extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 2) == 1){ if($this->meta < 0x07){ ++$this->meta; $this->level->setBlock($this, $this, true, false, true); return Level::BLOCK_UPDATE_RANDOM; - } else{ + }else{ for($side = 2; $side <= 5; ++$side){ $b = $this->getSide($side); if($b->getID() === self::PUMPKIN){ @@ -80,7 +80,7 @@ class PumpkinStem extends Flowable{ return false; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta = 0x07; $this->level->setBlock($this, $this, true, false, true); @@ -94,7 +94,7 @@ class PumpkinStem extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::PUMPKIN_SEEDS, 0, mt_rand(0, 2)), ); diff --git a/src/PocketMine/block/Quartz.php b/src/PocketMine/block/Quartz.php index 05d2e2cc5..5ee5084b7 100644 --- a/src/PocketMine/block/Quartz.php +++ b/src/PocketMine/block/Quartz.php @@ -36,10 +36,8 @@ class Quartz extends Solid{ $this->name = $names[$this->meta & 0x03]; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.15; @@ -56,12 +54,12 @@ class Quartz extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::QUARTZ_BLOCK, $this->meta & 0x03, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/RedMushroom.php b/src/PocketMine/block/RedMushroom.php index a8da0879b..7bb3a91f3 100644 --- a/src/PocketMine/block/RedMushroom.php +++ b/src/PocketMine/block/RedMushroom.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class RedMushroom extends Flowable{ public function __construct(){ @@ -45,7 +45,7 @@ class RedMushroom extends Flowable{ return false; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->isTransparent === false){ $this->level->setBlock($block, $this, true, false, true); diff --git a/src/PocketMine/block/RedstoneOre.php b/src/PocketMine/block/RedstoneOre.php index b03abdc1a..37206d898 100644 --- a/src/PocketMine/block/RedstoneOre.php +++ b/src/PocketMine/block/RedstoneOre.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class RedstoneOre extends Solid{ public function __construct(){ @@ -41,12 +41,12 @@ class RedstoneOre extends Solid{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 2){ return array( array(Item::REDSTONE_DUST, 0, mt_rand(4, 5)), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Sandstone.php b/src/PocketMine/block/Sandstone.php index fcefae259..b9f5fdea0 100644 --- a/src/PocketMine/block/Sandstone.php +++ b/src/PocketMine/block/Sandstone.php @@ -36,10 +36,8 @@ class Sandstone extends Solid{ $this->hardness = 4; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.15; @@ -56,12 +54,12 @@ class Sandstone extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::SANDSTONE, $this->meta & 0x03, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Sapling.php b/src/PocketMine/block/Sapling.php index 3e3f230a7..bb9501a26 100644 --- a/src/PocketMine/block/Sapling.php +++ b/src/PocketMine/block/Sapling.php @@ -21,11 +21,11 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Generator\Object\Tree; use PocketMine\Level\Level; use PocketMine\Utils\Random; -use PocketMine; class Sapling extends Flowable{ const OAK = 0; @@ -47,7 +47,7 @@ class Sapling extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::FARMLAND){ $this->level->setBlock($block, $this, true, false, true); @@ -58,7 +58,7 @@ class Sapling extends Flowable{ return false; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal Tree::growTree($this->level, $this, new Random(), $this->meta & 0x03); if(($player->gamemode & 0x01) === 0){ @@ -80,17 +80,17 @@ class Sapling extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth if(mt_rand(1, 7) === 1){ if(($this->meta & 0x08) === 0x08){ Tree::growTree($this->level, $this, new Random(), $this->meta & 0x03); - } else{ + }else{ $this->meta |= 0x08; $this->level->setBlock($this, $this, true, false, true); return Level::BLOCK_UPDATE_RANDOM; } - } else{ + }else{ return Level::BLOCK_UPDATE_RANDOM; } } @@ -98,7 +98,7 @@ class Sapling extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, $this->meta & 0x03, 1), ); diff --git a/src/PocketMine/block/SignPost.php b/src/PocketMine/block/SignPost.php index 00aff45ea..2ef596259 100644 --- a/src/PocketMine/block/SignPost.php +++ b/src/PocketMine/block/SignPost.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class SignPost extends Transparent{ public function __construct($meta = 0){ @@ -33,7 +33,7 @@ class SignPost extends Transparent{ $this->hardness = 5; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ if($face !== 0){ $faces = array( 2 => 2, @@ -46,7 +46,7 @@ class SignPost extends Transparent{ $this->level->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true, false, true); return true; - } else{ + }else{ $this->meta = $faces[$face]; $this->level->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true, false, true); @@ -71,13 +71,13 @@ class SignPost extends Transparent{ return false; } - public function onBreak(Item $item, PocketMine\Player $player){ + public function onBreak(Item $item){ $this->level->setBlock($this, new Air(), true, true, true); return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::SIGN, 0, 1), ); diff --git a/src/PocketMine/block/Slab.php b/src/PocketMine/block/Slab.php index ef2cfac58..3123133cd 100644 --- a/src/PocketMine/block/Slab.php +++ b/src/PocketMine/block/Slab.php @@ -40,37 +40,37 @@ class Slab extends Transparent{ $this->name = (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab"; if(($this->meta & 0x08) === 0x08){ $this->isFullBlock = true; - } else{ + }else{ $this->isFullBlock = false; } $this->hardness = 30; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $this->meta &= 0x07; if($face === 0){ if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true); return true; - } elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ + }elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true); return true; - } else{ + }else{ $this->meta |= 0x08; } - } elseif($face === 1){ + }elseif($face === 1){ if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true); return true; - } elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ + }elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true); return true; } - } elseif(!$player->inBlock($block)){ + }elseif(!($player instanceof PocketMine\Player) or !$player->inBlock($block)){ if($block->getID() === self::SLAB){ if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true); @@ -79,12 +79,12 @@ class Slab extends Transparent{ } return false; - } else{ + }else{ if($fy > 0.5){ $this->meta |= 0x08; } } - } else{ + }else{ return false; } if($block->getID() === self::SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){ @@ -95,10 +95,8 @@ class Slab extends Transparent{ return true; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.4; @@ -115,12 +113,12 @@ class Slab extends Transparent{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array($this->id, $this->meta & 0x07, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/SnowLayer.php b/src/PocketMine/block/SnowLayer.php index d19d0a449..9ad520a72 100644 --- a/src/PocketMine/block/SnowLayer.php +++ b/src/PocketMine/block/SnowLayer.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class SnowLayer extends Flowable{ public function __construct($meta = 0){ @@ -34,7 +34,7 @@ class SnowLayer extends Flowable{ $this->hardness = 0.5; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down instanceof Solid){ $this->level->setBlock($block, $this, true, false, true); @@ -57,7 +57,7 @@ class SnowLayer extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isShovel() !== false){ return array( array(Item::SNOWBALL, 0, 1), diff --git a/src/PocketMine/block/SpruceWoodStairs.php b/src/PocketMine/block/SpruceWoodStairs.php index 45c9188f4..84bfdfca6 100644 --- a/src/PocketMine/block/SpruceWoodStairs.php +++ b/src/PocketMine/block/SpruceWoodStairs.php @@ -29,7 +29,7 @@ class SpruceWoodStairs extends Stair{ parent::__construct(self::SPRUCE_WOOD_STAIRS, $meta, "Spruce Wood Stairs"); } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Stair.php b/src/PocketMine/block/Stair.php index e1ad7c28f..887900216 100644 --- a/src/PocketMine/block/Stair.php +++ b/src/PocketMine/block/Stair.php @@ -30,13 +30,13 @@ class Stair extends Transparent{ parent::__construct($id, $meta, $name); if(($this->meta & 0x04) === 0x04){ $this->isFullBlock = true; - } else{ + }else{ $this->isFullBlock = false; } $this->hardness = 30; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $faces = array( 0 => 0, 1 => 2, @@ -52,12 +52,12 @@ class Stair extends Transparent{ return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array($this->id, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Stone.php b/src/PocketMine/block/Stone.php index 3d8dba5b7..335e363ef 100644 --- a/src/PocketMine/block/Stone.php +++ b/src/PocketMine/block/Stone.php @@ -30,10 +30,8 @@ class Stone extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.4; @@ -50,12 +48,12 @@ class Stone extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::COBBLESTONE, 0, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/StoneBricks.php b/src/PocketMine/block/StoneBricks.php index 04a9c8842..640019985 100644 --- a/src/PocketMine/block/StoneBricks.php +++ b/src/PocketMine/block/StoneBricks.php @@ -37,10 +37,8 @@ class StoneBricks extends Solid{ $this->hardness = 30; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ case 5: return 0.4; @@ -57,12 +55,12 @@ class StoneBricks extends Solid{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ if($item->isPickaxe() >= 1){ return array( array(Item::STONE_BRICKS, $this->meta & 0x03, 1), ); - } else{ + }else{ return array(); } } diff --git a/src/PocketMine/block/Stonecutter.php b/src/PocketMine/block/Stonecutter.php index 754be5708..b2fc6e096 100644 --- a/src/PocketMine/block/Stonecutter.php +++ b/src/PocketMine/block/Stonecutter.php @@ -30,13 +30,13 @@ class Stonecutter extends Solid{ $this->isActivable = true; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ $player->toCraft[-1] = 2; return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Sugarcane.php b/src/PocketMine/block/Sugarcane.php index 9d0fd03a4..178d4324a 100644 --- a/src/PocketMine/block/Sugarcane.php +++ b/src/PocketMine/block/Sugarcane.php @@ -21,10 +21,10 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; use PocketMine\Math\Vector3 as Vector3; -use PocketMine; class Sugarcane extends Flowable{ public function __construct($meta = 0){ @@ -32,13 +32,13 @@ class Sugarcane extends Flowable{ $this->hardness = 0; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::SUGARCANE, 0, 1), ); } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){ for($y = 1; $y < 3; ++$y){ @@ -71,7 +71,7 @@ class Sugarcane extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){ if($this->meta === 0x0F){ for($y = 1; $y < 3; ++$y){ @@ -83,7 +83,7 @@ class Sugarcane extends Flowable{ } $this->meta = 0; $this->level->setBlock($this, $this, true, false, true); - } else{ + }else{ ++$this->meta; $this->level->setBlock($this, $this, true, false, true); } @@ -95,13 +95,13 @@ class Sugarcane extends Flowable{ return false; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::SUGARCANE_BLOCK){ $this->level->setBlock($block, new Sugarcane(), true, false, true); return true; - } elseif($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::SAND){ + }elseif($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::SAND){ $block0 = $down->getSide(2); $block1 = $down->getSide(3); $block2 = $down->getSide(4); diff --git a/src/PocketMine/block/TNT.php b/src/PocketMine/block/TNT.php index d844df7d8..5caeaf703 100644 --- a/src/PocketMine/block/TNT.php +++ b/src/PocketMine/block/TNT.php @@ -31,7 +31,7 @@ class TNT extends Solid{ $this->isActivable = true; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::FLINT_STEEL){ if(($player->gamemode & 0x01) === 0){ $item->useOn($this); diff --git a/src/PocketMine/block/TallGrass.php b/src/PocketMine/block/TallGrass.php index 7f73b1f4d..ff16fadde 100644 --- a/src/PocketMine/block/TallGrass.php +++ b/src/PocketMine/block/TallGrass.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class TallGrass extends Flowable{ public function __construct($meta = 1){ @@ -50,7 +50,7 @@ class TallGrass extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ $drops = array(); $possibleDrops = array( array(Item::WHEAT_SEEDS, 0, 1), diff --git a/src/PocketMine/block/Torch.php b/src/PocketMine/block/Torch.php index 8cb8fc5f9..c2a5c6672 100644 --- a/src/PocketMine/block/Torch.php +++ b/src/PocketMine/block/Torch.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Torch extends Flowable{ public function __construct($meta = 0){ @@ -56,7 +56,7 @@ class Torch extends Flowable{ return false; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ if($target->isTransparent === false and $face !== 0){ $faces = array( 1 => 5, @@ -69,7 +69,7 @@ class Torch extends Flowable{ $this->level->setBlock($block, $this, true, false, true); return true; - } elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === self::FENCE){ + }elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === self::FENCE){ $this->meta = 0; $this->level->setBlock($block, $this, true, false, true); @@ -79,7 +79,7 @@ class Torch extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Trapdoor.php b/src/PocketMine/block/Trapdoor.php index ebdb0562d..df7c7a5d6 100644 --- a/src/PocketMine/block/Trapdoor.php +++ b/src/PocketMine/block/Trapdoor.php @@ -30,13 +30,13 @@ class Trapdoor extends Transparent{ $this->isActivable = true; if(($this->meta & 0x04) === 0x04){ $this->isFullBlock = false; - } else{ + }else{ $this->isFullBlock = true; } $this->hardness = 15; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ if(($target->isTransparent === false or $target->getID() === self::SLAB) and $face !== 0 and $face !== 1){ $faces = array( 2 => 0, @@ -56,13 +56,13 @@ class Trapdoor extends Transparent{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ $this->meta ^= 0x04; $this->level->setBlock($this, $this, true, false, true); diff --git a/src/PocketMine/block/Water.php b/src/PocketMine/block/Water.php index be823710c..50b5a5bd6 100644 --- a/src/PocketMine/block/Water.php +++ b/src/PocketMine/block/Water.php @@ -22,10 +22,10 @@ namespace PocketMine\Block; use PocketMine\Item\Item; -use PocketMine\Level\Level; -use PocketMine\ServerAPI; use PocketMine; +use PocketMine\Level\Level; use PocketMine\Level\Position; +use PocketMine\ServerAPI; class Water extends Liquid{ public function __construct($meta = 0){ @@ -33,7 +33,7 @@ class Water extends Liquid{ $this->hardness = 500; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $ret = $this->level->setBlock($this, $this, true, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, Level::BLOCK_UPDATE_NORMAL); @@ -65,7 +65,7 @@ class Water extends Liquid{ $level = $b->meta & 0x07; if($level == 0x00){ $this->level->setBlock($b, new Obsidian(), false, false, true); - } else{ + }else{ $this->level->setBlock($b, new Cobblestone(), false, false, true); } @@ -111,21 +111,21 @@ class Water extends Liquid{ if($down instanceof Air || $down instanceof Water){ $this->level->setBlock($down, new Water(0x01), false, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($down, $this->level), 10, Level::BLOCK_UPDATE_NORMAL); - } else{ + }else{ for($side = 2; $side <= 5; ++$side){ $b = $this->getSide($side); if($b instanceof Water){ if($this->getSourceCount() >= 2 && $level != 0x00){ $this->level->setBlock($this, new Water(0), false, false, true); } - } elseif($b->isFlowable === true){ + }elseif($b->isFlowable === true){ $this->level->setBlock($b, new Water($level + 1), false, false, true); ServerAPI::request()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL); } } } } - } else{ + }else{ //Extend Remove for Left Waters for($side = 2; $side <= 5; ++$side){ $sb = $this->getSide($side); diff --git a/src/PocketMine/block/Wheat.php b/src/PocketMine/block/Wheat.php index fa348b90d..9d4d0211a 100644 --- a/src/PocketMine/block/Wheat.php +++ b/src/PocketMine/block/Wheat.php @@ -21,9 +21,9 @@ namespace PocketMine\Block; +use PocketMine; use PocketMine\Item\Item; use PocketMine\Level\Level; -use PocketMine; class Wheat extends Flowable{ public function __construct($meta = 0){ @@ -32,7 +32,7 @@ class Wheat extends Flowable{ $this->hardness = 0; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $down = $this->getSide(0); if($down->getID() === self::FARMLAND){ $this->level->setBlock($block, $this, true, false, true); @@ -43,7 +43,7 @@ class Wheat extends Flowable{ return false; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal $this->meta = 0x07; $this->level->setBlock($this, $this, true, false, true); @@ -66,7 +66,7 @@ class Wheat extends Flowable{ return Level::BLOCK_UPDATE_NORMAL; } - } elseif($type === Level::BLOCK_UPDATE_RANDOM){ + }elseif($type === Level::BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 2) == 1){ if($this->meta < 0x07){ ++$this->meta; @@ -78,12 +78,12 @@ class Wheat extends Flowable{ return false; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ $drops = array(); if($this->meta >= 0x07){ $drops[] = array(Item::WHEAT, 0, 1); $drops[] = array(Item::WHEAT_SEEDS, 0, mt_rand(0, 3)); - } else{ + }else{ $drops[] = array(Item::WHEAT_SEEDS, 0, 1); } diff --git a/src/PocketMine/block/Wood.php b/src/PocketMine/block/Wood.php index 8bec3645b..3beca68ca 100644 --- a/src/PocketMine/block/Wood.php +++ b/src/PocketMine/block/Wood.php @@ -42,7 +42,7 @@ class Wood extends Solid{ $this->hardness = 10; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $faces = array( 0 => 0, 1 => 0, @@ -58,7 +58,7 @@ class Wood extends Solid{ return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, $this->meta & 0x03, 1), ); diff --git a/src/PocketMine/block/WoodDoor.php b/src/PocketMine/block/WoodDoor.php index cb2865336..5a49b290a 100644 --- a/src/PocketMine/block/WoodDoor.php +++ b/src/PocketMine/block/WoodDoor.php @@ -31,7 +31,7 @@ class WoodDoor extends Door{ $this->hardness = 15; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array(Item::WOODEN_DOOR, 0, 1), ); diff --git a/src/PocketMine/block/WoodSlab.php b/src/PocketMine/block/WoodSlab.php index bd85c76fc..cf831d14e 100644 --- a/src/PocketMine/block/WoodSlab.php +++ b/src/PocketMine/block/WoodSlab.php @@ -36,37 +36,37 @@ class WoodSlab extends Transparent{ $this->name = (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Wooden Slab"; if(($this->meta & 0x08) === 0x08){ $this->isFullBlock = true; - } else{ + }else{ $this->isFullBlock = false; } $this->hardness = 15; } - public function place(Item $item, PocketMine\Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, PocketMine\Player $player = null){ $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(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; - } elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ + }elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; - } else{ + }else{ $this->meta |= 0x08; } - } elseif($face === 1){ + }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(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; - } elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ + }elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } - } elseif(!$player->inBlock($block)){ + }elseif(!($player instanceof PocketMine\Player) or !$player->inBlock($block)){ if($block->getID() === self::WOOD_SLAB){ if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true); @@ -75,12 +75,12 @@ class WoodSlab extends Transparent{ } return false; - } else{ + }else{ if($fy > 0.5){ $this->meta |= 0x08; } } - } else{ + }else{ return false; } if($block->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){ @@ -91,10 +91,8 @@ class WoodSlab extends Transparent{ return true; } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isAxe()){ case 5: return 0.4; @@ -111,7 +109,7 @@ class WoodSlab extends Transparent{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, $this->meta & 0x07, 1), ); diff --git a/src/PocketMine/block/WoodStairs.php b/src/PocketMine/block/WoodStairs.php index b18a3788f..b14f15eb8 100644 --- a/src/PocketMine/block/WoodStairs.php +++ b/src/PocketMine/block/WoodStairs.php @@ -29,10 +29,8 @@ class WoodStairs extends Stair{ parent::__construct(self::WOOD_STAIRS, $meta, "Wood Stairs"); } - public function getBreakTime(Item $item, PocketMine\Player $player){ - if(($player->gamemode & 0x01) === 0x01){ - return 0.20; - } + public function getBreakTime(Item $item){ + switch($item->isAxe()){ case 5: return 0.4; @@ -49,7 +47,7 @@ class WoodStairs extends Stair{ } } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/block/Workbench.php b/src/PocketMine/block/Workbench.php index 2fdd09569..31ecd34f8 100644 --- a/src/PocketMine/block/Workbench.php +++ b/src/PocketMine/block/Workbench.php @@ -31,13 +31,13 @@ class Workbench extends Solid{ $this->hardness = 15; } - public function onActivate(Item $item, PocketMine\Player $player){ + public function onActivate(Item $item, PocketMine\Player $player = null){ $player->toCraft[-1] = 1; return true; } - public function getDrops(Item $item, PocketMine\Player $player){ + public function getDrops(Item $item){ return array( array($this->id, 0, 1), ); diff --git a/src/PocketMine/entity/Human.php b/src/PocketMine/entity/Human.php index ef5c06c74..ff746c211 100644 --- a/src/PocketMine/entity/Human.php +++ b/src/PocketMine/entity/Human.php @@ -21,6 +21,7 @@ namespace PocketMine\Entity; +use PocketMine; use PocketMine\Event\Entity\EntityArmorChangeEvent; use PocketMine\Event\Entity\EntityInventoryChangeEvent; use PocketMine\Event\Event; @@ -29,14 +30,13 @@ use PocketMine\Item\Item; use PocketMine\NBT\Tag\Byte; use PocketMine\NBT\Tag\Compound; use PocketMine\NBT\Tag\Short; -use PocketMine\Network; use PocketMine\Network\Protocol\AddPlayerPacket; use PocketMine\Network\Protocol\ContainerSetContentPacket; use PocketMine\Network\Protocol\PlayerEquipmentPacket; use PocketMine\Network\Protocol\RemovePlayerPacket; use PocketMine\Network\Protocol\SetEntityMotionPacket; +use PocketMine\Network; use PocketMine\Player; -use PocketMine; class Human extends Creature implements ProjectileSource, InventorySource{ @@ -61,9 +61,9 @@ class Human extends Creature implements ProjectileSource, InventorySource{ foreach($this->namedtag->Inventory as $item){ if($item["Slot"] >= 0 and $item["Slot"] < 9){ //Hotbar $this->hotbar[$item["Slot"]] = isset($item["TrueSlot"]) ? $item["TrueSlot"] : -1; - } elseif($item["Slot"] >= 100 and $item["Slot"] < 104){ //Armor + }elseif($item["Slot"] >= 100 and $item["Slot"] < 104){ //Armor $this->armor[$item["Slot"] - 100] = Item::get($item["id"], $item["Damage"], $item["Count"]); - } else{ + }else{ $this->inventory[$item["Slot"] - 9] = Item::get($item["id"], $item["Damage"], $item["Count"]); } } @@ -75,6 +75,8 @@ class Human extends Creature implements ProjectileSource, InventorySource{ public function saveNBT(){ parent::saveNBT(); + $this->namedtag->Inventory = new PocketMine\NBT\Tag\Enum("Inventory", array()); + $this->namedtag->Inventory->setTagType(PocketMine\NBT\NBT::TAG_Compound); for($slot = 0; $slot < 9; ++$slot){ if(isset($this->hotbar[$slot]) and $this->hotbar[$slot] !== -1){ $item = $this->getSlot($this->hotbar[$slot]); @@ -93,15 +95,16 @@ class Human extends Creature implements ProjectileSource, InventorySource{ new Byte("Count", 0), new Short("Damage", 0), new Byte("Slot", $slot), - new Byte("Slot", -1), + new Byte("TrueSlot", -1), new Short("id", 0), )); } //Normal inventory - $slotCount = (($this instanceof Player and ($this->gamemode & 0x01) === 1) ? Player::CREATIVE_SLOTS : Player::SURVIVAL_SLOTS) + 9; + $slotCount = Player::SURVIVAL_SLOTS + 9; + //$slotCount = (($this instanceof Player and ($this->gamemode & 0x01) === 1) ? Player::CREATIVE_SLOTS : Player::SURVIVAL_SLOTS) + 9; for($slot = 9; $slot < $slotCount; ++$slot){ - $item = $this->getSlot($slot); + $item = $this->getSlot($slot - 9); $this->namedtag->Inventory[$slot] = new Compound(false, array( new Byte("Count", $item->getCount()), new Short("Damage", $item->getMetadata()), @@ -216,7 +219,7 @@ class Human extends Creature implements ProjectileSource, InventorySource{ return $this->armor[$slot]; } - public function sendArmor(Player $player = null){ + public function sendArmor($player = null){ $slots = array(); for($i = 0; $i < 4; ++$i){ if(isset($this->armor[$i]) and ($this->armor[$i] instanceof Item) and $this->armor[$i]->getID() > Item::AIR){ diff --git a/src/PocketMine/event/block/BlockBreakEvent.php b/src/PocketMine/event/block/BlockBreakEvent.php new file mode 100644 index 000000000..0ab6b8f6b --- /dev/null +++ b/src/PocketMine/event/block/BlockBreakEvent.php @@ -0,0 +1,74 @@ +block = $block; + $this->item = $item; + $this->player = $player; + $this->instaBreak = (bool) $instaBreak; + } + + public function getPlayer(){ + return $this->player; + } + + public function getItem(){ + return $item; + } + + public function getInstaBreak(){ + return $this->instaBreak; + } + + /** + * @param boolean $instaBreak + */ + public function setInstaBreak($instaBreak){ + $this->instaBreak = (bool) $instaBreak; + } +} \ No newline at end of file diff --git a/src/PocketMine/event/block/BlockEvent.php b/src/PocketMine/event/block/BlockEvent.php new file mode 100644 index 000000000..29a5311a2 --- /dev/null +++ b/src/PocketMine/event/block/BlockEvent.php @@ -0,0 +1,39 @@ +block; + } +} \ No newline at end of file diff --git a/src/PocketMine/event/block/BlockPlaceEvent.php b/src/PocketMine/event/block/BlockPlaceEvent.php new file mode 100644 index 000000000..67821e0da --- /dev/null +++ b/src/PocketMine/event/block/BlockPlaceEvent.php @@ -0,0 +1,79 @@ +block = $blockPlace; + $this->blockReplace = $blockReplace; + $this->blockAgainst = $blockAgainst; + $this->item = $item; + $this->player = $player; + } + + public function getPlayer(){ + return $this->player; + } + + /** + * Gets the item in hand + * + * @return mixed + */ + public function getItem(){ + return $item; + } + + public function getBlockReplaced(){ + return $this->blockReplace; + } + + public function getBlockAgainst(){ + return $this->blockAgainst; + } +} \ No newline at end of file diff --git a/src/PocketMine/event/player/PlayerInteractEvent.php b/src/PocketMine/event/player/PlayerInteractEvent.php new file mode 100644 index 000000000..5b5afc25b --- /dev/null +++ b/src/PocketMine/event/player/PlayerInteractEvent.php @@ -0,0 +1,70 @@ +blockTouched = $block; + $this->player = $player; + $this->item = $item; + $this->blockFace = (int) $face; + } + + public function getItem(){ + return $item; + } + + public function getBlock(){ + return $this->blockTouched; + } + + public function getFace(){ + return $this->blockFace; + } +} \ No newline at end of file diff --git a/src/PocketMine/event/player/PlayerEquipmentChangeEvent.php b/src/PocketMine/event/player/PlayerItemHeldEvent.php similarity index 94% rename from src/PocketMine/event/player/PlayerEquipmentChangeEvent.php rename to src/PocketMine/event/player/PlayerItemHeldEvent.php index 9e5c0da3f..9362cc222 100644 --- a/src/PocketMine/event/player/PlayerEquipmentChangeEvent.php +++ b/src/PocketMine/event/player/PlayerItemHeldEvent.php @@ -21,13 +21,13 @@ namespace PocketMine\Event\Player; -use PocketMine\Event; use PocketMine\Event\CancellableEvent; -use PocketMine\Item\Item; use PocketMine; +use PocketMine\Event; +use PocketMine\Item\Item; use PocketMine\Player; -class PlayerEquipmentChangeEvent extends PlayerEvent implements CancellableEvent{ +class PlayerItemHeldEvent extends PlayerEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; diff --git a/src/PocketMine/item/Bucket.php b/src/PocketMine/item/Bucket.php index 6ac86b0bc..7090694d3 100644 --- a/src/PocketMine/item/Bucket.php +++ b/src/PocketMine/item/Bucket.php @@ -22,12 +22,12 @@ namespace PocketMine\Item; use PocketMine\Block\Air; +use PocketMine; use PocketMine\Block\Block; use PocketMine\Block\Lava; use PocketMine\Block\Liquid; use PocketMine\Block\Water; use PocketMine\Level\Level; -use PocketMine; use PocketMine\Player; class Bucket extends Item{ @@ -47,19 +47,19 @@ class Bucket extends Item{ return true; } - } elseif($this->meta === Item::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(); $level->setBlock($block, $water, true, false, true); - $water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz); + $water->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player); if(($player->gamemode & 0x01) === 0){ $this->meta = 0; } return true; } - } elseif($this->meta === Item::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/level/Level.php b/src/PocketMine/level/Level.php index 017c5c7e9..a7cc1e5a5 100644 --- a/src/PocketMine/level/Level.php +++ b/src/PocketMine/level/Level.php @@ -24,16 +24,21 @@ */ namespace PocketMine\Level; +use PocketMine; use PocketMine\Block\Air; use PocketMine\Block\Block; +use PocketMine\Item\Item; use PocketMine\Level\Generator\Flat; use PocketMine\Level\Generator\Generator; use PocketMine\Level\Generator\Normal; use PocketMine\Math\Vector3 as Vector3; use PocketMine\NBT\NBT; +use PocketMine\NBT\Tag\Byte; use PocketMine\NBT\Tag\Compound; use PocketMine\NBT\Tag\Enum; +use PocketMine\NBT\Tag\Int; use PocketMine\NBT\Tag\Short; +use PocketMine\NBT\Tag\String; use PocketMine\Network\Protocol\SetTimePacket; use PocketMine\Network\Protocol\UpdateBlockPacket; use PocketMine\Player; @@ -47,10 +52,6 @@ use PocketMine\Utils\Cache; use PocketMine\Utils\Config; use PocketMine\Utils\Random; use PocketMine\Utils\Utils; -use PocketMine; -use PocketMine\NBT\Tag\Byte; -use PocketMine\NBT\Tag\String; -use PocketMine\NBT\Tag\Int; /** * Class Level @@ -682,6 +683,141 @@ class Level{ return $ret; } + /** + * Tries to break a block using a item, including Player time checks if available + * + * @param Vector3 $vector + * @param Item &$item (if null, can break anything) + * @param Player $player + * + * @return boolean + */ + public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null){ + $target = $this->getBlock($vector); + + if($player instanceof Player){ + $lastTime = $player->lastBreak - $player->getLag() / 1000; + if(($player->getGamemode() & 0x01) === 1 and ($lastTime + 0.15) >= microtime(true)){ + return false; + }elseif(($lastTime + $target->getBreakTime($item)) >= microtime(true)){ + return false; + } + $player->lastBreak = microtime(true); + } + + //TODO: Adventure mode checks + if($player instanceof Player){ + $ev = new PocketMine\Event\Block\BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false); + if($item instanceof Item and !$target->isBreakable($item) and $ev->getInstaBreak() === false){ + $ev->setCancelled(); + } + if(PocketMine\Event\EventHandler::callEvent($ev) === PocketMine\Event\Event::DENY){ + return false; + } + }elseif($item instanceof Item and !$target->isBreakable($item)){ + return false; + } + + $target->onBreak($item); + if($item instanceof Item){ + $item->useOn($target); + if($item->isTool() and $item->getMetadata() >= $item->getMaxDurability()){ + $item = Item::get(Item::AIR, 0, 0); + } + } + + return $target->getDrops($item); + } + + /** + * Uses a item on a position and face, placing it or activating the block + * + * @param Vector3 $vector + * @param Item &$item + * @param int $face + * @param float $fx default 0.0 + * @param float $fy default 0.0 + * @param float $fz default 0.0 + * @param Player $player default null + * + * @return boolean + */ + public function useItemOn(Vector3 $vector, Item &$item, $face, $fx = 0.0, $fy = 0.0, $fz = 0.0, Player $player = null){ + $target = $this->getBlock($vector); + $block = $target->getSide($face); + + if($block->y > 127 or $block->y < 0){ + return false; + } + + if($target->getID() === Item::AIR){ + return false; + } + + if($player instanceof Player and PocketMine\Event\EventHandler::callEvent($ev = new PocketMine\Event\Player\PlayerInteractEvent($player, $item, $target, $face)) !== PocketMine\Event\Event::DENY){ + $target->onUpdate(Level::BLOCK_UPDATE_TOUCH); + } + + if($target->isActivable === true and $target->onActivate($item, $player) === true){ + return true; + } + + if($item->isPlaceable()){ + $hand = $item->getBlock(); + $hand->position($block); + }elseif($block->getID() === Item::FIRE){ + $this->setBlock($block, new PocketMine\Block\Air(), true, false, true); + + return false; + }else{ + return false; + } + + if(!($block->isReplaceable === true or ($hand->getID() === Item::SLAB and $block->getID() === Item::SLAB))){ + return false; + } + + if($target->isReplaceable === true){ + $block = $target; + $hand->position($block); + //$face = -1; + } + + //TODO: Implement using Bounding Boxes, all entities + /*if($hand->isSolid === true and $player->inBlock($block)){ + return false; //Entity in block + }*/ + $ev = new PocketMine\Event\Block\BlockPlaceEvent($player, $hand, $block, $target, $item); + + if($player instanceof Player and PocketMine\Event\EventHandler::callEvent($ev) === PocketMine\Event\Event::DENY){ + return false; + }elseif($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false){ + return false; + } + + if($hand->getID() === Item::SIGN_POST or $hand->getID() === Item::WALL_SIGN){ + $tile = new Sign($this, new Compound(false, array( + new String("id", PocketMine\Tile\Tile::SIGN), + new Int("x", $block->x), + new Int("y", $block->y), + new Int("z", $block->z), + new String("Text1", ""), + new String("Text2", ""), + new String("Text3", ""), + new String("Text4", "") + ))); + if($player instanceof Player){ + $tile->namedtag->creator = new String("creator", $player->getUsername()); + } + } + $item->setCount($item->getCount() - 1); + if($item->getCount() <= 0){ + $item = Item::get(Item::AIR, 0, 0); + } + + return true; + } + public function getBiome($x, $z){ return $this->level->getBiome((int) $x, (int) $z); } @@ -761,6 +897,9 @@ class Level{ $tags = $this->level->getChunkNBT($X, $Z); if(isset($tags->Entities)){ foreach($tags->Entities as $nbt){ + if(!isset($nbt["id"])){ + continue; + } switch($nbt["id"]){ //TODO: spawn entities } diff --git a/src/PocketMine/level/generator/Flat.php b/src/PocketMine/level/generator/Flat.php index 97348d496..4f4e53dd5 100644 --- a/src/PocketMine/level/generator/Flat.php +++ b/src/PocketMine/level/generator/Flat.php @@ -21,6 +21,7 @@ namespace PocketMine\Level\Generator; +use PocketMine; use PocketMine\Block\CoalOre; use PocketMine\Block\DiamondOre; use PocketMine\Block\Dirt; @@ -29,12 +30,11 @@ use PocketMine\Block\Gravel; use PocketMine\Block\IronOre; use PocketMine\Block\LapisOre; use PocketMine\Block\RedstoneOre; -use PocketMine\BlockAPI; +use PocketMine\Item\Item; use PocketMine\Level\Generator\Populator\Ore; use PocketMine\Level\Level; use PocketMine\Math\Vector3 as Vector3; use PocketMine\Utils\Random; -use PocketMine; class Flat extends Generator{ private $level, $random, $structure, $chunks, $options, $floorLevel, $preset, $populators = array(); @@ -87,7 +87,7 @@ class Flat extends Generator{ $this->structure = array(); $this->chunks = array(); foreach($matches[3] as $i => $b){ - $b = BlockAPI::fromString($b); + $b = Item::fromString($b); $cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]); for($cY = $y, $y += $cnt; $cY < $y; ++$cY){ $this->structure[$cY] = $b; diff --git a/src/PocketMine/nbt/NBT.php b/src/PocketMine/nbt/NBT.php index d672c0636..e22caad24 100644 --- a/src/PocketMine/nbt/NBT.php +++ b/src/PocketMine/nbt/NBT.php @@ -24,6 +24,7 @@ */ namespace PocketMine\NBT; +use PocketMine; use PocketMine\NBT\Tag\Byte; use PocketMine\NBT\Tag\Byte_Array; use PocketMine\NBT\Tag\Compound; @@ -39,7 +40,6 @@ use PocketMine\NBT\Tag\Short; use PocketMine\NBT\Tag\String; use PocketMine\NBT\Tag\Tag; use PocketMine\Utils\Utils; -use PocketMine; /** * Named Binary Tag encoder/decoder @@ -190,12 +190,12 @@ class NBT{ $tag->write($this); } - public function getByte(){ - return ord($this->get(1)); + public function getByte($signed = false){ + return Utils::readByte($this->get(1), $signed); } public function putByte($v){ - $this->buffer .= chr($v); + $this->buffer .= Utils::writeByte($v); } public function getShort(){ diff --git a/src/PocketMine/nbt/tag/Byte.php b/src/PocketMine/nbt/tag/Byte.php index 76c0d3c53..d11583457 100644 --- a/src/PocketMine/nbt/tag/Byte.php +++ b/src/PocketMine/nbt/tag/Byte.php @@ -31,7 +31,7 @@ class Byte extends NamedTag{ } public function read(NBT $nbt){ - $this->value = $nbt->getByte(); + $this->value = $nbt->getByte(true); } public function write(NBT $nbt){