▶️ ЗАБЕРИ СВОИ 8 ПОДАРКОВ 🎁 ПРИ СОЗДАНИИ СВОЕГО МАЙНКРАФТ СЕРВЕРА
Моды/Text Placeholder API Expressions

Text Placeholder API Expressions

Adds math, conditional, and string manipulation expressions to Text Placeholder API.

Оцените первым
1.5K
5

Text Placeholder API Expressions

Adds math, conditional, and string manipulation expressions to Text Placeholder API.
This project uses Keval for parsing math expressions, and would have been exponentially more difficult without it. Show the author some love and star his repo!

Using Placeholders In Expressions

This extension uses the ${category:placeholder} syntax to allow supplying placeholders that resolve to numbers as components.
For example; to display a player's health as a percentage (such as within the tab list), you could use the following:
%expr:math ${player:health} * 100 / ${player:max_health}%%

Math Placeholder

The bulk of the additions (no pun intended) in this extension are accessed through the expr:math placeholder.

You can think of this placeholder as handling three distinct 'types':

  • Components, such as numbers, functions, constants, and placeholders that resolve to numbers.
  • Binary operators, such as addition or subtraction, which go between two components.
  • Unary operators, such as negation and factorial, which apply to a single component.

Components and operators supplied by this extension

Binary operators are applied between two components.

Binary OperatorFunctionExampleResult
+Add%expr:math 2 + 2%4
-Subtract%expr:math 4 - 1%3
*Multiply%expr:math 3 * 3%9
/Divide%expr:math 9 / 4%2.25
^Exponent%expr:math 3 ^ 3%27

Unary operators are applied to a single component.

Unary OperatorFunctionExampleResult
-Negate%expr:math 1 + -1%0
+Identity%expr:math ??%What does this even do
!Factorial%expr:math 5!%120

Functions are components, taking expressions as arguments.

FunctionArgumentsDescriptionExampleResult
mod2Modulo / remainder%expr:math mod(7, 2)%1
neg1Negate / invert (Like unary -)%expr:math neg(10)%-10
abs1Absolute value%expr:math abs(-10)%10
sqrt1Square root%expr:math sqrt(34)%5.8309
cbrt1Cube root%expr:math cbrt(30)%3.1072
exp1Exponential%expr:math exp(4)%54.5981
ln1Natural logarithm%expr:math ln(4)%1.3862
log101Base 10 logarithm%expr:math log10(4)%0.6020
log21Base 2 logarithm%expr:math log2(4)%2
rad1Degrees to radians%expr:math rad(30)%0.5235
sin1Sine%expr:math sin(rad(30))%0.4999
cos1Cosine%expr:math cos(rad(30))%0.8660
tan1Tangent%expr:math tan(rad(30))%0.5773
asin1Arcsine%expr:math asin(rad(30))%0.5510
acos1Arccosine%expr:math acos(rad(30))%1.0197
atan1Arctangent%expr:math atan(rad(30))%0.4823
ceil1Round up%expr:math ceil(0.4)%1
floor1Round down%expr:math floor(0.6)%0
round1Round%expr:math round(0.5)%1
min2+Smallest argument%expr:math min(1, 0.3, 7)%0.3
max2+Largest argument%expr:math max(1, 0.3, 7)%7
avg2+Average of arguments%expr:math avg(1, 0.3, 7)%2.7666

Constants are components which resolve to a constant value.

ConstantDescription
PIπ
eEuler's number

Conditional Placeholders

Arguments to these placeholders must be separated by semicolons (;) instead of spaces.

%expr:ifeq%

Test whether a and b are equal, and return c or d depending on the result.

%expr:ifeq aIsMath a bIsMath b cIsMath c dIsMath d%

ArgumentDescription
aIsMathWhether to parse a as a math expression. Either true or false.
aMath expression or text to compare against b. If treated as text, and spaces at the start or end of the string are removed.
bIsMathWhether to parse b as a math expression. Either true or false.
bMath expression or text to compare against a. If treated as text, and spaces at the start or end of the string are removed.
cIsMathWhether to parse c as a math expression. Either true or false.
cMath expression or text to use if a and b are equal.
dIsMathWhether to parse d as a math expression. Either true or false.
dMath expression or text to use if a and b are not equal.

Example

Player %expr:ifeq false; ${player:equipment_slot mainhand}; false; Diamond Sword; false; is; false; is not% holding a Diamond Sword.

ConditionResult
%player:equipment_slot mainhand% == "Diamond Sword"Player is holding a Diamond Sword.
%player:equipment_slot mainhand% != "Diamond Sword"Player is not holding a Diamond Sword.

%expr:iflt%

Test whether a is less than b, and return c or d depending on the result.

%expr:iflt a b cIsMath c dIsMath d%

ArgumentDescription
aMath expression to compare against b.
bMath expression to compare against a.
cIsMathWhether to parse c as a math expression. Either true or false.
cMath expression or text to use if a is less than b.
dIsMathWhether to parse d as a math expression. Either true or false.
dMath expression or text to use if a is not less than b.

Example

Player is in %expr:iflt ${player:health}; 14; false; poor; false; good% health

ConditionResult
%player:health% < 14Player is in poor health
%player:health% >= 14Player is in good health

%expr:ifgt%

Test whether a is greater than b, and return c or d depending on the result.

%expr:ifgt a b cIsMath c dIsMath d%

ArgumentDescription
aMath expression to compare against b.
bMath expression to compare against a.
cIsMathWhether to parse c as a math expression. Either true or false.
cMath expression or text to use if a is greater than b.
dIsMathWhether to parse d as a math expression. Either true or false.
dMath expression or text to use if a is not greater than b.

Example

Health: %expr:ifgt ${player:health}; 4; true; ${player:health} * 100 / ${player:max_health}%; false; Nearly dead!%

ConditionResult
%player:health% == 15Health: 75
%player:health% == 14Health: 70
%player:health% <= 4Health: Nearly dead!

String Placeholders

Arguments to these placeholders must be separated by semicolons (;) instead of spaces.

%expr:pad%, %expr:padleft%, and %expr:padright%

Pad one or both sides of str with c until the string length reaches length.

%expr:pad length; str; c% %expr:padleft length; str; c% %expr:padright length; str; c%

ArgumentDescription
lengthMath expression, target length of the padded string.
strSource string to pad. Spaces at the start or end of the string are removed.
cCharacter to use for padding.

Example

%expr:padleft 2 ${server:online} 0% / %server:max_players%

ConditionResult
%server:online% == 1212 / 40
%server:online% == 404 / 40

%expr:padmatch%, %expr:padmatchleft%, and %expr:padmatchright%

Pad one or both sides of str with c until the string length matches the length of match.

%expr:padmatch match; str; c% %expr:padmatchleft match; str; c% %expr:padmatchright match; str; c%

ArgumentDescription
matchString to match the length of. Spaces at the start or end of the string are removed.
strSource string to pad. Spaces at the start or end of the string are removed.
cCharacter to use for padding.

Example

%expr:padmatchleft ${server:max_players} ${server:online} 0% / %server:max_players%

ConditionResult
%server:max_players% == 40, %server:online% == 404 / 40
%server:max_players% == 100, %server:online% == 4004 / 100

Часто задаваемые вопросы

Совместимость

Minecraft: Java Edition

1.21.x

Платформы

Поддерживаемые окружения

Сервер

Зависимости

Ссылки

Создатели

Детали

Лицензия:
Опубликован:1 год назад
Обновлён:4 месяца назад
Главная