From ddcb2f002ac710f3c9f11fcf772552e0ac249337 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 19 Aug 2018 19:54:22 +0100 Subject: [PATCH] Tile: Be explicit about not calling Tile::createNBT() (#2388) A common pitfall developers fall into with this function is that it has to be called from the scope of the tile class you're creating NBT for, but people commonly do Tile::createNBT() directly, which then results in cryptic "Tile is not registered" errors. This now throws a BadMethodCallException instead to be fully clear about this. In the future this will be removed completely once NBT is no longer required to create a tile, but for now this is a confusing issue that should be dealt with. --- src/pocketmine/tile/Tile.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index e2b864c3b..9081bbb01 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -209,6 +209,9 @@ abstract class Tile extends Position{ * @return CompoundTag */ public static function createNBT(Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : CompoundTag{ + if(static::class === self::class){ + throw new \BadMethodCallException(__METHOD__ . " must be called from the scope of a child class"); + } $nbt = new CompoundTag("", [ new StringTag(self::TAG_ID, static::getSaveId()), new IntTag(self::TAG_X, (int) $pos->x),