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

@ -154,6 +154,9 @@ abstract class Block extends Position{
public $y = 0;
public $z = 0;
public $slipperiness;
public static function interact(Level $level, $x, $y, $z, Player $player){}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){}
public static function getAABB(Level $level, $x, $y, $z){
return StaticBlock::getAABB($level, $x, $y, $z);

View file

@ -106,23 +106,19 @@ class DoorBlock extends TransparentBlock{
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
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);
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
$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));
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;
$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 false;
}

View file

@ -25,7 +25,8 @@ class FallableBlock extends SolidBlock{
*/
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);
$clz = StaticBlock::getBlock($this->getID());
$clz::neighborChanged($this->level, $this->x, $this->y, $this->z, 0, 0, 0, 0); //TODO move to another method
return $ret;
}
}

View file

@ -52,14 +52,14 @@ class GenericBlock extends Block{
*
* @return boolean
*/
public static function onUpdate(Level $level, $x, $y, $z, $type){
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if(StaticBlock::getHasPhysics($id) and $type === BLOCK_UPDATE_NORMAL){ //TODO move from here to different class
if(StaticBlock::getHasPhysics($id)){ //TODO move from here to different class
$down = $level->level->getBlockID($x, $y - 1, $z);
if($down == AIR || StaticBlock::getIsLiquid($down)){
$data = array(
"x" => $x + 0.5,
"y" => $y,
"y" => $y - 0.5,
"z" => $z + 0.5,
"Tile" => $id,
);
@ -68,9 +68,7 @@ class GenericBlock extends Block{
$e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data);
$server->api->entity->spawnToAll($e);
}
return false;
}
return false;
}
/**

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

View file

@ -36,27 +36,28 @@ class FireBlock extends FlowableBlock implements LightingBlock{
public function getMaxLightValue(){
return 15;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$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);
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$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){ //TODO get rid of it
if($type === BLOCK_UPDATE_SCHEDULED){
$idBelow = $level->level->getBlockID($x, $y - 1, $z);
[$id, $meta] = $level->level->getBlock($x, $y, $z);
$alwaysBurn = $idBelow == NETHERRACK;
@ -83,7 +84,6 @@ class FireBlock extends FlowableBlock implements LightingBlock{
$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;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
parent::place($item, $player, $block, $target, $face, $fx, $fy, $fz);

View file

@ -29,14 +29,10 @@ class CakeBlock extends TransparentBlock{
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) == AIR){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
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) == AIR){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
}
return false;
}
public function getDrops(Item $item, Player $player){

View file

@ -35,15 +35,11 @@ class CarpetBlock 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) == 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;
}
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
[$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 false;
}
}

View file

@ -58,14 +58,10 @@ class FarmlandBlock extends TransparentBlock{
}
}
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))){
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true);
return $type;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z))){
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true);
}
return false;
}
public function getBlockID($x, $y, $z){

View file

@ -26,33 +26,23 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here
public function updateState(){}
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if($id === POWERED_RAIL){
$meta &= 7;
}
if(
($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)
){
$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{
//TODO fix me pls $this->updateState();
}
//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);
//}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if($id === POWERED_RAIL){
$meta &= 7;
}
if(
($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)
){
$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{
//TODO fix me pls $this->updateState();
}
}
}

View file

@ -20,14 +20,10 @@ class SnowLayerBlock 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) == AIR){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
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) == AIR){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
}
return false;
}
public function getDrops(Item $item, Player $player){

View file

@ -5,15 +5,11 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
$this->hardness = 15;
}
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 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;
$level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0);
}
public function getMaxLightValue(){
return 9;
}

View file

@ -6,12 +6,8 @@ class RedstoneOreBlock extends SolidBlock{
$this->hardness = 15;
}
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;
public static function interact(Level $level, $x, $y, $z, Player $player){
$level->fastSetBlockUpdate($x, $y, $z, GLOWING_REDSTONE_ORE, 0);
}
public function getDrops(Item $item, Player $player){

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){

View file

@ -42,7 +42,7 @@ class IceBlock extends TransparentBlock{
}
}
}
public static function onUpdate(Level $level, $x, $y, $z, $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){
@ -52,7 +52,7 @@ class IceBlock extends TransparentBlock{
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

@ -64,13 +64,12 @@ class LeavesBlock extends TransparentBlock{
}
}
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
[$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;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){