forgot to add new files

This commit is contained in:
GameHerobrine 2022-05-11 19:49:17 +03:00
parent 945730e148
commit 28303a95fb
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,9 @@
<?php
/*
BLOCKS:
BurningFurnace, Fire, GlowingObsidian, GlowingRedstoneOre, Glowstone, Lava, LitPumpkin, Torch
*/
interface LightingBlock{
/*Max light distance (Used to melt ice)*/
public function getMaxLightValue(); /*number of blocks must always be Integer */
}

23
src/utils/LightUtils.php Normal file
View file

@ -0,0 +1,23 @@
<?php
class LightUtils {
/*
args: $source: <Block> 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);
}
}