Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/patches/server/0520-Item-Rarity-API.patch

64 Zeilen
2.8 KiB
Diff

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
== AT ==
public net.minecraft.world.item.Item rarity
2021-06-15 04:59:31 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
2024-04-26 08:29:16 +02:00
index c0592a85a1a0781b83232533b9ca1b30b116eb98..125ed63d8ae812284cd452b4387fd0d674c9c25a 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
2024-04-26 08:29:16 +02:00
@@ -542,6 +542,20 @@ public final class CraftMagicNumbers implements UnsafeValues {
public String getMainLevelName() {
return ((net.minecraft.server.dedicated.DedicatedServer) net.minecraft.server.MinecraftServer.getServer()).getProperties().levelName;
2021-06-15 04:59:31 +02:00
}
+
+ @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");
+ }
2024-04-25 07:16:04 +02:00
+ return io.papermc.paper.inventory.ItemRarity.values()[item.components().getOrDefault(net.minecraft.core.component.DataComponents.RARITY, net.minecraft.world.item.Rarity.COMMON).ordinal()];
2021-06-15 04:59:31 +02:00
+ }
+
+ @Override
+ public io.papermc.paper.inventory.ItemRarity getItemStackRarity(org.bukkit.inventory.ItemStack itemStack) {
2024-04-25 07:16:04 +02:00
+ return io.papermc.paper.inventory.ItemRarity.values()[itemStack.getRarity().ordinal()];
2021-06-15 04:59:31 +02:00
+ }
// 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
2024-04-26 20:39:20 +02:00
index 0000000000000000000000000000000000000000..8086e6a754cb94ce15428ac0cdbaa43590beb9fe
2021-07-22 06:48:24 +02:00
--- /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.jupiter.api.Test;
2021-07-22 06:48:24 +02:00
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
2021-07-22 06:48:24 +02:00
+
+public class ItemRarityTest {
+
+ @Test
+ public void testConvertFromNmsToBukkit() {
+ for (Rarity nmsRarity : Rarity.values()) {
+ assertEquals(ItemRarity.values()[nmsRarity.ordinal()].name(), nmsRarity.name(), "rarity names are mis-matched");
2021-07-22 06:48:24 +02:00
+ }
+ }
+
+ @Test
+ public void testRarityFormatting() {
+ for (Rarity nmsRarity : Rarity.values()) {
2024-04-26 20:39:20 +02:00
+ assertEquals(nmsRarity.color(), PaperAdventure.asVanilla(ItemRarity.values()[nmsRarity.ordinal()].color), "rarity formatting is mis-matched");
2021-07-22 06:48:24 +02:00
+ }
+ }
+}