mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Improved entity base ticks
This commit is contained in:
parent
fde61b7d21
commit
b0bd927545
@ -40,6 +40,7 @@ class Lava extends Liquid{
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->fallDistance *= 0.5;
|
||||
$entity->setOnFire(15);
|
||||
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_LAVA, 4);
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev);
|
||||
|
@ -137,7 +137,6 @@ abstract class Entity extends Position implements Metadatable{
|
||||
protected $isStatic = false;
|
||||
protected $isColliding = false;
|
||||
|
||||
protected $inWater;
|
||||
public $noDamageTicks;
|
||||
private $justCreated;
|
||||
protected $fireProof;
|
||||
@ -473,14 +472,6 @@ abstract class Entity extends Position implements Metadatable{
|
||||
|
||||
$this->checkBlockCollision();
|
||||
|
||||
if(!$isPlayer and $this->handleWaterMovement()){
|
||||
$this->fallDistance = 0;
|
||||
$this->inWater = true;
|
||||
$this->extinguish();
|
||||
}else{
|
||||
$this->inWater = false;
|
||||
}
|
||||
|
||||
if($this->y < 0 and $this->dead !== true){
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10));
|
||||
if(!$ev->isCancelled()){
|
||||
@ -512,13 +503,6 @@ abstract class Entity extends Position implements Metadatable{
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
if($this->handleLavaMovement()){
|
||||
//$this->attack(4, EntityDamageEvent::CAUSE_LAVA);
|
||||
//$this->setOnFire(15);
|
||||
$hasUpdate = true;
|
||||
$this->fallDistance *= 0.5;
|
||||
}
|
||||
|
||||
++$this->age;
|
||||
++$this->ticksLived;
|
||||
}
|
||||
@ -676,10 +660,6 @@ abstract class Entity extends Position implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
public function handleWaterMovement(){
|
||||
return $this->getLevel()->handleBlockAcceleration($this->boundingBox->grow(0, -0.4, 0)->shrink(0.001, 0.001, 0.001), Block::WATER, $this);
|
||||
}
|
||||
|
||||
public function handleLavaMovement(){ //TODO
|
||||
|
||||
}
|
||||
@ -997,16 +977,29 @@ abstract class Entity extends Position implements Metadatable{
|
||||
$maxY = Math::floorFloat($this->boundingBox->maxY + 0.001);
|
||||
$maxZ = Math::floorFloat($this->boundingBox->maxZ + 0.001);
|
||||
|
||||
$vector = new Vector3(0, 0, 0);
|
||||
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
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){
|
||||
$block->onEntityCollide($this);
|
||||
if(!($this instanceof Player)){
|
||||
$block->addVelocityToEntity($this, $vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($vector->length() > 0){
|
||||
$vector = $vector->normalize();
|
||||
$d = 0.014;
|
||||
$this->motionX += $vector->x * $d;
|
||||
$this->motionY += $vector->y * $d;
|
||||
$this->motionZ += $vector->z * $d;
|
||||
}
|
||||
}
|
||||
|
||||
public function setPositionAndRotation(Vector3 $pos, $yaw, $pitch, $force = false){
|
||||
|
@ -2041,51 +2041,6 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AxisAlignedBB $boundingBox
|
||||
* @param int $blockMaterial
|
||||
* @param Entity $entity
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function handleBlockAcceleration(AxisAlignedBB $boundingBox, $blockMaterial, Entity $entity){
|
||||
$minX = Math::floorFloat($boundingBox->minX);
|
||||
$minY = Math::floorFloat($boundingBox->minY);
|
||||
$minZ = Math::floorFloat($boundingBox->minZ);
|
||||
$maxX = Math::floorFloat($boundingBox->maxX + 1);
|
||||
$maxY = Math::floorFloat($boundingBox->maxY + 1);
|
||||
$maxZ = Math::floorFloat($boundingBox->maxZ + 1);
|
||||
|
||||
$vector = new Vector3(0, 0, 0);
|
||||
$flag = false;
|
||||
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$block = $this->getBlock(new Vector3($x, $y, $z));
|
||||
if($block !== null and $block->getID() === $blockMaterial){
|
||||
$d = $y + 1 - ($block instanceof Liquid ? $block->getFluidHeightPercent() : 1);
|
||||
if($maxY >= $d){
|
||||
$block->addVelocityToEntity($entity, $vector);
|
||||
$flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($vector->length() > 0){
|
||||
$vector = $vector->normalize();
|
||||
$d = 0.014;
|
||||
$entity->motionX += $vector->x * $d;
|
||||
$entity->motionY += $vector->y * $d;
|
||||
$entity->motionZ += $vector->z * $d;
|
||||
}
|
||||
|
||||
return $flag;
|
||||
}
|
||||
|
||||
|
||||
public function setMetadata($metadataKey, MetadataValue $metadataValue){
|
||||
$this->server->getPlayerMetadata()->setMetadata($this, $metadataKey, $metadataValue);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user