PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
AttributeFactory.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\entity;
25
26use pocketmine\utils\SingletonTrait;
27
28final class AttributeFactory{
29 use SingletonTrait;
30
32 private array $attributes = [];
33
34 public function __construct(){
35 $this->register(Attribute::ABSORPTION, 0.00, 340282346638528859811704183484516925440.00, 0.00);
36 $this->register(Attribute::SATURATION, 0.00, 20.00, 20.00);
37 $this->register(Attribute::EXHAUSTION, 0.00, 5.00, 0.0, false);
38 $this->register(Attribute::KNOCKBACK_RESISTANCE, 0.00, 1.00, 0.00);
39 $this->register(Attribute::HEALTH, 0.00, 20.00, 20.00);
40 $this->register(Attribute::MOVEMENT_SPEED, 0.00, 340282346638528859811704183484516925440.00, 0.10);
41 $this->register(Attribute::FOLLOW_RANGE, 0.00, 2048.00, 16.00, false);
42 $this->register(Attribute::HUNGER, 0.00, 20.00, 20.00);
43 $this->register(Attribute::ATTACK_DAMAGE, 0.00, 340282346638528859811704183484516925440.00, 1.00, false);
44 $this->register(Attribute::EXPERIENCE_LEVEL, 0.00, 24791.00, 0.00);
45 $this->register(Attribute::EXPERIENCE, 0.00, 1.00, 0.00);
46 $this->register(Attribute::UNDERWATER_MOVEMENT, 0.0, 340282346638528859811704183484516925440.0, 0.02);
47 $this->register(Attribute::LUCK, -1024.0, 1024.0, 0.0);
48 $this->register(Attribute::FALL_DAMAGE, 0.0, 340282346638528859811704183484516925440.0, 1.0);
49 $this->register(Attribute::HORSE_JUMP_STRENGTH, 0.0, 2.0, 0.7);
50 $this->register(Attribute::ZOMBIE_SPAWN_REINFORCEMENTS, 0.0, 1.0, 0.0);
51 $this->register(Attribute::LAVA_MOVEMENT, 0.0, 340282346638528859811704183484516925440.0, 0.02);
52 }
53
54 public function get(string $id) : ?Attribute{
55 return isset($this->attributes[$id]) ? clone $this->attributes[$id] : null;
56 }
57
58 public function mustGet(string $id) : Attribute{
59 $result = $this->get($id);
60 if($result === null){
61 throw new \InvalidArgumentException("Attribute $id is not registered");
62 }
63 return $result;
64 }
65
69 public function register(string $id, float $minValue, float $maxValue, float $defaultValue, bool $shouldSend = true) : Attribute{
70 return $this->attributes[$id] = new Attribute($id, $minValue, $maxValue, $defaultValue, $shouldSend);
71 }
72}