13
0
geforkt von Mirrors/Paper

Update Enchantment damage increase API

The Enchantment damage increase API added previously used the
EntityCategory enum as a parameter. These values are now however
determined by tags instead of the categories themselves.

Deprecated the outdated api method, create a new overload that takes
EntityType instead and implement deprecated method by guessing an entity
type from the builtin registry based on the category passed.
This method allows
a) the tags to still be modified and the legacy
   method still respecting such.
b) potential cursed implementations of enchantments of plugins to not
   break that override the getDamageBonus method on Enchantment.
Dieser Commit ist enthalten in:
Bjarne Koll 2024-04-25 18:42:50 +02:00
Ursprung dc556091df
Commit b7e5de9401
3 geänderte Dateien mit 39 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -109,10 +109,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param level the level of enchantment
+ * @param entityCategory the category of entity
+ * @return the damage increase
+ * @deprecated Use {@link #getDamageIncrease(int, org.bukkit.entity.EntityType)} instead.
+ * Enchantment damage increase is no longer handled via {@link org.bukkit.entity.EntityCategory}s, but
+ * is instead controlled by tags, e.g. {@link org.bukkit.Tag#ENTITY_TYPES_SENSITIVE_TO_BANE_OF_ARTHROPODS}.
+ * As such, a category cannot properly represent all entities defined by the tags.
+ */
+ @Deprecated(forRemoval = true, since = "1.20.5")
+ public abstract float getDamageIncrease(int level, @NotNull org.bukkit.entity.EntityCategory entityCategory);
+
+ /**
+ * Gets the damage increase as a result of the level and entity type specified
+ *
+ * @param level the level of enchantment
+ * @param entityType the type of entity.
+ * @return the damage increase
+ */
+ public abstract float getDamageIncrease(int level, @NotNull org.bukkit.entity.EntityType entityType);
+
+ /**
+ * Gets the equipment slots where this enchantment is considered "active".
+ *
+ * @return the equipment slots

Datei anzeigen

@ -9,9 +9,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -0,0 +0,0 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
throw new IllegalArgumentException(entityCategory + " is an unrecognized entity category");
throw new UnsupportedOperationException("Cannot set the hurt direction on a non player");
}
// Paper end - more enchant API
// Paper end - hurt direction API
+
+ // Paper start - knockback API
+ @Override

Datei anzeigen

@ -53,7 +53,29 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ @Override
+ public float getDamageIncrease(int level, org.bukkit.entity.EntityCategory entityCategory) {
+ return handle.getDamageBonus(level, org.bukkit.craftbukkit.entity.CraftLivingEntity.fromBukkitEntityCategory(entityCategory));
+ return handle.getDamageBonus(level, guessEntityTypeFromEnchantmentCategory(entityCategory));
+ }
+
+ @Override
+ public float getDamageIncrease(int level, org.bukkit.entity.EntityType entityType) {
+ return handle.getDamageBonus(level, org.bukkit.craftbukkit.util.CraftMagicNumbers.getEntityTypes(entityType));
+ }
+
+ @Deprecated(forRemoval = true)
+ private net.minecraft.world.entity.EntityType<?> guessEntityTypeFromEnchantmentCategory(
+ final org.bukkit.entity.EntityCategory entityCategory
+ ) {
+ final net.minecraft.tags.TagKey<net.minecraft.world.entity.EntityType<?>> tag = switch (entityCategory) {
+ case ARTHROPOD -> net.minecraft.tags.EntityTypeTags.SENSITIVE_TO_BANE_OF_ARTHROPODS;
+ case UNDEAD -> net.minecraft.tags.EntityTypeTags.SENSITIVE_TO_SMITE;
+ case WATER -> net.minecraft.tags.EntityTypeTags.SENSITIVE_TO_IMPALING;
+ default -> null;
+ };
+ if (tag == null) return null;
+
+ return net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getTag(tag)
+ .map(e -> e.size() > 0 ? e.get(0).value() : null)
+ .orElse(null);
+ }
+
+ @Override
@ -77,33 +99,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// Paper end
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -0,0 +0,0 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
throw new UnsupportedOperationException("Cannot set the hurt direction on a non player");
}
// Paper end - hurt direction API
+
+ // Paper start - more enchant API
+ public static MobType fromBukkitEntityCategory(EntityCategory entityCategory) {
+ switch (entityCategory) {
+ case NONE:
+ return MobType.UNDEFINED;
+ case UNDEAD:
+ return MobType.UNDEAD;
+ case ARTHROPOD:
+ return MobType.ARTHROPOD;
+ case ILLAGER:
+ return MobType.ILLAGER;
+ case WATER:
+ return MobType.WATER;
+ }
+ throw new IllegalArgumentException(entityCategory + " is an unrecognized entity category");
+ }
+ // Paper end - more enchant API
}
diff --git a/src/test/java/io/papermc/paper/enchantments/EnchantmentRarityTest.java b/src/test/java/io/papermc/paper/enchantments/EnchantmentRarityTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000