From b26ee09f76482f995b6dbe7226e7dd33f494bdeb Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 13 Oct 2014 18:54:34 +0200 Subject: [PATCH] Removed a bunch of TODO and fixed item drops on block update --- src/pocketmine/Player.php | 96 +------------------ src/pocketmine/block/Block.php | 1 - src/pocketmine/block/Carpet.php | 5 +- src/pocketmine/block/CyanFlower.php | 5 +- src/pocketmine/block/Dandelion.php | 6 +- src/pocketmine/block/RedMushroom.php | 6 +- src/pocketmine/block/Sapling.php | 6 +- src/pocketmine/block/SignPost.php | 6 +- src/pocketmine/block/Sugarcane.php | 6 +- .../command/defaults/KillCommand.php | 4 +- src/pocketmine/entity/Entity.php | 2 +- .../event/entity/EntityDespawnEvent.php | 6 +- .../event/entity/EntitySpawnEvent.php | 6 +- src/pocketmine/tile/Tile.php | 2 - 14 files changed, 26 insertions(+), 131 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 51ebcbeeb..2f9290eb9 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -906,46 +906,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return; } - /*public function eventHandler($data, $event){ - switch($event){ - //TODO, obsolete - case "tile.update": - if($data->getLevel() === $this->getLevel()){ - if($data instanceof Furnace){ - foreach($this->windows as $id => $w){ - if($w === $data){ - $pk = new ContainerSetDataPacket; - $pk->windowid = $id; - $pk->property = 0; //Smelting - $pk->value = floor($data->namedtag->CookTime); - $this->dataPacket($pk); - - $pk = new ContainerSetDataPacket; - $pk->windowid = $id; - $pk->property = 1; //Fire icon - $pk->value = $data->namedtag->BurnTicks; - $this->dataPacket($pk); - } - } - } - } - break; - case "entity.metadata": - if($data->getID() === $this->id){ - $eid = 0; - }else{ - $eid = $data->getID(); - } - if($data->getLevel() === $this->getLevel()){ - $pk = new SetEntityDataPacket; - $pk->eid = $eid; - $pk->metadata = $data->getDamage(); - $this->dataPacket($pk); - } - break; - } - }*/ - /** * @param string $achievementId * @@ -2152,7 +2112,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->awardAchievement("makeBread"); break; case Item::CAKE: - //TODO: detect complex recipes like cake that leave remainings + //TODO: detect complex recipes like cake that leave remains $this->awardAchievement("bakeCake"); $this->inventory->addItem(Item::get(Item::BUCKET, 0, 3)); break; @@ -2611,56 +2571,4 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } -} - - -/* - * TODO death reasons -if(is_numeric($data["cause"])){ - $e = Entity::get($data["cause"]); - if($e instanceof Entity){ - switch($e->class){ - case ENTITY_PLAYER: - $message = " was killed by " . $e->name; - break; - default: - $message = " was killed"; - break; - } - } -}else{ - switch($data["cause"]){ - case "cactus": - $message = " was pricked to death"; - break; - case "lava": - $message = " tried to swim in lava"; - break; - case "fire": - $message = " went up in flames"; - break; - case "burning": - $message = " burned to death"; - break; - case "suffocation": - $message = " suffocated in a wall"; - break; - case "water": - $message = " drowned"; - break; - case "void": - $message = " fell out of the world"; - break; - case "fall": - $message = " hit the ground too hard"; - break; - case "explosion": - $message = " blew up"; - break; - default: - $message = " died"; - break; - } -} -Player::broadcastMessage($data["player"]->getName() . $message); -*/ +} \ No newline at end of file diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index d7ca18d93..ea28c66e3 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -363,7 +363,6 @@ class Block extends Position implements Metadatable{ [Item::STONECUTTER, 0], [Item::CHEST, 0], [Item::FURNACE, 0], - //TODO: End Portal [Item::END_PORTAL, 0], [Item::DANDELION, 0], [Item::POPPY, 0], diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index dc51e0e63..91269b9b0 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -81,9 +81,8 @@ class Carpet extends Flowable{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->getID() === self::AIR){ //TODO: Replace with common break method - $this->getLevel()->dropItem($this, Item::get($this->id, $this->meta, 1)); - $this->getLevel()->setBlock($this, new Air(), true); + if($this->getSide(0)->getID() === self::AIR){ + $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/block/CyanFlower.php b/src/pocketmine/block/CyanFlower.php index 4f1c96b76..e854b5a4c 100644 --- a/src/pocketmine/block/CyanFlower.php +++ b/src/pocketmine/block/CyanFlower.php @@ -49,9 +49,8 @@ class CyanFlower extends Flowable{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->isTransparent === true){ //TODO: Replace with common break method - $this->getLevel()->dropItem($this, Item::get($this->id, 0, 1)); - $this->getLevel()->setBlock($this, new Air(), false, false, true); + if($this->getSide(0)->isTransparent === true){ + $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/block/Dandelion.php b/src/pocketmine/block/Dandelion.php index b78f9042c..4dd1ead8c 100644 --- a/src/pocketmine/block/Dandelion.php +++ b/src/pocketmine/block/Dandelion.php @@ -49,10 +49,8 @@ class Dandelion extends Flowable{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->isTransparent === true){ //Replace with common break method - //TODO - //Server::getInstance()->api->entity->drop($this, Item::get($this->id)); - $this->getLevel()->setBlock($this, new Air(), false, false, true); + if($this->getSide(0)->isTransparent === true){ + $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/block/RedMushroom.php b/src/pocketmine/block/RedMushroom.php index 82128031e..60cdcd4b7 100644 --- a/src/pocketmine/block/RedMushroom.php +++ b/src/pocketmine/block/RedMushroom.php @@ -38,10 +38,8 @@ class RedMushroom extends Flowable{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->isTransparent === true){ //Replace with common break method - //TODO - //Server::getInstance()->api->entity->drop($this, Item::get($this->id)); - $this->getLevel()->setBlock($this, new Air(), false); + if($this->getSide(0)->isTransparent === true){ + $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index 502a8e42d..fafdf1571 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -81,10 +81,8 @@ class Sapling extends Flowable{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->isTransparent === true){ //Replace with common break method - //TODO - //Server::getInstance()->api->entity->drop($this, Item::get($this->id)); - $this->getLevel()->setBlock($this, new Air(), false, false, true); + if($this->getSide(0)->isTransparent === true){ + $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index 610c6d53a..bfece4e1f 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -64,10 +64,8 @@ class SignPost extends Transparent{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method - //TODO - //Server::getInstance()->api->entity->drop($this, Item::get(SIGN, 0, 1)); - $this->getLevel()->setBlock($this, new Air(), true, true, true); + if($this->getSide(0)->getID() === self::AIR){ + $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index 811f61e71..262604a48 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -74,10 +74,8 @@ class Sugarcane extends Flowable{ public function onUpdate($type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $down = $this->getSide(0); - if($down->isTransparent === true and $down->getID() !== self::SUGARCANE_BLOCK){ //Replace with common break method - //TODO - //Server::getInstance()->api->entity->drop($this, Item::get(SUGARCANE)); - $this->getLevel()->setBlock($this, new Air(), false, false, true); + if($down->isTransparent === true and $down->getID() !== self::SUGARCANE_BLOCK){ + $this->getLevel()->useBreakOn($this); return Level::BLOCK_UPDATE_NORMAL; } diff --git a/src/pocketmine/command/defaults/KillCommand.php b/src/pocketmine/command/defaults/KillCommand.php index 9e394b439..35cb93451 100644 --- a/src/pocketmine/command/defaults/KillCommand.php +++ b/src/pocketmine/command/defaults/KillCommand.php @@ -45,9 +45,7 @@ class KillCommand extends VanillaCommand{ } if($sender instanceof Player){ - //TODO: EntityDamageEvent - - Server::getInstance()->getPluginManager()->callEvent($ev = new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000)); + $sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000)); if($ev->isCancelled()){ return true; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 4c3cce7d1..7476b147a 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1151,7 +1151,7 @@ abstract class Entity extends Position implements Metadatable{ return false; } - public function getID(){ + public function getId(){ return $this->id; } diff --git a/src/pocketmine/event/entity/EntityDespawnEvent.php b/src/pocketmine/event/entity/EntityDespawnEvent.php index 736578837..fe080d83b 100644 --- a/src/pocketmine/event/entity/EntityDespawnEvent.php +++ b/src/pocketmine/event/entity/EntityDespawnEvent.php @@ -34,19 +34,21 @@ use pocketmine\entity\Vehicle; class EntityDespawnEvent extends EntityEvent{ public static $handlerList = null; + private $entityType; + /** * @param Entity $entity */ public function __construct(Entity $entity){ $this->entity = $entity; + $this->entityType = $entity::NETWORK_ID; } /** * @return int */ public function getType(){ - //TODO: implement Entity types - return -1; + return $this->entityType; } /** diff --git a/src/pocketmine/event/entity/EntitySpawnEvent.php b/src/pocketmine/event/entity/EntitySpawnEvent.php index 490f19a73..d66947e8a 100644 --- a/src/pocketmine/event/entity/EntitySpawnEvent.php +++ b/src/pocketmine/event/entity/EntitySpawnEvent.php @@ -34,11 +34,14 @@ use pocketmine\entity\Vehicle; class EntitySpawnEvent extends EntityEvent{ public static $handlerList = null; + private $entityType; + /** * @param Entity $entity */ public function __construct(Entity $entity){ $this->entity = $entity; + $this->entityType = $entity::NETWORK_ID; } /** @@ -52,8 +55,7 @@ class EntitySpawnEvent extends EntityEvent{ * @return int */ public function getType(){ - //TODO: implement Entity types - return -1; + return $this->entityType; } /** diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 16a21a7c5..4e735e488 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -38,8 +38,6 @@ abstract class Tile extends Position{ const CHEST = "Chest"; const FURNACE = "Furnace"; - //TODO: pre-close step NBT data saving method - public static $tileCount = 1; /** @var Chunk */