Skip to content

Commit 97eed34

Browse files
committed
Update tag/placeholder docs, make player tag support dynamic values
1 parent 1e78cec commit 97eed34

5 files changed

Lines changed: 89 additions & 9 deletions

File tree

docs/user/default-placeholders.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Prior to 1.19, arguments were separated with a slash (`/`) instead of space.
5050
- `%player:objective [objective]%` - The value of player's scoreboard objective.
5151
- `%player:biome%` (2.7.2+) - Biome at player's location
5252
- `%player:biome_raw%` (2.7.2+) - Raw biome id at player's location
53+
- `%player:head%` (2.8.0+) - Shows player's head texture.
5354

5455
### World
5556

docs/user/quicktext.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ Hover tag allows adding simple hover on text. It can be used to display addition
116116

117117
This tag allows you to change font to any build in one or one provided by resource pack.
118118

119-
You can use it by simply adding `#!xml <font '[VALUE]'>`, where `'[VALUE]'` is just a font name.
119+
- `#!xml <font '[VALUE]'>` - Sets font within tagwhere (`'[VALUE]'` is just a font name).
120+
120121
Minecraft has 3 build-in fonts `default`, `uniform` and `alt`.
121122

122123
### Inserting
@@ -155,13 +156,50 @@ This tag allows you to add information about player control keys, with respectin
155156

156157
You can use it with `#!xml <keybind '[VALUE]'>` or `#!xml <keybind value:'[VALUE]'>`, where `'[VALUE]'` is a control key used.
157158

159+
### Atlas (2.8.0+1.21.9+)
160+
161+
!!! question inline end "Atlas"
162+
163+
You can read more about atlases on the [Minecraft Wiki](https://minecraft.wiki/w/Atlas)
164+
165+
!!! note inline end
166+
167+
This tag is self containing, so it doesn't contain a closing tag.
168+
169+
This tag allows you to display a texture from select atlas. If not set correctly, it will show missing
170+
texture.
171+
172+
- `#!xml <atlas '[ATLAS ID]' '[TEXTURE ID]'>` - Quick format of atlas tag.
173+
- `#!xml <atlas atlas:'[ATLAS ID]' texture:'[TEXTURE ID]'>` - Full format of atlas tag.
174+
175+
Where `'[ATLAS ID]'` is a atlas identifier used and `'[TEXURE ID]'` is a texture within that atlas.
176+
177+
### Player (2.8.0+1.21.9+)
178+
!!! note inline end
179+
180+
This tag is self containing, so it doesn't contain a closing tag.
181+
182+
This tag allows you to display a player head. If not set correctly, it will show one of default textures.
183+
184+
- `#!xml <atlas '[NAME / UUID]'>` - Shorthand format for showing player head.
185+
- `#!xml <atlas name:'[NAME]' hat:[BOOLEAN]>` - Show player head by name (and toggle hat).
186+
- `#!xml <atlas uuid:'[NAME]' hat:[BOOLEAN]>` - Show player head by uuid (and toggle hat).
187+
- `#!xml <atlas texture:'[TEXTURE VALUE]' hat:[BOOLEAN]>` - Show player head by raw remote texture value (and toggle hat).
188+
189+
Where `'[NAME]'` is player name,
190+
`'[UUID]'` is player uuid, `'[TEXTURE VALUE]'` is skin texture value (not resource pack one!)
191+
and `[BOOLEAN]` is true or false.
192+
193+
194+
158195
### Gradients
159196

160197
This tag allows you to add gradients to the text. However, it has multiple limitation that can
161198
block its usage. Currently, you can't use dynamic values (translations, control keys, placeholders, etc)
162199
within them, as they require static text.
163200

164201
There 2 types of gradients:
202+
165203
- `#!xml <gradient (type:[type]) [color 1] [color 2] ...>`/`#!xml <gr (type:[type]) [color 1] [color 2] ...>` - I can take multiple colors to move between them
166204
smoothly. You can replace the optional `(type:[type])` with `type:oklab` (default), `type:hvs` or `type:hard` to change how thge gradient is handled
167205
- `#!xml <hard_gradient [color 1] [color 2] ...>`/`#!xml <hgr [color 1] [color 2] ...>` - I can take multiple colors to move between them
@@ -181,6 +219,7 @@ works with placeholders, which gives a bit more flexibility.
181219
This tag can work without arguments making it clear all formatting or with them limiting clearing to selected types.
182220

183221
Examples:
222+
184223
- `#!xml <clear>` - Removes all formatting, leaving only text.
185224
- `#!xml <clear hover>` - Removes all hovers.
186225
- `#!xml <clear hover color>` - Removes all hovers and colors.

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
55
# check these on https://fabricmc.net/use
6-
minecraft_version=1.21.9-rc1
7-
yarn_mappings=1.21.9-rc1+build.2
6+
minecraft_version=1.21.10
7+
yarn_mappings=1.21.10+build.1
88
loader_version=0.17.2
99
loom_version=1.11-SNAPSHOT
1010

1111
# Fabric API
12-
fabric_version=0.133.13+1.21.9
12+
fabric_version=0.135.0+1.21.10
1313

1414
# Mod Properties
15-
mod_version = 2.8.0+1.21.9
15+
mod_version = 2.8.1+1.21.10
1616
maven_group = eu.pb4
1717
archives_base_name = placeholder-api
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package eu.pb4.placeholders.api.node;
2+
3+
import eu.pb4.placeholders.api.ParserContext;
4+
import net.minecraft.component.type.ProfileComponent;
5+
import net.minecraft.text.Text;
6+
import net.minecraft.text.object.PlayerTextObjectContents;
7+
8+
import java.util.UUID;
9+
10+
public record DynamicPlayerHeadNode(TextNode name, boolean hat, Type type) implements TextNode {
11+
@Override
12+
public Text toText(ParserContext context, boolean removeBackslashes) {
13+
var val = this.name.toText(context).getString();
14+
15+
if (type == Type.UUID || type == Type.EITHER) {
16+
try {
17+
return Text.object(new PlayerTextObjectContents(ProfileComponent.ofDynamic(UUID.fromString(val)), hat));
18+
} catch (Throwable e) {
19+
// ignore
20+
}
21+
}
22+
23+
if (type == Type.NAME || type == Type.EITHER) {
24+
return Text.object(new PlayerTextObjectContents(ProfileComponent.ofDynamic(val), hat));
25+
}
26+
27+
return Text.object(new PlayerTextObjectContents(ProfileComponent.ofDynamic(""), hat));
28+
}
29+
30+
public enum Type {
31+
UUID,
32+
NAME,
33+
EITHER
34+
}
35+
}

src/main/java/eu/pb4/placeholders/impl/textparser/BuiltinTags.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,20 @@ public static void register() {
218218
(nodes, data, parser) -> {
219219
var hat = SimpleArguments.bool(data.get("hat"), true);
220220

221-
var next = data.getNext("name", "");
222-
var maybeUuid = data.get("uuid");
223221
var texture = data.get("texture");
224222

225223
if (texture != null) {
226224
PropertyMap map = new PropertyMap(ImmutableMultimap.of("textures", new Property("textures", texture, null)));
227225
return new ObjectNode(new PlayerTextObjectContents(ProfileComponent.ofStatic(new GameProfile(Util.NIL_UUID, "", map)), hat));
228226
}
229227

228+
var next = data.getNext("name", "");
229+
var maybeUuid = data.get("uuid");
230+
231+
if (maybeUuid != null) {
232+
return new DynamicPlayerHeadNode(parser.parseNode(maybeUuid), hat, DynamicPlayerHeadNode.Type.UUID);
233+
}
234+
230235
UUID uuid = null;
231236
if (maybeUuid == null) {
232237
try {
@@ -245,10 +250,10 @@ public static void register() {
245250
}
246251

247252
if (next != null) {
248-
return new ObjectNode(new PlayerTextObjectContents(ProfileComponent.ofDynamic(next), hat));
253+
return new DynamicPlayerHeadNode(parser.parseNode(next), hat, DynamicPlayerHeadNode.Type.EITHER);
249254
}
250255

251-
return new ObjectNode(new AtlasTextObjectContents(emptyId, emptyId));
256+
return new ObjectNode(new PlayerTextObjectContents(ProfileComponent.ofDynamic(""), hat));
252257
}
253258
)
254259
);

0 commit comments

Comments
 (0)