### Example NBT Configuration for 'powered' property Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/specification_documentation.md An example of an NBT configuration for a 'powered' byte property, specifying its name, type, options, and default value. ```json { "properties": {}, "defaults": {}, "nbt": { "powered": { "name": "powered", "type": "byte", "options": ["0", "1"], "default": "0" } } } ``` -------------------------------- ### Translate Blocks to Universal Format Source: https://context7.com/amulet-team/pymctranslate/llms.txt Demonstrates converting version-specific blocks to the Universal format and querying block namespaces and base names. ```python import PyMCTranslate from PyMCTranslate.py3.api import Block from amulet_nbt import StringTag translation_manager = PyMCTranslate.new_translation_manager() java_1_20 = translation_manager.get_version("java", (1, 20, 4)) # Create a block to translate oak_log = Block.from_string_blockstate("minecraft:oak_log[axis=y]") # Translate to Universal format universal_block, block_entity, extra_needed = java_1_20.block.to_universal( oak_log, force_blockstate=True # Use blockstate format (required for Java 1.13+) ) print(universal_block) # universal_minecraft:oak_log[axis="y"] print(block_entity) # None (no block entity for simple blocks) print(extra_needed) # False (no additional data needed) # Translate a block with multiple states redstone_wire = Block.from_string_blockstate("minecraft:redstone_wire[east=side,north=none,power=0,south=none,west=up]") universal_redstone, _, _ = java_1_20.block.to_universal(redstone_wire, force_blockstate=True) print(universal_redstone) # universal_minecraft:redstone_wire[...] # List available namespaces and blocks for a version namespaces = java_1_20.block.namespaces(force_blockstate=True) print(namespaces) # ['minecraft'] base_names = java_1_20.block.base_names("minecraft", force_blockstate=True) print(len(base_names)) # Number of blocks (varies by version) print(base_names[:5]) # ['acacia_button', 'acacia_door', 'acacia_fence', ...] ``` -------------------------------- ### Initialize TranslationManager Source: https://context7.com/amulet-team/pymctranslate/llms.txt Create a new translation manager instance to access platform and version information. ```python import PyMCTranslate # Create a new translation manager with default files # Each unique world should have its own TranslationManager translation_manager = PyMCTranslate.new_translation_manager() # List all available platforms platforms = translation_manager.platforms() print(platforms) # ['java', 'bedrock', 'universal'] # List all version numbers for a platform java_versions = translation_manager.version_numbers("java") print(java_versions) # [(1, 12, 2), (1, 13, 0), ..., (1, 21, 9)] bedrock_versions = translation_manager.version_numbers("bedrock") print(bedrock_versions) # [(1, 1, 0), (1, 2, 0), ..., (1, 21, 90)] # Access the universal format directly universal = translation_manager.universal_format print(universal) # PyMCTranslate.Version(universal, (1, 0, 0)) ``` -------------------------------- ### Retrieve Version Instances Source: https://context7.com/amulet-team/pymctranslate/llms.txt Access specific game version data using version tuples or DataVersion integers. ```python import PyMCTranslate translation_manager = PyMCTranslate.new_translation_manager() # Get a specific version by version number tuple java_1_20 = translation_manager.get_version("java", (1, 20, 4)) print(java_1_20) # PyMCTranslate.Version(java, (1, 20, 4)) # Get version by DataVersion (integer) - useful when reading world files java_by_data_version = translation_manager.get_version("java", 3700) print(java_by_data_version) # Will find the closest matching version # Get a Bedrock version bedrock_1_20 = translation_manager.get_version("bedrock", (1, 20, 50)) print(bedrock_1_20.platform) # 'bedrock' print(bedrock_1_20.version_number) # (1, 20, 50) print(bedrock_1_20.data_version) # Integer DataVersion for this version print(bedrock_1_20.block_format) # 'nbt-blockstate' for modern Bedrock # Check if version has abstract format (numerical blocks) print(bedrock_1_20.has_abstract_format) # True for older versions ``` -------------------------------- ### Create and Translate Entity with NBT Data Source: https://context7.com/amulet-team/pymctranslate/llms.txt Demonstrates creating an entity with custom NBT data and translating it between Minecraft versions using the TranslationManager. Ensure the necessary version is obtained from the translation manager. ```python from PyMCTranslate.py3.api import Entity, NamedTag, TAG_Compound, TAG_String, TAG_List, TAG_Float creeper_nbt = TAG_Compound({ "id": TAG_String("minecraft:creeper"), "Pos": TAG_List([TAG_Float(100.5), TAG_Float(64.0), TAG_Float(200.5)]), "Health": TAG_Float(20.0), }) creeper = Entity( "minecraft", "creeper", x=100.5, y=64.0, z=200.5, nbt=NamedTag(creeper_nbt, "") ) # Assuming java_1_20 and translation_manager are initialized elsewhere # universal_entity = java_1_20.entity.to_universal(creeper, force_blockstate=True) # print(universal_entity.namespace) # 'universal_minecraft' # print(universal_entity.base_name) # 'creeper' # bedrock_1_20 = translation_manager.get_version("bedrock", (1, 20, 50)) # result, extra = bedrock_1_20.entity.from_universal(universal_entity, force_blockstate=True) # if isinstance(result, Entity): # print(f"Entity: {result.namespace}:{result.base_name}") # else: # print(f"Block: {result}") # entity_spec = java_1_20.entity.get_specification("minecraft", "creeper") # print(entity_spec.nbt_identifier) # Entity NBT identifier # print(entity_spec.default_nbt) # Default NBT structure ``` -------------------------------- ### Properties and Defaults in Block Specification Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/specification_documentation.md Defines how to specify block properties and their default values. All options must be strings. ```json { "properties": { "bites": [ "0", "1", "2", "3", "4", "5", "6" ] }, "defaults": { "bites": "0" }, "nbt": {} } ``` -------------------------------- ### Initialize Entity Translator Source: https://context7.com/amulet-team/pymctranslate/llms.txt Initializes the translation manager for entity data conversion. ```python import PyMCTranslate from PyMCTranslate.py3.api import Entity from amulet_nbt import NamedTag, TAG_Compound, TAG_String, TAG_List, TAG_Float translation_manager = PyMCTranslate.new_translation_manager() java_1_20 = translation_manager.get_version("java", (1, 20, 4)) ``` -------------------------------- ### Rotate and Transform Universal Format Blocks Source: https://context7.com/amulet-team/pymctranslate/llms.txt Demonstrates how to rotate and transform blocks that are in the universal format using PyMCTranslate's rotation utilities. This requires converting the block to universal format first. ```python import PyMCTranslate from PyMCTranslate.py3.api import Block from PyMCTranslate.py3.api.rotate import RotateMode from amulet_nbt import StringTag import numpy as np translation_manager = PyMCTranslate.new_translation_manager() java_1_20 = translation_manager.get_version("java", (1, 20, 4)) # Create a directional block stairs = Block.from_string_blockstate("minecraft:oak_stairs[facing=north,half=bottom,shape=straight]") # Convert to universal format first universal_stairs, _, _ = java_1_20.block.to_universal(stairs, force_blockstate=True) # Example of rotation (actual rotation logic would follow here) # rotated_universal_stairs = universal_stairs.rotate(RotateMode.ROTATE_90, (0, 0, 0)) # print(rotated_universal_stairs) ``` -------------------------------- ### Add New Properties Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md The `new_properties` key allows you to add specific properties with their values to the output blockstate. ```json "new_properties": { "": "", "": "" } ``` -------------------------------- ### NBT Configuration in Block Specification Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/specification_documentation.md Details the structure for configuring NBT data, including path, name, type, default value, and options. ```json { "properties": {}, "defaults": {}, "nbt": { "": { "path": [ ["", ""], ["", ""] ], "name": "", "type": "", "default": "", "options": [ "", "" ] } } } ``` -------------------------------- ### Define New Block Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md Use `new_block` to specify the target block namespace and name. This overwrites the output block but does not affect separately added properties or NBT. ```json "new_block": ":" ``` -------------------------------- ### Construct and Manipulate Block Objects Source: https://context7.com/amulet-team/pymctranslate/llms.txt Create and modify block states, including support for NBT properties and waterlogging. ```python from PyMCTranslate.py3.api import Block from amulet_nbt import StringTag, IntTag, ByteTag # Create a simple block stone = Block("minecraft", "stone") print(stone.blockstate) # 'minecraft:stone' # Create a block with properties water = Block( "minecraft", "water", {"level": StringTag("0")} ) print(water.blockstate) # 'minecraft:water[level=0]' # Parse from Java blockstate string oak_stairs = Block.from_string_blockstate("minecraft:oak_stairs[facing=north,half=bottom,shape=straight,waterlogged=false]") print(oak_stairs.namespace) # 'minecraft' print(oak_stairs.base_name) # 'oak_stairs' print(oak_stairs.properties) # {'facing': StringTag("north"), 'half': StringTag("bottom"), ...} # Create a Bedrock-style block with NBT property types bell = Block("minecraft", "bell", { "attachment": StringTag("standing"), "direction": IntTag(0), "toggle_bit": ByteTag(0) }) print(bell.snbt_blockstate) # 'minecraft:bell[attachment="standing",direction=0,toggle_bit=0b]' # Create waterlogged blocks using extra_blocks waterlogged_stone = Block( "minecraft", "stone", extra_blocks=Block("minecraft", "water", {"level": StringTag("0")}) ) print(waterlogged_stone.full_blockstate) # 'minecraft:stone{minecraft:water[level="0"]}' # Combine blocks with + operator combined = stone + water print(repr(combined)) # 'Block(minecraft:stone, extra_blocks=(minecraft:water[level="0"]))' # Access block components print(combined.base_block) # Block(minecraft:stone) print(combined.extra_blocks) # (Block(minecraft:water[level="0"]),) print(combined.block_tuple) # (Block(minecraft:stone), Block(minecraft:water[level="0"])) ``` -------------------------------- ### Advanced Block Translation with Callbacks Source: https://context7.com/amulet-team/pymctranslate/llms.txt Translates blocks using a callback function to provide context from neighboring blocks, essential for multiblock structures like double chests. Requires importing necessary classes and setting up a translation manager. ```python import PyMCTranslate from PyMCTranslate.py3.api import Block, BlockEntity from amulet_nbt import NamedTag, TAG_Compound, TAG_String, TAG_Int, TAG_List from typing import Tuple, Optional translation_manager = PyMCTranslate.new_translation_manager() java_1_20 = translation_manager.get_version("java", (1, 20, 4)) # Define a world data callback for multiblock operations def get_block_at_location( relative_coords: Tuple[int, int, int] ) -> Tuple[Block, Optional[BlockEntity]]: """ Callback function to retrieve block data at relative coordinates. This would typically query your world data structure. """ x, y, z = relative_coords # Example: return air for any position return Block("minecraft", "air"), None # Create a chest block (which may need neighbor info for double chests) chest = Block.from_string_blockstate("minecraft:chest[facing=north,type=single,waterlogged=false]") # Create chest block entity chest_nbt = TAG_Compound({ "id": TAG_String("minecraft:chest"), "x": TAG_Int(0), "y": TAG_Int(64), "z": TAG_Int(0), "Items": TAG_List([]), }) chest_entity = BlockEntity( "minecraft", "chest", x=0, y=64, z=0, nbt=NamedTag(chest_nbt, "") ) # Translate with block location and callback universal_chest, universal_entity, extra_needed = java_1_20.block.to_universal( chest, block_entity=chest_entity, force_blockstate=True, block_location=(0, 64, 0), # World coordinates get_block_callback=get_block_at_location # Callback for neighbor data ) print(f"Block: {universal_chest}") print(f"Entity: {universal_entity}") print(f"Extra data needed: {extra_needed}") # True if translation requires more context ``` -------------------------------- ### Basic Block Specification Structure Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/specification_documentation.md The fundamental structure for a block specification JSON file, including properties, defaults, and NBT sections. ```json { "properties": {}, "defaults": {}, "nbt": {} } ``` -------------------------------- ### Translate Biome Identifiers Between Versions Source: https://context7.com/amulet-team/pymctranslate/llms.txt Shows how to convert biome identifiers between specific Minecraft versions and a universal format using the BiomeTranslator. Ensure the translation manager and version objects are properly initialized. ```python import PyMCTranslate translation_manager = PyMCTranslate.new_translation_manager() java_1_20 = translation_manager.get_version("java", (1, 20, 4)) bedrock_1_20 = translation_manager.get_version("bedrock", (1, 20, 50)) # Get list of biome IDs for a version biome_ids = java_1_20.biome.biome_ids print(biome_ids[:5]) # ['minecraft:badlands', 'minecraft:bamboo_jungle', ...] # Convert biome string to universal format version_biome = "minecraft:plains" universal_biome = java_1_20.biome.to_universal(version_biome) print(universal_biome) # 'universal_minecraft:plains' # Convert from universal back to version format back_to_version = java_1_20.biome.from_universal(universal_biome) print(back_to_version) # 'minecraft:plains' # Cross-platform biome translation java_biome = "minecraft:dark_forest" universal = java_1_20.biome.to_universal(java_biome) bedrock_biome = bedrock_1_20.biome.from_universal(universal) print(f"Java: {java_biome} -> Bedrock: {bedrock_biome}") # Pack/unpack numerical biome IDs (for chunk data) biome_int = java_1_20.biome.pack("minecraft:plains") print(biome_int) # Numerical ID biome_str = java_1_20.biome.unpack(biome_int) print(biome_str) # 'minecraft:plains' # Universal format biomes universal_biomes = translation_manager.universal_format.biome.biome_ids print(universal_biomes[:3]) # ['universal_minecraft:badlands', ...] ``` -------------------------------- ### Retrieve Block Specifications Source: https://context7.com/amulet-team/pymctranslate/llms.txt Accesses detailed block metadata, including default properties, valid property values, and waterloggable status. ```python import PyMCTranslate translation_manager = PyMCTranslate.new_translation_manager() java_1_20 = translation_manager.get_version("java", (1, 20, 4)) # Get block specification spec = java_1_20.block.get_specification("minecraft", "oak_stairs", force_blockstate=True) # Access default properties print(spec.default_properties) # {'facing': StringTag("north"), 'half': StringTag("bottom"), # 'shape': StringTag("straight"), 'waterlogged': StringTag("false")} # Access all valid property values print(spec.valid_properties) # {'facing': (StringTag("north"), StringTag("south"), StringTag("west"), StringTag("east")), # 'half': (StringTag("top"), StringTag("bottom")), # 'shape': (StringTag("straight"), StringTag("inner_left"), ...), # 'waterlogged': (StringTag("true"), StringTag("false"))} # Check for block entity info chest_spec = java_1_20.block.get_specification("minecraft", "chest", force_blockstate=True) print(chest_spec.nbt_identifier) # ('minecraft', 'chest') print(chest_spec.default_nbt) # Default NBT compound for chest block entity # Check if a block can be waterlogged (Java only) print(java_1_20.block.is_waterloggable("minecraft:oak_stairs")) # True print(java_1_20.block.is_waterloggable("minecraft:stone")) # False print(java_1_20.block.is_waterloggable("minecraft:seagrass", always=True)) # True (always waterlogged) ``` -------------------------------- ### Registering Custom Blocks and Biomes Source: https://context7.com/amulet-team/pymctranslate/llms.txt Registers custom block and biome mappings for modded worlds, allowing PyMCTranslate to recognize custom IDs. This involves using the biome_registry and block_registry objects of the translation manager. ```python import PyMCTranslate translation_manager = PyMCTranslate.new_translation_manager() # Register custom biome mappings # Maps numerical ID to string identifier translation_manager.biome_registry.register( private=1000, # Custom numerical ID string="mymod:custom_biome" # Namespaced string ID ) # Register custom block mappings translation_manager.block_registry.register( private=5000, # Custom numerical ID string="mymod:custom_block" # Namespaced string ID ) # Now translations will recognize these custom entries java_1_12 = translation_manager.get_version("java", (1, 12, 2)) # Unpack custom biome biome_str = java_1_12.biome.unpack(1000) print(biome_str) # 'mymod:custom_biome' # Check registry contents print(1000 in translation_manager.biome_registry) # True print("mymod:custom_biome" in translation_manager.biome_registry) # True ``` -------------------------------- ### Multiblock Mapping (Multiple) Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md Allows multiple `multiblock` mappings to be applied to the same input block, processing different relative coordinates and applying distinct functions for each. ```json "multiblock": [ { "coords": [dx, dy, dz], => }, { "coords": [dx, dy, dz], => } ] ``` -------------------------------- ### Block Mapping JSON Structure Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md This is the base structure for a block mapping JSON file. It includes all possible keys for defining conversions. ```json { "new_block": ":", "new_properties": {}, "map_properties": {}, "carry_properties": {}, "new_nbt": {}, "map_nbt": {}, "multiblock": {}, "map_block_name": {} } ``` -------------------------------- ### Translate Blocks from Universal Format Source: https://context7.com/amulet-team/pymctranslate/llms.txt Converts blocks from the Universal format to specific version formats, including cross-version translation workflows. ```python import PyMCTranslate from PyMCTranslate.py3.api import Block from amulet_nbt import StringTag translation_manager = PyMCTranslate.new_translation_manager() java_1_20 = translation_manager.get_version("java", (1, 20, 4)) bedrock_1_20 = translation_manager.get_version("bedrock", (1, 20, 50)) # Start with a universal block universal_oak_log = Block( "universal_minecraft", "oak_log", {"axis": StringTag("y")} ) # Convert to Java format java_block, java_entity, extra_needed = java_1_20.block.from_universal( universal_oak_log, force_blockstate=True ) print(java_block) # minecraft:oak_log[axis=y] # Convert the same universal block to Bedrock format bedrock_block, bedrock_entity, extra_needed = bedrock_1_20.block.from_universal( universal_oak_log, force_blockstate=True # Use blockstate even on Bedrock ) print(bedrock_block) # minecraft:log[pillar_axis="y"] # Cross-version translation workflow # Step 1: Java 1.20 -> Universal # Step 2: Universal -> Bedrock 1.20 java_block = Block.from_string_blockstate("minecraft:grass_block[snowy=false]") universal, _, _ = java_1_20.block.to_universal(java_block, force_blockstate=True) bedrock_result, _, _ = bedrock_1_20.block.from_universal(universal, force_blockstate=True) print(f"Java: {java_block} -> Bedrock: {bedrock_result}") ``` -------------------------------- ### Multiblock Mapping (Single) Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md The `multiblock` function processes a block relative to the input block's coordinates. It loads the blockstate at the specified `coords` and applies further functions. ```json "multiblock": { "coords": [dx, dy, dz], => } ``` -------------------------------- ### Convert Numerical Block IDs to Block Objects Source: https://context7.com/amulet-team/pymctranslate/llms.txt Illustrates converting numerical block IDs and data values to Block objects for older Minecraft versions. This is useful when working with chunk data from versions that do not use string-based block identifiers. Ensure the correct version with numerical block format is loaded. ```python import PyMCTranslate from PyMCTranslate.py3.api import Block from amulet_nbt import TAG_Int translation_manager = PyMCTranslate.new_translation_manager() # Get an older version with numerical block format java_1_12 = translation_manager.get_version("java", (1, 12, 2)) print(java_1_12.block_format) # 'numerical' print(java_1_12.has_abstract_format) # True # Convert numerical IDs to Block object # Stone has ID 1, data 0 stone_block = java_1_12.block.ints_to_block(block_id=1, block_data=0) print(stone_block) # minecraft:stone[block_data=0] # Granite has ID 1, data 1 granite_block = java_1_12.block.ints_to_block(block_id=1, block_data=1) print(granite_block) # minecraft:stone[block_data=1] # Convert Block back to numerical IDs block_id, block_data = java_1_12.block.block_to_ints(stone_block) print(f"ID: {block_id}, Data: {block_data}") # ID: 1, Data: 0 # Full translation workflow for numerical versions # Numerical -> Universal -> Modern Java numerical_block = java_1_12.block.ints_to_block(1, 1) # Granite universal, _, _ = java_1_12.block.to_universal(numerical_block) print(universal) # universal_minecraft:granite java_1_20 = translation_manager.get_version("java", (1, 20, 4)) modern_block, _, _ = java_1_20.block.from_universal(universal, force_blockstate=True) print(modern_block) # minecraft:granite ``` -------------------------------- ### Add New NBT Data Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md Similar to `new_properties`, `new_nbt` is used to add specific NBT tags with their values to the output block. ```json "new_nbt": { "": "", "": "" } ``` -------------------------------- ### Map Properties Based on Value Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md Use `map_properties` to apply specific functions or transformations based on the input blockstate's property values. Nested functions are supported. ```json "map_properties": { "": { "val1": { => }, "val2": { => } } } ``` -------------------------------- ### Carry Over Properties Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md The `carry_properties` function allows specific property values to be carried over from the input blockstate to the output blockstate. ```json "carry_properties": { "": ["val1", "val2", ...], "": ["val1", "val2", ...] } ``` -------------------------------- ### Apply Rotation Transformation to Blocks Source: https://context7.com/amulet-team/pymctranslate/llms.txt Applies a rotation matrix to a universal block representation. Ensure the rotation matrix is correctly defined and the universal block data is available. The mode parameter controls the rotation interpolation. ```python import numpy as np from PyMCTranslate.py3.api import RotateMode # Create a rotation transformation matrix (90 degrees around Y axis) rotation_matrix = np.array([ [0, 0, 1, 0], [0, 1, 0, 0], [-1, 0, 0, 0], [0, 0, 0, 1] ], dtype=np.float64) # Apply rotation to the universal block rotated_universal = translation_manager.transform_universal_block( universal_stairs, rotation_matrix, mode=RotateMode.Nearest # Use nearest valid rotation ) # Convert back to version format rotated_java, _, _ = java_1_20.block.from_universal(rotated_universal, force_blockstate=True) print(f"Original: {stairs.blockstate}") print(f"Rotated: {rotated_java.blockstate}") ``` -------------------------------- ### Map Block Name Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md Similar to `map_properties` and `map_nbt`, `map_block_name` allows functions to be applied based on the input block's namespaced name. ```json "map_block_name": { ":": { => }, ":": { => } } ``` -------------------------------- ### Map NBT Data Based on Value Source: https://github.com/amulet-team/pymctranslate/blob/main/docs/mappings_documentation.md The `map_nbt` function enables transformations on NBT tags based on their input values, supporting nested function calls. ```json "map_nbt": { "": { "val1": { => }, "val2": { => } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.