note: this file was auto-generated by docsgen.sh
Make a new file, and import minecraft.sh with the source
keyword. run "start_login" and make sure to use "wait_on_login" before sending any packets. See the documentation for start_login to see the full list of options
source src/minecraft.sh
start_login
wait_on_login
And that's it! your bot will log in and do nothing. To get it to actually do something, look at the methods here or the examples in examples/
minecraft.sh works on a system of "hooks", function handlers that are called whenever certain packets are recieved. scroll down for the full list For example, to respawn and print a method whenever the bot dies, add this code to your script
pkt_hook_combat_death() {
echo "I died! Full information: $1"
pkt_respawn
}
If you just want to play around with the methods, ./interactive will give you an interactive shell with all the methods loaded
If you need to ask any questions, feel free to ask me @coolelectronics on discord
called after login and the state switches to "play"
it is NOT safe to send packets until this function is called
(username:string)
called whenever an entity in render distance moves
(eid)
called whenever a player chat message is sent
(uuid, message: hex string, timestamp: hex long, metadata: json string as hex)
called whenever the system sends you a chat event
player death, running an invalid command, actionbar, etc
(metadata: json string as hex)
called on certain types of chat events, i don't know which ones
not entirely sure what the arguments mean
(message: hex string, typename: hex string, hasname: 0 | 1, name: hex string)"
called whenever the player joins the game or is teleported
after this packet, player position will be accessible inside $PLAYER/x, $PLAYER/y, etc
(x: decimal string, y: decimal string, z: decimal string)
called when the player dies in any way
unless you have a reason not to, you should call pkt_respawn inside the hook
(reason: json string as hex)
called whenever the player's health changes
(health: decimal string, food: int, saturation: decimal string)
# attempt to leave when health falls below THRESHOLD
pkt_hook_set_health () {
if (( $(echo "$1 $THRESHOLD" | awk '{print ($1 < $2)}') )); then
echo "health was $1, leaving!"
disconnect
fi
}
called whenever an unhandled packet gets processed
sets "pkt_id", data is read from stdin
pkt_hook_unknown () {
case $pkt_id in
24) # "24" would be the packet name in hex
a=$(fromvarint)
b=$(readhex 4)
# etc etc
;;
esac
}
called whenever an entity enters view distance (NOT A PLAYER)
(eid)
called whenever a player enters view distance
(eid)
called whenever an entity (OR PLAYER) is removed or exits view distance
the entity directory gets deleted immediately after the hook exits
(eid)
called when the server kicks you for any reason
this is differnt from pkt_hook_disconnect because it only fires when the server kicks you, not if you lose connection for unrelated reasons
(reason: json string as hex)
echo -n "kicked from server: "
echosafe "$1" | fromhex
echo
called when the underlying TCP connection to the server closes, after pkt_hook_kicked
stores player position in "x" "y" and "z"
terminates all jobs on exit
mine block XYZ bocks relative to the player
"delay" is the number of seconds it should take to fully mine the block
(x,y,z,delay)
moves XYZ blocks relative to the current location
(x,y,z)
gets the ping of a server, player count, MOTD, icon, etc
returns a JSON string
HOST=endcrystal.me
json=$(server_list_ping)
echo "$json" | jq ".description.text"
echo "players: $(echo "$json" | jq ".players.online")/$(echo "$json" | jq ".players.max")"
echo "version: $(echo "$json" | jq ".version.name")"
echo "ping: ${ping}ms"
start the login process
PORT is 25565 by default, HOST is localhost by default, USERNAME is sh
pkt_swing_arm $ARM_LEFT
HOST=tf2.mercurywork.shop
PORT=25565
USERNAME=juliet
start_login
# you must call wait_on_login before sending packets
wait_on_login
wait for login to finish
you MUST call this at least once before sending any packets
send a raw serverbound packet
(packet_num: hex(2), data: hex)
pkt_send 2f "$(tovarint 1)"
# "2f" is the serverbound packet id for "swing arm" and 1 here means "left hand"
# see the full list of packets at https://wiki.vg/Protocol
respawn the player after a death
no arguments
pkt_hook_combat_death() {
pkt_respawn
}
sends a message in public chat
(message: string)
pkt_chat "hello! I sent a chat message!"
runs a server command
the command response is recieved in pkt_hook_system_chat
(command: string)
pkt_chat_command "kill CoolElectronics"
swings the player arm
(arm: ARM_LEFT | ARM_RIGHT)
pkt_swing_arm $ARM_RIGHT
interact with an entity
in the standard client, this happens when right clicking something (mounting a horse, trading with a villager, etc)
(eid, arm: arm_left | arm_right, sneaking: 0 | 1)
# attempt to interact with every entity in view distance
hook_entity_move(){
eid=$1
pkt_interact $eid $ARM_RIGHT 0
}
attack an entity
(eid)
# attempt to attack every entity in view distance whenever it moves
pkt_hook_entity_move(){
eid=$1
pkt_attack $eid
}
drop the currently held item
(DROP_ITEM|DROP_STACK)
attempt to mine a block
(DIG_START | DIG_CANCEL | DIG_FINISH, x, y, z, face)
pkt_dig $DIG_START 12 50 14
sleep 4 # wait for enough time to mine the block
pkt_dig $DIG_FINISH 12 50 14
sneak or unsneak
(SNEAK|UNSNEAK)
teleport to a coordinate, within reason
(x: decimal string, y: decimal string, z: decimal string, onground: 0 | 1)
tell server if you're grounded or not
(0 | 1)
select an item from the hotbar
(item: 0-8)
use item (eg, throw snowball)