From ba85d691499d30e546b6e22e8d906741d41db35c Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 10 Jul 2023 15:44:08 +0300 Subject: [PATCH] rail connection is enabled by default + some tweaks --- src/PocketMinecraftServer.php | 2 +- .../block/nonfull/PoweredRailBlock.php | 13 +------ src/material/block/nonfull/RailBaseBlock.php | 35 +++++++++++++++++++ src/material/block/nonfull/RailBlock.php | 14 +++----- src/utils/RailLogic.php | 8 +++++ 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index f3f71bd0..dc86061a 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -79,7 +79,7 @@ class PocketMinecraftServer{ "enable-mob-ai" => false, "enable-nether-reactor" => true, "enable-explosions" => true, - "enable-rail-connection" => false, + "enable-rail-connection" => true, "save-player-data" => true, "save-console-data" => true, "query-plugins" => false, diff --git a/src/material/block/nonfull/PoweredRailBlock.php b/src/material/block/nonfull/PoweredRailBlock.php index a807fa0c..c8362074 100644 --- a/src/material/block/nonfull/PoweredRailBlock.php +++ b/src/material/block/nonfull/PoweredRailBlock.php @@ -5,18 +5,7 @@ class PoweredRailBlock extends RailBaseBlock{ parent::__construct(POWERED_RAIL, 0, "PoweredRailBlock"); $this->hardness = 0.7; $this->isFullBlock = false; - $this->isSolid = true; - } - - public function onUpdate($type){ - if($type === BLOCK_UPDATE_NORMAL){ - if($this->getSide(0)->getID() === AIR){ //Replace with common break method TODO change meta on break - ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1)); - $this->level->setBlock($this, new AirBlock(), true, false, true); - return BLOCK_UPDATE_NORMAL; - } - } - return false; + $this->isSolid = false; } } \ No newline at end of file diff --git a/src/material/block/nonfull/RailBaseBlock.php b/src/material/block/nonfull/RailBaseBlock.php index d43eaa0c..fda95e51 100644 --- a/src/material/block/nonfull/RailBaseBlock.php +++ b/src/material/block/nonfull/RailBaseBlock.php @@ -20,5 +20,40 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here } return false; } + + public function updateState(){} + + public function onUpdate($type){ + if($type === BLOCK_UPDATE_NORMAL){ + + $meta = $this->getMetadata(); + if($this->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) + ){ + $this->level->setBlock($this, new AirBlock(), true, false, true); + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1)); + }else{ + $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); + //} + + } + + } } diff --git a/src/material/block/nonfull/RailBlock.php b/src/material/block/nonfull/RailBlock.php index ecb10bc5..330c21de 100644 --- a/src/material/block/nonfull/RailBlock.php +++ b/src/material/block/nonfull/RailBlock.php @@ -8,17 +8,13 @@ class RailBlock extends RailBaseBlock{ $this->isSolid = false; } - public static $shouldconnectrails = false; + public static $shouldconnectrails = true; - 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($this->id, $this->meta, 1)); - $this->level->setBlock($this, new AirBlock(), true, false, true); - return BLOCK_UPDATE_NORMAL; - } + public function updateState(){ + $logic = (new RailLogic($this)); + if($logic->countPotentialConnections() == 3){ + $logic->place(false, false); } - return false; } } \ No newline at end of file diff --git a/src/utils/RailLogic.php b/src/utils/RailLogic.php index 09caef61..63635ebd 100644 --- a/src/utils/RailLogic.php +++ b/src/utils/RailLogic.php @@ -33,6 +33,14 @@ class RailLogic return null; } + public function hasRail($x, $y, $z){ + return RailBaseBlock::isRailBlock($this->level, $x, $y, $z) || RailBaseBlock::isRailBlock($this->level, $x, $y + 1, $z) || RailBaseBlock::isRailBlock($this->level, $x, $y - 1, $z); + } + + public function countPotentialConnections(){ + return $this->hasRail($this->x, $this->y, $this->z - 1) + $this->hasRail($this->x, $this->y, $this->z + 1) + $this->hasRail($this->x - 1, $this->y, $this->z) + $this->hasRail($this->x + 1, $this->y, $this->z); + } + public function removeSoftConnections(){ for($ind = 0; $ind < count($this->railPositions); ++$ind){ $logic = $this->getRail($this->railPositions[$ind]);