mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-16 00:15:35 +00:00
remove utils\Color, use new pocketmine/color class
we're so close to separating protocol from core !!!
This commit is contained in:
parent
4437756987
commit
86db3af896
@ -43,6 +43,7 @@
|
||||
"pocketmine/callback-validator": "^1.0.1",
|
||||
"pocketmine/errorhandler": "^0.1.0",
|
||||
"pocketmine/uuid": "^0.1.0",
|
||||
"pocketmine/color": "^0.1.0",
|
||||
"adhocore/json-comment": "^0.1.0",
|
||||
"particle/validator": "^2.3",
|
||||
"netresearch/jsonmapper": "^2.0",
|
||||
|
36
composer.lock
generated
36
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "475fdc2cb5250b9813bc55fb87f7733c",
|
||||
"content-hash": "4bd35ad045d13f81b88bef943137c79f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/json-comment",
|
||||
@ -465,6 +465,40 @@
|
||||
"description": "Ad-hoc autoloading components used by PocketMine-MP",
|
||||
"time": "2020-01-31T14:26:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pocketmine/color",
|
||||
"version": "0.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/pmmp/Color.git",
|
||||
"reference": "10f3453d0eb3eccbccad5cf58a00e42cdaef1772"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/pmmp/Color/zipball/10f3453d0eb3eccbccad5cf58a00e42cdaef1772",
|
||||
"reference": "10f3453d0eb3eccbccad5cf58a00e42cdaef1772",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^0.12.25",
|
||||
"phpstan/phpstan-strict-rules": "^0.12.2"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"pocketmine\\color\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-3.0"
|
||||
],
|
||||
"description": "Color handling library used by PocketMine-MP and related projects",
|
||||
"time": "2020-05-14T19:15:33+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pocketmine/errorhandler",
|
||||
"version": "0.1.0",
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\utils;
|
||||
|
||||
use pocketmine\utils\Color;
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\utils\EnumTrait;
|
||||
|
||||
/**
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\command\defaults;
|
||||
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||
use pocketmine\item\ItemFactory;
|
||||
@ -31,7 +32,6 @@ use pocketmine\item\VanillaItems;
|
||||
use pocketmine\lang\TranslationContainer;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\utils\Color;
|
||||
use pocketmine\utils\Random;
|
||||
use pocketmine\utils\TextFormat;
|
||||
use pocketmine\world\particle\AngryVillagerParticle;
|
||||
|
@ -23,9 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity\effect;
|
||||
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Living;
|
||||
use pocketmine\utils\Color;
|
||||
|
||||
class Effect{
|
||||
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity\effect;
|
||||
|
||||
use pocketmine\utils\Color;
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\utils\Limits;
|
||||
use function max;
|
||||
|
||||
|
@ -24,10 +24,10 @@ declare(strict_types=1);
|
||||
namespace pocketmine\entity\effect;
|
||||
|
||||
use Ds\Set;
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\entity\Living;
|
||||
use pocketmine\event\entity\EntityEffectAddEvent;
|
||||
use pocketmine\event\entity\EntityEffectRemoveEvent;
|
||||
use pocketmine\utils\Color;
|
||||
use function abs;
|
||||
use function count;
|
||||
|
||||
|
@ -23,10 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity\effect;
|
||||
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Living;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\utils\Color;
|
||||
|
||||
class PoisonEffect extends Effect{
|
||||
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity\effect;
|
||||
|
||||
use pocketmine\utils\Color;
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\utils\RegistryTrait;
|
||||
use function assert;
|
||||
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\entity\projectile;
|
||||
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\entity\effect\EffectInstance;
|
||||
use pocketmine\entity\effect\InstantEffect;
|
||||
use pocketmine\entity\Living;
|
||||
@ -36,7 +37,6 @@ use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
use pocketmine\utils\Color;
|
||||
use pocketmine\world\particle\PotionSplashParticle;
|
||||
use pocketmine\world\sound\PotionSplashSound;
|
||||
use function count;
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\inventory\ArmorInventory;
|
||||
use pocketmine\item\enchantment\Enchantment;
|
||||
@ -33,7 +34,6 @@ use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\Color;
|
||||
use function lcg_value;
|
||||
use function mt_rand;
|
||||
|
||||
|
@ -25,11 +25,11 @@ namespace pocketmine\network\mcpe\protocol;
|
||||
|
||||
#include <rules/DataPacket.h>
|
||||
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\network\mcpe\protocol\serializer\NetworkBinaryStream;
|
||||
use pocketmine\network\mcpe\protocol\types\DimensionIds;
|
||||
use pocketmine\network\mcpe\protocol\types\MapDecoration;
|
||||
use pocketmine\network\mcpe\protocol\types\MapTrackedObject;
|
||||
use pocketmine\utils\Color;
|
||||
use function count;
|
||||
#ifndef COMPILE
|
||||
use pocketmine\utils\Binary;
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\network\mcpe\protocol\types;
|
||||
|
||||
use pocketmine\utils\Color;
|
||||
use pocketmine\color\Color;
|
||||
|
||||
class MapDecoration{
|
||||
/** @var int */
|
||||
|
@ -1,130 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\utils;
|
||||
|
||||
use function count;
|
||||
use function intdiv;
|
||||
|
||||
final class Color{
|
||||
|
||||
/** @var int */
|
||||
protected $a;
|
||||
/** @var int */
|
||||
protected $r;
|
||||
/** @var int */
|
||||
protected $g;
|
||||
/** @var int */
|
||||
protected $b;
|
||||
|
||||
public function __construct(int $r, int $g, int $b, int $a = 0xff){
|
||||
$this->r = $r & 0xff;
|
||||
$this->g = $g & 0xff;
|
||||
$this->b = $b & 0xff;
|
||||
$this->a = $a & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alpha (opacity) value of this colour.
|
||||
*/
|
||||
public function getA() : int{
|
||||
return $this->a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retuns the red value of this colour.
|
||||
*/
|
||||
public function getR() : int{
|
||||
return $this->r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the green value of this colour.
|
||||
*/
|
||||
public function getG() : int{
|
||||
return $this->g;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blue value of this colour.
|
||||
*/
|
||||
public function getB() : int{
|
||||
return $this->b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixes the supplied list of colours together to produce a result colour.
|
||||
*
|
||||
* @param Color ...$colors
|
||||
*/
|
||||
public static function mix(Color $color1, Color ...$colors) : Color{
|
||||
$colors[] = $color1;
|
||||
$count = count($colors);
|
||||
|
||||
$a = $r = $g = $b = 0;
|
||||
|
||||
foreach($colors as $color){
|
||||
$a += $color->a;
|
||||
$r += $color->r;
|
||||
$g += $color->g;
|
||||
$b += $color->b;
|
||||
}
|
||||
|
||||
return new Color(intdiv($r, $count), intdiv($g, $count), intdiv($b, $count), intdiv($a, $count));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Color from the supplied RGB colour code (24-bit)
|
||||
*/
|
||||
public static function fromRGB(int $code) : Color{
|
||||
return new Color(($code >> 16) & 0xff, ($code >> 8) & 0xff, $code & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Color from the supplied ARGB colour code (32-bit)
|
||||
*/
|
||||
public static function fromARGB(int $code) : Color{
|
||||
return new Color(($code >> 16) & 0xff, ($code >> 8) & 0xff, $code & 0xff, ($code >> 24) & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ARGB 32-bit colour value.
|
||||
*/
|
||||
public function toARGB() : int{
|
||||
return ($this->a << 24) | ($this->r << 16) | ($this->g << 8) | $this->b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Color from the supplied RGBA colour code (32-bit)
|
||||
*/
|
||||
public static function fromRGBA(int $c) : Color{
|
||||
return new Color(($c >> 24) & 0xff, ($c >> 16) & 0xff, ($c >> 8) & 0xff, $c & 0xff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an RGBA 32-bit colour value.
|
||||
*/
|
||||
public function toRGBA() : int{
|
||||
return ($this->r << 24) | ($this->g << 16) | ($this->b << 8) | $this->a;
|
||||
}
|
||||
}
|
@ -23,10 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\particle;
|
||||
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\ParticleIds;
|
||||
use pocketmine\utils\Color;
|
||||
|
||||
class DustParticle implements Particle{
|
||||
/** @var Color */
|
||||
|
@ -23,10 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\particle;
|
||||
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\ParticleIds;
|
||||
use pocketmine\utils\Color;
|
||||
|
||||
class InstantEnchantParticle implements Particle{
|
||||
/** @var Color */
|
||||
|
@ -23,9 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\particle;
|
||||
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||
use pocketmine\utils\Color;
|
||||
|
||||
class PotionSplashParticle implements Particle{
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user