separated neighbor updates and scheduled updates

This commit is contained in:
GameHerobrine 2024-05-22 06:15:34 +03:00
parent ee989ef556
commit 2ebc482e3d
36 changed files with 197 additions and 262 deletions

View file

@ -40,7 +40,7 @@ class LadderBlock extends TransparentBlock{
return false;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$side = $level->level->getBlockDamage($x, $y, $z);
$attached = match($side){
@ -54,9 +54,7 @@ class LadderBlock extends TransparentBlock{
if($attached == AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(LADDER, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public function getDrops(Item $item, Player $player){

View file

@ -33,14 +33,12 @@ class SignPostBlock extends TransparentBlock{
return false;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){ //TODO remove $type
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SIGN, 0, 1));
//$this->level->setBlock($this, new AirBlock(), true, true, true);
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public function onBreak(Item $item, Player $player){

View file

@ -14,24 +14,20 @@ class TorchBlock extends FlowableBlock implements LightingBlock{
return null;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$side = $level->level->getBlockDamage($x, $y, $z);
$attach = match($side){
1 => $level->level->getBlockID($x - 1, $y, $z),
2 => $level->level->getBlockID($x + 1, $y, $z),
3 => $level->level->getBlockID($x, $y, $z - 1),
4 => $level->level->getBlockID($x, $y, $z + 1),
default => $level->level->getBlockID($x, $y - 1, $z)
};
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$side = $level->level->getBlockDamage($x, $y, $z);
$attach = match($side){
1 => $level->level->getBlockID($x - 1, $y, $z),
2 => $level->level->getBlockID($x + 1, $y, $z),
3 => $level->level->getBlockID($x, $y, $z - 1),
4 => $level->level->getBlockID($x, $y, $z + 1),
default => $level->level->getBlockID($x, $y - 1, $z)
};
if(StaticBlock::getIsTransparent($attach) && !($side === 0 && $attach === FENCE)){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
if(StaticBlock::getIsTransparent($attach) && !($side === 0 && $attach === FENCE)){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -74,24 +74,21 @@ class TrapdoorBlock extends TransparentBlock{
array($this->id, 0, 1),
);
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$attach = match($level->level->getBlockDamage($x, $y, $z)){
0, 4 => $level->level->getBlockID($x, $y, $z + 1),
1, 5 => $level->level->getBlockID($x, $y, $z - 1),
2, 6 => $level->level->getBlockID($x + 1, $y, $z),
3, 7 => $level->level->getBlockID($x - 1, $y, $z),
default => 0
};
$attach = match($level->level->getBlockDamage($x, $y, $z)){
0, 4 => $level->level->getBlockID($x, $y, $z + 1),
1, 5 => $level->level->getBlockID($x, $y, $z - 1),
2, 6 => $level->level->getBlockID($x + 1, $y, $z),
3, 7 => $level->level->getBlockID($x - 1, $y, $z),
default => 0
};
if($attach == AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TRAPDOOR, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL;
}
if($attach == AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TRAPDOOR, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
}
}
public function onActivate(Item $item, Player $player){
$this->meta ^= 0x04;
$this->level->setBlock($this, $this, true, false, true);

View file

@ -10,8 +10,7 @@ class WallSignBlock extends SignPostBlock{
$this->isSolid = false;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$attached = match($level->level->getBlockDamage($x, $y, $z)){
2 => $level->level->getBlockID($x, $y, $z + 1),
3 => $level->level->getBlockID($x, $y, $z - 1),
@ -19,12 +18,10 @@ class WallSignBlock extends SignPostBlock{
5 => $level->level->getBlockID($x - 1, $y, $z),
default => WALL_SIGN
};
if(!StaticBlock::getIsSolid($attached) && $attached != SIGN_POST && $attached != WALL_SIGN){
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true);
(ServerAPI::request())->api->entity->drop(new Position($x + 0.5, $y + 0.5, $z + 0.5, $level), BlockAPI::getItem(SIGN, 0, 1));
}
return false;
}
}