#1070: Make Attribute an interface and align names with the new minecraft ones

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
Bukkit/Spigot 2024-10-29 06:43:08 +11:00
parent 8ec64c4481
commit 5b78d5d8a2
3 changed files with 62 additions and 46 deletions

View File

@ -93,7 +93,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
*
* @see Attribute
*/
Registry<Attribute> ATTRIBUTE = new SimpleRegistry<>(Attribute.class);
Registry<Attribute> ATTRIBUTE = Objects.requireNonNull(Bukkit.getRegistry(Attribute.class), "No registry present for Attribute. This is a bug.");
/**
* Server banner patterns.
*

View File

@ -98,6 +98,7 @@ public interface UnsafeValues {
String getTranslationKey(ItemStack itemStack);
@Deprecated(since = "1.21.3", forRemoval = true)
String getTranslationKey(Attribute attribute);
@Nullable

View File

@ -1,160 +1,175 @@
package org.bukkit.attribute;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Translatable;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull;
/**
* Types of attributes which may be present on an {@link Attributable}.
*/
public enum Attribute implements Keyed, Translatable {
public interface Attribute extends OldEnum<Attribute>, Keyed, Translatable {
/**
* Maximum health of an Entity.
*/
GENERIC_MAX_HEALTH("max_health"),
Attribute MAX_HEALTH = getAttribute("max_health");
/**
* Range at which an Entity will follow others.
*/
GENERIC_FOLLOW_RANGE("follow_range"),
Attribute FOLLOW_RANGE = getAttribute("follow_range");
/**
* Resistance of an Entity to knockback.
*/
GENERIC_KNOCKBACK_RESISTANCE("knockback_resistance"),
Attribute KNOCKBACK_RESISTANCE = getAttribute("knockback_resistance");
/**
* Movement speed of an Entity.
*/
GENERIC_MOVEMENT_SPEED("movement_speed"),
Attribute MOVEMENT_SPEED = getAttribute("movement_speed");
/**
* Flying speed of an Entity.
*/
GENERIC_FLYING_SPEED("flying_speed"),
Attribute FLYING_SPEED = getAttribute("flying_speed");
/**
* Attack damage of an Entity.
*/
GENERIC_ATTACK_DAMAGE("attack_damage"),
Attribute ATTACK_DAMAGE = getAttribute("attack_damage");
/**
* Attack knockback of an Entity.
*/
GENERIC_ATTACK_KNOCKBACK("attack_knockback"),
Attribute ATTACK_KNOCKBACK = getAttribute("attack_knockback");
/**
* Attack speed of an Entity.
*/
GENERIC_ATTACK_SPEED("attack_speed"),
Attribute ATTACK_SPEED = getAttribute("attack_speed");
/**
* Armor bonus of an Entity.
*/
GENERIC_ARMOR("armor"),
Attribute ARMOR = getAttribute("armor");
/**
* Armor durability bonus of an Entity.
*/
GENERIC_ARMOR_TOUGHNESS("armor_toughness"),
Attribute ARMOR_TOUGHNESS = getAttribute("armor_toughness");
/**
* The fall damage multiplier of an Entity.
*/
GENERIC_FALL_DAMAGE_MULTIPLIER("fall_damage_multiplier"),
Attribute FALL_DAMAGE_MULTIPLIER = getAttribute("fall_damage_multiplier");
/**
* Luck bonus of an Entity.
*/
GENERIC_LUCK("luck"),
Attribute LUCK = getAttribute("luck");
/**
* Maximum absorption of an Entity.
*/
GENERIC_MAX_ABSORPTION("max_absorption"),
Attribute MAX_ABSORPTION = getAttribute("max_absorption");
/**
* The distance which an Entity can fall without damage.
*/
GENERIC_SAFE_FALL_DISTANCE("safe_fall_distance"),
Attribute SAFE_FALL_DISTANCE = getAttribute("safe_fall_distance");
/**
* The relative scale of an Entity.
*/
GENERIC_SCALE("scale"),
Attribute SCALE = getAttribute("scale");
/**
* The height which an Entity can walk over.
*/
GENERIC_STEP_HEIGHT("step_height"),
Attribute STEP_HEIGHT = getAttribute("step_height");
/**
* The gravity applied to an Entity.
*/
GENERIC_GRAVITY("gravity"),
Attribute GRAVITY = getAttribute("gravity");
/**
* Strength with which an Entity will jump.
*/
GENERIC_JUMP_STRENGTH("jump_strength"),
Attribute JUMP_STRENGTH = getAttribute("jump_strength");
/**
* How long an entity remains burning after ingition.
*/
GENERIC_BURNING_TIME("burning_time"),
Attribute BURNING_TIME = getAttribute("burning_time");
/**
* Resistance to knockback from explosions.
*/
GENERIC_EXPLOSION_KNOCKBACK_RESISTANCE("explosion_knockback_resistance"),
Attribute EXPLOSION_KNOCKBACK_RESISTANCE = getAttribute("explosion_knockback_resistance");
/**
* Movement speed through difficult terrain.
*/
GENERIC_MOVEMENT_EFFICIENCY("movement_efficiency"),
Attribute MOVEMENT_EFFICIENCY = getAttribute("movement_efficiency");
/**
* Oxygen use underwater.
*/
GENERIC_OXYGEN_BONUS("oxygen_bonus"),
Attribute OXYGEN_BONUS = getAttribute("oxygen_bonus");
/**
* Movement speed through water.
*/
GENERIC_WATER_MOVEMENT_EFFICIENCY("water_movement_efficiency"),
Attribute WATER_MOVEMENT_EFFICIENCY = getAttribute("water_movement_efficiency");
/**
* Range at which mobs will be tempted by items.
*/
GENERIC_TEMPT_RANGE("tempt_range"),
Attribute TEMPT_RANGE = getAttribute("tempt_range");
/**
* The block reach distance of a Player.
*/
PLAYER_BLOCK_INTERACTION_RANGE("block_interaction_range"),
Attribute BLOCK_INTERACTION_RANGE = getAttribute("block_interaction_range");
/**
* The entity reach distance of a Player.
*/
PLAYER_ENTITY_INTERACTION_RANGE("entity_interaction_range"),
Attribute ENTITY_INTERACTION_RANGE = getAttribute("entity_interaction_range");
/**
* Block break speed of a Player.
*/
PLAYER_BLOCK_BREAK_SPEED("block_break_speed"),
Attribute BLOCK_BREAK_SPEED = getAttribute("block_break_speed");
/**
* Mining speed for correct tools.
*/
PLAYER_MINING_EFFICIENCY("mining_efficiency"),
Attribute MINING_EFFICIENCY = getAttribute("mining_efficiency");
/**
* Sneaking speed.
*/
PLAYER_SNEAKING_SPEED("sneaking_speed"),
Attribute SNEAKING_SPEED = getAttribute("sneaking_speed");
/**
* Underwater mining speed.
*/
PLAYER_SUBMERGED_MINING_SPEED("submerged_mining_speed"),
Attribute SUBMERGED_MINING_SPEED = getAttribute("submerged_mining_speed");
/**
* Sweeping damage.
*/
PLAYER_SWEEPING_DAMAGE_RATIO("sweeping_damage_ratio"),
Attribute SWEEPING_DAMAGE_RATIO = getAttribute("sweeping_damage_ratio");
/**
* Chance of a zombie to spawn reinforcements.
*/
ZOMBIE_SPAWN_REINFORCEMENTS("spawn_reinforcements");
private final NamespacedKey key;
private Attribute(String key) {
this.key = NamespacedKey.minecraft(key);
}
Attribute SPAWN_REINFORCEMENTS = getAttribute("spawn_reinforcements");
@NotNull
@Override
public NamespacedKey getKey() {
return key;
private static Attribute getAttribute(@NotNull String key) {
return Registry.ATTRIBUTE.getOrThrow(NamespacedKey.minecraft(key));
}
/**
* @param name of the attribute.
* @return the attribute with the given name.
* @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
*/
@NotNull
@Override
public String getTranslationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
@Deprecated(since = "1.21.3")
static Attribute valueOf(@NotNull String name) {
Attribute attribute = Bukkit.getUnsafe().get(Registry.ATTRIBUTE, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(attribute != null, "No attribute found with the name %s", name);
return attribute;
}
/**
* @return an array of all known attributes.
* @deprecated use {@link Registry#iterator()}.
*/
@NotNull
@Deprecated(since = "1.21.3")
static Attribute[] values() {
return Lists.newArrayList(Registry.ATTRIBUTE).toArray(new Attribute[0]);
}
}