mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 04:00:29 +00:00
Merge branch 'mcpe-0.11'
This commit is contained in:
@@ -48,10 +48,11 @@ use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Double;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\nbt\tag\Float;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\Short;
|
||||
use pocketmine\nbt\tag\String;
|
||||
use pocketmine\Network;
|
||||
use pocketmine\network\protocol\MovePlayerPacket;
|
||||
use pocketmine\network\protocol\MobEffectPacket;
|
||||
use pocketmine\network\protocol\RemoveEntityPacket;
|
||||
use pocketmine\network\protocol\SetEntityDataPacket;
|
||||
use pocketmine\network\protocol\SetTimePacket;
|
||||
@@ -65,6 +66,32 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
const NETWORK_ID = -1;
|
||||
|
||||
|
||||
const DATA_TYPE_BYTE = 0;
|
||||
const DATA_TYPE_SHORT = 1;
|
||||
const DATA_TYPE_INT = 2;
|
||||
const DATA_TYPE_FLOAT = 3;
|
||||
const DATA_TYPE_STRING = 4;
|
||||
const DATA_TYPE_SLOT = 5;
|
||||
const DATA_TYPE_POS = 6;
|
||||
const DATA_TYPE_ROTATION = 7;
|
||||
const DATA_TYPE_LONG = 8;
|
||||
|
||||
const DATA_FLAGS = 0;
|
||||
const DATA_AIR = 1;
|
||||
const DATA_SHOW_NAMETAG = 3;
|
||||
const DATA_POTION_COLOR = 7;
|
||||
const DATA_POTION_VISIBLE = 8;
|
||||
const DATA_NO_AI = 15;
|
||||
|
||||
|
||||
const DATA_FLAG_ONFIRE = 0;
|
||||
const DATA_FLAG_SNEAKING = 1;
|
||||
const DATA_FLAG_RIDING = 2;
|
||||
const DATA_FLAG_ACTION = 4;
|
||||
const DATA_FLAG_INVISIBLE = 5;
|
||||
|
||||
|
||||
public static $entityCount = 1;
|
||||
/** @var Entity[] */
|
||||
private static $knownEntities = [];
|
||||
@@ -75,8 +102,18 @@ abstract class Entity extends Location implements Metadatable{
|
||||
*/
|
||||
protected $hasSpawned = [];
|
||||
|
||||
/** @var Effect[] */
|
||||
protected $effects = [];
|
||||
|
||||
protected $id;
|
||||
|
||||
protected $dataFlags = 0;
|
||||
protected $dataProperties = [
|
||||
self::DATA_FLAGS => [self::DATA_TYPE_BYTE, 0],
|
||||
self::DATA_SHOW_NAMETAG => [self::DATA_TYPE_BYTE, 1],
|
||||
self::DATA_AIR => [self::DATA_TYPE_SHORT, 300]
|
||||
];
|
||||
|
||||
public $passenger = null;
|
||||
public $vehicle = null;
|
||||
|
||||
@@ -134,7 +171,6 @@ abstract class Entity extends Location implements Metadatable{
|
||||
public $lastUpdate;
|
||||
public $maxFireTicks;
|
||||
public $fireTicks;
|
||||
public $airTicks;
|
||||
public $namedtag;
|
||||
public $canCollide = true;
|
||||
|
||||
@@ -206,7 +242,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if(!isset($this->namedtag->Air)){
|
||||
$this->namedtag->Air = new Short("Air", 300);
|
||||
}
|
||||
$this->airTicks = $this->namedtag["Air"];
|
||||
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"]);
|
||||
|
||||
if(!isset($this->namedtag->OnGround)){
|
||||
$this->namedtag->OnGround = new Byte("OnGround", 0);
|
||||
@@ -228,6 +264,87 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Effect[]
|
||||
*/
|
||||
public function getEffects(){
|
||||
return $this->effects;
|
||||
}
|
||||
|
||||
public function removeAllEffects(){
|
||||
foreach($this->effects as $effect){
|
||||
$this->removeEffect($effect->getId());
|
||||
}
|
||||
}
|
||||
|
||||
public function removeEffect($effectId){
|
||||
if(isset($this->effects[$effectId])){
|
||||
$effect = $this->effects[$effectId];
|
||||
unset($this->effects[$effectId]);
|
||||
$effect->remove($this);
|
||||
|
||||
$this->recalculateEffectColor();
|
||||
}
|
||||
}
|
||||
|
||||
public function getEffect($effectId){
|
||||
return isset($this->effects[$effectId]) ? $this->effects[$effectId] : null;
|
||||
}
|
||||
|
||||
public function hasEffect($effectId){
|
||||
return isset($this->effects[$effectId]);
|
||||
}
|
||||
|
||||
public function addEffect(Effect $effect){
|
||||
if(isset($this->effects[$effect->getId()])){
|
||||
$oldEffect = $this->effects[$effect->getId()];
|
||||
if(
|
||||
$effect->getAmplifier() <= $oldEffect->getAmplifier()
|
||||
or ($effect->getAmplifier() === $oldEffect->getAmplifier()
|
||||
and $effect->getDuration() < $oldEffect->getDuration())
|
||||
){
|
||||
return;
|
||||
}
|
||||
$effect->add($this, true);
|
||||
}else{
|
||||
$effect->add($this, false);
|
||||
}
|
||||
|
||||
$this->effects[$effect->getId()] = $effect;
|
||||
|
||||
$this->recalculateEffectColor();
|
||||
}
|
||||
|
||||
protected function recalculateEffectColor(){
|
||||
$color = [0, 0, 0]; //RGB
|
||||
$count = 0;
|
||||
$ambient = true;
|
||||
foreach($this->effects as $effect){
|
||||
if($effect->isVisible()){
|
||||
$c = $effect->getColor();
|
||||
$color[0] += $c[0] * ($effect->getAmplifier() + 1);
|
||||
$color[1] += $c[1] * ($effect->getAmplifier() + 1);
|
||||
$color[2] += $c[2] * ($effect->getAmplifier() + 1);
|
||||
$count += $effect->getAmplifier() + 1;
|
||||
if(!$effect->isAmbient()){
|
||||
$ambient = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($count > 0){
|
||||
$r = ($color[0] / $count) & 0xff;
|
||||
$g = ($color[1] / $count) & 0xff;
|
||||
$b = ($color[2] / $count) & 0xff;
|
||||
|
||||
$this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, ($r << 16) + ($g << 8) + $b);
|
||||
$this->setDataProperty(Entity::DATA_POTION_VISIBLE, Entity::DATA_TYPE_BYTE, $ambient ? 1 : 0);
|
||||
}else{
|
||||
$this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, 0);
|
||||
$this->setDataProperty(Entity::DATA_POTION_VISIBLE, Entity::DATA_TYPE_BYTE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|string $type
|
||||
* @param FullChunk $chunk
|
||||
@@ -295,12 +412,42 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
$this->namedtag->FallDistance = new Float("FallDistance", $this->fallDistance);
|
||||
$this->namedtag->Fire = new Short("Fire", $this->fireTicks);
|
||||
$this->namedtag->Air = new Short("Air", $this->airTicks);
|
||||
$this->namedtag->Air = new Short("Air", $this->getDataProperty(self::DATA_AIR));
|
||||
$this->namedtag->OnGround = new Byte("OnGround", $this->onGround == true ? 1 : 0);
|
||||
$this->namedtag->Invulnerable = new Byte("Invulnerable", $this->invulnerable == true ? 1 : 0);
|
||||
|
||||
if(count($this->effects) > 0){
|
||||
$effects = [];
|
||||
foreach($this->effects as $effect){
|
||||
$effects[$effect->getId()] = new Compound($effect->getId(), [
|
||||
"Id" => new Byte("Id", $effect->getId()),
|
||||
"Amplifier" => new Byte("Amplifier", $effect->getAmplifier()),
|
||||
"Duration" => new Int("Duration", $effect->getDuration()),
|
||||
"Ambient" => new Byte("Ambient", 0),
|
||||
"ShowParticles" => new Byte("ShowParticles", $effect->isVisible() ? 1 : 0)
|
||||
]);
|
||||
}
|
||||
|
||||
$this->namedtag->ActiveEffects = new Enum("ActiveEffects", $effects);
|
||||
}else{
|
||||
unset($this->namedtag->ActiveEffects);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract function initEntity();
|
||||
protected function initEntity(){
|
||||
if(isset($this->namedtag->ActiveEffects)){
|
||||
foreach($this->namedtag->ActiveEffects->getValue() as $e){
|
||||
$effect = Effect::getEffect($e["Id"]);
|
||||
if($effect === null){
|
||||
continue;
|
||||
}
|
||||
|
||||
$effect->setAmplifier($e["Amplifier"])->setDuration($e["Duration"])->setVisible($e["ShowParticles"] > 0);
|
||||
|
||||
$this->addEffect($effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Player[]
|
||||
@@ -318,30 +465,40 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
public function sendPotionEffects(Player $player){
|
||||
foreach($this->effects as $effect){
|
||||
$pk = new MobEffectPacket();
|
||||
$pk->eid = $this->getId();
|
||||
$pk->effectId = $effect->getId();
|
||||
$pk->amplifier = $effect->getAmplifier();
|
||||
$pk->particles = $effect->isVisible();
|
||||
$pk->duration = $effect->getDuration();
|
||||
$pk->eventId = MobEffectPacket::EVENT_ADD;
|
||||
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player[]|Player $player
|
||||
* @deprecated
|
||||
*/
|
||||
public function sendMetadata($player){
|
||||
$this->sendData($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player[]|Player $player
|
||||
* @param array $data Properly formatted entity data, defaults to everything
|
||||
*/
|
||||
public function sendData($player, array $data = null){
|
||||
if($player instanceof Player){
|
||||
$player = [$player];
|
||||
}
|
||||
|
||||
$pk = new SetEntityDataPacket();
|
||||
$pk->eid = $this->id;
|
||||
$pk->metadata = $this->getData();
|
||||
$pk->encode();
|
||||
$pk->isEncoded = true;
|
||||
foreach($player as $p){
|
||||
if($p === $this){
|
||||
/** @var Player $p */
|
||||
$pk2 = new SetEntityDataPacket();
|
||||
$pk2->eid = 0;
|
||||
$pk2->metadata = $this->getData();
|
||||
$p->dataPacket($pk2);
|
||||
}else{
|
||||
$p->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
$pk->metadata = $data === null ? $this->dataProperties : $data;
|
||||
Server::broadcastPacket($player, $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -357,18 +514,41 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $damage
|
||||
* @param int|EntityDamageEvent $source
|
||||
* @param float $damage
|
||||
* @param EntityDamageEvent $source
|
||||
*
|
||||
*/
|
||||
abstract function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC);
|
||||
public function attack($damage, EntityDamageEvent $source){
|
||||
if($this->hasEffect(Effect::FIRE_RESISTANCE)
|
||||
and $source->getCause() === EntityDamageEvent::CAUSE_FIRE
|
||||
and $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK
|
||||
and $source->getCause() === EntityDamageEvent::CAUSE_LAVA){
|
||||
$source->setCancelled();
|
||||
}
|
||||
|
||||
$this->server->getPluginManager()->callEvent($source);
|
||||
if($source->isCancelled()){
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setLastDamageCause($source);
|
||||
|
||||
$this->setHealth($this->getHealth() - $source->getFinalDamage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
* @param int|EntityRegainHealthEvent $source
|
||||
* @param float $amount
|
||||
* @param EntityRegainHealthEvent $source
|
||||
*
|
||||
*/
|
||||
abstract function heal($amount, $source = EntityRegainHealthEvent::CAUSE_MAGIC);
|
||||
public function heal($amount, EntityRegainHealthEvent $source){
|
||||
$this->server->getPluginManager()->callEvent($source);
|
||||
if($source->isCancelled()){
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setHealth($this->getHealth() + $source->getAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
@@ -400,10 +580,10 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|EntityDamageEvent $type
|
||||
* @param EntityDamageEvent $type
|
||||
*/
|
||||
public function setLastDamageCause($type){
|
||||
$this->lastDamageCause = $type instanceof EntityDamageEvent ? $type : $type;
|
||||
public function setLastDamageCause(EntityDamageEvent $type){
|
||||
$this->lastDamageCause = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -433,29 +613,25 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
protected function checkObstruction($x, $y, $z){
|
||||
$i = (int) $x;
|
||||
$j = (int) $y;
|
||||
$k = (int) $z;
|
||||
$i = Math::floorFloat($x);
|
||||
$j = Math::floorFloat($y);
|
||||
$k = Math::floorFloat($z);
|
||||
|
||||
$diffX = $x - $i;
|
||||
$diffY = $y - $j;
|
||||
$diffZ = $z - $k;
|
||||
|
||||
$list = $this->level->getCollisionBlocks($this->boundingBox);
|
||||
|
||||
$v = new Vector3($i, $j, $k);
|
||||
|
||||
if(count($list) === 0 and !$this->level->isFullBlock($v->setComponents($i, $j, $k))){
|
||||
return false;
|
||||
}else{
|
||||
if($this->level->isFullBlock($v)){
|
||||
$flag = !$this->level->isFullBlock($v->setComponents($i - 1, $j, $k));
|
||||
$flag1 = !$this->level->isFullBlock($v->setComponents($i + 1, $j, $k));
|
||||
//$flag2 = !$this->level->isFullBlock($v->setComponents($i, $j - 1, $k));
|
||||
$flag2 = !$this->level->isFullBlock($v->setComponents($i, $j - 1, $k));
|
||||
$flag3 = !$this->level->isFullBlock($v->setComponents($i, $j + 1, $k));
|
||||
$flag4 = !$this->level->isFullBlock($v->setComponents($i, $j, $k - 1));
|
||||
$flag5 = !$this->level->isFullBlock($v->setComponents($i, $j, $k + 1));
|
||||
|
||||
$direction = 3; //UP!
|
||||
$direction = -1;
|
||||
$limit = 9999;
|
||||
|
||||
if($flag){
|
||||
@@ -468,6 +644,11 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$direction = 1;
|
||||
}
|
||||
|
||||
if($flag2 and $diffY < $limit){
|
||||
$limit = $diffY;
|
||||
$direction = 2;
|
||||
}
|
||||
|
||||
if($flag3 and 1 - $diffY < $limit){
|
||||
$limit = 1 - $diffY;
|
||||
$direction = 3;
|
||||
@@ -496,7 +677,11 @@ abstract class Entity extends Location implements Metadatable{
|
||||
return true;
|
||||
}
|
||||
|
||||
//No direction 2
|
||||
if($direction === 2){
|
||||
$this->motionY = -$force;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if($direction === 3){
|
||||
$this->motionY = $force;
|
||||
@@ -517,6 +702,8 @@ abstract class Entity extends Location implements Metadatable{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function entityBaseTick($tickDiff = 1){
|
||||
@@ -528,6 +715,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$isPlayer = $this instanceof Player;
|
||||
|
||||
if($this->dead === true){
|
||||
$this->removeAllEffects();
|
||||
$this->despawnFromAll();
|
||||
if(!$isPlayer){
|
||||
$this->close();
|
||||
@@ -537,6 +725,18 @@ abstract class Entity extends Location implements Metadatable{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(count($this->effects) > 0){
|
||||
foreach($this->effects as $effect){
|
||||
if($effect->canTick()){
|
||||
$effect->applyEffect($this);
|
||||
}
|
||||
$effect->setDuration($effect->getDuration() - $tickDiff);
|
||||
if($effect->getDuration() <= 0){
|
||||
$this->removeEffect($effect->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$hasUpdate = false;
|
||||
|
||||
$this->checkBlockCollision();
|
||||
@@ -554,7 +754,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->fireTicks = 0;
|
||||
}
|
||||
}else{
|
||||
if(($this->fireTicks % 20) === 0 or $tickDiff > 20){
|
||||
if(!$this->hasEffect(Effect::FIRE_RESISTANCE) and ($this->fireTicks % 20) === 0 or $tickDiff > 20){
|
||||
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
|
||||
$this->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
@@ -564,6 +764,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if($this->fireTicks <= 0){
|
||||
$this->extinguish();
|
||||
}else{
|
||||
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, true);
|
||||
$hasUpdate = true;
|
||||
}
|
||||
}
|
||||
@@ -592,22 +793,11 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->lastYaw = $this->yaw;
|
||||
$this->lastPitch = $this->pitch;
|
||||
|
||||
if($this instanceof Human){
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk->eid = $this->id;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$pk->bodyYaw = $this->yaw;
|
||||
Server::broadcastPacket($this->hasSpawned, $pk);
|
||||
}else{
|
||||
if(!($this instanceof Player)){
|
||||
foreach($this->hasSpawned as $player){
|
||||
$player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch);
|
||||
$player->addEntityMovement($this->id, $this->x, $this->y + $this->height, $this->z, $this->yaw, $this->pitch, $this->yaw);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(($this->lastMotionX != $this->motionX or $this->lastMotionY != $this->motionY or $this->lastMotionZ != $this->motionZ)){
|
||||
@@ -669,11 +859,6 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if($ticks > $this->fireTicks){
|
||||
$this->fireTicks = $ticks;
|
||||
}
|
||||
|
||||
$this->sendMetadata($this->hasSpawned);
|
||||
if($this instanceof Player){
|
||||
$this->sendMetadata($this);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDirection(){
|
||||
@@ -696,10 +881,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
public function extinguish(){
|
||||
$this->fireTicks = 0;
|
||||
$this->sendMetadata($this->hasSpawned);
|
||||
if($this instanceof Player){
|
||||
$this->sendMetadata($this);
|
||||
}
|
||||
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, false);
|
||||
}
|
||||
|
||||
public function canTriggerWalking(){
|
||||
@@ -827,7 +1009,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
$newBB = $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz);
|
||||
|
||||
$list = $this->level->getCollisionCubes($this, $newBB->expand(-0.01, -0.01, -0.01));
|
||||
$list = $this->level->getCollisionCubes($this, $newBB->grow(-0.01, -0.01, -0.01), false);
|
||||
|
||||
if(count($list) === 0){
|
||||
$this->boundingBox = $newBB;
|
||||
@@ -835,7 +1017,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
$pos = new Vector3(
|
||||
($this->boundingBox->minX + $this->boundingBox->maxX) / 2,
|
||||
$this->boundingBox->minY + $this->ySize,
|
||||
$this->boundingBox->minY,
|
||||
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2
|
||||
);
|
||||
|
||||
@@ -924,8 +1106,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
//TODO: big messy loop
|
||||
}*/
|
||||
|
||||
$list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz));
|
||||
|
||||
$list = $this->level->getCollisionCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
|
||||
|
||||
foreach($list as $bb){
|
||||
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
||||
@@ -933,12 +1114,6 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
$this->boundingBox->offset(0, $dy, 0);
|
||||
|
||||
if($movY != $dy){
|
||||
$dx = 0;
|
||||
$dy = 0;
|
||||
$dz = 0;
|
||||
}
|
||||
|
||||
$fallingFlag = ($this->onGround or ($dy != $movY and $movY < 0));
|
||||
|
||||
foreach($list as $bb){
|
||||
@@ -947,24 +1122,12 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
$this->boundingBox->offset($dx, 0, 0);
|
||||
|
||||
if($movX != $dx){
|
||||
$dx = 0;
|
||||
$dy = 0;
|
||||
$dz = 0;
|
||||
}
|
||||
|
||||
foreach($list as $bb){
|
||||
$dz = $bb->calculateZOffset($this->boundingBox, $dz);
|
||||
}
|
||||
|
||||
$this->boundingBox->offset(0, 0, $dz);
|
||||
|
||||
if($movZ != $dz){
|
||||
$dx = 0;
|
||||
$dy = 0;
|
||||
$dz = 0;
|
||||
}
|
||||
|
||||
|
||||
if($this->stepHeight > 0 and $fallingFlag and $this->ySize < 0.05 and ($movX != $dx or $movZ != $dz)){
|
||||
$cx = $dx;
|
||||
@@ -978,7 +1141,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
$this->boundingBox->setBB($axisalignedbb);
|
||||
|
||||
$list = $this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz), false);
|
||||
$list = $this->level->getCollisionCubes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
|
||||
|
||||
foreach($list as $bb){
|
||||
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
||||
@@ -991,34 +1154,12 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
$this->boundingBox->offset($dx, 0, 0);
|
||||
if($movX != $dx){
|
||||
$dx = 0;
|
||||
$dy = 0;
|
||||
$dz = 0;
|
||||
}
|
||||
|
||||
foreach($list as $bb){
|
||||
$dz = $bb->calculateZOffset($this->boundingBox, $dz);
|
||||
}
|
||||
|
||||
$this->boundingBox->offset(0, 0, $dz);
|
||||
if($movZ != $dz){
|
||||
$dx = 0;
|
||||
$dy = 0;
|
||||
$dz = 0;
|
||||
}
|
||||
|
||||
if($dy == 0){
|
||||
$dx = 0;
|
||||
$dy = 0;
|
||||
$dz = 0;
|
||||
}else{
|
||||
$dy = -$this->stepHeight;
|
||||
foreach($list as $bb){
|
||||
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
||||
}
|
||||
$this->boundingBox->offset(0, $dy, 0);
|
||||
}
|
||||
|
||||
if(($cx ** 2 + $cz ** 2) >= ($dx ** 2 + $dz ** 2)){
|
||||
$dx = $cx;
|
||||
@@ -1026,11 +1167,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$dz = $cz;
|
||||
$this->boundingBox->setBB($axisalignedbb1);
|
||||
}else{
|
||||
$diff = $this->boundingBox->minY - (int) $this->boundingBox->minY;
|
||||
|
||||
if($diff > 0){
|
||||
$this->ySize += $diff + 0.01;
|
||||
}
|
||||
$this->ySize += 0.5;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1204,7 +1341,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
if(!$this->justCreated){
|
||||
if($this instanceof Player){
|
||||
$this->addEntityMotion(0, $this->motionX, $this->motionY, $this->motionZ);
|
||||
$this->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ);
|
||||
}
|
||||
$this->updateMovement();
|
||||
}
|
||||
@@ -1259,7 +1396,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->lastPitch = $this->pitch;
|
||||
|
||||
foreach($this->hasSpawned as $player){
|
||||
$player->addEntityMovement($this->getId(), $this->x, $this->y, $this->z, $this->yaw, $this->pitch);
|
||||
$player->addEntityMovement($this->getId(), $this->x, $this->y + $this->height, $this->z, $this->yaw, $this->pitch, $this->yaw);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1300,7 +1437,67 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
abstract public function getData();
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $type
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setDataProperty($id, $type, $value){
|
||||
if($this->getDataProperty($id) !== $value){
|
||||
$this->dataProperties[$id] = [$type, $value];
|
||||
|
||||
$targets = $this->hasSpawned;
|
||||
if($this instanceof Player){
|
||||
if(!$this->spawned){
|
||||
return;
|
||||
}
|
||||
$targets[] = $this;
|
||||
}
|
||||
|
||||
$this->sendData($targets, [$id => $this->dataProperties[$id]]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDataProperty($id){
|
||||
return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][1] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDataPropertyType($id){
|
||||
return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propertyId;
|
||||
* @param int $id
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setDataFlag($propertyId, $id, $value = true, $type = self::DATA_TYPE_BYTE){
|
||||
if($this->getDataFlag($propertyId, $id) !== $value){
|
||||
$flags = (int) $this->getDataProperty($propertyId);
|
||||
$flags ^= 1 << $id;
|
||||
$this->setDataProperty($propertyId, $type, $flags);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propertyId
|
||||
* @param int $id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getDataFlag($propertyId, $id){
|
||||
return (((int) $this->getDataProperty($propertyId)) & (1 << $id)) > 0;
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
|
Reference in New Issue
Block a user