Merge branch 'master' into mcpe-1.1

This commit is contained in:
Dylan K. Taylor 2017-05-08 17:43:09 +01:00
commit 046f17c9e2
7 changed files with 45 additions and 31 deletions

View File

@ -1560,7 +1560,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);
@ -1583,7 +1583,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);
@ -3274,7 +3273,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;
}

View File

@ -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);

View File

@ -455,6 +455,7 @@ abstract class Entity extends Location implements Metadatable{
$this->width *= $multiplier;
$this->height *= $multiplier;
$this->eyeHeight *= $multiplier;
$halfWidth = $this->width / 2;
$this->boundingBox->setBounds(
@ -467,8 +468,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(){
@ -666,10 +665,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;
}
@ -1332,7 +1331,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);
@ -1455,6 +1454,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));
@ -1583,7 +1584,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);

View File

@ -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);
}
/**

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -1612,11 +1612,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