Don't override getTranslatableRewriter in 1.13->1.12, 1.14->1.13 protocols

The method is used in item handling and would otherwise mess up the lore
This commit is contained in:
Nassim Jahnke 2023-03-20 10:05:46 +01:00
parent 614207aeef
commit 0d4257f228
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
5 changed files with 25 additions and 8 deletions

View File

@ -63,7 +63,9 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
if (lore != null) { if (lore != null) {
boolean changed = false; boolean changed = false;
for (Tag loreEntryTag : lore) { for (Tag loreEntryTag : lore) {
if (!(loreEntryTag instanceof StringTag)) continue; if (!(loreEntryTag instanceof StringTag)) {
continue;
}
StringTag loreEntry = (StringTag) loreEntryTag; StringTag loreEntry = (StringTag) loreEntryTag;
String newValue = protocol.getTranslatableRewriter().processText(loreEntry.getValue()).toString(); String newValue = protocol.getTranslatableRewriter().processText(loreEntry.getValue()).toString();

View File

@ -142,8 +142,8 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
return blockItemPackets; return blockItemPackets;
} }
@Override // Don't override the parent method
public TranslatableRewriter<ClientboundPackets1_13> getTranslatableRewriter() { public TranslatableRewriter<ClientboundPackets1_13> translatableRewriter() {
return translatableRewriter; return translatableRewriter;
} }

View File

@ -279,7 +279,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
int typeId = meta.metaType().typeId(); int typeId = meta.metaType().typeId();
if (typeId == 4) { if (typeId == 4) {
JsonElement element = meta.value(); JsonElement element = meta.value();
protocol.getTranslatableRewriter().processText(element); protocol.translatableRewriter().processText(element);
meta.setMetaType(MetaType1_12.Chat); meta.setMetaType(MetaType1_12.Chat);
} else if (typeId == 5) { } else if (typeId == 5) {
// Rewrite optional chat to string // Rewrite optional chat to string

View File

@ -228,8 +228,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
return itemRewriter; return itemRewriter;
} }
@Override public TranslatableRewriter<ClientboundPackets1_13> translatableRewriter() {
public TranslatableRewriter<ClientboundPackets1_13> getTranslatableRewriter() {
return translatableRewriter; return translatableRewriter;
} }
} }

View File

@ -22,10 +22,13 @@ import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import java.util.List; import java.util.List;
@ -127,8 +130,21 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<ClientboundPackets
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
registerMetaTypeHandler(Types1_13.META_TYPES.itemType, Types1_13.META_TYPES.blockStateType, Types1_13.META_TYPES.particleType, // Rewrite items & blocks
Types1_13.META_TYPES.optionalComponentType, Types1_13.META_TYPES.componentType); filter().handler((event, meta) -> {
if (meta.metaType() == Types1_13.META_TYPES.itemType) {
protocol.getItemRewriter().handleItemToClient((Item) meta.getValue());
} else if (meta.metaType() == Types1_13.META_TYPES.blockStateType) {
// Convert to new block id
int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (meta.metaType() == Types1_13.META_TYPES.particleType) {
rewriteParticle((Particle) meta.getValue());
} else if (meta.metaType() == Types1_13.META_TYPES.optionalComponentType || meta.metaType() == Types1_13.META_TYPES.componentType) {
JsonElement element = meta.value();
protocol.translatableRewriter().processText(element);
}
});
// Remove shooter UUID // Remove shooter UUID
filter().filterFamily(Entity1_13Types.EntityType.ABSTRACT_ARROW).cancel(7); filter().filterFamily(Entity1_13Types.EntityType.ABSTRACT_ARROW).cancel(7);