Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/FasterChest.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
name: FasterChest
main: cosmoverse\fasterchest\Loader
api: 5.0.0
version: 0.0.1
version: 2.0.0-beta
author: Muqsit
commands:
fasterchest:
description: Convert or revert chests in worlds between vanilla chests and faster chests
usage: /fasterchest convert/revert <world>
permission: fasterchest.command.fasterchest
aliases: ["fasterchests"]

permissions:
fasterchest.command.fasterchest:
description: Ability to use /fasterchest command
manage.fasterchest.command:
default: op
4 changes: 2 additions & 2 deletions src/cosmoverse/fasterchest/DefaultFasterChestSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
use pocketmine\nbt\TreeRoot;
use function assert;

final class DefaultFasterChestSerializer implements FasterChestSerializer{
final readonly class DefaultFasterChestSerializer implements FasterChestSerializer{

public static function instance() : self{
static $instance = null;
return $instance ??= new self();
}

readonly private BigEndianNbtSerializer $serializer;
private BigEndianNbtSerializer $serializer;

private function __construct(){
$this->serializer = new BigEndianNbtSerializer();
Expand Down
94 changes: 51 additions & 43 deletions src/cosmoverse/fasterchest/FasterChestChunkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace cosmoverse\fasterchest;

use Closure;
use pocketmine\block\tile\Barrel as VanillaBarrelTile;
use pocketmine\block\tile\Chest as VanillaChestTile;
use pocketmine\math\Vector3;
use pocketmine\world\ChunkListener;
Expand All @@ -13,47 +14,54 @@

final class FasterChestChunkListener implements ChunkListener{

/** @var array<int, true> */
private array $exclude_list = [];

public function __construct(
readonly private Loader $loader,
readonly private World $world
){}

public function onChunkChanged(int $chunkX, int $chunkZ, Chunk $chunk) : void{
}

public function onChunkLoaded(int $chunkX, int $chunkZ, Chunk $chunk) : void{
}

public function onChunkUnloaded(int $chunkX, int $chunkZ, Chunk $chunk) : void{
}

public function onChunkPopulated(int $chunkX, int $chunkZ, Chunk $chunk) : void{
}

public function onBlockChanged(Vector3 $block) : void{
$tile = $this->world->getTileAt($block->x, $block->y, $block->z);
if($tile === null || $tile::class !== VanillaChestTile::class || isset($this->exclude_list[World::blockHash($block->x, $block->y, $block->z)])){
return;
}
$this->loader->convertTile($tile);
}

/**
* @param int $x
* @param int $y
* @param int $z
* @param Closure() : void $callback
*/
public function excluding(int $x, int $y, int $z, Closure $callback) : void{
$hash = World::blockHash($x, $y, $z);
$this->exclude_list[$hash] = true;
try{
$callback();
}finally{
unset($this->exclude_list[$hash]);
}
}
/** @var array<int, true> */
private array $exclude_list = [];

public function __construct(
readonly private Loader $loader,
readonly private World $world
){}

public function onChunkChanged(int $chunkX, int $chunkZ, Chunk $chunk) : void{
}

public function onChunkLoaded(int $chunkX, int $chunkZ, Chunk $chunk) : void{
}

public function onChunkUnloaded(int $chunkX, int $chunkZ, Chunk $chunk) : void{
}

public function onChunkPopulated(int $chunkX, int $chunkZ, Chunk $chunk) : void{
}

public function onBlockChanged(Vector3 $block) : void{
$tile = $this->world->getTileAt($block->x, $block->y, $block->z);
$hash = World::blockHash($block->x, $block->y, $block->z);

if($tile === null || isset($this->exclude_list[$hash])){
return;
}

if($tile::class === VanillaChestTile::class){
$this->loader->convertChestTile($tile);
} elseif($tile::class === VanillaBarrelTile::class){
$this->loader->convertBarrelTile($tile);
}
}

/**
* @param int $x
* @param int $y
* @param int $z
* @param Closure() : void $callback
*/
public function excluding(int $x, int $y, int $z, Closure $callback) : void{
$hash = World::blockHash($x, $y, $z);
$this->exclude_list[$hash] = true;
try{
$callback();
}finally{
unset($this->exclude_list[$hash]);
}
}
}
Loading