From c4f461f65d71efc0b5e0ca00c49e3c4b97c57757 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 5 May 2017 10:41:44 +0100 Subject: [PATCH 1/5] Fixed fall damage in 1 block of water, close #470 --- src/pocketmine/entity/Entity.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 094e80ea5..6eebae055 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1301,6 +1301,8 @@ abstract class Entity extends Location implements Metadatable{ return true; } + $this->blocksAround = null; + if($this->keepMovement){ $this->boundingBox->offset($dx, $dy, $dz); $this->setPosition($this->temporalVector->setComponents(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2)); @@ -1429,7 +1431,7 @@ abstract class Entity extends Location implements Metadatable{ $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2; $this->checkChunks(); - + $this->checkBlockCollision(); $this->checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz); $this->updateFallState($dy, $this->onGround); From 11f35d28c2f58e4db4189d9038be5e97e3d5edf3 Mon Sep 17 00:00:00 2001 From: Muqsit Rayyan Date: Fri, 5 May 2017 13:18:58 +0300 Subject: [PATCH 2/5] Call PlayerInteractEventm when receiving ItemFrameDropItemPacket to allow plugins to prevent item frame item removal (#887) --- src/pocketmine/Player.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 62d1a36e3..110d06e3f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3240,7 +3240,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z)); if($tile instanceof ItemFrame){ + $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK); + $this->server->getPluginManager()->callEvent($ev); + if($this->isSpectator()){ + $ev->setCancelled(); + } + + if($ev->isCancelled()){ $tile->spawnTo($this); return true; } From 76ceddf266f4b78f405559d2ae064bdea379eea1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 5 May 2017 11:23:06 +0100 Subject: [PATCH 3/5] Reduced deltas for player movement, significantly smoother player movement and rotation (#883) Send movement to viewers if the player moved more than 0.01 blocks in a tick or rotated more than 1 degree in any direction. --- src/pocketmine/Player.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 110d06e3f..f4c75dee5 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1544,7 +1544,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2); $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch); - if(!$revert and ($delta > (1 / 16) or $deltaAngle > 10)){ + if(!$revert and ($delta > 0.0001 or $deltaAngle > 1.0)){ $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null); @@ -1567,7 +1567,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); $distance = $from->distance($to); - //TODO: check swimming (adds 0.015 exhaustion in MCPE) if($this->isSprinting()){ $this->exhaust(0.1 * $distance, PlayerExhaustEvent::CAUSE_SPRINTING); From 8a7259aa73247e2bc3c31d9263564c4661c2aad6 Mon Sep 17 00:00:00 2001 From: smarticles101 Date: Fri, 5 May 2017 18:58:54 +0800 Subject: [PATCH 4/5] Merge #826: use getEffectLevel() instead of getAmplifier() + 1 Closes #412 --- src/pocketmine/entity/Effect.php | 37 +++++++++++-------- src/pocketmine/entity/Entity.php | 10 ++--- src/pocketmine/entity/Living.php | 2 +- .../entity/EntityDamageByEntityEvent.php | 4 +- .../event/entity/EntityDamageEvent.php | 2 +- src/pocketmine/level/Level.php | 4 +- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index a5327dbde..942ec62f5 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -222,9 +222,17 @@ class Effect{ return $this; } + /** + * Returns the level of this effect, which is always one higher than the amplifier. + * + * @return int + */ + public function getEffectLevel() : int{ + return $this->amplifier + 1; + } + /** * Returns the amplifier of this effect. - * TODO: fix mess of amplifier used instead of level for effect calculation. * * @return int */ @@ -337,19 +345,19 @@ class Effect{ case Effect::HUNGER: if($entity instanceof Human){ - $entity->exhaust(0.5 * $this->amplifier, PlayerExhaustEvent::CAUSE_POTION); + $entity->exhaust(0.5 * $this->getEffectLevel(), PlayerExhaustEvent::CAUSE_POTION); } break; case Effect::INSTANT_HEALTH: //TODO: add particles (witch spell) if($entity->getHealth() < $entity->getMaxHealth()){ - $amount = 2 * (2 ** (($this->amplifier + 1) % 32)); + $amount = 2 * (2 ** ($this->getEffectLevel() % 32)); $entity->heal($amount, new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC)); } break; case Effect::INSTANT_DAMAGE: //TODO: add particles (witch spell) - $amount = 2 * (2 ** (($this->amplifier + 1) % 32)); + $amount = 2 * (2 ** ($this->getEffectLevel() % 32)); $entity->attack($amount, new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount)); break; } @@ -410,42 +418,41 @@ class Effect{ case Effect::SPEED: $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); if($ev->willModify() and $oldEffect !== null){ - $speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier()); + $speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getEffectLevel()); }else{ $speed = $attr->getValue(); } - $speed *= (1 + 0.2 * $this->amplifier); + $speed *= (1 + 0.2 * $this->getEffectLevel()); $attr->setValue($speed); break; case Effect::SLOWNESS: $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); if($ev->willModify() and $oldEffect !== null){ - $speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getAmplifier()); + $speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getEffectLevel()); }else{ $speed = $attr->getValue(); } - $speed *= (1 - 0.15 * $this->amplifier); + $speed *= (1 - 0.15 * $this->getEffectLevel()); $attr->setValue($speed, true); break; case Effect::HEALTH_BOOST: $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); if($ev->willModify() and $oldEffect !== null){ - $max = $attr->getMaxValue() - (4 * ($oldEffect->getAmplifier() + 1)); + $max = $attr->getMaxValue() - (4 * $oldEffect->getEffectLevel()); }else{ $max = $attr->getMaxValue(); } - $max += (4 * ($this->amplifier + 1)); + $max += (4 * $this->getEffectLevel()); $attr->setMaxValue($max); break; case Effect::ABSORPTION: - $new = (4 * ($this->amplifier + 1)); + $new = (4 * $this->getEffectLevel()); if($new > $entity->getAbsorption()){ $entity->setAbsorption($new); } break; - } } @@ -475,15 +482,15 @@ class Effect{ break; case Effect::SPEED: $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier)); + $attr->setValue($attr->getValue() / (1 + 0.2 * $this->getEffectLevel())); break; case Effect::SLOWNESS: $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() / (1 - 0.15 * $this->amplifier)); + $attr->setValue($attr->getValue() / (1 - 0.15 * $this->getEffectLevel())); break; case Effect::HEALTH_BOOST: $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); - $attr->setMaxValue($attr->getMaxValue() - (4 * ($this->amplifier + 1))); + $attr->setMaxValue($attr->getMaxValue() - 4 * $this->getEffectLevel()); break; case Effect::ABSORPTION: $entity->setAbsorption(0); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 6eebae055..a32c6d17d 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -512,10 +512,10 @@ abstract class Entity extends Location implements Metadatable{ foreach($this->effects as $effect){ if($effect->isVisible() and $effect->hasBubbles()){ $c = $effect->getColor(); - $color[0] += $c[0] * ($effect->getAmplifier() + 1); - $color[1] += $c[1] * ($effect->getAmplifier() + 1); - $color[2] += $c[2] * ($effect->getAmplifier() + 1); - $count += $effect->getAmplifier() + 1; + $color[0] += $c[0] * $effect->getEffectLevel(); + $color[1] += $c[1] * $effect->getEffectLevel(); + $color[2] += $c[2] * $effect->getEffectLevel(); + $count += $effect->getEffectLevel(); if(!$effect->isAmbient()){ $ambient = false; } @@ -1178,7 +1178,7 @@ abstract class Entity extends Location implements Metadatable{ } public function fall($fallDistance){ - $damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getAmplifier() + 1 : 0)); + $damage = floor($fallDistance - 3 - ($this->hasEffect(Effect::JUMP) ? $this->getEffect(Effect::JUMP)->getEffectLevel() : 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 e45131d38..8e58880d6 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -122,7 +122,7 @@ abstract class Living extends Entity implements Damageable{ * @return float */ public function getJumpVelocity() : float{ - return $this->jumpVelocity + ($this->hasEffect(Effect::JUMP) ? (($this->getEffect(Effect::JUMP)->getAmplifier() + 1) / 10) : 0); + return $this->jumpVelocity + ($this->hasEffect(Effect::JUMP) ? ($this->getEffect(Effect::JUMP)->getEffectLevel() / 10) : 0); } /** diff --git a/src/pocketmine/event/entity/EntityDamageByEntityEvent.php b/src/pocketmine/event/entity/EntityDamageByEntityEvent.php index ea6228ae1..833445730 100644 --- a/src/pocketmine/event/entity/EntityDamageByEntityEvent.php +++ b/src/pocketmine/event/entity/EntityDamageByEntityEvent.php @@ -50,11 +50,11 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{ protected function addAttackerModifiers(Entity $damager){ if($damager->hasEffect(Effect::STRENGTH)){ - $this->setDamage($this->getDamage(self::MODIFIER_BASE) * 0.3 * ($damager->getEffect(Effect::STRENGTH)->getAmplifier() + 1), self::MODIFIER_STRENGTH); + $this->setDamage($this->getDamage(self::MODIFIER_BASE) * 0.3 * $damager->getEffect(Effect::STRENGTH)->getEffectLevel(), self::MODIFIER_STRENGTH); } if($damager->hasEffect(Effect::WEAKNESS)){ - $this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.2 * ($damager->getEffect(Effect::WEAKNESS)->getAmplifier() + 1)), self::MODIFIER_WEAKNESS); + $this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.2 * $damager->getEffect(Effect::WEAKNESS)->getEffectLevel()), self::MODIFIER_WEAKNESS); } } diff --git a/src/pocketmine/event/entity/EntityDamageEvent.php b/src/pocketmine/event/entity/EntityDamageEvent.php index 57b77a629..d3eac739e 100644 --- a/src/pocketmine/event/entity/EntityDamageEvent.php +++ b/src/pocketmine/event/entity/EntityDamageEvent.php @@ -86,7 +86,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ } if($entity->hasEffect(Effect::DAMAGE_RESISTANCE)){ - $this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.20 * ($entity->getEffect(Effect::DAMAGE_RESISTANCE)->getAmplifier() + 1)), self::MODIFIER_RESISTANCE); + $this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.20 * $entity->getEffect(Effect::DAMAGE_RESISTANCE)->getEffectLevel()), self::MODIFIER_RESISTANCE); } } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 37b272d49..f2e41bd17 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1601,11 +1601,11 @@ class Level implements ChunkManager, Metadatable{ } if($player->hasEffect(Effect::HASTE)){ - $breakTime *= 1 - (0.2 * ($player->getEffect(Effect::HASTE)->getAmplifier() + 1)); + $breakTime *= 1 - (0.2 * $player->getEffect(Effect::HASTE)->getEffectLevel()); } if($player->hasEffect(Effect::MINING_FATIGUE)){ - $breakTime *= 1 + (0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1)); + $breakTime *= 1 + (0.3 * $player->getEffect(Effect::MINING_FATIGUE)->getEffectLevel()); } $breakTime -= 1; //1 tick compensation From adbb53929e8b01e4f0c63afde392a54a5bc8b70a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 5 May 2017 16:51:15 +0100 Subject: [PATCH 5/5] Fixed scaling issues with height and width on the client, close #819 Seems these metadata fields are actually the _base_ height/width. Setting the scale will cause the client to calculate bounding boxes with the scale already taken into account. This caused the scale to be applied twice on the client. --- src/pocketmine/entity/Entity.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index a32c6d17d..0a92b237e 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -409,6 +409,7 @@ abstract class Entity extends Location implements Metadatable{ $this->width *= $multiplier; $this->height *= $multiplier; + $this->eyeHeight *= $multiplier; $halfWidth = $this->width / 2; $this->boundingBox->setBounds( @@ -421,8 +422,6 @@ abstract class Entity extends Location implements Metadatable{ ); $this->setDataProperty(self::DATA_SCALE, self::DATA_TYPE_FLOAT, $value); - $this->setDataProperty(self::DATA_BOUNDING_BOX_WIDTH, self::DATA_TYPE_FLOAT, $this->width); - $this->setDataProperty(self::DATA_BOUNDING_BOX_HEIGHT, self::DATA_TYPE_FLOAT, $this->height); } public function isSneaking(){