From 7b699d9afd947d3f80794cf77c187fae86e14d68 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 24 Apr 2015 16:43:29 +0200 Subject: [PATCH] Improved fall damage while on jump boost, new protocol update, build 7, allow for live inventory resizing --- src/pocketmine/Player.php | 6 +- src/pocketmine/PocketMine.php | 2 +- src/pocketmine/entity/Entity.php | 15 +++- src/pocketmine/entity/Living.php | 71 ++++++++----------- src/pocketmine/inventory/BaseInventory.php | 4 ++ src/pocketmine/inventory/PlayerInventory.php | 5 ++ src/pocketmine/network/protocol/Info.php | 2 +- .../network/protocol/MovePlayerPacket.php | 3 + 8 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 50abb31a9..1071158a3 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -865,7 +865,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $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->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(); $pk = new StartGamePacket(); - $pk->seed = $this->level->getSeed(); + $pk->seed = -1; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; @@ -1569,7 +1569,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->dead = false; $pk = new StartGamePacket(); - $pk->seed = $this->level->getSeed(); + $pk->seed = -1; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 126ab2580..8c8839129 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -74,7 +74,7 @@ namespace pocketmine { const VERSION = "1.5dev"; const API_VERSION = "1.12.0"; 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. diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index d01c1391e..bc3b95f30 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -446,6 +446,8 @@ abstract class Entity extends Location implements Metadatable{ $this->addEffect($effect); } } + + $this->scheduleUpdate(); } /** @@ -832,6 +834,17 @@ abstract class Entity extends Location implements Metadatable{ 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; if($tickDiff <= 0){ return false; @@ -914,7 +927,7 @@ abstract class Entity extends Location implements Metadatable{ } 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){ $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage); $this->attack($ev->getFinalDamage(), $ev); diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index e3769a96b..57c51e15c 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -146,54 +146,43 @@ abstract class Living extends Entity implements Damageable{ public function entityBaseTick($tickDiff = 1){ 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); - if($this->dead !== true and $this->isInsideOfSolid()){ - $hasUpdate = true; - $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{ + if($this->dead !== true){ + if($this->isInsideOfSolid()){ $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); + $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1); + $this->attack($ev->getFinalDamage(), $ev); } - }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); - $this->attack($ev->getFinalDamage(), $ev); + if(!$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; + $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{ - $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); + } } } diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index ddd0abf74..dd7f922bd 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -82,6 +82,10 @@ abstract class BaseInventory implements Inventory{ return $this->size; } + public function setSize($size){ + $this->size = (int) $size; + } + public function getMaxStackSize(){ return $this->maxStackSize; } diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 67eb04938..6f97afcde 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -49,6 +49,11 @@ class PlayerInventory extends BaseInventory{ return parent::getSize() - 4; //Remove armor slots } + public function setSize($size){ + parent::setSize($size + 4); + $this->sendContents($this->getViewers()); + } + public function getHotbarSlotIndex($index){ return ($index >= 0 and $index < $this->getHotbarSize()) ? $this->hotbar[$index] : -1; } diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 986da6997..ff99f112d 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -30,7 +30,7 @@ interface Info{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 23; + const CURRENT_PROTOCOL = 24; const LOGIN_PACKET = 0x82; const PLAY_STATUS_PACKET = 0x83; diff --git a/src/pocketmine/network/protocol/MovePlayerPacket.php b/src/pocketmine/network/protocol/MovePlayerPacket.php index 75d93e7e2..165c8239f 100644 --- a/src/pocketmine/network/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/protocol/MovePlayerPacket.php @@ -36,6 +36,7 @@ class MovePlayerPacket extends DataPacket{ public $bodyYaw; public $pitch; public $mode = 0; + public $onGround; public function pid(){ return Info::MOVE_PLAYER_PACKET; @@ -55,6 +56,7 @@ class MovePlayerPacket extends DataPacket{ $this->bodyYaw = $this->getFloat(); $this->pitch = $this->getFloat(); $this->mode = $this->getByte(); + $this->onGround = $this->getByte() > 0; } public function encode(){ @@ -67,6 +69,7 @@ class MovePlayerPacket extends DataPacket{ $this->putFloat($this->bodyYaw); //TODO $this->putFloat($this->pitch); $this->putByte($this->mode); + $this->putByte($this->onGround > 0); } }