Skip to content

Commit

Permalink
fix(spigot): text displays not being translated on 1.19.3 through 1.20.1
Browse files Browse the repository at this point in the history
The data value index was changed on 1.20.2 to 23 (from 22).
  • Loading branch information
diogotcorreia committed Jun 23, 2024
1 parent 7cf8e45 commit 3485ea0
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class EntitiesPacketHandler extends PacketHandler {

private final DataWatcherHandler dataWatcherHandler;
private final DataValueHandler dataValueHandler;
private final int textDisplaysTextIndex;

public EntitiesPacketHandler() {
if (MinecraftVersion.AQUATIC_UPDATE.atOrAbove()) { // 1.13+
Expand All @@ -64,6 +65,12 @@ public EntitiesPacketHandler() {
this.dataWatcherHandler = new DataWatcherHandler1_8();
}
this.dataValueHandler = new DataValueHandler();

if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { // 1.20.2
textDisplaysTextIndex = 23;
} else {
textDisplaysTextIndex = 22;
}
}

/**
Expand Down Expand Up @@ -362,8 +369,8 @@ private void handleEntityMetadataForDataValues(PacketEvent packet, SpigotLanguag
)
).orElse(oldObject)
);
} else if (oldObject.getIndex() == 23) {
// Index 23 is "Text" of type "Chat"
} else if (oldObject.getIndex() == textDisplaysTextIndex) {
// Index 22/23 is "Text" of type "Chat"
// https://wiki.vg/Entity_metadata#Text_Display
// Used to translate text display entities
newWatchableObjects.add(
Expand Down Expand Up @@ -1346,11 +1353,11 @@ Optional<WrappedDataValue> getTextDisplayTextDataValue(BaseComponent[] component
payload = WrappedChatComponent.fromText("").getHandle();
}

// Display name has: index 23 and type chat
// Display name has: index 22/23 and type chat
// https://wiki.vg/Entity_metadata#Text_Display
return Optional.of(
new WrappedDataValue(
23,
textDisplaysTextIndex,
WrappedDataWatcher.Registry.getChatComponentSerializer(false),
payload
)
Expand Down

0 comments on commit 3485ea0

Please sign in to comment.