From ee989ef55617ea10f95c4befd9d3c8daac7102a1 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 20 May 2024 13:16:48 +0300 Subject: [PATCH 01/10] onUpdate is now static, disabled rail, water and lava updates to rework. --- src/API/BlockAPI.php | 10 +- src/API/TileAPI.php | 8 +- src/material/Block.php | 3 +- src/material/block/DoorBlock.php | 24 ++-- src/material/block/GenericBlock.php | 22 +-- src/material/block/attachable/LadderBlock.php | 29 ++-- .../block/attachable/SignPostBlock.php | 13 +- src/material/block/attachable/TorchBlock.php | 28 ++-- .../block/attachable/TrapdoorBlock.php | 28 ++-- .../block/attachable/WallSignBlock.php | 29 ++-- src/material/block/liquid/LavaBlock.php | 130 +++++++++--------- src/material/block/liquid/WaterBlock.php | 9 +- src/material/block/misc/FireBlock.php | 47 ++++--- src/material/block/nonfull/CakeBlock.php | 6 +- src/material/block/nonfull/CarpetBlock.php | 11 +- src/material/block/nonfull/FarmlandBlock.php | 6 +- src/material/block/nonfull/RailBaseBlock.php | 26 ++-- src/material/block/nonfull/SnowLayerBlock.php | 6 +- .../block/ore/GlowingRedstoneOreBlock.php | 7 +- src/material/block/ore/RedstoneOreBlock.php | 9 +- src/material/block/plant/BeetrootBlock.php | 8 +- .../block/plant/BrownMushroomBlock.php | 12 +- src/material/block/plant/CactusBlock.php | 20 +-- src/material/block/plant/CarrotBlock.php | 8 +- src/material/block/plant/CyanFlowerBlock.php | 12 +- src/material/block/plant/DandelionBlock.php | 12 +- src/material/block/plant/DeadBushBlock.php | 22 +-- src/material/block/plant/MelonStemBlock.php | 8 +- src/material/block/plant/PotatoBlock.php | 8 +- src/material/block/plant/PumpkinStemBlock.php | 29 +--- src/material/block/plant/RedMushroomBlock.php | 12 +- src/material/block/plant/SaplingBlock.php | 13 +- src/material/block/plant/SugarcaneBlock.php | 32 ++--- src/material/block/plant/TallGrassBlock.php | 12 +- src/material/block/plant/WheatBlock.php | 8 +- src/material/block/solid/IceBlock.php | 12 +- src/material/block/solid/LeavesBlock.php | 11 +- src/world/Level.php | 6 +- 38 files changed, 329 insertions(+), 367 deletions(-) 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){ From 2ebc482e3de2348ce453f928e2091e6cc2bb03aa Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 22 May 2024 06:15:34 +0300 Subject: [PATCH 02/10] separated neighbor updates and scheduled updates --- src/API/BlockAPI.php | 17 ++++++-- src/material/Block.php | 3 ++ src/material/block/DoorBlock.php | 24 +++++------ src/material/block/FallableBlock.php | 3 +- src/material/block/GenericBlock.php | 8 ++-- src/material/block/attachable/LadderBlock.php | 4 +- .../block/attachable/SignPostBlock.php | 4 +- src/material/block/attachable/TorchBlock.php | 28 ++++++------ .../block/attachable/TrapdoorBlock.php | 27 ++++++------ .../block/attachable/WallSignBlock.php | 7 +-- src/material/block/misc/FireBlock.php | 42 +++++++++--------- src/material/block/nonfull/CakeBlock.php | 10 ++--- src/material/block/nonfull/CarpetBlock.php | 14 +++--- src/material/block/nonfull/FarmlandBlock.php | 10 ++--- src/material/block/nonfull/RailBaseBlock.php | 42 +++++++----------- src/material/block/nonfull/SnowLayerBlock.php | 10 ++--- .../block/ore/GlowingRedstoneOreBlock.php | 10 ++--- src/material/block/ore/RedstoneOreBlock.php | 8 +--- src/material/block/plant/BeetrootBlock.php | 12 ++---- .../block/plant/BrownMushroomBlock.php | 4 +- src/material/block/plant/CactusBlock.php | 25 +++++------ src/material/block/plant/CarrotBlock.php | 12 ++---- src/material/block/plant/CyanFlowerBlock.php | 6 +-- src/material/block/plant/DandelionBlock.php | 4 +- src/material/block/plant/DeadBushBlock.php | 10 ++--- src/material/block/plant/MelonStemBlock.php | 12 ++---- src/material/block/plant/PotatoBlock.php | 12 ++---- src/material/block/plant/PumpkinStemBlock.php | 12 ++---- src/material/block/plant/RedMushroomBlock.php | 4 +- src/material/block/plant/SaplingBlock.php | 4 +- src/material/block/plant/SugarcaneBlock.php | 5 +-- src/material/block/plant/TallGrassBlock.php | 4 +- src/material/block/plant/WheatBlock.php | 12 ++---- src/material/block/solid/IceBlock.php | 4 +- src/material/block/solid/LeavesBlock.php | 3 +- src/world/Level.php | 43 ++++++++++++++----- 36 files changed, 197 insertions(+), 262 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index b94b70e8..d5fb53a7 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -457,7 +457,8 @@ class BlockAPI{ return $this->cancelAction($block, $player); } } - $this->blockUpdate($target, BLOCK_UPDATE_TOUCH); + + StaticBlock::getBlock($target->getID())::interact($target->level, $target->x, $target->y, $target->z, $player); if($target->isActivable === true){ if($this->server->api->dhandle("player.block.activate", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== false and $target->onActivate($item, $player) === true){ @@ -532,13 +533,21 @@ class BlockAPI{ return false; } $level = $block::onUpdate($pos->level, $pos->x, $pos->y, $pos->z, $type); - if($level === BLOCK_UPDATE_NORMAL){ - $this->blockUpdateAround($block, $level); - } return $level; } public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){ + + if($type == BLOCK_UPDATE_NORMAL){ + try{ + throw new Exception("Deprecated: tried updating $pos using BLOCK_UPDATE_NORMAL."); + }catch(Exception $e){ + ConsoleAPI::error($e->getMessage()); + ConsoleAPI::error($e->getTraceAsString()); + } + return; + } + if($delay !== false){ $this->scheduleBlockUpdate($pos->getSide(0), $delay, $type); $this->scheduleBlockUpdate($pos->getSide(1), $delay, $type); diff --git a/src/material/Block.php b/src/material/Block.php index 0c7e4711..650a47a8 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -154,6 +154,9 @@ abstract class Block extends Position{ public $y = 0; public $z = 0; public $slipperiness; + public static function interact(Level $level, $x, $y, $z, Player $player){} + + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){} public static function getAABB(Level $level, $x, $y, $z){ return StaticBlock::getAABB($level, $x, $y, $z); diff --git a/src/material/block/DoorBlock.php b/src/material/block/DoorBlock.php index 7df89757..abfe20a6 100644 --- a/src/material/block/DoorBlock.php +++ b/src/material/block/DoorBlock.php @@ -106,23 +106,19 @@ class DoorBlock extends TransparentBlock{ } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - $id = $level->level->getBlockID($x, $y, $z); + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); + $id = $level->level->getBlockID($x, $y, $z); + + if($id == 64) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(324, 0, 1)); + elseif($id == 71) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(330, 0, 1)); - if($id == 64) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(324, 0, 1)); - elseif($id == 71) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(330, 0, 1)); - - $top = $level->level->getBlockID($x, $y + 1, $z); - if($top == IRON_DOOR_BLOCK || $top == DOOR_BLOCK){ - $level->fastSetBlockUpdate($x, $y + 1, $z, 0, 0); - } - return BLOCK_UPDATE_NORMAL; + $top = $level->level->getBlockID($x, $y + 1, $z); + if($top == IRON_DOOR_BLOCK || $top == DOOR_BLOCK){ + $level->fastSetBlockUpdate($x, $y + 1, $z, 0, 0); } } - return false; } diff --git a/src/material/block/FallableBlock.php b/src/material/block/FallableBlock.php index 856050fa..ca8113db 100644 --- a/src/material/block/FallableBlock.php +++ b/src/material/block/FallableBlock.php @@ -25,7 +25,8 @@ class FallableBlock extends SolidBlock{ */ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $ret = $this->level->setBlock($this, $this, true, false, true); - ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL); + $clz = StaticBlock::getBlock($this->getID()); + $clz::neighborChanged($this->level, $this->x, $this->y, $this->z, 0, 0, 0, 0); //TODO move to another method return $ret; } } \ No newline at end of file diff --git a/src/material/block/GenericBlock.php b/src/material/block/GenericBlock.php index ed477403..a4867017 100644 --- a/src/material/block/GenericBlock.php +++ b/src/material/block/GenericBlock.php @@ -52,14 +52,14 @@ class GenericBlock extends Block{ * * @return boolean */ - public static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ [$id, $meta] = $level->level->getBlock($x, $y, $z); - if(StaticBlock::getHasPhysics($id) and $type === BLOCK_UPDATE_NORMAL){ //TODO move from here to different class + if(StaticBlock::getHasPhysics($id)){ //TODO move from here to different class $down = $level->level->getBlockID($x, $y - 1, $z); if($down == AIR || StaticBlock::getIsLiquid($down)){ $data = array( "x" => $x + 0.5, - "y" => $y, + "y" => $y - 0.5, "z" => $z + 0.5, "Tile" => $id, ); @@ -68,9 +68,7 @@ class GenericBlock extends Block{ $e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data); $server->api->entity->spawnToAll($e); } - return false; } - return false; } /** diff --git a/src/material/block/attachable/LadderBlock.php b/src/material/block/attachable/LadderBlock.php index 4b4a99d2..97f83b37 100644 --- a/src/material/block/attachable/LadderBlock.php +++ b/src/material/block/attachable/LadderBlock.php @@ -40,7 +40,7 @@ class LadderBlock extends TransparentBlock{ return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $side = $level->level->getBlockDamage($x, $y, $z); $attached = match($side){ @@ -54,9 +54,7 @@ class LadderBlock extends TransparentBlock{ if($attached == AIR){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(LADDER, 0, 1)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - return BLOCK_UPDATE_NORMAL; } - return false; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/attachable/SignPostBlock.php b/src/material/block/attachable/SignPostBlock.php index 044bf64c..514b9fc5 100644 --- a/src/material/block/attachable/SignPostBlock.php +++ b/src/material/block/attachable/SignPostBlock.php @@ -33,14 +33,12 @@ class SignPostBlock extends TransparentBlock{ return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ //TODO remove $type + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if($level->level->getBlockID($x, $y - 1, $z) === AIR){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SIGN, 0, 1)); //$this->level->setBlock($this, new AirBlock(), true, true, true); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true); - return BLOCK_UPDATE_NORMAL; } - return false; } public function onBreak(Item $item, Player $player){ diff --git a/src/material/block/attachable/TorchBlock.php b/src/material/block/attachable/TorchBlock.php index 11c5db80..c8b81963 100644 --- a/src/material/block/attachable/TorchBlock.php +++ b/src/material/block/attachable/TorchBlock.php @@ -14,24 +14,20 @@ class TorchBlock extends FlowableBlock implements LightingBlock{ return null; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - $side = $level->level->getBlockDamage($x, $y, $z); - $attach = match($side){ - 1 => $level->level->getBlockID($x - 1, $y, $z), - 2 => $level->level->getBlockID($x + 1, $y, $z), - 3 => $level->level->getBlockID($x, $y, $z - 1), - 4 => $level->level->getBlockID($x, $y, $z + 1), - default => $level->level->getBlockID($x, $y - 1, $z) - }; + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + $side = $level->level->getBlockDamage($x, $y, $z); + $attach = match($side){ + 1 => $level->level->getBlockID($x - 1, $y, $z), + 2 => $level->level->getBlockID($x + 1, $y, $z), + 3 => $level->level->getBlockID($x, $y, $z - 1), + 4 => $level->level->getBlockID($x, $y, $z + 1), + default => $level->level->getBlockID($x, $y - 1, $z) + }; - if(StaticBlock::getIsTransparent($attach) && !($side === 0 && $attach === FENCE)){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; - } + if(StaticBlock::getIsTransparent($attach) && !($side === 0 && $attach === FENCE)){ //Replace with common break method + ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1)); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } - return false; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/attachable/TrapdoorBlock.php b/src/material/block/attachable/TrapdoorBlock.php index 2a4b7996..5674318b 100644 --- a/src/material/block/attachable/TrapdoorBlock.php +++ b/src/material/block/attachable/TrapdoorBlock.php @@ -74,24 +74,21 @@ class TrapdoorBlock extends TransparentBlock{ array($this->id, 0, 1), ); } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + $attach = match($level->level->getBlockDamage($x, $y, $z)){ + 0, 4 => $level->level->getBlockID($x, $y, $z + 1), + 1, 5 => $level->level->getBlockID($x, $y, $z - 1), + 2, 6 => $level->level->getBlockID($x + 1, $y, $z), + 3, 7 => $level->level->getBlockID($x - 1, $y, $z), + default => 0 + }; - $attach = match($level->level->getBlockDamage($x, $y, $z)){ - 0, 4 => $level->level->getBlockID($x, $y, $z + 1), - 1, 5 => $level->level->getBlockID($x, $y, $z - 1), - 2, 6 => $level->level->getBlockID($x + 1, $y, $z), - 3, 7 => $level->level->getBlockID($x - 1, $y, $z), - default => 0 - }; - - if($attach == AIR){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TRAPDOOR, 0, 1)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - return BLOCK_UPDATE_NORMAL; - } + if($attach == AIR){ //Replace with common break method + ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TRAPDOOR, 0, 1)); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } } + public function onActivate(Item $item, Player $player){ $this->meta ^= 0x04; $this->level->setBlock($this, $this, true, false, true); diff --git a/src/material/block/attachable/WallSignBlock.php b/src/material/block/attachable/WallSignBlock.php index daaf164c..5eff39af 100644 --- a/src/material/block/attachable/WallSignBlock.php +++ b/src/material/block/attachable/WallSignBlock.php @@ -10,8 +10,7 @@ class WallSignBlock extends SignPostBlock{ $this->isSolid = false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $attached = match($level->level->getBlockDamage($x, $y, $z)){ 2 => $level->level->getBlockID($x, $y, $z + 1), 3 => $level->level->getBlockID($x, $y, $z - 1), @@ -19,12 +18,10 @@ class WallSignBlock extends SignPostBlock{ 5 => $level->level->getBlockID($x - 1, $y, $z), default => WALL_SIGN }; - + if(!StaticBlock::getIsSolid($attached) && $attached != SIGN_POST && $attached != WALL_SIGN){ $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true); (ServerAPI::request())->api->entity->drop(new Position($x + 0.5, $y + 0.5, $z + 0.5, $level), BlockAPI::getItem(SIGN, 0, 1)); } - - return false; } } \ No newline at end of file diff --git a/src/material/block/misc/FireBlock.php b/src/material/block/misc/FireBlock.php index aef7f4d7..6a62ac50 100644 --- a/src/material/block/misc/FireBlock.php +++ b/src/material/block/misc/FireBlock.php @@ -36,27 +36,28 @@ class FireBlock extends FlowableBlock implements LightingBlock{ public function getMaxLightValue(){ return 15; } + + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + $b = $level->level->getBlockID($x, $y - 1, $z); + if($b != AIR && StaticBlock::getIsLiquid($b)) return false; + $b = $level->level->getBlockID($x, $y - 1, $z); + if($b != AIR && StaticBlock::getIsLiquid($b)) return false; + + $b = $level->level->getBlockID($x - 1, $y, $z); + if($b != AIR && StaticBlock::getIsLiquid($b)) return false; + $b = $level->level->getBlockID($x + 1, $y, $z); + if($b != AIR && StaticBlock::getIsLiquid($b)) return false; + + $b = $level->level->getBlockID($x, $y, $z - 1); + if($b != AIR && StaticBlock::getIsLiquid($b)) return false; + $b = $level->level->getBlockID($x, $y, $z + 1); + if($b != AIR && StaticBlock::getIsLiquid($b)) return false; + + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + } + public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - - $b = $level->level->getBlockID($x, $y - 1, $z); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - $b = $level->level->getBlockID($x, $y - 1, $z); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - - $b = $level->level->getBlockID($x - 1, $y, $z); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - $b = $level->level->getBlockID($x + 1, $y, $z); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - - $b = $level->level->getBlockID($x, $y, $z - 1); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - $b = $level->level->getBlockID($x, $y, $z + 1); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - return BLOCK_UPDATE_NORMAL; - }else if($type === BLOCK_UPDATE_SCHEDULED){ //TODO get rid of it + if($type === BLOCK_UPDATE_SCHEDULED){ $idBelow = $level->level->getBlockID($x, $y - 1, $z); [$id, $meta] = $level->level->getBlock($x, $y, $z); $alwaysBurn = $idBelow == NETHERRACK; @@ -83,7 +84,6 @@ class FireBlock extends FlowableBlock implements LightingBlock{ $level->scheduleBlockUpdate(new Position($x, $y, $z, $level), 30, BLOCK_UPDATE_SCHEDULED); //TODO looks like it also adds mt_rand(0, 9) to it } - return false; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ parent::place($item, $player, $block, $target, $face, $fx, $fy, $fz); diff --git a/src/material/block/nonfull/CakeBlock.php b/src/material/block/nonfull/CakeBlock.php index c142d2fc..50a3baeb 100644 --- a/src/material/block/nonfull/CakeBlock.php +++ b/src/material/block/nonfull/CakeBlock.php @@ -29,14 +29,10 @@ class CakeBlock extends TransparentBlock{ return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } - return false; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/nonfull/CarpetBlock.php b/src/material/block/nonfull/CarpetBlock.php index 875637e0..0e9959e7 100644 --- a/src/material/block/nonfull/CarpetBlock.php +++ b/src/material/block/nonfull/CarpetBlock.php @@ -35,15 +35,11 @@ class CarpetBlock extends FlowableBlock{ } return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method - [$id, $meta] = $level->level->getBlock($x, $y, $z); - ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem($id, $meta)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method + [$id, $meta] = $level->level->getBlock($x, $y, $z); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem($id, $meta)); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } - return false; } } \ No newline at end of file diff --git a/src/material/block/nonfull/FarmlandBlock.php b/src/material/block/nonfull/FarmlandBlock.php index 14cf3fcd..b7d1fb20 100644 --- a/src/material/block/nonfull/FarmlandBlock.php +++ b/src/material/block/nonfull/FarmlandBlock.php @@ -58,14 +58,10 @@ class FarmlandBlock extends TransparentBlock{ } } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z))){ - $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true); - return $type; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z))){ + $level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true); } - return false; } public function getBlockID($x, $y, $z){ diff --git a/src/material/block/nonfull/RailBaseBlock.php b/src/material/block/nonfull/RailBaseBlock.php index d406253d..49c760c2 100644 --- a/src/material/block/nonfull/RailBaseBlock.php +++ b/src/material/block/nonfull/RailBaseBlock.php @@ -26,33 +26,23 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here public function updateState(){} - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - [$id, $meta] = $level->level->getBlock($x, $y, $z); - if($id === POWERED_RAIL){ - $meta &= 7; - } - if( - ($level->level->getBlockID($x, $y - 1, $z) === 0) || - (($meta == 2) && $level->level->getBlockID($x + 1, $y, $z) === 0) || - (($meta == 3) && $level->level->getBlockID($x - 1, $y, $z) === 0) || - (($meta == 4) && $level->level->getBlockID($x, $y, $z - 1) === 0) || - (($meta == 5) && $level->level->getBlockID($x, $y, $z + 1) === 0) - ){ - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem($id, $meta, 1)); - }else{ - //TODO fix me pls $this->updateState(); - } - - - //if($this->getSide(0)->getID() === AIR){//Replace with common break method - // ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1)); - // $this->level->setBlock($this, new AirBlock(), true, false, true); - //} - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + [$id, $meta] = $level->level->getBlock($x, $y, $z); + if($id === POWERED_RAIL){ + $meta &= 7; + } + if( + ($level->level->getBlockID($x, $y - 1, $z) === 0) || + (($meta == 2) && $level->level->getBlockID($x + 1, $y, $z) === 0) || + (($meta == 3) && $level->level->getBlockID($x - 1, $y, $z) === 0) || + (($meta == 4) && $level->level->getBlockID($x, $y, $z - 1) === 0) || + (($meta == 5) && $level->level->getBlockID($x, $y, $z + 1) === 0) + ){ + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem($id, $meta, 1)); + }else{ + //TODO fix me pls $this->updateState(); } - } } diff --git a/src/material/block/nonfull/SnowLayerBlock.php b/src/material/block/nonfull/SnowLayerBlock.php index fda65d8e..834cc71d 100644 --- a/src/material/block/nonfull/SnowLayerBlock.php +++ b/src/material/block/nonfull/SnowLayerBlock.php @@ -20,14 +20,10 @@ class SnowLayerBlock extends FlowableBlock{ return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); } - return false; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/ore/GlowingRedstoneOreBlock.php b/src/material/block/ore/GlowingRedstoneOreBlock.php index 2829377d..fc123f00 100644 --- a/src/material/block/ore/GlowingRedstoneOreBlock.php +++ b/src/material/block/ore/GlowingRedstoneOreBlock.php @@ -5,15 +5,11 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{ parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore"); $this->hardness = 15; } + public static function onRandomTick(Level $level, $x, $y, $z){ - $level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(REDSTONE_ORE, $level->level->getBlockDamage($x, $y, $z)), false, false, true); - } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_SCHEDULED){ //TODO replace with BLOCK_UPDATE_NORMAL - $level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0); - } - return false; + $level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0); } + public function getMaxLightValue(){ return 9; } diff --git a/src/material/block/ore/RedstoneOreBlock.php b/src/material/block/ore/RedstoneOreBlock.php index ea5c991f..ca134967 100644 --- a/src/material/block/ore/RedstoneOreBlock.php +++ b/src/material/block/ore/RedstoneOreBlock.php @@ -6,12 +6,8 @@ class RedstoneOreBlock extends SolidBlock{ $this->hardness = 15; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL || $type === BLOCK_UPDATE_TOUCH){ //TODO remove BLOCK_UPDATE_TOUCH - $level->fastSetBlockUpdate($x, $y, $z, GLOWING_REDSTONE_ORE, 0); - $level->scheduleBlockUpdate(new Position($x, $y, $z, $level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); - } - return false; + public static function interact(Level $level, $x, $y, $z, Player $player){ + $level->fastSetBlockUpdate($x, $y, $z, GLOWING_REDSTONE_ORE, 0); } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/plant/BeetrootBlock.php b/src/material/block/plant/BeetrootBlock.php index fffa936c..5a1b273a 100644 --- a/src/material/block/plant/BeetrootBlock.php +++ b/src/material/block/plant/BeetrootBlock.php @@ -39,15 +39,11 @@ class BeetrootBlock extends FlowableBlock{ return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ - ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(BEETROOT_SEEDS, 0, 1)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(BEETROOT_SEEDS, 0, 1)); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } - return false; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/plant/BrownMushroomBlock.php b/src/material/block/plant/BrownMushroomBlock.php index 16ac4b49..d0892ccb 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 static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(BROWN_MUSHROOM)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; } - return false; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/plant/CactusBlock.php b/src/material/block/plant/CactusBlock.php index d32b8bbd..48d1dffb 100644 --- a/src/material/block/plant/CactusBlock.php +++ b/src/material/block/plant/CactusBlock.php @@ -25,8 +25,7 @@ class CactusBlock extends TransparentBlock{ for($yy = 1; $yy < 3; ++$yy){ $bID = $level->level->getBlockID($x, $y + $yy, $z); if($bID === AIR){ - $level->fastSetBlockUpdate($x, $y + $yy, $z, CACTUS, 0); - CactusBlock::onUpdate($level, $x, $y + $yy, $z, BLOCK_UPDATE_NORMAL); //TODO rewrite ticking + $level->fastSetBlockUpdate($x, $y + $yy, $z, CACTUS, 0, true); break; } } @@ -39,20 +38,16 @@ class CactusBlock extends TransparentBlock{ } } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - $down = $level->level->getBlockID($x, $y, $z); - $b0 = $level->level->getBlockID($x, $y, $z - 1); - $b1 = $level->level->getBlockID($x, $y, $z + 1); - $b2 = $level->level->getBlockID($x - 1, $y, $z); - $b3 = $level->level->getBlockID($x + 1, $y, $z); - if(!StaticBlock::getIsFlowable($b0) || !StaticBlock::getIsFlowable($b1) || !StaticBlock::getIsFlowable($b2) || !StaticBlock::getIsFlowable($b3) || ($down !== SAND and $down !== CACTUS)){ //Replace with common break method - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CACTUS)); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + $down = $level->level->getBlockID($x, $y, $z); + $b0 = $level->level->getBlockID($x, $y, $z - 1); + $b1 = $level->level->getBlockID($x, $y, $z + 1); + $b2 = $level->level->getBlockID($x - 1, $y, $z); + $b3 = $level->level->getBlockID($x + 1, $y, $z); + if(!StaticBlock::getIsFlowable($b0) || !StaticBlock::getIsFlowable($b1) || !StaticBlock::getIsFlowable($b2) || !StaticBlock::getIsFlowable($b3) || ($down !== SAND and $down !== CACTUS)){ //Replace with common break method + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CACTUS)); } - return false; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/plant/CarrotBlock.php b/src/material/block/plant/CarrotBlock.php index 109a064f..b82ab91a 100644 --- a/src/material/block/plant/CarrotBlock.php +++ b/src/material/block/plant/CarrotBlock.php @@ -41,15 +41,11 @@ class CarrotBlock extends FlowableBlock{ } } } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ - ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CARROT, 0, 1)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CARROT, 0, 1)); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } - return false; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/plant/CyanFlowerBlock.php b/src/material/block/plant/CyanFlowerBlock.php index 19cb6dc2..4addd322 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -20,15 +20,15 @@ class CyanFlowerBlock extends FlowableBlock{ return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(CYAN_FLOWER)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; } - return false; } + + public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ if(($player->gamemode & 0x01) === 0){ diff --git a/src/material/block/plant/DandelionBlock.php b/src/material/block/plant/DandelionBlock.php index b1a108a6..bdd94561 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 static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(DANDELION)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; } - return false; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/plant/DeadBushBlock.php b/src/material/block/plant/DeadBushBlock.php index 8e05cd1b..100d51f6 100644 --- a/src/material/block/plant/DeadBushBlock.php +++ b/src/material/block/plant/DeadBushBlock.php @@ -11,14 +11,10 @@ class DeadBushBlock extends FlowableBlock{ return null; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } - return false; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/plant/MelonStemBlock.php b/src/material/block/plant/MelonStemBlock.php index 7cec6dd6..ca9571b6 100644 --- a/src/material/block/plant/MelonStemBlock.php +++ b/src/material/block/plant/MelonStemBlock.php @@ -43,15 +43,11 @@ class MelonStemBlock extends FlowableBlock{ } } } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2))); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ + ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2))); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } - return false; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/plant/PotatoBlock.php b/src/material/block/plant/PotatoBlock.php index 58cb13f6..35296a50 100644 --- a/src/material/block/plant/PotatoBlock.php +++ b/src/material/block/plant/PotatoBlock.php @@ -41,15 +41,11 @@ class PotatoBlock extends FlowableBlock{ return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ - ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(POTATO, 0, 1)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(POTATO, 0, 1)); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } - return false; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/plant/PumpkinStemBlock.php b/src/material/block/plant/PumpkinStemBlock.php index f74d4d11..df914871 100644 --- a/src/material/block/plant/PumpkinStemBlock.php +++ b/src/material/block/plant/PumpkinStemBlock.php @@ -43,15 +43,11 @@ class PumpkinStemBlock extends FlowableBlock{ } } } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2))); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ + ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2))); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } - return false; } public function onActivate(Item $item, Player $player){ diff --git a/src/material/block/plant/RedMushroomBlock.php b/src/material/block/plant/RedMushroomBlock.php index abd4db15..233ff0fc 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 static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(RED_MUSHROOM)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; } - return false; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/block/plant/SaplingBlock.php b/src/material/block/plant/SaplingBlock.php index 83c0b834..42bc95a6 100644 --- a/src/material/block/plant/SaplingBlock.php +++ b/src/material/block/plant/SaplingBlock.php @@ -42,14 +42,12 @@ class SaplingBlock extends FlowableBlock{ } return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method [$id, $meta] = $level->level->getBlock($x, $y, $z); ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem($id, $meta)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; } - return false; } public static function onRandomTick(Level $level, $x, $y, $z){ if(mt_rand(1,7) === 1){ diff --git a/src/material/block/plant/SugarcaneBlock.php b/src/material/block/plant/SugarcaneBlock.php index aeb450e7..b7eee207 100644 --- a/src/material/block/plant/SugarcaneBlock.php +++ b/src/material/block/plant/SugarcaneBlock.php @@ -36,7 +36,7 @@ class SugarcaneBlock extends FlowableBlock{ return false; } - public static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $down = $level->level->getBlockID($x, $y - 1, $z); if($down == GRASS or $down == DIRT or $down == SAND){ $b0 = $level->level->getBlockID($x, $y - 1, $z - 1); @@ -46,15 +46,12 @@ class SugarcaneBlock extends FlowableBlock{ if($b0 != WATER && $b0 != STILL_WATER && $b1 != WATER && $b1 != STILL_WATER && $b2 != WATER && $b2 != STILL_WATER && $b3 != WATER && $b3 != STILL_WATER){ $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SUGARCANE)); - return true; } } if(StaticBlock::getIsTransparent($down) && $down != SUGARCANE_BLOCK){ //Replace with common break method ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(SUGARCANE)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - return BLOCK_UPDATE_NORMAL; } - return false; } public static function onRandomTick(Level $level, $x, $y, $z){ $aboveID = $level->level->getBlockID($x, $y + 1, $z); diff --git a/src/material/block/plant/TallGrassBlock.php b/src/material/block/plant/TallGrassBlock.php index f5e68b3f..33afa559 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 static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(WHEAT_SEEDS)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; } - return false; } public static function getAABB(Level $level, $x, $y, $z){ diff --git a/src/material/block/plant/WheatBlock.php b/src/material/block/plant/WheatBlock.php index 7508cf0d..80b46af0 100644 --- a/src/material/block/plant/WheatBlock.php +++ b/src/material/block/plant/WheatBlock.php @@ -41,15 +41,11 @@ class WheatBlock extends FlowableBlock{ } } } - public static function onUpdate(Level $level, $x, $y, $z, $type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ - ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(WHEAT_SEEDS, 0, 1)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - return BLOCK_UPDATE_NORMAL; - } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){ + ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(WHEAT_SEEDS, 0, 1)); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } - return false; } public function getDrops(Item $item, Player $player){ diff --git a/src/material/block/solid/IceBlock.php b/src/material/block/solid/IceBlock.php index c05a8920..e394825b 100644 --- a/src/material/block/solid/IceBlock.php +++ b/src/material/block/solid/IceBlock.php @@ -42,7 +42,7 @@ class IceBlock extends TransparentBlock{ } } } - public static function onUpdate(Level $level, $x, $y, $z, $type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/ + //public static function onUpdate(Level $level, $x, $y, $z, $type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/ /*if($type === BLOCK_UPDATE_RANDOM){ $light = $this->scanForNearbyLightSources(3,3,3); if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){ @@ -52,7 +52,7 @@ class IceBlock extends TransparentBlock{ return BLOCK_UPDATE_RANDOM; } return false;*/ //TODO ice melting(after light?) - } + //} public function getBreakTime(Item $item, Player $player){ if(($player->gamemode & 0x01) === 0x01){ return 0.20; diff --git a/src/material/block/solid/LeavesBlock.php b/src/material/block/solid/LeavesBlock.php index 0b45ab40..c64564a8 100644 --- a/src/material/block/solid/LeavesBlock.php +++ b/src/material/block/solid/LeavesBlock.php @@ -64,13 +64,12 @@ class LeavesBlock extends TransparentBlock{ } } } - public static function onUpdate(Level $level, $x, $y, $z, $type){ + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ [$id, $meta] = $level->level->getBlock($x, $y, $z); if(($meta & 0b00001100) === 0){ $meta |= 0x08; $level->fastSetBlockUpdate($x, $y, $z, $id, $meta); //TODO maybe use $level->level->setBlock directly, the client doesnt need to know thism info. } - return false; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/world/Level.php b/src/world/Level.php index d29ea6f8..8b02b4d4 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -459,22 +459,42 @@ class Level{ } public function fastSetBlockUpdateMeta($x, $y, $z, $meta, $updateBlock = false){ $this->level->setBlockDamage($x, $y, $z, $meta); - $this->addBlockToSendQueue($x, $y, $z, $this->level->getBlockID($x, $y, $z), $meta); + $id = $this->level->getBlockID($x, $y, $z); + $this->addBlockToSendQueue($x, $y, $z, $id, $meta); if($updateBlock){ - $this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1); + $this->updateNeighborsAt($x, $y, $z, $id); } } + public function updateNeighborsAt($x, $y, $z, $oldID){ + $block = $this->level->getBlockID($x - 1, $y, $z); + if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID); + $block = $this->level->getBlockID($x + 1, $y, $z); + if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID); + + $block = $this->level->getBlockID($x, $y - 1, $z); + if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID); + $block = $this->level->getBlockID($x, $y + 1, $z); + if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID); + + $block = $this->level->getBlockID($x, $y, $z - 1); + if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID); + $block = $this->level->getBlockID($x, $y, $z + 1); + if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID); + } + public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false){ + $oldID = $this->level->getBlockID($x, $y, $z); + $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(); } + if($updateBlocksAround){ + self::updateNeighborsAt($x, $y, $z, $oldID); + } + $this->addBlockToSendQueue($x, $y, $z, $id, $meta); } public function onTick(PocketMinecraftServer $server, $currentTime){ @@ -683,6 +703,7 @@ class Level{ if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){ return false; } + $oldID = $this->level->getBlockID($pos->x, $pos->y, $pos->z); $ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata()); if($ret === true){ if(!($pos instanceof Position)){ @@ -700,15 +721,17 @@ class Level{ $this->changedBlocks[$i][] = [$block->x, $block->y, $block->z, $block->id, $block->getMetadata()]; ++$this->changedCount[$i]; } - - if($update === true){ - $this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1); - } + if($tiles === true){ if(($t = $this->server->api->tile->get($pos)) !== false){ $t->close(); } } + + if($update === true){ + $this->updateNeighborsAt($pos->x, $pos->y, $pos->z, $oldID); + } + } return $ret; } From 2f2c053255dfd42e6edbb25e2ddf4685290789c9 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 22 May 2024 07:22:20 +0300 Subject: [PATCH 03/10] begin reimplementing liquids --- src/material/block/LiquidBlock.php | 33 +++++ src/material/block/liquid/LavaBlock.php | 120 +----------------- .../block/liquid/LiquidBlockDynamic.php | 7 + .../block/liquid/LiquidBlockStatic.php | 29 +++++ src/material/block/liquid/StillLavaBlock.php | 6 +- src/material/block/liquid/StillWaterBlock.php | 5 +- src/material/block/liquid/WaterBlock.php | 111 +--------------- 7 files changed, 89 insertions(+), 222 deletions(-) create mode 100644 src/material/block/liquid/LiquidBlockDynamic.php create mode 100644 src/material/block/liquid/LiquidBlockStatic.php diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index 2cfa7f72..8aeb010f 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -24,6 +24,39 @@ class LiquidBlock extends TransparentBlock{ return $f; } + public static function getTickDelay(){ + throw new RuntimeException("If you see this, something bad happened"); + } + + public static function updateLiquid(Level $level, $x, $y, $z){ + [$id, $meta] = $level->level->getBlock($x, $y, $z); + if($id != LAVA && $id != STILL_LAVA) continue; + + $zNeg = $level->level->getBlockID($x, $y, $z - 1); + $zPos = $level->level->getBlockID($x, $y, $z + 1); + $xNeg = $level->level->getBlockID($x - 1, $y, $z); + $xPos = $level->level->getBlockID($x + 1, $y, $z); + $yPos = $level->level->getBlockID($x, $y + 1, $z); + + if( + $zNeg == WATER || $zNeg == STILL_WATER + || $zPos == WATER || $zPos == STILL_WATER + || $xNeg == WATER || $xNeg == STILL_WATER + || $xPos == WATER || $xPos == STILL_WATER + || $yPos == WATER || $yPos == STILL_WATER + ) { + if($meta){ + //if($meta > 4) -> fizz & ret + $replacement = COBBLESTONE; + }else{ + $replacement = OBSIDIAN; + } + + $level->fastSetBlockUpdate($x, $y, $z, $replacement, true); + } + } + + public function getDrops(Item $item, Player $player){ return array(); } diff --git a/src/material/block/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index 9e2506c2..7a6b7cdd 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -1,6 +1,6 @@ hardness = 500; @@ -8,123 +8,15 @@ class LavaBlock extends LiquidBlock implements LightingBlock{ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $ret = $this->level->setBlock($this, $this, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL); + //TODO place ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 40, BLOCK_UPDATE_NORMAL); return $ret; } + public static function getTickDelay(){ + return 30; + } + public function getMaxLightValue(){ return 15; } - - public function getSourceCount(){ - $count = 0; - for($side = 2; $side <= 5; ++$side){ - if($this->getSide($side) instanceof LavaBlock ){ - $b = $this->getSide($side); - $level = $b->meta & 0x06; - if($level == 0x00){ - $count++; - } - } - } - return $count; - } - - public function checkWater(){ - for($side = 0; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - $level = $this->meta & 0x07; - if($level == 0x00){ - $this->level->setBlock($b, new ObsidianBlock(), false, false, true); - }else{ - $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); - } - } - } - } - - public function getFrom(){ - for($side = 0; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof LavaBlock){ - $tlevel = $b->meta & 0x06; - $level = $this->meta & 0x06; - if( ($tlevel + 2) == $level || ($side == 0x01 && $level == 0x01 ) || ($tlevel == 6 && $level == 6 )){ - return $b; - } - } - } - return null; - } - - 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/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php new file mode 100644 index 00000000..085e6ccb --- /dev/null +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -0,0 +1,7 @@ +level->getBlock($x, $y, $z); + $dynamicID =$id - 1; //very unsafe + $level->fastSetBlockUpdate($x, $y, $z, $dynamicID, $meta); + $delay = static::getTickDelay(); + ServerAPI::request()->api->block->blockUpdateAroundXYZ($x, $y, $z, BLOCK_UPDATE_SCHEDULED, $delay); + } + + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + $oldID = $level->level->getBlockID($x, $y, $z); + static::updateLiquid($level, $x, $y, $z); + $newID = $level->level->getBlockID($x, $y, $z); + if($oldID == $newID){ + static::setDynamic($level, $x, $y, $z); + } + } + + +} \ No newline at end of file diff --git a/src/material/block/liquid/StillLavaBlock.php b/src/material/block/liquid/StillLavaBlock.php index ea82e135..a0388e82 100644 --- a/src/material/block/liquid/StillLavaBlock.php +++ b/src/material/block/liquid/StillLavaBlock.php @@ -1,9 +1,13 @@ hardness = 500; } + public static function getTickDelay(){ + return 30; + } + } \ No newline at end of file diff --git a/src/material/block/liquid/StillWaterBlock.php b/src/material/block/liquid/StillWaterBlock.php index 67ae7ab1..d6fd7f64 100644 --- a/src/material/block/liquid/StillWaterBlock.php +++ b/src/material/block/liquid/StillWaterBlock.php @@ -5,10 +5,13 @@ require_once("WaterBlock.php"); //TODO class loader? /***REM_END***/ -class StillWaterBlock extends WaterBlock{ +class StillWaterBlock extends LiquidBlockStatic{ public function __construct($meta = 0){ LiquidBlock::__construct(STILL_WATER, $meta, "Still Water"); $this->hardness = 500; } + public static function getTickDelay(){ + return 5; + } } \ No newline at end of file diff --git a/src/material/block/liquid/WaterBlock.php b/src/material/block/liquid/WaterBlock.php index 201ad48f..555b783c 100644 --- a/src/material/block/liquid/WaterBlock.php +++ b/src/material/block/liquid/WaterBlock.php @@ -1,6 +1,6 @@ hardness = 500; @@ -8,116 +8,15 @@ class WaterBlock extends LiquidBlock{ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $ret = $this->level->setBlock($this, $this, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); + //TODO place ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); return $ret; } - public function getSourceCount(){ - $count = 0; - for($side = 2; $side <= 5; ++$side){ - if( $this->getSide($side) instanceof WaterBlock ){ - $b = $this->getSide($side); - $level = $b->meta & 0x07; - if($level == 0x00){ - $count++; - } - } - } - return $count; - } - - public function checkLava(){ - $ret = false; - for($side = 0; $side <= 5; ++$side){ - if($side == 1){ - continue; - } - $b = $this->getSide($side); - if($b instanceof LavaBlock){ - $level = $b->meta & 0x07; - if($level == 0x00){ - $this->level->setBlock($b, new ObsidianBlock(), false, false, true); - }else{ - $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); - } - $ret = true; - } - } - return $ret; - } - - public function getFrom(){ - for($side = 0; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - $tlevel = $b->meta & 0x07; - $level = $this->meta & 0x07; - if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ - return $b; - } - } - } - return null; + public static function getTickDelay(){ + return 5; } 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){ - return false; - } - - $this->checkLava(); - - $falling = $this->meta >> 3; - $down = $this->getSide(0); - - $from = $this->getFrom(); - //Has Source or Its Source - if($from !== null || $level == 0x00){ - if($down instanceof AirBlock || $down instanceof WaterBlock){ - $this->level->setBlock($down, new WaterBlock(1), false, false, true); //TODO fix somehow - ServerAPI::request()->api->block->scheduleBlockUpdate($down, 5, BLOCK_UPDATE_NORMAL); - }elseif($level !== 0x07){{ - for($side = 2; $side <= 5; ++$side){ - $b = $this->getSide($side); - if($b instanceof WaterBlock){ - if($this->getSourceCount() >= 2 && $level != 0x00){ //Infinite water source - $this->level->setBlock($this, new WaterBlock(0), false, false, true); - } - }elseif($b->isFlowable === true){ - $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate($b, 5, BLOCK_UPDATE_NORMAL); - } - } - } - } - }else{ - //Extend Remove for Left Waters - for($side = 2; $side <= 5; ++$side){ - $sb = $this->getSide($side); - if($sb instanceof WaterBlock){ - $tlevel = $sb->meta & 0x07; - if($tlevel != 0x00){ - ServerAPI::request()->api->block->blockUpdateAround($sb, BLOCK_UPDATE_NORMAL, 5); - $this->level->setBlock($sb, new AirBlock(), false, false, true); - } - } - $b = $this->getSide(0)->getSide($side); - if($b instanceof WaterBlock){ - $tlevel = $b->meta & 0x07; - if($tlevel != 0x00){ - ServerAPI::request()->api->block->blockUpdateAround($b, BLOCK_UPDATE_NORMAL, 5); - $this->level->setBlock($b, new AirBlock(), false, false, true); - } - } - } - ServerAPI::request()->api->block->blockUpdateAround($this, BLOCK_UPDATE_NORMAL, 5); - $this->level->setBlock($this, new AirBlock(), false, false, true); - } - return false;*/ + } } From fbf4131bbd0da13b7d1f10d6f48809f7ce20b626 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 22 May 2024 12:57:37 +0300 Subject: [PATCH 04/10] more liquid stuff --- src/material/block/LiquidBlock.php | 10 ++ .../block/liquid/LiquidBlockDynamic.php | 92 +++++++++++++++++++ .../block/liquid/LiquidBlockStatic.php | 2 +- 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index 8aeb010f..413e2eea 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -15,6 +15,16 @@ class LiquidBlock extends TransparentBlock{ $this->isFullBlock = true; $this->hardness = 500; } + public static $blockID = 0; + + public static function getDepth(Level $level, $x, $y, $z){ + [$id, $meta] = $level->level->getBlock($x, $y, $z); + + if($id == static::$blockID) return $meta; + return -1; + + } + public static function getAABB(Level $level, $x, $y, $z){ return null; } diff --git a/src/material/block/liquid/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php index 085e6ccb..ee013737 100644 --- a/src/material/block/liquid/LiquidBlockDynamic.php +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -4,4 +4,96 @@ class LiquidBlockDynamic extends LiquidBlock{ public function __construct($id, $meta = 0, $name = "Unknown"){ parent::__construct($id, $meta, $name); } + + public static $blockID = 0; + public static $f_d8 = 0; //TODO rename + + public static function getHighest(Level $level, $x, $y, $z, $highest){ + $depth = self::getDepth($level, $x, $y, $z); + + if($depth >= 0){ + if($depth > 7) $depth = 0; + }else{ + ++self::$f_d8; + } + + if($highest < 0) return $depth; + else if($highest >= $depth) return $depth; + + return $highest; + } + + public static function setStatic(Level $level, $x, $y, $z){ + $meta = $level->level->getBlockDamage($x, $y, $z); + + $level->fastSetBlockUpdate($x, $y, $z, self::$blockID + 1, $meta); + } + + public static function onUpdate(Level $level, $x, $y, $z, $type){ + static::$blockID = $id = $level->level->getBlockID($x, $y, $z); + $depth = static::getDepth($level, $x, $y, $z); + if($id == LAVA || $id == STILL_LAVA){ + $spreadAdder = 2; //XXX nether has 1 + //TODO also call trySpreadFire + }else{ + $spreadAdder = 1; + } + + $tickDelay = static::getTickDelay(); + if($depth > 0){ + self::$f_d8 = 0; + $highest = static::getHighest($level, $x - 1, $y, $z, -100); + $highest = static::getHighest($level, $x + 1, $y, $z, $highest); + + $highest = static::getHighest($level, $x, $y, $z - 1, $highest); + $highest = static::getHighest($level, $x, $y, $z + 1, $highest); + + if($highest + $spreadAdder > 7) $v16 = -1; + else{ + $v16 = ($highest + $spreadAdder) & ~($highest >> 31); //XXX xor? + if($highest < 0) $v16 = -1; + } + $dpth = static::getDepth($level, $x, $y + 1, $z); + if($dpth >= 0){ + if($dpth > 7) $v16 = $dpth; + else $v16 = $dpth + 8; + } + + if(static::$f_d8 && (static::$blockID == WATER || static::$blockID == STILL_WATER)){ + //XXX Level::isSolidBlockingTile + [$id, $meta] = $level->level->getBlock($x, $y, $z); + if(StaticBlock::getIsFlowable($id) || ($id == WATER || $id == STILL_WATER) && $meta != 0){ + $v16 = 0; + } + } + + if((static::$blockID == LAVA || static::$blockID == STILL_LAVA) && $depth <= 7){ + if($v16 > 7) goto LABEL_32; //TODO remove gotos + + if($v16 > $depth){ + if(mt_rand(0, 3)) $tickDelay *= 4; + + LABEL_30: + if($v16 < 0){ + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + LABEL_33: + $depth = $v16; + goto LABEL_35; + } + LABEL_32: + $level->fastSetBlockUpdateMeta($x, $y, $z, $v16, false); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($x, $y, $z, $level), $tickDelay); //TODO get rid of new Position + $level->updateNeighborsAt($x, $y, $z, self::$blockID); + goto LABEL_33; + } + } + + if($v16 != $depth) goto LABEL_30; + } + self::setStatic($level, $x, $y, $z); + LABEL_35: + //TODO + + + } } \ No newline at end of file diff --git a/src/material/block/liquid/LiquidBlockStatic.php b/src/material/block/liquid/LiquidBlockStatic.php index 08f1c710..9e68a28b 100644 --- a/src/material/block/liquid/LiquidBlockStatic.php +++ b/src/material/block/liquid/LiquidBlockStatic.php @@ -4,7 +4,7 @@ class LiquidBlockStatic extends LiquidBlock{ public function __construct($id, $meta = 0, $name = "Unknown"){ parent::__construct($id, $meta, $name); } - + public static $blockID = 0; //TODO: tick: try spread fire if lava public static function setDynamic(Level $level, $x, $y, $z){ From b94d0f2ba13f5076a6a92fa08ee7a4b246646a19 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 23 May 2024 04:59:48 +0300 Subject: [PATCH 05/10] ported by needs fixing --- src/API/BlockAPI.php | 21 +++ src/material/block/LiquidBlock.php | 6 +- src/material/block/liquid/LavaBlock.php | 1 + .../block/liquid/LiquidBlockDynamic.php | 166 +++++++++++++++++- .../block/liquid/LiquidBlockStatic.php | 6 +- src/material/block/liquid/StillLavaBlock.php | 1 + src/material/block/liquid/StillWaterBlock.php | 2 + src/material/block/liquid/WaterBlock.php | 5 +- src/world/Level.php | 6 + 9 files changed, 201 insertions(+), 13 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index d5fb53a7..92bc0034 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -536,6 +536,9 @@ class BlockAPI{ return $level; } + + + public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){ if($type == BLOCK_UPDATE_NORMAL){ @@ -564,6 +567,24 @@ class BlockAPI{ $this->blockUpdate($pos->getSide(5), $type); } } + public function scheduleBlockUpdateXYZ(Level $level, $x, $y, $z, $type = BLOCK_UPDATE_SCHEDULED, $delay = false){ + $type = (int) $type; + ConsoleAPI::debug($delay); + if($delay < 0){ + return false; + } + + $index = $x . "." . $y . "." . $z . "." . $level->getName() . "." . $type; + $delay = microtime(true) + $delay * 0.05; + ConsoleAPI::debug($index); + if(!isset($this->scheduledUpdates[$index])){ + $this->scheduledUpdates[$index] = new Position($x, $y, $z, $level); //TODO dont create a position + $this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES ($x, $y, $z, '{$level->getName()}', $type, $delay);"); + ConsoleAPI::debug("added block update $x $y $z $type"); + return true; + } + return false; + } public function scheduleBlockUpdate(Position $pos, $delay, $type = BLOCK_UPDATE_SCHEDULED){ $type = (int) $type; diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index 413e2eea..aaa89868 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -24,7 +24,9 @@ class LiquidBlock extends TransparentBlock{ return -1; } - + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + static::updateLiquid($level, $x, $y, $z); + } public static function getAABB(Level $level, $x, $y, $z){ return null; } @@ -40,7 +42,7 @@ class LiquidBlock extends TransparentBlock{ public static function updateLiquid(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); - if($id != LAVA && $id != STILL_LAVA) continue; + if($id != LAVA && $id != STILL_LAVA) return; $zNeg = $level->level->getBlockID($x, $y, $z - 1); $zPos = $level->level->getBlockID($x, $y, $z + 1); diff --git a/src/material/block/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index 7a6b7cdd..ba02516b 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -1,4 +1,5 @@ fastSetBlockUpdate($x, $y, $z, self::$blockID + 1, $meta); } + public static function isWaterBlocking(Level $level, $x, $y, $z){ + $id = $level->level->getBlockID($x, $y, $z); + + if($id == AIR) return false; + + if($id == DOOR_BLOCK || $id == SIGN || $id == LADDER || $id == SUGARCANE_BLOCK) return true; + + if($id == CARPET || $id == SNOW_LAYER || $id == RAIL || $id == POWERED_RAIL) return false; //TODO Tile::getThickness() > 0 + + //TODO materials + if(!StaticBlock::getIsFlowable($id)) return 1; + else return StaticBlock::getIsSolid($id); + } + + public static function canSpreadTo(Level $level, $x, $y, $z){ + $id = $level->level->getBlockID($x, $y, $z); + if($id == LAVA || $id == STILL_LAVA) return false; + if((static::$blockID == WATER || static::$blockID == STILL_WATER) && ($id == WATER || $id == STILL_WATER)) return false; + + return static::isWaterBlocking($level, $x, $y, $z) ^ 1; + } + + public static function getSpread(Level $level, $x, $y, $z){ + //TODO get rid of gotos + for($i = 0; $i < 4; ++$i){ + static::$spread[$i] = 1000; + $xs = $x; + $ys = $y; + $zs = $z; + + switch($i){ + case 0: + --$xs; + break; + case 1: + ++$xs; + break; + case 2: + --$zs; + break; + case 3: + ++$zs; + break; + } + + if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue; + [$id, $meta] = $level->level->getBlock($xs, $ys, $zs); + + if( + (((static::$blockID == WATER || static::$blockID == STILL_WATER) && ($id == WATER || $id == STILL_WATER)) || + ((static::$blockID == LAVA || static::$blockID == STILL_LAVA) && ($id == LAVA || $id == STILL_LAVA))) && + $meta == 0 + ){ + continue; + } + + if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) static::$spread[$i] = 0; + else static::$spread[$i] = static::getSlopeDistance($level, $xs, $ys, $zs, 1, $i); + } + + $i1 = max(static::$spread); + $ba = []; + for($i = 0; $i < 4; ++$i) $ba[$i] = ($i1 == static::$spread[$i]); + return $ba; + } + + public static function getSlopeDistance(Level $level, $x, $y, $z, $l, $i1){ + $j1 = 1000; + for($k1 = 0; $k1 < 4; ++$k1){ + if($k1 == 0 && $i1 == 1 || $k1 == 1 && $i1 == 0 || $k1 == 2 && $i1 == 3 || $k1 == 3 && $i1 == 2){ + continue; + } + + $xs = $x; + $ys = $y; + $zs = $z; + + switch($k1){ + case 0: + --$xs; + break; + case 1: + ++$xs; + break; + case 2: + --$zs; + break; + case 3: + ++$zs; + break; + } + + if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue; + [$id, $meta] = $level->level->getBlock($xs, $ys, $zs); + + if( + (((static::$blockID == WATER || static::$blockID == STILL_WATER) && ($id == WATER || $id == STILL_WATER)) || + ((static::$blockID == LAVA || static::$blockID == STILL_LAVA) && ($id == LAVA || $id == STILL_LAVA))) && + $meta == 0 + ){ + continue; + } + + if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) return $l; + + if($l >= 4) continue; + $k2 = static::getSlopeDistance($level, $xs, $ys, $zs, $l + 1, $k1); + if($k2 < $j1) $j1 = $k2; + } + return $j1; + } + + public static function trySpreadTo(Level $level, $x, $y, $z, $meta){ + if(static::canSpreadTo($level, $x, $y, $z)){ + $id = $level->level->getBlockID($x, $y, $z); + + if($id > 0){ + if(($id == LAVA || $id == STILL_LAVA) && (self::$id == LAVA || self::$id == STILL_LAVA)); //fizz + else{ + //TODO spawnResources + } + } + + $level->fastSetBlockUpdate($x, $y, $z, self::$blockID, $meta, true); + } + } + public static function onUpdate(Level $level, $x, $y, $z, $type){ static::$blockID = $id = $level->level->getBlockID($x, $y, $z); $depth = static::getDepth($level, $x, $y, $z); @@ -71,7 +199,7 @@ class LiquidBlockDynamic extends LiquidBlock{ if($v16 > 7) goto LABEL_32; //TODO remove gotos if($v16 > $depth){ - if(mt_rand(0, 3)) $tickDelay *= 4; + //if(mt_rand(0, 3)) $tickDelay *= 4; LABEL_30: if($v16 < 0){ @@ -83,17 +211,45 @@ class LiquidBlockDynamic extends LiquidBlock{ LABEL_32: $level->fastSetBlockUpdateMeta($x, $y, $z, $v16, false); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($x, $y, $z, $level), $tickDelay); //TODO get rid of new Position - $level->updateNeighborsAt($x, $y, $z, self::$blockID); + $level->updateNeighborsAt($x, $y, $z, static::$blockID); goto LABEL_33; } } if($v16 != $depth) goto LABEL_30; } - self::setStatic($level, $x, $y, $z); + static::setStatic($level, $x, $y, $z); LABEL_35: - //TODO - + if(static::canSpreadTo($level, $x, $y - 1, $z)){ + if($id == LAVA || $id == STILL_LAVA){ + $idBottom = $level->level->getBlockID($x, $y, $z); + if($idBottom == WATER || $idBottom == STILL_WATER){ + $level->fastSetBlockUpdate($x, $y - 1, $z, STONE, 0, true); + //fizz + } + }else{ + if($depth > 7){ + $meta = $depth; + }else{ + $meta = $depth + 8; + } + + $level->fastSetBlockUpdate($x, $y - 1, $z, $id, $meta, true); + } + }else if($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){ + $spread = static::getSpread($level, $x, $y, $z); + + if($depth > 7) $v18 = 1; + else{ + $v18 = $depth + $spreadAdder; + if($v18 > 7) return; + } + if($spread[0]) static::trySpreadTo($level, $x - 1, $y, $z, $v18); + if($spread[1]) static::trySpreadTo($level, $x + 1, $y, $z, $v18); + + if($spread[2]) static::trySpreadTo($level, $x, $y, $z - 1, $v18); + if($spread[3]) static::trySpreadTo($level, $x, $y, $z + 1, $v18); + } } } \ No newline at end of file diff --git a/src/material/block/liquid/LiquidBlockStatic.php b/src/material/block/liquid/LiquidBlockStatic.php index 9e68a28b..d5d315b7 100644 --- a/src/material/block/liquid/LiquidBlockStatic.php +++ b/src/material/block/liquid/LiquidBlockStatic.php @@ -10,16 +10,18 @@ class LiquidBlockStatic extends LiquidBlock{ public static function setDynamic(Level $level, $x, $y, $z){ //TODO set dynamic [$id, $meta] = $level->level->getBlock($x, $y, $z); - $dynamicID =$id - 1; //very unsafe + $dynamicID = $id - 1; //very unsafe $level->fastSetBlockUpdate($x, $y, $z, $dynamicID, $meta); $delay = static::getTickDelay(); - ServerAPI::request()->api->block->blockUpdateAroundXYZ($x, $y, $z, BLOCK_UPDATE_SCHEDULED, $delay); + ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, $delay); + } public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $oldID = $level->level->getBlockID($x, $y, $z); static::updateLiquid($level, $x, $y, $z); $newID = $level->level->getBlockID($x, $y, $z); + ConsoleAPI::debug($oldID.":".$newID); if($oldID == $newID){ static::setDynamic($level, $x, $y, $z); } diff --git a/src/material/block/liquid/StillLavaBlock.php b/src/material/block/liquid/StillLavaBlock.php index a0388e82..252d2ae2 100644 --- a/src/material/block/liquid/StillLavaBlock.php +++ b/src/material/block/liquid/StillLavaBlock.php @@ -1,4 +1,5 @@ level->getBlockID($x - 1, $y, $z); + ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x + 1, $y, $z); + ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y - 1, $z); + ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y + 1, $z); + ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y, $z - 1); + ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y, $z + 1); + ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID); } From 3d6c4feb0f463447e1183148a9d1f8b0abd635f0 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 23 May 2024 06:38:20 +0300 Subject: [PATCH 06/10] some tweaks --- src/material/Block.php | 2 +- src/material/block/LiquidBlock.php | 9 ++-- src/material/block/liquid/LavaBlock.php | 1 + .../block/liquid/LiquidBlockDynamic.php | 51 +++++++++---------- src/material/block/liquid/WaterBlock.php | 3 ++ src/pmf/PMFLevel.php | 9 +--- src/world/Level.php | 6 --- 7 files changed, 37 insertions(+), 44 deletions(-) diff --git a/src/material/Block.php b/src/material/Block.php index 650a47a8..8b49559c 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -219,7 +219,7 @@ abstract class Block extends Position{ return MovingObjectPosition::fromBlock($x, $y, $z, $v14, $v13->add($x, $y, $z)); } - + public static function onPlace(Level $level, $x, $y, $z){} 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){} diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index aaa89868..88f7c078 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -16,14 +16,17 @@ class LiquidBlock extends TransparentBlock{ $this->hardness = 500; } public static $blockID = 0; - public static function getDepth(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); if($id == static::$blockID) return $meta; - return -1; - + return -1; } + + public static function onPlace(Level $level, $x, $y, $z){ + static::updateLiquid($level, $x, $y, $z); + } + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ static::updateLiquid($level, $x, $y, $z); } diff --git a/src/material/block/liquid/LavaBlock.php b/src/material/block/liquid/LavaBlock.php index ba02516b..21249474 100644 --- a/src/material/block/liquid/LavaBlock.php +++ b/src/material/block/liquid/LavaBlock.php @@ -2,6 +2,7 @@ require_once("LiquidBlockDynamic.php"); //TODO class loader? class LavaBlock extends LiquidBlockDynamic implements LightingBlock{ + public static $blockID = LAVA; public function __construct($meta = 0){ parent::__construct(LAVA, $meta, "Lava"); $this->hardness = 500; diff --git a/src/material/block/liquid/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php index e1b617d1..df4ae3b0 100644 --- a/src/material/block/liquid/LiquidBlockDynamic.php +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -10,24 +10,18 @@ class LiquidBlockDynamic extends LiquidBlock{ public static $spread = [0, 0, 0, 0]; public static function getHighest(Level $level, $x, $y, $z, $highest){ - $depth = self::getDepth($level, $x, $y, $z); + $depth = static::getDepth($level, $x, $y, $z); + if($depth < 0) return $highest; + if($depth == 0) ++static::$f_d8; + if($depth >= 8) $depth = 0; - if($depth >= 0){ - if($depth > 7) $depth = 0; - }else{ - ++self::$f_d8; - } - - if($highest < 0) return $depth; - else if($highest >= $depth) return $depth; - - return $highest; + return $highest >= 0 && $depth >= $highest ? $highest : $depth; } public static function setStatic(Level $level, $x, $y, $z){ $meta = $level->level->getBlockDamage($x, $y, $z); - $level->fastSetBlockUpdate($x, $y, $z, self::$blockID + 1, $meta); + $level->fastSetBlockUpdate($x, $y, $z, static::$blockID + 1, $meta); } public static function isWaterBlocking(Level $level, $x, $y, $z){ @@ -53,7 +47,6 @@ class LiquidBlockDynamic extends LiquidBlock{ } public static function getSpread(Level $level, $x, $y, $z){ - //TODO get rid of gotos for($i = 0; $i < 4; ++$i){ static::$spread[$i] = 1000; $xs = $x; @@ -78,11 +71,7 @@ class LiquidBlockDynamic extends LiquidBlock{ if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue; [$id, $meta] = $level->level->getBlock($xs, $ys, $zs); - if( - (((static::$blockID == WATER || static::$blockID == STILL_WATER) && ($id == WATER || $id == STILL_WATER)) || - ((static::$blockID == LAVA || static::$blockID == STILL_LAVA) && ($id == LAVA || $id == STILL_LAVA))) && - $meta == 0 - ){ + if(((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && $meta == 0){ continue; } @@ -147,18 +136,24 @@ class LiquidBlockDynamic extends LiquidBlock{ $id = $level->level->getBlockID($x, $y, $z); if($id > 0){ - if(($id == LAVA || $id == STILL_LAVA) && (self::$id == LAVA || self::$id == STILL_LAVA)); //fizz + if(($id == LAVA || $id == STILL_LAVA) && (static::$blockID == LAVA || static::$blockID == STILL_LAVA)); //fizz else{ //TODO spawnResources } } - $level->fastSetBlockUpdate($x, $y, $z, self::$blockID, $meta, true); + $level->fastSetBlockUpdate($x, $y, $z, static::$blockID, $meta, true); } } + public static function onPlace(Level $level, $x, $y, $z){ + static::updateLiquid($level, $x, $y, $z); + $id = $level->level->getBlockID($x, $y, $z); + if($id == static::$blockID) ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, static::getTickDelay()); + } + public static function onUpdate(Level $level, $x, $y, $z, $type){ - static::$blockID = $id = $level->level->getBlockID($x, $y, $z); + $id = $level->level->getBlockID($x, $y, $z); $depth = static::getDepth($level, $x, $y, $z); if($id == LAVA || $id == STILL_LAVA){ $spreadAdder = 2; //XXX nether has 1 @@ -169,7 +164,7 @@ class LiquidBlockDynamic extends LiquidBlock{ $tickDelay = static::getTickDelay(); if($depth > 0){ - self::$f_d8 = 0; + static::$f_d8 = 0; $highest = static::getHighest($level, $x - 1, $y, $z, -100); $highest = static::getHighest($level, $x + 1, $y, $z, $highest); @@ -187,15 +182,16 @@ class LiquidBlockDynamic extends LiquidBlock{ else $v16 = $dpth + 8; } - if(static::$f_d8 && (static::$blockID == WATER || static::$blockID == STILL_WATER)){ + if(static::$f_d8 && (static::$blockID == WATER)){ //XXX Level::isSolidBlockingTile - [$id, $meta] = $level->level->getBlock($x, $y, $z); - if(StaticBlock::getIsFlowable($id) || ($id == WATER || $id == STILL_WATER) && $meta != 0){ - $v16 = 0; + $idb = $level->level->getBlockID($x, $y - 1, $z); + $metab = $level->level->getBlockDamage($x, $y, $z); + if(StaticBlock::getIsFlowable($idb) || (($idb == WATER || $idb == STILL_WATER) && $metab != 0)){ + //$v16 = 0; } } - if((static::$blockID == LAVA || static::$blockID == STILL_LAVA) && $depth <= 7){ + if(static::$blockID == LAVA && $depth <= 7){ if($v16 > 7) goto LABEL_32; //TODO remove gotos if($v16 > $depth){ @@ -209,6 +205,7 @@ class LiquidBlockDynamic extends LiquidBlock{ goto LABEL_35; } LABEL_32: + ConsoleAPI::debug("v16 is $v16"); $level->fastSetBlockUpdateMeta($x, $y, $z, $v16, false); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($x, $y, $z, $level), $tickDelay); //TODO get rid of new Position $level->updateNeighborsAt($x, $y, $z, static::$blockID); diff --git a/src/material/block/liquid/WaterBlock.php b/src/material/block/liquid/WaterBlock.php index 28ebc131..f0506a23 100644 --- a/src/material/block/liquid/WaterBlock.php +++ b/src/material/block/liquid/WaterBlock.php @@ -2,6 +2,9 @@ require_once("LiquidBlockDynamic.php"); //TODO class loader? class WaterBlock extends LiquidBlockDynamic{ + + public static $blockID = WATER; + public function __construct($meta = 0){ parent::__construct(WATER, $meta, "Water"); $this->hardness = 500; diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 0eb99304..5856dea0 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -500,13 +500,8 @@ class PMFLevel extends PMF{ ++$this->chunkChange[$index][$Y]; } $this->chunkChange[$index][-1] = true; - if($old_b instanceof LiquidBlock){ - $pos = new Position($x, $y, $z, $this->level); - for($side = 0; $side <= 5; ++$side){ - $b = $pos->getSide($side); - ServerAPI::request()->api->block->scheduleBlockUpdate($b, ($b instanceof LavaBlock ? 40: 10), BLOCK_UPDATE_NORMAL); - } - } + + if($block > 0) StaticBlock::getBlock($block)::onPlace($this->level, $x, $y, $z); return true; } return false; diff --git a/src/world/Level.php b/src/world/Level.php index 3e2a461e..8b02b4d4 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -468,24 +468,18 @@ class Level{ public function updateNeighborsAt($x, $y, $z, $oldID){ $block = $this->level->getBlockID($x - 1, $y, $z); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x + 1, $y, $z); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y - 1, $z); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y + 1, $z); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y, $z - 1); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID); $block = $this->level->getBlockID($x, $y, $z + 1); - ConsoleAPI::debug(StaticBlock::getBlock($block)); if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID); } From 589bc9f1c0685acaa966ff0a49e53920ffd58651 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 23 May 2024 07:24:44 +0300 Subject: [PATCH 07/10] works better --- src/material/block/LiquidBlock.php | 8 +- .../block/liquid/LiquidBlockDynamic.php | 129 ++++++------------ src/material/block/liquid/StillLavaBlock.php | 1 + src/material/block/liquid/StillWaterBlock.php | 1 + 4 files changed, 52 insertions(+), 87 deletions(-) diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index 88f7c078..001a23ed 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -18,9 +18,11 @@ class LiquidBlock extends TransparentBlock{ public static $blockID = 0; public static function getDepth(Level $level, $x, $y, $z){ [$id, $meta] = $level->level->getBlock($x, $y, $z); - - if($id == static::$blockID) return $meta; - return -1; + return match(static::$blockID){ + WATER, STILL_WATER => $id == WATER || $id == STILL_WATER ? $meta : -1, + LAVA, STILL_LAVA => $id == LAVA || $id == STILL_LAVA ? $meta : -1, + default=> -1 + }; } public static function onPlace(Level $level, $x, $y, $z){ diff --git a/src/material/block/liquid/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php index df4ae3b0..f6e71664 100644 --- a/src/material/block/liquid/LiquidBlockDynamic.php +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -6,13 +6,13 @@ class LiquidBlockDynamic extends LiquidBlock{ } public static $blockID = 0; - public static $f_d8 = 0; //TODO rename + public static $sourcesAround = 0; //TODO rename public static $spread = [0, 0, 0, 0]; public static function getHighest(Level $level, $x, $y, $z, $highest){ $depth = static::getDepth($level, $x, $y, $z); if($depth < 0) return $highest; - if($depth == 0) ++static::$f_d8; + if($depth == 0) ++static::$sourcesAround; if($depth >= 8) $depth = 0; return $highest >= 0 && $depth >= $highest ? $highest : $depth; @@ -34,14 +34,14 @@ class LiquidBlockDynamic extends LiquidBlock{ if($id == CARPET || $id == SNOW_LAYER || $id == RAIL || $id == POWERED_RAIL) return false; //TODO Tile::getThickness() > 0 //TODO materials - if(!StaticBlock::getIsFlowable($id)) return 1; - else return StaticBlock::getIsSolid($id); + //if(!StaticBlock::getIsFlowable($id)) return 1; + return StaticBlock::getIsSolid($id); } public static function canSpreadTo(Level $level, $x, $y, $z){ $id = $level->level->getBlockID($x, $y, $z); if($id == LAVA || $id == STILL_LAVA) return false; - if((static::$blockID == WATER || static::$blockID == STILL_WATER) && ($id == WATER || $id == STILL_WATER)) return false; + if((static::$blockID == WATER) && ($id == WATER || $id == STILL_WATER)) return false; return static::isWaterBlocking($level, $x, $y, $z) ^ 1; } @@ -115,8 +115,8 @@ class LiquidBlockDynamic extends LiquidBlock{ [$id, $meta] = $level->level->getBlock($xs, $ys, $zs); if( - (((static::$blockID == WATER || static::$blockID == STILL_WATER) && ($id == WATER || $id == STILL_WATER)) || - ((static::$blockID == LAVA || static::$blockID == STILL_LAVA) && ($id == LAVA || $id == STILL_LAVA))) && + ((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || + (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && $meta == 0 ){ continue; @@ -155,98 +155,59 @@ class LiquidBlockDynamic extends LiquidBlock{ public static function onUpdate(Level $level, $x, $y, $z, $type){ $id = $level->level->getBlockID($x, $y, $z); $depth = static::getDepth($level, $x, $y, $z); - if($id == LAVA || $id == STILL_LAVA){ - $spreadAdder = 2; //XXX nether has 1 - //TODO also call trySpreadFire - }else{ - $spreadAdder = 1; - } + $flowAdd = (static::$blockID == LAVA) ? 2 : 1; + $flag = true; - $tickDelay = static::getTickDelay(); if($depth > 0){ - static::$f_d8 = 0; + static::$sourcesAround = 0; $highest = static::getHighest($level, $x - 1, $y, $z, -100); $highest = static::getHighest($level, $x + 1, $y, $z, $highest); - $highest = static::getHighest($level, $x, $y, $z - 1, $highest); $highest = static::getHighest($level, $x, $y, $z + 1, $highest); + ConsoleAPI::debug("h".$highest); + $j1 = $highest + $flowAdd; + if($j1 >= 8 || $highest < 0) $j1 = -1; + $l1 = static::getDepth($level, $x, $y + 1, $z); + if($l1 >= 0) $j1 = ($l1 >= 8 ? $l1 : $l1 + 8); - if($highest + $spreadAdder > 7) $v16 = -1; - else{ - $v16 = ($highest + $spreadAdder) & ~($highest >> 31); //XXX xor? - if($highest < 0) $v16 = -1; - } - $dpth = static::getDepth($level, $x, $y + 1, $z); - if($dpth >= 0){ - if($dpth > 7) $v16 = $dpth; - else $v16 = $dpth + 8; - } - - if(static::$f_d8 && (static::$blockID == WATER)){ - //XXX Level::isSolidBlockingTile - $idb = $level->level->getBlockID($x, $y - 1, $z); - $metab = $level->level->getBlockDamage($x, $y, $z); - if(StaticBlock::getIsFlowable($idb) || (($idb == WATER || $idb == STILL_WATER) && $metab != 0)){ - //$v16 = 0; + if(static::$sourcesAround >= 2 && static::$blockID == WATER){ + $idBot = $level->level->getBlockID($x, $y - 1, $z); + if($idBot > 0){ + if(StaticBlock::getIsSolid($idBot) || (($idBot == WATER || $idBot == STILL_WATER) && $level->level->getBlockDamage($x, $y, $z) == 0)) $j1 = 0; } } - if(static::$blockID == LAVA && $depth <= 7){ - if($v16 > 7) goto LABEL_32; //TODO remove gotos - - if($v16 > $depth){ - //if(mt_rand(0, 3)) $tickDelay *= 4; - - LABEL_30: - if($v16 < 0){ - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - LABEL_33: - $depth = $v16; - goto LABEL_35; - } - LABEL_32: - ConsoleAPI::debug("v16 is $v16"); - $level->fastSetBlockUpdateMeta($x, $y, $z, $v16, false); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($x, $y, $z, $level), $tickDelay); //TODO get rid of new Position - $level->updateNeighborsAt($x, $y, $z, static::$blockID); - goto LABEL_33; - } + if(static::$blockID == LAVA && $depth < 8 && $j1 < 8 && $j1 > $depth && mt_rand(0, 4) != 0){ + $j1 = $depth; + $flag = false; } - if($v16 != $depth) goto LABEL_30; - } - static::setStatic($level, $x, $y, $z); - LABEL_35: - if(static::canSpreadTo($level, $x, $y - 1, $z)){ - if($id == LAVA || $id == STILL_LAVA){ - $idBottom = $level->level->getBlockID($x, $y, $z); - if($idBottom == WATER || $idBottom == STILL_WATER){ - $level->fastSetBlockUpdate($x, $y - 1, $z, STONE, 0, true); - //fizz + if($j1 != $depth){ + $depth = $j1; + if($depth < 0) $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + else{ + $level->fastSetBlockUpdateMeta($x, $y, $z, $depth, true); + ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, static::getTickDelay()); + $level->updateNeighborsAt($x, $y, $z, static::$blockID); //TODO check is needed } - }else{ - if($depth > 7){ - $meta = $depth; - }else{ - $meta = $depth + 8; - } - - $level->fastSetBlockUpdate($x, $y - 1, $z, $id, $meta, true); + }else if($flag){ + static::setStatic($level, $x, $y, $z); } - }else if($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){ - $spread = static::getSpread($level, $x, $y, $z); - - if($depth > 7) $v18 = 1; - else{ - $v18 = $depth + $spreadAdder; - if($v18 > 7) return; - } - if($spread[0]) static::trySpreadTo($level, $x - 1, $y, $z, $v18); - if($spread[1]) static::trySpreadTo($level, $x + 1, $y, $z, $v18); - - if($spread[2]) static::trySpreadTo($level, $x, $y, $z - 1, $v18); - if($spread[3]) static::trySpreadTo($level, $x, $y, $z + 1, $v18); + }else{ + static::setStatic($level, $x, $y, $z); } + if(static::canSpreadTo($level, $x, $y - 1, $z)){ + $level->fastSetBlockUpdate($x, $y - 1, $z, static::$blockID, ($depth >= 8 ? $depth : $depth + 8) & 0xf, true); + }else if($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){ + $flags = static::getSpread($level, $x, $y, $z); + $k1 = $depth >= 8 ? 1 : ($depth + $flowAdd); + if($k1 >= 8) return; + //TODO flags are broken, no flags makes too much of the liquid + /*if($flags[0])*/ static::trySpreadTo($level, $x - 1, $y, $z, $k1); + /*if($flags[1])*/ static::trySpreadTo($level, $x + 1, $y, $z, $k1); + /*if($flags[2])*/ static::trySpreadTo($level, $x, $y, $z - 1, $k1); + /*if($flags[3])*/ static::trySpreadTo($level, $x, $y, $z + 1, $k1); + } } } \ No newline at end of file diff --git a/src/material/block/liquid/StillLavaBlock.php b/src/material/block/liquid/StillLavaBlock.php index 252d2ae2..2a8e89cf 100644 --- a/src/material/block/liquid/StillLavaBlock.php +++ b/src/material/block/liquid/StillLavaBlock.php @@ -2,6 +2,7 @@ require_once("LiquidBlockStatic.php"); //TODO class loader? class StillLavaBlock extends LiquidBlockStatic{ + public static $blockID = STILL_LAVA; public function __construct($meta = 0){ parent::__construct(STILL_LAVA, $meta, "Still Lava"); $this->hardness = 500; diff --git a/src/material/block/liquid/StillWaterBlock.php b/src/material/block/liquid/StillWaterBlock.php index b556e762..632177a3 100644 --- a/src/material/block/liquid/StillWaterBlock.php +++ b/src/material/block/liquid/StillWaterBlock.php @@ -8,6 +8,7 @@ require_once("LiquidBlockStatic.php"); //TODO class loader? /***REM_END***/ class StillWaterBlock extends LiquidBlockStatic{ + public static $blockID = STILL_WATER; public function __construct($meta = 0){ LiquidBlock::__construct(STILL_WATER, $meta, "Still Water"); $this->hardness = 500; From 9c21a984cd0498c8e9bf2cd888c20928384adbc6 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 24 May 2024 06:45:34 +0300 Subject: [PATCH 08/10] vanilla(or close to vanila) liquid physics --- src/API/BlockAPI.php | 3 --- src/material/block/liquid/LiquidBlockDynamic.php | 16 ++++++++-------- src/material/block/liquid/LiquidBlockStatic.php | 1 - src/material/item/generic/BucketItem.php | 15 +++------------ src/world/Explosion.php | 3 +-- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 92bc0034..d8fb334c 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -569,18 +569,15 @@ class BlockAPI{ } public function scheduleBlockUpdateXYZ(Level $level, $x, $y, $z, $type = BLOCK_UPDATE_SCHEDULED, $delay = false){ $type = (int) $type; - ConsoleAPI::debug($delay); if($delay < 0){ return false; } $index = $x . "." . $y . "." . $z . "." . $level->getName() . "." . $type; $delay = microtime(true) + $delay * 0.05; - ConsoleAPI::debug($index); if(!isset($this->scheduledUpdates[$index])){ $this->scheduledUpdates[$index] = new Position($x, $y, $z, $level); //TODO dont create a position $this->server->query("INSERT INTO blockUpdates (x, y, z, level, type, delay) VALUES ($x, $y, $z, '{$level->getName()}', $type, $delay);"); - ConsoleAPI::debug("added block update $x $y $z $type"); return true; } return false; diff --git a/src/material/block/liquid/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php index f6e71664..7736582f 100644 --- a/src/material/block/liquid/LiquidBlockDynamic.php +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -70,7 +70,6 @@ class LiquidBlockDynamic extends LiquidBlock{ if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue; [$id, $meta] = $level->level->getBlock($xs, $ys, $zs); - if(((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && $meta == 0){ continue; } @@ -78,8 +77,10 @@ class LiquidBlockDynamic extends LiquidBlock{ if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) static::$spread[$i] = 0; else static::$spread[$i] = static::getSlopeDistance($level, $xs, $ys, $zs, 1, $i); } - - $i1 = max(static::$spread); + $i1 = static::$spread[0]; + for($k1 = 1; $k1 < 4; ++$k1){ + if(static::$spread[$k1] < $i1) $i1 = static::$spread[$k1]; + } $ba = []; for($i = 0; $i < 4; ++$i) $ba[$i] = ($i1 == static::$spread[$i]); return $ba; @@ -164,7 +165,6 @@ class LiquidBlockDynamic extends LiquidBlock{ $highest = static::getHighest($level, $x + 1, $y, $z, $highest); $highest = static::getHighest($level, $x, $y, $z - 1, $highest); $highest = static::getHighest($level, $x, $y, $z + 1, $highest); - ConsoleAPI::debug("h".$highest); $j1 = $highest + $flowAdd; if($j1 >= 8 || $highest < 0) $j1 = -1; $l1 = static::getDepth($level, $x, $y + 1, $z); @@ -204,10 +204,10 @@ class LiquidBlockDynamic extends LiquidBlock{ $k1 = $depth >= 8 ? 1 : ($depth + $flowAdd); if($k1 >= 8) return; //TODO flags are broken, no flags makes too much of the liquid - /*if($flags[0])*/ static::trySpreadTo($level, $x - 1, $y, $z, $k1); - /*if($flags[1])*/ static::trySpreadTo($level, $x + 1, $y, $z, $k1); - /*if($flags[2])*/ static::trySpreadTo($level, $x, $y, $z - 1, $k1); - /*if($flags[3])*/ static::trySpreadTo($level, $x, $y, $z + 1, $k1); + if($flags[0]) static::trySpreadTo($level, $x - 1, $y, $z, $k1); + if($flags[1]) static::trySpreadTo($level, $x + 1, $y, $z, $k1); + if($flags[2]) static::trySpreadTo($level, $x, $y, $z - 1, $k1); + if($flags[3]) static::trySpreadTo($level, $x, $y, $z + 1, $k1); } } } \ No newline at end of file diff --git a/src/material/block/liquid/LiquidBlockStatic.php b/src/material/block/liquid/LiquidBlockStatic.php index d5d315b7..c37a461e 100644 --- a/src/material/block/liquid/LiquidBlockStatic.php +++ b/src/material/block/liquid/LiquidBlockStatic.php @@ -21,7 +21,6 @@ class LiquidBlockStatic extends LiquidBlock{ $oldID = $level->level->getBlockID($x, $y, $z); static::updateLiquid($level, $x, $y, $z); $newID = $level->level->getBlockID($x, $y, $z); - ConsoleAPI::debug($oldID.":".$newID); if($oldID == $newID){ static::setDynamic($level, $x, $y, $z); } diff --git a/src/material/item/generic/BucketItem.php b/src/material/item/generic/BucketItem.php index 4a71ecbf..e887585f 100644 --- a/src/material/item/generic/BucketItem.php +++ b/src/material/item/generic/BucketItem.php @@ -16,7 +16,7 @@ class BucketItem extends Item{ public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($this->meta === AIR){ - if($target instanceof LiquidBlock){ + if($block instanceof LiquidBlock){ $level->setBlock($target, new AirBlock(), true, false, true); if(($player->gamemode & 0x01) === 0){ $this->meta = ($target instanceof WaterBlock) ? WATER : LAVA; @@ -24,11 +24,9 @@ class BucketItem extends Item{ return true; } }elseif($this->meta === WATER){ - //Support Make Non-Support Water to Support Water - if($block->getID() === AIR || ( $block instanceof WaterBlock && ($block->getMetadata() & 0x07) != 0x00 ) || ($block instanceof LavaBlock)){ + if($block->getID() === AIR || $block instanceof LiquidBlock){ $water = new WaterBlock(); $level->setBlock($block, $water, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate($block, 5, BLOCK_UPDATE_NORMAL); //$water->place($this, $player, $block, $target, $face, $fx, $fy, $fz); if(($player->gamemode & 0x01) === 0){ $this->meta = 0; @@ -36,21 +34,14 @@ class BucketItem extends Item{ return true; } }elseif($this->meta === LAVA){ - if($block->getID() === AIR || ($block instanceof LavaBlock && ($block->getMetadata() & 0x6) != 0)){ + if($block->getID() === AIR || $block instanceof LiquidBlock){ $lava = new LavaBlock(); $level->setBlock($block, $lava, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate($block, 40, BLOCK_UPDATE_NORMAL); //$lava->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz); if(($player->gamemode & 0x01) === 0){ $this->meta = 0; } return true; - }elseif($block instanceof WaterBlock){ - $level->setBlock($block, new ObsidianBlock(), true, false, true); - if(($player->gamemode & 0x01) === 0){ - $this->meta = 0; - } - return true; } } return false; diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 96514a0e..a49d6277 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -41,7 +41,6 @@ class Explosion{ $index = ($vBlock->x << 16) + ($vBlock->z << 8) + $vBlock->y; if(StaticBlock::getIsLiquid($blockID) && !isset($visited[$index])){ - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($vBlock->x, $vBlock->y, $vBlock->z, $this->level), 5, BLOCK_UPDATE_NORMAL); $visited[$index] = true; } @@ -202,7 +201,7 @@ class Explosion{ } } } - $this->level->fastSetBlockUpdate($x, $y, $z, 0, 0); + $this->level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); $send[] = $xyz; } $pk = new ExplodePacket; From 5d5099c06f39fbdb9ed043988a098b0f456e5b08 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 24 May 2024 06:57:52 +0300 Subject: [PATCH 09/10] removed some useless stuff from explosion, onPlace should be called every ti --- .../block/liquid/LiquidBlockDynamic.php | 2 +- src/pmf/PMFLevel.php | 9 +++++++- src/world/Explosion.php | 21 +++++++------------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/material/block/liquid/LiquidBlockDynamic.php b/src/material/block/liquid/LiquidBlockDynamic.php index 7736582f..1dfcff3c 100644 --- a/src/material/block/liquid/LiquidBlockDynamic.php +++ b/src/material/block/liquid/LiquidBlockDynamic.php @@ -203,7 +203,7 @@ class LiquidBlockDynamic extends LiquidBlock{ $flags = static::getSpread($level, $x, $y, $z); $k1 = $depth >= 8 ? 1 : ($depth + $flowAdd); if($k1 >= 8) return; - //TODO flags are broken, no flags makes too much of the liquid + if($flags[0]) static::trySpreadTo($level, $x - 1, $y, $z, $k1); if($flags[1]) static::trySpreadTo($level, $x + 1, $y, $z, $k1); if($flags[2]) static::trySpreadTo($level, $x, $y, $z - 1, $k1); diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 5856dea0..3dfb7cfa 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -369,7 +369,14 @@ class PMFLevel extends PMF{ $aX = $x & 0xf; $aZ = $z & 0xf; $aY = $y & 0xf; - $this->chunks[$index][$Y][(int) ($aY + ($aX << 5) + ($aZ << 9))] = chr($block); + $bind = (int) ($aY + ($aX << 5) + ($aZ << 9)); + if($this->chunks[$index][$Y][$bind] == chr($block)){ + return false; //no changes done + }else{ + $this->chunks[$index][$Y][$bind] = chr($block); + if($block > 0) StaticBlock::getBlock($block)::onPlace($this->level, $x, $y, $z); + } + if(!isset($this->chunkChange[$index][$Y])){ $this->chunkChange[$index][$Y] = 1; }else{ diff --git a/src/world/Explosion.php b/src/world/Explosion.php index a49d6277..71e75c8e 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -27,7 +27,7 @@ class Explosion{ $this->nullPlayer = new PlayerNull(); } - public function sub_expl(&$visited, $i, $mRays, $j, $k){ + public function sub_expl($i, $mRays, $j, $k){ $vector = new Vector3($i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1); //($i / $mRays) * 2 - 1 $vector = $vector->normalize()->multiply($this->stepLen); $pointer = clone $this->source; @@ -39,11 +39,6 @@ class Explosion{ $blockMeta = $BIDM[1]; if($blockID > 0){ $index = ($vBlock->x << 16) + ($vBlock->z << 8) + $vBlock->y; - - if(StaticBlock::getIsLiquid($blockID) && !isset($visited[$index])){ - $visited[$index] = true; - } - $blastForce -= (StaticBlock::getHardness($blockID) / 5 + 0.3) * $this->stepLen; if($blastForce > 0){ if(!isset($this->affectedBlocks[$index])){ @@ -102,45 +97,45 @@ class Explosion{ ]) === false){ return false; } - $visited = []; + $mRays = $this->rays - 1; $i = 0; for($j = 0; $j <= $mRays; ++$j){ for($k = 0; $k <= $mRays; ++$k){ - $this->sub_expl($visited, $i, $mRays, $j, $k); //i wish there was #define or inline + $this->sub_expl($i, $mRays, $j, $k); //i wish there was #define or inline } } $i = $mRays; for($j = 0; $j <= $mRays; ++$j){ for($k = 0; $k <= $mRays; ++$k){ - $this->sub_expl($visited, $i, $mRays, $j, $k); + $this->sub_expl($i, $mRays, $j, $k); } } $j = 0; for($i = 1; $i < $mRays; ++$i){ for($k = 0; $k <= $mRays; ++$k){ - $this->sub_expl($visited, $i, $mRays, $j, $k); + $this->sub_expl($i, $mRays, $j, $k); } } $j = $mRays; for($i = 1; $i < $mRays; ++$i){ for($k = 0; $k <= $mRays; ++$k){ - $this->sub_expl($visited, $i, $mRays, $j, $k); + $this->sub_expl($i, $mRays, $j, $k); } } $k = 0; for($i = 1; $i < $mRays; ++$i){ for($j = 1; $j < $mRays; ++$j){ - $this->sub_expl($visited, $i, $mRays, $j, $k); + $this->sub_expl($i, $mRays, $j, $k); } } $k = $mRays; for($i = 1; $i < $mRays; ++$i){ for($j = 1; $j < $mRays; ++$j){ - $this->sub_expl($visited, $i, $mRays, $j, $k); + $this->sub_expl($i, $mRays, $j, $k); } } //if($i == 0 or $i == $mRays or $j == 0 or $j == $mRays or $k == 0 or $k == $mRays){ From f227daa1e0c797733a3669799ff775d0ea851323 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 24 May 2024 12:27:38 +0300 Subject: [PATCH 10/10] fire block tweaks --- src/material/block/misc/FireBlock.php | 22 ++++++---------------- src/material/item/tool/FlintSteelItem.php | 6 +++--- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/material/block/misc/FireBlock.php b/src/material/block/misc/FireBlock.php index 6a62ac50..8d906438 100644 --- a/src/material/block/misc/FireBlock.php +++ b/src/material/block/misc/FireBlock.php @@ -30,6 +30,10 @@ class FireBlock extends FlowableBlock implements LightingBlock{ } } + public static function onPlace(Level $level, $x, $y, $z){ + ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, 30); + } + public function getDrops(Item $item, Player $player){ return array(); } @@ -39,21 +43,7 @@ class FireBlock extends FlowableBlock implements LightingBlock{ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $b = $level->level->getBlockID($x, $y - 1, $z); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - $b = $level->level->getBlockID($x, $y - 1, $z); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - - $b = $level->level->getBlockID($x - 1, $y, $z); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - $b = $level->level->getBlockID($x + 1, $y, $z); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - - $b = $level->level->getBlockID($x, $y, $z - 1); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - $b = $level->level->getBlockID($x, $y, $z + 1); - if($b != AIR && StaticBlock::getIsLiquid($b)) return false; - - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + if(!StaticBlock::getIsSolid($b)) $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); //TODO more vanilla later? } public static function onUpdate(Level $level, $x, $y, $z, $type){ @@ -82,7 +72,7 @@ class FireBlock extends FlowableBlock implements LightingBlock{ goto REMOVE_FIRE; } - $level->scheduleBlockUpdate(new Position($x, $y, $z, $level), 30, BLOCK_UPDATE_SCHEDULED); //TODO looks like it also adds mt_rand(0, 9) to it + ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, 30); //TODO looks like it also adds mt_rand(0, 9) to it } } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/material/item/tool/FlintSteelItem.php b/src/material/item/tool/FlintSteelItem.php index 357ccac7..134b160a 100644 --- a/src/material/item/tool/FlintSteelItem.php +++ b/src/material/item/tool/FlintSteelItem.php @@ -11,9 +11,9 @@ class FlintSteelItem extends ItemTool{ if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){ $player->setSlot($player->slot, new Item(AIR, 0, 0), false); } - if($block->getID() === AIR and ($target instanceof SolidBlock)){ - $level->setBlock($block, new FireBlock(), true, false, true); - $level->scheduleBlockUpdate($block, 30, BLOCK_UPDATE_SCHEDULED); + + if($block->getID() === AIR && $target->isSolid){ + $level->fastSetBlockUpdate($block->x, $block->y, $block->z, FIRE, 0, true); return true; } return false;