Improved fall damage while on jump boost, new protocol update, build 7, allow for live inventory resizing

This commit is contained in:
Shoghi Cervantes 2015-04-24 16:43:29 +02:00
parent ba635b8858
commit 7b699d9afd
8 changed files with 61 additions and 47 deletions

View File

@ -865,7 +865,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
$this->sleeping = clone $pos; $this->sleeping = clone $pos;
//$this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level)); $this->teleport(new Position($pos->x + 0.5, $pos->y - 0.5, $pos->z + 0.5, $this->level));
$this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]); $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]);
$this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true); $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true);
@ -999,7 +999,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$spawnPosition = $this->getSpawn(); $spawnPosition = $this->getSpawn();
$pk = new StartGamePacket(); $pk = new StartGamePacket();
$pk->seed = $this->level->getSeed(); $pk->seed = -1;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;
@ -1569,7 +1569,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->dead = false; $this->dead = false;
$pk = new StartGamePacket(); $pk = new StartGamePacket();
$pk->seed = $this->level->getSeed(); $pk->seed = -1;
$pk->x = $this->x; $pk->x = $this->x;
$pk->y = $this->y; $pk->y = $this->y;
$pk->z = $this->z; $pk->z = $this->z;

View File

@ -74,7 +74,7 @@ namespace pocketmine {
const VERSION = "1.5dev"; const VERSION = "1.5dev";
const API_VERSION = "1.12.0"; const API_VERSION = "1.12.0";
const CODENAME = "活発(Kappatsu)フグ(Fugu)"; const CODENAME = "活発(Kappatsu)フグ(Fugu)";
const MINECRAFT_VERSION = "v0.11.0 alpha build 6"; const MINECRAFT_VERSION = "v0.11.0 alpha build 7";
/* /*
* Startup code. Do not look at it, it may harm you. * Startup code. Do not look at it, it may harm you.

View File

@ -446,6 +446,8 @@ abstract class Entity extends Location implements Metadatable{
$this->addEffect($effect); $this->addEffect($effect);
} }
} }
$this->scheduleUpdate();
} }
/** /**
@ -832,6 +834,17 @@ abstract class Entity extends Location implements Metadatable{
return false; return false;
} }
if($this->dead === true){
++$this->deadTicks;
if($this->deadTicks >= 10){
$this->despawnFromAll();
if(!($this instanceof Player)){
$this->close();
}
}
return $this->deadTicks < 10;
}
$tickDiff = $currentTick - $this->lastUpdate; $tickDiff = $currentTick - $this->lastUpdate;
if($tickDiff <= 0){ if($tickDiff <= 0){
return false; return false;
@ -914,7 +927,7 @@ abstract class Entity extends Location implements Metadatable{
} }
public function fall($fallDistance){ public function fall($fallDistance){
$damage = floor($fallDistance - 3); $damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getAmplifier() + 1 : 0));
if($damage > 0){ if($damage > 0){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage); $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
$this->attack($ev->getFinalDamage(), $ev); $this->attack($ev->getFinalDamage(), $ev);

View File

@ -146,54 +146,43 @@ abstract class Living extends Entity implements Damageable{
public function entityBaseTick($tickDiff = 1){ public function entityBaseTick($tickDiff = 1){
Timings::$timerEntityBaseTick->startTiming(); Timings::$timerEntityBaseTick->startTiming();
if($this->dead === true){
++$this->deadTicks;
if($this->deadTicks >= 10){
$this->despawnFromAll();
if(!($this instanceof Player)){
$this->close();
}
}
Timings::$timerEntityBaseTick->stopTiming();
return $this->deadTicks < 10;
}
$hasUpdate = parent::entityBaseTick($tickDiff); $hasUpdate = parent::entityBaseTick($tickDiff);
if($this->dead !== true and $this->isInsideOfSolid()){ if($this->dead !== true){
$hasUpdate = true; if($this->isInsideOfSolid()){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
$this->attack($ev->getFinalDamage(), $ev);
}
if($this->dead !== true and !$this->hasEffect(Effect::WATER_BREATHING) and $this->isInsideOfWater()){
if($this instanceof WaterAnimal){
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300);
}else{
$hasUpdate = true; $hasUpdate = true;
$airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff; $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
if($airTicks <= -20){ $this->attack($ev->getFinalDamage(), $ev);
$airTicks = 0;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$this->attack($ev->getFinalDamage(), $ev);
}
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
} }
}else{
if($this instanceof WaterAnimal){
$hasUpdate = true;
$airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff;
if($airTicks <= -20){
$airTicks = 0;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2); if(!$this->hasEffect(Effect::WATER_BREATHING) and $this->isInsideOfWater()){
$this->attack($ev->getFinalDamage(), $ev); if($this instanceof WaterAnimal){
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300);
}else{
$hasUpdate = true;
$airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff;
if($airTicks <= -20){
$airTicks = 0;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$this->attack($ev->getFinalDamage(), $ev);
}
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
} }
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
}else{ }else{
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300); if($this instanceof WaterAnimal){
$hasUpdate = true;
$airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff;
if($airTicks <= -20){
$airTicks = 0;
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2);
$this->attack($ev->getFinalDamage(), $ev);
}
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
}else{
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300);
}
} }
} }

View File

@ -82,6 +82,10 @@ abstract class BaseInventory implements Inventory{
return $this->size; return $this->size;
} }
public function setSize($size){
$this->size = (int) $size;
}
public function getMaxStackSize(){ public function getMaxStackSize(){
return $this->maxStackSize; return $this->maxStackSize;
} }

View File

@ -49,6 +49,11 @@ class PlayerInventory extends BaseInventory{
return parent::getSize() - 4; //Remove armor slots return parent::getSize() - 4; //Remove armor slots
} }
public function setSize($size){
parent::setSize($size + 4);
$this->sendContents($this->getViewers());
}
public function getHotbarSlotIndex($index){ public function getHotbarSlotIndex($index){
return ($index >= 0 and $index < $this->getHotbarSize()) ? $this->hotbar[$index] : -1; return ($index >= 0 and $index < $this->getHotbarSize()) ? $this->hotbar[$index] : -1;
} }

View File

@ -30,7 +30,7 @@ interface Info{
/** /**
* Actual Minecraft: PE protocol version * Actual Minecraft: PE protocol version
*/ */
const CURRENT_PROTOCOL = 23; const CURRENT_PROTOCOL = 24;
const LOGIN_PACKET = 0x82; const LOGIN_PACKET = 0x82;
const PLAY_STATUS_PACKET = 0x83; const PLAY_STATUS_PACKET = 0x83;

View File

@ -36,6 +36,7 @@ class MovePlayerPacket extends DataPacket{
public $bodyYaw; public $bodyYaw;
public $pitch; public $pitch;
public $mode = 0; public $mode = 0;
public $onGround;
public function pid(){ public function pid(){
return Info::MOVE_PLAYER_PACKET; return Info::MOVE_PLAYER_PACKET;
@ -55,6 +56,7 @@ class MovePlayerPacket extends DataPacket{
$this->bodyYaw = $this->getFloat(); $this->bodyYaw = $this->getFloat();
$this->pitch = $this->getFloat(); $this->pitch = $this->getFloat();
$this->mode = $this->getByte(); $this->mode = $this->getByte();
$this->onGround = $this->getByte() > 0;
} }
public function encode(){ public function encode(){
@ -67,6 +69,7 @@ class MovePlayerPacket extends DataPacket{
$this->putFloat($this->bodyYaw); //TODO $this->putFloat($this->bodyYaw); //TODO
$this->putFloat($this->pitch); $this->putFloat($this->pitch);
$this->putByte($this->mode); $this->putByte($this->mode);
$this->putByte($this->onGround > 0);
} }
} }