mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 04:59:46 +00:00
forgot to add new files
This commit is contained in:
parent
945730e148
commit
28303a95fb
2 changed files with 32 additions and 0 deletions
9
src/material/block/LightingBlock.php
Normal file
9
src/material/block/LightingBlock.php
Normal 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
23
src/utils/LightUtils.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue