mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
Fixed collision against other entities
This commit is contained in:
parent
61ce7f11d6
commit
a45f8782b1
@ -1204,7 +1204,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$hasUpdate = $this->entityBaseTick();
|
$hasUpdate = $this->entityBaseTick();
|
||||||
foreach($this->getLevel()->getCollidingEntities($this->boundingBox->expand(1.5, 1, 1.5), $this) as $entity){
|
foreach($this->getLevel()->getNearbyEntities($this->boundingBox->expand(1.5, 1, 1.5), $this) as $entity){
|
||||||
if($entity instanceof DroppedItem){
|
if($entity instanceof DroppedItem){
|
||||||
if($entity->dead !== true and $entity->getPickupDelay() <= 0){
|
if($entity->dead !== true and $entity->getPickupDelay() <= 0){
|
||||||
$item = $entity->getItem();
|
$item = $entity->getItem();
|
||||||
|
@ -46,7 +46,6 @@ class DroppedItem extends Entity{
|
|||||||
protected $drag = 0.02;
|
protected $drag = 0.02;
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
//TODO: upgrade old numeric entity ids
|
|
||||||
$this->namedtag->id = new String("id", "Item");
|
$this->namedtag->id = new String("id", "Item");
|
||||||
$this->setMaxHealth(5);
|
$this->setMaxHealth(5);
|
||||||
$this->setHealth(@$this->namedtag["Health"]);
|
$this->setHealth(@$this->namedtag["Health"]);
|
||||||
@ -150,6 +149,10 @@ class DroppedItem extends Entity{
|
|||||||
return $this->item;
|
return $this->item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function canCollideWith(Entity $entity){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
@ -277,6 +277,10 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$this->health = (int) min($this->health, $this->maxHealth);
|
$this->health = (int) min($this->health, $this->maxHealth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function canCollideWith(Entity $entity){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected function checkObstruction($x, $y, $z){
|
protected function checkObstruction($x, $y, $z){
|
||||||
$i = (int) $x;
|
$i = (int) $x;
|
||||||
$j = (int) $y;
|
$j = (int) $y;
|
||||||
|
@ -566,9 +566,9 @@ class Level{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: fix this
|
//TODO: fix this
|
||||||
/*foreach($entity->getNearbyEntities($bb->expand(0.25, 0.25, 0.25)) as $ent){
|
foreach($this->getCollidingEntities($bb->expand(0.25, 0.25, 0.25), $entity) as $ent){
|
||||||
$collides[] = $ent->boundingBox;
|
$collides[] = $ent->boundingBox;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
return $collides;
|
return $collides;
|
||||||
}
|
}
|
||||||
@ -842,7 +842,7 @@ class Level{
|
|||||||
//$face = -1;
|
//$face = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($hand->isSolid === true and $this->getCollidingEntities($hand->getBoundingBox())){
|
if($hand->isSolid === true and count($this->getCollidingEntities($hand->getBoundingBox())) > 0){
|
||||||
return false; //Entity in block
|
return false; //Entity in block
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -948,6 +948,37 @@ class Level{
|
|||||||
$minZ = ($bb->minZ - 2) >> 4;
|
$minZ = ($bb->minZ - 2) >> 4;
|
||||||
$maxZ = ($bb->maxZ + 2) >> 4;
|
$maxZ = ($bb->maxZ + 2) >> 4;
|
||||||
|
|
||||||
|
for($x = $minX; $x <= $maxX; ++$x){
|
||||||
|
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||||
|
if($this->isChunkLoaded($x, $z)){
|
||||||
|
foreach($this->getChunkEntities($x, $z) as $ent){
|
||||||
|
if($ent !== $entity and ($entity === null or ($ent->canCollideWith($entity) and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){
|
||||||
|
$nearby[] = $ent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nearby;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the entities near the current one inside the AxisAlignedBB
|
||||||
|
*
|
||||||
|
* @param AxisAlignedBB $bb
|
||||||
|
* @param Entity $entity
|
||||||
|
*
|
||||||
|
* @return Entity[]
|
||||||
|
*/
|
||||||
|
public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){
|
||||||
|
$nearby = [];
|
||||||
|
|
||||||
|
$minX = ($bb->minX - 2) >> 4;
|
||||||
|
$maxX = ($bb->maxX + 2) >> 4;
|
||||||
|
$minZ = ($bb->minZ - 2) >> 4;
|
||||||
|
$maxZ = ($bb->maxZ + 2) >> 4;
|
||||||
|
|
||||||
for($x = $minX; $x <= $maxX; ++$x){
|
for($x = $minX; $x <= $maxX; ++$x){
|
||||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||||
if($this->isChunkLoaded($x, $z)){
|
if($this->isChunkLoaded($x, $z)){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user