diff --git a/plugin.yml b/plugin.yml index 2813f3c..e8636a2 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: WorldBuilder main: cosmicpe\worldbuilder\Loader -api: 4.0.0 -version: 0.0.2 +api: 5.0.0 +version: 0.0.3 author: CosmicPE commands: /copy: diff --git a/src/cosmicpe/worldbuilder/command/executor/DrainCommandExecutor.php b/src/cosmicpe/worldbuilder/command/executor/DrainCommandExecutor.php index 65aa614..d942b15 100644 --- a/src/cosmicpe/worldbuilder/command/executor/DrainCommandExecutor.php +++ b/src/cosmicpe/worldbuilder/command/executor/DrainCommandExecutor.php @@ -9,7 +9,7 @@ use cosmicpe\worldbuilder\editor\utils\replacement\BlockToBlockReplacementMap; use cosmicpe\worldbuilder\Loader; use cosmicpe\worldbuilder\session\utils\Selection; -use pocketmine\block\BlockFactory; +use pocketmine\block\RuntimeBlockStateRegistry; use pocketmine\block\VanillaBlocks; use pocketmine\block\Water; use pocketmine\command\Command; @@ -31,7 +31,7 @@ public function __construct( $this->map = new BlockToBlockReplacementMap(); $air = VanillaBlocks::AIR(); - foreach(BlockFactory::getInstance()->getAllKnownStates() as $state){ + foreach(RuntimeBlockStateRegistry::getInstance()->getAllKnownStates() as $state){ if($state instanceof Water){ $this->map->put($state, $air); } diff --git a/src/cosmicpe/worldbuilder/command/executor/ReplaceSetRandomCommandExecutor.php b/src/cosmicpe/worldbuilder/command/executor/ReplaceSetRandomCommandExecutor.php index 539b864..9645247 100644 --- a/src/cosmicpe/worldbuilder/command/executor/ReplaceSetRandomCommandExecutor.php +++ b/src/cosmicpe/worldbuilder/command/executor/ReplaceSetRandomCommandExecutor.php @@ -87,7 +87,7 @@ protected function executeCommand(CommandSender $sender, \pocketmine\command\Com return true; } - $randomizer->add($replacement_block->getFullId(), $weight); + $randomizer->add($replacement_block->getStateId(), $weight); } $randomizer->setup(); diff --git a/src/cosmicpe/worldbuilder/command/executor/SetRandomCommandExecutor.php b/src/cosmicpe/worldbuilder/command/executor/SetRandomCommandExecutor.php index fb6eb6a..36d9711 100644 --- a/src/cosmicpe/worldbuilder/command/executor/SetRandomCommandExecutor.php +++ b/src/cosmicpe/worldbuilder/command/executor/SetRandomCommandExecutor.php @@ -46,7 +46,7 @@ protected function executeCommand(CommandSender $sender, \pocketmine\command\Com return true; } - $randomizer->add($block->getFullId(), $weight); + $randomizer->add($block->getStateId(), $weight); } $randomizer->setup(); diff --git a/src/cosmicpe/worldbuilder/editor/format/EditorFormatRegistry.php b/src/cosmicpe/worldbuilder/editor/format/EditorFormatRegistry.php index abd2c41..ce4df69 100644 --- a/src/cosmicpe/worldbuilder/editor/format/EditorFormatRegistry.php +++ b/src/cosmicpe/worldbuilder/editor/format/EditorFormatRegistry.php @@ -4,7 +4,6 @@ namespace cosmicpe\worldbuilder\editor\format; -use cosmicpe\worldbuilder\editor\format\mcschematic\MinecraftSchematicEditorFormat; use InvalidArgumentException; final class EditorFormatRegistry{ @@ -13,7 +12,6 @@ final class EditorFormatRegistry{ private array $formats = []; public function __construct(){ - $this->register(EditorFormatIds::MINECRAFT_SCHEMATIC, new MinecraftSchematicEditorFormat()); } public function register(string $identifier, EditorFormat $format) : void{ diff --git a/src/cosmicpe/worldbuilder/editor/format/mcschematic/LazyLoadedMinecraftSchematic.php b/src/cosmicpe/worldbuilder/editor/format/mcschematic/LazyLoadedMinecraftSchematic.php deleted file mode 100644 index 2b95638..0000000 --- a/src/cosmicpe/worldbuilder/editor/format/mcschematic/LazyLoadedMinecraftSchematic.php +++ /dev/null @@ -1,72 +0,0 @@ -explorer = $explorer; - } - - public function getWidth() : int{ - return 1 + $this->explorer->width; - } - - public function getLength() : int{ - return 1 + $this->explorer->length; - } - - public function getHeight() : int{ - return 1 + $this->explorer->height; - } - - public function getVolume() : int{ - return $this->getWidth() * $this->getLength() * $this->getHeight(); - } - - public function get(int $x, int $y, int $z) : ?SchematicEntry{ - $result = parent::get($x, $y, $z); - if($result === null){ - $result = $this->explorer->getSchematicEntryAt($x, $y, $z); - if($result !== null){ - $this->copy($x, $y, $z, $result); - } - } - return $result; - } - - /** - * @param int $x - * @param int $y - * @param int $z - * @return Generator - */ - public function getAll(&$x, &$y, &$z) : Generator{ - $width = $this->explorer->width; - $height = $this->explorer->height; - $length = $this->explorer->length; - for($i = 0; $i < $width; ++$i){ - for($k = 0; $k < $length; ++$k){ - for($j = 0; $j < $height; ++$j){ - $entry = $this->get($i, $j, $k); - if($entry !== null){ - $x = $i; - $y = $j; - $z = $k; - yield $entry; - } - } - } - } - } -} \ No newline at end of file diff --git a/src/cosmicpe/worldbuilder/editor/format/mcschematic/MinecraftSchematicEditorFormat.php b/src/cosmicpe/worldbuilder/editor/format/mcschematic/MinecraftSchematicEditorFormat.php deleted file mode 100644 index d0a9aee..0000000 --- a/src/cosmicpe/worldbuilder/editor/format/mcschematic/MinecraftSchematicEditorFormat.php +++ /dev/null @@ -1,89 +0,0 @@ -read(zlib_decode($contents))->mustGetCompoundTag(); - - $width = $root->getShort(self::TAG_WIDTH); - $height = $root->getShort(self::TAG_HEIGHT); - $length = $root->getShort(self::TAG_LENGTH); - - $block_ids = $root->getByteArray(self::TAG_BLOCK_IDS); - $block_metas = $root->getByteArray(self::TAG_BLOCK_METAS); - - $explorer = new MinecraftSchematicExplorer($width, $height, $length, $block_ids, $block_metas, []); - /** @var CompoundTag $tag */ - foreach($root->getListTag(self::TAG_TILE_ENTITIES) as $tag){ - $explorer->tile_entities[$explorer->indexAt($tag->getInt(Tile::TAG_X), $tag->getInt(Tile::TAG_Y), $tag->getInt(Tile::TAG_Z))] = $tag; - } - - return new LazyLoadedMinecraftSchematic(new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3($width - 1, $height - 1, $length - 1), $explorer); - } - - public function export(Schematic $schematic) : string{ - $width = $schematic->getWidth(); - $height = $schematic->getHeight(); - $length = $schematic->getLength(); - - $block_ids = ""; - $block_metas = ""; - $tile_entities = new ListTag([], NBT::TAG_Compound); - - $block_factory = BlockFactory::getInstance(); - for($j = 0; $j < $height; ++$j){ - for($k = 0; $k < $length; ++$k){ - for($i = 0; $i < $width; ++$i){ - $entry = $schematic->get($i, $j, $k); - if($entry !== null){ - $block = $block_factory->fromFullBlock($entry->full_block); - $id = $block->getId(); - $meta = $block->getMeta(); - }else{ - $id = 0; - $meta = 0; - } - - $block_ids .= chr($id); - $block_metas .= chr($meta); - - if($entry->tile_nbt !== null){ - $tile_entities->push($entry->tile_nbt); - } - } - } - } - - return zlib_encode((new BigEndianNbtSerializer())->write(new TreeRoot( - CompoundTag::create() - ->setShort(self::TAG_WIDTH, $schematic->getWidth()) - ->setShort(self::TAG_HEIGHT, $schematic->getHeight()) - ->setShort(self::TAG_LENGTH, $schematic->getLength()) - ->setByteArray(self::TAG_BLOCK_IDS, $block_ids) - ->setByteArray(self::TAG_BLOCK_METAS, $block_metas) - ->setTag(self::TAG_TILE_ENTITIES, $tile_entities) - )), ZLIB_ENCODING_DEFLATE, 7); - } -} \ No newline at end of file diff --git a/src/cosmicpe/worldbuilder/editor/format/mcschematic/MinecraftSchematicExplorer.php b/src/cosmicpe/worldbuilder/editor/format/mcschematic/MinecraftSchematicExplorer.php deleted file mode 100644 index 67782ab..0000000 --- a/src/cosmicpe/worldbuilder/editor/format/mcschematic/MinecraftSchematicExplorer.php +++ /dev/null @@ -1,48 +0,0 @@ - $tile_entities - */ - public function __construct( - public int $width, - public int $height, - public int $length, - public string $block_ids, - public string $block_metas, - public array $tile_entities - ){} - - public function indexAt(int $x, int $y, int $z) : int{ - return self::index($x, $y, $z, $this->length, $this->width); - } - - public function getSchematicEntryAt(int $x, int $y, int $z) : ?SchematicEntry{ - return $this->getSchematicEntry($this->indexAt($x, $y, $z)); - } - - public function getSchematicEntry(int $index) : ?SchematicEntry{ - return isset($this->block_ids[$index]) ? new SchematicEntry( - BlockFactory::getInstance()->get(ord($this->block_ids[$index]), ord($this->block_metas[$index]))->getFullId(), - $this->tile_entities[$index] ?? null - ) : null; - } -} \ No newline at end of file diff --git a/src/cosmicpe/worldbuilder/editor/task/ReplaceEditorTask.php b/src/cosmicpe/worldbuilder/editor/task/ReplaceEditorTask.php index 53cb238..24fcc02 100644 --- a/src/cosmicpe/worldbuilder/editor/task/ReplaceEditorTask.php +++ b/src/cosmicpe/worldbuilder/editor/task/ReplaceEditorTask.php @@ -33,8 +33,8 @@ public function getName() : string{ } protected function onIterate(SubChunkIteratorCursor $cursor) : bool{ - if(isset($this->replacement_map[$find = $cursor->sub_chunk->getFullBlock($cursor->x, $cursor->y, $cursor->z)])){ - $cursor->sub_chunk->setFullBlock($cursor->x, $cursor->y, $cursor->z, $this->replacement_map[$find]); + if(isset($this->replacement_map[$find = $cursor->sub_chunk->getBlockStateId($cursor->x, $cursor->y, $cursor->z)])){ + $cursor->sub_chunk->setBlockStateId($cursor->x, $cursor->y, $cursor->z, $this->replacement_map[$find]); $tile = $cursor->chunk->getTile($cursor->x, ($cursor->subChunkY << Chunk::COORD_BIT_SIZE) + $cursor->y, $cursor->z); if($tile !== null){ $cursor->chunk->removeTile($tile); diff --git a/src/cosmicpe/worldbuilder/editor/task/ReplaceSetRandomEditorTask.php b/src/cosmicpe/worldbuilder/editor/task/ReplaceSetRandomEditorTask.php index f63cf89..1b1e228 100644 --- a/src/cosmicpe/worldbuilder/editor/task/ReplaceSetRandomEditorTask.php +++ b/src/cosmicpe/worldbuilder/editor/task/ReplaceSetRandomEditorTask.php @@ -34,8 +34,8 @@ public function getName() : string{ } protected function onIterate(SubChunkIteratorCursor $cursor) : bool{ - if(isset($this->replacement_map[$find = $cursor->sub_chunk->getFullBlock($cursor->x, $cursor->y, $cursor->z)])){ - $cursor->sub_chunk->setFullBlock($cursor->x, $cursor->y, $cursor->z, $this->replacement_map[$find]->generate(1)->current()); + if(isset($this->replacement_map[$find = $cursor->sub_chunk->getBlockStateId($cursor->x, $cursor->y, $cursor->z)])){ + $cursor->sub_chunk->setBlockStateId($cursor->x, $cursor->y, $cursor->z, $this->replacement_map[$find]->generate(1)->current()); $tile = $cursor->chunk->getTile($cursor->x, ($cursor->subChunkY << Chunk::COORD_BIT_SIZE) + $cursor->y, $cursor->z); if($tile !== null){ $cursor->chunk->removeTile($tile); diff --git a/src/cosmicpe/worldbuilder/editor/task/SetBiomeEditorTask.php b/src/cosmicpe/worldbuilder/editor/task/SetBiomeEditorTask.php index 308c835..e75c36d 100644 --- a/src/cosmicpe/worldbuilder/editor/task/SetBiomeEditorTask.php +++ b/src/cosmicpe/worldbuilder/editor/task/SetBiomeEditorTask.php @@ -12,10 +12,14 @@ class SetBiomeEditorTask extends AdvancedPlaneEditorTask{ private int $biome_id; + private int $min_y; + private int $max_y; public function __construct(World $world, Selection $selection, int $biome_id){ parent::__construct($world, $selection, (int) Vector3Utils::calculateVolume($selection->getPoint(0), $selection->getPoint(1))); $this->biome_id = $biome_id; + $this->min_y = $world->getMinY(); + $this->max_y = $world->getMaxY(); } final public function getBiomeId() : int{ @@ -27,7 +31,9 @@ public function getName() : string{ } protected function onIterate(ChunkIteratorCursor $cursor) : bool{ - $cursor->chunk->setBiomeId($cursor->x, $cursor->z, $this->biome_id); + for($y = $this->min_y; $y < $this->max_y; ++$y) { + $cursor->chunk->setBiomeId($cursor->x, $y, $cursor->z, $this->biome_id); + } return true; } } \ No newline at end of file diff --git a/src/cosmicpe/worldbuilder/editor/task/SetEditorTask.php b/src/cosmicpe/worldbuilder/editor/task/SetEditorTask.php index b20756f..ded8b85 100644 --- a/src/cosmicpe/worldbuilder/editor/task/SetEditorTask.php +++ b/src/cosmicpe/worldbuilder/editor/task/SetEditorTask.php @@ -8,7 +8,7 @@ use cosmicpe\worldbuilder\session\utils\Selection; use cosmicpe\worldbuilder\utils\Vector3Utils; use pocketmine\block\Block; -use pocketmine\block\BlockFactory; +use pocketmine\block\RuntimeBlockStateRegistry; use pocketmine\world\format\Chunk; use pocketmine\world\World; @@ -18,11 +18,11 @@ class SetEditorTask extends AdvancedEditorTask{ public function __construct(World $world, Selection $selection, Block $block){ parent::__construct($world, $selection, (int) Vector3Utils::calculateVolume($selection->getPoint(0), $selection->getPoint(1))); - $this->full_block = $block->getFullId(); + $this->full_block = $block->getStateId(); } final public function getBlockSet() : Block{ - return BlockFactory::getInstance()->fromFullBlock($this->full_block); + return RuntimeBlockStateRegistry::getInstance()->fromStateId($this->full_block); } public function getName() : string{ @@ -30,7 +30,7 @@ public function getName() : string{ } protected function onIterate(SubChunkIteratorCursor $cursor) : bool{ - $cursor->sub_chunk->setFullBlock($cursor->x, $cursor->y, $cursor->z, $this->full_block); + $cursor->sub_chunk->setBlockStateId($cursor->x, $cursor->y, $cursor->z, $this->full_block); $tile = $cursor->chunk->getTile($cursor->x, ($cursor->subChunkY << Chunk::COORD_BIT_SIZE) + $cursor->y, $cursor->z); if($tile !== null){ $cursor->chunk->removeTile($tile); diff --git a/src/cosmicpe/worldbuilder/editor/task/SetRandomEditorTask.php b/src/cosmicpe/worldbuilder/editor/task/SetRandomEditorTask.php index e9e5248..934c280 100644 --- a/src/cosmicpe/worldbuilder/editor/task/SetRandomEditorTask.php +++ b/src/cosmicpe/worldbuilder/editor/task/SetRandomEditorTask.php @@ -25,7 +25,7 @@ public function getName() : string{ } protected function onIterate(SubChunkIteratorCursor $cursor) : bool{ - $cursor->sub_chunk->setFullBlock($cursor->x, $cursor->y, $cursor->z, $this->selector->generate(1)->current()); + $cursor->sub_chunk->setBlockStateId($cursor->x, $cursor->y, $cursor->z, $this->selector->generate(1)->current()); $tile = $cursor->chunk->getTile($cursor->x, ($cursor->subChunkY << Chunk::COORD_BIT_SIZE) + $cursor->y, $cursor->z); if($tile !== null){ $cursor->chunk->removeTile($tile); diff --git a/src/cosmicpe/worldbuilder/editor/task/SetSchematicEditorTask.php b/src/cosmicpe/worldbuilder/editor/task/SetSchematicEditorTask.php index 7c2e24d..868385c 100644 --- a/src/cosmicpe/worldbuilder/editor/task/SetSchematicEditorTask.php +++ b/src/cosmicpe/worldbuilder/editor/task/SetSchematicEditorTask.php @@ -46,7 +46,7 @@ public function run() : Generator{ $tiles[] = $tile_factory->createFromData($world, NamedtagCopierManager::moveTo($entry->tile_nbt, $x, $y, $z)); } - $iterator->currentSubChunk->setFullBlock($x & Chunk::COORD_MASK, $y & Chunk::COORD_MASK, $z & Chunk::COORD_MASK, $entry->full_block); + $iterator->currentSubChunk->setBlockStateId($x & Chunk::COORD_MASK, $y & Chunk::COORD_MASK, $z & Chunk::COORD_MASK, $entry->block_state_id); $chunks[World::chunkHash($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)] = true; yield true; } diff --git a/src/cosmicpe/worldbuilder/editor/task/copy/CopyEditorTask.php b/src/cosmicpe/worldbuilder/editor/task/copy/CopyEditorTask.php index dfd996f..5afe5a7 100644 --- a/src/cosmicpe/worldbuilder/editor/task/copy/CopyEditorTask.php +++ b/src/cosmicpe/worldbuilder/editor/task/copy/CopyEditorTask.php @@ -41,7 +41,7 @@ protected function onIterate(SubChunkIteratorCursor $cursor) : bool{ $y - $this->minimum->y, ($cursor->chunkZ << Chunk::COORD_BIT_SIZE) + $cursor->z - $this->minimum->z, new SchematicEntry( - $cursor->sub_chunk->getFullBlock($cursor->x, $cursor->y, $cursor->z), + $cursor->sub_chunk->getBlockStateId($cursor->x, $cursor->y, $cursor->z), $tile !== null ? NamedtagCopierManager::copy($tile) : null ) ); diff --git a/src/cosmicpe/worldbuilder/editor/utils/replacement/BlockToBlockReplacementMap.php b/src/cosmicpe/worldbuilder/editor/utils/replacement/BlockToBlockReplacementMap.php index 9633c4d..3ef28d9 100644 --- a/src/cosmicpe/worldbuilder/editor/utils/replacement/BlockToBlockReplacementMap.php +++ b/src/cosmicpe/worldbuilder/editor/utils/replacement/BlockToBlockReplacementMap.php @@ -5,7 +5,7 @@ namespace cosmicpe\worldbuilder\editor\utils\replacement; use pocketmine\block\Block; -use pocketmine\block\BlockFactory; +use pocketmine\block\RuntimeBlockStateRegistry; final class BlockToBlockReplacementMap{ @@ -13,7 +13,7 @@ final class BlockToBlockReplacementMap{ private array $full_id_map = []; public function put(Block $find, Block $replace) : BlockToBlockReplacementMap{ - return $this->putFullId($find->getFullId(), $replace->getFullId()); + return $this->putFullId($find->getStateId(), $replace->getStateId()); } public function putFullId(int $find, int $replace) : BlockToBlockReplacementMap{ @@ -24,7 +24,7 @@ public function putFullId(int $find, int $replace) : BlockToBlockReplacementMap{ } public function contains(Block $block) : bool{ - return isset($this->full_id_map[$block->getFullId()]); + return isset($this->full_id_map[$block->getStateId()]); } public function isEmpty() : bool{ @@ -39,10 +39,10 @@ public function toFullIdArray() : array{ } public function __toString() : string{ - $block_factory = BlockFactory::getInstance(); + $block_state_registry = RuntimeBlockStateRegistry::getInstance(); $result = ""; foreach($this->full_id_map as $find => $replace){ - $result .= $block_factory->fromFullBlock($find)->getName() . " -> " . $block_factory->fromFullBlock($replace)->getName() . ", "; + $result .= $block_state_registry->fromStateId($find)->getName() . " -> " . $block_state_registry->fromStateId($replace)->getName() . ", "; } return rtrim($result, ", "); } diff --git a/src/cosmicpe/worldbuilder/editor/utils/replacement/BlockToWeightedRandomSelectorReplacementMap.php b/src/cosmicpe/worldbuilder/editor/utils/replacement/BlockToWeightedRandomSelectorReplacementMap.php index cd275d3..9279836 100644 --- a/src/cosmicpe/worldbuilder/editor/utils/replacement/BlockToWeightedRandomSelectorReplacementMap.php +++ b/src/cosmicpe/worldbuilder/editor/utils/replacement/BlockToWeightedRandomSelectorReplacementMap.php @@ -6,7 +6,7 @@ use cosmicpe\worldbuilder\utils\WeightedRandomIntegerSelector; use pocketmine\block\Block; -use pocketmine\block\BlockFactory; +use pocketmine\block\RuntimeBlockStateRegistry; final class BlockToWeightedRandomSelectorReplacementMap{ @@ -14,16 +14,16 @@ final class BlockToWeightedRandomSelectorReplacementMap{ private array $block_to_selector_map = []; public function put(Block $find, WeightedRandomIntegerSelector $selector) : self{ - $this->block_to_selector_map[$find->getFullId()] = $selector; + $this->block_to_selector_map[$find->getStateId()] = $selector; return $this; } public function get(Block $block) : ?WeightedRandomIntegerSelector{ - return $this->block_to_selector_map[$block->getFullId()] ?? null; + return $this->block_to_selector_map[$block->getStateId()] ?? null; } public function contains(Block $block) : bool{ - return isset($this->block_to_selector_map[$block->getFullId()]); + return isset($this->block_to_selector_map[$block->getStateId()]); } public function isEmpty() : bool{ @@ -38,10 +38,10 @@ public function toFullIdArray() : array{ } public function __toString() : string{ - $block_factory = BlockFactory::getInstance(); + $block_state_registry = RuntimeBlockStateRegistry::getInstance(); $result = ""; foreach($this->block_to_selector_map as $find => $replace){ - $result .= $block_factory->fromFullBlock($find)->getName() . " -> Random({" . $replace->count() . "}), "; + $result .= $block_state_registry->fromStateId($find)->getName() . " -> Random({" . $replace->count() . "}), "; } return rtrim($result, ", "); } diff --git a/src/cosmicpe/worldbuilder/editor/utils/schematic/SchematicEntry.php b/src/cosmicpe/worldbuilder/editor/utils/schematic/SchematicEntry.php index 2746e12..02acf4d 100644 --- a/src/cosmicpe/worldbuilder/editor/utils/schematic/SchematicEntry.php +++ b/src/cosmicpe/worldbuilder/editor/utils/schematic/SchematicEntry.php @@ -9,7 +9,7 @@ final class SchematicEntry{ public function __construct( - public int $full_block, + public int $block_state_id, public ?CompoundTag $tile_nbt ){} } \ No newline at end of file diff --git a/src/cosmicpe/worldbuilder/utils/BlockUtils.php b/src/cosmicpe/worldbuilder/utils/BlockUtils.php index 86af4bd..f50933e 100644 --- a/src/cosmicpe/worldbuilder/utils/BlockUtils.php +++ b/src/cosmicpe/worldbuilder/utils/BlockUtils.php @@ -4,37 +4,24 @@ namespace cosmicpe\worldbuilder\utils; -use InvalidArgumentException; use pocketmine\block\Block; -use pocketmine\block\BlockFactory; -use pocketmine\block\BlockLegacyIds; -use pocketmine\data\bedrock\LegacyBlockIdToStringIdMap; +use pocketmine\block\BlockTypeIds; +use pocketmine\item\ItemTypeIds; use pocketmine\item\LegacyStringToItemParser; use pocketmine\item\LegacyStringToItemParserException; +use pocketmine\item\StringToItemParser; final class BlockUtils{ public static function fromString(string $string) : ?Block{ - if(($id_meta_split_pos = strrpos($string, ":")) !== false){ - $id = substr($string, 0, $id_meta_split_pos); - if(!is_numeric($id) && strpos($id, "minecraft:") !== 0){ - $id = "minecraft:{$id}"; - } - - $meta = substr($string, $id_meta_split_pos + 1); - - try{ - return BlockFactory::getInstance()->get(LegacyBlockIdToStringIdMap::getInstance()->stringToLegacy($id) ?? (int) $id, (int) $meta); - }catch(InvalidArgumentException $e){ - return null; - } + try { + $item = StringToItemParser::getInstance()->parse($string) ?? LegacyStringToItemParser::getInstance()->parse($string); + }catch(LegacyStringToItemParserException){ + return null; } - - try{ - $block = LegacyStringToItemParser::getInstance()->parse($string)->getBlock(); - }catch(LegacyStringToItemParserException $e){ + if(!$item->isNull() && $item->getBlock()->getTypeId() === BlockTypeIds::AIR){ return null; } - return $block->canBePlaced() || ($block->getId() === BlockLegacyIds::AIR && ($string === "air" || $string === "0")) ? $block : null; + return $item->getBlock(); } } \ No newline at end of file