mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
Merge branch 'api3/network' into api3/network-mcpe-1.1
This commit is contained in:
@ -165,6 +165,10 @@ class Attribute{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function resetToDefault(){
|
||||
$this->setValue($this->getDefaultValue());
|
||||
}
|
||||
|
||||
public function getValue(){
|
||||
return $this->currentValue;
|
||||
}
|
||||
|
@ -38,6 +38,9 @@ class AttributeMap implements \ArrayAccess{
|
||||
return $this->attributes[$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attribute[]
|
||||
*/
|
||||
public function getAll(): array{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
@ -373,6 +373,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false;
|
||||
|
||||
$this->attributeMap = new AttributeMap();
|
||||
$this->addAttributes();
|
||||
|
||||
$this->chunk->addEntity($this);
|
||||
$this->level->addEntity($this);
|
||||
@ -710,8 +711,6 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
$this->scheduleUpdate();
|
||||
|
||||
$this->addAttributes();
|
||||
|
||||
if(isset($this->namedtag->ActiveEffects)){
|
||||
foreach($this->namedtag->ActiveEffects->getValue() as $e){
|
||||
$amplifier = $e["Amplifier"] & 0xff; //0-255 only
|
||||
@ -1179,7 +1178,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
//return !($this instanceof Player);
|
||||
}
|
||||
|
||||
public final function scheduleUpdate(){
|
||||
final public function scheduleUpdate(){
|
||||
$this->level->updateEntities[$this->id] = $this;
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
$this->skinId = $skinId;
|
||||
}
|
||||
|
||||
public function jump(){
|
||||
parent::jump();
|
||||
if($this->isSprinting()){
|
||||
$this->exhaust(0.8, PlayerExhaustEvent::CAUSE_SPRINT_JUMPING);
|
||||
}else{
|
||||
$this->exhaust(0.2, PlayerExhaustEvent::CAUSE_JUMPING);
|
||||
}
|
||||
}
|
||||
|
||||
public function getFood() : float{
|
||||
return $this->attributeMap->getAttribute(Attribute::HUNGER)->getValue();
|
||||
}
|
||||
@ -355,31 +364,35 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
if($this->isAlive()){
|
||||
$food = $this->getFood();
|
||||
$health = $this->getHealth();
|
||||
if($food >= 18){
|
||||
$this->foodTickTimer++;
|
||||
if($this->foodTickTimer >= 80 and $health < $this->getMaxHealth()){
|
||||
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
|
||||
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
|
||||
$this->foodTickTimer = 0;
|
||||
$difficulty = $this->server->getDifficulty();
|
||||
|
||||
$this->foodTickTimer++;
|
||||
if($this->foodTickTimer >= 80){
|
||||
$this->foodTickTimer = 0;
|
||||
}
|
||||
|
||||
if($difficulty === 0 and $this->foodTickTimer % 10 === 0){ //Peaceful
|
||||
if($food < 20){
|
||||
$this->addFood(1.0);
|
||||
}
|
||||
}elseif($food === 0){
|
||||
$this->foodTickTimer++;
|
||||
if($this->foodTickTimer >= 80){
|
||||
$diff = $this->server->getDifficulty();
|
||||
$can = false;
|
||||
if($diff === 1){
|
||||
$can = $health > 10;
|
||||
}elseif($diff === 2){
|
||||
$can = $health > 1;
|
||||
}elseif($diff === 3){
|
||||
$can = true;
|
||||
if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){
|
||||
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
|
||||
}
|
||||
}
|
||||
|
||||
if($this->foodTickTimer === 0){
|
||||
if($food >= 18){
|
||||
if($health < $this->getMaxHealth()){
|
||||
$this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION));
|
||||
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
|
||||
}
|
||||
if($can){
|
||||
}elseif($food <= 0){
|
||||
if(($difficulty === 1 and $health > 10) or ($difficulty === 2 and $health > 1) or $difficulty === 3){
|
||||
$this->attack(1, new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($food <= 6){
|
||||
if($this->isSprinting()){
|
||||
$this->setSprinting(false);
|
||||
|
@ -43,6 +43,8 @@ abstract class Living extends Entity implements Damageable{
|
||||
|
||||
protected $invisible = false;
|
||||
|
||||
protected $jumpVelocity = 0.42;
|
||||
|
||||
protected function initEntity(){
|
||||
parent::initEntity();
|
||||
|
||||
@ -68,7 +70,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
public function setHealth($amount){
|
||||
$wasAlive = $this->isAlive();
|
||||
parent::setHealth($amount);
|
||||
$this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth());
|
||||
$this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth(), true);
|
||||
if($this->isAlive() and !$wasAlive){
|
||||
$pk = new EntityEventPacket();
|
||||
$pk->eid = $this->getId();
|
||||
@ -98,7 +100,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->namedtag->Health = new ShortTag("Health", $this->getHealth());
|
||||
}
|
||||
|
||||
public abstract function getName();
|
||||
abstract public function getName();
|
||||
|
||||
public function hasLineOfSight(Entity $entity){
|
||||
//TODO: head height
|
||||
@ -115,6 +117,23 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->attackTime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the initial upwards velocity of a jumping entity in blocks/tick, including additional velocity due to effects.
|
||||
* @return float
|
||||
*/
|
||||
public function getJumpVelocity() : float{
|
||||
return $this->jumpVelocity + ($this->hasEffect(Effect::JUMP) ? (($this->getEffect(Effect::JUMP)->getAmplifier() + 1) / 10) : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the entity jumps from the ground. This method adds upwards velocity to the entity.
|
||||
*/
|
||||
public function jump(){
|
||||
if($this->onGround){
|
||||
$this->motionY = $this->getJumpVelocity(); //Y motion should already be 0 if we're jumping from the ground.
|
||||
}
|
||||
}
|
||||
|
||||
public function attack($damage, EntityDamageEvent $source){
|
||||
if($this->attackTime > 0 or $this->noDamageTicks > 0){
|
||||
$lastCause = $this->getLastDamageCause();
|
||||
@ -183,6 +202,10 @@ abstract class Living extends Entity implements Damageable{
|
||||
return;
|
||||
}
|
||||
parent::kill();
|
||||
$this->callDeathEvent();
|
||||
}
|
||||
|
||||
protected function callDeathEvent(){
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops()));
|
||||
foreach($ev->getDrops() as $item){
|
||||
$this->getLevel()->dropItem($this, $item);
|
||||
|
@ -43,8 +43,8 @@ class Squid extends WaterAnimal implements Ageable{
|
||||
private $switchDirectionTicker = 0;
|
||||
|
||||
public function initEntity(){
|
||||
$this->setMaxHealth(10);
|
||||
parent::initEntity();
|
||||
$this->setMaxHealth(5);
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
|
Reference in New Issue
Block a user