Skip to main content

Painter API

About

Painter API allows you to draw things on the screen, both from server and directly from client. This can allow you to create widgets from server side or effects on screen or in world from client side.

Currently it doesn't support any input, but in future, in-game menus similar to Source engine ones will be supported.

Paintable objects are created from NBT/Json objects and all have an id. If id isn't provided, a random one will be generated. Objects x and z are absolute positions based on screen, but you can align elements in one of the corners of screen. You can bulk add multiple objects in one json object. All properties are optional, but obviously some you should almost always override like size and position for rectangles.

You can edit painter objects with /kubejs painter command, but the recommended way is using player methods - .paint({ object }), .removePainter('id'), .clearPainter(). Painter objects will be cleared when players leave world/server, if its persistent, then it must be re-added in player.logged_in event every time.

When you call paint({...}) the object must contain either valid type to create new object or an underscored key to update existing:

  • event.player.paint({Rectangle: {id: 'example', x: 10, y: 10, w: 20, h: 20}})
  • event.player.paint({_example: {x: 10}})

You can bulk update/create multiple things in same object:

  • event.player.paint({_a: {x: 10}, _b: {x: 30}, Rectangle: {x: 10}})

You can remove object or bulk remove objects separated by space, or clear all of them:

  • event.player.removePainter('a')
  • event.player.removePainter('a b')
  • event.player.clearPainter()

These methods have command alternatives:

  • /kubejs painter add @p {Rectangle: {id: 'example', x: 10, y: 10, w: 20, h: 20}}
  • /kubejs painter remove @p example
  • /kubejs painter clear @p

Underlined objects are not something you can create 

Root

(available for all objects)

  • String id
Screen Object (extends Root)

(available for all screen / 2D objects)

  • Int x
  • Int y
  • Int z
  • Int width
  • Int height
  • Enum align (one of 'top_left', 'top_right', 'bottom_left', 'bottom_right')
  • Enum drawType (one of 'ingame', 'gui', 'always')
Rectangle (extends Screen Object)
  • Color color
  • String texture
  • Float u0
  • Float v0
  • Float u1
  • Float v1
Gradient (extends Screen Object)
  • Color color
  • Color colorT
  • Color colorB
  • Color colorL
  • Color colorR
  • Color colorTL
  • Color colorTR
  • Color colorBL
  • Color colorBR
  • String texture
  • Float u0
  • Float v0
  • Float u1
  • Float v1
Text (extends Screen Object)
  • Text/String text
  • Float scale
  • Color color

Examples

onEvent('player.logged_in', event => {
  event.player.paint({Rectangle:{id: 'example_rectangle', x: 10, y: 10, w: 50, h: 20, color: '#00FF00'}})
  event.player.paint({Text:{id: 'last_message', text: 'No last message', y: 10, align: 'bottom_left'}})
})

onEvent('player.chat', event => {
  // Updates example_rectangle x value and last_message text value to last message + contents from event
  event.player.paint({_example_rectangle: {x: 120}}) 
  event.player.paint({_last_message: {text: `Last message: ${event.message}`}}) 
  // Bulk update, this is the same code as 2 lines above, you can use whichever you like better
  event.player.paint({_example_rectangle: {x: 120}, _last_message: {text: `Last message: ${event.message}`}}) 
})