-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Structure Block and Structure Void #6045
base: minor-next
Are you sure you want to change the base?
Changes from all commits
aec64e3
f7452e4
0084569
bbe05d1
eb2add8
bb8c48b
cef12c2
93a0f91
95d7218
963d14a
88e82c7
cd8eae4
8daf0e7
554baa3
2b10c63
7e27de1
e963d19
7c9dc8e
d921664
a50a348
a6747c1
c277393
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* | ||
* ____ _ _ __ __ _ __ __ ____ | ||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* @author PocketMine Team | ||
* @link http://www.pocketmine.net/ | ||
* | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace pocketmine\block; | ||
|
||
use pocketmine\block\utils\StructureBlockType; | ||
use pocketmine\data\runtime\RuntimeDataDescriber; | ||
use pocketmine\item\Item; | ||
use pocketmine\math\Vector3; | ||
use pocketmine\network\mcpe\protocol\ContainerOpenPacket; | ||
use pocketmine\network\mcpe\protocol\types\BlockPosition; | ||
use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes; | ||
use pocketmine\player\Gamemode; | ||
Check failure on line 33 in src/block/StructureBlock.php GitHub Actions / PHP 8.1 / PHPStan analysis
Check failure on line 33 in src/block/StructureBlock.php GitHub Actions / PHP 8.2 / PHPStan analysis
|
||
use pocketmine\player\Player; | ||
|
||
class StructureBlock extends Opaque{ | ||
private StructureBlockType $type = StructureBlockType::SAVE; | ||
|
||
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ | ||
parent::__construct($idInfo, $name, $typeInfo); | ||
} | ||
|
||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ | ||
if ($player instanceof Player) { | ||
if (!$player->getGamemode() === GameMode::CREATIVE) { | ||
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.1 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.1 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.1 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.1 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.2 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.2 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.2 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.2 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.3 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.3 / PHPStan analysis
Check failure on line 45 in src/block/StructureBlock.php GitHub Actions / PHP 8.3 / PHPStan analysis
|
||
return false; | ||
} | ||
// the 0 is dubious but any value works | ||
$pk = ContainerOpenPacket::blockInv(0, WindowTypes::STRUCTURE_EDITOR, BlockPosition::fromVector3($this->getPosition())); | ||
$player->getNetworkSession()->sendDataPacket($pk); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public function describeBlockItemState(RuntimeDataDescriber $w) : void{ | ||
$w->enum($this->type); | ||
} | ||
|
||
public function getType() : StructureBlockType{ | ||
return $this->type; | ||
} | ||
|
||
/** @return $this */ | ||
public function setType(StructureBlockType $type) : self{ | ||
$this->type = $type; | ||
return $this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* | ||
* ____ _ _ __ __ _ __ __ ____ | ||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* @author PocketMine Team | ||
* @link http://www.pocketmine.net/ | ||
* | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace pocketmine\block; | ||
|
||
use pocketmine\block\utils\StructureVoidType; | ||
use pocketmine\data\runtime\RuntimeDataDescriber; | ||
use pocketmine\math\AxisAlignedBB; | ||
|
||
class StructureVoid extends Transparent{ | ||
private StructureVoidType $type; | ||
|
||
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ | ||
$this->type = StructureVoidType::VOID; | ||
parent::__construct($idInfo, $name, $typeInfo); | ||
} | ||
|
||
/** | ||
* @return AxisAlignedBB[] | ||
*/ | ||
protected function recalculateCollisionBoxes() : array{ | ||
return []; | ||
} | ||
|
||
public function isSolid() : bool{ | ||
return false; | ||
} | ||
|
||
public function describeBlockItemState(RuntimeDataDescriber $w) : void{ | ||
$w->enum($this->type); | ||
} | ||
|
||
public function getType() : StructureVoidType{ | ||
return $this->type; | ||
} | ||
|
||
/** @return $this */ | ||
public function setType(StructureVoidType $type) : self{ | ||
$this->type = $type; | ||
return $this; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like this. Packets shouldn't be directly baked into the core code like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I create an Inventory extending BlockInventory and TemporaryInventory with no slots then ? Sounds odd