From f58ee2028e6f1a0eb7bf8b5a89e0ceef7c619c54 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 12 Mar 2017 19:52:57 +0000 Subject: [PATCH] Moved effects stuff to json --- src/pocketmine/entity/Effect.php | 44 ++++----- src/pocketmine/lang/locale | 2 +- src/pocketmine/resources/effects.json | 131 ++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 28 deletions(-) create mode 100644 src/pocketmine/resources/effects.json diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 9e95cd20b..f55c4b1de 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -28,6 +28,7 @@ use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\player\PlayerExhaustEvent; use pocketmine\network\mcpe\protocol\MobEffectPacket; use pocketmine\Player; +use pocketmine\utils\Config; class Effect{ const SPEED = 1; @@ -58,34 +59,23 @@ class Effect{ const SATURATION = 23; /** @var Effect[] */ - protected static $effects; + protected static $effects = []; public static function init(){ - self::$effects = new \SplFixedArray(256); + $config = new Config(\pocketmine\PATH . "src/pocketmine/resources/effects.json", Config::JSON, []); - self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "%potion.moveSpeed", 124, 175, 198); - self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "%potion.moveSlowdown", 90, 108, 129, true); - self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "%potion.digSpeed", 217, 192, 67); - self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "%potion.digSlowDown", 74, 66, 23, true); - self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "%potion.damageBoost", 147, 36, 35); - //self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "%potion.heal", 248, 36, 35); - //self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "%potion.harm", 67, 10, 9, true); - self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "%potion.jump", 34, 255, 76); - self::$effects[Effect::NAUSEA] = new Effect(Effect::NAUSEA, "%potion.confusion", 85, 29, 74, true); - self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "%potion.regeneration", 205, 92, 171); - self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "%potion.resistance", 153, 69, 58); - self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", 228, 154, 58); - self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "%potion.waterBreathing", 46, 82, 153); - self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "%potion.invisibility", 127, 131, 146); - self::$effects[Effect::BLINDNESS] = new Effect(Effect::BLINDNESS, "%potion.blindness", 191, 192, 192); - self::$effects[Effect::NIGHT_VISION] = new Effect(Effect::NIGHT_VISION, "%potion.nightVision", 0, 0, 139); - self::$effects[Effect::HUNGER] = new Effect(Effect::HUNGER, "%potion.hunger", 46, 139, 87); - self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "%potion.weakness", 72, 77, 72, true); - self::$effects[Effect::POISON] = new Effect(Effect::POISON, "%potion.poison", 78, 147, 49, true); - self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "%potion.wither", 53, 42, 39, true); - self::$effects[Effect::HEALTH_BOOST] = new Effect(Effect::HEALTH_BOOST, "%potion.healthBoost", 248, 125, 35); - self::$effects[Effect::ABSORPTION] = new Effect(Effect::ABSORPTION, "%potion.absorption", 36, 107, 251); - self::$effects[Effect::SATURATION] = new Effect(Effect::SATURATION, "%potion.saturation", 255, 0, 255); + foreach($config->getAll() as $name => $data){ + $color = hexdec($data["color"]); + $r = ($color >> 16) & 0xff; + $g = ($color >> 8) & 0xff; + $b = $color & 0xff; + self::registerEffect($name, new Effect($data["id"], "%" . $data["name"], $r, $g, $b, $data["isBad"] ?? false)); + } + } + + public static function registerEffect(string $internalName, Effect $effect){ + self::$effects[$effect->getId()] = $effect; + self::$effects[$internalName] = $effect; } /** @@ -101,8 +91,8 @@ class Effect{ } public static function getEffectByName($name){ - if(defined(Effect::class . "::" . strtoupper($name))){ - return self::getEffect(constant(Effect::class . "::" . strtoupper($name))); + if(isset(self::$effects[$name])){ + return clone self::$effects[$name]; } return null; } diff --git a/src/pocketmine/lang/locale b/src/pocketmine/lang/locale index 8d56e216b..a1c4d8f11 160000 --- a/src/pocketmine/lang/locale +++ b/src/pocketmine/lang/locale @@ -1 +1 @@ -Subproject commit 8d56e216be03710208800ba31aa3b63612742623 +Subproject commit a1c4d8f117f27b7da42a9db644e3c252c1fc033a diff --git a/src/pocketmine/resources/effects.json b/src/pocketmine/resources/effects.json new file mode 100644 index 000000000..b750536dd --- /dev/null +++ b/src/pocketmine/resources/effects.json @@ -0,0 +1,131 @@ +{ + "speed": { + "id": 1, + "color": "7cafc6", + "name": "potion.moveSpeed" + }, + "slowness": { + "id": 2, + "color": "5a6c81", + "name": "potion.moveSlowdown", + "isBad": true + }, + "haste": { + "id": 3, + "color": "d9c043", + "name": "potion.digSpeed" + }, + "mining_fatigue": { + "id": 4, + "color": "4a4217", + "name": "potion.digSlowDown", + "isBad": true + }, + "strength": { + "id": 5, + "color": "932423", + "name": "potion.damageBoost" + }, + "instant_health": { + "id": 6, + "color": "f82423", + "name": "potion.heal" + }, + "instant_damage": { + "id": 7, + "color": "430a09", + "name": "potion.harm", + "isBad": true + }, + "jump_boost": { + "id": 8, + "color": "22ff4c", + "name": "potion.jump" + }, + "nausea": { + "id": 9, + "color": "551d4a", + "name": "potion.confusion", + "isBad": true + }, + "regeneration": { + "id": 10, + "color": "cd5cab", + "name": "potion.regeneration" + }, + "resistance": { + "id": 11, + "color": "99453a", + "name": "potion.resistance" + }, + "fire_resistance": { + "id": 12, + "color": "e49a3a", + "name": "potion.fireResistance" + }, + "water_breathing": { + "id": 13, + "color": "2e5299", + "name": "potion.waterBreathing" + }, + "invisibility": { + "id": 14, + "color": "7f8392", + "name": "potion.invisibility" + }, + "blindness": { + "id": 15, + "color": "1f1f23", + "name": "potion.blindness", + "isBad": true + }, + "night_vision": { + "id": 16, + "color": "1f1fa1", + "name": "potion.nightVision" + }, + "hunger": { + "id": 17, + "color": "587653", + "name": "potion.hunger", + "isBad": true + }, + "weakness": { + "id": 18, + "color": "484d48", + "name": "potion.weakness", + "isBad": true + }, + "poison": { + "id": 19, + "color": "4e9331", + "name": "potion.poison", + "isBad": true + }, + "wither": { + "id": 20, + "color": "352a27", + "name": "potion.wither", + "isBad": true + }, + "health_boost": { + "id": 21, + "color": "f87d23", + "name": "potion.healthBoost" + }, + "absorption": { + "id": 22, + "color": "2552a5", + "name": "potion.absorption" + }, + "saturation": { + "id": 23, + "color": "f82423", + "name": "potion.saturation" + }, + "levitation": { + "id": 24, + "color": "ceffff", + "name": "potion.levitation" + } +} \ No newline at end of file