### Example autorun command Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md This example shows how to use the `autorun[*]` configuration to execute a command upon entering any world. It prints a welcome message including the world's name. ```text autorun[*]=eval 'echo(f"Hello, {world_info().name}!")' ``` -------------------------------- ### Pyjinn JavaClass Type and Instance Examples Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Illustrates the behavior of `JavaClass` in Pyjinn, showing how to print `JavaClass` objects, get their Java metaclass, and instantiate Java objects. ```python print(JavaClass("java.lang.String")) # prints: JavaClass("java.lang.String") print(type("This is a string")) # prints: JavaClass("java.lang.String") print("This is a string".getClass()) # prints Class: class java.lang.String print(type(42)) # prints: JavaClass("java.lang.Integer") print(type(42).MAX_VALUE) # prints equivalent of `Integer.MAX_VALUE`: 2147483647 print(type(42)(99)) # prints equivalent of `new Integer(99)`: 99 print(type(Integer)) ``` -------------------------------- ### Example Client Mappings URL Source: https://github.com/maxuser0/minescript/blob/main/docs/mappings.md This example demonstrates the URL structure for downloading client-side mappings for a specific Minecraft version. Minescript uses this URL to fetch the `client.txt` file, which contains the mappings. ```json "client_mappings" which should have a "url" value like "https://piston-data.mojang.com/v1/objects/8d83af626cae1865deaf55fbf96934be4886fd45/client.txt". ``` -------------------------------- ### Example Minecraft Version Manifest Entry Source: https://github.com/maxuser0/minescript/blob/main/docs/mappings.md This JSON snippet shows an example entry from the Minecraft version manifest, highlighting the ID, type, and URL for a specific game version's package. This is used by Minescript to locate mapping files. ```json "versions": [{"id": "1.21.7", "type": "release", "url": "https://piston-meta.mojang.com/v1/packages/5d22e5893fd9c565b9a3039f1fc842aef2c4aefc/1.21.7.json", ...} ``` -------------------------------- ### JavaClass Usage Example Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Demonstrates how to load a Java class and access its methods using the `JavaClass` wrapper. ```APIDOC ## JavaClass Usage Example ### Description This example shows how to import a Java class and call one of its methods. ### Code ```python from minescript import echo from java import JavaClass Minecraft = JavaClass("net.minecraft.client.Minecraft") minecraft = Minecraft.getInstance() echo("fps:", minecraft.getFps()) ``` ``` -------------------------------- ### Create Empty BlockPacker Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Initializes a new, empty BlockPacker instance. Use this to start collecting blocks. ```python BlockPacker() ``` -------------------------------- ### Chained autorun commands Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Demonstrates how to specify multiple commands within a single `autorun[...]` configuration line, separated by semicolons. This example first displays world information and then lists the 10 nearest entities. ```text autorun[*]=eval "world_info()"; eval "[e.name for e in entities(sort='nearest', limit=10)]" ``` -------------------------------- ### Minescript Command for Default Output Example Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Executes the output_example.py script with default output behavior, where stdout appears as white text and stderr as yellow text, both visible only to the user. ```minecraft \output_example ``` -------------------------------- ### version_info Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets version information about Minescript and the game in the Minescript mod. ```APIDOC ## version_info ### Description Gets version information about Minescript and the game. ### Returns * **VersionInfo** - An object containing version details. ### Example ```python version = minescript.version_info() ``` ``` -------------------------------- ### Register Mouse Listener Example Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Registers a listener for mouse events within a context manager, ensuring automatic unregistration. It logs mouse button actions (up or down) and the button code. ```python with EventQueue() as event_queue: event_queue.register_mouse_listener() while True: event = event_queue.get() if event.type == EventType.MOUSE: echo(f"Got mouse {'up' if event.action == 0 else 'down'} of button {event.button}") ``` -------------------------------- ### Asynchronous Region Loading Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md This example shows how to use `await_loaded_region` asynchronously by calling `.as_async(...)`. This returns a future, allowing other operations to proceed while the chunks load in the background. ```python import minescript x, y, z = [int(p) for p in minescript.player().position] # .as_async(...) causes the script function to return a "future" value: future = minescript.await_loaded_region.as_async(x - 50, z - 50, x + 50, z + 50) # Do other work while the chunks are loading in the background... minescript.echo("Waiting for chunks around player to finish loading...") ``` -------------------------------- ### Synchronous Region Loading Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md This example demonstrates a synchronous call to `await_loaded_region`. The script execution will pause until the specified region of chunks has finished loading. ```python import minescript x, y, z = [int(p) for p in minescript.player().position] # Waits until all chunks from (x ± 50, z ± 50) are loaded: minescript.await_loaded_region(x - 50, z - 50, x + 50, z + 50) minescript.echo("Chunks around player finished loading.") ``` -------------------------------- ### Python Script Output Examples Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Demonstrates various methods for outputting messages from a Python script within Minescript, including plain text to chat (visible only to self), styled text via echo_json, and logging. ```python # Prints a plain-text message to the in-game chat that's # visible only to you (displayed as white text): print("Note to self...") ``` ```python # Same as the previous print(...) statement, except # that the output to stdout is explicit: print("Note to self...", file=sys.stdout) ``` ```python # Same output as the previous print(...) statements, # but using a Minescript function (behavior can be # different from above print(...) statements when # using "Script output redirection"; see below): import minescript minescript.echo("Note to self...") ``` ```python # Echo JSON-formatted text (for styled and colored text) # as a JSON string to the in-game chat only to yourself: minescript.echo_json('{"text":"hello!", "color":"green"}') ``` ```python # Or as a Python dict or list converted to JSON: minescript.echo_json({"text":"hello!", "color":"green"}) ``` ```python # Prints a plain-text message to the in-game chat that's # visible only to you, displayed as yellow text so that # it's visually distinguishable from text written to stdout: print("Note to self...", file=sys.stderr) ``` ```python # Send a chat message that's visible to all players # in the world: minescript.chat("hi, friends!") ``` ```python # Log a message to Minecrafts log file # (in minecraft/logs/latest.log): minescript.log("This is a debug message that does not appear in-game.") ``` -------------------------------- ### Get Help for a Minescript Command Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Use the `\help NAME` command to retrieve documentation for a specific Minescript script or command. Available since v1.19.2. ```minescript \help NAME ``` -------------------------------- ### Locate Built Mod Jars Source: https://github.com/maxuser0/minescript/blob/main/README.md After building the mod, the generated jar files will be located in the 'build/libs' directory within the specific mod platform's subdirectory. Example shown for different mod loaders. ```bash $ ls */build/libs/*-4.0.jar fabric/build/libs/minescript-fabric-1.21.1-4.0.jar forge/build/libs/minescript-forge-1.21.1-4.0.jar neoforge/build/libs/minescript-neoforge-1.21.1-4.0.jar ``` -------------------------------- ### ManagedCallback Example Usage Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Demonstrates how to register a ManagedCallback with a Java event, such as HudRenderCallback, and how to cancel it after a delay using set_timeout. This is a Pyjinn-only feature. ```python callback = ManagedCallback(on_hud_render) HudRenderCallback.EVENT.register(HudRenderCallback(callback)) # Cancel after 1 second (1000 milliseconds): set_timeout(callback.cancel, 1000) ``` -------------------------------- ### player_inventory Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets all items in the local player's inventory, returning a list of ItemStack objects. ```APIDOC ## player_inventory ### Description Gets the items in the local player's inventory. ### Usage player_inventory() -> List[ItemStack] ### Returns - Items in player's inventory. ``` -------------------------------- ### player_press_forward Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from moving forward, simulating the press and release of the 'w' key. Available since v2.1. ```APIDOC ## player_press_forward ### Description Starts/stops moving the local player forward, simulating press/release of the 'w' key. ### Method Signature player_press_forward(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, go forward, otherwise stop doing so. ``` -------------------------------- ### Register Key Listener Example Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Registers a listener for key events and processes them within a 'with' block. The listener automatically unregisters upon exiting the block. It distinguishes between key up, down, and repeat actions. ```python with EventQueue() as event_queue: event_queue.register_key_listener() while True: event = event_queue.get() if event.type == EventType.KEY: if event.action == 0: action = 'up' elif event.action == 1: action = 'down' else: action = 'repeat' echo(f"Got key {action} with code {event.key}") ``` -------------------------------- ### player_press_left Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from moving left, simulating the press and release of the 'a' key. Available since v2.1. ```APIDOC ## player_press_left ### Description Starts/stops moving the local player to the left, simulating press/release of the 'a' key. ### Method Signature player_press_left(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, move to the left, otherwise stop doing so. ``` -------------------------------- ### player_press_right Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from moving right, simulating the press and release of the 'd' key. Available since v2.1. ```APIDOC ## player_press_right ### Description Starts/stops moving the local player to the right, simulating press/release of the 'd' key. ### Method Signature player_press_right(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, move to the right, otherwise stop doing so. ``` -------------------------------- ### Get Player's Inventory Items Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Retrieves all items in the local player's inventory. Returns a list of `ItemStack` objects. Async execution available via `.as_async()`. ```python player_inventory() -> List[ItemStack] ``` -------------------------------- ### player_press_backward Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from moving backward, simulating the press and release of the 's' key. Available since v2.1. ```APIDOC ## player_press_backward ### Description Starts/stops moving the local player backward, simulating press/release of the 's' key. ### Method Signature player_press_backward(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, go backward, otherwise stop doing so. ``` -------------------------------- ### player_press_drop Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from dropping an item, simulating the press and release of the 'q' key. Available since v2.1. ```APIDOC ## player_press_drop ### Description Starts/stops the local player dropping an item, simulating press/release of the 'q' key. ### Method Signature player_press_drop(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, drop an item, otherwise stop doing so. ``` -------------------------------- ### Get Block Type at Position Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the type of block at a specific 3D coordinate. An alias `get_block(...)` is available. ```python getblock(x: int, y: int, z: int) ``` -------------------------------- ### Access Pyjinn Globals from Python Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates how to get and set global variables from an embedded Pyjinn script using `script.get()` and `script.set()`. Supported types include basic types, collections, and Java objects. ```python get_fps = script.get("get_fps") print("fps:", get_fps("frames per second")) print(f"x from Python = {script.get('x')}") print_x = script.get("print_x") print_x() script.set("x", 99) print_x() ``` -------------------------------- ### help Command Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Prints documentation for a given script or command name. ```APIDOC ## help Command ### Description Prints documentation for the given script or command name. ### Usage `\help NAME` ### Since v1.19.2 ``` -------------------------------- ### Running Dice Roll Script from Minecraft Chat Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Example command to execute the roll_dice.py script from Minecraft's in-game chat, passing arguments for the number of dice and sides. ```minecraft \roll_dice 2 6 ``` -------------------------------- ### player_name Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the local player's name. ```APIDOC ## player_name ### Description Gets the local player's name. ### Usage player_name() -> str ``` -------------------------------- ### world_info Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets information about the current world in the Minescript mod. ```APIDOC ## world_info ### Description Gets information about the current world. ### Returns * **WorldInfo** - An object containing world details. ### Example ```python world = minescript.world_info() ``` ``` -------------------------------- ### player_name Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the player's name in the Minescript mod. ```APIDOC ## player_name ### Description Gets the player's name. ### Returns * **string** - The player's name. ### Example ```python name = minescript.player_name() ``` ``` -------------------------------- ### Create New Java Instance Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Instantiates a new Java object using a constructor handle and provided arguments. Arguments must be Java handles. ```python java_new_instance(ctor: JavaHandle, *args: List[JavaHandle]) -> JavaHandle ``` -------------------------------- ### Basic Minescript Python Script Source: https://github.com/maxuser0/minescript/blob/main/README.md This script demonstrates basic Minescript functionalities like echoing messages, sending chat messages, getting player position, interacting with blocks, and displaying inventory. Ensure the 'minescript' library is imported. ```python # example.py: import minescript # Write a message to the chat that only you can see: minescript.echo("Hello, world!") # Write a chat message that other players can see: minescript.chat("Hello, everyone!") # Get your player's current position: x, y, z = minescript.player().position # Print information for the block that your player is standing on: minescript.echo(minescript.getblock(x, y - 1, z)) # Set the block directly beneath your player (assuming commands are enabled): x, y, z = int(x), int(y), int(z) minescript.execute(f"setblock {x} {y-1} {z} yellow_concrete") # Display the contents of your inventory: for item in minescript.player_inventory(): minescript.echo(item.item) ``` -------------------------------- ### player_inventory Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the player's inventory in the Minescript mod. ```APIDOC ## player_inventory ### Description Gets the player's inventory. ### Returns * **list[ItemStack]** - A list of items in the inventory. ### Example ```python inventory = minescript.player_inventory() ``` ``` -------------------------------- ### Configure command execution for JAR files Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md This configuration block specifies how to execute `.jar` files using the `java -jar` command. It includes settings for the file extension, the command to run, and optional environment variables. ```json command = { "extension": ".jar", "command": [ "/usr/bin/java", "-jar", "{command}", "{args}" ], "environment": [ "FIRST_ENV_VAR=1234", "SECOND_ENV_VAR=2468" ] } ``` -------------------------------- ### get_block Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the block at a specific position in the Minescript mod. ```APIDOC ## get_block ### Description Gets the block at a specific position. ### Parameters * **pos** (BlockPos) - Required - The position of the block. ### Returns * **Block** - The block at the specified position. ### Example ```python block = minescript.get_block(minescript.BlockPos(10, 64, 20)) ``` ``` -------------------------------- ### Get Local Player Name Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Retrieves the name of the local player. ```python player_name() -> str ``` -------------------------------- ### Run Minescript Dev Client Source: https://github.com/maxuser0/minescript/blob/main/README.md Run the dev client for Fabric, Forge, or NeoForge after setting up the repositories and building Pyjinn. Execute the appropriate Gradle command for your chosen mod loader. ```bash $ cd path/to/minescript # Fabric client: $ ./gradlew fabric:runClient # Forge client: $ ./gradlew forge:runClient # NeoForge client: $ ./gradlew neoforge:runClient ``` -------------------------------- ### screen_name Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the name of the currently open screen in the Minescript mod. ```APIDOC ## screen_name ### Description Gets the name of the currently open screen. ### Returns * **string** - The name of the screen. ### Example ```python screen = minescript.screen_name() ``` ``` -------------------------------- ### Pyjinn Python Expressions: Tuple and List Literals Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Illustrates the creation of tuple and list literals in Pyjinn. ```python # Tuple literal: (X, Y, Z) # Tuple assignment: X, Y = 1, 2 X, Y = (1, 2) X, Y = [1, 2] # List literal: [X, Y, Z] ``` -------------------------------- ### players Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets a list of all players currently in the game in the Minescript mod. ```APIDOC ## players ### Description Gets a list of all players currently in the game. ### Returns * **list[PlayerData]** - A list of player data objects. ### Example ```python all_players = minescript.players() ``` ``` -------------------------------- ### JavaMap Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Creates a Java Map handle from a Pyjinn dictionary. ```APIDOC ## JavaMap ### Description Pyjinn built-in that returns the Java Map representing the given Pyjinn dict. ### Usage JavaMap(pyjinn_dict) -> JavaHandle ### Parameters #### Args: - `pyjinn_dict`: The Pyjinn dictionary to convert to a Java Map. ``` -------------------------------- ### Importing Pyjinn Libraries Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Shows how to import custom Pyjinn libraries from the minecraft/minescript directory. Ensure the library is compatible with both Python and Pyjinn if it needs to be shared. ```python import my_kewl_library ``` -------------------------------- ### player_position Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the player's current position in the Minescript mod. ```APIDOC ## player_position ### Description Gets the player's current position. ### Returns * **Vector3f** - The player's position. ### Example ```python position = minescript.player_position() ``` ``` -------------------------------- ### player_health Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the player's current health in the Minescript mod. ```APIDOC ## player_health ### Description Gets the player's current health. ### Returns * **float** - The player's health value. ### Example ```python health = minescript.player_health() ``` ``` -------------------------------- ### Pack BlockPacker to BlockPack Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Creates a compact, immutable BlockPack snapshot from the current BlockPacker. Can include comments. ```python BlockPacker.pack(*, comments: Dict[str, str] = {}) -> [BlockPack](#blockpack) ``` -------------------------------- ### player_hand_items Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the items the player is holding in their hands in the Minescript mod. ```APIDOC ## player_hand_items ### Description Gets the items the player is holding in their hands. ### Returns * **HandItems** - An object containing the main and off-hand items. ### Example ```python hand_items = minescript.player_hand_items() ``` ``` -------------------------------- ### player_get_targeted_entity Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the entity the player is currently targeting in the Minescript mod. ```APIDOC ## player_get_targeted_entity ### Description Gets the entity the player is currently targeting. ### Returns * **EntityData** - Information about the targeted entity. ### Example ```python targeted_entity = minescript.player_get_targeted_entity() ``` ``` -------------------------------- ### BlockPack.visit_blocks Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Invokes provided callbacks to visit all blocks in the BlockPack, distinguishing between individual blocks and contiguous volumes. ```APIDOC ## BlockPack.visit_blocks ### Description Invokes the given callbacks to visit all the blocks in this BlockPack. ### Method `BlockPack.visit_blocks(setblock: Callable[[int, int, int, str], None], fill: Callable[[int, int, int, int, int, int, str], None]) -> None` ### Parameters #### Path Parameters - `setblock` (Callable[[int, int, int, str], None]): Callback for individual blocks. - `fill` (Callable[[int, int, int, int, int, int, str], None]): Callback for contiguous volumes of blocks. ### Compatibility Pyjinn only. ``` -------------------------------- ### player_get_targeted_block Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the block the player is currently targeting in the Minescript mod. ```APIDOC ## player_get_targeted_block ### Description Gets the block the player is currently targeting. ### Returns * **TargetedBlock** - Information about the targeted block. ### Example ```python targeted_block = minescript.player_get_targeted_block() ``` ``` -------------------------------- ### JavaList Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Creates a Java List handle from a Pyjinn list. ```APIDOC ## JavaList ### Description Pyjinn built-in that returns the Java List representing the given Pyjinn list. ### Usage JavaList(pyjinn_list) -> JavaHandle ### Parameters #### Args: - `pyjinn_list`: The Pyjinn list to convert to a Java List. ``` -------------------------------- ### chat_input Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the current chat input string in the Minescript mod. ```APIDOC ## chat_input ### Description Gets the current chat input string. ### Returns * **string** - The current chat input. ### Example ```python current_input = minescript.chat_input() ``` ``` -------------------------------- ### Build Pyjinn Interpreter Locally Source: https://github.com/maxuser0/minescript/blob/main/README.md For Minescript 5.0 and later, build the Pyjinn interpreter and publish it to your local Maven repository using the provided Gradle command. ```bash $ cd path/to/pyjinn $ ./gradlew interpreter:publishToMavenLocal ``` -------------------------------- ### player_orientation Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the player's current orientation (rotation) in the Minescript mod. ```APIDOC ## player_orientation ### Description Gets the player's current orientation (rotation). ### Returns * **Rotation** - The player's rotation. ### Example ```python orientation = minescript.player_orientation() ``` ``` -------------------------------- ### Call Static Java Method Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates calling a static method of a Java class using Pyjinn. Requires importing the Java class. ```python List = JavaClass("java.util.List") java_list = List.of(1, 2, 3) ``` -------------------------------- ### get_block_list Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets a list of blocks within a specified region in the Minescript mod. ```APIDOC ## get_block_list ### Description Gets a list of blocks within a specified region. ### Parameters * **region** (BlockRegion) - Required - The region to get blocks from. ### Returns * **list[Block]** - A list of blocks in the region. ### Example ```python blocks = minescript.get_block_list(minescript.BlockRegion(minescript.BlockPos(0, 0, 0), minescript.BlockPos(16, 16, 16))) ``` ``` -------------------------------- ### player_hand_items Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the items currently held in the local player's main and off hands. ```APIDOC ## player_hand_items ### Description Gets the items in the local player's hands. ### Usage player_hand_items() -> [HandItems](#handitems) ### Returns - Items in player's hands. ``` -------------------------------- ### Pyjinn Python Expressions: Dictionary Literals Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates the creation of dictionary literals in Pyjinn. ```python # Dict literal: {K1: V1, K2: V2, ...} ``` -------------------------------- ### execute Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Executes the given command. If the command is prefixed with a backslash, it's treated as a Minescript command; otherwise, it's treated as a Minecraft command. ```APIDOC ## execute ### Description Executes the given command. If `command` is prefixed by a backslash, it's treated as Minescript command, otherwise it's treated as a Minecraft command (the slash prefix is optional). ### Usage execute(command: str) ### Parameters #### Path Parameters - **command** (str) - Description: The command to execute. ``` -------------------------------- ### player_position Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the local player's position as a list of floats [x, y, z]. ```APIDOC ## player_position ### Description Gets the local player's position. ### Usage player_position() -> List[float] ### Returns - player's position as [x: float, y: float, z: float] ``` -------------------------------- ### Python Expressions Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates basic Python expression syntax supported by Pyjinn, including if-else, list comprehensions, and lambda expressions. ```python TRUE_VALUE if CONDITION else FALSE_VALUE ``` ```python [X * 2 for X in range(5)] # evaluates to: [0, 2, 4, 6, 8] ``` ```python [C for C in "hello"] # evaluates to: ["h", "e", "l", "l", "o"] ``` ```python lambda: print("no args") ``` ```python lambda X: print("1 arg:", X) ``` ```python lambda X, Y: print("2 args:", X, Y) ``` -------------------------------- ### get_block_region Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets a BlockRegion object representing a cubic region of space in the Minescript mod. ```APIDOC ## get_block_region ### Description Gets a BlockRegion object representing a cubic region of space. ### Parameters * **pos1** (BlockPos) - Required - The first corner of the region. * **pos2** (BlockPos) - Required - The opposite corner of the region. ### Returns * **BlockRegion** - The BlockRegion object. ### Example ```python region = minescript.get_block_region(minescript.BlockPos(0, 0, 0), minescript.BlockPos(10, 10, 10)) ``` ``` -------------------------------- ### Get Block Index Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Calculates the index for a block's position within the 'blocks' sequence. ```python BlockRegion.get_index(x: int, y: int, z: int) -> int ``` -------------------------------- ### Get Block Type Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Retrieves the type of block at a specific 3D coordinate within a region. ```python BlockRegion.get_block(x: int, y: int, z: int) -> str ``` -------------------------------- ### JavaBoundMember.__init__ Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Initializes a JavaBoundMember, representing a Java method or field reference in Python. ```APIDOC ## JavaBoundMember.__init__ ### Description Initializes a JavaBoundMember, representing a Java method or field reference in Python. ### Method JavaBoundMember(target_class_id: JavaHandle, target, name: str, ref: [JavaRef](#javaref) = None, script: [JavaObject](#javaobject) = None) ### Parameters #### Args - **target_class_id** (JavaHandle) - Java object ID of enclosing class for this member - **target** (JavaObject ID) - Java object ID of the target through which this member is accessed - **name** (str) - name of this member - **ref** (JavaRef, optional) - JavaRef to manage reference lifetime - **script** (JavaObject, optional) - Pyjinn Script object for accessing and calling script functions ``` -------------------------------- ### Event Queue Initialization Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Initializes an EventQueue for managing event listeners. It supports context management for automatic listener unregistration. ```python EventQueue() ``` -------------------------------- ### JavaObject.__init__ Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Constructs a Python handle to a Java object given a `JavaHandle`. ```APIDOC ## JavaObject.__init__ ### Description Constructs a Python handle to a Java object given a `JavaHandle`. ### Usage `JavaObject(target_id: JavaHandle, ref: [JavaRef](#javaref) = None, is_script: bool = False)` ``` -------------------------------- ### Converting JavaString to String in Pyjinn Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates how to explicitly convert a JavaString object back to a standard String using the toString() method when needed. ```python s = "foo" print(s is JavaString(s).toString()) # prints: True ``` -------------------------------- ### player_orientation Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets the local player's current orientation, including yaw and pitch. Available since v2.1. ```APIDOC ## player_orientation ### Description Gets the local player's orientation. ### Method Signature player_orientation() -> List[float] ### Returns - A list containing two floats: [yaw: float, pitch: float] representing angles in degrees. ``` -------------------------------- ### Manually Convert Pyjinn Function to Java Interface Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates manually converting a Pyjinn function to a Java interface implementation by calling the interface as a Python constructor. ```python Runnable = JavaClass("java.lang.Runnable") x = Runnable(lambda: print("hello!")) x.run() # prints: hello! ``` -------------------------------- ### Get Active Job Information Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Returns information about active Minescript jobs. For the enclosing job, `JobInfo.self` is `True`. ```python job_info() -> List[JobInfo] ``` -------------------------------- ### java_array_index Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Gets an indexed element of a Java array handle. Returns a handle to the object at the specified index, or None if null. ```APIDOC ## java_array_index ### Description Gets indexed element of Java array handle. ### Usage java_array_index(array: JavaHandle, i: int) -> Union[JavaHandle, None] ### Parameters #### Args: - `array`: handle to Java array object - `i`: index into array ### Returns - handle to object at `array[i]` in Java, or `None` if `null`. ``` -------------------------------- ### player_press_jump Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from jumping, simulating the press and release of the space key. Available since v2.1. ```APIDOC ## player_press_jump ### Description Starts/stops the local player jumping, simulating press/release of the space key. ### Method Signature player_press_jump(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, jump, otherwise stop doing so. ``` -------------------------------- ### BlockRegion.__init__ Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Creates a BlockRegion object, representing an axis-aligned bounding box of blocks. ```APIDOC ## BlockRegion.__init__ ### Description Creates a block region between `min_pos` and `max_pos`, inclusive. ### Method BlockRegion(min_pos: [BlockPos](#blockpos), max_pos: [BlockPos](#blockpos), blocks: Tuple[str, ...]) ### Parameters #### Path Parameters - **min_pos** ([BlockPos](#blockpos)) - The minimum position of the axis-aligned bounding box. - **max_pos** ([BlockPos](#blockpos)) - The maximum position of the axis-aligned bounding box. - **blocks** (Tuple[str, ...]) - A tuple of block type strings covering the volume of blocks between `min_pos` and `max_pos`, inclusive. The order and dimensions are crucial for correct interpretation. ``` -------------------------------- ### version_info Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Retrieves version information for Minecraft, Minescript, the mod loader, launcher, and operating system. ```APIDOC ## version_info ### Description Gets version info for Minecraft, Minescript, mod loader, launcher, and OS. `minecraft_class_name` is the runtime class name of the main Minecraft class which may be obfuscated. ### Method version_info() -> [VersionInfo](#versioninfo) ### Returns - `[VersionInfo](#versioninfo)` - An object containing version details. ``` -------------------------------- ### Pyjinn Python Function Definition with Keyword Arguments Capture Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Illustrates how to use '**kwargs' in a function definition to capture arbitrary keyword arguments into a dictionary (since Pyjinn 0.9). ```python # Capture keyword args passed to a function as a dict: # (since Pyjinn 0.9) def FUNC(**kwargs): ... ``` -------------------------------- ### Pyjinn Event Handling with Async/Await Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates asynchronous event handling in Pyjinn using the EventLoop class. Use this for managing events in a unified loop similar to Python's EventQueue but with async/await syntax. ```python async def handle_events(event_loop: EventLoop): while True: # Await an event for 3 seconds (omit param to wait indefinitely): event = await event_loop.event(timeout_seconds=3) if event is None: print("No events in last 3 seconds. Awaiting more events...") elif event.type == "mouse": if event.button == 1 and event.action == 0: print("Got right-click release. Quitting.") break else: print("Got mouse event.") event_loop = EventLoop() event_loop.add_listener("mouse") event_loop.run(handle_events) ``` -------------------------------- ### player_press_swap_hands Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from swapping hands, simulating the press and release of the 'f' key. Available since v2.1. ```APIDOC ## player_press_swap_hands ### Description Starts/stops moving the local player swapping hands, simulating press/release of the 'f' key. ### Method Signature player_press_swap_hands(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, swap hands, otherwise stop doing so. ``` -------------------------------- ### player_press_sneak Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from sneaking, simulating the press and release of the left shift key. Available since v2.1. ```APIDOC ## player_press_sneak ### Description Starts/stops the local player sneaking, simulating press/release of the left shift key. ### Method Signature player_press_sneak(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, sneak, otherwise stop doing so. ``` -------------------------------- ### Pyjinn Python Index and Slice Operations Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Explains the syntax for accessing elements and sub-sequences using indexing and slicing operations on sequences in Pyjinn. ```python # Index/Slice operations: X[INDEX] X[FROM:] X[:TO] X[:] X[FROM:TO:STEP] X[:-1] # Negative indices are relative to the end of the sequence. ``` -------------------------------- ### player_press_sprint Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from sprinting, simulating the press and release of the left control key. Available since v2.1. ```APIDOC ## player_press_sprint ### Description Starts/stops the local player sprinting, simulating press/release of the left control key. ### Method Signature player_press_sprint(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, sprint, otherwise stop doing so. ``` -------------------------------- ### Pyjinn Python Function Call Keyword Argument Unpacking Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Shows how to use the '**' operator to unpack a dictionary with string keys into keyword arguments for a function call (since Pyjinn 0.9). ```python # Convert dict with str keys into keyword arguments to a function: # (since Pyjinn 0.9) FUNC(**{"K1": V1, "K2": V2, ...}) # equivalent to: FUNC(K1=V1, K2=V2, ...) ``` -------------------------------- ### JavaString Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Exposes the Java String API for a given Pyjinn string. ```APIDOC ## JavaString ### Description Pyjinn built-in that exposes the Java String API for the given Pyjinn str. ### Usage JavaString(pyjinn_str) -> JavaHandle ### Compatibility Pyjinn only. ``` -------------------------------- ### BlockPack.import_data Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Creates a BlockPack from base64-encoded serialized blockpack data. ```APIDOC ## BlockPack.import_data ### Description Creates a blockpack from base64-encoded serialized blockpack data. ### Method `@classmethod BlockPack.import_data(base64_data: str) -> [BlockPack](#blockpack)` ### Parameters #### Path Parameters - `base64_data` (str): Base64-encoded string containing serialization of blockpack data. ### Returns - A new BlockPack containing blocks read from the base64-encoded data. ``` -------------------------------- ### show_chat_screen Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Controls the visibility of the chat screen. Can optionally set initial text in the input box. ```APIDOC ## show_chat_screen ### Description Shows or hides the chat screen. ### Usage show_chat_screen(show: bool, prompt: str = None) -> bool ### Args - `show` (bool): If `True`, show the chat screen; otherwise hide it. - `prompt` (str, optional): If `show` is `True`, insert `prompt` into chat input box upon showing chat screen. ### Returns `True` if chat screen was successfully shown (`show=True`) or hidden (`show=False`). ### Since v4.0 ``` -------------------------------- ### Get Java Constructor Handle Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Retrieves a handle to the constructor of a given Java class. This handle is needed to create new Java objects. ```python java_ctor(clazz: JavaHandle) ``` -------------------------------- ### Pyjinn Python Function Call Argument Unpacking Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates using the '*' operator to unpack an iterable sequence into distinct arguments for a function call. ```python # Call function with an iterable sequence into distinct args: FUNC(*[1, 2, 3]) # call as FUNC(1, 2, 3) ``` -------------------------------- ### player_press_pick_item Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from picking an item, simulating the press and release of the middle mouse button. Available since v2.1. ```APIDOC ## player_press_pick_item ### Description Starts/stops the local player picking an item, simulating press/release of the middle mouse button. ### Method Signature player_press_pick_item(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, pick an item, otherwise stop doing so. ``` -------------------------------- ### Python vs. Java String Methods in Pyjinn Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Shows how to call Python-compatible string methods and Java String methods. Use JavaString() to access Java String functionality when conflicts arise. ```python # Python-compatible call to str.startswith(): print("foo".startswith("o", 1)) # prints: True # Java call to String.startsWith() (note the different capitalization): print("foo".startsWith("f")) # prints: True ``` -------------------------------- ### getblock Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Alias for get_block. ```APIDOC ## getblock ### Description Alias for `get_block`. ### Parameters * **pos** (BlockPos) - Required - The position of the block. ### Returns * **Block** - The block at the specified position. ### Example ```python block = minescript.getblock(minescript.BlockPos(10, 64, 20)) ``` ``` -------------------------------- ### player_press_attack Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from attacking or breaking a block, simulating the press and release of the left mouse button. Available since v2.1. ```APIDOC ## player_press_attack ### Description Starts/stops the local player attacking or breaking a block, simulating press/release of the left mouse button. ### Method Signature player_press_attack(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, press attack, otherwise stop doing so. ``` -------------------------------- ### Minescript Commands to Redirect stderr Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Demonstrates redirecting standard error (stderr) from the output_example.py script to chat, log file, or null. ```minecraft \output_example 2> chat ``` ```minecraft \output_example 2> log ``` ```minecraft \output_example 2> null ``` -------------------------------- ### Get Java Member Handle Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Looks up a Java class member (field or method) by name and returns a handle. Used for accessing fields or calling methods. ```python java_member(clazz: JavaHandle, name: str) -> JavaHandle ``` -------------------------------- ### Access Minecraft Java API Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Demonstrates accessing Minecraft's Java API from Python using the Java module. Imports necessary classes and retrieves the current FPS. ```python from minescript import echo from java import JavaClass Minecraft = JavaClass("net.minecraft.client.Minecraft") minecraft = Minecraft.getInstance() echo("fps:", minecraft.getFps()) ``` -------------------------------- ### Get Local Player Position Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Retrieves the local player's position as a list of floats [x, y, z]. Async execution can be achieved using `.as_async()`. ```python player_position() -> List[float] ``` -------------------------------- ### Python String Slicing in Pyjinn Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Demonstrates Python-compatible slice operations on Pyjinn strings, which are instances of java.lang.String. ```python s = "foobarbaz" print(s[0]) # prints: f print(s[-1]) # prints: z print(s[3:]) # prints: barbaz print(s[3:6]) # prints: bar ``` -------------------------------- ### player_press_use Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Starts or stops the local player from using an item or selecting a block, simulating the press and release of the right mouse button. Available since v2.1. ```APIDOC ## player_press_use ### Description Starts/stops the local player using an item or selecting a block, simulating press/release of the right mouse button. ### Method Signature player_press_use(pressed: bool) ### Parameters #### Args - **pressed** (bool) - Required - if `True`, use an item, otherwise stop doing so. ``` -------------------------------- ### Register Add Entity Listener Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Registers a listener for entity addition events. Use this to detect when new entities are spawned in the game world. ```python with EventQueue() as event_queue: event_queue.register_add_entity_listener() while True: event = event_queue.get() if event.type == EventType.ADD_ENTITY: echo(f"Entity added: {event.entity.name}") ``` -------------------------------- ### chat Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Sends messages to the chat. If the first message starts with a slash or backslash, a space is prepended to send it as a chat message. Multiple messages are joined by spaces. ```APIDOC ## chat ### Description Sends messages to the chat. If `messages[0]` is a str starting with a slash or backslash, automatically prepends a space so that the messages are sent as a chat and not executed as a command. If `len(messages)` is greater than 1, join messages with a space separating them. Ignores empty `messages`. ### Usage chat(*messages) ### Parameters #### Path Parameters - **messages** (str) - Description: One or more messages to send to the chat. ``` -------------------------------- ### JavaClass Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Creates a Java class handle from its fully qualified name. ```APIDOC ## JavaClass ### Description Pyjinn built-in that returns a Java class given its fully qualified name. ### Usage JavaClass(class_name: str) -> JavaHandle ### Parameters #### Args: - `class_name`: The fully qualified name of the Java class. ``` -------------------------------- ### Pyjinn Python Operator Overloading (User-Defined Classes) Source: https://github.com/maxuser0/minescript/blob/main/docs/pyjinn.md Shows the special methods supported for operator overloading in user-defined classes in Pyjinn, starting from version 0.12. ```python # Operator overloading for user-defined classes (since Pyjinn 0.12): class CLASS_NAME: def __add__(self, rhs): ... def __sub__(self, rhs): ... def __mul__(self, rhs): ... def __truediv__(self, rhs): ... def __floordiv__(self, rhs): ... def __pow__(self, rhs): ... def __mod__(self, rhs): ... def __lshift__(self, rhs): ... def __rshift__(self, rhs): ... def __eq__(self, rhs): ... def __lt__(self, rhs): ... def __le__(self, rhs): ... def __gt__(self, rhs): ... def __ge__(self, rhs): ... def __ne__(self, rhs): ... def __contains__(self, rhs): ... def __len__(self): ... def __getitem__(self, key): ... def __setitem__(self, key, value): ... def __call__(self, *args): ... ``` -------------------------------- ### world_info Source: https://github.com/maxuser0/minescript/blob/main/docs/README.md Retrieves properties of the current world, including game ticks, day cycle progress, weather status, spawn point, and difficulty. ```APIDOC ## world_info ### Description Gets world properties. If the current world is a multiplayer world loaded from the server list, then the returned `name` and `address` attributes are the values as they appear in the server list; otherwise `name` is the name of the locally saved world and `address` is `localhost`. `day_ticks` are the ticks associated with the day-night cycle. Renamed from `world_properties()` from v3.1. ### Method world_info() -> [WorldInfo](#worldinfo) ### Returns - `[WorldInfo](#worldinfo)` - An object containing world properties. ```