mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Add an event similar to PlayerEvent.NameFormat but for the name shown in the tab list. (#7740)
This commit is contained in:
1 parent
da2594289c
commit
77d41023b5
3 files changed
+76
-3
No files matched your search
@@ -150,6 +150,19 @@
|
||||
}
|
||||
|
||||
public ChatVisibility func_147096_v() {
|
||||
@@ -1276,7 +_,11 @@
|
||||
|
||||
@Nullable
|
||||
public ITextComponent func_175396_E() {
|
||||
- return null;
|
||||
+ if (!this.hasTabListName) {
|
||||
+ this.tabListDisplayName = net.minecraftforge.event.ForgeEventFactory.getPlayerTabListDisplayName(this);
|
||||
+ this.hasTabListName = true;
|
||||
+ }
|
||||
+ return this.tabListDisplayName;
|
||||
}
|
||||
|
||||
public void func_184609_a(Hand p_184609_1_) {
|
||||
@@ -1301,14 +_,14 @@
|
||||
this.func_184210_p();
|
||||
if (p_200619_1_ == this.field_70170_p) {
|
||||
@@ -193,10 +206,11 @@
|
||||
this.field_70170_p.func_217376_c(itementity);
|
||||
ItemStack itemstack = itementity.func_92059_d();
|
||||
if (p_146097_3_) {
|
||||
@@ -1403,6 +_,15 @@
|
||||
@@ -1402,6 +_,29 @@
|
||||
}
|
||||
|
||||
return itementity;
|
||||
}
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private String language = "en_us";
|
||||
@@ -206,6 +220,19 @@
|
||||
+ */
|
||||
+ public String getLanguage() {
|
||||
+ return this.language;
|
||||
+ }
|
||||
+
|
||||
+ // We need this as tablistDisplayname may be null even if the the event was fired.
|
||||
+ private boolean hasTabListName = false;
|
||||
+ private ITextComponent tabListDisplayName = null;
|
||||
+ /**
|
||||
+ * Force the name displayed in the tab list to refresh, by firing {@link net.minecraftforge.event.entity.player.PlayerEvent.TabListNameFormat}.
|
||||
+ */
|
||||
+ public void refreshTabListName() {
|
||||
+ ITextComponent oldName = this.tabListDisplayName;
|
||||
+ this.tabListDisplayName = net.minecraftforge.event.ForgeEventFactory.getPlayerTabListDisplayName(this);
|
||||
+ if (!java.util.Objects.equals(oldName, this.tabListDisplayName)) {
|
||||
+ this.func_184102_h().func_184103_al().func_148540_a(new net.minecraft.network.play.server.SPlayerListItemPacket(net.minecraft.network.play.server.SPlayerListItemPacket.Action.UPDATE_DISPLAY_NAME, this));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -260,6 +260,13 @@ public class ForgeEventFactory
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getDisplayname();
|
||||
}
|
||||
|
||||
public static ITextComponent getPlayerTabListDisplayName(PlayerEntity player)
|
||||
{
|
||||
PlayerEvent.TabListNameFormat event = new PlayerEvent.TabListNameFormat(player);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getDisplayName();
|
||||
}
|
||||
|
||||
public static BlockState fireFluidPlaceBlockEvent(IWorld world, BlockPos pos, BlockPos liquidPos, BlockState state)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ package net.minecraftforge.event.entity.player;
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
@@ -39,6 +40,7 @@ import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* PlayerEvent is fired whenever an event involving Living entities occurs. <br>
|
||||
@@ -180,6 +182,43 @@ public class PlayerEvent extends LivingEvent
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TabListNameFormat is fired when a player's display name for the tablist is retrieved.<br>
|
||||
* This event is fired whenever a player's display name for the tablist is retrieved in
|
||||
* {@link ServerPlayerEntity#getTabListDisplayName()} or {@link ServerPlayerEntity#refreshTabListName()}.<br>
|
||||
* <br>
|
||||
* This event is fired via the {@link ForgeEventFactory#getPlayerTabListDisplayName(PlayerEntity)}.<br>
|
||||
* <br>
|
||||
* {@link #getDisplayName()} contains the display name of the player or null if the client should determine the display name itself.
|
||||
* <br>
|
||||
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
public static class TabListNameFormat extends PlayerEvent
|
||||
{
|
||||
@Nullable
|
||||
private ITextComponent displayName;
|
||||
|
||||
public TabListNameFormat(PlayerEntity player)
|
||||
{
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(@Nullable ITextComponent displayName)
|
||||
{
|
||||
this.displayName = displayName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the EntityPlayer is cloned, typically caused by the network sending a RESPAWN_PLAYER event.
|
||||
* Either caused by death, or by traveling from the End to the overworld.
|
||||
|
||||
Reference in new issue
Block a user