mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-20 01:25:27 +01:00
hollow-cube/fix-entity-metadata-translation
(cherry picked from commit d47db72421
)
This commit is contained in:
parent
f8518bdae8
commit
47a5f9dea4
@ -2,6 +2,7 @@ package net.minestom.demo;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.adventure.MinestomAdventure;
|
||||
import net.minestom.server.adventure.audience.Audiences;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
@ -160,6 +161,9 @@ public class PlayerInit {
|
||||
var eventHandler = MinecraftServer.getGlobalEventHandler();
|
||||
eventHandler.addChild(DEMO_NODE);
|
||||
|
||||
MinestomAdventure.AUTOMATIC_COMPONENT_TRANSLATION = true;
|
||||
MinestomAdventure.COMPONENT_TRANSLATOR = (c, l) -> c;
|
||||
|
||||
eventHandler.addListener(ServerTickMonitorEvent.class, event -> LAST_TICK.set(event.getTickMonitor()));
|
||||
|
||||
BenchmarkManager benchmarkManager = MinecraftServer.getBenchmarkManager();
|
||||
|
@ -13,8 +13,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static net.minestom.server.network.NetworkBuffer.BYTE;
|
||||
import static net.minestom.server.network.NetworkBuffer.VAR_INT;
|
||||
import static net.minestom.server.network.NetworkBuffer.*;
|
||||
|
||||
public record EntityMetaDataPacket(int entityId,
|
||||
@NotNull Map<Integer, Metadata.Entry<?>> entries) implements ComponentHoldingServerPacket {
|
||||
@ -69,9 +68,17 @@ public record EntityMetaDataPacket(int entityId,
|
||||
final var entries = new HashMap<Integer, Metadata.Entry<?>>();
|
||||
|
||||
this.entries.forEach((key, value) -> {
|
||||
final var t = value.type();
|
||||
final var v = value.value();
|
||||
|
||||
entries.put(key, v instanceof Component c ? Metadata.OptChat(operator.apply(c)) : value);
|
||||
if (v instanceof Component c) {
|
||||
var translated = operator.apply(c);
|
||||
entries.put(key, t == Metadata.TYPE_OPTCHAT ? Metadata.OptChat(translated) : Metadata.Chat(translated));
|
||||
} else {
|
||||
entries.put(key, value);
|
||||
}
|
||||
|
||||
entries.put(key, v instanceof Component c ? Metadata.Chat(operator.apply(c)) : value);
|
||||
});
|
||||
|
||||
return new EntityMetaDataPacket(this.entityId, entries);
|
||||
|
Loading…
Reference in New Issue
Block a user