diff --git a/patches/api/0480-Item-stack-name-tooltip-API.patch b/patches/api/0480-Item-stack-name-tooltip-API.patch new file mode 100644 index 000000000000..6c190f48818a --- /dev/null +++ b/patches/api/0480-Item-stack-name-tooltip-API.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: radsteve +Date: Sun, 7 Jul 2024 10:51:46 +0200 +Subject: [PATCH] Item stack name tooltip API + + +diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java +index 7c56182acaf827f4b1a986a61cea8e9960604c98..9da64bc368b1eac55fad336f58619509542dd5e1 100644 +--- a/src/main/java/org/bukkit/entity/Player.java ++++ b/src/main/java/org/bukkit/entity/Player.java +@@ -3855,6 +3855,23 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM + boolean isChunkSent(long chunkKey); + // Paper end + ++ // Paper start - Item stack name tooltip API ++ /** ++ * Checks whether the currently held item is assumed to be displaying the item name tooltip on the client. ++ * However, this behavior can be changed via the Accessibility Settings, which can lead to inaccuracies. ++ * Keep in mind that this assumes default settings and is prone to break. ++ * @return true if it is showing with default settings, false if not. ++ */ ++ boolean isItemNameTooltipEstimatedToBeVisible(); ++ ++ /** ++ * Gets the last timestamp when the player has changed their selected item stack in their hotbar. ++ * This time is measured using {@link net.minecraft.Util#getMillis}. ++ * @return The last timestamp, or zero, if the player hasn't changed selected item stacks. ++ */ ++ long getLastItemStackChangeTime(); ++ ++ // Paper end - Item stack name tooltip API + @NotNull + @Override + Spigot spigot(); diff --git a/patches/server/1036-Item-stack-name-tooltip-API.patch b/patches/server/1036-Item-stack-name-tooltip-API.patch new file mode 100644 index 000000000000..40e050ff47b9 --- /dev/null +++ b/patches/server/1036-Item-stack-name-tooltip-API.patch @@ -0,0 +1,68 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: radsteve +Date: Sun, 7 Jul 2024 10:51:55 +0200 +Subject: [PATCH] Item stack name tooltip API + + +diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java +index 9d1e68c09fa7093cf0f6fa636f90cb15a44cbb38..4384869b79539c9e424b20bd656b67160a475b77 100644 +--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java ++++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java +@@ -805,6 +805,19 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple + this.trackEnteredOrExitedLavaOnVehicle(); + this.updatePlayerAttributes(); + this.advancements.flushDirty(this); ++ ++ // Paper start - Item stack name tooltip API ++ // This is taken from net.minecraft.client.gui.Gui#tick and adapted to a non-tick behaviour. ++ ItemStack selectedStack = this.getInventory().getSelected(); ++ if(selectedStack.isEmpty()) { ++ lastItemStackChangeTime = 0; ++ } else { ++ if(!selectedStack.is(this.currentlySelectedItemStack.getItem()) || !selectedStack.getDisplayName().equals(this.currentlySelectedItemStack.getDisplayName())) { ++ lastItemStackChangeTime = net.minecraft.Util.getMillis(); ++ } ++ } ++ this.currentlySelectedItemStack = selectedStack; ++ // Paper end - Item stack name tooltip API + } + + private void updatePlayerAttributes() { +@@ -2944,4 +2957,12 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple + return (CraftPlayer) super.getBukkitEntity(); + } + // CraftBukkit end ++ ++ // Paper start - Item stack name tooltip API ++ private ItemStack currentlySelectedItemStack = ItemStack.EMPTY; ++ private long lastItemStackChangeTime = 0; ++ public long getLastItemStackChangeTime() { ++ return lastItemStackChangeTime; ++ } ++ // Paper end - Item stack name tooltip API + } +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +index d01b45a48d412e3cb591acee101730704574448a..52a985b95d8c6a35f7df52979b7fab84ad673e98 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -3554,4 +3554,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + ((ca.spottedleaf.moonrise.patches.chunk_system.player.ChunkSystemServerPlayer)this.getHandle()) + .moonrise$getViewDistanceHolder().setSendViewDistance(viewDistance); + } ++ ++ // Paper start - Item stack name tooltip API ++ private static final long DEFAULT_ITEM_TOOLTIP_DURATION_MS = 40 * 50; ++ ++ @Override ++ public long getLastItemStackChangeTime() { ++ return this.getHandle().getLastItemStackChangeTime(); ++ } ++ ++ @Override ++ public boolean isItemNameTooltipEstimatedToBeVisible() { ++ long currentTime = net.minecraft.Util.getMillis(); ++ long lastItemStackChange = this.getLastItemStackChangeTime(); ++ return currentTime - lastItemStackChange < DEFAULT_ITEM_TOOLTIP_DURATION_MS; ++ } ++ // Paper end - Item stack name tooltip API + }