2021-06-15 04:59:31 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Fri, 12 Mar 2021 17:09:42 -0800
|
|
|
|
Subject: [PATCH] Item Rarity API
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2021-12-22 19:02:31 +01:00
|
|
|
index b56b206c5d875a6b0f55bc506521d5a3dd7c8b68..88d18bcf4f0d7e14c7d358a2771c90422bca2f73 100644
|
2021-06-15 04:59:31 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
2021-11-11 03:53:27 +01:00
|
|
|
@@ -476,6 +476,20 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
2021-06-15 04:59:31 +02:00
|
|
|
public int nextEntityId() {
|
|
|
|
return net.minecraft.world.entity.Entity.nextEntityId();
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public io.papermc.paper.inventory.ItemRarity getItemRarity(org.bukkit.Material material) {
|
|
|
|
+ Item item = getItem(material);
|
|
|
|
+ if (item == null) {
|
|
|
|
+ throw new IllegalArgumentException(material + " is not an item, and rarity does not apply to blocks");
|
|
|
|
+ }
|
|
|
|
+ return io.papermc.paper.inventory.ItemRarity.values()[item.rarity.ordinal()];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public io.papermc.paper.inventory.ItemRarity getItemStackRarity(org.bukkit.inventory.ItemStack itemStack) {
|
|
|
|
+ return io.papermc.paper.inventory.ItemRarity.values()[getItem(itemStack.getType()).getRarity(CraftItemStack.asNMSCopy(itemStack)).ordinal()];
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
/**
|
2021-07-22 06:48:24 +02:00
|
|
|
diff --git a/src/test/java/io/papermc/paper/inventory/ItemRarityTest.java b/src/test/java/io/papermc/paper/inventory/ItemRarityTest.java
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000000000000000000000000000000000..38e6d42098f216b1d24f50386e7be98181122d8d
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/test/java/io/papermc/paper/inventory/ItemRarityTest.java
|
|
|
|
@@ -0,0 +1,24 @@
|
|
|
|
+package io.papermc.paper.inventory;
|
|
|
|
+
|
|
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
|
|
+import net.minecraft.world.item.Rarity;
|
|
|
|
+import org.junit.Test;
|
|
|
|
+
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
|
+
|
|
|
|
+public class ItemRarityTest {
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testConvertFromNmsToBukkit() {
|
|
|
|
+ for (Rarity nmsRarity : Rarity.values()) {
|
|
|
|
+ assertEquals("rarity names are mis-matched", ItemRarity.values()[nmsRarity.ordinal()].name(), nmsRarity.name());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testRarityFormatting() {
|
|
|
|
+ for (Rarity nmsRarity : Rarity.values()) {
|
|
|
|
+ assertEquals("rarity formatting is mis-matched", nmsRarity.color, PaperAdventure.asVanilla(ItemRarity.values()[nmsRarity.ordinal()].color));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|