45 private array $knownTiles = [];
50 private array $saveNames = [];
52 public function __construct(){
53 $this->
register(Barrel::class, [
"Barrel",
"minecraft:barrel"]);
54 $this->
register(Banner::class, [
"Banner",
"minecraft:banner"]);
55 $this->
register(Beacon::class, [
"Beacon",
"minecraft:beacon"]);
56 $this->
register(Bed::class, [
"Bed",
"minecraft:bed"]);
57 $this->
register(Bell::class, [
"Bell",
"minecraft:bell"]);
58 $this->
register(BlastFurnace::class, [
"BlastFurnace",
"minecraft:blast_furnace"]);
59 $this->
register(BrewingStand::class, [
"BrewingStand",
"minecraft:brewing_stand"]);
60 $this->
register(Campfire::class, [
"Campfire",
"minecraft:campfire"]);
61 $this->
register(Cauldron::class, [
"Cauldron",
"minecraft:cauldron"]);
62 $this->
register(Chest::class, [
"Chest",
"minecraft:chest"]);
63 $this->
register(ChiseledBookshelf::class, [
"ChiseledBookshelf",
"minecraft:chiseled_bookshelf"]);
64 $this->
register(Comparator::class, [
"Comparator",
"minecraft:comparator"]);
65 $this->
register(DaylightSensor::class, [
"DaylightDetector",
"minecraft:daylight_detector"]);
66 $this->
register(EnchantTable::class, [
"EnchantTable",
"minecraft:enchanting_table"]);
67 $this->
register(EnderChest::class, [
"EnderChest",
"minecraft:ender_chest"]);
68 $this->
register(FlowerPot::class, [
"FlowerPot",
"minecraft:flower_pot"]);
69 $this->
register(NormalFurnace::class, [
"Furnace",
"minecraft:furnace"]);
70 $this->
register(Hopper::class, [
"Hopper",
"minecraft:hopper"]);
71 $this->
register(ItemFrame::class, [
"ItemFrame"]);
72 $this->
register(Jukebox::class, [
"Jukebox",
"RecordPlayer",
"minecraft:jukebox"]);
73 $this->
register(Lectern::class, [
"Lectern",
"minecraft:lectern"]);
74 $this->
register(MonsterSpawner::class, [
"MobSpawner",
"minecraft:mob_spawner"]);
75 $this->
register(Note::class, [
"Music",
"minecraft:noteblock"]);
76 $this->
register(ShulkerBox::class, [
"ShulkerBox",
"minecraft:shulker_box"]);
77 $this->
register(Sign::class, [
"Sign",
"minecraft:sign"]);
78 $this->
register(Smoker::class, [
"Smoker",
"minecraft:smoker"]);
79 $this->
register(SporeBlossom::class, [
"SporeBlossom",
"minecraft:spore_blossom"]);
80 $this->
register(MobHead::class, [
"Skull",
"minecraft:skull"]);
81 $this->
register(GlowingItemFrame::class, [
"GlowItemFrame"]);
102 public function register(
string $className, array $saveNames = []) : void{
103 Utils::testValidInstance($className,
Tile::class);
105 $shortName = (new \ReflectionClass($className))->getShortName();
106 if(!in_array($shortName, $saveNames,
true)){
107 $saveNames[] = $shortName;
110 foreach($saveNames as $name){
111 $this->knownTiles[$name] = $className;
114 $this->saveNames[$className] = reset($saveNames);
123 $type = $nbt->getString(Tile::TAG_ID,
"");
124 if(!isset($this->knownTiles[$type])){
127 $class = $this->knownTiles[$type];
128 assert(is_a($class, Tile::class,
true));
133 $tile =
new $class($world,
new Vector3($nbt->getInt(Tile::TAG_X), $nbt->getInt(Tile::TAG_Y), $nbt->getInt(Tile::TAG_Z)));
134 $tile->readSaveData($nbt);
135 }
catch(NbtException $e){
136 throw new SavedDataLoadingException($e->getMessage(), 0, $e);
146 if(isset($this->saveNames[$class])){
147 return $this->saveNames[$class];
149 throw new \InvalidArgumentException(
"Tile $class is not registered");