Fixed collision against other entities

This commit is contained in:
Shoghi Cervantes 2014-05-29 18:03:17 +02:00
parent 61ce7f11d6
commit a45f8782b1
4 changed files with 43 additions and 5 deletions

View File

@ -1204,7 +1204,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return true;
}
$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->dead !== true and $entity->getPickupDelay() <= 0){
$item = $entity->getItem();

View File

@ -46,7 +46,6 @@ class DroppedItem extends Entity{
protected $drag = 0.02;
protected function initEntity(){
//TODO: upgrade old numeric entity ids
$this->namedtag->id = new String("id", "Item");
$this->setMaxHealth(5);
$this->setHealth(@$this->namedtag["Health"]);
@ -150,6 +149,10 @@ class DroppedItem extends Entity{
return $this->item;
}
public function canCollideWith(Entity $entity){
return false;
}
/**
* @return int
*/

View File

@ -277,6 +277,10 @@ abstract class Entity extends Position implements Metadatable{
$this->health = (int) min($this->health, $this->maxHealth);
}
public function canCollideWith(Entity $entity){
return true;
}
protected function checkObstruction($x, $y, $z){
$i = (int) $x;
$j = (int) $y;

View File

@ -566,9 +566,9 @@ class Level{
}
//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;
}*/
}
return $collides;
}
@ -842,7 +842,7 @@ class Level{
//$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
}
@ -948,6 +948,37 @@ class Level{
$minZ = ($bb->minZ - 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($z = $minZ; $z <= $maxZ; ++$z){
if($this->isChunkLoaded($x, $z)){