Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 02:50:09 +01:00
Add Item Rarity API (#5352)
Dieser Commit ist enthalten in:
Ursprung
d80e43647d
Commit
cdbf2578c0
88
Spigot-API-Patches/0282-Item-Rarity-API.patch
Normale Datei
88
Spigot-API-Patches/0282-Item-Rarity-API.patch
Normale Datei
@ -0,0 +1,88 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Date: Fri, 12 Mar 2021 17:09:40 -0800
|
||||
Subject: [PATCH] Item Rarity API
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/inventory/ItemRarity.java b/src/main/java/io/papermc/paper/inventory/ItemRarity.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..74ef8395cc040ce488c2acaa416db20272cc2734
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/inventory/ItemRarity.java
|
||||
@@ -0,0 +1,28 @@
|
||||
+package io.papermc.paper.inventory;
|
||||
+
|
||||
+import net.kyori.adventure.text.format.NamedTextColor;
|
||||
+import net.kyori.adventure.text.format.TextColor;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+public enum ItemRarity {
|
||||
+
|
||||
+ COMMON(NamedTextColor.WHITE),
|
||||
+ UNCOMMON(NamedTextColor.YELLOW),
|
||||
+ RARE(NamedTextColor.AQUA),
|
||||
+ EPIC(NamedTextColor.LIGHT_PURPLE);
|
||||
+
|
||||
+ TextColor color;
|
||||
+
|
||||
+ ItemRarity(TextColor color) {
|
||||
+ this.color = color;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the color formatting associated with the rarity.
|
||||
+ * @return
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public TextColor getColor() {
|
||||
+ return color;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
|
||||
index 7b77c7132723a01e8c38ddaa616b363be300b653..0a31a5321ac519568db936c94394f71b2e2fcec1 100644
|
||||
--- a/src/main/java/org/bukkit/Material.java
|
||||
+++ b/src/main/java/org/bukkit/Material.java
|
||||
@@ -3588,6 +3588,17 @@ public enum Material implements Keyed {
|
||||
public String getTranslationKey() {
|
||||
return Bukkit.getUnsafe().getTranslationKey(this);
|
||||
}
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the item rarity for the item. The Material <b>MUST</b> be an Item not a block.
|
||||
+ * Use {@link #isItem()} before this.
|
||||
+ *
|
||||
+ * @return the item rarity
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public io.papermc.paper.inventory.ItemRarity getItemRarity() {
|
||||
+ return Bukkit.getUnsafe().getItemRarity(this);
|
||||
+ }
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
|
||||
index f486d7c819f6330223980793c9b086fded0af059..7f90ef2fd1c87c5b8b69f2e9dba3ad8e6e9ce3ec 100644
|
||||
--- a/src/main/java/org/bukkit/UnsafeValues.java
|
||||
+++ b/src/main/java/org/bukkit/UnsafeValues.java
|
||||
@@ -125,5 +125,21 @@ public interface UnsafeValues {
|
||||
*/
|
||||
public int nextEntityId();
|
||||
|
||||
+ /**
|
||||
+ * Gets the item rarity of a material. The material <b>MUST</b> be an item.
|
||||
+ * Use {@link Material#isItem()} before this.
|
||||
+ *
|
||||
+ * @param material the material to get the rarity of
|
||||
+ * @return the item rarity
|
||||
+ */
|
||||
+ public io.papermc.paper.inventory.ItemRarity getItemRarity(Material material);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the item rarity of the itemstack. The rarity can change based on enchantements.
|
||||
+ *
|
||||
+ * @param itemStack the itemstack to get the rarity of
|
||||
+ * @return the itemstack rarity
|
||||
+ */
|
||||
+ public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack);
|
||||
// Paper end
|
||||
}
|
52
Spigot-Server-Patches/0695-Item-Rarity-API.patch
Normale Datei
52
Spigot-Server-Patches/0695-Item-Rarity-API.patch
Normale Datei
@ -0,0 +1,52 @@
|
||||
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/net/minecraft/server/Item.java b/src/main/java/net/minecraft/server/Item.java
|
||||
index c3b57e8d572d13ec74d6df5544072cdc55756690..2304730bbd66f9a37975f2684794bb8402654fad 100644
|
||||
--- a/src/main/java/net/minecraft/server/Item.java
|
||||
+++ b/src/main/java/net/minecraft/server/Item.java
|
||||
@@ -15,7 +15,7 @@ public class Item implements IMaterial {
|
||||
protected static final UUID g = UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3");
|
||||
protected static final Random RANDOM = new Random();
|
||||
protected final CreativeModeTab i;
|
||||
- private final EnumItemRarity a;
|
||||
+ private final EnumItemRarity a; public final EnumItemRarity getItemRarity() { return a; } // Paper - OBFHELPER
|
||||
private final int maxStackSize;
|
||||
private final int durability;
|
||||
private final boolean d;
|
||||
@@ -178,6 +178,7 @@ public class Item implements IMaterial {
|
||||
return itemstack.hasEnchantments();
|
||||
}
|
||||
|
||||
+ public EnumItemRarity getItemStackRarity(ItemStack itemStack) { return i(itemStack); } // Paper - OBFHELPER
|
||||
public EnumItemRarity i(ItemStack itemstack) {
|
||||
if (!itemstack.hasEnchantments()) {
|
||||
return this.a;
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
index 00e53d577b1dcaccb409e62d35165ee015de9330..57d56ff1b41582f0d249b24165d5b08b02b0f9fe 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -447,6 +447,20 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
return net.minecraft.server.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.getItemRarity().ordinal()];
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.inventory.ItemRarity getItemStackRarity(org.bukkit.inventory.ItemStack itemStack) {
|
||||
+ return io.papermc.paper.inventory.ItemRarity.values()[getItem(itemStack.getType()).getItemStackRarity(CraftItemStack.asNMSCopy(itemStack)).ordinal()];
|
||||
+ }
|
||||
+
|
||||
// Paper end
|
||||
|
||||
/**
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren