# Texts and Strings

In Minecraft text in the chat or as title is defined with JSON-data. objD makes the JSON part of it easier by utilizing a few classes:

# TextComponent

TextComponent
String the text displayed (required)
color a the color of the type Color
bold bool whether it is bold
italic bool whether it is italic
underlined bool whether it is underlined
strikethrough bool whether it is strikethrough
obfuscated bool whether it is obfuscated
clickEvent A TextClickEvent to handle left clicks
hoverEvent A TextHoverEvent to handle mouse overs
insertion a String witch is inserted into the input if shift left clicked

Puuh, that are a lot of properties, we'll come to Color, TextClickEvent and TextHoverEvent in a bit.

Example

Title(
	Entity.Player(),
	show: [
		TextComponent("Hello",
			color: Color.White,
			bold: true,
			italic:true,
			underlined: true,
			strikethrough: false,
			obfuscated: false,
			clickEvent: TextClickEvent.open_url("https://stevertus.com"),
			hoverEvent: TextHoverEvent.text([TextComponent("hover me")]),
			insertion: "panic"
		)
	]
)
⇒ title  title [{"text":"Hello","color":"white","bold":true,"italic":true,"underlined":true,"clickEvent":{"action":"open_url","value":"https://stevertus.com"},"hoverEvent":{"action":"text","value":[{text:"hover me"}]}}]

Now, its up to you to decide which is easier to read. There are also some other data sources:

TextComponent.translate
String the translate key (required)
conversionFlags a List containing a String, TextComponent or another List of TextComponents that replace placeholder values(e.g $s)
fallback fallback String when translation is not available
...same properties... from TextComponent
TextComponent.score
Entity the entity with the score(required)
objective Name of the Scoreboard Objective(required)
...same properties... from TextComponent
TextComponent.score(
	Entity.Selected(),
	objective: "myscores",
	color:Color.Black
){"score":{"name": "@s","objective":"myscores"},"color":"black"}
TextComponent.selector
Entity the entity whose name you want to display(required)
...same properties... from TextComponent
TextComponent.selector(
	Entity(name:"hello"),
	color:Color.Black
){"selector":"@e[name=hello]","color":"black"}
TextComponent.entityNbt
Entity the entity which has nbt to display
path the path as a String
interpret bool if nbt should be interpreted as TextComponent(optional)
...same properties... from TextComponent
TextComponent.entityNbt(
	Entity.Selected(),
	path: "CustomName"
	underlined: true
){"entity":"@s","nbt":"CustomName","underlined":true}
TextComponent.blockNbt
Location a location of a block
path the path as a String
interpret bool if nbt should be interpreted as TextComponent(optional)
...same properties... from TextComponent
TextComponent.blockNbt(
	Location.glob(x:5,y:10,z:100),
	path: "Items[0].tag.display.Name"
	interpret: true
){"block":"5 10 100","nbt":"Items[0].tag.display.Name","interpret":true}
TextComponent.storageNbt
String The name of your Storage(including namespace)
path the path as a String
interpret bool if nbt should be interpreted as TextComponent(optional)
...same properties... from TextComponent
TextComponent.storageNbt(
	'mypack:storage1',
	path: 'Custom.Stored.Text'
	interpret: true
)
TextComponent.lineBreak
This inserts a simple line break
TextComponent.none
Just an empty TextComponent, might be used to clear a previous textcomponent
TextComponent.customFont
String a Custom Font Character(\u[HEX]) to insert in your text
...same properties... from TextComponent
TextComponent.customFont("\uFaa4"){"text":"\uFaa4","color":"white"}

WARNING

Attention: This requires a custom negative spaces font by AmberW installed(get it here (opens new window))

TextComponent.space
int the pixel amount you want to move the next TextComponent (positive or negative)
...same properties... from TextComponent

This automatically calculates the custom characters for moving your text horizontally.

Tellraw(
	Entity.All(),
	show:[
		TextComponent.space(478),
		TextComponent("This is moved")
	]
)
⇒ tellraw    [{"text":"\uF82D\uF82C\uF82B\uF829\uF828\uF826"},{"text":"This is moved"}]

# Colors

Color([color_name]) or
Color.[color_name] Uppercase!

See all available colors: https://minecraft.gamepedia.com/Formatting_codes#Color_codes

Examples:

Color.Black,
Color.DarkPurple
Color("gold")
Color('dark_green')

With 1.16 you can also use any rgb color now:

Color("#ff6a00")
Color.fromInt(16738816)
Color.fromRGB(255,106,0)

# TextClickEvent

Fires on left click, Part of TextComponent.

constructors
TextClickEvent.open_url(String) Opens the specified web url
TextClickEvent.run_command(Command) runs the command
TextClickEvent.suggest(Command) puts the command in the chat input
TextClickEvent.change_page(int) turns a books page to the value(just Books!)

# TextHoverEvent

Fires on mouse over, Part of TextComponent.

constructors
TextClickEvent.text(List<TextComponent>) Accepts a new List of TextComponents to display
TextClickEvent.achievement(String) shows achievement
TextClickEvent.item(Item) shows item
TextClickEvent.entity(String,String,String) displays a dummy entity with name, type and UUID(in this order))

# Log

The log widgets displays a console logging in the players chat. That way you can quickly check execution times, score values, numbers, booleans and entities.

constructor
String, Number, Boolean, Score or Entity message to display
to which player you want to send the log(default = Entity.All())
desc a message that is inserted before the value
color the color of the console indicator(default = Color.DarkAqua)

Example:

Log("Hello there!",color:Color.White),
⇒ tellraw  [{"text":"Console > ","color":"white"},{"text":"Hello there!"}]
Log(Score(Entity.Selected(),"objective"),to: Entity.Selected())
⇒ tellraw  [{"text":"Console > ","color":"dark_aqua"},{"score":{"name":"@s","objective":"objective"}}]

You can also use Log.debug and Log.info with the same syntax to get a more prominent and less prominent version.

# Title

To display our TextComponent, we need the /title command and the Title class wrapper.

constructor
selector the Entity for the title to show
show A List of TextComponents to show

Example

Title(
	Entity.Player(),
	show: List<TextComponent>[
		TextComponent(
			"hey",
			color: Color.Black
		)
	]
)
⇒ title  title [{"text":"hey","color":"black"}]

The same goes also for subtitle and actionbar:

Title.subtitle or Title.actionbar
selector the Entity for the title to show
show A List of TextComponents to show

Title.clear clears all titles again:

Title.clear
selector clears title for the selector

Title.times sets the timings

Title.times
selector edit the durations for this selector
fadein the fadein Time (default 1 second)
display the Time the title stays (default 3 seconds)
fadeout the fadeout Time in ticks(default 1 second)

And also a resetter for that:

Title.resetTimes
selector resets times for this selector

Examples:

Title.actionbar(
	Entity.All(),
	show: [
		TextComponent("hey")
	]
)
⇒ title  actionbar [{"text":"hey"}]
Title.clear(Entity())
⇒ title  clear

Title.times(Entity.All(),fadein:30.ticks,display:2.seconds,fadeout:1.seconds)
⇒ title  times 30 2s 1s

Title.resetTimes(Entity.All())
⇒ title  reset

# Tellraw

The Tellraw class is very similar to the Title class, but shows its texts in the chat:

constructor
selector the Entity for the text to show
show A List of TextComponents to show

Example

Tellraw(
	Entity.Player(),
	show: List<TextComponent>[
		TextComponent(
			"hey",
			color: Color.Black
		)
	]
)
⇒ tellraw  [{"text":"hey","color":"black"}]

# Item.Book

This provides a book generator to use TextComponents with Books.

Item.Book
List of BookPage content of the pages
title a String to give the book a title(optional)
author displays an author message (optional)
... same as Item

The page itself is another class:

BookPage
content either a String, TextComponent or List of TextComponents

Or with a custom font character:

BookPage.customFont
String your custom character(\u[HEX])

A possible book could look like this:

Item.Book(
 [
   BookPage("This is the title page"),
   BookPage(
     TextComponent("Colored text",color:Color.Blue),
   ),
   BookPage.customFont("\uEaa2"),
   BookPage([
     TextComponent("one text"),
     TextComponent(
	     "another clickable text",
	     clickEvent:TextClickEvent.change_page(0)
     )
   ])
 ],
 title: "my book",
 lore: [TextComponent("This is my description")]
)
⇒ minecraft:written_book{"title":"my book","author":"","pages":["[{\"text\":\"This is the title page\"}]","[{\"text\":\"Colored text\",\"color\":\"blue\"}]","[{\"text\":\"\uEaa2\",\"color\":\"white\"}]","[{\"text\":\"one text\"},{\"text\":\"another clickable text\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"0\"}}]"],"display":{"Lore":["{\"text\":\"This is my description\"}"]}}

# Bossbar

The Bossbar shows up on the top of a specific player screen and displays a text with a value bar.

constructor
String id of the bossbar(tip: use [namespace]:id to avoid interference)
name a String for the displayed text(optional)

This alone would add a new bossbar to the game:

Bossbar("test:mybar","This is my bar")
⇒ bossbar add test:mybar {"text":"This is my bar"}

To modifiy some properties, there are some methods on the Bossbar to change the output:

# Methods

These methods give a new Widget that performs the action, the original widget does not change

remove - removes the selected bossbar in the game show - takes in an entity and shows the bossbar for the selected players get - gets an BossbarOption of the specified Bossbar

BossbarOption.max, BossbarOption.value, BossbarOption.visible or BossbarOption.players

set sets an option of the bossbar
name displayed String
nameTexts a List of TextComponents that override the name with more control
color the Color of the Bossbar
style a Style Mode
value the displayed value
max the maximum amount of the displayed value
visible bool if the bossbar is visible
players the Entityselector to which the bossbar is displayed

The set method generates multiple commands:

Bossbar("test:mybar").set(
	name:"My name",
	value: 5,
	max: 10,
	color: Color.Red,
	players: Entity.All()
)
⇒ bossbar set test:mybar name {"text":"My name"}
⇒ bossbar set test:mybar color red
⇒ bossbar set test:mybar value 5
⇒ bossbar set test:mybar max 10
⇒ bossbar set test:mybar players 
Last Updated: 6/17/2023, 11:39:58 PM