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

Handle 1.12 keybind components

Fixes #474
Dieser Commit ist enthalten in:
Nassim Jahnke 2023-03-18 13:55:16 +01:00
Ursprung 68e578a04e
Commit 509055307a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
12 geänderte Dateien mit 44 neuen und 37 gelöschten Zeilen

Datei anzeigen

@ -175,15 +175,6 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
}
}
public void registerMetaTypeHandler(
@Nullable MetaType itemType,
@Nullable MetaType blockType,
@Nullable MetaType particleType,
@Nullable MetaType optionalComponentType
) {
this.registerMetaTypeHandler(itemType, blockType, particleType, optionalComponentType, null);
}
public void registerMetaTypeHandler(
@Nullable MetaType itemType,
@Nullable MetaType blockType,

Datei anzeigen

@ -29,7 +29,24 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter;
public class ChatPackets1_12 extends RewriterBase<Protocol1_11_1To1_12> {
private final ComponentRewriter<ClientboundPackets1_12> componentRewriter = new ComponentRewriter<ClientboundPackets1_12>() {
public static final ComponentRewriter<ClientboundPackets1_12> COMPONENT_REWRITER = new ComponentRewriter<ClientboundPackets1_12>() {
@Override
public void processText(JsonElement element) {
super.processText(element);
if (element == null || !element.isJsonObject()) {
return;
}
JsonObject object = element.getAsJsonObject();
JsonElement keybind = object.remove("keybind");
if (keybind == null) {
return;
}
//TODO Add nicer text for the key, also use this component rewriter in more packets
object.addProperty("text", keybind.getAsString());
}
@Override
protected void handleTranslate(JsonObject object, String translate) {
String text = AdvancementTranslations.get(translate);
@ -47,7 +64,7 @@ public class ChatPackets1_12 extends RewriterBase<Protocol1_11_1To1_12> {
protected void registerPackets() {
protocol.registerClientbound(ClientboundPackets1_12.CHAT_MESSAGE, wrapper -> {
JsonElement element = wrapper.passthrough(Type.COMPONENT);
componentRewriter.processText(element);
COMPONENT_REWRITER.processText(element);
});
}
}

Datei anzeigen

@ -28,10 +28,12 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_12Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_12;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_12;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
@ -205,6 +207,12 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<ClientboundPackets1_
mapEntityTypeWithData(Entity1_12Types.EntityType.PARROT, Entity1_12Types.EntityType.BAT).plainName().spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00)));
mapEntityTypeWithData(Entity1_12Types.EntityType.ILLUSION_ILLAGER, Entity1_12Types.EntityType.EVOCATION_ILLAGER).plainName();
filter().handler((event, meta) -> {
if (meta.metaType() == MetaType1_9.Chat) {
ChatPackets1_12.COMPONENT_REWRITER.processText((JsonElement) meta.getValue());
}
});
// Handle Illager
filter().filterFamily(Entity1_12Types.EntityType.EVOCATION_ILLAGER).cancel(12);
filter().filterFamily(Entity1_12Types.EntityType.EVOCATION_ILLAGER).index(13).toIndex(12);

Datei anzeigen

@ -348,7 +348,8 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
}
});
registerMetaTypeHandler(Types1_13_2.META_TYPES.itemType, Types1_13_2.META_TYPES.blockStateType, null, Types1_13_2.META_TYPES.optionalComponentType);
registerMetaTypeHandler(Types1_13_2.META_TYPES.itemType, Types1_13_2.META_TYPES.blockStateType, null,
Types1_13_2.META_TYPES.optionalComponentType, Types1_13_2.META_TYPES.componentType);
filter().type(Entity1_14Types.PILLAGER).cancel(15);

Datei anzeigen

@ -22,13 +22,10 @@ import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter;
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.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
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.libs.gson.JsonElement;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import java.util.List;
@ -130,21 +127,8 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<ClientboundPackets
@Override
protected void registerRewrites() {
// Rewrite items & blocks
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) {
JsonElement element = meta.value();
protocol.getTranslatableRewriter().processText(element);
}
});
registerMetaTypeHandler(Types1_13.META_TYPES.itemType, Types1_13.META_TYPES.blockStateType, Types1_13.META_TYPES.particleType,
Types1_13.META_TYPES.optionalComponentType, Types1_13.META_TYPES.componentType);
// Remove shooter UUID
filter().filterFamily(Entity1_13Types.EntityType.ABSTRACT_ARROW).cancel(7);

Datei anzeigen

@ -192,7 +192,8 @@ public class EntityPackets1_15 extends EntityRewriter<ClientboundPackets1_15, Pr
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, Types1_14.META_TYPES.particleType, Types1_14.META_TYPES.optionalComponentType);
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, Types1_14.META_TYPES.particleType,
Types1_14.META_TYPES.optionalComponentType, Types1_14.META_TYPES.componentType);
filter().filterFamily(Entity1_15Types.LIVINGENTITY).removeIndex(12);

Datei anzeigen

@ -123,7 +123,7 @@ public class EntityPackets1_16_2 extends EntityRewriter<ClientboundPackets1_16_2
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType,
Types1_16.META_TYPES.particleType, Types1_16.META_TYPES.optionalComponentType);
Types1_16.META_TYPES.particleType, Types1_16.META_TYPES.optionalComponentType, Types1_16.META_TYPES.componentType);
mapTypes(Entity1_16_2Types.values(), Entity1_16Types.class);
mapEntityTypeWithData(Entity1_16_2Types.PIGLIN_BRUTE, Entity1_16_2Types.PIGLIN).jsonName();

Datei anzeigen

@ -180,7 +180,8 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
});
// Particles have already been handled
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null, Types1_16.META_TYPES.optionalComponentType);
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null,
Types1_16.META_TYPES.optionalComponentType, Types1_16.META_TYPES.componentType);
mapTypes(Entity1_17Types.values(), Entity1_16_2Types.class);
filter().type(Entity1_17Types.AXOLOTL).cancel(17);

Datei anzeigen

@ -117,7 +117,8 @@ public final class EntityPackets1_18 extends EntityRewriter<ClientboundPackets1_
});
// Particles have already been handled
registerMetaTypeHandler(Types1_17.META_TYPES.itemType, null, null, Types1_17.META_TYPES.optionalComponentType);
registerMetaTypeHandler(Types1_17.META_TYPES.itemType, null, null,
Types1_17.META_TYPES.optionalComponentType, Types1_17.META_TYPES.componentType);
}
@Override

Datei anzeigen

@ -269,7 +269,8 @@ public final class EntityPackets1_19 extends EntityRewriter<ClientboundPackets1_
}
});
registerMetaTypeHandler(Types1_18.META_TYPES.itemType, Types1_18.META_TYPES.blockStateType, null, Types1_18.META_TYPES.optionalComponentType);
registerMetaTypeHandler(Types1_18.META_TYPES.itemType, Types1_18.META_TYPES.blockStateType, null,
Types1_18.META_TYPES.optionalComponentType, Types1_18.META_TYPES.componentType);
filter().filterFamily(Entity1_19Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
final int data = (int) meta.getValue();

Datei anzeigen

@ -230,7 +230,8 @@ public final class EntityPackets1_19_3 extends EntityRewriter<ClientboundPackets
meta.setMetaType(Types1_19.META_TYPES.byId(id));
}
});
registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, Types1_19.META_TYPES.particleType, Types1_19.META_TYPES.optionalComponentType);
registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, Types1_19.META_TYPES.particleType,
Types1_19.META_TYPES.optionalComponentType, Types1_19.META_TYPES.componentType);
filter().index(6).handler((event, meta) -> {
// Sitting pose added

Datei anzeigen

@ -143,7 +143,8 @@ public final class EntityPackets1_19_4 extends EntityRewriter<ClientboundPackets
meta.setMetaType(Types1_19_3.META_TYPES.byId(id));
});
registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, Types1_19_3.META_TYPES.particleType, Types1_19_3.META_TYPES.optionalComponentType);
registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, Types1_19_3.META_TYPES.particleType,
Types1_19_3.META_TYPES.optionalComponentType, Types1_19_3.META_TYPES.componentType);
filter().filterFamily(Entity1_19_4Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
final int blockState = meta.value();