GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Effect Class Reference

Public Member Functions

 __construct ($id, $name, $r, $g, $b, $isBad=false)
 
 getName ()
 
 getId ()
 
 setDuration ($ticks)
 
 getDuration ()
 
 isVisible ()
 
 setVisible ($bool)
 
 getAmplifier ()
 
 setAmplifier (int $amplifier)
 
 isAmbient ()
 
 setAmbient ($ambient=true)
 
 isBad ()
 
 canTick ()
 
 applyEffect (Entity $entity)
 
 getColor ()
 
 setColor ($r, $g, $b)
 
 add (Entity $entity, $modify=false, Effect $oldEffect=null)
 
 remove (Entity $entity)
 

Static Public Member Functions

static init ()
 
static getEffect ($id)
 
static getEffectByName ($name)
 

Data Fields

const SPEED = 1
 
const SLOWNESS = 2
 
const HASTE = 3
 
const SWIFTNESS = 3
 
const FATIGUE = 4
 
const MINING_FATIGUE = 4
 
const STRENGTH = 5
 
const HEALING = 6
 
const HARMING = 7
 
const JUMP = 8
 
const NAUSEA = 9
 
const CONFUSION = 9
 
const REGENERATION = 10
 
const DAMAGE_RESISTANCE = 11
 
const FIRE_RESISTANCE = 12
 
const WATER_BREATHING = 13
 
const INVISIBILITY = 14
 
const BLINDNESS = 15
 
const NIGHT_VISION = 16
 
const HUNGER = 17
 
const WEAKNESS = 18
 
const POISON = 19
 
const WITHER = 20
 
const HEALTH_BOOST = 21
 
const ABSORPTION = 22
 
const SATURATION = 23
 
const LEVITATION = 24
 
const MAX_DURATION = 2147483648
 

Protected Attributes

 $id
 
 $name
 
 $duration
 
 $amplifier = 0
 
 $color
 
 $show = true
 
 $ambient = false
 
 $bad
 

Static Protected Attributes

static $effects
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $id,
  $name,
  $r,
  $g,
  $b,
  $isBad = false 
)

Effect constructor.

Parameters
$id
$name
$r
$g
$b
bool$isBad
149  {
150  $this->id = $id;
151  $this->name = $name;
152  $this->bad = (bool) $isBad;
153  $this->setColor($r, $g, $b);
154  }

Member Function Documentation

◆ add()

add ( Entity  $entity,
  $modify = false,
Effect  $oldEffect = null 
)
Parameters
Entity$entity
bool$modify
Effect | null$oldEffect
362  {
363  if($entity instanceof Player){
364  $pk = new MobEffectPacket();
365  $pk->eid = $entity->getId();
366  $pk->effectId = $this->getId();
367  $pk->amplifier = $this->getAmplifier();
368  $pk->particles = $this->isVisible();
369  $pk->duration = $this->getDuration();
370  if($modify){
371  $pk->eventId = MobEffectPacket::EVENT_MODIFY;
372  }else{
373  $pk->eventId = MobEffectPacket::EVENT_ADD;
374  }
375 
376  $entity->dataPacket($pk);
377 
378  if($this->id === Effect::SPEED){
379  $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
380  if($modify and $oldEffect !== null){
381  $speed = $attr->getValue() / (1 + 0.2 * ($oldEffect->getAmplifier() + 1));
382  }else{
383  $speed = $attr->getValue();
384  }
385  $speed *= (1 + 0.2 * ($this->amplifier + 1));
386  $attr->setValue($speed);
387  }elseif($this->id === Effect::SLOWNESS){
388  $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
389  if($modify and $oldEffect !== null){
390  $speed = $attr->getValue() / (1 - 0.15 * ($oldEffect->getAmplifier() + 1));
391  }else{
392  $speed = $attr->getValue();
393  }
394  $speed *= (1 - (0.15 * $this->amplifier + 1));
395  $attr->setValue($speed);
396  }
397  }
398 
399  if($this->id === Effect::INVISIBILITY){
400  $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true);
401  $entity->setNameTagVisible(false);
402  }
403  }

◆ applyEffect()

applyEffect ( Entity  $entity)
Parameters
Entity$entity
286  {
287  switch($this->id){
288  case Effect::POISON:
289  if($entity->getHealth() > 1){
290  $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
291  $entity->attack($ev->getFinalDamage(), $ev);
292  }
293  break;
294 
295  case Effect::WITHER:
296  $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
297  $entity->attack($ev->getFinalDamage(), $ev);
298  break;
299 
301  if($entity->getHealth() < $entity->getMaxHealth()){
302  $ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC);
303  $entity->heal($ev->getAmount(), $ev);
304  }
305  break;
306  case Effect::HUNGER:
307  if($entity instanceof Human){
308  $entity->exhaust(0.5 * $this->amplifier, PlayerExhaustEvent::CAUSE_POTION);
309  }
310  break;
311  case Effect::HEALING:
312  $level = $this->amplifier + 1;
313  if(($entity->getHealth() + 4 * $level) <= $entity->getMaxHealth()){
314  $ev = new EntityRegainHealthEvent($entity, 4 * $level, EntityRegainHealthEvent::CAUSE_MAGIC);
315  $entity->heal($ev->getAmount(), $ev);
316  }else{
317  $ev = new EntityRegainHealthEvent($entity, $entity->getMaxHealth() - $entity->getHealth(), EntityRegainHealthEvent::CAUSE_MAGIC);
318  $entity->heal($ev->getAmount(), $ev);
319  }
320  break;
321  case Effect::HARMING:
322  $level = $this->amplifier + 1;
323  if(($entity->getHealth() - 6 * $level) >= 0){
324  $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 6 * $level);
325  $entity->attack($ev->getFinalDamage(), $ev);
326  }else{
327  $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $entity->getHealth());
328  $entity->attack($ev->getFinalDamage(), $ev);
329  }
330  break;
331  case Effect::SATURATION:
332  if($entity instanceof Player){
333  if($entity->getServer()->foodEnabled){
334  $entity->setFood($entity->getFood() + 1);
335  }
336  }
337  break;
338  }
339  }

◆ canTick()

canTick ( )
Returns
bool
245  {
246  if($this->amplifier < 0) $this->amplifier = 0;
247  switch($this->id){
248  case Effect::POISON:
249  if(($interval = (25 >> $this->amplifier)) > 0){
250  return ($this->duration % $interval) === 0;
251  }
252  return true;
253  case Effect::WITHER:
254  if(($interval = (50 >> $this->amplifier)) > 0){
255  return ($this->duration % $interval) === 0;
256  }
257  return true;
259  if(($interval = (40 >> $this->amplifier)) > 0){
260  return ($this->duration % $interval) === 0;
261  }
262  return true;
263  case Effect::HUNGER:
264  if($this->amplifier < 0){ // prevents hacking with amplifier -1
265  return false;
266  }
267  if(($interval = 20) > 0){
268  return ($this->duration % $interval) === 0;
269  }
270  return true;
271  case Effect::HEALING:
272  case Effect::HARMING:
273  return true;
274  case Effect::SATURATION:
275  if(($interval = (20 >> $this->amplifier)) > 0){
276  return ($this->duration % $interval) === 0;
277  }
278  return true;
279  }
280  return false;
281  }

◆ getAmplifier()

getAmplifier ( )
Returns
int
204  {
205  return $this->amplifier;
206  }

◆ getColor()

getColor ( )
Returns
array
344  {
345  return [$this->color >> 16, ($this->color >> 8) & 0xff, $this->color & 0xff];
346  }

◆ getDuration()

getDuration ( )
180  {
181  return $this->duration;
182  }

◆ getEffect()

static getEffect (   $id)
static
Parameters
int$id
Returns
$this
103  {
104  if(isset(self::$effects[$id])){
105  return clone self::$effects[(int) $id];
106  }
107  return null;
108  }

◆ getEffectByName()

static getEffectByName (   $name)
static
Parameters
$name
Returns
null|Effect
115  {
116  if(defined(Effect::class . "::" . strtoupper($name))){
117  return self::getEffect(constant(Effect::class . "::" . strtoupper($name)));
118  }
119  return null;
120  }

◆ getId()

getId ( )
Returns
int
166  {
167  return $this->id;
168  }

◆ getName()

getName ( )
Returns
string
159  : string{
160  return $this->name;
161  }

◆ init()

static init ( )
static
65  {
66  self::$effects = new \SplFixedArray(256);
67 
68  self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "%potion.moveSpeed", 124, 175, 198);
69  self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "%potion.moveSlowdown", 90, 108, 129, true);
70  self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "%potion.digSpeed", 217, 192, 67);
71  self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "%potion.digSlowDown", 74, 66, 23, true);
72  self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "%potion.damageBoost", 147, 36, 35);
73  self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "%potion.heal", 248, 36, 35);
74  self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "%potion.harm", 67, 10, 9, true);
75  self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "%potion.jump", 34, 255, 76);
76  self::$effects[Effect::NAUSEA] = new Effect(Effect::NAUSEA, "%potion.confusion", 85, 29, 74, true);
77  self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "%potion.regeneration", 205, 92, 171);
78  self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "%potion.resistance", 153, 69, 58);
79  self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", 228, 154, 58);
80  self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "%potion.waterBreathing", 46, 82, 153);
81  self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "%potion.invisibility", 127, 131, 146);
82 
83  self::$effects[Effect::BLINDNESS] = new Effect(Effect::BLINDNESS, "%potion.blindness", 191, 192, 192);
84  self::$effects[Effect::NIGHT_VISION] = new Effect(Effect::NIGHT_VISION, "%potion.nightVision", 0, 0, 139);
85  self::$effects[Effect::HUNGER] = new Effect(Effect::HUNGER, "%potion.hunger", 46, 139, 87);
86 
87  self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "%potion.weakness", 72, 77, 72, true);
88  self::$effects[Effect::POISON] = new Effect(Effect::POISON, "%potion.poison", 78, 147, 49, true);
89  self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "%potion.wither", 53, 42, 39, true);
90  self::$effects[Effect::HEALTH_BOOST] = new Effect(Effect::HEALTH_BOOST, "%potion.healthBoost", 248, 125, 35);
91 
92  self::$effects[Effect::ABSORPTION] = new Effect(Effect::ABSORPTION, "%potion.absorption", 36, 107, 251);
93  self::$effects[Effect::SATURATION] = new Effect(Effect::SATURATION, "%potion.saturation", 255, 0, 255);
94 
95  self::$effects[Effect::LEVITATION] = new Effect(Effect::LEVITATION, "%potion.levitation", 206, 255, 255);
96  }

◆ isAmbient()

isAmbient ( )
Returns
bool
221  {
222  return $this->ambient;
223  }

◆ isBad()

isBad ( )
Returns
bool
238  {
239  return $this->bad;
240  }

◆ isVisible()

isVisible ( )
Returns
bool
187  {
188  return $this->show;
189  }

◆ remove()

remove ( Entity  $entity)
Parameters
Entity$entity
408  {
409  if($entity instanceof Player){
410  $pk = new MobEffectPacket();
411  $pk->eid = $entity->getId();
412  $pk->eventId = MobEffectPacket::EVENT_REMOVE;
413  $pk->effectId = $this->getId();
414 
415  $entity->dataPacket($pk);
416 
417  if($this->id === Effect::SPEED){
418  $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
419  $attr->setValue($attr->getValue() / (1 + 0.2 * ($this->amplifier + 1)));
420  }elseif($this->id === Effect::SLOWNESS){
421  $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
422  $attr->setValue($attr->getValue() / (1 - 0.15 * ($this->amplifier + 1)));
423  }
424  }
425 
426  if($this->id === Effect::INVISIBILITY){
427  $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false);
428  $entity->setNameTagVisible(true);
429  }
430  }

◆ setAmbient()

setAmbient (   $ambient = true)
Parameters
bool$ambient
Returns
$this
230  {
231  $this->ambient = (bool) $ambient;
232  return $this;
233  }

◆ setAmplifier()

setAmplifier ( int  $amplifier)
Parameters
int$amplifier
Returns
$this
213  {
214  $this->amplifier = $amplifier & 0xff;
215  return $this;
216  }

◆ setColor()

setColor (   $r,
  $g,
  $b 
)
Parameters
$r
$g
$b
353  {
354  $this->color = (($r & 0xff) << 16) + (($g & 0xff) << 8) + ($b & 0xff);
355  }

◆ setDuration()

setDuration (   $ticks)
Parameters
$ticks
Returns
$this
175  {
176  $this->duration = (($ticks > self::MAX_DURATION) ? self::MAX_DURATION : $ticks);
177  return $this;
178  }

◆ setVisible()

setVisible (   $bool)
Parameters
$bool
Returns
$this
196  {
197  $this->show = (bool) $bool;
198  return $this;
199  }

Field Documentation

◆ $ambient

$ambient = false
protected

◆ $amplifier

$amplifier = 0
protected

◆ $bad

$bad
protected

◆ $color

$color
protected

◆ $duration

$duration
protected

◆ $effects

$effects
staticprotected

◆ $id

$id
protected

◆ $name

$name
protected

◆ $show

$show = true
protected

◆ ABSORPTION

const ABSORPTION = 22

◆ BLINDNESS

const BLINDNESS = 15

◆ CONFUSION

const CONFUSION = 9

◆ DAMAGE_RESISTANCE

const DAMAGE_RESISTANCE = 11

◆ FATIGUE

const FATIGUE = 4

◆ FIRE_RESISTANCE

const FIRE_RESISTANCE = 12

◆ HARMING

const HARMING = 7

◆ HASTE

const HASTE = 3

◆ HEALING

const HEALING = 6

◆ HEALTH_BOOST

const HEALTH_BOOST = 21

◆ HUNGER

const HUNGER = 17

◆ INVISIBILITY

const INVISIBILITY = 14

◆ JUMP

const JUMP = 8

◆ LEVITATION

const LEVITATION = 24

◆ MAX_DURATION

const MAX_DURATION = 2147483648

◆ MINING_FATIGUE

const MINING_FATIGUE = 4

◆ NAUSEA

const NAUSEA = 9

◆ NIGHT_VISION

const NIGHT_VISION = 16

◆ POISON

const POISON = 19

◆ REGENERATION

const REGENERATION = 10

◆ SATURATION

const SATURATION = 23

◆ SLOWNESS

const SLOWNESS = 2

◆ SPEED

const SPEED = 1

◆ STRENGTH

const STRENGTH = 5

◆ SWIFTNESS

const SWIFTNESS = 3

◆ WATER_BREATHING

const WATER_BREATHING = 13

◆ WEAKNESS

const WEAKNESS = 18

◆ WITHER

const WITHER = 20

The documentation for this class was generated from the following file: