Skip to content

Commit eab6bee

Browse files
committed
some DisplayEntity & TextDisplay Data
1 parent 29652bc commit eab6bee

File tree

6 files changed

+225
-11
lines changed

6 files changed

+225
-11
lines changed

src/main/java/org/spongepowered/api/data/Keys.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
import org.spongepowered.api.entity.display.BillboardType;
117117
import org.spongepowered.api.entity.display.DisplayEntity;
118118
import org.spongepowered.api.entity.display.ItemDisplayType;
119+
import org.spongepowered.api.entity.display.TextAlignment;
119120
import org.spongepowered.api.entity.display.TextDisplay;
120121
import org.spongepowered.api.entity.explosive.EndCrystal;
121122
import org.spongepowered.api.entity.explosive.Explosive;
@@ -505,6 +506,9 @@ public final class Keys {
505506
* <p>In vanilla minecraft is this value in steps of 1/15 from 0 to 1.</p>
506507
* <p>For the skylight see {@link #SKY_LIGHT}.</p>
507508
* Readonly
509+
* <p>
510+
* Or the blocklight override for a {@link DisplayEntity}.
511+
* </p>
508512
*/
509513
public static final Key<Value<Integer>> BLOCK_LIGHT = Keys.key(ResourceKey.sponge("block_light"), Integer.class);
510514

@@ -1185,6 +1189,11 @@ public final class Keys {
11851189
*/
11861190
public static final Key<Value<Boolean>> HAS_CHEST = Keys.key(ResourceKey.sponge("has_chest"), Boolean.class);
11871191

1192+
/**
1193+
* Whether the {@link TextDisplay} has a default background.
1194+
*/
1195+
public static final Key<Value<Boolean>> HAS_DEFAULT_BACKGROUND = Keys.key(ResourceKey.sponge("has_default_background"), Boolean.class);
1196+
11881197
/**
11891198
*Whether a {@link Turtle} currently has an egg.
11901199
*/
@@ -1254,6 +1263,11 @@ public final class Keys {
12541263
*/
12551264
public static final Key<Value<Boolean>> HAS_SKYLIGHT = Keys.key(ResourceKey.sponge("has_skylight"), Boolean.class);
12561265

1266+
/**
1267+
* Whether the {@link TextDisplay} has a shadow.
1268+
*/
1269+
public static final Key<Value<Boolean>> HAS_TEXT_SHADOW = Keys.key(ResourceKey.sponge("has_text_shadow"), Boolean.class);
1270+
12571271
/**
12581272
* Whether a server player has viewed the credits.
12591273
*
@@ -2067,6 +2081,11 @@ public final class Keys {
20672081
*/
20682082
public static final Key<Value<Integer>> LIGHT_EMISSION = Keys.key(ResourceKey.sponge("light_emission"), Integer.class);
20692083

2084+
/**
2085+
* The maximum line width of a {@link TextDisplay}.
2086+
*/
2087+
public static final Key<Value<Integer>> LINE_WIDTH = Keys.key(ResourceKey.sponge("line_width"), Integer.class);
2088+
20702089
/**
20712090
* A {@link Llama}'s {@link LlamaType}.
20722091
*/
@@ -2331,6 +2350,11 @@ public final class Keys {
23312350
*/
23322351
public static final Key<Value<Boolean>> ON_GROUND = Keys.key(ResourceKey.sponge("on_ground"), Boolean.class);
23332352

2353+
/**
2354+
* The opacity of a {@link TextDisplay}. 0 to 255
2355+
*/
2356+
public static final Key<Value<Byte>> OPACITY = Keys.key(ResourceKey.sponge("opacity"), Byte.class);
2357+
23342358
/**
23352359
* The {@link Orientation} of an {@link ItemFrame}.
23362360
*/
@@ -2681,6 +2705,11 @@ public final class Keys {
26812705
*/
26822706
public static final Key<Value<Long>> SEED = Keys.key(ResourceKey.sponge("structure_seed"), Long.class);
26832707

2708+
/**
2709+
* Whether {@link TextDisplay} are visible through blocks.
2710+
*/
2711+
public static final Key<Value<Boolean>> SEE_THROUGH_BLOCKS = Keys.key(ResourceKey.sponge("see_through_blocks"), Boolean.class);
2712+
26842713
/**
26852714
* The {@link SerializationBehavior} of a {@link WorldTemplate} or {@link ServerWorldProperties}
26862715
* Readonly
@@ -2740,6 +2769,9 @@ public final class Keys {
27402769
* The skylight value at a {@link ServerLocation}.
27412770
* For the blocklight see {@link #BLOCK_LIGHT}.
27422771
* Readonly
2772+
* <p>
2773+
* Or the skylight override for a {@link DisplayEntity}.
2774+
* </p>
27432775
*/
27442776
public static final Key<Value<Integer>> SKY_LIGHT = Keys.key(ResourceKey.sponge("sky_light"), Integer.class);
27452777

@@ -2969,6 +3001,16 @@ public final class Keys {
29693001
*/
29703002
public static final Key<Value<TemperatureModifier>> TEMPERATURE_MODIFIER = Keys.key(ResourceKey.sponge("temperature_modifier"), TemperatureModifier.class);
29713003

3004+
/**
3005+
* The {@link TextAlignment} of a {@link TextDisplay}.
3006+
*/
3007+
public static final Key<Value<TextAlignment>> TEXT_ALIGNMENT = Keys.key(ResourceKey.sponge("text_alignment"), TextAlignment.class);
3008+
3009+
/**
3010+
* The background {@link java.awt.Color} of a {@link TextDisplay}.
3011+
*/
3012+
public static final Key<Value<java.awt.Color>> TEXT_BACKGROUND_COLOR = Keys.key(ResourceKey.sponge("text_background_color"), java.awt.Color.class);
3013+
29723014
/**
29733015
* The remaining fuse time in ticks of a {@link FusedExplosive}.
29743016
* This value may be set to an arbitrary value

src/main/java/org/spongepowered/api/entity/display/DisplayEntity.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,35 @@
2727
import org.spongepowered.api.data.Keys;
2828
import org.spongepowered.api.entity.Entity;
2929

30+
import java.util.Optional;
31+
3032
public interface DisplayEntity extends Entity {
3133

3234
// TODO rotation/transformation?
3335

34-
// TODO interpolation?
36+
// TODO interpolation? textopacity/backgroundcolor
3537

3638
default BillboardType billboardType() {
3739
return this.require(Keys.BILLBOARD_TYPE);
3840
}
39-
//
40-
// default int skyLight() {
41-
// // TODO impl
42-
// return this.require(Keys.SKY_LIGHT);
43-
// }
44-
//
45-
// default int blockLight() {
46-
// // TODO impl
47-
// return this.require(Keys.BLOCK_LIGHT);
48-
// }
41+
42+
/**
43+
* Returns the skylight override.
44+
*
45+
* @return the skylight override
46+
*/
47+
default Optional<Integer> skyLight() {
48+
return this.get(Keys.SKY_LIGHT);
49+
}
50+
51+
/**
52+
* Returns the blocklight override.
53+
*
54+
* @return the blocklight override
55+
*/
56+
default Optional<Integer> blockLight() {
57+
return this.get(Keys.BLOCK_LIGHT);
58+
}
4959

5060
// TODO view_range float/double
5161

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.entity.display;
26+
27+
import org.spongepowered.api.registry.DefaultedRegistryValue;
28+
import org.spongepowered.api.util.annotation.CatalogedBy;
29+
30+
@CatalogedBy(ItemDisplayTypes.class)
31+
public interface TextAlignment extends DefaultedRegistryValue {
32+
33+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.entity.display;
26+
27+
import org.spongepowered.api.ResourceKey;
28+
import org.spongepowered.api.Sponge;
29+
import org.spongepowered.api.registry.DefaultedRegistryReference;
30+
import org.spongepowered.api.registry.Registry;
31+
import org.spongepowered.api.registry.RegistryKey;
32+
import org.spongepowered.api.registry.RegistryScope;
33+
import org.spongepowered.api.registry.RegistryScopes;
34+
import org.spongepowered.api.registry.RegistryTypes;
35+
36+
@SuppressWarnings("unused")
37+
@RegistryScopes(scopes = RegistryScope.GAME)
38+
public final class TextAlignments {
39+
40+
// @formatter:off
41+
// SORTFIELDS:ON
42+
public static final DefaultedRegistryReference<TextAlignment> CENTER = TextAlignments.key(ResourceKey.sponge("center"));
43+
44+
public static final DefaultedRegistryReference<TextAlignment> LEFT = TextAlignments.key(ResourceKey.sponge("left"));
45+
46+
public static final DefaultedRegistryReference<TextAlignment> RIGHT = TextAlignments.key(ResourceKey.sponge("right"));
47+
48+
// SORTFIELDS:OFF
49+
// @formatter:on
50+
private TextAlignments() {
51+
}
52+
53+
public static Registry<TextAlignment> registry() {
54+
return Sponge.game().registry(RegistryTypes.TEXT_ALIGNMENT);
55+
}
56+
57+
private static DefaultedRegistryReference<TextAlignment> key(final ResourceKey location) {
58+
return RegistryKey.of(RegistryTypes.TEXT_ALIGNMENT, location).asDefaultedReference(Sponge::game);
59+
}
60+
}

src/main/java/org/spongepowered/api/entity/display/TextDisplay.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import net.kyori.adventure.text.Component;
2828
import org.spongepowered.api.data.Keys;
2929

30+
import java.awt.Color;
31+
3032
public interface TextDisplay extends DisplayEntity {
3133

3234
/**
@@ -38,4 +40,68 @@ default Component displayedText() {
3840
return this.require(Keys.DISPLAY_NAME);
3941
}
4042

43+
/**
44+
* Gets the maximum line width used to split lines of text.
45+
*
46+
* @return The maximum line width used to split lines of text
47+
*/
48+
default int lineWidth() {
49+
return this.require(Keys.LINE_WIDTH);
50+
}
51+
52+
/**
53+
* Gets the opacity of the displayed text.
54+
*
55+
* @return The opacity of the displayed text
56+
*/
57+
default int textOpacity() {
58+
return this.require(Keys.OPACITY);
59+
}
60+
61+
/**
62+
* Checks if the displayed text is visible through blocks.
63+
*
64+
* @return True if the displayed text is visible through blocks, false otherwise
65+
*/
66+
default boolean canSeeThroughBlocks() {
67+
return this.require(Keys.SEE_THROUGH_BLOCKS);
68+
}
69+
70+
/**
71+
* Checks if the displayed text has a shadow.
72+
*
73+
* @return True if the displayed text has a shadow, false otherwise
74+
*/
75+
default boolean hasShadow() {
76+
return this.require(Keys.HAS_TEXT_SHADOW);
77+
}
78+
79+
/**
80+
* Gets the background color of the displayed text.
81+
* Note that this supports alpha values.
82+
*
83+
* @return The background color of the displayed text
84+
*/
85+
default Color backgroundColor() {
86+
return this.require(Keys.TEXT_BACKGROUND_COLOR);
87+
}
88+
89+
/**
90+
* Gets the background color of the displayed text.
91+
*
92+
* @return The background color of the displayed text
93+
*/
94+
default boolean defaultBackground() {
95+
return this.require(Keys.HAS_DEFAULT_BACKGROUND);
96+
}
97+
98+
/**
99+
* Gets the alignment direction of the displayed text.
100+
*
101+
* @return The alignment direction of the displayed text
102+
*/
103+
default TextAlignment textAlignment() {
104+
return this.require(Keys.TEXT_ALIGNMENT);
105+
}
106+
41107
}

src/main/java/org/spongepowered/api/registry/RegistryTypes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import org.spongepowered.api.entity.attribute.type.AttributeType;
106106
import org.spongepowered.api.entity.display.BillboardType;
107107
import org.spongepowered.api.entity.display.ItemDisplayType;
108+
import org.spongepowered.api.entity.display.TextAlignment;
108109
import org.spongepowered.api.entity.living.monster.boss.dragon.phase.DragonPhaseType;
109110
import org.spongepowered.api.entity.living.player.chat.ChatVisibility;
110111
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
@@ -483,6 +484,8 @@ public final class RegistryTypes {
483484

484485
public static final DefaultedRegistryType<TeleportHelperFilter> TELEPORT_HELPER_FILTER = RegistryTypes.spongeKeyInGame("teleport_helper_filter");
485486

487+
public static final DefaultedRegistryType<TextAlignment> TEXT_ALIGNMENT = RegistryTypes.spongeKeyInGame("text_alignment");
488+
486489
public static final DefaultedRegistryType<TicketType<?>> TICKET_TYPE = RegistryTypes.spongeKeyInGame("ticket_type");
487490

488491
public static final DefaultedRegistryType<TransactionType> TRANSACTION_TYPE = RegistryTypes.spongeKeyInGame("transaction_type");

0 commit comments

Comments
 (0)