Paper/patches/server-remapped/0691-Item-Rarity-API.patch
2021-06-11 14:02:28 +02:00

53 lines
2.6 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
diff --git a/src/main/java/net/minecraft/world/item/Item.java b/src/main/java/net/minecraft/world/item/Item.java
index 58400e84830c93675b0a1fe632be5e217c19a932..cb079bfd5339b96ad372b0a3b483d02cd0636bfd 100644
--- a/src/main/java/net/minecraft/world/item/Item.java
+++ b/src/main/java/net/minecraft/world/item/Item.java
@@ -45,7 +45,7 @@ public class Item implements ItemLike {
protected static final UUID BASE_ATTACK_SPEED_UUID = UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3");
protected static final Random random = new Random();
protected final CreativeModeTab category;
- private final Rarity rarity;
+ private final Rarity rarity; public final Rarity getItemRarity() { return rarity; } // Paper - OBFHELPER
private final int maxStackSize;
private final int maxDamage;
private final boolean isFireResistant;
@@ -209,6 +209,7 @@ public class Item implements ItemLike {
return stack.isEnchanted();
}
+ public Rarity getItemStackRarity(ItemStack itemStack) { return getRarity(itemStack); } // Paper - OBFHELPER
public Rarity getRarity(ItemStack stack) {
if (!stack.isEnchanted()) {
return this.rarity;
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index 25a29d997f163ce2b11330d66a691601f514a9cb..472b0615dcdc3c0c52bd377fd69752716f354262 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -470,6 +470,20 @@ public final class CraftMagicNumbers implements UnsafeValues {
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.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
/**