Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 17:10:13 +01:00
Fix argument type handling
Dieser Commit ist enthalten in:
Ursprung
555e1a7722
Commit
ef204c2ab2
@ -17,13 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1;
|
package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.data.MappingData;
|
import com.viaversion.viaversion.api.data.MappingData;
|
||||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_3Types;
|
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_3Types;
|
||||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
@ -71,6 +71,9 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
|
|||||||
@Override
|
@Override
|
||||||
protected void registerPackets() {
|
protected void registerPackets() {
|
||||||
final TagRewriter tagRewriter = new TagRewriter(this);
|
final TagRewriter tagRewriter = new TagRewriter(this);
|
||||||
|
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:bookshelf_books", "minecraft:hanging_signs", "minecraft:stripped_logs");
|
||||||
|
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:all_hanging_signs", "minecraft:ceiling_hanging_signs", "minecraft:invalid_spawn_inside",
|
||||||
|
"minecraft:stripped_logs", "minecraft:wall_hanging_signs");
|
||||||
tagRewriter.registerGeneric(ClientboundPackets1_19_1.TAGS);
|
tagRewriter.registerGeneric(ClientboundPackets1_19_1.TAGS);
|
||||||
|
|
||||||
entityRewriter.register();
|
entityRewriter.register();
|
||||||
@ -82,56 +85,41 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
|
|||||||
|
|
||||||
new StatisticsRewriter(this).register(ClientboundPackets1_19_1.STATISTICS);
|
new StatisticsRewriter(this).register(ClientboundPackets1_19_1.STATISTICS);
|
||||||
|
|
||||||
final CommandRewriter commandRewriter = new CommandRewriter(this);
|
final CommandRewriter commandRewriter = new CommandRewriter(this) {
|
||||||
registerClientbound(ClientboundPackets1_19_1.DECLARE_COMMANDS, new PacketRemapper() {
|
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception {
|
||||||
handler(wrapper -> {
|
switch (argumentType) {
|
||||||
final int size = wrapper.passthrough(Type.VAR_INT);
|
case "minecraft:item_enchantment":
|
||||||
for (int i = 0; i < size; i++) {
|
wrapper.write(Type.STRING, "minecraft:enchantment");
|
||||||
final byte flags = wrapper.passthrough(Type.BYTE);
|
break;
|
||||||
wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE); // Children indices
|
case "minecraft:mob_effect":
|
||||||
if ((flags & 0x08) != 0) {
|
wrapper.write(Type.STRING, "minecraft:mob_effect");
|
||||||
wrapper.passthrough(Type.VAR_INT); // Redirect node index
|
break;
|
||||||
}
|
case "minecraft:entity_summon":
|
||||||
|
wrapper.write(Type.STRING, "minecraft:entity_type");
|
||||||
final int nodeType = flags & 0x03;
|
break;
|
||||||
if (nodeType == 1 || nodeType == 2) { // Literal/argument node
|
default:
|
||||||
wrapper.passthrough(Type.STRING); // Name
|
super.handleArgument(wrapper, argumentType);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
if (nodeType == 2) { // Argument node
|
|
||||||
final int argumentTypeId = wrapper.read(Type.VAR_INT);
|
|
||||||
final int mappedArgumentTypeId = MAPPINGS.getArgumentTypeMappings().mappings().getNewId(argumentTypeId);
|
|
||||||
Preconditions.checkArgument(mappedArgumentTypeId != -1, "Unknown command argument type id: " + argumentTypeId);
|
|
||||||
wrapper.write(Type.VAR_INT, mappedArgumentTypeId);
|
|
||||||
|
|
||||||
final String identifier = MAPPINGS.getArgumentTypeMappings().identifier(argumentTypeId);
|
|
||||||
commandRewriter.handleArgument(wrapper, identifier);
|
|
||||||
switch (identifier) {
|
|
||||||
case "minecraft:item_enchantment":
|
|
||||||
wrapper.write(Type.STRING, "minecraft:enchantment");
|
|
||||||
break;
|
|
||||||
case "minecraft:mob_effect":
|
|
||||||
wrapper.write(Type.STRING, "minecraft:mob_effect");
|
|
||||||
break;
|
|
||||||
case "minecraft:entity_summon":
|
|
||||||
wrapper.write(Type.STRING, "minecraft:entity_type");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & 0x10) != 0) {
|
|
||||||
wrapper.passthrough(Type.STRING); // Suggestion type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wrapper.passthrough(Type.VAR_INT); // Root node index
|
|
||||||
|
|
||||||
wrapper.cancel(); //TODO
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
@Override
|
||||||
|
public String handleArgumentType(final String argumentType) {
|
||||||
|
switch (argumentType) {
|
||||||
|
case "minecraft:resource":
|
||||||
|
return "minecraft:resource_key";
|
||||||
|
case "minecraft:resource_or_tag":
|
||||||
|
return "minecraft:resource_or_tag_key";
|
||||||
|
case "minecraft:entity_summon":
|
||||||
|
case "minecraft:item_enchantment":
|
||||||
|
case "minecraft:mob_effect":
|
||||||
|
return "minecraft:resource";
|
||||||
|
}
|
||||||
|
return argumentType;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
commandRewriter.registerDeclareCommands1_19(ClientboundPackets1_19_1.DECLARE_COMMANDS);
|
||||||
|
|
||||||
registerClientbound(ClientboundPackets1_19_1.SERVER_DATA, new PacketRemapper() {
|
registerClientbound(ClientboundPackets1_19_1.SERVER_DATA, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.rewriter;
|
package com.viaversion.viaversion.rewriter;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
@ -150,9 +151,8 @@ public class CommandRewriter {
|
|||||||
int argumentTypeId = wrapper.read(Type.VAR_INT);
|
int argumentTypeId = wrapper.read(Type.VAR_INT);
|
||||||
String argumentType = protocol.getMappingData().getArgumentTypeMappings().identifier(argumentTypeId);
|
String argumentType = protocol.getMappingData().getArgumentTypeMappings().identifier(argumentTypeId);
|
||||||
String newArgumentType = handleArgumentType(argumentType);
|
String newArgumentType = handleArgumentType(argumentType);
|
||||||
if (newArgumentType != null) {
|
Preconditions.checkArgument(newArgumentType != null, "No mapping for argument type " + argumentType);
|
||||||
wrapper.write(Type.VAR_INT, protocol.getMappingData().getArgumentTypeMappings().mappedId(newArgumentType));
|
wrapper.write(Type.VAR_INT, protocol.getMappingData().getArgumentTypeMappings().mappedId(newArgumentType));
|
||||||
}
|
|
||||||
|
|
||||||
// Always call the handler using the previous name
|
// Always call the handler using the previous name
|
||||||
handleArgument(wrapper, argumentType);
|
handleArgument(wrapper, argumentType);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"argumenttypes": {
|
"argumenttypes": {
|
||||||
"minecraft:item_enchantment": "minecraft:resource_or_tag_key",
|
"minecraft:item_enchantment": "minecraft:resource",
|
||||||
"minecraft:mob_effect": "minecraft:resource_or_tag_key",
|
"minecraft:mob_effect": "minecraft:resource",
|
||||||
"minecraft:entity_summon": "minecraft:resource_or_tag_key"
|
"minecraft:entity_summon": "minecraft:resource"
|
||||||
}
|
}
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren