remove utils\Color, use new pocketmine/color class

we're so close to separating protocol from core !!!
This commit is contained in:
Dylan K. Taylor
2020-05-14 20:38:08 +01:00
parent 4437756987
commit 86db3af896
17 changed files with 50 additions and 145 deletions

View File

@@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block\utils;
use pocketmine\utils\Color;
use pocketmine\color\Color;
use pocketmine\utils\EnumTrait;
/**

View File

@@ -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;

View File

@@ -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{

View File

@@ -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;

View File

@@ -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;

View File

@@ -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{

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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;
}
}

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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{