class Rosegold::Bot

Defined in:

rosegold/bot.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Rosegold::EventEmitter

emit_event(event : Event) emit_event, event_handlers : Handlers event_handlers, off(event_type : T.class, id : UUID) forall T off, on(event_type : T.class, id : UUID = UUID.random, &block : T -> ) forall T on, once(event_type : T.class, &block : T -> ) forall T once, wait_for(event_type : T.class, timeout : Time::Span | Nil = nil) forall T wait_for

Constructor Detail

def self.new(client : Rosegold::Client) #

[View source]

Class Method Detail

def self.join_game(address : String, timeout_ticks = 1200) #

Connects to the server and waits for being ingame.


[View source]

Instance Method Detail

def attack(target : Vec3d | Nil | Look | Nil = nil) #

Looks in the direction of target, then activates and immediately deactivates the #attack button.


[View source]
def chat(message : String) #

Send a message or slash command.


[View source]
def connect(*args, **options) #

[View source]
def connect(*args, **options, &) #

[View source]
def connected?(*args, **options) #

[View source]
def connected?(*args, **options, &) #

[View source]
def dead? #

[View source]
def dig(ticks : Int32, target : Vec3d | Nil | Look | Nil = nil) #

Looks in the direction of target, then activates the #attack button, waits ticks, and deactivates it again.


[View source]
def disconnect(*args, **options) #

[View source]
def disconnect(*args, **options, &) #

[View source]
def disconnect_reason #

[View source]
def drop_hand_full #

[View source]
def drop_hand_single #

[View source]
def eat! #

[View source]
def eyes(*args, **options) #

[View source]
def eyes(*args, **options, &) #

[View source]
def feet #

DEPRECATED Use bot.location instead of bot.feet


[View source]
def food(*args, **options) #

[View source]
def food(*args, **options, &) #

[View source]
def full_health? #

[View source]
def gamemode(*args, **options) #

[View source]
def gamemode(*args, **options, &) #

[View source]
def health(*args, **options) #

[View source]
def health(*args, **options, &) #

[View source]
def host(*args, **options) #

[View source]
def host(*args, **options, &) #

[View source]
def hotbar_selection #

The active (main hand) hotbar slot number (1-9).


[View source]
def hotbar_selection=(index : UInt8) #

Selects the active (main hand) hotbar slot number (1-9).


[View source]
def inventory : Inventory #

[View source]
def join_game(*args, **options) #

[View source]
def join_game(*args, **options, &) #

[View source]
def jump_by_height(height = 1, timeout_ticks = 20) #

Jumps and waits until the bot is height above the ground. Fails if the bot lands before reaching this height.


[View source]
def land_on_ground(timeout_ticks = 120) #

Waits until the bot's y level stops changing.


[View source]
def leave_bed #

Use #interact_block to enter a bed.


[View source]
def location #

[View source]
def look #

Direction the player is looking.


[View source]
def look(&block : Look -> Look) #

Computes the new look from the current look. Waits for the new look to be sent to the server.


[View source]
def look=(look : Look) #

Waits for the new look to be sent to the server.


[View source]
def look=(vec : Vec3d) #

Waits for the new look to be sent to the server.


[View source]
def look_at(location : Vec3d) #

Waits for the new look to be sent to the server.


[View source]
def look_at_horizontal(location : Vec3d) #

Ignores y coordinate; useful for looking straight while moving. Waits for the new look to be sent to the server.


[View source]
def main_hand(*args, **options) #

[View source]
def main_hand(*args, **options, &) #

[View source]
def move_to(location : Vec3d, stuck_timeout_ticks : Int32 = 60) #

Moves straight towards #location. Waits for arrival. stuck_timeout_ticks specifies how many consecutive stuck ticks before throwing MovementStuck.


[View source]
def move_to(location : Vec3i, stuck_timeout_ticks : Int32 = 60) #

[View source]
def move_to(x : Float, z : Float, stuck_timeout_ticks : Int32 = 60) #

Moves straight towards #location. Waits for arrival. stuck_timeout_ticks specifies how many consecutive stuck ticks before throwing MovementStuck.


[View source]
def move_to(x : Int, z : Int, stuck_timeout_ticks : Int32 = 60) #

[View source]
def move_to(stuck_timeout_ticks : Int32 = 10, &block : Vec3d -> Vec3d) #

Computes the destination location from the current feet location. Moves straight towards the destination. Waits for arrival. stuck_timeout_ticks specifies how many consecutive stuck ticks before throwing MovementStuck.


[View source]
def new(address : String) #

Does not connect immediately.


[View source]
def open_container(timeout : Time::Span = 5.seconds, &) #

Opens a container (chest, barrel, etc.) and yields control for interaction. Automatically uses the main hand, waits for container content to load, executes the provided block, then closes the container.

bot.open_container do
  bot.inventory.deposit_at_least(10, "diamond")
  bot.inventory.withdraw_at_least(5, "emerald")
end

[View source]
def pick_slot(slot_number : UInt16) #

Moves the slot to the hotbar and selects it. This is faster and less error-prone than moving slots around individually.


[View source]
def pitch #

[View source]
def pitch=(pitch : Float64) #

Sets the pitch of the look Waits for the new look to be sent to the server


[View source]
def place_block_against(block : Vec3i, face : BlockFace) #

Looks at that face of that block, then activates and immediately deactivates the use button.


[View source]
def port(*args, **options) #

[View source]
def port(*args, **options, &) #

[View source]
def respawn(timeout_ticks = 1200) #

Revive the player if dead. Does nothing if alive.


[View source]
def run_command_with_confirmation(command : String, expected_message : String, max_tries : Int32 = 3, inverse_message : String | Nil = nil) #

Runs a slash command and waits for a confirmation message from the server.

Use this for non-idempotent commands (like toggles) or when you want to force retries on idempotent commands until confirmation. Retries automatically if the command fails or returns an inverse message.

The expected_message is matched after stripping formatting codes. If inverse_message is provided and received, the command will retry, which is useful for toggle commands where the bot may be in the wrong state.

Returns true if the expected message is received within max_tries attempts, false otherwise.

bot.run_command_with_confirmation(
  "/ignoregroup !",
  "You stopped ignoring !.",
  3,
  "You are now ignoring !"
)

[View source]
def saturation(*args, **options) #

[View source]
def saturation(*args, **options, &) #

[View source]
def sneak(*args, **options) #

[View source]
def sneak(*args, **options, &) #

[View source]
def sneaking?(*args, **options) #

[View source]
def sneaking?(*args, **options, &) #

[View source]
def spawned?(*args, **options) #

[View source]
def spawned?(*args, **options, &) #

[View source]
def sprint(*args, **options) #

[View source]
def sprint(*args, **options, &) #

[View source]
def sprinting?(*args, **options) #

[View source]
def sprinting?(*args, **options, &) #

[View source]
def start_digging(target : Vec3d | Nil | Look | Nil = nil) #

Looks at that target, then activates the #attack button.


[View source]
def start_jump #

Jumps the next time the player is on the ground.


[View source]
def start_using_hand(hand : Hand = :main_hand) #

Activates the "use" button.


[View source]
def stop_digging(*args, **options) #

[View source]
def stop_digging(*args, **options, &) #

[View source]
def stop_moving #

Stop moving towards the target specified in #move_to Dequeue any jump queued with #start_jump


[View source]
def stop_using_hand(*args, **options) #

[View source]
def stop_using_hand(*args, **options, &) #

[View source]
def subscribe(event_class : Class) #

[View source]
def swap_hands #

[View source]
def unsneak #

[View source]
def unsprint #

[View source]
def use_hand(target : Vec3d | Nil | Look | Nil = nil, hand : Hand = :main_hand) #

Looks in the direction of target, then activates and immediately deactivates the use button.


[View source]
def username(*args, **options) #

[View source]
def username(*args, **options, &) #

[View source]
def uuid(*args, **options) #

[View source]
def uuid(*args, **options, &) #

[View source]
def wait_tick(*args, **options) #

[View source]
def wait_tick(*args, **options, &) #

[View source]
def wait_ticks(*args, **options) #

[View source]
def wait_ticks(*args, **options, &) #

[View source]
def x(*args, **options) #

[View source]
def x(*args, **options, &) #

[View source]
def y(*args, **options) #

[View source]
def y(*args, **options, &) #

[View source]
def yaw #

[View source]
def yaw=(yaw : Float64) #

Sets the yaw of the look Waits for the new look to be sent to the server


[View source]
def z(*args, **options) #

[View source]
def z(*args, **options, &) #

[View source]