onUpdate is now static, disabled rail, water and lava updates to rework.

This commit is contained in:
GameHerobrine 2024-05-20 13:16:48 +03:00
parent 3c37dc446e
commit ee989ef556
38 changed files with 329 additions and 367 deletions

View file

@ -39,11 +39,11 @@ class BeetrootBlock extends FlowableBlock{
return false;
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(BEETROOT_SEEDS, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
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;
}
}

View file

@ -6,13 +6,11 @@ class BrownMushroomBlock extends FlowableBlock{
$this->hardness = 0;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
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;
}

View file

@ -26,7 +26,7 @@ class CactusBlock extends TransparentBlock{
$bID = $level->level->getBlockID($x, $y + $yy, $z);
if($bID === AIR){
$level->fastSetBlockUpdate($x, $y + $yy, $z, CACTUS, 0);
$level->getBlockWithoutVector($x, $y + $yy, $z)->onUpdate(BLOCK_UPDATE_NORMAL); //TODO rewrite ticking
CactusBlock::onUpdate($level, $x, $y + $yy, $z, BLOCK_UPDATE_NORMAL); //TODO rewrite ticking
break;
}
}
@ -39,16 +39,16 @@ class CactusBlock extends TransparentBlock{
}
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
$block0 = $this->getSide(2);
$block1 = $this->getSide(3);
$block2 = $this->getSide(4);
$block3 = $this->getSide(5);
if($block0->isFlowable === false or $block1->isFlowable === false or $block2->isFlowable === false or $block3->isFlowable === false or ($down->getID() !== SAND and $down->getID() !== CACTUS)){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true);
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem($this->id));
$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;
}
}

View file

@ -41,11 +41,11 @@ class CarrotBlock extends FlowableBlock{
}
}
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(CARROT, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
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;
}
}

View file

@ -20,13 +20,11 @@ class CyanFlowerBlock extends FlowableBlock{
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
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;
}

View file

@ -18,13 +18,11 @@ class DandelionBlock extends FlowableBlock{
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
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;
}

View file

@ -11,10 +11,10 @@ class DeadBushBlock extends FlowableBlock{
return null;
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false, false, true);
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;
}
}
@ -30,13 +30,13 @@ class DeadBushBlock extends FlowableBlock{
return false;
}
public function getDrops(Item $item, Player $player){
if($item->isShears()){
return [
[DEAD_BUSH, 0, 1],
];
}
return [];
public function getDrops(Item $item, Player $player){
if($item->isShears()){
return [
[DEAD_BUSH, 0, 1],
];
}
return [];
}
}

View file

@ -43,11 +43,11 @@ class MelonStemBlock extends FlowableBlock{
}
}
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true);
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;
}
}

View file

@ -41,11 +41,11 @@ class PotatoBlock extends FlowableBlock{
return false;
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(POTATO, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
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;
}
}

View file

@ -43,34 +43,13 @@ class PumpkinStemBlock extends FlowableBlock{
}
}
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true);
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;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x07){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}else{
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b->getID() === PUMPKIN){
return BLOCK_UPDATE_RANDOM;
}
}
$side = $this->getSide(mt_rand(2,5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$this->level->setBlock($side, new PumpkinBlock(), true, false, true);
}
}
}
return BLOCK_UPDATE_RANDOM;
}
return false;
}

View file

@ -6,13 +6,11 @@ class RedMushroomBlock extends FlowableBlock{
$this->hardness = 0;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem($this->id));
$this->level->setBlock($this, new AirBlock(), false);
return BLOCK_UPDATE_NORMAL;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
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;
}

View file

@ -42,13 +42,12 @@ class SaplingBlock extends FlowableBlock{
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem($this->id, $this->getMetadata()));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
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;
}

View file

@ -36,27 +36,23 @@ class SugarcaneBlock extends FlowableBlock{
return false;
}
public function onUpdate($type){
$down = $this->getSide(0);
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
$block0 = $down->getSide(2);
$block1 = $down->getSide(3);
$block2 = $down->getSide(4);
$block3 = $down->getSide(5);
if(!($block0 instanceof WaterBlock) and !($block1 instanceof WaterBlock) and !($block2 instanceof WaterBlock) and !($block3 instanceof WaterBlock)){
$this->level->setBlock($this, new AirBlock(), true, false, true);
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
public static function onUpdate(Level $level, $x, $y, $z, $type){
$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);
$b1 = $level->level->getBlockID($x, $y - 1, $z + 1);
$b2 = $level->level->getBlockID($x - 1, $y - 1, $z);
$b3 = $level->level->getBlockID($x + 1, $y - 1, $z);
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($type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(SUGARCANE));
$this->level->setBlock($this, new AirBlock(), false, false, true);
return BLOCK_UPDATE_NORMAL;
}
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;
}

View file

@ -13,13 +13,11 @@ class TallGrassBlock extends FlowableBlock{
$this->hardness = 0;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){//Replace with common break method
$this->level->setBlock($this, new AirBlock(), false, false, true);
if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(WHEAT_SEEDS));
return BLOCK_UPDATE_NORMAL;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
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;
}

View file

@ -41,11 +41,11 @@ class WheatBlock extends FlowableBlock{
}
}
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true);
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;
}
}