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

@ -39,15 +39,11 @@ class BeetrootBlock extends FlowableBlock{
return false;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(BEETROOT_SEEDS, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(BEETROOT_SEEDS, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
return false;
}
public function getDrops(Item $item, Player $player){

View file

@ -6,13 +6,11 @@ class BrownMushroomBlock extends FlowableBlock{
$this->hardness = 0;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(BROWN_MUSHROOM));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -25,8 +25,7 @@ class CactusBlock extends TransparentBlock{
for($yy = 1; $yy < 3; ++$yy){
$bID = $level->level->getBlockID($x, $y + $yy, $z);
if($bID === AIR){
$level->fastSetBlockUpdate($x, $y + $yy, $z, CACTUS, 0);
CactusBlock::onUpdate($level, $x, $y + $yy, $z, BLOCK_UPDATE_NORMAL); //TODO rewrite ticking
$level->fastSetBlockUpdate($x, $y + $yy, $z, CACTUS, 0, true);
break;
}
}
@ -39,20 +38,16 @@ class CactusBlock extends TransparentBlock{
}
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$down = $level->level->getBlockID($x, $y, $z);
$b0 = $level->level->getBlockID($x, $y, $z - 1);
$b1 = $level->level->getBlockID($x, $y, $z + 1);
$b2 = $level->level->getBlockID($x - 1, $y, $z);
$b3 = $level->level->getBlockID($x + 1, $y, $z);
if(!StaticBlock::getIsFlowable($b0) || !StaticBlock::getIsFlowable($b1) || !StaticBlock::getIsFlowable($b2) || !StaticBlock::getIsFlowable($b3) || ($down !== SAND and $down !== CACTUS)){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CACTUS));
return BLOCK_UPDATE_NORMAL;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$down = $level->level->getBlockID($x, $y, $z);
$b0 = $level->level->getBlockID($x, $y, $z - 1);
$b1 = $level->level->getBlockID($x, $y, $z + 1);
$b2 = $level->level->getBlockID($x - 1, $y, $z);
$b3 = $level->level->getBlockID($x + 1, $y, $z);
if(!StaticBlock::getIsFlowable($b0) || !StaticBlock::getIsFlowable($b1) || !StaticBlock::getIsFlowable($b2) || !StaticBlock::getIsFlowable($b3) || ($down !== SAND and $down !== CACTUS)){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CACTUS));
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -41,15 +41,11 @@ class CarrotBlock extends FlowableBlock{
}
}
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CARROT, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CARROT, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
return false;
}
public function getDrops(Item $item, Player $player){

View file

@ -20,15 +20,15 @@ class CyanFlowerBlock extends FlowableBlock{
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){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(CYAN_FLOWER));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
if(($player->gamemode & 0x01) === 0){

View file

@ -18,13 +18,11 @@ class DandelionBlock extends FlowableBlock{
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){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(DANDELION));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public function onActivate(Item $item, Player $player){

View file

@ -11,14 +11,10 @@ class DeadBushBlock extends FlowableBlock{
return null;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
$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

@ -43,15 +43,11 @@ class MelonStemBlock extends FlowableBlock{
}
}
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
return false;
}
public function onActivate(Item $item, Player $player){

View file

@ -41,15 +41,11 @@ class PotatoBlock extends FlowableBlock{
return false;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(POTATO, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(POTATO, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
return false;
}
public function getDrops(Item $item, Player $player){

View file

@ -43,15 +43,11 @@ class PumpkinStemBlock extends FlowableBlock{
}
}
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
return false;
}
public function onActivate(Item $item, Player $player){

View file

@ -6,13 +6,11 @@ class RedMushroomBlock extends FlowableBlock{
$this->hardness = 0;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(RED_MUSHROOM));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -42,14 +42,12 @@ class SaplingBlock extends FlowableBlock{
}
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){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
[$id, $meta] = $level->level->getBlock($x, $y, $z);
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem($id, $meta));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(1,7) === 1){

View file

@ -36,7 +36,7 @@ class SugarcaneBlock extends FlowableBlock{
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){
$down = $level->level->getBlockID($x, $y - 1, $z);
if($down == GRASS or $down == DIRT or $down == SAND){
$b0 = $level->level->getBlockID($x, $y - 1, $z - 1);
@ -46,15 +46,12 @@ class SugarcaneBlock extends FlowableBlock{
if($b0 != WATER && $b0 != STILL_WATER && $b1 != WATER && $b1 != STILL_WATER && $b2 != WATER && $b2 != STILL_WATER && $b3 != WATER && $b3 != STILL_WATER){
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SUGARCANE));
return true;
}
}
if(StaticBlock::getIsTransparent($down) && $down != SUGARCANE_BLOCK){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(SUGARCANE));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public static function onRandomTick(Level $level, $x, $y, $z){
$aboveID = $level->level->getBlockID($x, $y + 1, $z);

View file

@ -13,13 +13,11 @@ class TallGrassBlock extends FlowableBlock{
$this->hardness = 0;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(WHEAT_SEEDS));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
return false;
}
public static function getAABB(Level $level, $x, $y, $z){

View file

@ -41,15 +41,11 @@ class WheatBlock extends FlowableBlock{
}
}
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
return false;
}
public function getDrops(Item $item, Player $player){