Skip to content

Commit 10a73fe

Browse files
authored
Add and clarify Attribute#getDefaultValue (#13345)
1 parent 34cf3ab commit 10a73fe

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

paper-api/src/main/java/org/bukkit/attribute/Attribute.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.bukkit.NamespacedKey;
1111
import org.bukkit.Registry;
1212
import org.bukkit.Translatable;
13+
import org.bukkit.entity.EntityType;
1314
import org.bukkit.util.OldEnum;
1415
import org.jetbrains.annotations.NotNull;
1516

@@ -170,6 +171,13 @@ private static Attribute getAttribute(@NotNull @KeyPattern.Value String key) {
170171
@NotNull
171172
Sentiment getSentiment();
172173

174+
/**
175+
* {@return the default value of this attribute}
176+
* <p>
177+
* Default attribute values may differ between entity types, use {@link EntityType#getDefaultAttributes()} to get default attribute values for a specific entity type.
178+
*/
179+
double getDefaultValue();
180+
173181
/**
174182
* @param name of the attribute.
175183
* @return the attribute with the given name.

paper-api/src/main/java/org/bukkit/attribute/AttributeInstance.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public interface AttributeInstance {
111111
* Gets the default value of the Attribute attached to this instance.
112112
*
113113
* @return server default value
114+
* @deprecated this method is placed misleadingly as it does not return the default value in the current entity's context, but in the server's context.
115+
* Use {@link Attribute#getDefaultValue()} as a replacement and see the note there about default values for specific entity types
116+
* @see Attribute#getDefaultValue()
117+
* @see org.bukkit.entity.EntityType#getDefaultAttributes()
114118
*/
119+
@Deprecated(since = "26.1")
115120
double getDefaultValue();
116121
}

paper-server/patches/sources/net/minecraft/world/entity/animal/equine/AbstractChestedHorse.java.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- a/net/minecraft/world/entity/animal/equine/AbstractChestedHorse.java
22
+++ b/net/minecraft/world/entity/animal/equine/AbstractChestedHorse.java
3-
@@ -75,6 +_,16 @@
3+
@@ -74,6 +_,14 @@
44
super.dropEquipment(level);
55
if (this.hasChest()) {
66
this.spawnAtLocation(level, Blocks.CHEST);

paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public Sentiment getSentiment() {
5353
return Sentiment.valueOf(this.getHandle().sentiment.name());
5454
}
5555

56+
@Override
57+
public double getDefaultValue() {
58+
return this.getHandle().getDefaultValue();
59+
}
60+
5661
@Override
5762
public String getTranslationKey() {
5863
return this.getHandle().getDescriptionId();

0 commit comments

Comments
 (0)