mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
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.
This commit is contained in:
parent
c496480d2b
commit
ddcb2f002a
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user