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

@ -28,6 +28,12 @@ class SnowLayerBlock extends FlowableBlock{
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
}
}
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){
if($item->isShovel() !== false){

View file

@ -29,33 +29,13 @@ class IceBlock extends TransparentBlock{
}
return true;
}
private function scanForNearbyLightSources($offsetX, $offsetY, $offsetZ){
for($x = -$offsetX; $x <= $offsetX; ++$x){ //i hope it is possible to optimize it
for($z = -$offsetZ; $z <= $offsetZ; ++$z){
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 onRandomTick(Level $level, $x, $y, $z){
if($level->level->getBlockLight($x, $y, $z) > 11 - StaticBlock::$lightBlock[ICE]){
$level->fastSetBlockUpdate($x, $y, $z, STILL_WATER, true);
}
}
//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){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;

View file

@ -43,8 +43,9 @@ class Level{
WHEAT_BLOCK => true,
DIRT => 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){