2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 6 May 2021 19:57:58 -0700
Subject: [PATCH] More Enchantment API
2022-11-20 00:53:20 +01:00
== AT ==
public net.minecraft.world.item.enchantment.Enchantment slots
2021-06-11 14:02:28 +02:00
2023-11-11 21:09:48 +01:00
Co-authored-by: Luis <luisc99@icloud.com>
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
2024-01-26 20:17:06 +01:00
index 7aa4035a4df1ddcc71065034eafd569ca59be810..5b7579395e61684592758f408d61cffe57f8b21d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
2024-01-26 20:17:06 +01:00
@@ -81,7 +81,7 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
2021-06-11 14:02:28 +02:00
@Override
public boolean isCursed() {
2023-12-06 04:57:46 +01:00
- return this.handle instanceof BindingCurseEnchantment || this.handle instanceof VanishingCurseEnchantment;
2024-01-19 13:22:30 +01:00
+ return this.handle.isCurse(); // Paper - More Enchantment API
2021-06-11 14:02:28 +02:00
}
@Override
2024-01-26 20:17:06 +01:00
@@ -157,6 +157,55 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
2021-08-14 06:11:12 +02:00
public String translationKey() {
2023-12-06 19:21:23 +01:00
return this.handle.getDescriptionId();
2021-06-11 14:02:28 +02:00
}
+
+ @Override
+ public boolean isTradeable() {
2023-12-06 19:21:23 +01:00
+ return handle.isTradeable();
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public boolean isDiscoverable() {
2023-12-06 19:21:23 +01:00
+ return handle.isDiscoverable();
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
2023-11-11 21:09:48 +01:00
+ public int getMinModifiedCost(int level) {
2023-12-06 19:21:23 +01:00
+ return handle.getMinCost(level);
2023-11-11 21:09:48 +01:00
+ }
+
+ @Override
+ public int getMaxModifiedCost(int level) {
2023-12-06 19:21:23 +01:00
+ return handle.getMaxCost(level);
2023-11-11 21:09:48 +01:00
+ }
+
+ @Override
2021-06-11 14:02:28 +02:00
+ public io.papermc.paper.enchantments.EnchantmentRarity getRarity() {
2023-12-06 19:21:23 +01:00
+ return fromNMSRarity(handle.getRarity());
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public float getDamageIncrease(int level, org.bukkit.entity.EntityCategory entityCategory) {
2023-12-06 19:21:23 +01:00
+ return handle.getDamageBonus(level, org.bukkit.craftbukkit.entity.CraftLivingEntity.fromBukkitEntityCategory(entityCategory));
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public java.util.Set<org.bukkit.inventory.EquipmentSlot> getActiveSlots() {
2023-12-06 19:21:23 +01:00
+ return java.util.stream.Stream.of(handle.slots).map(org.bukkit.craftbukkit.CraftEquipmentSlot::getSlot).collect(java.util.stream.Collectors.toSet());
2021-06-11 14:02:28 +02:00
+ }
+
+ public static io.papermc.paper.enchantments.EnchantmentRarity fromNMSRarity(net.minecraft.world.item.enchantment.Enchantment.Rarity nmsRarity) {
+ if (nmsRarity == net.minecraft.world.item.enchantment.Enchantment.Rarity.COMMON) {
+ return io.papermc.paper.enchantments.EnchantmentRarity.COMMON;
+ } else if (nmsRarity == net.minecraft.world.item.enchantment.Enchantment.Rarity.UNCOMMON) {
+ return io.papermc.paper.enchantments.EnchantmentRarity.UNCOMMON;
+ } else if (nmsRarity == net.minecraft.world.item.enchantment.Enchantment.Rarity.RARE) {
+ return io.papermc.paper.enchantments.EnchantmentRarity.RARE;
+ } else if (nmsRarity == net.minecraft.world.item.enchantment.Enchantment.Rarity.VERY_RARE) {
+ return io.papermc.paper.enchantments.EnchantmentRarity.VERY_RARE;
+ }
+
+ throw new IllegalArgumentException(String.format("Unable to convert %s to a enum value of %s.", nmsRarity, io.papermc.paper.enchantments.EnchantmentRarity.class));
+ }
// Paper end
2023-12-06 04:57:46 +01:00
@Override
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent
CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00
index 72d9a9696c95374bed29e2e453c7750d0cf06170..40fbd911943abd6f6cc7910b5179c196bb3fe8f8 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent
CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00
@@ -978,5 +978,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
2021-06-11 14:02:28 +02:00
public void setHurtDirection(float hurtDirection) {
2023-03-14 23:13:41 +01:00
throw new UnsupportedOperationException("Cannot set the hurt direction on a non player");
2021-06-11 14:02:28 +02:00
}
+
+ 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
}
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
2023-09-24 09:16:58 +02:00
index 0000000000000000000000000000000000000000..03a53ceb0dc3aaff7b5d10ec57f74d71be90ec3a
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/test/java/io/papermc/paper/enchantments/EnchantmentRarityTest.java
@@ -0,0 +1,18 @@
+package io.papermc.paper.enchantments;
+
+import net.minecraft.world.item.enchantment.Enchantment.Rarity;
+import org.bukkit.craftbukkit.enchantments.CraftEnchantment;
2023-09-24 09:16:58 +02:00
+import org.junit.jupiter.api.Test;
2021-06-11 14:02:28 +02:00
+
2023-09-24 09:16:58 +02:00
+import static org.junit.jupiter.api.Assertions.assertNotNull;
2021-06-11 14:02:28 +02:00
+
+public class EnchantmentRarityTest {
+
+ @Test
+ public void test() {
+ for (Rarity nmsRarity : Rarity.values()) {
+ // Will throw exception if a bukkit counterpart is not found
+ CraftEnchantment.fromNMSRarity(nmsRarity);
+ }
+ }
+}
diff --git a/src/test/java/io/papermc/paper/entity/EntityCategoryTest.java b/src/test/java/io/papermc/paper/entity/EntityCategoryTest.java
new file mode 100644
2023-09-24 09:16:58 +02:00
index 0000000000000000000000000000000000000000..4ee48ef89f0e31a7bda4b04453fca8177874f540
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/test/java/io/papermc/paper/entity/EntityCategoryTest.java
@@ -0,0 +1,34 @@
+package io.papermc.paper.entity;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
2021-06-15 04:59:31 +02:00
+import net.minecraft.world.entity.MobType;
2021-06-11 14:02:28 +02:00
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.EntityCategory;
2023-09-24 09:16:58 +02:00
+import org.junit.jupiter.api.Test;
2021-06-11 14:02:28 +02:00
+
+import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.Set;
+
2023-09-24 09:16:58 +02:00
+import static org.junit.jupiter.api.Assertions.assertTrue;
2021-06-11 14:02:28 +02:00
+
+public class EntityCategoryTest {
+
+ @Test
+ public void test() throws IllegalAccessException {
+
2021-06-15 04:59:31 +02:00
+ Map<MobType, String> enumMonsterTypeFieldMap = Maps.newHashMap();
+ for (Field field : MobType.class.getDeclaredFields()) {
+ if (field.getType() == MobType.class) {
+ enumMonsterTypeFieldMap.put( (MobType) field.get(null), field.getName());
2021-06-11 14:02:28 +02:00
+ }
+ }
+
+ for (EntityCategory entityCategory : EntityCategory.values()) {
+ enumMonsterTypeFieldMap.remove(CraftLivingEntity.fromBukkitEntityCategory(entityCategory));
+ }
2023-09-24 09:16:58 +02:00
+ assertTrue(enumMonsterTypeFieldMap.size() == 0, MobType.class.getName() + " instance(s): " + Joiner.on(", ").join(enumMonsterTypeFieldMap.values()) + " do not have bukkit equivalents");
2021-06-11 14:02:28 +02:00
+ }
+}