Attribute .java

net.minecraft.world.entity.ai.attributes.Attribute (class): members: isClientSyncable, getDefaultValue, setSentiment, setSyncable, Sentiment, sentiment.

net.minecraft.world.entity.ai.attributesclass69 linescommon1.9 KB

API Surface (8)

double getDefaultValue()
boolean isClientSyncable()
Attribute setSyncable(final boolean syncable)
Attribute setSentiment(final Attribute.Sentiment sentiment)
double sanitizeValue(final double value)
String getDescriptionId()
ChatFormatting getStyle(final boolean valueIncrease)
ChatFormatting getStyle(final boolean valueIncrease)

Fields & Constants (6)

CODEC
STREAM_CODEC
defaultValue
syncable
descriptionId
sentiment

Code Graph: Dependencies (7)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

Attribute.java69 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.attributes;
2
3
import com.mojang.serialization.Codec;
4
import net.minecraft.ChatFormatting;
5
import net.minecraft.core.Holder;
6
import net.minecraft.core.registries.BuiltInRegistries;
7
import net.minecraft.core.registries.Registries;
8
import net.minecraft.network.RegistryFriendlyByteBuf;
9
import net.minecraft.network.codec.ByteBufCodecs;
10
import net.minecraft.network.codec.StreamCodec;
11
12
public class Attribute {
13
	public static final Codec<Holder<Attribute>> CODEC = BuiltInRegistries.ATTRIBUTE.holderByNameCodec();
14
	public static final StreamCodec<RegistryFriendlyByteBuf, Holder<Attribute>> STREAM_CODEC = ByteBufCodecs.holderRegistry(Registries.ATTRIBUTE);
15
	private final double defaultValue;
16
	private boolean syncable;
17
	private final String descriptionId;
18
	private Attribute.Sentiment sentiment = Attribute.Sentiment.POSITIVE;
19
20
	protected Attribute(final String descriptionId, final double defaultValue) {
21
		this.defaultValue = defaultValue;
22
		this.descriptionId = descriptionId;
23
	}
24
25
	public double getDefaultValue() {
26
		return this.defaultValue;
27
	}
28
29
	public boolean isClientSyncable() {
30
		return this.syncable;
31
	}
32
33
	public Attribute setSyncable(final boolean syncable) {
34
		this.syncable = syncable;
35
		return this;
36
	}
37
38
	public Attribute setSentiment(final Attribute.Sentiment sentiment) {
39
		this.sentiment = sentiment;
40
		return this;
41
	}
42
43
	public double sanitizeValue(final double value) {
44
		return value;
45
	}
46
47
	public String getDescriptionId() {
48
		return this.descriptionId;
49
	}
50
51
	public ChatFormatting getStyle(final boolean valueIncrease) {
52
		return this.sentiment.getStyle(valueIncrease);
53
	}
54
55
	public enum Sentiment {
56
		POSITIVE,
57
		NEUTRAL,
58
		NEGATIVE;
59
60
		public ChatFormatting getStyle(final boolean valueIncrease) {
61
			return switch (this) {
62
				case POSITIVE -> valueIncrease ? ChatFormatting.BLUE : ChatFormatting.RED;
63
				case NEUTRAL -> ChatFormatting.GRAY;
64
				case NEGATIVE -> valueIncrease ? ChatFormatting.RED : ChatFormatting.BLUE;
65
			};
66
		}
67
	}
68
}
69

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