Handle argument types, update Via usage

This commit is contained in:
Nassim Jahnke 2022-05-14 12:32:10 +02:00
parent fdc73126f7
commit 68c0a0b333
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
11 changed files with 28 additions and 28 deletions

View File

@ -108,7 +108,7 @@ public class BackwardsMappings extends MappingDataBase {
}
protected boolean shouldWarnOnMissing(String key) {
return !key.equals("blocks") && !key.equals("statistics");
return !key.equals("blocks") && !key.equals("statistics") && !key.equals("entities");
}
@Override

View File

@ -23,13 +23,13 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.entities.storage.EntityData;
import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.Int2IntMapMappings;
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap;
import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import com.viaversion.viaversion.libs.gson.JsonElement;
@ -147,13 +147,12 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends En
@Override
public <E extends Enum<E> & EntityType> void mapTypes(EntityType[] oldTypes, Class<E> newTypeClass) {
if (typeMappings == null) {
typeMappings = new Int2IntOpenHashMap(oldTypes.length, 0.99F);
typeMappings.defaultReturnValue(-1);
typeMappings = Int2IntMapMappings.of();
}
for (EntityType oldType : oldTypes) {
try {
E newType = Enum.valueOf(newTypeClass, oldType.name());
typeMappings.put(oldType.getId(), newType.getId());
typeMappings.setNewId(oldType.getId(), newType.getId());
} catch (IllegalArgumentException ignored) {
// Don't warn
}

View File

@ -37,7 +37,7 @@ public class CommandRewriter1_14 extends CommandRewriter {
}
@Override
protected @Nullable String handleArgumentType(String argumentType) {
public @Nullable String handleArgumentType(String argumentType) {
switch (argumentType) {
case "minecraft:nbt_compound_tag":
return "minecraft:nbt";

View File

@ -33,7 +33,7 @@ public class CommandRewriter1_13_1 extends CommandRewriter {
}
@Override
protected @Nullable String handleArgumentType(String argumentType) {
public @Nullable String handleArgumentType(String argumentType) {
if (argumentType.equals("minecraft:column_pos")) {
return "minecraft:vec2";
} else if (argumentType.equals("minecraft:dimension")) {

View File

@ -28,7 +28,7 @@ public class CommandRewriter1_16 extends CommandRewriter {
}
@Override
protected @Nullable String handleArgumentType(String argumentType) {
public @Nullable String handleArgumentType(String argumentType) {
if (argumentType.equals("minecraft:uuid")) {
return "minecraft:game_profile";
}

View File

@ -33,7 +33,7 @@ public class CommandRewriter1_16_2 extends CommandRewriter {
}
@Override
protected @Nullable String handleArgumentType(String argumentType) {
public @Nullable String handleArgumentType(String argumentType) {
if (argumentType.equals("minecraft:angle")) {
return "brigadier:string";
}

View File

@ -71,8 +71,10 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
@Override
protected void registerPackets() {
//TODO block entity update, chunk?
executeAsyncAfterLoaded(Protocol1_19To1_18_2.class, MAPPINGS::load);
executeAsyncAfterLoaded(Protocol1_19To1_18_2.class, () -> {
MAPPINGS.load();
entityRewriter.onMappingDataLoaded();
});
//TODO update translation mappings on release
translatableRewriter.registerComponentPacket(ClientboundPackets1_19.ACTIONBAR);
@ -169,7 +171,7 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
argumentType = "minecraft:no";
}
wrapper.write(Type.STRING, argumentType);
wrapper.write(Type.STRING, commandRewriter.handleArgumentType(argumentType));
commandRewriter.handleArgument(wrapper, argumentType);
if ((flags & 0x10) != 0) {
@ -188,8 +190,12 @@ public final class Protocol1_18_2To1_19 extends BackwardsProtocol<ClientboundPac
registerClientbound(ClientboundPackets1_19.PLAYER_CHAT, ClientboundPackets1_18.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.COMPONENT); // Message
read(Type.OPTIONAL_COMPONENT); //TODO Oh god oh no
handler(wrapper -> {
// Send the unsigned message if present, otherwise the signed message
final JsonElement message = wrapper.read(Type.COMPONENT);
final JsonElement unsignedMessage = wrapper.read(Type.OPTIONAL_COMPONENT);
wrapper.write(Type.COMPONENT, unsignedMessage != null ? unsignedMessage : message);
});
map(Type.VAR_INT, Type.BYTE); // Chat type
map(Type.UUID); // Sender
handler(wrapper -> {

View File

@ -20,20 +20,12 @@ package com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.data;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.rewriter.CommandRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class CommandRewriter1_19 extends CommandRewriter {
public CommandRewriter1_19(Protocol protocol) {
super(protocol);
//TODO
}
@Override
protected @Nullable String handleArgumentType(String argumentType) {
if (argumentType.equals("minecraft:resource") || argumentType.equals("minecraft:resource_or_tag")) {
return "brigadier:string";
}
return super.handleArgumentType(argumentType);
this.parserHandlers.put("minecraft:template_mirror", wrapper -> wrapper.write(Type.VAR_INT, 0));
this.parserHandlers.put("minecraft:template_rotation", wrapper -> wrapper.write(Type.VAR_INT, 0));
}
}

View File

@ -24,7 +24,6 @@ import com.viaversion.viabackwards.protocol.protocol1_18_2to1_19.storage.StoredP
import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
@ -231,7 +230,7 @@ public final class EntityPackets1_19 extends EntityRewriter<Protocol1_18_2To1_19
}
@Override
protected void registerRewrites() {
public void onMappingDataLoaded() {
filter().handler((event, meta) -> {
if (meta.metaType().typeId() <= Types1_18.META_TYPES.poseType.typeId()) {
meta.setMetaType(Types1_18.META_TYPES.byId(meta.metaType().typeId()));
@ -267,7 +266,7 @@ public final class EntityPackets1_19 extends EntityRewriter<Protocol1_18_2To1_19
registerMetaTypeHandler(Types1_18.META_TYPES.itemType, Types1_18.META_TYPES.blockStateType, null, Types1_18.META_TYPES.optionalComponentType);
mapTypes(Entity1_19Types.values(), Entity1_17Types.class);
mapTypes();
filter().filterFamily(Entity1_19Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
final int data = (int) meta.getValue();

View File

@ -39,7 +39,7 @@ public final class CommandRewriter1_18_2 extends CommandRewriter {
}
@Override
protected @Nullable String handleArgumentType(String argumentType) {
public @Nullable String handleArgumentType(String argumentType) {
if (argumentType.equals("minecraft:resource") || argumentType.equals("minecraft:resource_or_tag")) {
return "brigadier:string";
}

View File

@ -728,6 +728,10 @@
"minecraft:water": "minecraft:void",
"minecraft:wind": "minecraft:void"
},
"argumenttypes": {
"minecraft:template_mirror": "brigadier:string",
"minecraft:template_rotation": "brigadier:string"
},
"entitynames": {
"warden": "Warden",
"frog": "Frog",