Skip to content

Commit

Permalink
Resolved diamond-gold#3
Browse files Browse the repository at this point in the history
  • Loading branch information
DavyCraft648 committed Nov 12, 2023
1 parent 6f7b420 commit fe7f8f0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
8 changes: 7 additions & 1 deletion src/diamondgold/DummyItemsBlocks/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use diamondgold\DummyItemsBlocks\item\horn\GoatHornTypeIdMap;
use diamondgold\DummyItemsBlocks\item\ItemPlacedAsBlock;
use diamondgold\DummyItemsBlocks\tile\DummyTile;
use diamondgold\DummyItemsBlocks\tile\NGDummyTiles;
use diamondgold\DummyItemsBlocks\tile\PMDummyTiles;
use diamondgold\DummyItemsBlocks\tile\TileNames;
use diamondgold\DummyItemsBlocks\util\BlockStateRegistration;
use diamondgold\DummyItemsBlocks\util\DummyBlocks;
Expand Down Expand Up @@ -50,6 +52,7 @@
use pocketmine\item\StringToItemParser;
use pocketmine\item\VanillaItems;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\player\Player;
use pocketmine\plugin\DisablePluginException;
use pocketmine\plugin\PluginBase;
Expand All @@ -59,6 +62,7 @@
use pocketmine\world\format\io\GlobalBlockStateHandlers;
use pocketmine\world\format\io\GlobalItemDataHandlers;
use Throwable;
use function defined;

final class Main extends PluginBase
{
Expand Down Expand Up @@ -99,6 +103,7 @@ public static function canChangeBlockStates(Block $block, ?Player $player): bool

protected function onEnable(): void
{
DummyTile::$CLASS = defined(ProtocolInfo::class . "::ACCEPTED_PROTOCOL") ? NGDummyTiles::class : PMDummyTiles::class;
$this->saveDefaultConfig();
$config = $this->getConfig();
//$config->set("blocks", ReflectionHelper::BlockTypeNames());
Expand Down Expand Up @@ -317,6 +322,7 @@ public function __construct(protected string $blocksSerialized, protected string

public function onRun(): void
{
DummyTile::$CLASS = defined(ProtocolInfo::class . "::ACCEPTED_PROTOCOL") ? NGDummyTiles::class : PMDummyTiles::class;
/** @var string[] $items */
$items = igbinary_unserialize($this->itemsSerialized);
/** @var string[] $blocks */
Expand Down Expand Up @@ -894,6 +900,6 @@ private function registerDummyTiles(array $blocks): void
unset($tiles[$name]);
}
}
TileFactory::getInstance()->register(DummyTile::class, array_keys($tiles));
TileFactory::getInstance()->register(DummyTile::$CLASS, array_keys($tiles));
}
}
5 changes: 3 additions & 2 deletions src/diamondgold/DummyItemsBlocks/tile/DummyTile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\VersionInfo;

final class DummyTile extends Spawnable
abstract class DummyTile extends Spawnable
{
public static string $CLASS;
protected ?CompoundTag $nbt = null;

protected function addAdditionalSpawnData(CompoundTag $nbt): void
protected function additionalSpawnData(CompoundTag $nbt): void
{
$this->writeSaveData($nbt); // IDK which tags affect appearance, so just send the whole thing :P
// can't override getSpawnCompound()... override id here instead
Expand Down
14 changes: 14 additions & 0 deletions src/diamondgold/DummyItemsBlocks/tile/NGDummyTiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);

namespace diamondgold\DummyItemsBlocks\tile;

use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\convert\TypeConverter;

class NGDummyTiles extends DummyTile{

protected function addAdditionalSpawnData(CompoundTag $nbt, TypeConverter $typeConverter) : void{
$this->additionalSpawnData($nbt);
}
}
14 changes: 14 additions & 0 deletions src/diamondgold/DummyItemsBlocks/tile/PMDummyTiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);

namespace diamondgold\DummyItemsBlocks\tile;

use pocketmine\nbt\tag\CompoundTag;

class PMDummyTiles extends DummyTile{

/** @noinspection PhpHierarchyChecksInspection */
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
$this->additionalSpawnData($nbt);
}
}
28 changes: 14 additions & 14 deletions src/diamondgold/DummyItemsBlocks/util/BlockStateRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public static function AmethystAnyFacing(string $id): void

public static function BeeHive(string $id): void
{
$block = new BeeHive(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new BeeHive(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down Expand Up @@ -355,7 +355,7 @@ public static function BubbleColumn(): void
public static function CalibratedSculkSensor(): void
{
$id = BlockTypeNames::CALIBRATED_SCULK_SENSOR;
$block = new CalibratedSculkSensor(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new CalibratedSculkSensor(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand All @@ -373,7 +373,7 @@ public static function CalibratedSculkSensor(): void
// obsolete when merged https://github.com/pmmp/PocketMine-MP/pull/4696
public static function Campfire(string $id): void
{
$block = new Campfire(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new Campfire(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id . '_block'], false);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down Expand Up @@ -408,7 +408,7 @@ public static function CherrySapling(): void
public static function ChiseledBookshelf(): void
{
$id = BlockTypeNames::CHISELED_BOOKSHELF;
$block = new ChiseledBookshelf(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new ChiseledBookshelf(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand All @@ -425,7 +425,7 @@ public static function ChiseledBookshelf(): void

public static function CommandBlock(string $id): void
{
$block = new CommandBlock(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::indestructible()));
$block = new CommandBlock(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::indestructible()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down Expand Up @@ -460,7 +460,7 @@ public static function Composter(): void
public static function DecoratedPot(): void
{
$id = BlockTypeNames::DECORATED_POT;
$block = new DecoratedPot(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new DecoratedPot(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand All @@ -475,7 +475,7 @@ public static function DecoratedPot(): void

public static function Dispenser(string $id): void
{
$block = new Dispenser(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new Dispenser(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down Expand Up @@ -511,7 +511,7 @@ public static function Grindstone(): void
// obsolete when merged https://github.com/pmmp/PocketMine-MP/pull/6013
public static function HangingSign(string $id): void
{
$block = new HangingSign(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new HangingSign(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id . '_block'], false);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down Expand Up @@ -610,7 +610,7 @@ public static function Observer(): void

public static function Piston(string $id): void
{
$block = new Piston(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new Piston(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down Expand Up @@ -721,7 +721,7 @@ public static function Scaffolding(): void
public static function SculkCatalyst(): void
{
$id = BlockTypeNames::SCULK_CATALYST;
$block = new SculkCatalyst(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new SculkCatalyst(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand All @@ -737,7 +737,7 @@ public static function SculkCatalyst(): void
public static function SculkSensor(): void
{
$id = BlockTypeNames::SCULK_SENSOR;
$block = new SculkSensor(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new SculkSensor(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand All @@ -753,7 +753,7 @@ public static function SculkSensor(): void
public static function SculkShrieker(): void
{
$id = BlockTypeNames::SCULK_SHRIEKER;
$block = new SculkShrieker(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
$block = new SculkShrieker(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down Expand Up @@ -814,7 +814,7 @@ public static function SnifferEgg(): void
public static function StructureBlock(): void
{
$id = BlockTypeNames::STRUCTURE_BLOCK;
$block = new StructureBlock(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::indestructible()));
$block = new StructureBlock(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::indestructible()));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down Expand Up @@ -864,7 +864,7 @@ public static function SuspiciousFallable(string $id): void
$tags = [];
}
// Note: does not implement Fallable nor use the FallableTrait
$block = new SuspiciousFallable(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::class), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant(), $tags));
$block = new SuspiciousFallable(new BlockIdentifier(BlockTypeIds::newId(), DummyTile::$CLASS), Utils::generateNameFromId($id), new BlockTypeInfo(BlockBreakInfo::instant(), $tags));
self::register($block, [$id]);

GlobalBlockStateHandlers::getDeserializer()->map($id,
Expand Down

0 comments on commit fe7f8f0

Please sign in to comment.