From 28303a95fb047e48370a51792edf34f11d9a7ae9 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 11 May 2022 19:49:17 +0300 Subject: [PATCH] forgot to add new files --- src/material/block/LightingBlock.php | 9 +++++++++ src/utils/LightUtils.php | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/material/block/LightingBlock.php create mode 100644 src/utils/LightUtils.php diff --git a/src/material/block/LightingBlock.php b/src/material/block/LightingBlock.php new file mode 100644 index 00000000..694574ab --- /dev/null +++ b/src/material/block/LightingBlock.php @@ -0,0 +1,9 @@ + instanceof LightingBlock, $block: Block + */ + public static function getLightValueFromNearbySource($source, $block){ + if($source === null || $block === null){ + return 0; + } + $distance = sqrt(LightUtils::sqr($source->x - $block->x)+LightUtils::sqr($source->y - $block->y)+LightUtils::sqr($source->z - $block->z)); /*Distance between 2 3d objects*/ + $result = floor($source->getMaxLightValue() - $distance); //i dont need something like 0.2192032434454... + return $result <= 0 ? 0 : $result; //if result is smaller or equals 0 then return 0 else return result + } + + /* Used only internally for calculating 2^(2) */ + private static function sqr($val){ + return pow($val,2); + } + +} + +