mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-06 10:01:53 +00:00
Better damage handling + cactus damage
This commit is contained in:
parent
061faaa410
commit
09385daf60
@ -50,7 +50,7 @@ class PlayerAPI{
|
|||||||
if($player->dead === true){
|
if($player->dead === true){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$player->setHealth(min(20, $player->entity->getHealth() + $data), "regeneration");
|
$player->setHealth(min(20, $player->getHealth() + $data), "regeneration");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,33 +86,43 @@ class Entity extends stdClass{
|
|||||||
if($this->closed === true){
|
if($this->closed === true){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$down = $this->server->api->level->getBlock(round($this->x + 0.5), round($this->y), round($this->z + 0.5));
|
$startX = (int) (round($this->x - 0.5) - 1);
|
||||||
$up = $this->server->api->level->getBlock(round($this->x + 0.5), round($this->y + 1), round($this->z + 0.5));
|
$startY = (int) (round($this->y) - 1);
|
||||||
switch($down[0]){
|
$startZ = (int) (round($this->z - 0.5) - 1);
|
||||||
|
$endX = $startX + 2;
|
||||||
|
$endY = $startY + 2;
|
||||||
|
$endZ = $startZ + 2;
|
||||||
|
for($y = $startY; $y <= $endY; ++$y){
|
||||||
|
for($x = $startX; $x <= $endX; ++$x){
|
||||||
|
for($z = $startZ; $z <= $endZ; ++$z){
|
||||||
|
$b = $this->server->api->level->getBlock($x, $y, $z);
|
||||||
|
switch($b[0]){
|
||||||
case 10: //Lava damage
|
case 10: //Lava damage
|
||||||
case 11:
|
case 11:
|
||||||
|
if($this->inBlock($x, $y, $z)){
|
||||||
$this->harm(5, "lava");
|
$this->harm(5, "lava");
|
||||||
break;
|
|
||||||
case 51: //Fire block damage
|
|
||||||
$this->harm(1, "fire");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($up[0]){
|
|
||||||
case 10: //Lava damage
|
|
||||||
case 11:
|
|
||||||
$this->harm(5, "lava");
|
|
||||||
break;
|
break;
|
||||||
case 51: //Fire block damage
|
case 51: //Fire block damage
|
||||||
|
if($this->inBlock($x, $y, $z)){
|
||||||
$this->harm(1, "fire");
|
$this->harm(1, "fire");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 81: //Cactus damage
|
||||||
|
if($this->touchingBlock($x, $y, $z)){
|
||||||
|
$this->harm(1, "cactus");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(!isset(Material::$transparent[$up[0]])){
|
if($this->inBlock($x, $y, $z) and !isset(Material::$transparent[$b[0]])){
|
||||||
$this->harm(1, "suffocation");
|
$this->harm(1, "suffocation"); //Suffocation
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function update(){
|
public function update(){
|
||||||
if($this->closed === true){
|
if($this->closed === true){
|
||||||
@ -265,10 +275,19 @@ class Entity extends stdClass{
|
|||||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function inBlock($x, $y, $z){
|
public function inBlock($x, $y, $z, $radius = 0.8){
|
||||||
$block = new Vector3($x + 0.5, $y, $z + 0.5);
|
$block = new Vector3($x, $y, $z);
|
||||||
$me = new Vector3($this->x, $this->y, $this->z);
|
$me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5);
|
||||||
if(($y == ((int) $this->y) or $y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < 0.8){
|
if(($y == ((int) $this->y) or $y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < $radius){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function touchingBlock($x, $y, $z, $radius = 0.9){
|
||||||
|
$block = new Vector3($x, $y, $z);
|
||||||
|
$me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5);
|
||||||
|
if(($y == (((int) $this->y) - 1) or $y == ((int) $this->y)) and $block->maxPlainDistance($me) < $radius){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user