diff --git a/src/diamondgold/DummyItemsBlocks/Main.php b/src/diamondgold/DummyItemsBlocks/Main.php index 3d79227..45a814b 100644 --- a/src/diamondgold/DummyItemsBlocks/Main.php +++ b/src/diamondgold/DummyItemsBlocks/Main.php @@ -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; @@ -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; @@ -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 { @@ -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()); @@ -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 */ @@ -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)); } } \ No newline at end of file diff --git a/src/diamondgold/DummyItemsBlocks/tile/DummyTile.php b/src/diamondgold/DummyItemsBlocks/tile/DummyTile.php index a4afd20..e6388e5 100644 --- a/src/diamondgold/DummyItemsBlocks/tile/DummyTile.php +++ b/src/diamondgold/DummyItemsBlocks/tile/DummyTile.php @@ -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 diff --git a/src/diamondgold/DummyItemsBlocks/tile/NGDummyTiles.php b/src/diamondgold/DummyItemsBlocks/tile/NGDummyTiles.php new file mode 100644 index 0000000..69c02f0 --- /dev/null +++ b/src/diamondgold/DummyItemsBlocks/tile/NGDummyTiles.php @@ -0,0 +1,14 @@ +additionalSpawnData($nbt); + } +} \ No newline at end of file diff --git a/src/diamondgold/DummyItemsBlocks/tile/PMDummyTiles.php b/src/diamondgold/DummyItemsBlocks/tile/PMDummyTiles.php new file mode 100644 index 0000000..a2e1c65 --- /dev/null +++ b/src/diamondgold/DummyItemsBlocks/tile/PMDummyTiles.php @@ -0,0 +1,14 @@ +additionalSpawnData($nbt); + } +} \ No newline at end of file diff --git a/src/diamondgold/DummyItemsBlocks/util/BlockStateRegistration.php b/src/diamondgold/DummyItemsBlocks/util/BlockStateRegistration.php index 8bb1244..ad3fa17 100644 --- a/src/diamondgold/DummyItemsBlocks/util/BlockStateRegistration.php +++ b/src/diamondgold/DummyItemsBlocks/util/BlockStateRegistration.php @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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,