mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Implemented effect colors
This commit is contained in:
parent
62ba36b474
commit
ebc8928c21
@ -2168,26 +2168,28 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
|
||||
break;
|
||||
case ProtocolInfo::MESSAGE_PACKET:
|
||||
case ProtocolInfo::TEXT_PACKET:
|
||||
if($this->spawned === false or $this->dead === true){
|
||||
break;
|
||||
}
|
||||
$this->craftingType = 0;
|
||||
$packet->message = TextFormat::clean($packet->message);
|
||||
if(trim($packet->message) != "" and strlen($packet->message) <= 255){
|
||||
$message = $packet->message;
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent($this, $message));
|
||||
if($ev->isCancelled()){
|
||||
break;
|
||||
}
|
||||
if(substr($ev->getMessage(), 0, 1) === "/"){ //Command
|
||||
Timings::$playerCommandTimer->startTiming();
|
||||
$this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
|
||||
Timings::$playerCommandTimer->stopTiming();
|
||||
}else{
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerChatEvent($this, $ev->getMessage()));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->server->broadcastMessage(sprintf($ev->getFormat(), $ev->getPlayer()->getDisplayName(), $ev->getMessage()), $ev->getRecipients());
|
||||
if($packet->type === TextPacket::TYPE_CHAT){
|
||||
$packet->message = TextFormat::clean($packet->message, $this->removeFormat);
|
||||
if(trim($packet->message) != "" and strlen($packet->message) <= 255){
|
||||
$message = $packet->message;
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent($this, $message));
|
||||
if($ev->isCancelled()){
|
||||
break;
|
||||
}
|
||||
if(substr($ev->getMessage(), 0, 1) === "/"){ //Command
|
||||
Timings::$playerCommandTimer->startTiming();
|
||||
$this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
|
||||
Timings::$playerCommandTimer->stopTiming();
|
||||
}else{
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerChatEvent($this, $ev->getMessage()));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->server->broadcastMessage(sprintf($ev->getFormat(), $ev->getPlayer()->getDisplayName(), $ev->getMessage()), $ev->getRecipients());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\entity\Effect;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\event\entity\EntityCombustByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||
@ -58,8 +59,10 @@ class Fire extends Flowable{
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
|
||||
$entity->attack($ev->getFinalDamage(), $ev);
|
||||
if(!$entity->hasEffect(Effect::FIRE_RESISTANCE)){
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
|
||||
$entity->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
|
||||
$ev = new EntityCombustByBlockEvent($this, $entity, 8);
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev);
|
||||
|
@ -32,6 +32,7 @@ class Effect{
|
||||
const SLOWNESS = 2;
|
||||
//TODO: const SWIFTNESS = 3;
|
||||
const FATIGUE = 4;
|
||||
const MINING_FATIGUE = 4;
|
||||
//TODO: const STRENGTH = 5;
|
||||
//TODO: const HEALING = 6;
|
||||
//TODO: const HARMING = 7;
|
||||
@ -58,22 +59,22 @@ class Effect{
|
||||
public static function init(){
|
||||
self::$effects = new \SplFixedArray(256);
|
||||
|
||||
self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "Speed");
|
||||
self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "Slowness", true);
|
||||
//self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "Swiftness");
|
||||
self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "Mining Fatigue", true);
|
||||
//self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "Strength");
|
||||
//self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "Healing");
|
||||
//self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "Harming", true);
|
||||
self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "Jump");
|
||||
self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "Regeneration");
|
||||
//self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "Damage Resistance");
|
||||
self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "Fire Resistance");
|
||||
self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "Water Breathing");
|
||||
self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "Invisibility");
|
||||
//self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "Weakness", true);
|
||||
self::$effects[Effect::POISON] = new Effect(Effect::POISON, "Poison", true);
|
||||
self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "Wither", true);
|
||||
self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "Speed", 124, 175, 198);
|
||||
self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "Slowness", 90, 108, 129, true);
|
||||
//self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "Swiftness", 217, 192, 67);
|
||||
self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "Mining Fatigue", 74, 66, 23, true);
|
||||
//self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "Strength", 147, 36, 35);
|
||||
//self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "Healing", 248, 36, 35);
|
||||
//self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "Harming", 67, 10, 9, true);
|
||||
self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "Jump", 34, 255, 76);
|
||||
self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "Regeneration", 205, 92, 171);
|
||||
//self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "Damage Resistance", 153, 69, 58);
|
||||
self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "Fire Resistance", 228, 154, 58);
|
||||
self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "Water Breathing", 46, 82, 153);
|
||||
self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "Invisibility", 127, 131, 146);
|
||||
//self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "Weakness", 72, 77, 72 , true);
|
||||
self::$effects[Effect::POISON] = new Effect(Effect::POISON, "Poison", 78, 147, 49, true);
|
||||
self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "Wither", 53, 42, 39, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,14 +104,19 @@ class Effect{
|
||||
|
||||
protected $amplifier;
|
||||
|
||||
protected $color;
|
||||
|
||||
protected $show = true;
|
||||
|
||||
protected $isBad;
|
||||
protected $ambient = false;
|
||||
|
||||
public function __construct($id, $name, $isBad = false){
|
||||
protected $bad;
|
||||
|
||||
public function __construct($id, $name, $r, $g, $b, $isBad = false){
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->isBad = (bool) $isBad;
|
||||
$this->bad = (bool) $isBad;
|
||||
$this->setColor($r, $g, $b);
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
@ -156,6 +162,19 @@ class Effect{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isAmbient(){
|
||||
return $this->ambient;
|
||||
}
|
||||
|
||||
public function setAmbient($ambient = true){
|
||||
$this->ambient = (bool) $ambient;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isBad(){
|
||||
return $this->bad;
|
||||
}
|
||||
|
||||
public function canTick(){
|
||||
switch($this->id){
|
||||
case Effect::POISON:
|
||||
@ -200,6 +219,14 @@ class Effect{
|
||||
}
|
||||
}
|
||||
|
||||
public function getColor(){
|
||||
return [$this->color >> 16, ($this->color >> 8) & 0xff, $this->color & 0xff];
|
||||
}
|
||||
|
||||
public function setColor($r, $g, $b){
|
||||
$this->color = (($r & 0xff) << 16) + (($g & 0xff) << 8) + ($b & 0xff);
|
||||
}
|
||||
|
||||
public function add(Entity $entity, $modify = false){
|
||||
$pk = new MobEffectPacket();
|
||||
$pk->eid = $entity->getId();
|
||||
|
@ -81,6 +81,8 @@ abstract class Entity extends Location implements Metadatable{
|
||||
const DATA_FLAGS = 0;
|
||||
const DATA_AIR = 1;
|
||||
const DATA_SHOW_NAMETAG = 3;
|
||||
const DATA_POTION_COLOR = 7;
|
||||
const DATA_POTION_VISIBLE = 8;
|
||||
|
||||
|
||||
const DATA_FLAG_ONFIRE = 0;
|
||||
@ -278,6 +280,8 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$effect = $this->effects[$effectId];
|
||||
unset($this->effects[$effectId]);
|
||||
$effect->remove($this);
|
||||
|
||||
$this->recalculateEffectColor();
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,6 +305,38 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
$this->effects[$effect->getId()] = $effect;
|
||||
|
||||
$this->recalculateEffectColor();
|
||||
}
|
||||
|
||||
protected function recalculateEffectColor(){
|
||||
$color = [0, 0, 0]; //RGB
|
||||
$count = 0;
|
||||
$ambient = true;
|
||||
foreach($this->effects as $effect){
|
||||
if($effect->isVisible()){
|
||||
$c = $effect->getColor();
|
||||
$color[0] += $c[0];
|
||||
$color[1] += $c[1];
|
||||
$color[2] += $c[2];
|
||||
++$count;
|
||||
if(!$effect->isAmbient()){
|
||||
$ambient = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($count > 0){
|
||||
$r = ($color[0] / $count) & 0xff;
|
||||
$g = ($color[1] / $count) & 0xff;
|
||||
$b = ($color[2] / $count) & 0xff;
|
||||
|
||||
$this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, ($r << 16) + ($g << 8) + $b);
|
||||
$this->setDataProperty(Entity::DATA_POTION_VISIBLE, Entity::DATA_TYPE_BYTE, $ambient ? 1 : 0);
|
||||
}else{
|
||||
$this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, 0);
|
||||
$this->setDataProperty(Entity::DATA_POTION_VISIBLE, Entity::DATA_TYPE_BYTE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,11 +64,15 @@ abstract class TextFormat{
|
||||
* Cleans the string from Minecraft codes and ANSI Escape Codes
|
||||
*
|
||||
* @param string $string
|
||||
* @param bool $removeFormat
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function clean($string){
|
||||
return preg_replace(["/§[0123456789abcdefklmnor]/", "/\x1b\\[[0-9;]+m/"], "", $string);
|
||||
public static function clean($string, $removeFormat = true){
|
||||
if($removeFormat){
|
||||
return preg_replace(["/§[0123456789abcdefklmnor]/", "/\x1b\\[[0-9;]+m/"], "", $string);
|
||||
}
|
||||
return preg_replace("/\x1b\\[[0-9;]+m/", "", $string);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user