Skip to content

Commit 3d9e4b1

Browse files
committed
Update to 1.17.x
1 parent c4ee655 commit 3d9e4b1

7 files changed

Lines changed: 51 additions & 49 deletions

File tree

src/xenialdan/libstructure/PacketListener.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
use pocketmine\block\BlockLegacyIds;
99
use pocketmine\block\tile\TileFactory;
1010
use pocketmine\event\Listener;
11-
use pocketmine\event\player\PlayerInteractEvent;
1211
use pocketmine\event\server\DataPacketReceiveEvent;
13-
use pocketmine\item\ItemIds;
1412
use pocketmine\network\mcpe\protocol\StructureBlockUpdatePacket;
1513
use pocketmine\network\mcpe\protocol\StructureTemplateDataRequestPacket;
1614
use pocketmine\network\mcpe\protocol\StructureTemplateDataResponsePacket;
@@ -21,15 +19,11 @@
2119
use xenialdan\libstructure\tile\StructureBlockTags;
2220
use xenialdan\libstructure\tile\StructureBlockTile;
2321
use xenialdan\libstructure\window\StructureBlockInventory;
24-
use xenialdan\MagicWE2\API;
25-
use xenialdan\MagicWE2\helper\SessionHelper;
26-
use xenialdan\MagicWE2\session\data\AssetCollection;
27-
use xenialdan\MagicWE2\session\UserSession;
2822

2923
class PacketListener implements Listener
3024
{
3125
/** @var Plugin|null */
32-
private static $registrant;
26+
private static ?Plugin $registrant = null;
3327

3428
public static function isRegistered(): bool
3529
{
@@ -57,10 +51,10 @@ public static function register(Plugin $plugin): void
5751
}
5852

5953
self::$registrant = $plugin;
60-
TileFactory::getInstance()->register(StructureBlockTile::class, [StructureBlockTags::TAG_ID, "minecraft:structure_block"]);
6154
try {
62-
BlockFactory::getInstance()->register(new StructureBlock(new BlockIdentifier(BlockLegacyIds::STRUCTURE_BLOCK,0, null, StructureBlockTile::class), "Structure Block"));
63-
} catch (InvalidArgumentException $e) {
55+
TileFactory::getInstance()->register(StructureBlockTile::class, [StructureBlockTags::TAG_ID, "minecraft:structure_block"]);
56+
BlockFactory::getInstance()->register(new StructureBlock(new BlockIdentifier(BlockLegacyIds::STRUCTURE_BLOCK,0, null, StructureBlockTile::class), "Structure Block"), true);
57+
} catch (InvalidArgumentException) {
6458
}
6559
$plugin->getServer()->getPluginManager()->registerEvents(new self, $plugin);
6660
}
@@ -74,8 +68,8 @@ public function onDataPacketReceiveEvent(DataPacketReceiveEvent $e)
7468

7569
private function onStructureBlockUpdatePacket(DataPacketReceiveEvent $e)
7670
{
77-
if (!($pk = $e->getPacket()) instanceof StructureBlockUpdatePacket) return;
78-
/** @var StructureBlockUpdatePacket $pk */
71+
if (!$e->getPacket() instanceof StructureBlockUpdatePacket) return;
72+
//** @var StructureBlockUpdatePacket $pk */
7973
var_dump($e->getPacket());//TODO remove
8074
$session = $e->getOrigin();
8175
$window = $session->getInvManager()->getWindow($session->getInvManager()->getCurrentWindowId());
@@ -89,7 +83,7 @@ private function onStructureTemplateDataExportRequestPacket(DataPacketReceiveEve
8983
{
9084
/** @var StructureTemplateDataRequestPacket $pk */
9185
$pk = $e->getPacket();
92-
$player = $e->getOrigin()->getPlayer();
86+
#$player = $e->getOrigin()->getPlayer();
9387
if ($pk instanceof StructureTemplateDataRequestPacket) {
9488
var_dump($pk);//TODO remove
9589
}
@@ -99,7 +93,7 @@ private function onStructureTemplateDataExportResponsePacket(DataPacketReceiveEv
9993
{
10094
/** @var StructureTemplateDataResponsePacket $pk */
10195
$pk = $e->getPacket();
102-
$player = $e->getOrigin()->getPlayer();
96+
#$player = $e->getOrigin()->getPlayer();
10397
if ($pk instanceof StructureTemplateDataResponsePacket) {
10498
var_dump($pk);//TODO remove
10599
}

src/xenialdan/libstructure/block/StructureBlock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public function getStateBitmask() : int{
4141
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null): bool
4242
{
4343
if ($player instanceof Player) {
44-
$structureBlock = $this->pos->getWorld()->getTile($this->pos);
44+
$structureBlock = $this->position->getWorld()->getTile($this->position);
4545
if ($structureBlock instanceof TileStructureBlock/* and $player->isCreative(true)*/) {
4646
$player->setCurrentWindow($structureBlock->getInventory());
4747
//TODO remove once PMMP allows injecting to InventoryManager::createContainerOpen
4848
$id = $player->getNetworkSession()->getInvManager()->getCurrentWindowId();
49-
$pk = ContainerOpenPacket::blockInvVec3($id, WindowTypes::STRUCTURE_EDITOR, $this->pos->asVector3());
49+
$pk = ContainerOpenPacket::blockInvVec3($id, WindowTypes::STRUCTURE_EDITOR, $this->position->asVector3());
5050
$player->getNetworkSession()->sendDataPacket($pk);
5151
} else {
5252
var_dump("not tile", $structureBlock);

src/xenialdan/libstructure/format/MCStructure.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ class MCStructure
5151
public const LAYER_BLOCKS = 0;
5252
public const LAYER_LIQUIDS = 1;
5353
/** @var Vector3 */
54-
private $structure_world_origin;
54+
private Vector3 $structure_world_origin;
5555
/** @var int */
56-
private $format_version;
56+
private int $format_version;
5757
/** @var Vector3 */
58-
private $size;
58+
private Vector3 $size;
5959
/** @var PalettedBlockArray[] */
60-
private $blockLayers = [];
60+
private array $blockLayers = [];
6161
/** @var array|CompoundTag[] */
62-
private $entities = [];
62+
private array $entities = [];
6363
/** @var array|CompoundTag[] */
64-
private $blockEntities = [];
64+
private array $blockEntities = [];
6565

6666
/**
6767
* Parses a *.mcstructure file
@@ -123,7 +123,7 @@ private static function parseVec3(CompoundTag $nbt, string $tagName, bool $optio
123123
private function parseStructure(CompoundTag $structure): void
124124
{
125125
$blockIndicesList = $structure->getListTag('block_indices');//list<list<int>>
126-
$entitiesList = $structure->getListTag('entities');
126+
#$entitiesList = $structure->getListTag('entities');
127127
#var_dump($entitiesList->toString(2));
128128
$paletteCompound = $structure->getCompoundTag('palette');
129129
#$this->parseEntities($entitiesList);//TODO
@@ -170,10 +170,12 @@ private function parseBlockLayers(?CompoundTag $paletteCompound, ?ListTag $block
170170
// }
171171
// }
172172
$offset = (int)(($x * $l * $h) + ($y * $l) + $z);
173+
/** @var ListTag<IntTag> $tag */
174+
if(!$tag instanceof ListTag) continue;
173175

174176
//block layer
175-
/** @var ListTag<IntTag> $tag */
176-
$tag = $blockIndicesList->get(0);
177+
if($blockIndicesList->isset(0)){
178+
$tag = $blockIndicesList->get(0);
177179
$blockLayer = $tag->getAllValues();
178180
if (($i = $blockLayer[$offset] ?? -1) !== -1) {
179181
if (($statesEntry = $paletteArray[$i] ?? null) !== null) {
@@ -184,8 +186,9 @@ private function parseBlockLayers(?CompoundTag $paletteCompound, ?ListTag $block
184186
GlobalLogger::get()->logException($e);
185187
}
186188
}
187-
}
189+
}}
188190
//liquid layer
191+
if($blockIndicesList->isset(1)){
189192
$tag = $blockIndicesList->get(1);
190193
$liquidLayer = $tag->getAllValues();
191194
if (($i = $liquidLayer[$offset] ?? -1) !== -1) {
@@ -197,7 +200,7 @@ private function parseBlockLayers(?CompoundTag $paletteCompound, ?ListTag $block
197200
GlobalLogger::get()->logException($e);
198201
}
199202
}
200-
}
203+
}}
201204
//nbt
202205
if ($blockPositionData->getTag((string)$offset) !== null) {
203206
/** @var CompoundTag<CompoundTag> $tag1 */
@@ -225,7 +228,7 @@ public function blocks(int $layer = 0): Generator
225228
for ($z = 0; $z < $this->size->getZ(); $z++) {
226229
$fullState = $this->blockLayers[$layer]->get($x, $y, $z);
227230
$block = BlockFactory::getInstance()->fromFullBlock($fullState);
228-
[$block->getPos()->x, $block->getPos()->y, $block->getPos()->z] = [$x, $y, $z];
231+
[$block->getPosition()->x, $block->getPosition()->y, $block->getPosition()->z] = [$x, $y, $z];
229232
yield $block;
230233
}
231234
}
@@ -248,9 +251,9 @@ public function translateBlockEntity(Position $position, Vector3 $origin): ?Tile
248251
foreach ($inventoryTag as $itemNBT) {
249252
$itemNBT->setString("id", $itemNBT->getString("Name", "minecraft:air"));
250253
$itemNBT->removeTag("Name");
251-
if ($itemNBT->getTag("tag", CompoundTag::class) !== null) {
254+
if ($itemNBT->getCompoundTag("tag") !== null) {
252255
/** @var CompoundTag $tag */
253-
$tag = $itemNBT->getTag("tag", CompoundTag::class);
256+
$tag = $itemNBT->getCompoundTag("tag");
254257
if ($tag->getTag("Damage") !== null) $tag->removeTag("Damage");
255258
}
256259
}
@@ -283,7 +286,7 @@ public function translateBlockEntity(Position $position, Vector3 $origin): ?Tile
283286
* @param string $property
284287
* @return mixed
285288
*/
286-
public static function &readAnyValue(object $object, string $property)
289+
public static function &readAnyValue(object $object, string $property): mixed
287290
{
288291
$invoke = Closure::bind(function & () use ($property) {
289292
return $this->$property;

src/xenialdan/libstructure/format/NBTStructure.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use pocketmine\nbt\tag\StringTag;
1919
use xenialdan\libstructure\exception\StructureFileException;
2020
use xenialdan\MagicWE2\exception\InvalidBlockStateException;
21+
use xenialdan\MagicWE2\helper\BlockQuery;
2122
use xenialdan\MagicWE2\helper\BlockStatesParser;
2223
use xenialdan\MagicWE2\Loader;
2324
use function file_get_contents;
@@ -26,17 +27,17 @@
2627
class NBTStructure
2728
{
2829
/** @var int */
29-
private $version;
30+
private int $version;
3031
/** @var string */
31-
private $author;
32+
private string $author;
3233
/** @var Vector3 */
33-
private $size;
34+
private Vector3 $size;
3435
/** @var ListTag<CompoundTag> */
35-
private $palettes;
36+
private ListTag $palettes;
3637
/** @var ListTag<CompoundTag> */
37-
private $blocks;
38+
private ListTag $blocks;
3839
/** @var ListTag<CompoundTag> */
39-
private $entities;
40+
private ListTag $entities;
4041

4142
/**
4243
* save saves a schematic to disk.
@@ -128,7 +129,7 @@ private function paletteToBlocks(ListTag $paletteList): array
128129
$states[] = $name . '=' . $valueString;
129130
}
130131
try {
131-
$fromString = BlockStatesParser::fromString($id . '[' . implode(',', $states) . ']');
132+
$fromString = BlockStatesParser::fromString(BlockQuery::fromString($id . '[' . implode(',', $states) . ']'));
132133
} catch (InvalidBlockStateException $e) {
133134
Loader::getInstance()->getLogger()->logException($e);
134135
}
@@ -155,7 +156,7 @@ public function blocks(int $palette = 0): Generator
155156
/** @var ListTag<IntTag> $pos */
156157
$pos = $blockTag->getListTag("pos");
157158
$block = $blockPalette[$blockTag->getInt('state')];
158-
[$block->getPos()->x, $block->getPos()->y, $block->getPos()->z] = [$pos->get(0)->getValue(), $pos->get(1)->getValue(), $pos->get(2)->getValue()];
159+
[$block->getPosition()->x, $block->getPosition()->y, $block->getPosition()->z] = [$pos->get(0)->getValue(), $pos->get(1)->getValue(), $pos->get(2)->getValue()];
159160
yield $block;
160161
}
161162
}

src/xenialdan/libstructure/tile/StructureBlockTile.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function __construct(World $world, Vector3 $pos)
3838
{
3939
var_dump("constructing tile");
4040
parent::__construct($world, $pos);
41-
$this->fromV3 = $this->toV3 = $this->pos->asVector3();
42-
$this->inventory = new StructureBlockInventory($this->pos);
41+
$this->fromV3 = $this->toV3 = $this->position->asVector3();
42+
$this->inventory = new StructureBlockInventory($this->position);
4343
var_dump("constructing tile done");
4444
}
4545

@@ -69,7 +69,7 @@ protected function addAdditionalSpawnData(CompoundTag $nbt): void
6969
/**
7070
* @return StructureBlockInventory
7171
*/
72-
public function getInventory()
72+
public function getInventory(): StructureBlockInventory
7373
{
7474
return $this->inventory;
7575
}
@@ -171,11 +171,11 @@ private function calculateSize(): Vector3
171171

172172
protected function addStructureBlockData(CompoundTag $nbt): void
173173
{
174-
$pos = $this->getPos();
174+
$pos = $this->getPosition();
175175
$offset = $this->calculateOffset($pos->asVector3());
176176
$size = $this->calculateSize();
177177
var_dump("offset", $offset, "size", $size, "blockV3", $pos->asVector3());
178-
$nbt->setInt("data", (int)$this->mode);
178+
$nbt->setInt("data", $this->mode);
179179
$nbt->setString("dataField", "");
180180
$nbt->setByte("ignoreEntities", $this->showEntities ? 0 : 1);
181181
$nbt->setByte("includePlayers", $this->showPlayers ? 1 : 0);

src/xenialdan/libstructure/window/StructureBlockInventory.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
namespace xenialdan\libstructure\window;
66

77
use pocketmine\block\inventory\BlockInventory;
8+
use pocketmine\block\inventory\BlockInventoryTrait;
9+
use pocketmine\inventory\SimpleInventory;
810
use pocketmine\world\Position;
911

10-
class StructureBlockInventory extends BlockInventory
12+
class StructureBlockInventory extends SimpleInventory implements BlockInventory
1113
{
12-
public function __construct(Position $position)
14+
use BlockInventoryTrait;
15+
public function __construct(Position $holder)
1316
{
14-
parent::__construct($position, 0);
17+
$this->holder = $holder;
18+
parent::__construct(0);
1519
}
1620
}

virion.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: libstructure
2-
version: 0.1.4
2+
version: 0.1.5
33
antigen: xenialdan\libstructure
44
api: [4.0.0]
5-
php: [ 7.3, 8.0 ]
5+
php: [ 7.4, 8.0 ]
66
author: XenialDan

0 commit comments

Comments
 (0)