Improved Living entity ticking

This commit is contained in:
Shoghi Cervantes 2014-10-11 17:35:13 +02:00
parent 6f1f201c41
commit 0af3dfedd5
10 changed files with 42 additions and 9 deletions

View File

@ -513,6 +513,7 @@ abstract class Block extends Position implements Metadatable{
protected $name = "Unknown";
protected $breakTime = 0.20;
protected $hardness = 10;
public $hasEntityCollision = false;
public $isActivable = false;
public $breakable = true;
public $isFlowable = false;

View File

@ -32,6 +32,9 @@ use pocketmine\Player;
use pocketmine\Server;
class Cactus extends Transparent{
public $hasEntityCollision = true;
public function __construct($meta = 0){
parent::__construct(self::CACTUS, $meta, "Cactus");
$this->isFullBlock = false;

View File

@ -25,6 +25,9 @@ use pocketmine\entity\Entity;
use pocketmine\item\Item;
class Cobweb extends Flowable{
public $hasEntityCollision = true;
public function __construct(){
parent::__construct(self::COBWEB, 0, "Cobweb");
$this->isSolid = true;

View File

@ -30,6 +30,9 @@ use pocketmine\level\Level;
use pocketmine\Server;
class Fire extends Flowable{
public $hasEntityCollision = true;
public function __construct($meta = 0){
parent::__construct(self::FIRE, $meta, "Fire");
$this->isReplaceable = true;

View File

@ -28,6 +28,9 @@ use pocketmine\math\AxisAlignedBB;
use pocketmine\Player;
class Ladder extends Transparent{
public $hasEntityCollision = true;
public function __construct($meta = 0){
parent::__construct(self::LADDER, $meta, "Ladder");
$this->isSolid = false;
@ -37,6 +40,7 @@ class Ladder extends Transparent{
public function onEntityCollide(Entity $entity){
$entity->fallDistance = 0;
$entity->onGround = true;
}
public function getBoundingBox(){

View File

@ -30,6 +30,7 @@ use pocketmine\Player;
use pocketmine\Server;
class Lava extends Liquid{
public function __construct($meta = 0){
parent::__construct(self::LAVA, $meta, "Lava");
$this->hardness = 0;

View File

@ -28,6 +28,8 @@ use pocketmine\level\Level;
use pocketmine\math\Vector3;
abstract class Liquid extends Transparent{
public $hasEntityCollision = true;
public $isLiquid = true;
public $breakable = false;
public $isReplaceable = true;

View File

@ -29,6 +29,9 @@ use pocketmine\math\AxisAlignedBB;
use pocketmine\Player;
class Vine extends Transparent{
public $hasEntityCollision = true;
public function __construct($meta = 0){
parent::__construct(self::VINE, $meta, "Vines");
$this->isSolid = false;

View File

@ -749,11 +749,17 @@ abstract class Entity extends Position implements Metadatable{
}
public function isInsideOfSolid(){
$blocks = [];
for($i = 0; $i < 8; ++$i){
$x = (($i % 2) - 0.5) * $this->width * 0.8;
$y = ((($i >> 1) % 2) - 0.5) * 0.1;
$z = ((($i >> 2) % 2) - 0.5) * $this->width * 0.8;
$block = $this->getLevel()->getBlock((new Vector3($this->x + $x, $this->y + $this->getEyeHeight() + $y, $this->z + $z))->floor());
$v = (new Vector3($this->x + $x, $this->y + $this->getEyeHeight() + $y, $this->z + $z))->floor();
$blocks["{$v->x}:{$v->y}:{$v->z}"] = $v;
}
foreach($blocks as $vector){
$block = $this->getLevel()->getBlock($vector);
$bb = $block->getBoundingBox();
@ -830,7 +836,7 @@ abstract class Entity extends Position implements Metadatable{
//TODO: big messy loop
}*/
$list = $this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz));
$list = $this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false);
foreach($list as $bb){
@ -884,7 +890,7 @@ abstract class Entity extends Position implements Metadatable{
$this->boundingBox->setBB($axisalignedbb);
$list = $this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($movX, $dy, $movZ));
$list = $this->getLevel()->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($movX, $dy, $movZ), false);
foreach($list as $bb){
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
@ -955,7 +961,9 @@ abstract class Entity extends Position implements Metadatable{
if($this instanceof Player){
if(($this->onGround and $movY != 0) or (!$this->onGround and $movY <= 0)){
if(count($this->getLevel()->getCollisionBlocks($this->boundingBox->getOffsetBoundingBox(0, $movY - 0.1, 0)->expand(0.01, 0, 0.01))) > 0){
$bb = clone $this->boundingBox;
$bb->maxY = $bb->minY + 0.5;
if(count($this->getLevel()->getCollisionBlocks($bb->expand(0.01, 0.01, 0.01))) > 0){
$isColliding = true;
}else{
$isColliding = false;
@ -1003,7 +1011,7 @@ abstract class Entity extends Position implements Metadatable{
for($x = $minX; $x <= $maxX; ++$x){
for($y = $minY; $y <= $maxY; ++$y){
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if($block !== null and $block->getID() > 0){
if($block !== null and $block->getID() > 0 and $block->hasEntityCollision){
$block->onEntityCollide($this);
if(!($this instanceof Player)){
$block->addVelocityToEntity($this, $vector);
@ -1013,7 +1021,7 @@ abstract class Entity extends Position implements Metadatable{
}
}
if($vector->length() > 0){
if(!($this instanceof Player) and $vector->length() > 0){
$vector = $vector->normalize();
$d = 0.014;
$this->motionX += $vector->x * $d;

View File

@ -756,10 +756,11 @@ class Level implements ChunkManager, Metadatable{
/**
* @param Entity $entity
* @param AxisAlignedBB $bb
* @param boolean $entities
*
* @return AxisAlignedBB[]
*/
public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb){
public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb, $entities = true){
$minX = Math::floorFloat($bb->minX);
$minY = Math::floorFloat($bb->minY);
$minZ = Math::floorFloat($bb->minZ);
@ -780,8 +781,10 @@ class Level implements ChunkManager, Metadatable{
}
}
foreach($this->getCollidingEntities($bb->grow(0.25, 0.25, 0.25), $entity) as $ent){
$collides[] = clone $ent->boundingBox;
if($entities){
foreach($this->getCollidingEntities($bb->grow(0.25, 0.25, 0.25), $entity) as $ent){
$collides[] = clone $ent->boundingBox;
}
}
return $collides;
@ -1690,6 +1693,8 @@ class Level implements ChunkManager, Metadatable{
}
unset($this->chunkSendQueue[$index]);
unset($this->chunkSendTasks[$index]);
}else{
var_dump("ARGH");
}
}