-
Notifications
You must be signed in to change notification settings - Fork 11
API
The CodeClient API allows you to connect to the game and do things like giving items, placing templates, changing modes, and much more.
It is space argument based and is found on ws://localhost:31375
When you connect you are only exposed to the default scopes.
Note
You must have the CodeClient API setting enabled (disabled by default) for applications to connect to your game!
The API operates on a scope-based system for permissions.
Scopes unlocks more commands for you to run, if you try to access a command that requires an auth scope that you do not have access to, you will get sent unauthed
. Each scope has its own danger level specified below
By default, every application that connects has access to the default
scope (more information later).
You can request the user for more scopes ("permissions") by sending the scopes <scopes>
command.
When requesting scopes the player will be sent a message for approving the requested scopes using /auth
, you will get sent auth
when the player does so.
Applications may request a token from CodeClient to feed back to CodeClient when they are restarted to preserve scopes the application was approved for.
Note: For security reasons, requesting scopes again overrides the accepted scopes instead of stacking.
default
: (default
)
inventory
: (safe
)
movement
: (caution
)
read_plot
: (caution
)
write_code
: (risky
)
clear_plot
: (dangerous
)
Here are all the commands that exist, keep in mind you do need to have the associated scope with each command to be able to run it.
Note: You don't need to wait between sending commands, they are added to a queue and are completed eventually.
Without any parameters, returns the currently approved scopes separated by a space.
Provide a list of scopes to request separated by a space, the player will be sent a confirmation message.
You will receive auth
when the player does accept the scopes.
Without any parameters, returns a token that is authenticated with the currently approved scopes.
Provide a token to authenticate with, if it's invalid you'll get invalid token
, if it's valid you will be sent auth
and the scopes affiliated with the token will be applied. Tokens are not persistent, as in they clear when the player restarts the game. You should store the token you receive from CodeClient to keep your scopes between re-launches of your application.
Clears the codespace
Moves the player to codespace spawn
Responds with the plot size. Wait for a response, any of
BASIC
,LARGE
,MASSIVE
,MEGA
Gets all the templates in the plot
Responds with newline separated gzip+base64 data.
Initials placing code into the codespace.
At any time, including the first initizer you can send either swap
or compact
.
Makes the placer place templates one after another with no space.
Cannot be used with swap
.
Makes the placer to swap any preexisting templates, and place any ones which don't exist.
Cannot be used with compact
.
Do not use swap after compact, if a template gets longer it could get cut off.
The most ideal use for this is a final "compilation", or you just don't have space (in which case you shouldn't be using swap).
After sending place
, send place <template>
replacing <template>
with a template gzip+base64 data.
Send this for each template you wish to place.
Send place go
when you are ready.
Dumps the inventory.
The response is raw SNBT, an example response would be:
[{Count:1b,Slot:0b,id:"minecraft:diamond_sword",tag:{Damage:0,display:{Name:'{"italic":false,"extra":[{"text":"Item"}],"text":""}'}}},{Count:1b,Slot:1b,id:"minecraft:diamond_sword",tag:{Damage:0,display:{Name:'{"italic":false,"extra":[{"text":"Item"}],"text":""}'}}}]
If in creative mode, sets the inventory, including emptying slots.
Exact same format as gotten from inv.
Items need a count higher than 0.
There is no response, unless you are not in creative, which you will get not creative mode
.
An example would be
setinv [{Count:1b,Slot:1b,id:"minecraft:diamond_sword",tag:{Damage:0,display:{Name:'{"italic":false,"extra":[{"text":"Item"}],"text":""}'}}},{Count:1b,Slot:1b,id:"minecraft:diamond_sword",tag:{Damage:0,display:{Name:'{"italic":false,"extra":[{"text":"Item"}],"text":""}'}}}]
Gives an item if in creative mode.
Format of a single item in inv. See this page.
Items need a count higher than 0.
There is no response, unless you are not in creative, which you will get not creative mode
.
An example would be
give {Count:1b,id:"minecraft:diamond_sword",tag:{Damage:0,display:{Name:'{"italic":false,"extra":[{"text":"Item"}],"text":""}'}}}
Note the lack of []
.
Without any parameters, sends you the player's mode, any of:
spawn
,play
,build
,code
Provide any mode which would work in the /mode
command, so play
, build
, code
, and dev
.
Right now it doesn't send any confirmation, instead you could wait and resend mode
.
An example of a transaction would be.
INC
is from the game to your app
OUT
is from the app to your game
--- CONNECT TO ws://localhost:31375 ---
OUT give {Count:1b,id:"minecraft:stone"}
OUT scopes movement read_plot write_code
--- PLAYER RUNS /auth ---
INC auth
OUT mode code
OUT clear
INC unauthed
OUT size
INC BASIC
OUT place
OUT place H4sIAAAAAAAAAy3MQQqAMAxE0btk7Ql6FXGhddBgTbFGQaR3d0RXYT6P3DKkHJddQnuLjhK+Lc1/g+CEOXdfJioix/ryrrJF12xEczbsni46J4SzbQcpg9qJ4nh/q8WCUYcEqV19ANub6Ot8AAAA
OUT place H4sIAAAAAAAAAy3MQQqAMAxE0btk7Ql6FXGhddBgTbFGQaR3d0RXYT6P3DKkHJddQnuLjhK+Lc1/g+CEOXdfJioix/ryrrJF12xEczbsni46J4SzbQcpg9qJ4nh/q8WCUYcEqV19ANub6Ot8AAAA
OUT place go
INC place done
--- CLOSE ---