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

Public Member Functions

 __construct ($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend=true)
 
 getMinValue ()
 
 setMinValue ($minValue)
 
 getMaxValue ()
 
 setMaxValue ($maxValue)
 
 getDefaultValue ()
 
 setDefaultValue ($defaultValue)
 
 getValue ()
 
 setValue ($value, bool $fit=true, bool $shouldSend=false)
 
 getName ()
 
 getId ()
 
 isSyncable ()
 
 isDesynchronized ()
 
 markSynchronized (bool $synced=true)
 

Static Public Member Functions

static init ()
 
static addAttribute ($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend=true)
 
static getAttribute ($id)
 
static getAttributeByName ($name)
 

Data Fields

const ABSORPTION = 0
 
const SATURATION = 1
 
const EXHAUSTION = 2
 
const KNOCKBACK_RESISTANCE = 3
 
const HEALTH = 4
 
const MOVEMENT_SPEED = 5
 
const FOLLOW_RANGE = 6
 
const HUNGER = 7
 
const FOOD = 7
 
const ATTACK_DAMAGE = 8
 
const EXPERIENCE_LEVEL = 9
 
const EXPERIENCE = 10
 

Protected Attributes

 $minValue
 
 $maxValue
 
 $defaultValue
 
 $currentValue
 
 $name
 
 $shouldSend
 
 $desynchronized = true
 

Static Protected Attributes

static $attributes = []
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $id,
  $name,
  $minValue,
  $maxValue,
  $defaultValue,
  $shouldSend = true 
)

Attribute constructor.

Parameters
$id
$name
$minValue
$maxValue
$defaultValue
bool$shouldSend
121  {
122  $this->id = (int) $id;
123  $this->name = (string) $name;
124  $this->minValue = (float) $minValue;
125  $this->maxValue = (float) $maxValue;
126  $this->defaultValue = (float) $defaultValue;
127  $this->shouldSend = (bool) $shouldSend;
128 
129  $this->currentValue = $this->defaultValue;
130  }

Member Function Documentation

◆ addAttribute()

static addAttribute (   $id,
  $name,
  $minValue,
  $maxValue,
  $defaultValue,
  $shouldSend = true 
)
static
Parameters
int$id
string$name
float$minValue
float$maxValue
float$defaultValue
bool$shouldSend
Returns
Attribute
79  {
81  throw new \InvalidArgumentException("Invalid ranges: min value: $minValue, max value: $maxValue, $defaultValue: $defaultValue");
82  }
83 
84  return self::$attributes[(int) $id] = new Attribute($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend);
85  }

◆ getAttribute()

static getAttribute (   $id)
static
Parameters
$id
Returns
null|Attribute
92  {
93  return isset(self::$attributes[$id]) ? clone self::$attributes[$id] : null;
94  }

◆ getAttributeByName()

static getAttributeByName (   $name)
static
Parameters
$name
Returns
null|Attribute
101  {
102  foreach(self::$attributes as $a){
103  if($a->getName() === $name){
104  return clone $a;
105  }
106  }
107 
108  return null;
109  }

◆ getDefaultValue()

getDefaultValue ( )
Returns
float
183  {
184  return $this->defaultValue;
185  }

◆ getId()

getId ( )
Returns
int
247  {
248  return $this->id;
249  }

◆ getMaxValue()

getMaxValue ( )
Returns
float
159  {
160  return $this->maxValue;
161  }

◆ getMinValue()

getMinValue ( )
Returns
float
135  {
136  return $this->minValue;
137  }

◆ getName()

getName ( )
Returns
string
240  {
241  return $this->name;
242  }

◆ getValue()

getValue ( )
Returns
float
207  {
208  return $this->currentValue;
209  }

◆ init()

static init ( )
static
54  {
55  self::addAttribute(self::ABSORPTION, "minecraft:absorption", 0.00, 340282346638528859811704183484516925440.00, 0.00);
56  self::addAttribute(self::SATURATION, "minecraft:player.saturation", 0.00, 20.00, 5.00);
57  self::addAttribute(self::EXHAUSTION, "minecraft:player.exhaustion", 0.00, 5.00, 0.41);
58  self::addAttribute(self::KNOCKBACK_RESISTANCE, "minecraft:knockback_resistance", 0.00, 1.00, 0.00);
59  self::addAttribute(self::HEALTH, "minecraft:health", 0.00, 20.00, 20.00);
60  self::addAttribute(self::MOVEMENT_SPEED, "minecraft:movement", 0.00, 340282346638528859811704183484516925440.00, 0.10);
61  self::addAttribute(self::FOLLOW_RANGE, "minecraft:follow_range", 0.00, 2048.00, 16.00, false);
62  self::addAttribute(self::HUNGER, "minecraft:player.hunger", 0.00, 20.00, 20.00);
63  self::addAttribute(self::ATTACK_DAMAGE, "minecraft:attack_damage", 0.00, 340282346638528859811704183484516925440.00, 1.00, false);
64  self::addAttribute(self::EXPERIENCE_LEVEL, "minecraft:player.level", 0.00, 24791.00, 0.00);
65  self::addAttribute(self::EXPERIENCE, "minecraft:player.experience", 0.00, 1.00, 0.00);
66  //TODO: minecraft:luck (for fishing?)
67  }

◆ isDesynchronized()

isDesynchronized ( )
Returns
bool
261  : bool{
262  return $this->shouldSend and $this->desynchronized;
263  }

◆ isSyncable()

isSyncable ( )
Returns
bool
254  {
255  return $this->shouldSend;
256  }

◆ markSynchronized()

markSynchronized ( bool  $synced = true)
Parameters
bool$synced
268  {
269  $this->desynchronized = !$synced;
270  }

◆ setDefaultValue()

setDefaultValue (   $defaultValue)
Parameters
$defaultValue
Returns
$this
192  {
193  if($defaultValue > $this->getMaxValue() or $defaultValue < $this->getMinValue()){
194  throw new \InvalidArgumentException("Value $defaultValue exceeds the range!");
195  }
196 
197  if($this->defaultValue !== $defaultValue){
198  $this->desynchronized = true;
199  $this->defaultValue = $defaultValue;
200  }
201  return $this;
202  }

◆ setMaxValue()

setMaxValue (   $maxValue)
Parameters
$maxValue
Returns
$this
168  {
169  if($maxValue < $this->getMinValue()){
170  throw new \InvalidArgumentException("Value $maxValue is bigger than the minValue!");
171  }
172 
173  if($this->maxValue != $maxValue){
174  $this->desynchronized = true;
175  $this->maxValue = $maxValue;
176  }
177  return $this;
178  }

◆ setMinValue()

setMinValue (   $minValue)
Parameters
$minValue
Returns
$this
144  {
145  if($minValue > $this->getMaxValue()){
146  throw new \InvalidArgumentException("Value $minValue is bigger than the maxValue!");
147  }
148 
149  if($this->minValue != $minValue){
150  $this->desynchronized = true;
151  $this->minValue = $minValue;
152  }
153  return $this;
154  }

◆ setValue()

setValue (   $value,
bool  $fit = true,
bool  $shouldSend = false 
)
Parameters
$value
bool$fit
bool$shouldSend
Returns
$this
218  {
219  if($value > $this->getMaxValue() or $value < $this->getMinValue()){
220  if(!$fit){
221  Server::getInstance()->getLogger()->error("[Attribute / {$this->getName()}] Value $value exceeds the range!");
222  }
223  $value = min(max($value, $this->getMinValue()), $this->getMaxValue());
224  }
225 
226  if($this->currentValue != $value){
227  $this->desynchronized = true;
228  $this->currentValue = $value;
229  }
230 
231  if($shouldSend){
232  $this->desynchronized = true;
233  }
234  return $this;
235  }

Field Documentation

◆ $attributes

$attributes = []
staticprotected

◆ $currentValue

$currentValue
protected

◆ $defaultValue

$defaultValue
protected

◆ $desynchronized

$desynchronized = true
protected

◆ $maxValue

$maxValue
protected

◆ $minValue

$minValue
protected

◆ $name

$name
protected

◆ $shouldSend

$shouldSend
protected

◆ ABSORPTION

const ABSORPTION = 0

◆ ATTACK_DAMAGE

const ATTACK_DAMAGE = 8

◆ EXHAUSTION

const EXHAUSTION = 2

◆ EXPERIENCE

const EXPERIENCE = 10

◆ EXPERIENCE_LEVEL

const EXPERIENCE_LEVEL = 9

◆ FOLLOW_RANGE

const FOLLOW_RANGE = 6

◆ FOOD

const FOOD = 7

◆ HEALTH

const HEALTH = 4

◆ HUNGER

const HUNGER = 7

◆ KNOCKBACK_RESISTANCE

const KNOCKBACK_RESISTANCE = 3

◆ MOVEMENT_SPEED

const MOVEMENT_SPEED = 5

◆ SATURATION

const SATURATION = 1

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