diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 30adaf3d..b94b70e8 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -527,17 +527,11 @@ class BlockAPI{ } public function blockUpdate(Position $pos, $type = BLOCK_UPDATE_NORMAL){ - if(!($pos instanceof Block)){ - $block = $pos->level->getBlock($pos); - }else{ - $pos = new Position($pos->x, $pos->y, $pos->z, $pos->level); - $block = $pos->level->getBlock($pos); - } + $block = StaticBlock::getBlock($pos->level->level->getBlockID($pos->x, $pos->y, $pos->z)); if($block === false){ return false; } - - $level = $block->onUpdate($type); + $level = $block::onUpdate($pos->level, $pos->x, $pos->y, $pos->z, $type); if($level === BLOCK_UPDATE_NORMAL){ $this->blockUpdateAround($block, $level); } diff --git a/src/API/TileAPI.php b/src/API/TileAPI.php index 000b70a5..6770c656 100644 --- a/src/API/TileAPI.php +++ b/src/API/TileAPI.php @@ -10,7 +10,13 @@ class TileAPI{ $this->tiles = []; $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){ $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){ diff --git a/src/material/Block.php b/src/material/Block.php index ed847ec0..0c7e4711 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -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***/ diff --git a/src/material/block/DoorBlock.php b/src/material/block/DoorBlock.php index d2ba29b0..7df89757 100644 --- a/src/material/block/DoorBlock.php +++ b/src/material/block/DoorBlock.php @@ -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; } diff --git a/src/material/block/GenericBlock.php b/src/material/block/GenericBlock.php index f8ffb163..ed477403 100644 --- a/src/material/block/GenericBlock.php +++ b/src/material/block/GenericBlock.php @@ -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; } diff --git a/src/material/block/attachable/LadderBlock.php b/src/material/block/attachable/LadderBlock.php index e51d6888..4b4a99d2 100644 --- a/src/material/block/attachable/LadderBlock.php +++ b/src/material/block/attachable/LadderBlock.php @@ -1,13 +1,6 @@ 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; } diff --git a/src/material/block/attachable/SignPostBlock.php b/src/material/block/attachable/SignPostBlock.php index e94fae08..044bf64c 100644 --- a/src/material/block/attachable/SignPostBlock.php +++ b/src/material/block/attachable/SignPostBlock.php @@ -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; } diff --git a/src/material/block/attachable/TorchBlock.php b/src/material/block/attachable/TorchBlock.php index 70e4ff76..11c5db80 100644 --- a/src/material/block/attachable/TorchBlock.php +++ b/src/material/block/attachable/TorchBlock.php @@ -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; } } diff --git a/src/material/block/attachable/TrapdoorBlock.php b/src/material/block/attachable/TrapdoorBlock.php index 7d638722..2a4b7996 100644 --- a/src/material/block/attachable/TrapdoorBlock.php +++ b/src/material/block/attachable/TrapdoorBlock.php @@ -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; } } diff --git a/src/material/block/attachable/WallSignBlock.php b/src/material/block/attachable/WallSignBlock.php index 5f7f0f12..daaf164c 100644 --- a/src/material/block/attachable/WallSignBlock.php +++ b/src/material/block/attachable/WallSignBlock.php @@ -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; diff --git a/src/material/block/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index 5d6bff7a..9e2506c2 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -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; } } diff --git a/src/material/block/liquid/WaterBlock.php b/src/material/block/liquid/WaterBlock.php index e6ecc512..201ad48f 100644 --- a/src/material/block/liquid/WaterBlock.php +++ b/src/material/block/liquid/WaterBlock.php @@ -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;*/ } } diff --git a/src/material/block/misc/FireBlock.php b/src/material/block/misc/FireBlock.php index c4908adf..aef7f4d7 100644 --- a/src/material/block/misc/FireBlock.php +++ b/src/material/block/misc/FireBlock.php @@ -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; } diff --git a/src/material/block/nonfull/CakeBlock.php b/src/material/block/nonfull/CakeBlock.php index 6d049dda..c142d2fc 100644 --- a/src/material/block/nonfull/CakeBlock.php +++ b/src/material/block/nonfull/CakeBlock.php @@ -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; } } diff --git a/src/material/block/nonfull/CarpetBlock.php b/src/material/block/nonfull/CarpetBlock.php index ed1903aa..875637e0 100644 --- a/src/material/block/nonfull/CarpetBlock.php +++ b/src/material/block/nonfull/CarpetBlock.php @@ -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; } - } \ No newline at end of file diff --git a/src/material/block/nonfull/FarmlandBlock.php b/src/material/block/nonfull/FarmlandBlock.php index 3eb447c6..14cf3fcd 100644 --- a/src/material/block/nonfull/FarmlandBlock.php +++ b/src/material/block/nonfull/FarmlandBlock.php @@ -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; } } diff --git a/src/material/block/nonfull/RailBaseBlock.php b/src/material/block/nonfull/RailBaseBlock.php index d5fb7c0b..d406253d 100644 --- a/src/material/block/nonfull/RailBaseBlock.php +++ b/src/material/block/nonfull/RailBaseBlock.php @@ -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(); } diff --git a/src/material/block/nonfull/SnowLayerBlock.php b/src/material/block/nonfull/SnowLayerBlock.php index 24ac9082..fda65d8e 100644 --- a/src/material/block/nonfull/SnowLayerBlock.php +++ b/src/material/block/nonfull/SnowLayerBlock.php @@ -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; } } diff --git a/src/material/block/ore/GlowingRedstoneOreBlock.php b/src/material/block/ore/GlowingRedstoneOreBlock.php index 1f679adb..2829377d 100644 --- a/src/material/block/ore/GlowingRedstoneOreBlock.php +++ b/src/material/block/ore/GlowingRedstoneOreBlock.php @@ -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; } diff --git a/src/material/block/ore/RedstoneOreBlock.php b/src/material/block/ore/RedstoneOreBlock.php index 499a580e..ea5c991f 100644 --- a/src/material/block/ore/RedstoneOreBlock.php +++ b/src/material/block/ore/RedstoneOreBlock.php @@ -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; } diff --git a/src/material/block/plant/BeetrootBlock.php b/src/material/block/plant/BeetrootBlock.php index 8957769e..fffa936c 100644 --- a/src/material/block/plant/BeetrootBlock.php +++ b/src/material/block/plant/BeetrootBlock.php @@ -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; } } diff --git a/src/material/block/plant/BrownMushroomBlock.php b/src/material/block/plant/BrownMushroomBlock.php index 85cb771c..16ac4b49 100644 --- a/src/material/block/plant/BrownMushroomBlock.php +++ b/src/material/block/plant/BrownMushroomBlock.php @@ -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; } diff --git a/src/material/block/plant/CactusBlock.php b/src/material/block/plant/CactusBlock.php index a4380251..d32b8bbd 100644 --- a/src/material/block/plant/CactusBlock.php +++ b/src/material/block/plant/CactusBlock.php @@ -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; } } diff --git a/src/material/block/plant/CarrotBlock.php b/src/material/block/plant/CarrotBlock.php index d84f598b..109a064f 100644 --- a/src/material/block/plant/CarrotBlock.php +++ b/src/material/block/plant/CarrotBlock.php @@ -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; } } diff --git a/src/material/block/plant/CyanFlowerBlock.php b/src/material/block/plant/CyanFlowerBlock.php index 67225b8b..19cb6dc2 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -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; } diff --git a/src/material/block/plant/DandelionBlock.php b/src/material/block/plant/DandelionBlock.php index def18792..b1a108a6 100644 --- a/src/material/block/plant/DandelionBlock.php +++ b/src/material/block/plant/DandelionBlock.php @@ -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; } diff --git a/src/material/block/plant/DeadBushBlock.php b/src/material/block/plant/DeadBushBlock.php index a528b6f8..8e05cd1b 100644 --- a/src/material/block/plant/DeadBushBlock.php +++ b/src/material/block/plant/DeadBushBlock.php @@ -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 []; + } } \ No newline at end of file diff --git a/src/material/block/plant/MelonStemBlock.php b/src/material/block/plant/MelonStemBlock.php index 8b5bbfba..7cec6dd6 100644 --- a/src/material/block/plant/MelonStemBlock.php +++ b/src/material/block/plant/MelonStemBlock.php @@ -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; } } diff --git a/src/material/block/plant/PotatoBlock.php b/src/material/block/plant/PotatoBlock.php index 8a687985..58cb13f6 100644 --- a/src/material/block/plant/PotatoBlock.php +++ b/src/material/block/plant/PotatoBlock.php @@ -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; } } diff --git a/src/material/block/plant/PumpkinStemBlock.php b/src/material/block/plant/PumpkinStemBlock.php index bd029c32..f74d4d11 100644 --- a/src/material/block/plant/PumpkinStemBlock.php +++ b/src/material/block/plant/PumpkinStemBlock.php @@ -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; } diff --git a/src/material/block/plant/RedMushroomBlock.php b/src/material/block/plant/RedMushroomBlock.php index c9f43b7b..abd4db15 100644 --- a/src/material/block/plant/RedMushroomBlock.php +++ b/src/material/block/plant/RedMushroomBlock.php @@ -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; } diff --git a/src/material/block/plant/SaplingBlock.php b/src/material/block/plant/SaplingBlock.php index 0f7dffa4..83c0b834 100644 --- a/src/material/block/plant/SaplingBlock.php +++ b/src/material/block/plant/SaplingBlock.php @@ -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; } diff --git a/src/material/block/plant/SugarcaneBlock.php b/src/material/block/plant/SugarcaneBlock.php index 1f179a0b..aeb450e7 100644 --- a/src/material/block/plant/SugarcaneBlock.php +++ b/src/material/block/plant/SugarcaneBlock.php @@ -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; } diff --git a/src/material/block/plant/TallGrassBlock.php b/src/material/block/plant/TallGrassBlock.php index ff72cc56..f5e68b3f 100644 --- a/src/material/block/plant/TallGrassBlock.php +++ b/src/material/block/plant/TallGrassBlock.php @@ -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; } diff --git a/src/material/block/plant/WheatBlock.php b/src/material/block/plant/WheatBlock.php index 5b57ca81..7508cf0d 100644 --- a/src/material/block/plant/WheatBlock.php +++ b/src/material/block/plant/WheatBlock.php @@ -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; } } diff --git a/src/material/block/solid/IceBlock.php b/src/material/block/solid/IceBlock.php index e4eb6d59..c05a8920 100644 --- a/src/material/block/solid/IceBlock.php +++ b/src/material/block/solid/IceBlock.php @@ -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){ diff --git a/src/material/block/solid/LeavesBlock.php b/src/material/block/solid/LeavesBlock.php index b03e726e..0b45ab40 100644 --- a/src/material/block/solid/LeavesBlock.php +++ b/src/material/block/solid/LeavesBlock.php @@ -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; } diff --git a/src/world/Level.php b/src/world/Level.php index ea0c6b1a..d29ea6f8 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -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->addBlockToSendQueue($x, $y, $z, $id, $meta); if($updateBlocksAround){ $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){