mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 21:35:21 +00:00
Flying damage
This commit is contained in:
parent
f53e08bb84
commit
e433f0f6dc
@ -44,11 +44,11 @@ class PlayerAPI{
|
|||||||
public function handle($data, $event){
|
public function handle($data, $event){
|
||||||
switch($event){
|
switch($event){
|
||||||
case "server.regeneration":
|
case "server.regeneration":
|
||||||
$result = $this->server->query("SELECT EID FROM players WHERE EID = (SELECT EID FROM entities WHERE health < 20);");
|
$result = $this->server->query("SELECT EID FROM entities WHERE class = ".ENTITY_PLAYER." AND health < 20;");
|
||||||
if($result !== true and $result !== false){
|
if($result !== true and $result !== false){
|
||||||
while(false !== ($player = $result->fetchArray())){
|
while(($player = $result->fetchArray()) !== false){
|
||||||
if(($player = $this->server->api->entity->get($player["EID"])) !== false){
|
if(($player = $this->server->api->entity->get($player["EID"])) !== false){
|
||||||
if($player->dead === true){
|
if($player->getHealth() <= 0){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$player->setHealth(min(20, $player->getHealth() + $data), "regeneration");
|
$player->setHealth(min(20, $player->getHealth() + $data), "regeneration");
|
||||||
@ -94,6 +94,9 @@ class PlayerAPI{
|
|||||||
case "fall":
|
case "fall":
|
||||||
$message .= " hit the ground too hard";
|
$message .= " hit the ground too hard";
|
||||||
break;
|
break;
|
||||||
|
case "flying":
|
||||||
|
$message .= " tried to get up to the sky";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$message .= " died";
|
$message .= " died";
|
||||||
break;
|
break;
|
||||||
@ -171,6 +174,8 @@ class PlayerAPI{
|
|||||||
public function tppos($name, $x, $y, $z){
|
public function tppos($name, $x, $y, $z){
|
||||||
$player = $this->get($name);
|
$player = $this->get($name);
|
||||||
if($player !== false){
|
if($player !== false){
|
||||||
|
$player->entity->setPosition($x, $y, $z, 0, 0);
|
||||||
|
$player->fallY = false;
|
||||||
$player->dataPacket(MC_MOVE_PLAYER, array(
|
$player->dataPacket(MC_MOVE_PLAYER, array(
|
||||||
"eid" => 0,
|
"eid" => 0,
|
||||||
"x" => $x,
|
"x" => $x,
|
||||||
@ -179,6 +184,7 @@ class PlayerAPI{
|
|||||||
"yaw" => 0,
|
"yaw" => 0,
|
||||||
"pitch" => 0,
|
"pitch" => 0,
|
||||||
));
|
));
|
||||||
|
$player->fallY = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -607,7 +607,6 @@ class Player{
|
|||||||
$this->dataPacket(MC_ADVENTURE_SETTINGS, array(
|
$this->dataPacket(MC_ADVENTURE_SETTINGS, array(
|
||||||
"flags" => $flags,
|
"flags" => $flags,
|
||||||
));
|
));
|
||||||
$this->orderChunks();
|
|
||||||
$this->getNextChunk();
|
$this->getNextChunk();
|
||||||
break;
|
break;
|
||||||
case 2://Chunk loaded?
|
case 2://Chunk loaded?
|
||||||
@ -683,9 +682,9 @@ class Player{
|
|||||||
switch($data["event"]){
|
switch($data["event"]){
|
||||||
case 9: //Eating
|
case 9: //Eating
|
||||||
$items = array(
|
$items = array(
|
||||||
260 => 2, //Apples
|
APPLE => 2, //Apples
|
||||||
282 => 10, //Stew
|
282 => 10, //Stew
|
||||||
297 => 5, //Bread
|
BREAD => 5, //Bread
|
||||||
319 => 3,
|
319 => 3,
|
||||||
320 => 8,
|
320 => 8,
|
||||||
363 => 3,
|
363 => 3,
|
||||||
|
@ -46,7 +46,6 @@ define("ENTITY_OBJECT", 2);
|
|||||||
define("ENTITY_ITEM", 3);
|
define("ENTITY_ITEM", 3);
|
||||||
|
|
||||||
class Entity extends stdClass{
|
class Entity extends stdClass{
|
||||||
public $invincible;
|
|
||||||
public $age;
|
public $age;
|
||||||
public $air;
|
public $air;
|
||||||
public $spawntime;
|
public $spawntime;
|
||||||
@ -71,10 +70,12 @@ class Entity extends stdClass{
|
|||||||
public $closed;
|
public $closed;
|
||||||
public $player;
|
public $player;
|
||||||
public $fallY;
|
public $fallY;
|
||||||
|
public $fallStart;
|
||||||
private $tickCounter;
|
private $tickCounter;
|
||||||
private $server;
|
private $server;
|
||||||
function __construct(PocketMinecraftServer $server, $eid, $class, $type = 0, $data = array()){
|
function __construct(PocketMinecraftServer $server, $eid, $class, $type = 0, $data = array()){
|
||||||
$this->fallY = false;
|
$this->fallY = false;
|
||||||
|
$this->fallStart = false;
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->eid = (int) $eid;
|
$this->eid = (int) $eid;
|
||||||
$this->type = (int) $type;
|
$this->type = (int) $type;
|
||||||
@ -110,7 +111,6 @@ class Entity extends stdClass{
|
|||||||
switch($this->class){
|
switch($this->class){
|
||||||
case ENTITY_PLAYER:
|
case ENTITY_PLAYER:
|
||||||
$this->player = $this->data["player"];
|
$this->player = $this->data["player"];
|
||||||
$this->health = &$this->player->data["health"];
|
|
||||||
$this->setHealth($this->health, "generic");
|
$this->setHealth($this->health, "generic");
|
||||||
break;
|
break;
|
||||||
case ENTITY_ITEM:
|
case ENTITY_ITEM:
|
||||||
@ -272,18 +272,27 @@ class Entity extends stdClass{
|
|||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if($blockDown->isFlowable === true){
|
if($blockDown->isFlowable === true){
|
||||||
if($this->fallY === false or $y > $this->fallY){
|
if($this->fallY === false){
|
||||||
|
$this->fallY = $y;
|
||||||
|
$this->fallStart = microtime(true);
|
||||||
|
}elseif($y > $this->fallY){
|
||||||
|
$this->fallY = $y;
|
||||||
|
}
|
||||||
|
if($this->fallY !== false and ($this->fallStart + 8) < microtime(true)){ //Flying
|
||||||
|
$this->harm(1, "flying");
|
||||||
$this->fallY = $y;
|
$this->fallY = $y;
|
||||||
}
|
}
|
||||||
}elseif($this->fallY !== false){ //Fall damage!
|
}elseif($this->fallY !== false){ //Fall damage!
|
||||||
if($y < $this->fallY){
|
if($y < $this->fallY){
|
||||||
$d = $this->server->api->block->getBlock(new Vector3($x, $y + 1, $z));
|
$d = $this->server->api->block->getBlock(new Vector3($x, $y + 1, $z));
|
||||||
$dmg = ($this->fallY - $y) - 3;
|
$dmg = ($this->fallY - $y) - 3;
|
||||||
if($dmg > 0 and !($d instanceof LiquidBlock)){
|
if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER){
|
||||||
$this->harm($dmg, "fall");
|
$this->harm($dmg, "fall");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->fallY = false;
|
$this->fallY = false;
|
||||||
|
$this->fallStart = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user