mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-05 17:41:46 +00:00
Added suffocation, drowning damage. Closes #1908
This commit is contained in:
parent
3ba099b309
commit
f0e7713dce
@ -28,4 +28,13 @@ class Liquid extends Transparent{
|
|||||||
public $isReplaceable = true;
|
public $isReplaceable = true;
|
||||||
public $isSolid = false;
|
public $isSolid = false;
|
||||||
public $isFullBlock = true;
|
public $isFullBlock = true;
|
||||||
|
|
||||||
|
public function getFluidHeightPercent(){
|
||||||
|
$d = $this->meta;
|
||||||
|
if($d >= 8){
|
||||||
|
$d = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($d + 1) / 9;
|
||||||
|
}
|
||||||
}
|
}
|
@ -21,17 +21,10 @@
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\entity\Entity;
|
|
||||||
|
|
||||||
class StillWater extends Water{
|
class StillWater extends Water{
|
||||||
public function __construct($meta = 0){
|
public function __construct($meta = 0){
|
||||||
Liquid::__construct(self::STILL_WATER, $meta, "Still Water");
|
Liquid::__construct(self::STILL_WATER, $meta, "Still Water");
|
||||||
$this->hardness = 500;
|
$this->hardness = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onEntityCollide(Entity $entity){
|
|
||||||
$entity->fallDistance = 0;
|
|
||||||
$entity->extinguish();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -25,6 +25,7 @@
|
|||||||
namespace pocketmine\entity;
|
namespace pocketmine\entity;
|
||||||
|
|
||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\block\Water;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\event\entity\EntityDespawnEvent;
|
use pocketmine\event\entity\EntityDespawnEvent;
|
||||||
use pocketmine\event\entity\EntityLevelChangeEvent;
|
use pocketmine\event\entity\EntityLevelChangeEvent;
|
||||||
@ -110,6 +111,9 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
protected $age = 0;
|
protected $age = 0;
|
||||||
|
|
||||||
public $height;
|
public $height;
|
||||||
|
|
||||||
|
public $eyeHeight = null;
|
||||||
|
|
||||||
public $width;
|
public $width;
|
||||||
public $length;
|
public $length;
|
||||||
|
|
||||||
@ -153,6 +157,10 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
throw new \Exception("Invalid garbage Chunk given to Entity");
|
throw new \Exception("Invalid garbage Chunk given to Entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->eyeHeight === null){
|
||||||
|
$this->eyeHeight = $this->height;
|
||||||
|
}
|
||||||
|
|
||||||
$this->id = Entity::$entityCount++;
|
$this->id = Entity::$entityCount++;
|
||||||
$this->justCreated = true;
|
$this->justCreated = true;
|
||||||
$this->namedtag = $nbt;
|
$this->namedtag = $nbt;
|
||||||
@ -674,7 +682,7 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getEyeHeight(){
|
public function getEyeHeight(){
|
||||||
return 0;
|
return $this->eyeHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function moveFlying(){ //TODO
|
public function moveFlying(){ //TODO
|
||||||
@ -726,6 +734,40 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
return new Position($this->x, $this->y, $this->z, $this->getLevel());
|
return new Position($this->x, $this->y, $this->z, $this->getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isInsideOfWater(){
|
||||||
|
$block = $this->getLevel()->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor());
|
||||||
|
|
||||||
|
if($block instanceof Water){
|
||||||
|
$f = ($pos->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
|
||||||
|
return $y < $f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isInsideOfSolid(){
|
||||||
|
for($i = 0; $i < 8; ++$i){
|
||||||
|
$x = (($i % 2) - 0.5) * $this->width * 0.8;
|
||||||
|
$y = ((($i >> 1) % 2) - 0.5) * 0.1;
|
||||||
|
$z = ((($i >> 2) % 2) - 0.5) * $this->width * 0.8;
|
||||||
|
$block = $this->getLevel()->getBlock((new Vector3($this->x + $x, $this->y + $this->getEyeHeight() + $y, $this->z + $z))->floor());
|
||||||
|
|
||||||
|
if($block->isSolid){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$block = $this->getLevel()->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor());
|
||||||
|
|
||||||
|
if($block instanceof Water){
|
||||||
|
$f = ($pos->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
|
||||||
|
return $y < $f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function collision(){
|
public function collision(){
|
||||||
$this->isColliding = true;
|
$this->isColliding = true;
|
||||||
$this->fallDistance = 0;
|
$this->fallDistance = 0;
|
||||||
|
@ -45,6 +45,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
public $width = 0.6;
|
public $width = 0.6;
|
||||||
public $length = 0.6;
|
public $length = 0.6;
|
||||||
public $height = 1.8;
|
public $height = 1.8;
|
||||||
|
public $eyeHeight = 1.62;
|
||||||
|
|
||||||
public function getInventory(){
|
public function getInventory(){
|
||||||
return $this->inventory;
|
return $this->inventory;
|
||||||
|
@ -116,6 +116,27 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
Timings::$timerEntityBaseTick->startTiming();
|
Timings::$timerEntityBaseTick->startTiming();
|
||||||
parent::entityBaseTick();
|
parent::entityBaseTick();
|
||||||
|
|
||||||
|
if($this->dead !== true and $this->isInsideOfSolid()){
|
||||||
|
$this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1));
|
||||||
|
if(!$ev->isCancelled()){
|
||||||
|
$this->attack($ev->getFinalDamage(), $ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->dead !== true and $this->isInsideOfWater()){
|
||||||
|
--$this->airTicks;
|
||||||
|
if($this->airTicks <= -20){
|
||||||
|
$this->airTicks = 0;
|
||||||
|
|
||||||
|
$this->server->getPluginManager()->callEvent($ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2));
|
||||||
|
if(!$ev->isCancelled()){
|
||||||
|
$this->attack($ev->getFinalDamage(), $ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->extinguish();
|
||||||
|
}
|
||||||
|
|
||||||
if($this->attackTime > 0){
|
if($this->attackTime > 0){
|
||||||
--$this->attackTime;
|
--$this->attackTime;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user