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