mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-05 10:20:53 +01:00
275173e538
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: 0c5d8709 SPIGOT-7400: Downgrade maven-resolver due to issues resolving certain depends 255c4fdb SPIGOT-7380: Add PlayerInteractEvent#getClickedPosition and ChiseledBookshelf#getSlot CraftBukkit Changes: b6b514b7e SPIGOT-7400: Downgrade maven-resolver due to issues resolving certain depends fcff84de9 SPIGOT-7399: Revert null check in CraftMetaItem#safelyAdd 44a4b5649 SPIGOT-7380: Add PlayerInteractEvent#getClickedPosition and ChiseledBookshelf#getSlot 676969d01 SPIGOT-7389: Handle setting null items in ChiseledBookshelf Inventory
64 lines
2.7 KiB
Diff
64 lines
2.7 KiB
Diff
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
|
|
|
|
== AT ==
|
|
public net.minecraft.world.item.Item rarity
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 16ef907b9443b9feedd768d0116762799fee9ab3..2a08fca2c863717b72341772630cd4b690f34968 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -528,6 +528,20 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
public String getMainLevelName() {
|
|
return ((net.minecraft.server.dedicated.DedicatedServer) net.minecraft.server.MinecraftServer.getServer()).getProperties().levelName;
|
|
}
|
|
+
|
|
+ @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
|
|
|
|
/**
|
|
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));
|
|
+ }
|
|
+ }
|
|
+}
|