Skip to content
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

Open
wants to merge 22 commits into
base: minor-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aec64e3
StructureBlock: register block
Bqleine Sep 8, 2023
f7452e4
StructureVoid: register block
Bqleine Sep 8, 2023
0084569
StructureVoid: add serialization and block state
Bqleine Sep 9, 2023
bbe05d1
StructureVoid: use BlockStateStringValues instead of integers
Bqleine Sep 9, 2023
eb2add8
StructureBlock: add serialization and block state
Bqleine Sep 9, 2023
bb8c48b
StructureBlock: create tile to store editor settings
Bqleine Sep 11, 2023
cef12c2
StructureBlock: only open if the player is in creative mode
Bqleine Sep 12, 2023
93a0f91
StructureBlock: use backed enum for StructureBlockType
Bqleine Sep 13, 2023
95d7218
StructureBlock: add types, getters and setters for editor settings
Bqleine Sep 13, 2023
963d14a
StructureBlock: stop using backed enumerations
Bqleine Sep 13, 2023
88e82c7
StructureBlock: make function non-nullable
Bqleine Sep 16, 2023
cd8eae4
StructureBlock: inline helper functions
Bqleine Sep 20, 2023
8daf0e7
Merge branch 'minor-next' into minor-next
Bqleine Sep 20, 2023
554baa3
Merge remote-tracking branch 'upstream/minor-next' into minor-next
Bqleine Oct 7, 2023
2b10c63
Remove merge accident
Bqleine Oct 7, 2023
7e27de1
StructureBlock: add tag type comments
Bqleine Oct 7, 2023
e963d19
StructureBlock: fix changed imports
Bqleine Oct 7, 2023
7c9dc8e
StructureBlock: last touches for pr
Bqleine Oct 13, 2023
d921664
Merge branch 'pmmp:minor-next' into minor-next
Bqleine Nov 10, 2023
a50a348
StructureBlock: cosmetic changes
Bqleine Nov 13, 2023
a6747c1
StructureBlock: fix unit tests
Bqleine Nov 13, 2023
c277393
Merge branch 'pmmp:minor-next' into minor-next
Bqleine Mar 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/block/BlockTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ private function __construct(){
public const STONE_SLAB = 10503;
public const STONE_STAIRS = 10504;
public const STONECUTTER = 10505;
public const STRUCTURE_BLOCK = 10506;
public const STRUCTURE_VOID = 10507;

public const SUGARCANE = 10518;
public const SUNFLOWER = 10519;
Expand Down
71 changes: 71 additions & 0 deletions src/block/StructureBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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\Player;

class StructureBlock extends Opaque{
private StructureBlockType $type;

public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){
$this->type = StructureBlockType::SAVE;
Bqleine marked this conversation as resolved.
Show resolved Hide resolved
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->isCreative(true)) return false;
Bqleine marked this conversation as resolved.
Show resolved Hide resolved
$pk = ContainerOpenPacket::blockInv(0, WindowTypes::STRUCTURE_EDITOR, BlockPosition::fromVector3($this->getPosition()));
Copy link
Member

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.

Copy link
Author

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

$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;
if ($this->position->isValid()){
$this->position->getWorld()->setBlock($this->position, $this);
}
return $this;
}

//TODO: The Structure Block has redstone effects, they are not implemented.
}
62 changes: 62 additions & 0 deletions src/block/StructureVoid.php
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;
}
}
6 changes: 6 additions & 0 deletions src/block/VanillaBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use pocketmine\block\tile\Note as TileNote;
use pocketmine\block\tile\ShulkerBox as TileShulkerBox;
use pocketmine\block\tile\Smoker as TileSmoker;
use pocketmine\block\tile\StructureBlock as TileStructureBlock;
use pocketmine\block\utils\LeavesType;
use pocketmine\block\utils\SaplingType;
use pocketmine\block\utils\WoodType;
Expand Down Expand Up @@ -717,6 +718,8 @@
* @method static StonePressurePlate STONE_PRESSURE_PLATE()
* @method static Slab STONE_SLAB()
* @method static Stair STONE_STAIRS()
* @method static StructureBlock STRUCTURE_BLOCK()
* @method static StructureVoid STRUCTURE_VOID()
* @method static Sugarcane SUGARCANE()
* @method static DoublePlant SUNFLOWER()
* @method static SweetBerryBush SWEET_BERRY_BUSH()
Expand Down Expand Up @@ -1093,6 +1096,9 @@ public function isAffectedBySilkTouch() : bool{
self::register("smooth_quartz_slab", new Slab(new BID(Ids::SMOOTH_QUARTZ_SLAB), "Smooth Quartz", $stoneSlabBreakInfo));
self::register("stone_slab", new Slab(new BID(Ids::STONE_SLAB), "Stone", $stoneSlabBreakInfo));

self::register("structure_block", new StructureBlock(new BID(Ids::STRUCTURE_BLOCK, TileStructureBlock::class), "Structure Block", new Info(BreakInfo::indestructible(3600000))));
self::register("structure_void", new StructureVoid(new BID(Ids::STRUCTURE_VOID), "Structure Void", new Info(BreakInfo::indestructible(3600000))));

self::register("legacy_stonecutter", new Opaque(new BID(Ids::LEGACY_STONECUTTER), "Legacy Stonecutter", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD))));
self::register("sugarcane", new Sugarcane(new BID(Ids::SUGARCANE), "Sugarcane", new Info(BreakInfo::instant())));
self::register("sweet_berry_bush", new SweetBerryBush(new BID(Ids::SWEET_BERRY_BUSH), "Sweet Berry Bush", new Info(BreakInfo::instant())));
Expand Down
Loading
Loading