mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
Improved entity ticking
This commit is contained in:
parent
d53ba52d32
commit
de11cce154
@ -46,6 +46,8 @@ class DroppedItem extends Entity{
|
|||||||
protected $gravity = 0.04;
|
protected $gravity = 0.04;
|
||||||
protected $drag = 0.02;
|
protected $drag = 0.02;
|
||||||
|
|
||||||
|
public $canCollide = false;
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
$this->namedtag->id = new String("id", "Item");
|
$this->namedtag->id = new String("id", "Item");
|
||||||
$this->setMaxHealth(5);
|
$this->setMaxHealth(5);
|
||||||
@ -87,7 +89,7 @@ class DroppedItem extends Entity{
|
|||||||
|
|
||||||
$friction = 1 - $this->drag;
|
$friction = 1 - $this->drag;
|
||||||
|
|
||||||
if($this->onGround){
|
if($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)){
|
||||||
$friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction;
|
$friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +134,8 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
public $fireTicks;
|
public $fireTicks;
|
||||||
public $airTicks;
|
public $airTicks;
|
||||||
public $namedtag;
|
public $namedtag;
|
||||||
|
public $canCollide = true;
|
||||||
|
|
||||||
protected $isStatic = false;
|
protected $isStatic = false;
|
||||||
protected $isColliding = false;
|
protected $isColliding = false;
|
||||||
|
|
||||||
@ -555,7 +557,9 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$pk->entities = [
|
$pk->entities = [
|
||||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||||
];
|
];
|
||||||
Server::broadcastPacket($this->hasSpawned, $pk);
|
foreach($this->hasSpawned as $player){
|
||||||
|
$player->dataPacket($pk);
|
||||||
|
}
|
||||||
|
|
||||||
if($this instanceof Player){
|
if($this instanceof Player){
|
||||||
$this->motionX = 0;
|
$this->motionX = 0;
|
||||||
|
@ -43,6 +43,8 @@ class FallingBlock extends Entity{
|
|||||||
protected $drag = 0.02;
|
protected $drag = 0.02;
|
||||||
protected $blockId = 0;
|
protected $blockId = 0;
|
||||||
|
|
||||||
|
public $canCollide = false;
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
$this->namedtag->id = new String("id", "FallingSand");
|
$this->namedtag->id = new String("id", "FallingSand");
|
||||||
if(isset($this->namedtag->Tile)){
|
if(isset($this->namedtag->Tile)){
|
||||||
|
@ -728,7 +728,10 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
for($z = $minZ; $z < $maxZ; ++$z){
|
for($z = $minZ; $z < $maxZ; ++$z){
|
||||||
for($x = $minX; $x < $maxX; ++$x){
|
for($x = $minX; $x < $maxX; ++$x){
|
||||||
for($y = $minY - 1; $y < $maxY; ++$y){
|
for($y = $minY - 1; $y < $maxY; ++$y){
|
||||||
$this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
|
$block = $this->getBlock(new Vector3($x, $y, $z));
|
||||||
|
if(!($block instanceof Air)){
|
||||||
|
$block->collidesWithBB($bb, $collides);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -767,11 +770,13 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
|
|
||||||
$collides = [];
|
$collides = [];
|
||||||
|
|
||||||
//TODO: optimize this loop, check collision cube boundaries
|
|
||||||
for($z = $minZ; $z < $maxZ; ++$z){
|
for($z = $minZ; $z < $maxZ; ++$z){
|
||||||
for($x = $minX; $x < $maxX; ++$x){
|
for($x = $minX; $x < $maxX; ++$x){
|
||||||
for($y = $minY - 1; $y < $maxY; ++$y){
|
for($y = $minY - 1; $y < $maxY; ++$y){
|
||||||
$this->getBlock(new Vector3($x, $y, $z))->collidesWithBB($bb, $collides);
|
$block = $this->getBlock(new Vector3($x, $y, $z));
|
||||||
|
if(!($block instanceof Air)){
|
||||||
|
$block->collidesWithBB($bb, $collides);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1233,7 +1238,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the entities near the current one inside the AxisAlignedBB
|
* Returns the entities colliding the current one inside the AxisAlignedBB
|
||||||
*
|
*
|
||||||
* @param AxisAlignedBB $bb
|
* @param AxisAlignedBB $bb
|
||||||
* @param Entity $entity
|
* @param Entity $entity
|
||||||
@ -1243,10 +1248,11 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
public function getCollidingEntities(AxisAlignedBB $bb, Entity $entity = null){
|
public function getCollidingEntities(AxisAlignedBB $bb, Entity $entity = null){
|
||||||
$nearby = [];
|
$nearby = [];
|
||||||
|
|
||||||
$minX = ($bb->minX - 2) >> 4;
|
if($entity->canCollide){
|
||||||
$maxX = ($bb->maxX + 2) >> 4;
|
$minX = Math::floorFloat(($bb->minX - 2) / 16);
|
||||||
$minZ = ($bb->minZ - 2) >> 4;
|
$maxX = Math::floorFloat(($bb->maxX - 2) / 16);
|
||||||
$maxZ = ($bb->maxZ + 2) >> 4;
|
$minZ = Math::floorFloat(($bb->minZ - 2) / 16);
|
||||||
|
$maxZ = Math::floorFloat(($bb->maxZ - 2) / 16);
|
||||||
|
|
||||||
for($x = $minX; $x <= $maxX; ++$x){
|
for($x = $minX; $x <= $maxX; ++$x){
|
||||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||||
@ -1257,6 +1263,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $nearby;
|
return $nearby;
|
||||||
}
|
}
|
||||||
@ -1272,10 +1279,10 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){
|
public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){
|
||||||
$nearby = [];
|
$nearby = [];
|
||||||
|
|
||||||
$minX = ($bb->minX - 2) >> 4;
|
$minX = Math::floorFloat(($bb->minX - 2) / 16);
|
||||||
$maxX = ($bb->maxX + 2) >> 4;
|
$maxX = Math::floorFloat(($bb->maxX - 2) / 16);
|
||||||
$minZ = ($bb->minZ - 2) >> 4;
|
$minZ = Math::floorFloat(($bb->minZ - 2) / 16);
|
||||||
$maxZ = ($bb->maxZ + 2) >> 4;
|
$maxZ = Math::floorFloat(($bb->maxZ - 2) / 16);
|
||||||
|
|
||||||
for($x = $minX; $x <= $maxX; ++$x){
|
for($x = $minX; $x <= $maxX; ++$x){
|
||||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user