diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index fa0b848e0..d2148fc37 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -776,10 +776,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ public function sleepOn(Vector3 $pos){ foreach($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p){ if($p instanceof Player){ - if($p->sleeping !== null){ - if($pos->distance($p->sleeping) <= 0.1){ - return false; - } + if($p->sleeping !== null and $pos->distance($p->sleeping) <= 0.1){ + return false; } } } @@ -790,7 +788,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $this->sleeping = clone $pos; - $this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level)); + //$this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level)); $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]); $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true); @@ -856,8 +854,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } } - - return; } /** @@ -1024,7 +1020,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ protected function getCreativeBlock(Item $item){ foreach(Block::$creative as $i => $d){ - if($d[0] === $item->getId() and $d[1] === $item->getDamage()){ + if($d[0] === $item->getId() and ($item->isTool() or $d[1] === $item->getDamage())){ return $i; } } @@ -1772,11 +1768,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ case 5: //Shot arrow if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION) and $this->inventory->getItemInHand()->getId() === Item::BOW){ $bow = $this->inventory->getItemInHand(); - if($this->isSurvival()){ - if(!$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){ - $this->inventory->sendContents($this); - break; - } + if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){ + $this->inventory->sendContents($this); + break; } @@ -1798,22 +1792,19 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ ]); $diff = ($this->server->getTick() - $this->startAction); - if($diff < 5){ - $this->inventory->sendContents($this); - break; - } $p = $diff / 20; $f = min((($p ** 2) + $p * 2) / 3, 1) * 2; - if($f < 0.1){ - $this->inventory->sendContents($this); - break; - } $ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->chunk, $nbt, $this, $f == 2 ? true : false), $f); + if($f < 0.1 or $diff < 5){ + $ev->setCancelled(); + } + $this->server->getPluginManager()->callEvent($ev); if($ev->isCancelled()){ $ev->getProjectile()->kill(); + $this->inventory->sendContents($this); }else{ $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce())); if($this->isSurvival()){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 54c7734c2..fc55a8ea2 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -534,7 +534,6 @@ abstract class Entity extends Location implements Metadatable{ $this->setLastDamageCause($source); - $this->setHealth($this->getHealth() - $source->getFinalDamage()); } @@ -615,29 +614,25 @@ abstract class Entity extends Location implements Metadatable{ } protected function checkObstruction($x, $y, $z){ - $i = (int) $x; - $j = (int) $y; - $k = (int) $z; + $i = Math::floorFloat($x); + $j = Math::floorFloat($y); + $k = Math::floorFloat($z); $diffX = $x - $i; $diffY = $y - $j; $diffZ = $z - $k; - $list = $this->level->getCollisionBlocks($this->boundingBox); - $v = new Vector3($i, $j, $k); - if(count($list) === 0 and !$this->level->isFullBlock($v->setComponents($i, $j, $k))){ - return false; - }else{ + if($this->level->isFullBlock($v)){ $flag = !$this->level->isFullBlock($v->setComponents($i - 1, $j, $k)); $flag1 = !$this->level->isFullBlock($v->setComponents($i + 1, $j, $k)); - //$flag2 = !$this->level->isFullBlock($v->setComponents($i, $j - 1, $k)); + $flag2 = !$this->level->isFullBlock($v->setComponents($i, $j - 1, $k)); $flag3 = !$this->level->isFullBlock($v->setComponents($i, $j + 1, $k)); $flag4 = !$this->level->isFullBlock($v->setComponents($i, $j, $k - 1)); $flag5 = !$this->level->isFullBlock($v->setComponents($i, $j, $k + 1)); - $direction = 3; //UP! + $direction = -1; $limit = 9999; if($flag){ @@ -650,6 +645,11 @@ abstract class Entity extends Location implements Metadatable{ $direction = 1; } + if($flag2 and $diffY < $limit){ + $limit = $diffY; + $direction = 2; + } + if($flag3 and 1 - $diffY < $limit){ $limit = 1 - $diffY; $direction = 3; @@ -678,7 +678,11 @@ abstract class Entity extends Location implements Metadatable{ return true; } - //No direction 2 + if($direction === 2){ + $this->motionY = -$force; + + return true; + } if($direction === 3){ $this->motionY = $force; @@ -699,6 +703,8 @@ abstract class Entity extends Location implements Metadatable{ return true; } + + return false; } public function entityBaseTick($tickDiff = 1){ @@ -728,10 +734,6 @@ abstract class Entity extends Location implements Metadatable{ $effect->setDuration($effect->getDuration() - $tickDiff); if($effect->getDuration() <= 0){ $this->removeEffect($effect->getId()); - $this->sendMetadata($this->hasSpawned); - if($this instanceof Player){ - $this->sendMetadata($this); - } } } } @@ -1106,8 +1108,7 @@ abstract class Entity extends Location implements Metadatable{ //TODO: big messy loop }*/ - $list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false); - + $list = $this->level->getCollisionCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false); foreach($list as $bb){ $dy = $bb->calculateYOffset($this->boundingBox, $dy); @@ -1160,7 +1161,7 @@ abstract class Entity extends Location implements Metadatable{ $this->boundingBox->setBB($axisalignedbb); - $list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false); + $list = $this->level->getCollisionCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false); foreach($list as $bb){ $dy = $bb->calculateYOffset($this->boundingBox, $dy); diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 09af1e1ef..74887267e 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -71,6 +71,10 @@ class FallingSand extends Entity{ return false; } + public function attack($damage, EntityDamageEvent $source){ + + } + public function onUpdate($currentTick){ if($this->closed){ diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index b311951b8..c7d9bc149 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -74,6 +74,13 @@ class Item extends Entity{ $this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this)); } + + public function attack($damage, EntityDamageEvent $source){ + if($source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK){ + parent::attack($damage, $source); + } + } + public function onUpdate($currentTick){ if($this->closed !== false){ return false; @@ -94,7 +101,7 @@ class Item extends Entity{ $this->motionY -= $this->gravity; - $this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); + $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); $this->move($this->motionX, $this->motionY, $this->motionZ); $friction = 1 - $this->drag; diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 5087e4c64..c23774303 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -44,6 +44,11 @@ class PrimedTNT extends Entity implements Explosive{ public $canCollide = false; + + public function attack($damage, EntityDamageEvent $source){ + + } + protected function initEntity(){ parent::initEntity(); @@ -102,8 +107,6 @@ class PrimedTNT extends Entity implements Explosive{ if($this->fuse <= 0){ $this->kill(); $this->explode(); - }else{ - $this->sendMetadata($this->getViewers()); } } diff --git a/src/pocketmine/entity/Projectile.php b/src/pocketmine/entity/Projectile.php index b6418c20f..583ca67ab 100644 --- a/src/pocketmine/entity/Projectile.php +++ b/src/pocketmine/entity/Projectile.php @@ -39,6 +39,11 @@ abstract class Projectile extends Entity{ public $hadCollision = false; + + public function attack($damage, EntityDamageEvent $source){ + + } + protected function initEntity(){ parent::initEntity(); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 3cc6fdde4..0efb2a7ad 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -824,17 +824,17 @@ class Level implements ChunkManager, Metadatable{ $minX = Math::floorFloat($bb->minX); $minY = Math::floorFloat($bb->minY); $minZ = Math::floorFloat($bb->minZ); - $maxX = Math::floorFloat($bb->maxX + 1); - $maxY = Math::floorFloat($bb->maxY + 1); - $maxZ = Math::floorFloat($bb->maxZ + 1); + $maxX = Math::ceilFloat($bb->maxX); + $maxY = Math::ceilFloat($bb->maxY); + $maxZ = Math::ceilFloat($bb->maxZ); $collides = []; $v = $this->temporalVector; - for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ - for($v->x = $minX; $v->x < $maxX; ++$v->x){ - for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){ + for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ + for($v->x = $minX; $v->x <= $maxX; ++$v->x){ + for($v->y = $minY - 1; $v->y <= $maxY; ++$v->y){ $block = $this->getBlock($v); if($block->getId() !== 0){ $block->collidesWithBB($bb, $collides); @@ -872,15 +872,15 @@ class Level implements ChunkManager, Metadatable{ $minX = Math::floorFloat($bb->minX); $minY = Math::floorFloat($bb->minY); $minZ = Math::floorFloat($bb->minZ); - $maxX = Math::floorFloat($bb->maxX + 1); - $maxY = Math::floorFloat($bb->maxY + 1); - $maxZ = Math::floorFloat($bb->maxZ + 1); + $maxX = Math::ceilFloat($bb->maxX); + $maxY = Math::ceilFloat($bb->maxY); + $maxZ = Math::ceilFloat($bb->maxZ); $collides = []; $v = $this->temporalVector; - for($v->z = $minZ; $v->z < $maxZ; ++$v->z){ - for($v->x = $minX; $v->x < $maxX; ++$v->x){ + for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ + for($v->x = $minX; $v->x <= $maxX; ++$v->x){ for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){ $block = $this->getBlock($v); if($block->getId() !== 0){ @@ -1492,9 +1492,9 @@ class Level implements ChunkManager, Metadatable{ $nearby = []; if($entity === null or $entity->canCollide){ - $minX = Math::ceilFloat(($bb->minX - 2) / 16); + $minX = Math::floorFloat(($bb->minX - 2) / 16); $maxX = Math::ceilFloat(($bb->maxX + 2) / 16); - $minZ = Math::ceilFloat(($bb->minZ - 2) / 16); + $minZ = Math::floorFloat(($bb->minZ - 2) / 16); $maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16); for($x = $minX; $x <= $maxX; ++$x){ @@ -1522,9 +1522,9 @@ class Level implements ChunkManager, Metadatable{ public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){ $nearby = []; - $minX = Math::ceilFloat(($bb->minX - 2) / 16); + $minX = Math::floorFloat(($bb->minX - 2) / 16); $maxX = Math::ceilFloat(($bb->maxX + 2) / 16); - $minZ = Math::ceilFloat(($bb->minZ - 2) / 16); + $minZ = Math::floorFloat(($bb->minZ - 2) / 16); $maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16); for($x = $minX; $x <= $maxX; ++$x){