mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 06:55:29 +00:00
Fix #1615
Players in creative cannot die from non-magic (plugin/console) causes.
This commit is contained in:
parent
167ee97569
commit
a8359f29a8
@ -34,73 +34,76 @@ use pocketmine\item\Item;
|
|||||||
|
|
||||||
abstract class Living extends Entity implements Damageable{
|
abstract class Living extends Entity implements Damageable{
|
||||||
|
|
||||||
protected $gravity = 0.08;
|
protected $gravity = 0.08;
|
||||||
protected $drag = 0.02;
|
protected $drag = 0.02;
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
if(isset($this->namedtag->HealF)){
|
if(isset($this->namedtag->HealF)){
|
||||||
$this->namedtag->Health = new Short("Health", (int) $this->namedtag["HealF"]);
|
$this->namedtag->Health = new Short("Health", (int) $this->namedtag["HealF"]);
|
||||||
unset($this->namedtag->HealF);
|
unset($this->namedtag->HealF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->namedtag->Health) or !($this->namedtag->Health instanceof Short)){
|
if(!isset($this->namedtag->Health) or !($this->namedtag->Health instanceof Short)){
|
||||||
$this->namedtag->Health = new Short("Health", $this->getMaxHealth());
|
$this->namedtag->Health = new Short("Health", $this->getMaxHealth());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setHealth($this->namedtag["Health"]);
|
$this->setHealth($this->namedtag["Health"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT(){
|
public function saveNBT(){
|
||||||
parent::saveNBT();
|
parent::saveNBT();
|
||||||
$this->namedtag->Health = new Short("Health", $this->getHealth());
|
$this->namedtag->Health = new Short("Health", $this->getHealth());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract function getName();
|
public abstract function getName();
|
||||||
|
|
||||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||||
//TODO: attack tick limit
|
//TODO: attack tick limit
|
||||||
$pk = new EntityEventPacket();
|
if($this instanceof Player && $this->getGamemode() === 1 && $source != EntityDamageEvent::CAUSE_MAGIC) {
|
||||||
$pk->eid = $this->getID();
|
return;
|
||||||
$pk->event = 2; //Ouch!
|
}
|
||||||
Server::broadcastPacket($this->hasSpawned, $pk);
|
$pk = new EntityEventPacket();
|
||||||
$this->setLastDamageCause($source);
|
$pk->eid = $this->getID();
|
||||||
$motion = new Vector3(0, 0, 0);
|
$pk->event = 2; //Ouch!
|
||||||
if($source instanceof EntityDamageByEntityEvent){
|
Server::broadcastPacket($this->hasSpawned, $pk);
|
||||||
$e = $source->getDamager();
|
$this->setLastDamageCause($source);
|
||||||
$deltaX = $this->x - $e->x;
|
$motion = new Vector3(0, 0, 0);
|
||||||
$deltaZ = $this->z - $e->z;
|
if($source instanceof EntityDamageByEntityEvent){
|
||||||
$yaw = atan2($deltaX, $deltaZ);
|
$e = $source->getDamager();
|
||||||
$motion->x = sin($yaw) * 0.5;
|
$deltaX = $this->x - $e->x;
|
||||||
$motion->z = cos($yaw) * 0.5;
|
$deltaZ = $this->z - $e->z;
|
||||||
}
|
$yaw = atan2($deltaX, $deltaZ);
|
||||||
$this->setMotion($motion);
|
$motion->x = sin($yaw) * 0.5;
|
||||||
$this->setHealth($this->getHealth() - $damage);
|
$motion->z = cos($yaw) * 0.5;
|
||||||
|
}
|
||||||
|
$this->setMotion($motion);
|
||||||
|
$this->setHealth($this->getHealth() - $damage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function heal($amount){
|
public function heal($amount){
|
||||||
$this->server->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($this, $amount));
|
$this->server->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($this, $amount));
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->setHealth($this->getHealth() + $amount);
|
$this->setHealth($this->getHealth() + $amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function kill(){
|
public function kill(){
|
||||||
if($this->dead){
|
if($this->dead){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parent::kill();
|
parent::kill();
|
||||||
$this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops()));
|
$this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops()));
|
||||||
foreach($ev->getDrops() as $item){
|
foreach($ev->getDrops() as $item){
|
||||||
$this->getLevel()->dropItem($this, $item);
|
$this->getLevel()->dropItem($this, $item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Item[]
|
* @return Item[]
|
||||||
*/
|
*/
|
||||||
public function getDrops(){
|
public function getDrops(){
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user