3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Rewrite inventory names which use .name syntax

Dieser Commit ist enthalten in:
Myles 2019-04-23 10:30:21 +01:00
Ursprung 03382ea987
Commit dad71f1179
2 geänderte Dateien mit 48 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,45 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TranslatableComponent;
import net.md_5.bungee.chat.ComponentSerializer;
public class InventoryNameRewriter {
public static String processTranslate(String value) {
BaseComponent[] components = ComponentSerializer.parse(value);
for (BaseComponent component : components) {
processTranslate(component);
}
if (components.length == 1) {
return ComponentSerializer.toString(components[0]);
} else {
return ComponentSerializer.toString(components);
}
}
private static void processTranslate(BaseComponent component) {
if (component instanceof TranslatableComponent) {
String oldTranslate = ((TranslatableComponent) component).getTranslate();
// Mojang decided to remove .name from inventory titles
if (oldTranslate.startsWith("block.") && oldTranslate.endsWith(".name")) {
((TranslatableComponent) component).setTranslate(oldTranslate.substring(0, oldTranslate.length() - 5));
}
if (((TranslatableComponent) component).getWith() != null) {
for (BaseComponent baseComponent : ((TranslatableComponent) component).getWith()) {
processTranslate(baseComponent);
}
}
}
if (component.getHoverEvent() != null) {
for (BaseComponent baseComponent : component.getHoverEvent().getValue()) {
processTranslate(baseComponent);
}
}
if (component.getExtra() != null) {
for (BaseComponent baseComponent : component.getExtra()) {
processTranslate(baseComponent);
}
}
}
}

Datei anzeigen

@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.InventoryNameRewriter;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
@ -38,9 +39,10 @@ public class InventoryPackets {
public void handle(PacketWrapper wrapper) throws Exception {
Short windowsId = wrapper.read(Type.UNSIGNED_BYTE);
String type = wrapper.read(Type.STRING);
String title = wrapper.read(Type.STRING);
String title = InventoryNameRewriter.processTranslate(wrapper.read(Type.STRING));
Short slots = wrapper.read(Type.UNSIGNED_BYTE);
if (type.equals("EntityHorse")) {
wrapper.setId(0x1F);
int entityId = wrapper.read(Type.INT);