Finish 23w51a, maybe

This commit is contained in:
Nassim Jahnke 2023-12-18 17:14:24 +01:00
parent 90781c9d27
commit 2f8114abb1
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
9 changed files with 57 additions and 26 deletions

View File

@ -79,6 +79,8 @@ public interface MappingData {
*/ */
int getNewParticleId(int id); int getNewParticleId(int id);
int getNewAttributeId(int id);
/** /**
* Returns a list of tags to send if present. * Returns a list of tags to send if present.
* *
@ -105,6 +107,8 @@ public interface MappingData {
@Nullable Mappings getEnchantmentMappings(); @Nullable Mappings getEnchantmentMappings();
@Nullable Mappings getAttributeMappings();
@Nullable FullMappings getEntityMappings(); @Nullable FullMappings getEntityMappings();
@Nullable FullMappings getArgumentTypeMappings(); @Nullable FullMappings getArgumentTypeMappings();

View File

@ -166,6 +166,11 @@ public class MappingDataBase implements MappingData {
return checkValidity(id, particleMappings.getNewId(id), "particles"); return checkValidity(id, particleMappings.getNewId(id), "particles");
} }
@Override
public int getNewAttributeId(final int id) {
return checkValidity(id, attributeMappings.getNewId(id), "attributes");
}
@Override @Override
public @Nullable List<TagData> getTags(final RegistryType type) { public @Nullable List<TagData> getTags(final RegistryType type) {
return tags != null ? tags.get(type) : null; return tags != null ? tags.get(type) : null;
@ -216,6 +221,11 @@ public class MappingDataBase implements MappingData {
return enchantmentMappings; return enchantmentMappings;
} }
@Override
public @Nullable Mappings getAttributeMappings() {
return attributeMappings;
}
@Override @Override
public @Nullable FullMappings getEntityMappings() { public @Nullable FullMappings getEntityMappings() {
return entityMappings; return entityMappings;

View File

@ -44,7 +44,7 @@ public class MappingData extends MappingDataBase {
attributeMappings.put("generic.armorToughness", "minecraft:generic.armor_toughness"); attributeMappings.put("generic.armorToughness", "minecraft:generic.armor_toughness");
} }
public BiMap<String, String> getAttributeMappings() { public BiMap<String, String> attributeIdentifierMappings() {
return attributeMappings; return attributeMappings;
} }
} }

View File

@ -236,7 +236,7 @@ public class EntityPackets {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// Attributes have been renamed and are now namespaced identifiers // Attributes have been renamed and are now namespaced identifiers
String key = wrapper.read(Type.STRING); String key = wrapper.read(Type.STRING);
String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key); String attributeIdentifier = protocol.getMappingData().attributeIdentifierMappings().get(key);
if (attributeIdentifier == null) { if (attributeIdentifier == null) {
attributeIdentifier = Key.namespaced(key); attributeIdentifier = Key.namespaced(key);
if (!Key.isValid(attributeIdentifier)) { if (!Key.isValid(attributeIdentifier)) {

View File

@ -244,8 +244,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
attributeName = Key.namespaced(attributeName); attributeName = Key.namespaced(attributeName);
} }
String mappedAttribute = (inverse ? Protocol1_16To1_15_2.MAPPINGS.getAttributeMappings().inverse() String mappedAttribute = (inverse ? Protocol1_16To1_15_2.MAPPINGS.attributeIdentifierMappings().inverse()
: Protocol1_16To1_15_2.MAPPINGS.getAttributeMappings()).get(attributeName); : Protocol1_16To1_15_2.MAPPINGS.attributeIdentifierMappings()).get(attributeName);
if (mappedAttribute == null) return; if (mappedAttribute == null) return;
attributeNameTag.setValue(mappedAttribute); attributeNameTag.setValue(mappedAttribute);

View File

@ -17,20 +17,44 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data; package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/**
* String to/from int ID mappings for 1.20.3 attributes.
*/
public final class AttributeMappings { public final class AttributeMappings {
private static final String[] ATTRIBUTES; private static final String[] ATTRIBUTES = {
"generic.armor",
"generic.armor_toughness",
"generic.attack_damage",
"generic.attack_knockback",
"generic.attack_speed",
"generic.flying_speed",
"generic.follow_range",
"horse.jump_strength",
"generic.knockback_resistance",
"generic.luck",
"generic.max_absorption",
"generic.max_health",
"generic.movement_speed",
"zombie.spawn_reinforcements"
};
private static final Object2IntMap<String> STRING_TO_ID = new Object2IntOpenHashMap<>();
static { static {
for (int i = 0; i < ATTRIBUTES.length; i++) {
STRING_TO_ID.put(ATTRIBUTES[i], i);
}
} }
public @Nullable String attribute(final int id) { public static @Nullable String attribute(final int id) {
return id >= 0 && id < ATTRIBUTES.length ? ATTRIBUTES[id] : null; return id >= 0 && id < ATTRIBUTES.length ? ATTRIBUTES[id] : null;
} }
public int id(final String attribute) { public static int id(final String attribute) {
return STRING_TO_ID.getOrDefault(attribute, -1);
} }
} }

View File

@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.AttributeMappings;
import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
@ -37,9 +38,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
@Override @Override
public void registerPackets() { public void registerPackets() {
// Tracks entities, applies metadata rewrites registered below, untracks entities
registerTrackerWithData1_19(ClientboundPackets1_20_3.SPAWN_ENTITY, EntityTypes1_20_5.FALLING_BLOCK); registerTrackerWithData1_19(ClientboundPackets1_20_3.SPAWN_ENTITY, EntityTypes1_20_5.FALLING_BLOCK);
registerMetadataRewriter(ClientboundPackets1_20_3.ENTITY_METADATA, /*Types1_OLD.METADATA_LIST, */Types1_20_3.METADATA_LIST); registerMetadataRewriter(ClientboundPackets1_20_3.ENTITY_METADATA, Types1_20_3.METADATA_LIST);
registerRemoveEntities(ClientboundPackets1_20_3.REMOVE_ENTITIES); registerRemoveEntities(ClientboundPackets1_20_3.REMOVE_ENTITIES);
protocol.registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, new PacketHandlers() { protocol.registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, new PacketHandlers() {
@ -54,7 +54,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
protocol.registerClientbound(ClientboundPackets1_20_3.JOIN_GAME, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_20_3.JOIN_GAME, new PacketHandlers() {
@Override @Override
public void register() { public void register() {
map(Type.INT); // Entity id map(Type.INT); // Entity ID
map(Type.BOOLEAN); // Hardcore map(Type.BOOLEAN); // Hardcore
map(Type.STRING_ARRAY); // World List map(Type.STRING_ARRAY); // World List
map(Type.VAR_INT); // Max players map(Type.VAR_INT); // Max players
@ -79,8 +79,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
}); });
protocol.registerClientbound(ClientboundPackets1_20_3.ENTITY_EFFECT, wrapper -> { protocol.registerClientbound(ClientboundPackets1_20_3.ENTITY_EFFECT, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Entity id wrapper.passthrough(Type.VAR_INT); // Entity ID
wrapper.passthrough(Type.VAR_INT); // Effect id wrapper.passthrough(Type.VAR_INT); // Effect ID
wrapper.passthrough(Type.BYTE); // Amplifier wrapper.passthrough(Type.BYTE); // Amplifier
wrapper.passthrough(Type.VAR_INT); // Duration wrapper.passthrough(Type.VAR_INT); // Duration
wrapper.passthrough(Type.BYTE); // Flags wrapper.passthrough(Type.BYTE); // Flags
@ -88,17 +88,19 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
}); });
protocol.registerClientbound(ClientboundPackets1_20_3.ENTITY_PROPERTIES, wrapper -> { protocol.registerClientbound(ClientboundPackets1_20_3.ENTITY_PROPERTIES, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Entity id wrapper.passthrough(Type.VAR_INT); // Entity ID
final int size = wrapper.passthrough(Type.VAR_INT); final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
final String attributeIdentifier = Key.namespaced(wrapper.read(Type.STRING)); // From a string to a registry int ID
wrapper.write(Type.VAR_INT, protocol.getMappingData()); final String attributeIdentifier = Key.stripMinecraftNamespace(wrapper.read(Type.STRING));
final int id = AttributeMappings.id(attributeIdentifier);
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewAttributeId(id));
wrapper.passthrough(Type.DOUBLE); // Base wrapper.passthrough(Type.DOUBLE); // Base
final int modifierSize = wrapper.passthrough(Type.VAR_INT); final int modifierSize = wrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < modifierSize; j++) { for (int j = 0; j < modifierSize; j++) {
wrapper.passthrough(Type.UUID); // Id wrapper.passthrough(Type.UUID); // ID
wrapper.passthrough(Type.DOUBLE); // Amount wrapper.passthrough(Type.DOUBLE); // Amount
wrapper.passthrough(Type.BYTE); // Operation wrapper.passthrough(Type.BYTE); // Operation
} }
@ -108,15 +110,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
/* Uncomment if metatype classes changed
filter().handler((event, meta) -> {
int id = meta.metaType().typeId();
if (id >= SomeAddedIndex) {
id++;
}
meta.setMetaType(Types1_20_3.META_TYPES.byId(id));
});*/
registerMetaTypeHandler( registerMetaTypeHandler(
Types1_20_3.META_TYPES.itemType, Types1_20_3.META_TYPES.itemType,
Types1_20_3.META_TYPES.blockStateType, Types1_20_3.META_TYPES.blockStateType,