diff --git a/src/PocketMine/entity/Entity.php b/src/PocketMine/entity/Entity.php index 59f6d2c24..2bbfaae79 100644 --- a/src/PocketMine/entity/Entity.php +++ b/src/PocketMine/entity/Entity.php @@ -24,7 +24,6 @@ */ namespace PocketMine\Entity; -use PocketMine; use PocketMine\Event\Entity\EntityLevelChangeEvent; use PocketMine\Event\Entity\EntityMotionEvent; use PocketMine\Event\Entity\EntityMoveEvent; @@ -35,14 +34,14 @@ use PocketMine\Level\Position; use PocketMine\Math\AxisAlignedBB; use PocketMine\Math\Vector3 as Vector3; use PocketMine\NBT\Tag\Compound; +use PocketMine\Network; use PocketMine\Network\Protocol\MoveEntityPacket_PosRot; use PocketMine\Network\Protocol\MovePlayerPacket; use PocketMine\Network\Protocol\RemoveEntityPacket; use PocketMine\Network\Protocol\SetEntityMotionPacket; -use PocketMine\Network; use PocketMine\Player; use PocketMine\PMF\LevelFormat; -use PocketMine\ServerAPI; +use PocketMine; abstract class Entity extends Position{ public static $entityCount = 1; @@ -130,7 +129,7 @@ abstract class Entity extends Position{ $this->level->chunkEntities[$this->chunkIndex][$this->id] = $this; $this->lastUpdate = microtime(true); $this->initEntity(); - ServerAPI::request()->api->dhandle("entity.add", $this); + EventHandler::callEvent(new PocketMine\Event\Entity\EntitySpawnEvent($this)); } public function saveNBT(){ @@ -527,7 +526,7 @@ abstract class Entity extends Position{ unset($this->level->chunkEntities[$this->chunkIndex][$this->id]); unset(Entity::$list[$this->id]); $this->despawnFromAll(); - $this->server->api->dhandle("entity.remove", $this); + EventHandler::callEvent(new PocketMine\Event\Entity\EntityDespawnEvent($this)); } } diff --git a/src/PocketMine/event/entity/EntityDespawnEvent.php b/src/PocketMine/event/entity/EntityDespawnEvent.php new file mode 100644 index 000000000..754a54567 --- /dev/null +++ b/src/PocketMine/event/entity/EntityDespawnEvent.php @@ -0,0 +1,84 @@ +entity = $entity; + } + + /** + * @return int + */ + public function getType(){ + //TODO: implement Entity types + return -1; + } + + /** + * @return bool + */ + public function isCreature(){ + return $this->entity instanceof PocketMine\Entity\Creature; + } + + /** + * @return bool + */ + public function isHuman(){ + return $this->entity instanceof PocketMine\Entity\Human; + } + + /** + * @return bool + */ + public function isProjectile(){ + return $this->entity instanceof PocketMine\Entity\Projectile; + } + + /** + * @return bool + */ + public function isVehicle(){ + return $this->entity instanceof PocketMine\Entity\Vehicle; + } + + /** + * @return bool + */ + public function isItem(){ + return $this->entity instanceof PocketMine\Entity\DroppedItem; + } + +} \ No newline at end of file diff --git a/src/PocketMine/event/entity/EntityExplodeEvent.php b/src/PocketMine/event/entity/EntityExplodeEvent.php new file mode 100644 index 000000000..303305d4a --- /dev/null +++ b/src/PocketMine/event/entity/EntityExplodeEvent.php @@ -0,0 +1,100 @@ +entity = $entity; + $this->position = $position; + $this->blocks = $blocks; + $this->yield = $yield; + } + + /** + * @return Position + */ + public function getPosition(){ + return $this->position; + } + + /** + * @return Block[] + */ + public function getBlockList(){ + return $this->blocks; + } + + /** + * @param Block[] $blocks + */ + public function setBlockList(array $blocks){ + $this->blocks = $blocks; + } + + /** + * @return float + */ + public function getYield(){ + return $this->yield; + } + + /** + * @param float $yield + */ + public function setYield($yield){ + $this->yield = $yield; + } + +} \ No newline at end of file diff --git a/src/PocketMine/event/entity/EntityMoveEvent.php b/src/PocketMine/event/entity/EntityMoveEvent.php index 3971900d5..c6bee0ab5 100644 --- a/src/PocketMine/event/entity/EntityMoveEvent.php +++ b/src/PocketMine/event/entity/EntityMoveEvent.php @@ -22,15 +22,18 @@ namespace PocketMine\Event\Entity; use PocketMine\Entity\Entity; -use PocketMine; use PocketMine\Event\CancellableEvent; use PocketMine\Event; +use PocketMine; use PocketMine\Math\Vector3 as Vector3; class EntityMoveEvent extends EntityEvent implements CancellableEvent{ public static $handlers; public static $handlerPriority; + /** + * @var \PocketMine\Math\Vector3 + */ private $pos; public function __construct(Entity $entity, Vector3 $pos){ diff --git a/src/PocketMine/event/entity/EntitySpawnEvent.php b/src/PocketMine/event/entity/EntitySpawnEvent.php new file mode 100644 index 000000000..f2b3aa150 --- /dev/null +++ b/src/PocketMine/event/entity/EntitySpawnEvent.php @@ -0,0 +1,91 @@ +entity = $entity; + } + + /** + * @return PocketMine\Level\Position + */ + public function getPosition(){ + return $this->entity->getPosition(); + } + + /** + * @return int + */ + public function getType(){ + //TODO: implement Entity types + return -1; + } + + /** + * @return bool + */ + public function isCreature(){ + return $this->entity instanceof PocketMine\Entity\Creature; + } + + /** + * @return bool + */ + public function isHuman(){ + return $this->entity instanceof PocketMine\Entity\Human; + } + + /** + * @return bool + */ + public function isProjectile(){ + return $this->entity instanceof PocketMine\Entity\Projectile; + } + + /** + * @return bool + */ + public function isVehicle(){ + return $this->entity instanceof PocketMine\Entity\Vehicle; + } + + /** + * @return bool + */ + public function isItem(){ + return $this->entity instanceof PocketMine\Entity\DroppedItem; + } + +} \ No newline at end of file diff --git a/src/PocketMine/event/player/PlayerAchievementAwardedEvent.php b/src/PocketMine/event/player/PlayerAchievementAwardedEvent.php new file mode 100644 index 000000000..b30066082 --- /dev/null +++ b/src/PocketMine/event/player/PlayerAchievementAwardedEvent.php @@ -0,0 +1,52 @@ +player = $player; + $this->achievement = $achievementId; + } + + public function getAchievement(){ + return $this->achievement; + } +} \ No newline at end of file diff --git a/src/PocketMine/level/Explosion.php b/src/PocketMine/level/Explosion.php index 7739dc09d..b697ecfb7 100644 --- a/src/PocketMine/level/Explosion.php +++ b/src/PocketMine/level/Explosion.php @@ -22,13 +22,13 @@ namespace PocketMine\Level; use PocketMine\Block\Block; -use PocketMine; use PocketMine\Block\TNT; +use PocketMine\Entity\Entity; use PocketMine\Item\Item; use PocketMine\Math\Vector3 as Vector3; use PocketMine\Network\Protocol\ExplodePacket; +use PocketMine; use PocketMine\Player; -use PocketMine\ServerAPI; class Explosion{ public static $specialDrops = array( @@ -42,23 +42,22 @@ class Explosion{ public $level; public $source; public $size; + /** + * @var Block[] + */ public $affectedBlocks = array(); public $stepLen = 0.3; + private $what; - public function __construct(Position $center, $size){ + public function __construct(Position $center, $size, $what = null){ $this->level = $center->level; $this->source = $center; $this->size = max($size, 0); + $this->what = $what; } public function explode(){ - $server = ServerAPI::request(); - if($this->size < 0.1 or $server->api->dhandle("entity.explosion", array( - "level" => $this->level, - "source" => $this->source, - "size" => $this->size - )) === false - ){ + if($this->size < 0.1){ return false; } @@ -98,15 +97,26 @@ class Explosion{ $send = array(); $source = $this->source->floor(); $radius = 2 * $this->size; + $yield = (1 / $this->size) * 100; + + if($this->what instanceof Entity){ + if(PocketMine\Event\EventHandler::callEvent($ev = new PocketMine\Event\Entity\EntityExplodeEvent($this->what, $this->source, $this->affectedBlocks, $yield)) === PocketMine\Event\Event::DENY){ + return; + }else{ + $yield = $ev->getYield(); + $this->affectedBlocks = $ev->getBlockList(); + } + } + //TODO - foreach($server->api->entity->getRadius($this->source, $radius) as $entity){ + /*foreach($server->api->entity->getRadius($this->source, $radius) as $entity){ $impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //placeholder, 0.7 should be exposure $damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1); $entity->harm($damage, "explosion"); - } + }*/ + foreach($this->affectedBlocks as $block){ - if($block instanceof TNT){ $data = array( "x" => $block->x + 0.5, @@ -118,7 +128,7 @@ class Explosion{ //TODO //$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); //$e->spawnToAll(); - }elseif(mt_rand(0, 10000) < ((1 / $this->size) * 10000)){ + }elseif(mt_rand(0, 100) < $yield){ if(isset(self::$specialDrops[$block->getID()])){ //TODO //$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), Item::get(self::$specialDrops[$block->getID()], 0)); diff --git a/src/PocketMine/level/Level.php b/src/PocketMine/level/Level.php index 2f55341e9..4999975dc 100644 --- a/src/PocketMine/level/Level.php +++ b/src/PocketMine/level/Level.php @@ -24,6 +24,7 @@ */ namespace PocketMine\Level; +use PocketMine; use PocketMine\Block\Air; use PocketMine\Block\Block; use PocketMine\Item\Item; @@ -51,7 +52,6 @@ use PocketMine\Utils\Cache; use PocketMine\Utils\Config; use PocketMine\Utils\Random; use PocketMine\Utils\Utils; -use PocketMine; /** * Class Level @@ -421,14 +421,12 @@ class Level{ }else{ $time = $this->startTime + ($now - $this->startCheck) * 20; } - if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){ - $this->time = $time; - $pk = new SetTimePacket; - $pk->time = (int) $this->time; - $pk->started = $this->stopTime == false; - Player::broadcastPacket($this->players, $pk); - } + $this->time = $time; + $pk = new SetTimePacket; + $pk->time = (int) $this->time; + $pk->started = $this->stopTime == false; + Player::broadcastPacket($this->players, $pk); return; } diff --git a/src/PocketMine/tile/Tile.php b/src/PocketMine/tile/Tile.php index 7fce777c1..158a0c8bc 100644 --- a/src/PocketMine/tile/Tile.php +++ b/src/PocketMine/tile/Tile.php @@ -25,12 +25,12 @@ */ namespace PocketMine\Tile; -use PocketMine; use PocketMine\Level\Level; use PocketMine\Level\Position; use PocketMine\NBT\Tag\Compound; use PocketMine\PMF\LevelFormat; use PocketMine\ServerAPI; +use PocketMine; abstract class Tile extends Position{ const SIGN = "Sign"; @@ -84,7 +84,6 @@ abstract class Tile extends Position{ $this->chunkIndex = $index; $this->level->tiles[$this->id] = $this; $this->level->chunkTiles[$this->chunkIndex][$this->id] = $this; - $this->server->api->dhandle("tile.add", $this); } public function onUpdate(){ @@ -102,7 +101,6 @@ abstract class Tile extends Position{ unset($this->level->tiles[$this->id]); unset($this->level->chunkTiles[$this->chunkIndex][$this->id]); unset(Tile::$list[$this->id]); - $this->server->api->dhandle("tile.remove", $this); } }