mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
c0936a71bd
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: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
158 lines
6.8 KiB
Diff
158 lines
6.8 KiB
Diff
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
|
|
|
|
== AT ==
|
|
public net.minecraft.world.item.enchantment.Enchantment slots
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
index 57decf4156f176ebcc988478c17856cbc555c5e4..3d0ce0803e1da8a2681a3cb41096ac942ece54a1 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
@@ -71,7 +71,7 @@ public class CraftEnchantment extends Enchantment {
|
|
|
|
@Override
|
|
public boolean isCursed() {
|
|
- return this.target instanceof BindingCurseEnchantment || this.target instanceof VanishingCurseEnchantment;
|
|
+ return this.target.isCurse(); // Paper
|
|
}
|
|
|
|
@Override
|
|
@@ -199,6 +199,45 @@ public class CraftEnchantment extends Enchantment {
|
|
public String translationKey() {
|
|
return this.target.getDescriptionId();
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public boolean isTradeable() {
|
|
+ return target.isTradeable();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isDiscoverable() {
|
|
+ return target.isDiscoverable();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public io.papermc.paper.enchantments.EnchantmentRarity getRarity() {
|
|
+ return fromNMSRarity(target.getRarity());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public float getDamageIncrease(int level, org.bukkit.entity.EntityCategory entityCategory) {
|
|
+ return target.getDamageBonus(level, org.bukkit.craftbukkit.entity.CraftLivingEntity.fromBukkitEntityCategory(entityCategory));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public java.util.Set<org.bukkit.inventory.EquipmentSlot> getActiveSlots() {
|
|
+ return java.util.stream.Stream.of(target.slots).map(org.bukkit.craftbukkit.CraftEquipmentSlot::getSlot).collect(java.util.stream.Collectors.toSet());
|
|
+ }
|
|
+
|
|
+ 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
|
|
|
|
public net.minecraft.world.item.enchantment.Enchantment getHandle() {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
index 04816027a7affebb6b3a8e4d1988d56a3d071312..af4d84e35c8f28589edbac9824d8a5770c60552b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
@@ -954,5 +954,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|
public void setHurtDirection(float hurtDirection) {
|
|
throw new UnsupportedOperationException("Cannot set the hurt direction on a non player");
|
|
}
|
|
+
|
|
+ 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
|
|
index 0000000000000000000000000000000000000000..62b56b5b43696b03fc72cac59f986d006edc3f76
|
|
--- /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;
|
|
+import org.junit.Test;
|
|
+
|
|
+import static org.junit.Assert.assertNotNull;
|
|
+
|
|
+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
|
|
index 0000000000000000000000000000000000000000..b9824b1f9491304ceb91be18f4f3b3068526bb33
|
|
--- /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;
|
|
+import net.minecraft.world.entity.MobType;
|
|
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
|
|
+import org.bukkit.entity.EntityCategory;
|
|
+import org.junit.Test;
|
|
+
|
|
+import java.lang.reflect.Field;
|
|
+import java.util.Map;
|
|
+import java.util.Set;
|
|
+
|
|
+import static org.junit.Assert.assertTrue;
|
|
+
|
|
+public class EntityCategoryTest {
|
|
+
|
|
+ @Test
|
|
+ public void test() throws IllegalAccessException {
|
|
+
|
|
+ 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());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ for (EntityCategory entityCategory : EntityCategory.values()) {
|
|
+ enumMonsterTypeFieldMap.remove(CraftLivingEntity.fromBukkitEntityCategory(entityCategory));
|
|
+ }
|
|
+ assertTrue(MobType.class.getName() + " instance(s): " + Joiner.on(", ").join(enumMonsterTypeFieldMap.values()) + " do not have bukkit equivalents", enumMonsterTypeFieldMap.size() == 0);
|
|
+ }
|
|
+}
|