mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Fixed speed and slowness potions
This commit is contained in:
@ -250,7 +250,7 @@ class Effect{
|
||||
$this->color = (($r & 0xff) << 16) + (($g & 0xff) << 8) + ($b & 0xff);
|
||||
}
|
||||
|
||||
public function add(Entity $entity, $modify = false){
|
||||
public function add(Entity $entity, $modify = false, Effect $oldEffect = null){
|
||||
if($entity instanceof Player){
|
||||
$pk = new MobEffectPacket();
|
||||
$pk->eid = 0;
|
||||
@ -270,6 +270,24 @@ class Effect{
|
||||
if($this->id === Effect::INVISIBILITY){
|
||||
$entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true);
|
||||
$entity->setDataProperty(Entity::DATA_SHOW_NAMETAG, Entity::DATA_TYPE_BYTE, 0);
|
||||
}elseif($this->id === Effect::SPEED){
|
||||
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
|
||||
if($modify and $oldEffect !== null){
|
||||
$speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier());
|
||||
}else{
|
||||
$speed = $attr->getValue();
|
||||
}
|
||||
$speed *= (1 + 0.2 * $this->amplifier);
|
||||
$attr->setValue($speed);
|
||||
}elseif($this->id === Effect::SLOWNESS){
|
||||
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
|
||||
if($modify and $oldEffect !== null){
|
||||
$speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getAmplifier());
|
||||
}else{
|
||||
$speed = $attr->getValue();
|
||||
}
|
||||
$speed *= (1 - 0.15 * $this->amplifier);
|
||||
$attr->setValue($speed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,6 +304,12 @@ class Effect{
|
||||
if($this->id === Effect::INVISIBILITY){
|
||||
$entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false);
|
||||
$entity->setDataProperty(Entity::DATA_SHOW_NAMETAG, Entity::DATA_TYPE_BYTE, 1);
|
||||
}elseif($this->id === Effect::SPEED){
|
||||
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
|
||||
$attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier));
|
||||
}elseif($this->id === Effect::SLOWNESS){
|
||||
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
|
||||
$attr->setValue($attr->getValue() / (1 - 0.15 * $this->amplifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user