diff --git a/resources/lang/deu.yml b/resources/lang/deu.yml index 88b6803d..fc837e7e 100644 --- a/resources/lang/deu.yml +++ b/resources/lang/deu.yml @@ -1,6 +1,6 @@ #German language file #Author: platz1de -#Last updated at: 2024-03-05 +#Last updated at: 2024-05-24 #If you want to include double quotes (") in your messages please escape them with a backslash (\") @@ -70,6 +70,9 @@ benchmark-result: "#{task}: {name} - {blocks} in {time}s" #Args: {state} {id} {meta} {name} {x} {y} {z} {java_state} block-info: "{name} ({id}:{meta}) at {x} {y} {z}\nBlockzustand: {state}\nJava Blockzustand: {java_state}" +#Args: {count} {name} {id} {meta} {nbt} {java_nbt} +item-info: "{count}x {name}§r ({id}:{meta})\nItem data: {nbt}\nJava data: {java_nbt}" + #Args: {schematic} {known} unknown-schematic: "Unbekannte Struktur \"{schematic}\"\nBekannte Strukturen:{known}" @@ -219,6 +222,9 @@ command-pastestates-description: "Füge alle bekannten Blockzustände in die Wel command-pastestates-usage: "//pastestates" command-wand-description: "Erhalte eine Holzaxt" command-wand-usage: "//wand" +command-iteminfo-description: "Erhalte Informationen über den gehaltenen Gegenstand" +command-iteminfo-usage: "//iteminfo" + command-thru-description: "Teleportiere durch blöcke hindurch" command-thru-usage: "//thru" diff --git a/resources/lang/eng.yml b/resources/lang/eng.yml index 622f1293..ee8d4dba 100644 --- a/resources/lang/eng.yml +++ b/resources/lang/eng.yml @@ -1,6 +1,6 @@ #English language file #Author: platz1de -#Last updated at: 2024-03-05 +#Last updated at: 2024-05-24 #If you want to include double quotes (") in your messages please escape them with a backslash (\") @@ -70,6 +70,9 @@ benchmark-result: "#{task}: {name} - {blocks} in {time}s" #Args: {state} {id} {meta} {name} {x} {y} {z} {java_state} block-info: "{name} ({id}:{meta}) at {x} {y} {z}\nBlock state: {state}\nJava state: {java_state}" +#Args: {count} {name} {id} {meta} {nbt} {java_nbt} +item-info: "{count}x {name}§r ({id}:{meta})\nItem data: {nbt}\nJava data: {java_nbt}" + #Args: {schematic} {known} unknown-schematic: "Unknown schematic \"{schematic}\"\nKnown schematics: {known}" @@ -220,6 +223,9 @@ command-pastestates-description: "Paste all known block states" command-pastestates-usage: "//pastestates" command-wand-description: "Get a wooden axe" command-wand-usage: "//wand" +command-iteminfo-description: "Get information about the item in your hand" +command-iteminfo-usage: "//iteminfo" + command-thru-description: "Teleport through blocks" command-thru-usage: "//thru" diff --git a/resources/lang/idn.yml b/resources/lang/idn.yml index e1955cc1..b1a818cf 100644 --- a/resources/lang/idn.yml +++ b/resources/lang/idn.yml @@ -70,6 +70,9 @@ benchmark-result: "#{task}: {name} - {blocks} dalam {time} detik" #Args: {state} {id} {meta} {name} {x} {y} {z} {java_state} block-info: "{name} ({id}:{meta}) at {x} {y} {z}\nBlock state: {state}\nJava state: {java_state}" +#Args: {count} {name} {id} {meta} {nbt} {java_nbt} +item-info: "{count}x {name}§r ({id}:{meta})\nItem data: {nbt}\nJava data: {java_nbt}" + #Args: {schematic} {known} unknown-schematic: "Unknown schematic \"{schematic}\"\nKnown schematics: {known}" @@ -220,6 +223,9 @@ command-pastestates-description: "Rekatkan semua status blok yang diketahui" command-pastestates-usage: "//pastestates" command-wand-description: "Dapatkan wooden axe" command-wand-usage: "//wand" +command-iteminfo-description: "Get information about the item in your hand" +command-iteminfo-usage: "//iteminfo" + command-thru-description: "Teleportasi melalui blok" command-thru-usage: "//thru" diff --git a/resources/lang/jpn.yml b/resources/lang/jpn.yml index 4ecda89d..f42f2e46 100644 --- a/resources/lang/jpn.yml +++ b/resources/lang/jpn.yml @@ -70,6 +70,9 @@ benchmark-result: "#{task}: {name} - {blocks} を {time} 秒で処理" #Args: {state} {id} {meta} {name} {x} {y} {z} {java_state} block-info: "{name} ({id}:{meta}) {x} {y} {z}\nブロックステート: {state}\nJava state: {java_state}" +#Args: {count} {name} {id} {meta} {nbt} {java_nbt} +item-info: "{count}x {name}§r ({id}:{meta})\nItem data: {nbt}\nJava data: {java_nbt}" + #Args: {schematic} {known} unknown-schematic: "不明なschematic: \"{schematic}\"\n既知のschematic: {known}" @@ -220,6 +223,9 @@ command-pastestates-description: "全ての既知のブロックステートを command-pastestates-usage: "//pastestates" command-wand-description: "領域指定用の木の斧を手に入れる" command-wand-usage: "//wand" +command-iteminfo-description: "Get information about the item in your hand" +command-iteminfo-usage: "//iteminfo" + command-thru-description: "Teleport through blocks" command-thru-usage: "//thru" diff --git a/resources/lang/rus.yml b/resources/lang/rus.yml index 123652f8..e7e16395 100644 --- a/resources/lang/rus.yml +++ b/resources/lang/rus.yml @@ -70,6 +70,9 @@ benchmark-result: "#{task}: {name} - {blocks} за {time}сек." #Args: {state} {id} {meta} {name} {x} {y} {z} {java_state} block-info: "{name} ({id}:{meta}) на позиции {x} {y} {z}\nСостояние блока: {state}\nJava-состояние: {java_state}" +#Args: {count} {name} {id} {meta} {nbt} {java_nbt} +item-info: "{count}x {name}§r ({id}:{meta})\nItem data: {nbt}\nJava data: {java_nbt}" + #Args: {schematic} {known} unknown-schematic: "Неизвестная схема \"{schematic}\"\nИзвестные схемы: {known}" @@ -218,10 +221,13 @@ command-pastestates-description: "Вставить все известные с command-pastestates-usage: "//pastestates" command-wand-description: "Получить деревянную топорище" command-wand-usage: "//wand" +command-iteminfo-description: "Get information about the item in your hand" +command-iteminfo-usage: "//iteminfo" + command-thru-description: "Телепортироваться сквозь блоки" command-thru-usage: "//thru" command-unstuck-description: "Телепортироваться в безопасное место" command-unstuck-usage: "//unstuck" command-up-description: "Телепортироваться вверх" -command-up-usage: "//up <количество>" +command-up-usage: "//up <количество>" \ No newline at end of file diff --git a/resources/lang/spa.yml b/resources/lang/spa.yml index f1d30281..c830eff7 100644 --- a/resources/lang/spa.yml +++ b/resources/lang/spa.yml @@ -70,6 +70,9 @@ benchmark-result: "#{task}: {name} - {blocks} en {time}s" #Args: {state} {id} {meta} {name} {x} {y} {z} {java_state} block-info: "{name} ({id}:{meta}) a {x} {y} {z}\nEstado del bloque: {state}\nEstado Java: {java_state}" +#Args: {count} {name} {id} {meta} {nbt} {java_nbt} +item-info: "{count}x {name}§r ({id}:{meta})\nItem data: {nbt}\nJava data: {java_nbt}" + #Args: {schematic} {known} unknown-schematic: "Schematic desconocido \"{schematic}\"\nSchematics conocidos: {known}" @@ -220,10 +223,13 @@ command-pastestates-description: "Pegar todos los estados de bloque conocidos" command-pastestates-usage: "//pastestates" command-wand-description: "Consigue un hacha de madera" command-wand-usage: "//wand" +command-iteminfo-description: "Get information about the item in your hand" +command-iteminfo-usage: "//iteminfo" + command-thru-description: "Teletransportarse a través de bloques" command-thru-usage: "//thru" command-unstuck-description: "Teletransportarse a un lugar seguro" command-unstuck-usage: "//unstuck" command-up-description: "Teletransporte arriba" -command-up-usage: "//up " +command-up-usage: "//up " \ No newline at end of file diff --git a/resources/lang/vie.yml b/resources/lang/vie.yml index 526296da..614c36a3 100644 --- a/resources/lang/vie.yml +++ b/resources/lang/vie.yml @@ -70,6 +70,9 @@ benchmark-result: "#{task}: {name} - {blocks} trong {time}s" #Args: {state} {id} {meta} {name} {x} {y} {z} {java_state} block-info: "{name} ({id}:{meta}) tại {x} {y} {z}\nTrạng thái khối: {state}\nJava state: {java_state}" +#Args: {count} {name} {id} {meta} {nbt} {java_nbt} +item-info: "{count}x {name}§r ({id}:{meta})\nItem data: {nbt}\nJava data: {java_nbt}" + #Args: {schematic} {known} unknown-schematic: "Sơ đồ không xác định \"{schematic}\"\nCác sơ đồ đã biết: {known}" @@ -220,6 +223,9 @@ command-pastestates-description: "Dán tất cả các trạng thái khối đã command-pastestates-usage: "//pastestates" command-wand-description: "Nhận một cái rìu gỗ" command-wand-usage: "//wand" +command-iteminfo-description: "Get information about the item in your hand" +command-iteminfo-usage: "//iteminfo" + command-thru-description: "Teleport through blocks" command-thru-usage: "//thru" diff --git a/resources/messages.yml b/resources/messages.yml index a95108ec..d4123975 100644 --- a/resources/messages.yml +++ b/resources/messages.yml @@ -74,6 +74,9 @@ block-info: "{name} ({id}:{meta}) at {x} {y} {z}\nBlock state: {state}\nJava sta #Args: {schematic} {known} unknown-schematic: "Unknown schematic \"{schematic}\"\nKnown schematics: {known}" +#Args: {count} {name} {id} {meta} {nbt} {java_nbt} +item-info: "{count}x {name}§r ({id}:{meta})\nItem data: {nbt}\nJava data: {java_nbt}" + #Commands #Note: If command usages contains a short description, it should be spilt with a "-" (e.g. "help - Show this help") @@ -221,6 +224,9 @@ command-pastestates-description: "Paste all known block states" command-pastestates-usage: "//pastestates" command-wand-description: "Get a wooden axe" command-wand-usage: "//wand" +command-iteminfo-description: "Get information about the item in your hand" +command-iteminfo-usage: "//iteminfo" + command-thru-description: "Teleport through blocks" command-thru-usage: "//thru" diff --git a/src/platz1de/EasyEdit/EasyEdit.php b/src/platz1de/EasyEdit/EasyEdit.php index 61989463..99d344a4 100644 --- a/src/platz1de/EasyEdit/EasyEdit.php +++ b/src/platz1de/EasyEdit/EasyEdit.php @@ -39,6 +39,7 @@ use platz1de\EasyEdit\command\defaults\utility\DrainCommand; use platz1de\EasyEdit\command\defaults\utility\FillCommand; use platz1de\EasyEdit\command\defaults\utility\HelpCommand; +use platz1de\EasyEdit\command\defaults\utility\ItemInfoCommand; use platz1de\EasyEdit\command\defaults\utility\LineCommand; use platz1de\EasyEdit\command\defaults\utility\PasteStatesCommand; use platz1de\EasyEdit\command\defaults\utility\StatusCommand; @@ -144,6 +145,7 @@ public function onEnable(): void new BenchmarkCommand(), new PasteStatesCommand(), new WandCommand(), + new ItemInfoCommand(), // Movement new ThruCommand(), diff --git a/src/platz1de/EasyEdit/command/defaults/utility/ItemInfoCommand.php b/src/platz1de/EasyEdit/command/defaults/utility/ItemInfoCommand.php new file mode 100644 index 00000000..dfc98168 --- /dev/null +++ b/src/platz1de/EasyEdit/command/defaults/utility/ItemInfoCommand.php @@ -0,0 +1,50 @@ +asPlayer()->getInventory()->getItemInHand(); + $session->sendMessage("item-info", ItemInfoUtil::createItemInfo($itemInHand)); + } + + /** + * @param Session $session + * @return CommandFlag[] + */ + public function getKnownFlags(Session $session): array + { + return []; + } + + /** + * @param CommandFlagCollection $flags + * @param Session $session + * @param string[] $args + * @return Generator + */ + public function parseArguments(CommandFlagCollection $flags, Session $session, array $args): Generator + { + yield from []; + } +} \ No newline at end of file diff --git a/src/platz1de/EasyEdit/convert/ItemConvertor.php b/src/platz1de/EasyEdit/convert/ItemConvertor.php index e139290d..d62c52d8 100644 --- a/src/platz1de/EasyEdit/convert/ItemConvertor.php +++ b/src/platz1de/EasyEdit/convert/ItemConvertor.php @@ -12,6 +12,7 @@ use platz1de\EasyEdit\utils\RepoManager; use pocketmine\data\bedrock\item\SavedItemData; use pocketmine\nbt\tag\CompoundTag; +use platz1de\EasyEdit\utils\MixedUtils; use Throwable; class ItemConvertor @@ -28,6 +29,11 @@ class ItemConvertor * @var ItemConvertorPiece[] */ private static array $convertors = []; + /** + * @internal cache before being passed to the main thread + * @var string + */ + public static string $rawConversionMap = "{}"; public static function load(): void { @@ -36,11 +42,13 @@ public static function load(): void * @var string $java * @var array{name: string, damage: string|int} $bedrock */ - foreach (RepoManager::getJson("item-conversion-map", 3) as $java => $bedrock) { + foreach ($conversionMap = RepoManager::getJson("item-conversion-map", 3) as $java => $bedrock) { self::$itemTranslationBedrock[$java] = [$bedrock["name"], (int) $bedrock["damage"]]; self::$itemTranslationJava[$bedrock["name"]][(int) $bedrock["damage"]] = $java; } + self::$rawConversionMap = json_encode($conversionMap, JSON_THROW_ON_ERROR); + /** * TODO: Add more convertors * Bucket of Aquatic Mob @@ -143,4 +151,19 @@ public static function convertItemJava(CompoundTag $item): ?CompoundTag } return $item; } + + public static function loadResourceData(string $rawConversionMap): void + { + try { + $conversionMap = MixedUtils::decodeJson($rawConversionMap, 3); + } catch (Throwable $e) { + EditThread::getInstance()->getLogger()->error("Failed to parse conversion data, Item conversion is not available"); + EditThread::getInstance()->getLogger()->debug($e->getMessage()); + return; + } + foreach ($conversionMap as $java => $bedrock) { + self::$itemTranslationBedrock[$java] = [$bedrock["name"], (int) $bedrock["damage"]]; + self::$itemTranslationJava[$bedrock["name"]][(int) $bedrock["damage"]] = $java; + } + } } \ No newline at end of file diff --git a/src/platz1de/EasyEdit/thread/output/ResourceData.php b/src/platz1de/EasyEdit/thread/output/ResourceData.php index c81dd8c1..cd9f7638 100644 --- a/src/platz1de/EasyEdit/thread/output/ResourceData.php +++ b/src/platz1de/EasyEdit/thread/output/ResourceData.php @@ -5,6 +5,7 @@ use platz1de\EasyEdit\convert\BedrockStatePreprocessor; use platz1de\EasyEdit\convert\BlockStateConvertor; use platz1de\EasyEdit\convert\BlockTagManager; +use platz1de\EasyEdit\convert\ItemConvertor; use platz1de\EasyEdit\convert\TileConvertor; use platz1de\EasyEdit\utils\ConfigManager; use platz1de\EasyEdit\utils\ExtendedBinaryStream; @@ -23,6 +24,7 @@ public function putData(ExtendedBinaryStream $stream): void $stream->putString($this->rawBTJ); $stream->putString(BedrockStatePreprocessor::$rawData); $stream->putString(BlockTagManager::$rawData); + $stream->putString(ItemConvertor::$rawConversionMap); $stream->putLong(RepoManager::getVersion()); BedrockStatePreprocessor::$rawData = ""; BlockTagManager::$rawData = ""; @@ -33,6 +35,7 @@ public function parseData(ExtendedBinaryStream $stream): void BlockStateConvertor::loadResourceData($stream->getString(), $stream->getString()); BedrockStatePreprocessor::loadResourceData($stream->getString()); BlockTagManager::loadResourceData($stream->getString()); + ItemConvertor::loadResourceData($stream->getString()); TileConvertor::load($stream->getLong()); HeightMapCache::loadIgnore(ConfigManager::getTerrainIgnored()); } diff --git a/src/platz1de/EasyEdit/utils/ConfigManager.php b/src/platz1de/EasyEdit/utils/ConfigManager.php index ae804b92..32f2b7bc 100644 --- a/src/platz1de/EasyEdit/utils/ConfigManager.php +++ b/src/platz1de/EasyEdit/utils/ConfigManager.php @@ -251,9 +251,9 @@ public static function distributeData(): void LegacyBlockIdConvertor::load(); BedrockStatePreprocessor::load(); BlockTagManager::load(); + ItemConvertor::load(); BlockStateConvertor::load(); BlockRotationManipulator::load(); - ItemConvertor::load(); TileConvertor::load(RepoManager::getVersion()); HeightMapCache::loadIgnore(self::$terrainIgnored); } diff --git a/src/platz1de/EasyEdit/utils/ItemInfoUtil.php b/src/platz1de/EasyEdit/utils/ItemInfoUtil.php new file mode 100644 index 00000000..4b5375e0 --- /dev/null +++ b/src/platz1de/EasyEdit/utils/ItemInfoUtil.php @@ -0,0 +1,66 @@ +getValue() as $name => $tag) { + if ($tag instanceof CompoundTag || $tag instanceof ListTag) { + $value = self::convertNbtToPrettyString($tag); + } else { + $tagAsString = $tag->toString(); + $value = substr($tagAsString, strpos($tagAsString, "=") + 1); + } + + $valueColor = TextFormat::RESET; + if ($tag instanceof StringTag) { + $valueColor = TextFormat::GREEN; + } else if (!($tag instanceof IntArrayTag || $tag instanceof ByteArrayTag) + && $tag instanceof ImmutableTag) { + $valueColor = TextFormat::GOLD; + } + + $hasNextTagChar = ($idx < count($nbt->getValue()) - 1) ? ", " : ""; + $lhs = $isCompoundTag ? TextFormat::AQUA . $name . TextFormat::RESET . ": " : ""; + $stringified .= $lhs . $valueColor . $value . TextFormat::RESET . $hasNextTagChar; + + $idx++; + } + + $closingChar = $isCompoundTag ? "}" : "]"; + return $stringified . $closingChar; + } + + public static function createItemInfo(Item $item): array + { + $itemData = GlobalItemDataHandlers::getSerializer()->serializeType($item); + $javaNbt = ItemConvertor::convertItemJava($itemData->toNbt()); + return [ + "{name}" => $item->getName(), + "{id}" => $itemData->getName(), + "{count}" => $item->getCount(), + "{meta}" => $itemData->getMeta(), + "{nbt}" => self::convertNbtToPrettyString($itemData->toNbt()), + "{java_nbt}" => $javaNbt === null ? "-" : self::convertNbtToPrettyString($javaNbt) + ]; + } +} \ No newline at end of file