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

@ -219,6 +219,7 @@ abstract class Block extends Position{
public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){}
public static function onRandomTick(Level $level, $x, $y, $z){}
public static function onUpdate(Level $level, $x, $y, $z, $type){}
public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)];
@ -298,8 +299,6 @@ abstract class Block extends Position{
abstract function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);
abstract function onActivate(Item $item, Player $player);
abstract function onUpdate($type);
}
/***REM_START***/

View file

@ -104,20 +104,20 @@ class DoorBlock extends TransparentBlock{
return $metaLower & 7 | (($myMeta & 8) != 0 ? 8 : 0) | (($metaUpper & 1 != 0) ? 16 : 0);
}
/**
* @param int $type
*
* @return bool|int
*/
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false);
if($this->getID() == 64) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(324, 0, 1));
elseif($this->getID() == 71) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(330, 0, 1));
if($this->getSide(1) instanceof DoorBlock){
$this->level->setBlock($this->getSide(1), new AirBlock(), false);
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
$id = $level->level->getBlockID($x, $y, $z);
if($id == 64) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(324, 0, 1));
elseif($id == 71) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(330, 0, 1));
$top = $level->level->getBlockID($x, $y + 1, $z);
if($top == IRON_DOOR_BLOCK || $top == DOOR_BLOCK){
$level->fastSetBlockUpdate($x, $y + 1, $z, 0, 0);
}
return BLOCK_UPDATE_NORMAL;
}

View file

@ -52,21 +52,21 @@ class GenericBlock extends Block{
*
* @return boolean
*/
public function onUpdate($type){
if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0);
if($down->getID() === AIR or ($down instanceof LiquidBlock)){
public static function onUpdate(Level $level, $x, $y, $z, $type){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if(StaticBlock::getHasPhysics($id) and $type === BLOCK_UPDATE_NORMAL){ //TODO move from here to different class
$down = $level->level->getBlockID($x, $y - 1, $z);
if($down == AIR || StaticBlock::getIsLiquid($down)){
$data = array(
"x" => $this->x + 0.5,
"y" => $this->y,
"z" => $this->z + 0.5,
"Tile" => $this->id,
"x" => $x + 0.5,
"y" => $y,
"z" => $z + 0.5,
"Tile" => $id,
);
$server = ServerAPI::request();
$this->level->setBlock($this, new AirBlock(), false, false, true);
$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
$e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data);
$server->api->entity->spawnToAll($e);
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
}
return false;
}

View file

@ -1,13 +1,6 @@
<?php
class LadderBlock extends TransparentBlock{
public static $faces = [
3 => 2,
2 => 3,
5 => 4,
4 => 5,
];
public static function getAABB(Level $level, $x, $y, $z){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
@ -47,15 +40,21 @@ class LadderBlock extends TransparentBlock{
return false;
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
$side = $level->level->getBlockDamage($x, $y, $z);
if($type === BLOCK_UPDATE_NORMAL){
$side = $this->getMetadata();
if($this->getSide(self::$faces[$side]) instanceof AirBlock){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}
$attached = match($side){
3 => $level->level->getBlockID($x, $y, $z - 1),
2 => $level->level->getBlockID($x, $y, $z + 1),
5 => $level->level->getBlockID($x - 1, $y, $z),
4 => $level->level->getBlockID($x + 1, $y, $z),
default => 0 //TODO
};
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;
}

View file

@ -33,13 +33,12 @@ class SignPostBlock extends TransparentBlock{
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SIGN, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, true, true);
return BLOCK_UPDATE_NORMAL;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){ //TODO remove $type
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;
}

View file

@ -14,22 +14,20 @@ class TorchBlock extends FlowableBlock implements LightingBlock{
return null;
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$side = $this->getMetadata();
$faces = array(
1 => 4,
2 => 5,
3 => 2,
4 => 3,
5 => 0,
6 => 0,
0 => 0,
);
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
$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;
}
}

View file

@ -74,22 +74,20 @@ class TrapdoorBlock extends TransparentBlock{
array($this->id, 0, 1),
);
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$faces = array( //meta => side
0 => 3,
4 => 3, //activated
1 => 2,
5 => 2, //activated
2 => 5,
6 => 5, //activated
3 => 4,
7 => 4, //activated
);
$side = $faces[$this->meta];
if($this->getSide($side) instanceof AirBlock){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
$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;
}
}

View file

@ -5,25 +5,24 @@ require_once("SignPostBlock.php");
/***REM_END***/
class WallSignBlock extends SignPostBlock{
public static $meta2side = [
2 => 3,
3 => 2,
4 => 5,
5 => 4
];
public function __construct($meta = 0){
TransparentBlock::__construct(WALL_SIGN, $meta, "Wall Sign");
$this->isSolid = false;
}
public function onUpdate($type){
$attached = $this->getSide(self::$meta2side[$this->meta] ?? -1);
if(!($attached instanceof Block) || (!$attached->isSolid && $attached->getID() != SIGN_POST && $attached->getID() != WALL_SIGN)){
$this->level->setBlock($this, new AirBlock(), true, true, true);
(ServerAPI::request())->api->entity->drop(new Position($this->x + 0.5, $this->y + 0.5, $this->z + 0.5, $this->level), BlockAPI::getItem(SIGN, 0, 1));
public static function onUpdate(Level $level, $x, $y, $z, $type){
$attached = match($level->level->getBlockDamage($x, $y, $z)){
2 => $level->level->getBlockID($x, $y, $z + 1),
3 => $level->level->getBlockID($x, $y, $z - 1),
4 => $level->level->getBlockID($x + 1, $y, $z),
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;

View file

@ -58,71 +58,73 @@ class LavaBlock extends LiquidBlock implements LightingBlock{
return null;
}
public function onUpdate($type){
//return false;
$newId = $this->id;
$level = $this->meta & 0x06;
if($type !== BLOCK_UPDATE_NORMAL){
return false;
}
/*if($this->checkWater()){
return;
}*/
$falling = $this->meta >> 3;
$down = $this->getSide(0);
if($down instanceof WaterBlock) {
$this->level->fastSetBlockUpdate($down->x, $down->y, $down->z, STONE, 0, true);
return;
}
$from = $this->getFrom();
if($from !== null || $level == 0x00){
if($down instanceof AirBlock || $down instanceof LavaBlock){
$this->level->setBlock($down, new LavaBlock(0x01), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate($down, 40, BLOCK_UPDATE_NORMAL);
}elseif($level !== 0x06){
for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side);
if($b instanceof LavaBlock){
}elseif($b->isFlowable === true){
$this->level->setBlock($b, new LavaBlock( min($level + 2,6) ), false, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate($b, 40, BLOCK_UPDATE_NORMAL);
}
}
}
}else{
//Extend Remove for Left Lavas
for($side = 2; $side <= 5; ++$side){
$sb = $this->getSide($side);
if($sb instanceof LavaBlock){
$tlevel = $sb->meta & 0x06;
if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate($ssb, 40, BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($sb, new AirBlock(), false, false, true);
}
}
$b = $this->getSide(0)->getSide($side);
if($b instanceof LavaBlock){
$tlevel = $b->meta & 0x06;
if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate($ssb, 40, BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($b, new AirBlock(), false, false, true);
}
}
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
}
$this->level->setBlock($this, new AirBlock(), false, false, true);
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
//TODO rewrite
return false;
//return false;
// $newId = $this->id;
// $level = $this->meta & 0x06;
// if($type !== BLOCK_UPDATE_NORMAL){
// return false;
// }
// /*if($this->checkWater()){
// return;
// }*/
// $falling = $this->meta >> 3;
// $down = $this->getSide(0);
// if($down instanceof WaterBlock) {
// $this->level->fastSetBlockUpdate($down->x, $down->y, $down->z, STONE, 0, true);
// return;
// }
// $from = $this->getFrom();
// if($from !== null || $level == 0x00){
// if($down instanceof AirBlock || $down instanceof LavaBlock){
// $this->level->setBlock($down, new LavaBlock(0x01), false, false, true);
// ServerAPI::request()->api->block->scheduleBlockUpdate($down, 40, BLOCK_UPDATE_NORMAL);
// }elseif($level !== 0x06){
// for($side = 2; $side <= 5; ++$side){
// $b = $this->getSide($side);
// if($b instanceof LavaBlock){
// }elseif($b->isFlowable === true){
// $this->level->setBlock($b, new LavaBlock( min($level + 2,6) ), false, false, true);
// ServerAPI::request()->api->block->scheduleBlockUpdate($b, 40, BLOCK_UPDATE_NORMAL);
// }
// }
// }
// }else{
// //Extend Remove for Left Lavas
// for($side = 2; $side <= 5; ++$side){
// $sb = $this->getSide($side);
// if($sb instanceof LavaBlock){
// $tlevel = $sb->meta & 0x06;
// if($tlevel != 0x00){
// for ($s = 0; $s <= 5; $s++) {
// $ssb = $sb->getSide($s);
// ServerAPI::request()->api->block->scheduleBlockUpdate($ssb, 40, BLOCK_UPDATE_NORMAL);
// }
// $this->level->setBlock($sb, new AirBlock(), false, false, true);
// }
// }
// $b = $this->getSide(0)->getSide($side);
// if($b instanceof LavaBlock){
// $tlevel = $b->meta & 0x06;
// if($tlevel != 0x00){
// for ($s = 0; $s <= 5; $s++) {
// $ssb = $sb->getSide($s);
// ServerAPI::request()->api->block->scheduleBlockUpdate($ssb, 40, BLOCK_UPDATE_NORMAL);
// }
// $this->level->setBlock($b, new AirBlock(), false, false, true);
// }
// }
// //ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
// }
// $this->level->setBlock($this, new AirBlock(), false, false, true);
// }
// return false;
}
}

View file

@ -60,9 +60,10 @@ class WaterBlock extends LiquidBlock{
return null;
}
public function onUpdate($type){
//return false;
$newId = $this->id;
public static function onUpdate(Level $level, $x, $y, $z, $type){
//TODO rewrite
return false;
/*$newId = $this->id;
$level = $this->meta & 0x07;
if($type !== BLOCK_UPDATE_NORMAL){
@ -117,6 +118,6 @@ class WaterBlock extends LiquidBlock{
ServerAPI::request()->api->block->blockUpdateAround($this, BLOCK_UPDATE_NORMAL, 5);
$this->level->setBlock($this, new AirBlock(), false, false, true);
}
return false;
return false;*/
}
}

View file

@ -36,29 +36,40 @@ class FireBlock extends FlowableBlock implements LightingBlock{
public function getMaxLightValue(){
return 15;
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
for($s = 0; $s <= 5; ++$s){
$side = $this->getSide($s);
if($side->getID() !== AIR and !($side instanceof LiquidBlock)){
return false;
}
}
$this->level->setBlock($this, new AirBlock(), true, false, true);
$b = $level->level->getBlockID($x, $y - 1, $z);
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
$b = $level->level->getBlockID($x, $y - 1, $z);
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
$b = $level->level->getBlockID($x - 1, $y, $z);
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
$b = $level->level->getBlockID($x + 1, $y, $z);
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
$b = $level->level->getBlockID($x, $y, $z - 1);
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
$b = $level->level->getBlockID($x, $y, $z + 1);
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL;
}else if($type === BLOCK_UPDATE_SCHEDULED){
$idBelow = $this->level->level->getBlockID($this->x, $this->y - 1, $this->z);
}else if($type === BLOCK_UPDATE_SCHEDULED){ //TODO get rid of it
$idBelow = $level->level->getBlockID($x, $y - 1, $z);
[$id, $meta] = $level->level->getBlock($x, $y, $z);
$alwaysBurn = $idBelow == NETHERRACK;
if($this->meta < 15){
$newMeta = $this->meta + 1; //TODO better formula
if($meta < 15){
$newMeta = $meta + 1; //TODO better formula
if($newMeta > 15) $newMeta = 15;
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->id, $newMeta);
$level->fastSetBlockUpdate($x, $y, $z, $id, $newMeta);
}
if($this->meta == 15){
if(!$alwaysBurn && !self::canBurn($this->level, $this->x, $this->y - 1, $this->z) && mt_rand(0, 4) == 0){
if($meta == 15){
if(!$alwaysBurn && !self::canBurn($level, $x, $y - 1, $z) && mt_rand(0, 4) == 0){
REMOVE_FIRE:
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, 0, 0);
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return false;
}
}
@ -66,11 +77,11 @@ class FireBlock extends FlowableBlock implements LightingBlock{
if(mt_rand(0, 249) < $chance){
//TODO ignite tnt
$this->level->fastSetBlockUpdate($this->x, $this->y - 1, $this->z, 0, 0, true);
$level->fastSetBlockUpdate($x, $y - 1, $z, 0, 0, true);
goto REMOVE_FIRE;
}
$this->level->scheduleBlockUpdate($this, 30, BLOCK_UPDATE_SCHEDULED); //TODO looks like it also adds mt_rand(0, 9) to it
$level->scheduleBlockUpdate(new Position($x, $y, $z, $level), 30, BLOCK_UPDATE_SCHEDULED); //TODO looks like it also adds mt_rand(0, 9) to it
}
return false;
}

View file

@ -29,10 +29,10 @@ class CakeBlock extends TransparentBlock{
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() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true);
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL;
}
}

View file

@ -35,16 +35,15 @@ class CarpetBlock 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() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //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, true);
return BLOCK_UPDATE_NORMAL;
}
}
return false;
}
}

View file

@ -58,10 +58,10 @@ class FarmlandBlock extends TransparentBlock{
}
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
if(!$this->getSide(1)->isTransparent){
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z))){
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true);
return $type;
}
}

View file

@ -26,27 +26,23 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here
public function updateState(){}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$meta = $this->getMetadata();
if($this->id === POWERED_RAIL){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if($id === POWERED_RAIL){
$meta &= 7;
}
$x = $this->x;
$y = $this->y;
$z = $this->z;
if(
($this->level->level->getBlockID($x, $y - 1, $z) === 0) ||
(($meta == 2) && $this->level->level->getBlockID($x + 1, $y, $z) === 0) ||
(($meta == 3) && $this->level->level->getBlockID($x - 1, $y, $z) === 0) ||
(($meta == 4) && $this->level->level->getBlockID($x, $y, $z - 1) === 0) ||
(($meta == 5) && $this->level->level->getBlockID($x, $y, $z + 1) === 0)
($level->level->getBlockID($x, $y - 1, $z) === 0) ||
(($meta == 2) && $level->level->getBlockID($x + 1, $y, $z) === 0) ||
(($meta == 3) && $level->level->getBlockID($x - 1, $y, $z) === 0) ||
(($meta == 4) && $level->level->getBlockID($x, $y, $z - 1) === 0) ||
(($meta == 5) && $level->level->getBlockID($x, $y, $z + 1) === 0)
){
$this->level->setBlock($this, new AirBlock(), true, false, true);
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem($id, $meta, 1));
}else{
$this->updateState();
//TODO fix me pls $this->updateState();
}

View file

@ -20,10 +20,10 @@ class SnowLayerBlock 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() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true);
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL;
}
}

View file

@ -8,10 +8,9 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
public static function onRandomTick(Level $level, $x, $y, $z){
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(REDSTONE_ORE, $level->level->getBlockDamage($x, $y, $z)), false, false, true);
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_SCHEDULED){
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true);
return BLOCK_UPDATE_WEAK;
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_SCHEDULED){ //TODO replace with BLOCK_UPDATE_NORMAL
$level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0);
}
return false;
}

View file

@ -6,11 +6,10 @@ class RedstoneOreBlock extends SolidBlock{
$this->hardness = 15;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){
$this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return BLOCK_UPDATE_WEAK;
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL || $type === BLOCK_UPDATE_TOUCH){ //TODO remove BLOCK_UPDATE_TOUCH
$level->fastSetBlockUpdate($x, $y, $z, GLOWING_REDSTONE_ORE, 0);
$level->scheduleBlockUpdate(new Position($x, $y, $z, $level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
}
return false;
}

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;
}
}

View file

@ -26,11 +26,7 @@ class IceBlock extends TransparentBlock{
}
return true;
}
/*
Scan for blocks which can emit light
args: offsetX: int, offsetY: int, offsetZ: int
do not set offsets more than 15 : no lighting sources are giving so much light
*/
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){
@ -38,7 +34,7 @@ class IceBlock extends TransparentBlock{
$pX = $this->x+$x;
$pY = $this->y+$y;
$pZ = $this->z+$z;
$block = $this->level->getBlock(new Vector3($pX, $pY, $pZ));
$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;
}
@ -46,7 +42,7 @@ class IceBlock extends TransparentBlock{
}
}
}
public function onUpdate($type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/
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){
@ -55,7 +51,7 @@ class IceBlock extends TransparentBlock{
}
return BLOCK_UPDATE_RANDOM;
}
return false;*/ //TODO i dont want it now
return false;*/ //TODO ice melting(after light?)
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){

View file

@ -64,12 +64,11 @@ class LeavesBlock extends TransparentBlock{
}
}
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if(($this->meta & 0b00001100) === 0){
$this->meta |= 0x08;
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, $this->id, $this->meta);
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if(($meta & 0b00001100) === 0){
$meta |= 0x08;
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta); //TODO maybe use $level->level->setBlock directly, the client doesnt need to know thism info.
}
return false;
}