From 2ebc482e3de2348ce453f928e2091e6cc2bb03aa Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 22 May 2024 06:15:34 +0300 Subject: [PATCH] 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; }