mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Fix a bunch of metadata bugs, fixed air ticking and added some new API methods
This commit is contained in:
parent
468b3e8d44
commit
2ffbb452bb
@ -1498,7 +1498,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
$this->inAirTicks = 0;
|
||||
}else{
|
||||
if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and $this->getDataProperty(self::DATA_NO_AI) !== 1){
|
||||
if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and !$this->isImmobile()){
|
||||
$expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks));
|
||||
$diff = ($this->speed->y - $expectedVelocity) ** 2;
|
||||
|
||||
@ -1708,6 +1708,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$this->sendAttributes(true);
|
||||
$this->setNameTagVisible(true);
|
||||
$this->setNameTagAlwaysVisible(true);
|
||||
|
||||
$this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [
|
||||
TextFormat::AQUA . $this->username . TextFormat::WHITE,
|
||||
|
@ -114,7 +114,6 @@ abstract class Entity extends Location implements Metadatable{
|
||||
const DATA_SILENT = 4;
|
||||
const DATA_POTION_COLOR = 7;
|
||||
const DATA_POTION_AMBIENT = 8;
|
||||
const DATA_NO_AI = 15;
|
||||
const DATA_LINKED_EID = 23;
|
||||
*/
|
||||
|
||||
@ -128,6 +127,9 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
const DATA_FLAG_CAN_SHOW_NAMETAG = 14;
|
||||
const DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15;
|
||||
const DATA_FLAG_IMMOBILE = 16;
|
||||
|
||||
const DATA_FLAG_NOT_UNDERWATER = 30; //Hide bubbles if not underwater
|
||||
|
||||
|
||||
public static $entityCount = 1;
|
||||
@ -151,9 +153,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
self::DATA_AIR => [self::DATA_TYPE_SHORT, 400],
|
||||
self::DATA_MAX_AIR => [self::DATA_TYPE_SHORT, 400],
|
||||
self::DATA_NAMETAG => [self::DATA_TYPE_STRING, ""],
|
||||
//self::DATA_SHOW_NAMETAG => [self::DATA_TYPE_BYTE, 1],
|
||||
//self::DATA_SILENT => [self::DATA_TYPE_BYTE, 0],
|
||||
//self::DATA_NO_AI => [self::DATA_TYPE_BYTE, 0],
|
||||
self::DATA_LEAD_HOLDER_EID => [self::DATA_TYPE_LONG, -1],
|
||||
self::DATA_SCALE => [self::DATA_TYPE_FLOAT, 1],
|
||||
];
|
||||
@ -328,9 +328,17 @@ abstract class Entity extends Location implements Metadatable{
|
||||
* @return bool
|
||||
*/
|
||||
public function isNameTagVisible(){
|
||||
return $this->getDataProperty(self::DATA_SHOW_NAMETAG) > 0;
|
||||
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isNameTagAlwaysVisible(){
|
||||
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
@ -342,7 +350,14 @@ abstract class Entity extends Location implements Metadatable{
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setNameTagVisible($value = true){
|
||||
$this->setDataProperty(self::DATA_SHOW_NAMETAG, self::DATA_TYPE_BYTE, $value ? 1 : 0);
|
||||
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setNameTagAlwaysVisible($value = true){
|
||||
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value);
|
||||
}
|
||||
|
||||
public function isSneaking(){
|
||||
@ -365,6 +380,14 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
public function isImmobile() : bool{
|
||||
return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE);
|
||||
}
|
||||
|
||||
public function setImmobile($value = true) : bool{
|
||||
return $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Effect[]
|
||||
*/
|
||||
@ -612,14 +635,23 @@ abstract class Entity extends Location implements Metadatable{
|
||||
* @param array $data Properly formatted entity data, defaults to everything
|
||||
*/
|
||||
public function sendData($player, array $data = null){
|
||||
if(!is_array($player)){
|
||||
$player = [$player];
|
||||
}
|
||||
|
||||
$pk = new SetEntityDataPacket();
|
||||
$pk->eid = ($player === $this ? 0 : $this->getId());
|
||||
$pk->eid = $this->getId();
|
||||
$pk->metadata = $data === null ? $this->dataProperties : $data;
|
||||
|
||||
if(!is_array($player)){
|
||||
$player->dataPacket($pk);
|
||||
}else{
|
||||
Server::broadcastPacket($player, $pk);
|
||||
foreach($player as $p){
|
||||
if($p === $this){
|
||||
continue;
|
||||
}
|
||||
$p->dataPacket(clone $pk);
|
||||
}
|
||||
if($this instanceof Player){
|
||||
$pk->eid = 0;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,6 +178,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
|
||||
public function entityBaseTick($tickDiff = 1){
|
||||
Timings::$timerLivingEntityBaseTick->startTiming();
|
||||
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_NOT_UNDERWATER, !$this->isInsideOfWater());
|
||||
|
||||
$hasUpdate = parent::entityBaseTick($tickDiff);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user