Display .java

net.minecraft.world.entity.Display (class, 1036 lines): members: DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID, noCulling, RenderState.

net.minecraft.world.entityclass1,036 linescommonextends Entity38.2 KB

API Surface (83)

void onSyncedDataUpdated(final EntityDataAccessor<?> accessor)
boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage)
void tick()
InterpolationHandler createInterpolationHandler()
void defineSynchedData(final SynchedEntityData.Builder entityData)
void readAdditionalSaveData(final ValueInput input)
void setTransformation(final Transformation transformation)
void addAdditionalSaveData(final ValueOutput output)
AABB getInterpolatedBoundingBox(final float partialTicks)
boolean affectedByCulling()
PushReaction getPistonPushReaction()
boolean isIgnoringBlockTriggers()
void setTransformationInterpolationDuration(final int duration)
int getTransformationInterpolationDuration()
void setTransformationInterpolationDelay(final int ticks)
int getTransformationInterpolationDelay()
void setPosRotInterpolationDuration(final int duration)
int getPosRotInterpolationDuration()
void setBillboardConstraints(final Display.BillboardConstraints constraints)
Display.BillboardConstraints getBillboardConstraints()
void setBrightnessOverride(final @Nullable Brightness brightness)
int getPackedBrightnessOverride()
void setViewRange(final float range)
float getViewRange()
void setShadowRadius(final float size)
float getShadowRadius()
void setShadowStrength(final float strength)
float getShadowStrength()
void setWidth(final float width)
float getWidth()
void setHeight(final float width)
int getGlowColorOverride()
void setGlowColorOverride(final int value)
float calculateInterpolationProgress(final float partialTickTime)
float getHeight()
void setPos(final double x, final double y, final double z)
boolean shouldRenderAtSqrDistance(final double distanceSqr)
int getTeamColor()
String getSerializedName()
void defineSynchedData(final SynchedEntityData.Builder entityData)
void onSyncedDataUpdated(final EntityDataAccessor<?> accessor)
BlockState getBlockState()
void setBlockState(final BlockState blockState)
void readAdditionalSaveData(final ValueInput input)
void addAdditionalSaveData(final ValueOutput output)
void updateRenderSubState(final boolean shouldInterpolate, final float progress)
record BlockRenderState(BlockState blockState)
int get(final float progress)
void defineSynchedData(final SynchedEntityData.Builder entityData)
void onSyncedDataUpdated(final EntityDataAccessor<?> accessor)
ItemStack getItemStack()
void setItemStack(final ItemStack item)
void setItemTransform(final ItemDisplayContext transform)
ItemDisplayContext getItemTransform()
void readAdditionalSaveData(final ValueInput input)
void addAdditionalSaveData(final ValueOutput output)
void updateRenderSubState(final boolean shouldInterpolate, final float progress)
record ItemRenderState(ItemStack itemStack, ItemDisplayContext itemTransform)
float get(final float progress)
int get(final float progress)
record RenderState(Display.GenericInterpolator<Transformation> transformation, Display.BillboardConstraints billboardConstraints, int brightnessOverride, Display.FloatInterpolator shadowRadius, Display.FloatInterpolator shadowStrength, int glowColorOverride)
void defineSynchedData(final SynchedEntityData.Builder entityData)
void onSyncedDataUpdated(final EntityDataAccessor<?> accessor)
Component getText()
void setText(final Component text)
int getLineWidth()
void setLineWidth(final int width)
byte getTextOpacity()
void setTextOpacity(final byte opacity)
int getBackgroundColor()
void setBackgroundColor(final int color)
byte getFlags()
void setFlags(final byte flags)
void readAdditionalSaveData(final ValueInput input)
void addAdditionalSaveData(final ValueOutput output)
void updateRenderSubState(final boolean shouldInterpolate, final float progress)
Display.TextDisplay.CachedInfo cacheDisplay(final Display.TextDisplay.LineSplitter splitter)
Display.TextDisplay.Align getAlign(final byte flags)
String getSerializedName()
record CachedInfo(List<Display.TextDisplay.CachedLine> lines, int width)
record CachedLine(FormattedCharSequence contents, int width)
record TextRenderState(Component text, int lineWidth, Display.IntInterpolator textOpacity, Display.IntInterpolator backgroundColor, byte flags)
Transformation get(final float progress)

Fields & Constants (53)

LOGGER
NO_BRIGHTNESS_OVERRIDE
DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID
DATA_TRANSFORMATION_INTERPOLATION_DURATION_ID
DATA_POS_ROT_INTERPOLATION_DURATION_ID
DATA_TRANSLATION_ID
DATA_SCALE_ID
DATA_LEFT_ROTATION_ID
DATA_RIGHT_ROTATION_ID
DATA_BILLBOARD_RENDER_CONSTRAINTS_ID
DATA_BRIGHTNESS_OVERRIDE_ID
DATA_VIEW_RANGE_ID
DATA_SHADOW_RADIUS_ID
DATA_SHADOW_STRENGTH_ID
DATA_WIDTH_ID
DATA_HEIGHT_ID
DATA_GLOW_COLOR_OVERRIDE_ID
RENDER_STATE_IDS
INITIAL_TRANSFORMATION_INTERPOLATION_DURATION
INITIAL_TRANSFORMATION_START_INTERPOLATION
INITIAL_POS_ROT_INTERPOLATION_DURATION
INITIAL_SHADOW_RADIUS
INITIAL_SHADOW_STRENGTH
INITIAL_VIEW_RANGE
INITIAL_WIDTH
INITIAL_HEIGHT
NO_GLOW_COLOR_OVERRIDE
TAG_POS_ROT_INTERPOLATION_DURATION
TAG_TRANSFORMATION_INTERPOLATION_DURATION
TAG_TRANSFORMATION_START_INTERPOLATION
TAG_TRANSFORMATION
TAG_BILLBOARD
TAG_BRIGHTNESS
TAG_VIEW_RANGE
TAG_SHADOW_RADIUS
TAG_SHADOW_STRENGTH
TAG_WIDTH
TAG_HEIGHT
TAG_GLOW_COLOR_OVERRIDE
interpolationStartClientTick
interpolationDuration
lastProgress
cullingBoundingBox
noCulling
updateRenderState
updateStartTick
updateInterpolationDuration
renderState
transformation
billboardConstraints
brightnessOverride
shadowRadius
shadowStrength

String literals (28)

"teleport_duration"
"interpolation_duration"
"start_interpolation"
"transformation"
"billboard"
"brightness"
"view_range"
"shadow_radius"
"shadow_strength"
"width"
"height"
"glow_color_override"
"fixed"
"vertical"
"horizontal"
"center"
"block_state"
"item"
"item_display"
"line_width"
"text_opacity"
"background"
"shadow"
"see_through"

Full Source

Display.java1036 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity;
2
3
import com.mojang.logging.LogUtils;
4
import com.mojang.math.Transformation;
5
import com.mojang.serialization.Codec;
6
import it.unimi.dsi.fastutil.ints.IntSet;
7
import java.util.List;
8
import java.util.Optional;
9
import java.util.function.IntFunction;
10
import net.minecraft.commands.CommandSourceStack;
11
import net.minecraft.network.chat.Component;
12
import net.minecraft.network.chat.ComponentSerialization;
13
import net.minecraft.network.chat.ComponentUtils;
14
import net.minecraft.network.chat.ResolutionContext;
15
import net.minecraft.network.syncher.EntityDataAccessor;
16
import net.minecraft.network.syncher.EntityDataSerializers;
17
import net.minecraft.network.syncher.SynchedEntityData;
18
import net.minecraft.server.level.ServerLevel;
19
import net.minecraft.server.permissions.LevelBasedPermissionSet;
20
import net.minecraft.util.ARGB;
21
import net.minecraft.util.Brightness;
22
import net.minecraft.util.ByIdMap;
23
import net.minecraft.util.FormattedCharSequence;
24
import net.minecraft.util.Mth;
25
import net.minecraft.util.StringRepresentable;
26
import net.minecraft.world.damagesource.DamageSource;
27
import net.minecraft.world.item.ItemDisplayContext;
28
import net.minecraft.world.item.ItemStack;
29
import net.minecraft.world.level.Level;
30
import net.minecraft.world.level.block.Blocks;
31
import net.minecraft.world.level.block.state.BlockState;
32
import net.minecraft.world.level.material.PushReaction;
33
import net.minecraft.world.level.storage.ValueInput;
34
import net.minecraft.world.level.storage.ValueOutput;
35
import net.minecraft.world.phys.AABB;
36
import org.joml.Quaternionf;
37
import org.joml.Quaternionfc;
38
import org.joml.Vector3f;
39
import org.joml.Vector3fc;
40
import org.jspecify.annotations.Nullable;
41
import org.slf4j.Logger;
42
43
/**
44
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
45
 */
46
public abstract class Display extends Entity {
47
	private static final Logger LOGGER = LogUtils.getLogger();
48
	public static final int NO_BRIGHTNESS_OVERRIDE = -1;
49
	private static final EntityDataAccessor<Integer> DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID = SynchedEntityData.defineId(
50
		Display.class, EntityDataSerializers.INT
51
	);
52
	private static final EntityDataAccessor<Integer> DATA_TRANSFORMATION_INTERPOLATION_DURATION_ID = SynchedEntityData.defineId(
53
		Display.class, EntityDataSerializers.INT
54
	);
55
	private static final EntityDataAccessor<Integer> DATA_POS_ROT_INTERPOLATION_DURATION_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.INT);
56
	private static final EntityDataAccessor<Vector3fc> DATA_TRANSLATION_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.VECTOR3);
57
	private static final EntityDataAccessor<Vector3fc> DATA_SCALE_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.VECTOR3);
58
	private static final EntityDataAccessor<Quaternionfc> DATA_LEFT_ROTATION_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.QUATERNION);
59
	private static final EntityDataAccessor<Quaternionfc> DATA_RIGHT_ROTATION_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.QUATERNION);
60
	private static final EntityDataAccessor<Byte> DATA_BILLBOARD_RENDER_CONSTRAINTS_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.BYTE);
61
	private static final EntityDataAccessor<Integer> DATA_BRIGHTNESS_OVERRIDE_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.INT);
62
	private static final EntityDataAccessor<Float> DATA_VIEW_RANGE_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.FLOAT);
63
	private static final EntityDataAccessor<Float> DATA_SHADOW_RADIUS_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.FLOAT);
64
	private static final EntityDataAccessor<Float> DATA_SHADOW_STRENGTH_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.FLOAT);
65
	private static final EntityDataAccessor<Float> DATA_WIDTH_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.FLOAT);
66
	private static final EntityDataAccessor<Float> DATA_HEIGHT_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.FLOAT);
67
	private static final EntityDataAccessor<Integer> DATA_GLOW_COLOR_OVERRIDE_ID = SynchedEntityData.defineId(Display.class, EntityDataSerializers.INT);
68
	private static final IntSet RENDER_STATE_IDS = IntSet.of(
69
		DATA_TRANSLATION_ID.id(),
70
		DATA_SCALE_ID.id(),
71
		DATA_LEFT_ROTATION_ID.id(),
72
		DATA_RIGHT_ROTATION_ID.id(),
73
		DATA_BILLBOARD_RENDER_CONSTRAINTS_ID.id(),
74
		DATA_BRIGHTNESS_OVERRIDE_ID.id(),
75
		DATA_SHADOW_RADIUS_ID.id(),
76
		DATA_SHADOW_STRENGTH_ID.id()
77
	);
78
	private static final int INITIAL_TRANSFORMATION_INTERPOLATION_DURATION = 0;
79
	private static final int INITIAL_TRANSFORMATION_START_INTERPOLATION = 0;
80
	private static final int INITIAL_POS_ROT_INTERPOLATION_DURATION = 0;
81
	private static final float INITIAL_SHADOW_RADIUS = 0.0F;
82
	private static final float INITIAL_SHADOW_STRENGTH = 1.0F;
83
	private static final float INITIAL_VIEW_RANGE = 1.0F;
84
	private static final float INITIAL_WIDTH = 0.0F;
85
	private static final float INITIAL_HEIGHT = 0.0F;
86
	private static final int NO_GLOW_COLOR_OVERRIDE = -1;
87
	public static final String TAG_POS_ROT_INTERPOLATION_DURATION = "teleport_duration";
88
	public static final String TAG_TRANSFORMATION_INTERPOLATION_DURATION = "interpolation_duration";
89
	public static final String TAG_TRANSFORMATION_START_INTERPOLATION = "start_interpolation";
90
	public static final String TAG_TRANSFORMATION = "transformation";
91
	public static final String TAG_BILLBOARD = "billboard";
92
	public static final String TAG_BRIGHTNESS = "brightness";
93
	public static final String TAG_VIEW_RANGE = "view_range";
94
	public static final String TAG_SHADOW_RADIUS = "shadow_radius";
95
	public static final String TAG_SHADOW_STRENGTH = "shadow_strength";
96
	public static final String TAG_WIDTH = "width";
97
	public static final String TAG_HEIGHT = "height";
98
	public static final String TAG_GLOW_COLOR_OVERRIDE = "glow_color_override";
99
	private long interpolationStartClientTick = -2147483648L;
100
	private int interpolationDuration;
101
	private float lastProgress;
102
	private AABB cullingBoundingBox;
103
	private boolean noCulling = true;
104
	protected boolean updateRenderState;
105
	private boolean updateStartTick;
106
	private boolean updateInterpolationDuration;
107
	private Display.@Nullable RenderState renderState;
108
109
	public Display(final EntityType<?> type, final Level level) {
110
		super(type, level);
111
		this.noPhysics = true;
112
		this.cullingBoundingBox = this.getBoundingBox();
113
	}
114
115
	@Override
116
	public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
117
		super.onSyncedDataUpdated(accessor);
118
		if (DATA_HEIGHT_ID.equals(accessor) || DATA_WIDTH_ID.equals(accessor)) {
119
			this.updateCulling();
120
		}
121
122
		if (DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID.equals(accessor)) {
123
			this.updateStartTick = true;
124
		}
125
126
		if (DATA_POS_ROT_INTERPOLATION_DURATION_ID.equals(accessor) && this.interpolationHandler instanceof LinearInterpolationHandler interpolation) {
127
			interpolation.setInterpolationLength(this.getPosRotInterpolationDuration());
128
		}
129
130
		if (DATA_TRANSFORMATION_INTERPOLATION_DURATION_ID.equals(accessor)) {
131
			this.updateInterpolationDuration = true;
132
		}
133
134
		if (RENDER_STATE_IDS.contains(accessor.id())) {
135
			this.updateRenderState = true;
136
		}
137
	}
138
139
	@Override
140
	public final boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
141
		return false;
142
	}
143
144
	private static Transformation createTransformation(final SynchedEntityData entityData) {
145
		Vector3fc translation = entityData.get(DATA_TRANSLATION_ID);
146
		Quaternionfc leftRotation = entityData.get(DATA_LEFT_ROTATION_ID);
147
		Vector3fc scale = entityData.get(DATA_SCALE_ID);
148
		Quaternionfc rightRotation = entityData.get(DATA_RIGHT_ROTATION_ID);
149
		return new Transformation(translation, leftRotation, scale, rightRotation);
150
	}
151
152
	@Override
153
	public void tick() {
154
		Entity vehicle = this.getVehicle();
155
		if (vehicle != null && vehicle.isRemoved()) {
156
			this.stopRiding();
157
		}
158
159
		if (this.level().isClientSide()) {
160
			if (this.updateStartTick) {
161
				this.updateStartTick = false;
162
				int interpolationStartDelta = this.getTransformationInterpolationDelay();
163
				this.interpolationStartClientTick = this.tickCount + interpolationStartDelta;
164
			}
165
166
			if (this.updateInterpolationDuration) {
167
				this.updateInterpolationDuration = false;
168
				this.interpolationDuration = this.getTransformationInterpolationDuration();
169
			}
170
171
			if (this.updateRenderState) {
172
				this.updateRenderState = false;
173
				boolean shouldInterpolate = this.interpolationDuration != 0;
174
				if (shouldInterpolate && this.renderState != null) {
175
					this.renderState = this.createInterpolatedRenderState(this.renderState, this.lastProgress);
176
				} else {
177
					this.renderState = this.createFreshRenderState();
178
				}
179
180
				this.updateRenderSubState(shouldInterpolate, this.lastProgress);
181
			}
182
		}
183
	}
184
185
	@Override
186
	protected InterpolationHandler createInterpolationHandler() {
187
		return LinearInterpolationHandler.create(this, 0);
188
	}
189
190
	protected abstract void updateRenderSubState(boolean shouldInterpolate, float progress);
191
192
	@Override
193
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
194
		entityData.define(DATA_POS_ROT_INTERPOLATION_DURATION_ID, 0);
195
		entityData.define(DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID, 0);
196
		entityData.define(DATA_TRANSFORMATION_INTERPOLATION_DURATION_ID, 0);
197
		entityData.define(DATA_TRANSLATION_ID, new Vector3f());
198
		entityData.define(DATA_SCALE_ID, new Vector3f(1.0F, 1.0F, 1.0F));
199
		entityData.define(DATA_RIGHT_ROTATION_ID, new Quaternionf());
200
		entityData.define(DATA_LEFT_ROTATION_ID, new Quaternionf());
201
		entityData.define(DATA_BILLBOARD_RENDER_CONSTRAINTS_ID, Display.BillboardConstraints.FIXED.getId());
202
		entityData.define(DATA_BRIGHTNESS_OVERRIDE_ID, -1);
203
		entityData.define(DATA_VIEW_RANGE_ID, 1.0F);
204
		entityData.define(DATA_SHADOW_RADIUS_ID, 0.0F);
205
		entityData.define(DATA_SHADOW_STRENGTH_ID, 1.0F);
206
		entityData.define(DATA_WIDTH_ID, 0.0F);
207
		entityData.define(DATA_HEIGHT_ID, 0.0F);
208
		entityData.define(DATA_GLOW_COLOR_OVERRIDE_ID, -1);
209
	}
210
211
	@Override
212
	protected void readAdditionalSaveData(final ValueInput input) {
213
		this.setTransformation(input.read("transformation", Transformation.EXTENDED_CODEC).orElse(Transformation.IDENTITY));
214
		this.setTransformationInterpolationDuration(input.getIntOr("interpolation_duration", 0));
215
		this.setTransformationInterpolationDelay(input.getIntOr("start_interpolation", 0));
216
		int teleportDuration = input.getIntOr("teleport_duration", 0);
217
		this.setPosRotInterpolationDuration(Mth.clamp(teleportDuration, 0, 59));
218
		this.setBillboardConstraints(input.read("billboard", Display.BillboardConstraints.CODEC).orElse(Display.BillboardConstraints.FIXED));
219
		this.setViewRange(input.getFloatOr("view_range", 1.0F));
220
		this.setShadowRadius(input.getFloatOr("shadow_radius", 0.0F));
221
		this.setShadowStrength(input.getFloatOr("shadow_strength", 1.0F));
222
		this.setWidth(input.getFloatOr("width", 0.0F));
223
		this.setHeight(input.getFloatOr("height", 0.0F));
224
		this.setGlowColorOverride(input.getIntOr("glow_color_override", -1));
225
		this.setBrightnessOverride(input.read("brightness", Brightness.CODEC).orElse(null));
226
	}
227
228
	/**
229
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
230
	 */
231
	public final void setTransformation(final Transformation transformation) {
232
		this.entityData.set(DATA_TRANSLATION_ID, transformation.translation());
233
		this.entityData.set(DATA_LEFT_ROTATION_ID, transformation.leftRotation());
234
		this.entityData.set(DATA_SCALE_ID, transformation.scale());
235
		this.entityData.set(DATA_RIGHT_ROTATION_ID, transformation.rightRotation());
236
	}
237
238
	@Override
239
	protected void addAdditionalSaveData(final ValueOutput output) {
240
		output.store("transformation", Transformation.EXTENDED_CODEC, createTransformation(this.entityData));
241
		output.store("billboard", Display.BillboardConstraints.CODEC, this.getBillboardConstraints());
242
		output.putInt("interpolation_duration", this.getTransformationInterpolationDuration());
243
		output.putInt("teleport_duration", this.getPosRotInterpolationDuration());
244
		output.putFloat("view_range", this.getViewRange());
245
		output.putFloat("shadow_radius", this.getShadowRadius());
246
		output.putFloat("shadow_strength", this.getShadowStrength());
247
		output.putFloat("width", this.getWidth());
248
		output.putFloat("height", this.getHeight());
249
		output.putInt("glow_color_override", this.getGlowColorOverride());
250
		output.storeNullable("brightness", Brightness.CODEC, this.getBrightnessOverride());
251
	}
252
253
	@Override
254
	public AABB getInterpolatedBoundingBox(final float partialTicks) {
255
		return this.xOld == this.getX() && this.yOld == this.getY() && this.zOld == this.getZ()
256
			? this.cullingBoundingBox
257
			: this.cullingBoundingBox
258
				.move(
259
					Mth.lerp(partialTicks, this.xOld, this.getX()) - this.getX(),
260
					Mth.lerp(partialTicks, this.yOld, this.getY()) - this.getY(),
261
					Mth.lerp(partialTicks, this.zOld, this.getZ()) - this.getZ()
262
				);
263
	}
264
265
	public boolean affectedByCulling() {
266
		return !this.noCulling;
267
	}
268
269
	@Override
270
	public PushReaction getPistonPushReaction() {
271
		return PushReaction.IGNORE_ENTITY;
272
	}
273
274
	@Override
275
	public boolean isIgnoringBlockTriggers() {
276
		return true;
277
	}
278
279
	public Display.@Nullable RenderState renderState() {
280
		return this.renderState;
281
	}
282
283
	/**
284
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
285
	 */
286
	public final void setTransformationInterpolationDuration(final int duration) {
287
		this.entityData.set(DATA_TRANSFORMATION_INTERPOLATION_DURATION_ID, duration);
288
	}
289
290
	/**
291
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
292
	 */
293
	public final int getTransformationInterpolationDuration() {
294
		return this.entityData.get(DATA_TRANSFORMATION_INTERPOLATION_DURATION_ID);
295
	}
296
297
	/**
298
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
299
	 */
300
	public final void setTransformationInterpolationDelay(final int ticks) {
301
		this.entityData.set(DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID, ticks, true);
302
	}
303
304
	/**
305
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
306
	 */
307
	public final int getTransformationInterpolationDelay() {
308
		return this.entityData.get(DATA_TRANSFORMATION_INTERPOLATION_START_DELTA_TICKS_ID);
309
	}
310
311
	/**
312
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
313
	 */
314
	public final void setPosRotInterpolationDuration(final int duration) {
315
		this.entityData.set(DATA_POS_ROT_INTERPOLATION_DURATION_ID, duration);
316
	}
317
318
	/**
319
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
320
	 */
321
	public final int getPosRotInterpolationDuration() {
322
		return this.entityData.get(DATA_POS_ROT_INTERPOLATION_DURATION_ID);
323
	}
324
325
	/**
326
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
327
	 */
328
	public final void setBillboardConstraints(final Display.BillboardConstraints constraints) {
329
		this.entityData.set(DATA_BILLBOARD_RENDER_CONSTRAINTS_ID, constraints.getId());
330
	}
331
332
	/**
333
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
334
	 */
335
	public final Display.BillboardConstraints getBillboardConstraints() {
336
		return Display.BillboardConstraints.BY_ID.apply(this.entityData.get(DATA_BILLBOARD_RENDER_CONSTRAINTS_ID));
337
	}
338
339
	/**
340
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
341
	 */
342
	public final void setBrightnessOverride(final @Nullable Brightness brightness) {
343
		this.entityData.set(DATA_BRIGHTNESS_OVERRIDE_ID, brightness != null ? brightness.pack() : -1);
344
	}
345
346
	/**
347
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
348
	 */
349
	public final @Nullable Brightness getBrightnessOverride() {
350
		int value = this.entityData.get(DATA_BRIGHTNESS_OVERRIDE_ID);
351
		return value != -1 ? Brightness.unpack(value) : null;
352
	}
353
354
	/**
355
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
356
	 */
357
	public final int getPackedBrightnessOverride() {
358
		return this.entityData.get(DATA_BRIGHTNESS_OVERRIDE_ID);
359
	}
360
361
	/**
362
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
363
	 */
364
	public final void setViewRange(final float range) {
365
		this.entityData.set(DATA_VIEW_RANGE_ID, range);
366
	}
367
368
	/**
369
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
370
	 */
371
	public final float getViewRange() {
372
		return this.entityData.get(DATA_VIEW_RANGE_ID);
373
	}
374
375
	/**
376
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
377
	 */
378
	public final void setShadowRadius(final float size) {
379
		this.entityData.set(DATA_SHADOW_RADIUS_ID, size);
380
	}
381
382
	/**
383
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
384
	 */
385
	public final float getShadowRadius() {
386
		return this.entityData.get(DATA_SHADOW_RADIUS_ID);
387
	}
388
389
	/**
390
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
391
	 */
392
	public final void setShadowStrength(final float strength) {
393
		this.entityData.set(DATA_SHADOW_STRENGTH_ID, strength);
394
	}
395
396
	/**
397
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
398
	 */
399
	public final float getShadowStrength() {
400
		return this.entityData.get(DATA_SHADOW_STRENGTH_ID);
401
	}
402
403
	/**
404
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
405
	 */
406
	public final void setWidth(final float width) {
407
		this.entityData.set(DATA_WIDTH_ID, width);
408
	}
409
410
	/**
411
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
412
	 */
413
	public final float getWidth() {
414
		return this.entityData.get(DATA_WIDTH_ID);
415
	}
416
417
	/**
418
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
419
	 */
420
	public final void setHeight(final float width) {
421
		this.entityData.set(DATA_HEIGHT_ID, width);
422
	}
423
424
	/**
425
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
426
	 */
427
	public final int getGlowColorOverride() {
428
		return this.entityData.get(DATA_GLOW_COLOR_OVERRIDE_ID);
429
	}
430
431
	/**
432
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
433
	 */
434
	public final void setGlowColorOverride(final int value) {
435
		this.entityData.set(DATA_GLOW_COLOR_OVERRIDE_ID, value);
436
	}
437
438
	public float calculateInterpolationProgress(final float partialTickTime) {
439
		int duration = this.interpolationDuration;
440
		if (duration <= 0) {
441
			return 1.0F;
442
		}
443
444
		float ticksSinceUpdate = (float)(this.tickCount - this.interpolationStartClientTick);
445
		float partialTicksSinceLastUpdate = ticksSinceUpdate + partialTickTime;
446
		float result = Mth.clamp(Mth.inverseLerp(partialTicksSinceLastUpdate, 0.0F, duration), 0.0F, 1.0F);
447
		this.lastProgress = result;
448
		return result;
449
	}
450
451
	/**
452
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
453
	 */
454
	public final float getHeight() {
455
		return this.entityData.get(DATA_HEIGHT_ID);
456
	}
457
458
	@Override
459
	public void setPos(final double x, final double y, final double z) {
460
		super.setPos(x, y, z);
461
		this.updateCulling();
462
	}
463
464
	private void updateCulling() {
465
		float width = this.getWidth();
466
		float height = this.getHeight();
467
		this.noCulling = width == 0.0F || height == 0.0F;
468
		float w = width / 2.0F;
469
		double x = this.getX();
470
		double y = this.getY();
471
		double z = this.getZ();
472
		this.cullingBoundingBox = new AABB(x - w, y, z - w, x + w, y + height, z + w);
473
	}
474
475
	@Override
476
	public boolean shouldRenderAtSqrDistance(final double distanceSqr) {
477
		return distanceSqr < Mth.square(this.getViewRange() * 64.0 * getViewScale());
478
	}
479
480
	@Override
481
	public int getTeamColor() {
482
		int glowColorOverride = this.getGlowColorOverride();
483
		return glowColorOverride != -1 ? glowColorOverride : super.getTeamColor();
484
	}
485
486
	private Display.RenderState createFreshRenderState() {
487
		return new Display.RenderState(
488
			Display.GenericInterpolator.constant(createTransformation(this.entityData)),
489
			this.getBillboardConstraints(),
490
			this.getPackedBrightnessOverride(),
491
			Display.FloatInterpolator.constant(this.getShadowRadius()),
492
			Display.FloatInterpolator.constant(this.getShadowStrength()),
493
			this.getGlowColorOverride()
494
		);
495
	}
496
497
	private Display.RenderState createInterpolatedRenderState(final Display.RenderState previousState, final float progress) {
498
		Transformation currentTransform = previousState.transformation.get(progress);
499
		float currentShadowRadius = previousState.shadowRadius.get(progress);
500
		float currentShadowStrength = previousState.shadowStrength.get(progress);
501
		return new Display.RenderState(
502
			new Display.TransformationInterpolator(currentTransform, createTransformation(this.entityData)),
503
			this.getBillboardConstraints(),
504
			this.getPackedBrightnessOverride(),
505
			new Display.LinearFloatInterpolator(currentShadowRadius, this.getShadowRadius()),
506
			new Display.LinearFloatInterpolator(currentShadowStrength, this.getShadowStrength()),
507
			this.getGlowColorOverride()
508
		);
509
	}
510
511
	public enum BillboardConstraints implements StringRepresentable {
512
		FIXED((byte)0, "fixed"),
513
		VERTICAL((byte)1, "vertical"),
514
		HORIZONTAL((byte)2, "horizontal"),
515
		CENTER((byte)3, "center");
516
517
		public static final Codec<Display.BillboardConstraints> CODEC = StringRepresentable.fromEnum(Display.BillboardConstraints::values);
518
		public static final IntFunction<Display.BillboardConstraints> BY_ID = ByIdMap.continuous(
519
			Display.BillboardConstraints::getId, values(), ByIdMap.OutOfBoundsStrategy.ZERO
520
		);
521
		private final byte id;
522
		private final String name;
523
524
		BillboardConstraints(final byte id, final String name) {
525
			this.name = name;
526
			this.id = id;
527
		}
528
529
		@Override
530
		public String getSerializedName() {
531
			return this.name;
532
		}
533
534
		private byte getId() {
535
			return this.id;
536
		}
537
	}
538
539
	/**
540
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
541
	 */
542
	public static class BlockDisplay extends Display {
543
		public static final String TAG_BLOCK_STATE = "block_state";
544
		private static final EntityDataAccessor<BlockState> DATA_BLOCK_STATE_ID = SynchedEntityData.defineId(
545
			Display.BlockDisplay.class, EntityDataSerializers.BLOCK_STATE
546
		);
547
		private Display.BlockDisplay.@Nullable BlockRenderState blockRenderState;
548
549
		public BlockDisplay(final EntityType<?> type, final Level level) {
550
			super(type, level);
551
		}
552
553
		@Override
554
		protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
555
			super.defineSynchedData(entityData);
556
			entityData.define(DATA_BLOCK_STATE_ID, Blocks.AIR.defaultBlockState());
557
		}
558
559
		@Override
560
		public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
561
			super.onSyncedDataUpdated(accessor);
562
			if (accessor.equals(DATA_BLOCK_STATE_ID)) {
563
				this.updateRenderState = true;
564
			}
565
		}
566
567
		/**
568
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
569
		 */
570
		public final BlockState getBlockState() {
571
			return this.entityData.get(DATA_BLOCK_STATE_ID);
572
		}
573
574
		/**
575
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
576
		 */
577
		public final void setBlockState(final BlockState blockState) {
578
			this.entityData.set(DATA_BLOCK_STATE_ID, blockState);
579
		}
580
581
		@Override
582
		protected void readAdditionalSaveData(final ValueInput input) {
583
			super.readAdditionalSaveData(input);
584
			this.setBlockState(input.read("block_state", BlockState.CODEC).orElse(Blocks.AIR.defaultBlockState()));
585
		}
586
587
		@Override
588
		protected void addAdditionalSaveData(final ValueOutput output) {
589
			super.addAdditionalSaveData(output);
590
			output.store("block_state", BlockState.CODEC, this.getBlockState());
591
		}
592
593
		public Display.BlockDisplay.@Nullable BlockRenderState blockRenderState() {
594
			return this.blockRenderState;
595
		}
596
597
		@Override
598
		protected void updateRenderSubState(final boolean shouldInterpolate, final float progress) {
599
			this.blockRenderState = new Display.BlockDisplay.BlockRenderState(this.getBlockState());
600
		}
601
602
		public record BlockRenderState(BlockState blockState) {
603
		}
604
	}
605
606
	private record ColorInterpolator(int previous, int current) implements Display.IntInterpolator {
607
		@Override
608
		public int get(final float progress) {
609
			return ARGB.srgbLerp(progress, this.previous, this.current);
610
		}
611
	}
612
613
	@FunctionalInterface
614
	public interface FloatInterpolator {
615
		static Display.FloatInterpolator constant(final float value) {
616
			return progress -> value;
617
		}
618
619
		float get(final float progress);
620
	}
621
622
	@FunctionalInterface
623
	public interface GenericInterpolator<T> {
624
		static <T> Display.GenericInterpolator<T> constant(final T value) {
625
			return progress -> value;
626
		}
627
628
		T get(final float progress);
629
	}
630
631
	@FunctionalInterface
632
	public interface IntInterpolator {
633
		static Display.IntInterpolator constant(final int value) {
634
			return progress -> value;
635
		}
636
637
		int get(final float progress);
638
	}
639
640
	/**
641
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
642
	 */
643
	public static class ItemDisplay extends Display {
644
		private static final String TAG_ITEM = "item";
645
		private static final String TAG_ITEM_DISPLAY = "item_display";
646
		private static final EntityDataAccessor<ItemStack> DATA_ITEM_STACK_ID = SynchedEntityData.defineId(
647
			Display.ItemDisplay.class, EntityDataSerializers.ITEM_STACK
648
		);
649
		private static final EntityDataAccessor<Byte> DATA_ITEM_DISPLAY_ID = SynchedEntityData.defineId(Display.ItemDisplay.class, EntityDataSerializers.BYTE);
650
		private final SlotAccess slot = SlotAccess.of(this::getItemStack, this::setItemStack);
651
		private Display.ItemDisplay.@Nullable ItemRenderState itemRenderState;
652
653
		public ItemDisplay(final EntityType<?> type, final Level level) {
654
			super(type, level);
655
		}
656
657
		@Override
658
		protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
659
			super.defineSynchedData(entityData);
660
			entityData.define(DATA_ITEM_STACK_ID, ItemStack.EMPTY);
661
			entityData.define(DATA_ITEM_DISPLAY_ID, ItemDisplayContext.NONE.getId());
662
		}
663
664
		@Override
665
		public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
666
			super.onSyncedDataUpdated(accessor);
667
			if (DATA_ITEM_STACK_ID.equals(accessor) || DATA_ITEM_DISPLAY_ID.equals(accessor)) {
668
				this.updateRenderState = true;
669
			}
670
		}
671
672
		/**
673
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
674
		 */
675
		public final ItemStack getItemStack() {
676
			return this.entityData.get(DATA_ITEM_STACK_ID);
677
		}
678
679
		/**
680
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
681
		 */
682
		public final void setItemStack(final ItemStack item) {
683
			this.entityData.set(DATA_ITEM_STACK_ID, item);
684
		}
685
686
		/**
687
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
688
		 */
689
		public final void setItemTransform(final ItemDisplayContext transform) {
690
			this.entityData.set(DATA_ITEM_DISPLAY_ID, transform.getId());
691
		}
692
693
		/**
694
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
695
		 */
696
		public final ItemDisplayContext getItemTransform() {
697
			return ItemDisplayContext.BY_ID.apply(this.entityData.get(DATA_ITEM_DISPLAY_ID));
698
		}
699
700
		@Override
701
		protected void readAdditionalSaveData(final ValueInput input) {
702
			super.readAdditionalSaveData(input);
703
			this.setItemStack(input.read("item", ItemStack.CODEC).orElse(ItemStack.EMPTY));
704
			this.setItemTransform(input.read("item_display", ItemDisplayContext.CODEC).orElse(ItemDisplayContext.NONE));
705
		}
706
707
		@Override
708
		protected void addAdditionalSaveData(final ValueOutput output) {
709
			super.addAdditionalSaveData(output);
710
			ItemStack itemStack = this.getItemStack();
711
			if (!itemStack.isEmpty()) {
712
				output.store("item", ItemStack.CODEC, itemStack);
713
			}
714
715
			output.store("item_display", ItemDisplayContext.CODEC, this.getItemTransform());
716
		}
717
718
		@Override
719
		public @Nullable SlotAccess getSlot(final int slot) {
720
			return slot == 0 ? this.slot : null;
721
		}
722
723
		public Display.ItemDisplay.@Nullable ItemRenderState itemRenderState() {
724
			return this.itemRenderState;
725
		}
726
727
		@Override
728
		protected void updateRenderSubState(final boolean shouldInterpolate, final float progress) {
729
			this.itemRenderState = new Display.ItemDisplay.ItemRenderState(this.getItemStack(), this.getItemTransform());
730
		}
731
732
		public record ItemRenderState(ItemStack itemStack, ItemDisplayContext itemTransform) {
733
		}
734
	}
735
736
	private record LinearFloatInterpolator(float previous, float current) implements Display.FloatInterpolator {
737
		@Override
738
		public float get(final float progress) {
739
			return Mth.lerp(progress, this.previous, this.current);
740
		}
741
	}
742
743
	private record LinearIntInterpolator(int previous, int current) implements Display.IntInterpolator {
744
		@Override
745
		public int get(final float progress) {
746
			return Mth.lerpInt(progress, this.previous, this.current);
747
		}
748
	}
749
750
	public record RenderState(
751
		Display.GenericInterpolator<Transformation> transformation,
752
		Display.BillboardConstraints billboardConstraints,
753
		int brightnessOverride,
754
		Display.FloatInterpolator shadowRadius,
755
		Display.FloatInterpolator shadowStrength,
756
		int glowColorOverride
757
	) {
758
	}
759
760
	/**
761
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
762
	 */
763
	public static class TextDisplay extends Display {
764
		public static final String TAG_TEXT = "text";
765
		private static final String TAG_LINE_WIDTH = "line_width";
766
		private static final String TAG_TEXT_OPACITY = "text_opacity";
767
		private static final String TAG_BACKGROUND_COLOR = "background";
768
		private static final String TAG_SHADOW = "shadow";
769
		private static final String TAG_SEE_THROUGH = "see_through";
770
		private static final String TAG_USE_DEFAULT_BACKGROUND = "default_background";
771
		private static final String TAG_ALIGNMENT = "alignment";
772
		public static final byte FLAG_SHADOW = 1;
773
		public static final byte FLAG_SEE_THROUGH = 2;
774
		public static final byte FLAG_USE_DEFAULT_BACKGROUND = 4;
775
		public static final byte FLAG_ALIGN_LEFT = 8;
776
		public static final byte FLAG_ALIGN_RIGHT = 16;
777
		private static final byte INITIAL_TEXT_OPACITY = -1;
778
		public static final int INITIAL_BACKGROUND = 1073741824;
779
		private static final int INITIAL_LINE_WIDTH = 200;
780
		private static final EntityDataAccessor<Component> DATA_TEXT_ID = SynchedEntityData.defineId(Display.TextDisplay.class, EntityDataSerializers.COMPONENT);
781
		private static final EntityDataAccessor<Integer> DATA_LINE_WIDTH_ID = SynchedEntityData.defineId(Display.TextDisplay.class, EntityDataSerializers.INT);
782
		private static final EntityDataAccessor<Integer> DATA_BACKGROUND_COLOR_ID = SynchedEntityData.defineId(Display.TextDisplay.class, EntityDataSerializers.INT);
783
		private static final EntityDataAccessor<Byte> DATA_TEXT_OPACITY_ID = SynchedEntityData.defineId(Display.TextDisplay.class, EntityDataSerializers.BYTE);
784
		private static final EntityDataAccessor<Byte> DATA_STYLE_FLAGS_ID = SynchedEntityData.defineId(Display.TextDisplay.class, EntityDataSerializers.BYTE);
785
		private static final IntSet TEXT_RENDER_STATE_IDS = IntSet.of(
786
			DATA_TEXT_ID.id(), DATA_LINE_WIDTH_ID.id(), DATA_BACKGROUND_COLOR_ID.id(), DATA_TEXT_OPACITY_ID.id(), DATA_STYLE_FLAGS_ID.id()
787
		);
788
		private Display.TextDisplay.@Nullable CachedInfo clientDisplayCache;
789
		private Display.TextDisplay.@Nullable TextRenderState textRenderState;
790
791
		public TextDisplay(final EntityType<?> type, final Level level) {
792
			super(type, level);
793
		}
794
795
		@Override
796
		protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
797
			super.defineSynchedData(entityData);
798
			entityData.define(DATA_TEXT_ID, Component.empty());
799
			entityData.define(DATA_LINE_WIDTH_ID, 200);
800
			entityData.define(DATA_BACKGROUND_COLOR_ID, 1073741824);
801
			entityData.define(DATA_TEXT_OPACITY_ID, (byte)-1);
802
			entityData.define(DATA_STYLE_FLAGS_ID, (byte)0);
803
		}
804
805
		@Override
806
		public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
807
			super.onSyncedDataUpdated(accessor);
808
			if (TEXT_RENDER_STATE_IDS.contains(accessor.id())) {
809
				this.updateRenderState = true;
810
			}
811
		}
812
813
		/**
814
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
815
		 */
816
		public final Component getText() {
817
			return this.entityData.get(DATA_TEXT_ID);
818
		}
819
820
		/**
821
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
822
		 */
823
		public final void setText(final Component text) {
824
			this.entityData.set(DATA_TEXT_ID, text);
825
		}
826
827
		/**
828
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
829
		 */
830
		public final int getLineWidth() {
831
			return this.entityData.get(DATA_LINE_WIDTH_ID);
832
		}
833
834
		/**
835
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
836
		 */
837
		public final void setLineWidth(final int width) {
838
			this.entityData.set(DATA_LINE_WIDTH_ID, width);
839
		}
840
841
		/**
842
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
843
		 */
844
		public final byte getTextOpacity() {
845
			return this.entityData.get(DATA_TEXT_OPACITY_ID);
846
		}
847
848
		/**
849
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
850
		 */
851
		public final void setTextOpacity(final byte opacity) {
852
			this.entityData.set(DATA_TEXT_OPACITY_ID, opacity);
853
		}
854
855
		/**
856
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
857
		 */
858
		public final int getBackgroundColor() {
859
			return this.entityData.get(DATA_BACKGROUND_COLOR_ID);
860
		}
861
862
		/**
863
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
864
		 */
865
		public final void setBackgroundColor(final int color) {
866
			this.entityData.set(DATA_BACKGROUND_COLOR_ID, color);
867
		}
868
869
		/**
870
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
871
		 */
872
		public final byte getFlags() {
873
			return this.entityData.get(DATA_STYLE_FLAGS_ID);
874
		}
875
876
		/**
877
		 * Access widened by fabric-transitive-access-wideners-v1 to accessible
878
		 */
879
		public final void setFlags(final byte flags) {
880
			this.entityData.set(DATA_STYLE_FLAGS_ID, flags);
881
		}
882
883
		private static byte loadFlag(final byte flags, final ValueInput input, final String id, final byte mask) {
884
			return input.getBooleanOr(id, false) ? (byte)(flags | mask) : flags;
885
		}
886
887
		@Override
888
		protected void readAdditionalSaveData(final ValueInput input) {
889
			super.readAdditionalSaveData(input);
890
			this.setLineWidth(input.getIntOr("line_width", 200));
891
			this.setTextOpacity(input.getByteOr("text_opacity", (byte)-1));
892
			this.setBackgroundColor(input.getIntOr("background", 1073741824));
893
			byte flags = loadFlag((byte)0, input, "shadow", (byte)1);
894
			flags = loadFlag(flags, input, "see_through", (byte)2);
895
			flags = loadFlag(flags, input, "default_background", (byte)4);
896
			Optional<Display.TextDisplay.Align> alignment = input.read("alignment", Display.TextDisplay.Align.CODEC);
897
			if (alignment.isPresent()) {
898
				flags = switch ((Display.TextDisplay.Align)alignment.get()) {
899
					case CENTER -> flags;
900
					case LEFT -> (byte)(flags | 8);
901
					case RIGHT -> (byte)(flags | 16);
902
				};
903
			}
904
905
			this.setFlags(flags);
906
			Optional<Component> text = input.read("text", ComponentSerialization.CODEC);
907
			if (text.isPresent()) {
908
				try {
909
					if (this.level() instanceof ServerLevel serverLevel) {
910
						CommandSourceStack context = this.createCommandSourceStackForNameResolution(serverLevel).withPermission(LevelBasedPermissionSet.GAMEMASTER);
911
						Component resolvedText = ComponentUtils.resolve(ResolutionContext.create(context), text.get());
912
						this.setText(resolvedText);
913
					} else {
914
						this.setText(Component.empty());
915
					}
916
				} catch (Exception e) {
917
					Display.LOGGER.warn("Failed to parse display entity text {}", text, e);
918
				}
919
			}
920
		}
921
922
		private static void storeFlag(final byte flags, final ValueOutput output, final String id, final byte mask) {
923
			output.putBoolean(id, (flags & mask) != 0);
924
		}
925
926
		@Override
927
		protected void addAdditionalSaveData(final ValueOutput output) {
928
			super.addAdditionalSaveData(output);
929
			output.store("text", ComponentSerialization.CODEC, this.getText());
930
			output.putInt("line_width", this.getLineWidth());
931
			output.putInt("background", this.getBackgroundColor());
932
			output.putByte("text_opacity", this.getTextOpacity());
933
			byte flags = this.getFlags();
934
			storeFlag(flags, output, "shadow", (byte)1);
935
			storeFlag(flags, output, "see_through", (byte)2);
936
			storeFlag(flags, output, "default_background", (byte)4);
937
			output.store("alignment", Display.TextDisplay.Align.CODEC, getAlign(flags));
938
		}
939
940
		@Override
941
		protected void updateRenderSubState(final boolean shouldInterpolate, final float progress) {
942
			if (shouldInterpolate && this.textRenderState != null) {
943
				this.textRenderState = this.createInterpolatedTextRenderState(this.textRenderState, progress);
944
			} else {
945
				this.textRenderState = this.createFreshTextRenderState();
946
			}
947
948
			this.clientDisplayCache = null;
949
		}
950
951
		public Display.TextDisplay.@Nullable TextRenderState textRenderState() {
952
			return this.textRenderState;
953
		}
954
955
		private Display.TextDisplay.TextRenderState createFreshTextRenderState() {
956
			return new Display.TextDisplay.TextRenderState(
957
				this.getText(),
958
				this.getLineWidth(),
959
				Display.IntInterpolator.constant(this.getTextOpacity()),
960
				Display.IntInterpolator.constant(this.getBackgroundColor()),
961
				this.getFlags()
962
			);
963
		}
964
965
		private Display.TextDisplay.TextRenderState createInterpolatedTextRenderState(final Display.TextDisplay.TextRenderState previous, final float progress) {
966
			int currentBackground = previous.backgroundColor.get(progress);
967
			int currentOpacity = previous.textOpacity.get(progress);
968
			return new Display.TextDisplay.TextRenderState(
969
				this.getText(),
970
				this.getLineWidth(),
971
				new Display.LinearIntInterpolator(currentOpacity, this.getTextOpacity()),
972
				new Display.ColorInterpolator(currentBackground, this.getBackgroundColor()),
973
				this.getFlags()
974
			);
975
		}
976
977
		public Display.TextDisplay.CachedInfo cacheDisplay(final Display.TextDisplay.LineSplitter splitter) {
978
			if (this.clientDisplayCache == null) {
979
				if (this.textRenderState != null) {
980
					this.clientDisplayCache = splitter.split(this.textRenderState.text(), this.textRenderState.lineWidth());
981
				} else {
982
					this.clientDisplayCache = new Display.TextDisplay.CachedInfo(List.of(), 0);
983
				}
984
			}
985
986
			return this.clientDisplayCache;
987
		}
988
989
		public static Display.TextDisplay.Align getAlign(final byte flags) {
990
			if ((flags & 8) != 0) {
991
				return Display.TextDisplay.Align.LEFT;
992
			} else {
993
				return (flags & 16) != 0 ? Display.TextDisplay.Align.RIGHT : Display.TextDisplay.Align.CENTER;
994
			}
995
		}
996
997
		public enum Align implements StringRepresentable {
998
			CENTER("center"),
999
			LEFT("left"),
1000
			RIGHT("right");
1001
1002
			public static final Codec<Display.TextDisplay.Align> CODEC = StringRepresentable.fromEnum(Display.TextDisplay.Align::values);
1003
			private final String name;
1004
1005
			Align(final String name) {
1006
				this.name = name;
1007
			}
1008
1009
			@Override
1010
			public String getSerializedName() {
1011
				return this.name;
1012
			}
1013
		}
1014
1015
		public record CachedInfo(List<Display.TextDisplay.CachedLine> lines, int width) {
1016
		}
1017
1018
		public record CachedLine(FormattedCharSequence contents, int width) {
1019
		}
1020
1021
		@FunctionalInterface
1022
		public interface LineSplitter {
1023
			Display.TextDisplay.CachedInfo split(Component input, int width);
1024
		}
1025
1026
		public record TextRenderState(Component text, int lineWidth, Display.IntInterpolator textOpacity, Display.IntInterpolator backgroundColor, byte flags) {
1027
		}
1028
	}
1029
1030
	private record TransformationInterpolator(Transformation previous, Transformation current) implements Display.GenericInterpolator<Transformation> {
1031
		public Transformation get(final float progress) {
1032
			return progress >= 1.0 ? this.current : this.previous.slerp(this.current, progress);
1033
		}
1034
	}
1035
}
1036

Decompiled Minecraft 26.3 source of Display (net/minecraft/world/entity/Display.java) with Mojang official mappings, stored verbatim on the site.