-
Notifications
You must be signed in to change notification settings - Fork 10
TemplateString
youyihj edited this page Aug 30, 2024
·
6 revisions
@since 1.18.0
Template string is an enhanced string. It can be embedded with several expressions.
Wrap backquote (`) to define a template string, and use ${}
to embed a expression
val name as string = "world";
print(`hello, ${name}!`); // hello, world!
Most expressions are allowed, including variables, getters, functions, but nested template string is not supported currently.
import crafttweaker.event.EntityLivingAttackedEvent;
events.onEntityLivingAttacked(function(event as EntityLivingAttackedEvent) {
val entity = event.entity;
print(`entity ${typeof(entity)} ${entity.x} ${entity.y} ${entity.z}`);
});
Similar ability is also implemented in bracket handlers. You don't need itemUtils or IGame
functions anymore.
- Only CraftTweaker and ContentTweaker standard bracket handlers are supported.
- About item bracket handler,
item:
prefix can not be omitted.
import crafttweaker.item.IItemStack;
function getIngot(type as string) as IItemStack {
return <ore:ingot${type}>.firstItem;
}
print(getIngot("Iron").commandString); // <item:minecraft:iron_ingot>
print(getIngot("Gold").commandString); // <item:minecraft:gold_ingot>
// prints display name of all wools
for i in 0 .. 16 {
// item: prefix can't be removed
print(<item:minecraft:wool:${i}>.displayName);
}
- GlobalFunctions
- ScriptReloading
- SuppressErrorPreprocessor
- HardFailPreprocessor
- OrderlyMap
- IData Deep Update
- Template String
- Native Method Access
- Mixin
- CrTI18n
- CrTUUID
- CrTItemHandler
- CrTLiquidHandler
- ILiquidTankProperties
- StringList
- HexHelper
- StaticString
- Catenation
- PersistedCatenation
- PlayerStat
- IStatFormatter
- GameRuleHelper
- ZenCommand
- ZenCommandTree
- ZenUtilsCommandSender
- IGetCommandUsage
- ICommandExecute
- IGetTabCompletion
- CommandUtils