Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item stack name tooltip API #11033

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions patches/api/0480-Item-stack-name-tooltip-API.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: radsteve <[email protected]>
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..f7d0d7937e86a4a1b51fc2105f072f40ae623396 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -3855,6 +3855,14 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
boolean isChunkSent(long chunkKey);
// Paper end

+ /**
+ * Checks whether the currently held item is 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 isItemNameTooltipShown(); // Paper - Item stack name tooltip API
+
@NotNull
@Override
Spigot spigot();
94 changes: 94 additions & 0 deletions patches/server/1036-Item-stack-name-tooltip-API.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: radsteve <[email protected]>
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..1ec6599676de973d10c297c9082cb4dece1a34cd 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -95,7 +95,6 @@ import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Unit;
import net.minecraft.world.damagesource.DamageSource;
-import net.minecraft.world.damagesource.DamageSources;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
@@ -805,6 +804,18 @@ 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
radstevee marked this conversation as resolved.
Show resolved Hide resolved
+ 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 +2955,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..156f64452a766f235c8a3d7c75e1129fbc260aef 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -161,7 +161,6 @@ import org.bukkit.craftbukkit.map.CraftMapView;
import org.bukkit.craftbukkit.map.RenderData;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
-import org.bukkit.craftbukkit.profile.CraftPlayerProfile;
radstevee marked this conversation as resolved.
Show resolved Hide resolved
import org.bukkit.craftbukkit.scoreboard.CraftScoreboard;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.craftbukkit.util.CraftLocation;
@@ -174,7 +173,6 @@ import org.bukkit.event.player.PlayerExpCooldownChangeEvent;
import org.bukkit.event.player.PlayerHideEntityEvent;
import org.bukkit.event.player.PlayerRegisterChannelEvent;
import org.bukkit.event.player.PlayerShowEntityEvent;
-import org.bukkit.event.player.PlayerSpawnChangeEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerUnregisterChannelEvent;
import org.bukkit.inventory.EquipmentSlot;
@@ -187,7 +185,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
-import org.bukkit.profile.PlayerProfile;
import org.bukkit.scoreboard.Scoreboard;
import org.jetbrains.annotations.NotNull;

@@ -3554,4 +3551,15 @@ 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 boolean isItemNameTooltipShown() {
+ long currentTime = net.minecraft.Util.getMillis();
+ long lastItemStackChange = this.getHandle().getLastItemStackChangeTime();
+ return currentTime - lastItemStackChange < DEFAULT_ITEM_TOOLTIP_DURATION_MS;
+ }
+ // Paper end - Item stack name tooltip API
}