added ice and snow layer melting based on light level

This commit is contained in:
GameHerobrine 2025-11-30 01:55:31 +03:00
parent 3256a957d3
commit a6d96c4ac7
3 changed files with 14 additions and 27 deletions

View file

@ -29,6 +29,12 @@ class SnowLayerBlock extends FlowableBlock{
} }
} }
public static function onRandomTick(Level $level, $x, $y, $z){
if($level->level->getBlockLight($x, $y, $z) > 11){
$level->fastSetBlockUpdate($x, $y, $z, 0, true);
}
}
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->isShovel() !== false){ if($item->isShovel() !== false){
return array( return array(

View file

@ -30,32 +30,12 @@ class IceBlock extends TransparentBlock{
return true; return true;
} }
private function scanForNearbyLightSources($offsetX, $offsetY, $offsetZ){ public static function onRandomTick(Level $level, $x, $y, $z){
for($x = -$offsetX; $x <= $offsetX; ++$x){ //i hope it is possible to optimize it if($level->level->getBlockLight($x, $y, $z) > 11 - StaticBlock::$lightBlock[ICE]){
for($z = -$offsetZ; $z <= $offsetZ; ++$z){ $level->fastSetBlockUpdate($x, $y, $z, STILL_WATER, true);
for($y = -$offsetY; $y <= $offsetY; ++$y){
$pX = $this->x+$x;
$pY = $this->y+$y;
$pZ = $this->z+$z;
$block = $this->level->getBlock(new Vector3($pX, $pY, $pZ)); //D= slow what was u thinking of gameherobrine from 2022
if($block instanceof LightingBlock){ //idk is it possible to make it better
return $block;
}
}
}
} }
} }
//public static function onUpdate(Level $level, $x, $y, $z, $type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/
/*if($type === BLOCK_UPDATE_RANDOM){
$light = $this->scanForNearbyLightSources(3,3,3);
if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){
$this->level->setBlock($this, new WaterBlock(), true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); //additional request for update
}
return BLOCK_UPDATE_RANDOM;
}
return false;*/ //TODO ice melting(after light?)
//}
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;

View file

@ -43,8 +43,9 @@ class Level{
WHEAT_BLOCK => true, WHEAT_BLOCK => true,
DIRT => true, DIRT => true,
GRASS => true, GRASS => true,
ICE => true, LEAVES => true,
LEAVES => true SNOW_LAYER => true,
ICE => true
]; ];
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){