Added Fall Damage

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-03 10:51:12 +01:00
parent 861a017fa0
commit 38a1f82456

View File

@ -70,9 +70,11 @@ class Entity extends stdClass{
public $attach; public $attach;
public $closed; public $closed;
public $player; public $player;
public $fallY;
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->server = $server; $this->server = $server;
$this->eid = (int) $eid; $this->eid = (int) $eid;
$this->type = (int) $type; $this->type = (int) $type;
@ -185,8 +187,8 @@ class Entity extends stdClass{
for($z = $startZ; $z <= $endZ; ++$z){ for($z = $startZ; $z <= $endZ; ++$z){
$b = $this->server->api->level->getBlock($x, $y, $z); $b = $this->server->api->level->getBlock($x, $y, $z);
switch($b[0]){ switch($b[0]){
case 8: case WATER:
case 9: //Drowing case STILL_WATER: //Drowing
if($this->fire > 0 and $this->inBlock($x, $y, $z)){ if($this->fire > 0 and $this->inBlock($x, $y, $z)){
$this->fire = 0; $this->fire = 0;
$this->updateMetadata(); $this->updateMetadata();
@ -198,22 +200,22 @@ class Entity extends stdClass{
$this->updateMetadata(); $this->updateMetadata();
} }
break; break;
case 10: //Lava damage case LAVA: //Lava damage
case 11: case STILL_LAVA:
if($this->inBlock($x, $y, $z)){ if($this->inBlock($x, $y, $z)){
$this->harm(5, "lava"); $this->harm(5, "lava");
$this->fire = 300; $this->fire = 300;
$this->updateMetadata(); $this->updateMetadata();
} }
break; break;
case 51: //Fire block damage case FIRE: //Fire block damage
if($this->inBlock($x, $y, $z)){ if($this->inBlock($x, $y, $z)){
$this->harm(1, "fire"); $this->harm(1, "fire");
$this->fire = 300; $this->fire = 300;
$this->updateMetadata(); $this->updateMetadata();
} }
break; break;
case 81: //Cactus damage case CACTUS: //Cactus damage
if($this->touchingBlock($x, $y, $z)){ if($this->touchingBlock($x, $y, $z)){
$this->harm(1, "cactus"); $this->harm(1, "cactus");
} }
@ -243,10 +245,12 @@ class Entity extends stdClass{
$this->tickCounter = 0; $this->tickCounter = 0;
} }
if($this->class === ENTITY_ITEM or $this->class === ENTITY_MOB){ if($this->class === ENTITY_ITEM or $this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER){
$x = (int) round($this->x - 0.5); $x = (int) round($this->x - 0.5);
$y = (int) round($this->y - 1); $y = (int) round($this->y - 1);
$z = (int) round($this->z - 0.5); $z = (int) round($this->z - 0.5);
$blockDown = $this->server->api->level->getBlock($x, $y, $z);
if($this->class === ENTITY_ITEM or $this->class === ENTITY_MOB){
if($this->speedX != 0){ if($this->speedX != 0){
$this->x += $this->speedX * 5; $this->x += $this->speedX * 5;
} }
@ -256,8 +260,7 @@ class Entity extends stdClass{
if($this->speedZ != 0){ if($this->speedZ != 0){
$this->z += $this->speedZ * 5; $this->z += $this->speedZ * 5;
} }
$b = $this->server->api->level->getBlock($x, $y, $z); if(isset(Material::$transparent[$blockDown[0]])){
if(isset(Material::$transparent[$b[0]])){
$this->speedY -= 0.04 * 5; $this->speedY -= 0.04 * 5;
//$this->server->api->handle("entity.motion", $this); //$this->server->api->handle("entity.motion", $this);
}elseif($this->speedY < 0){ }elseif($this->speedY < 0){
@ -267,6 +270,21 @@ class Entity extends stdClass{
$this->speedZ = 0; $this->speedZ = 0;
//$this->server->api->handle("entity.motion", $this); //$this->server->api->handle("entity.motion", $this);
} }
}else{
if(isset(Material::$flowable[$blockDown[0]])){
if($this->fallY === false or $y > $this->fallY){
$this->fallY = $y;
}
}elseif($this->fallY !== false){ //Fall damage!
if($y < $this->fallY){
$dmg = ($this->fallY - $y) - 3;
if($dmg > 0){
$this->harm($dmg, "fall");
}
}
$this->fallY = false;
}
}
} }
if($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch){ if($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch){