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

@ -527,17 +527,11 @@ class BlockAPI{
} }
public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){ public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){
if(!($pos instanceof Block)){ $block = StaticBlock::getBlock($pos->level->level->getBlockID($pos->x, $pos->y, $pos->z));
$block = $pos->level->getBlock($pos);
}else{
$pos = new Position($pos->x, $pos->y, $pos->z, $pos->level);
$block = $pos->level->getBlock($pos);
}
if($block === false){ if($block === false){
return false; return false;
} }
$level = $block::onUpdate($pos->level, $pos->x, $pos->y, $pos->z, $type);
$level = $block->onUpdate($type);
if($level === BLOCK_UPDATE_NORMAL){ if($level === BLOCK_UPDATE_NORMAL){
$this->blockUpdateAround($block, $level); $this->blockUpdateAround($block, $level);
} }

View file

@ -10,7 +10,13 @@ class TileAPI{
$this->tiles = []; $this->tiles = [];
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
public function getXYZ(Level $level, $x, $y, $z){
$tile = $this->server->query("SELECT * FROM tiles WHERE level = '{$level->getName()}' AND x = $z AND y = $y AND z = $z;", true);
if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){
return $tile;
}
return false;
}
public function get(Position $pos){ public function get(Position $pos){
$tile = $this->server->query("SELECT * FROM tiles WHERE level = '" . $pos->level->getName() . "' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true); $tile = $this->server->query("SELECT * FROM tiles WHERE level = '" . $pos->level->getName() . "' AND x = {$pos->x} AND y = {$pos->y} AND z = {$pos->z};", true);
if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){ if($tile !== false and $tile !== true and ($tile = $this->getByID($tile["ID"])) !== false){

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 addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){}
public static function onRandomTick(Level $level, $x, $y, $z){} 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 fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)]; 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 place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz);
abstract function onActivate(Item $item, Player $player); abstract function onActivate(Item $item, Player $player);
abstract function onUpdate($type);
} }
/***REM_START***/ /***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); return $metaLower & 7 | (($myMeta & 8) != 0 ? 8 : 0) | (($metaUpper & 1 != 0) ? 16 : 0);
} }
/** public static function onUpdate(Level $level, $x, $y, $z, $type){
* @param int $type
*
* @return bool|int
*/
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false); $level->fastSetBlockUpdate($x, $y, $z, 0, 0);
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)); $id = $level->level->getBlockID($x, $y, $z);
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){ if($id == 64) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(324, 0, 1));
$this->level->setBlock($this->getSide(1), new AirBlock(), false); 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; return BLOCK_UPDATE_NORMAL;
} }

View file

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

View file

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

View file

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

View file

@ -14,22 +14,20 @@ class TorchBlock extends FlowableBlock implements LightingBlock{
return null; return null;
} }
public function onUpdate($type){ public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
$side = $this->getMetadata(); $side = $level->level->getBlockDamage($x, $y, $z);
$faces = array( $attach = match($side){
1 => 4, 1 => $level->level->getBlockID($x - 1, $y, $z),
2 => 5, 2 => $level->level->getBlockID($x + 1, $y, $z),
3 => 2, 3 => $level->level->getBlockID($x, $y, $z - 1),
4 => 3, 4 => $level->level->getBlockID($x, $y, $z + 1),
5 => 0, default => $level->level->getBlockID($x, $y - 1, $z)
6 => 0, };
0 => 0,
); 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));
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace with common break method $level->fastSetBlockUpdate($x, $y, $z, 0, 0);
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; return BLOCK_UPDATE_NORMAL;
} }
} }

View file

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

View file

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

View file

@ -58,71 +58,73 @@ class LavaBlock extends LiquidBlock implements LightingBlock{
return null; return null;
} }
public function onUpdate($type){ public static function onUpdate(Level $level, $x, $y, $z, $type){
//return false; //TODO rewrite
$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; 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; return null;
} }
public function onUpdate($type){ public static function onUpdate(Level $level, $x, $y, $z, $type){
//return false; //TODO rewrite
$newId = $this->id; return false;
/*$newId = $this->id;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if($type !== BLOCK_UPDATE_NORMAL){ if($type !== BLOCK_UPDATE_NORMAL){
@ -117,6 +118,6 @@ class WaterBlock extends LiquidBlock{
ServerAPI::request()->api->block->blockUpdateAround($this, BLOCK_UPDATE_NORMAL, 5); ServerAPI::request()->api->block->blockUpdateAround($this, BLOCK_UPDATE_NORMAL, 5);
$this->level->setBlock($this, new AirBlock(), false, false, true); $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(){ public function getMaxLightValue(){
return 15; return 15;
} }
public function onUpdate($type){ public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
for($s = 0; $s <= 5; ++$s){
$side = $this->getSide($s); $b = $level->level->getBlockID($x, $y - 1, $z);
if($side->getID() !== AIR and !($side instanceof LiquidBlock)){ if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
return false; $b = $level->level->getBlockID($x, $y - 1, $z);
} if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
}
$this->level->setBlock($this, new AirBlock(), true, false, true); $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; return BLOCK_UPDATE_NORMAL;
}else if($type === BLOCK_UPDATE_SCHEDULED){ }else if($type === BLOCK_UPDATE_SCHEDULED){ //TODO get rid of it
$idBelow = $this->level->level->getBlockID($this->x, $this->y - 1, $this->z); $idBelow = $level->level->getBlockID($x, $y - 1, $z);
[$id, $meta] = $level->level->getBlock($x, $y, $z);
$alwaysBurn = $idBelow == NETHERRACK; $alwaysBurn = $idBelow == NETHERRACK;
if($this->meta < 15){ if($meta < 15){
$newMeta = $this->meta + 1; //TODO better formula $newMeta = $meta + 1; //TODO better formula
if($newMeta > 15) $newMeta = 15; 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($meta == 15){
if(!$alwaysBurn && !self::canBurn($this->level, $this->x, $this->y - 1, $this->z) && mt_rand(0, 4) == 0){ if(!$alwaysBurn && !self::canBurn($level, $x, $y - 1, $z) && mt_rand(0, 4) == 0){
REMOVE_FIRE: REMOVE_FIRE:
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, 0, 0); $level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return false; return false;
} }
} }
@ -66,11 +77,11 @@ class FireBlock extends FlowableBlock implements LightingBlock{
if(mt_rand(0, 249) < $chance){ if(mt_rand(0, 249) < $chance){
//TODO ignite tnt //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; 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; return false;
} }

View file

@ -29,10 +29,10 @@ class CakeBlock extends TransparentBlock{
return false; return false;
} }
public function onUpdate($type){ public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }

View file

@ -35,16 +35,15 @@ class CarpetBlock extends FlowableBlock{
} }
return false; return false;
} }
public static function onUpdate(Level $level, $x, $y, $z, $type){
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1)); [$id, $meta] = $level->level->getBlock($x, $y, $z);
$this->level->setBlock($this, new AirBlock(), true, false, true); 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 BLOCK_UPDATE_NORMAL;
} }
} }
return false; 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($type === BLOCK_UPDATE_NORMAL){
if(!$this->getSide(1)->isTransparent){ if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z))){
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true); $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true);
return $type; return $type;
} }
} }

View file

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

View file

@ -20,10 +20,10 @@ class SnowLayerBlock extends FlowableBlock{
return false; return false;
} }
public function onUpdate($type){ public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL; 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){ 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); $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){ public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_SCHEDULED){ if($type === BLOCK_UPDATE_SCHEDULED){ //TODO replace with BLOCK_UPDATE_NORMAL
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false, false, true); $level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0);
return BLOCK_UPDATE_WEAK;
} }
return false; return false;
} }

View file

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

View file

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

View file

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

View file

@ -26,7 +26,7 @@ class CactusBlock extends TransparentBlock{
$bID = $level->level->getBlockID($x, $y + $yy, $z); $bID = $level->level->getBlockID($x, $y + $yy, $z);
if($bID === AIR){ if($bID === AIR){
$level->fastSetBlockUpdate($x, $y + $yy, $z, CACTUS, 0); $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; 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){ if($type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0); $down = $level->level->getBlockID($x, $y, $z);
$block0 = $this->getSide(2); $b0 = $level->level->getBlockID($x, $y, $z - 1);
$block1 = $this->getSide(3); $b1 = $level->level->getBlockID($x, $y, $z + 1);
$block2 = $this->getSide(4); $b2 = $level->level->getBlockID($x - 1, $y, $z);
$block3 = $this->getSide(5); $b3 = $level->level->getBlockID($x + 1, $y, $z);
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 if(!StaticBlock::getIsFlowable($b0) || !StaticBlock::getIsFlowable($b1) || !StaticBlock::getIsFlowable($b2) || !StaticBlock::getIsFlowable($b3) || ($down !== SAND and $down !== CACTUS)){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), true, false, true); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem($this->id)); ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CACTUS));
return BLOCK_UPDATE_NORMAL; 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($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){ if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(CARROT, 0, 1)); ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CARROT, 0, 1));
$this->level->setBlock($this, new AirBlock(), false, false, true); $level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }

View file

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

View file

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

View file

@ -11,10 +11,10 @@ class DeadBushBlock extends FlowableBlock{
return null; return null;
} }
public function onUpdate($type){ public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false, false, true); $level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }
@ -30,13 +30,13 @@ class DeadBushBlock extends FlowableBlock{
return false; return false;
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->isShears()){ if($item->isShears()){
return [ return [
[DEAD_BUSH, 0, 1], [DEAD_BUSH, 0, 1],
]; ];
}
return [];
} }
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($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() != 60){ if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
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))); ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
$this->level->setBlock($this, new AirBlock(), false, false, true); $level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL; return BLOCK_UPDATE_NORMAL;
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -26,11 +26,7 @@ class IceBlock extends TransparentBlock{
} }
return true; 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){ private function scanForNearbyLightSources($offsetX, $offsetY, $offsetZ){
for($x = -$offsetX; $x <= $offsetX; ++$x){ //i hope it is possible to optimize it for($x = -$offsetX; $x <= $offsetX; ++$x){ //i hope it is possible to optimize it
for($z = -$offsetZ; $z <= $offsetZ; ++$z){ for($z = -$offsetZ; $z <= $offsetZ; ++$z){
@ -38,7 +34,7 @@ class IceBlock extends TransparentBlock{
$pX = $this->x+$x; $pX = $this->x+$x;
$pY = $this->y+$y; $pY = $this->y+$y;
$pZ = $this->z+$z; $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 if($block instanceof LightingBlock){ //idk is it possible to make it better
return $block; 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){ /*if($type === BLOCK_UPDATE_RANDOM){
$light = $this->scanForNearbyLightSources(3,3,3); $light = $this->scanForNearbyLightSources(3,3,3);
if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){ if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){
@ -55,7 +51,7 @@ class IceBlock extends TransparentBlock{
} }
return BLOCK_UPDATE_RANDOM; 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){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){

View file

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

View file

@ -465,12 +465,16 @@ class Level{
} }
} }
public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false){ public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false){
$this->level->setBlock($x, $y, $z, $id, $meta); $this->level->setBlock($x, $y, $z, $id, $meta);
$this->addBlockToSendQueue($x, $y, $z, $id, $meta); $this->addBlockToSendQueue($x, $y, $z, $id, $meta);
if($updateBlocksAround){ if($updateBlocksAround){
$this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1); $this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1);
} }
if($tiles && ($t = $this->server->api->tile->getXYZ($this, $x, $y, $z)) != false){ //TODO rewrite
$t->close();
}
} }
public function onTick(PocketMinecraftServer $server, $currentTime){ public function onTick(PocketMinecraftServer $server, $currentTime){