MClibrary (Documentation)

Class MClibrary

Package: org.lauro.blocklyMc

The MClibrary class provides a high-level API for controlling world manipulation, geometry creation, player interaction, and event handling inside Minecraft through a scripting environment. It acts as a public wrapper around the internal MClib utilities and a SessionContext, exposing safe script-callable methods for use in automated building or Blockly/Python integrations.


Constructor Summary

ConstructorDescription
MClibrary(SessionContext sessionContext) Creates a new library instance bound to the given scripting session context.

Method Summary

Position
void movePositionRelative(double steps, String direction) Moves the current position relative to the player’s orientation using a directional keyword.
Location movePositionAbsolute(String coordSystem, Double x_radius, Double y_theta, Double z_phi) Moves the current position using absolute spatial coordinates (Cartesian, Cylindrical, or Spherical).
Location moveToViewTarget() Moves the internal cursor to the block the player is currently looking at.
Location moveToPlayer() Moves the internal cursor to the player’s current location.
Location resetPosition() Moves the internal cursor back to the session’s original starting location.
Location moveToLastMark() Moves the cursor to the last stored marker position.
Location moveToNextSolidBlock() Moves the cursor forward along the facing direction until the next solid block is found.
Location rotateYawRelative(float angle) Rotates the facing direction horizontally (yaw) by the given relative angle.
Location rotateYawAbsolute(String direction) Sets the yaw to an absolute direction, such as cardinal directions or the player’s own yaw.
Location setPitchAbsolute(float angle) Sets the vertical viewing angle (pitch) to the specified absolute value.
Location setPitchRelative(float angle) Rotates the pitch by a relative delta amount.
Geometry / Shape Construction
void createBlock(Value blocks) Places a block or a block pattern at the current cursor position.
void createSquare(Double width, boolean filled, Value blocks) Creates a square in the X/Y plane, optionally filled or outline only.
void createRectangle(Double width, Double height, boolean filled, Value blocks) Creates a rectangle in the X/Y plane with optional filled/outline behavior.
void createPolygon(int sides, Double radiusX, Double radiusY, int arcAngle, boolean filled, Value blocks) Creates a regular polygon or arc with optional elliptical radii.
void createArc(Double radiusX, Double radiusY, int arcAngle, boolean filled, Value blocks) Creates a circular or elliptical arc.
void createEllipse(Double radiusX, Double radiusY, boolean filled, Value blocks) Creates a complete ellipse.
void createCircle(Double radiusX, boolean filled, Value blocks) Creates a perfect circle.
void createStar(int points, double innerRadius, double outerRadius, boolean filled, Value blocks) Creates a multi-pointed star shape centered on the cursor.
void createLine(long length, Value blocks) Creates a straight line extending forward from the cursor.
void connectPositions(Value blocks) Draws a polygonal chain connecting all marked positions.
void markPosition() Stores the current location as a named bookmark for later geometry operations.
Location createText(String text, int fontSize, boolean filled, Value blocks) Renders text as block-based pixel characters using a selected block palette.
void createDrawing(String[] blockList, Value[] blockMaterials, int matIndex, String origin) Creates a 2D pixel-art drawing from encoded block lists.
void createChest(Value blocks) Places a chest containing the provided blocks or items.
Player / Entity Interaction
void giveToPlayer(String equipMode, Value blocks) Gives blocks/items to the player, placing them in a chosen equipment slot.
boolean isCurrentBlockOfType(Value blocks) Checks if the block at the current cursor position matches one of the given types.
boolean isPlayerHolding(Value blocks) Checks whether the player is currently holding an item of the given type.
boolean hasPlayerItem(Value blocks) Checks if the player has the specified material in their inventory.
boolean isPlayerInteractingWith(Value blocks) Returns whether the player is currently hitting or interacting with the given block type.
Events / Logic
void onEvent(String eventType, String functionToCall) Registers a callback function to execute when the specified event occurs.
void clearEvents() Removes all registered event listeners for the session.
void callFunction(String functionName, String playerName, Object param1) Invokes a scripting-engine function with parameters.

Detailed Method Descriptions

movePositionRelative

void movePositionRelative(double steps, String direction)

Moves the current cursor relative to the player’s orientation. Valid directions: FORWARD, BACKWARD, LEFT, RIGHT, UP, DOWN.

movePositionAbsolute

Location movePositionAbsolute(String coordSystem, Double x_radius, Double y_theta, Double z_phi)

Moves the cursor using absolute coordinates. Supported coordinate systems:

  • CARTESIAN (x, y, z)
  • CYLINDRICAL (radius, theta, height)
  • SPHERICAL (radius, theta, phi)

moveToViewTarget

Location moveToViewTarget()

Moves the cursor to the location the player is pointing at (raycast hit position).

moveToPlayer

Location moveToPlayer()

Moves the cursor to the player’s exact current world coordinates.

resetPosition

Location resetPosition()

Moves the cursor back to the session’s initial starting point.

moveToLastMark

Location moveToLastMark()

Moves to the last position stored with markPosition().

moveToNextSolidBlock

Location moveToNextSolidBlock()

Advances forward until the next solid (non-air) block is encountered.

rotateYawRelative

Location rotateYawRelative(float angle)

Rotates the yaw by a relative amount, positive or negative.

rotateYawAbsolute

Location rotateYawAbsolute(String direction)

Sets the yaw to an absolute direction: N, S, E, W, or PLAYER_YAW.

setPitchAbsolute / setPitchRelative

Controls the vertical look angle.

createBlock

void createBlock(Value blocks)

Places blocks according to a block descriptor or list.

createSquare / createRectangle / createPolygon / createCircle / createEllipse

Constructs geometric primitives around the current cursor.

createStar

Creates a star shape using inner/outer radii.

createLine

Draws a line in the current facing direction.

connectPositions

Connects all previously marked positions with straight lines.

markPosition

Saves the current position to the mark list.

createText

Renders characters using block pixels.

createDrawing

Creates pixel art based on encoded block maps.

createChest

Places a chest and fills it with provided items.

giveToPlayer

Gives items to the player in the specified equipment slot.

Inventory & Interaction Checks

Methods to check block type, held items, inventory contents, or player interactions.

onEvent / clearEvents

Registers or clears event callbacks for the scripting engine.

callFunction

Invokes a user-defined scripting function with arguments.