This commit is contained in:
Nassim Jahnke 2024-03-16 23:11:38 +01:00
parent a453163822
commit e1f2f151c9
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
9 changed files with 80 additions and 28 deletions

View File

@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.data.Int2IntMapMappings;
import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.data.entity.TrackedEntity; import com.viaversion.viaversion.api.data.entity.TrackedEntity;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
@ -210,12 +211,13 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
} }
public void registerMetaTypeHandler1_20_3( public void registerMetaTypeHandler1_20_3(
@Nullable MetaType itemType, @Nullable MetaType itemType,
@Nullable MetaType blockStateType, @Nullable MetaType blockStateType,
@Nullable MetaType optionalBlockStateType, @Nullable MetaType optionalBlockStateType,
@Nullable MetaType particleType, @Nullable MetaType particleType,
@Nullable MetaType componentType, @Nullable MetaType particlesType,
@Nullable MetaType optionalComponentType @Nullable MetaType componentType,
@Nullable MetaType optionalComponentType
) { ) {
filter().handler((event, meta) -> { filter().handler((event, meta) -> {
MetaType type = meta.metaType(); MetaType type = meta.metaType();
@ -231,6 +233,11 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
} }
} else if (type == particleType) { } else if (type == particleType) {
rewriteParticle(meta.value()); rewriteParticle(meta.value());
} else if (type == particlesType) {
Particle[] particles = meta.value();
for (final Particle particle : particles) {
rewriteParticle(particle);
}
} else if (type == optionalComponentType || type == componentType) { } else if (type == optionalComponentType || type == componentType) {
protocol.getTranslatableRewriter().processTag(meta.value()); protocol.getTranslatableRewriter().processTag(meta.value());
} }

View File

@ -116,7 +116,7 @@ public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversi
} }
if (mappedId != soundEventHolder.id()) { if (mappedId != soundEventHolder.id()) {
soundEventHolder = new Holder<>(mappedId); soundEventHolder = Holder.of(mappedId);
} }
wrapper.write(Type.SOUND_EVENT, soundEventHolder); wrapper.write(Type.SOUND_EVENT, soundEventHolder);
@ -128,7 +128,7 @@ public class SoundRewriter<C extends ClientboundPacketType> extends com.viaversi
final String mappedIdentifier = protocol.getMappingData().getMappedNamedSound(soundEvent.identifier()); final String mappedIdentifier = protocol.getMappingData().getMappedNamedSound(soundEvent.identifier());
if (mappedIdentifier != null) { if (mappedIdentifier != null) {
if (!mappedIdentifier.isEmpty()) { if (!mappedIdentifier.isEmpty()) {
return new Holder<>(soundEvent.withIdentifier(mappedIdentifier)); return Holder.of(soundEvent.withIdentifier(mappedIdentifier));
} }
wrapper.cancel(); wrapper.cancel();
} }

View File

@ -74,6 +74,8 @@ public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol<ClientboundP
@Override @Override
protected void registerPackets() { protected void registerPackets() {
// TODO Trim storage in registry sending
// TODO also for banners?
super.registerPackets(); super.registerPackets();
final TagRewriter<ClientboundPacket1_20_5> tagRewriter = new TagRewriter<>(this); final TagRewriter<ClientboundPacket1_20_5> tagRewriter = new TagRewriter<>(this);

View File

@ -166,7 +166,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
if (item == null) return null; if (item == null) return null;
// Convert to structured item first // Convert to structured item first
final Item structuredItem = vvProtocol.getItemRewriter().toStructuredItem(item, false); final Item structuredItem = vvProtocol.getItemRewriter().toStructuredItem(item);
return super.handleItemToServer(structuredItem); return super.handleItemToServer(structuredItem);
} }
} }

View File

@ -23,6 +23,7 @@ import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.RegistryDataStorage; import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.RegistryDataStorage;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.SecureChatStorage; import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.storage.SecureChatStorage;
import com.viaversion.viaversion.api.data.entity.DimensionData; import com.viaversion.viaversion.api.data.entity.DimensionData;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.RegistryEntry;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
@ -34,7 +35,9 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
import com.viaversion.viaversion.data.entity.DimensionDataImpl; import com.viaversion.viaversion.data.entity.DimensionDataImpl;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.AttributeMappings; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
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.Attributes1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundConfigurationPackets1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPacket1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPacket1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5;
@ -79,9 +82,14 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
protected void register() { protected void register() {
handler(wrapper -> { handler(wrapper -> {
final String registryKey = Key.stripMinecraftNamespace(wrapper.read(Type.STRING)); final String registryKey = Key.stripMinecraftNamespace(wrapper.read(Type.STRING));
final RegistryEntry[] entries = wrapper.read(Type.REGISTRY_ENTRY_ARRAY); // TODO Track banner pattern/material ids
if (registryKey.equals("wolf_variant") || registryKey.equals("banner_pattern") || registryKey.equals("banner_material")) {
wrapper.cancel();
return;
}
// Track data // Track data
final RegistryEntry[] entries = wrapper.read(Type.REGISTRY_ENTRY_ARRAY);
final RegistryDataStorage registryDataStorage = wrapper.user().get(RegistryDataStorage.class); final RegistryDataStorage registryDataStorage = wrapper.user().get(RegistryDataStorage.class);
if (registryKey.equals("worldgen/biome")) { if (registryKey.equals("worldgen/biome")) {
tracker(wrapper.user()).setBiomesSent(entries.length); tracker(wrapper.user()).setBiomesSent(entries.length);
@ -109,6 +117,15 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
final RegistryEntry entry = entries[i]; final RegistryEntry entry = entries[i];
Preconditions.checkNotNull(entry.tag(), "Server unexpectedly sent null registry data entry for " + entry.key()); Preconditions.checkNotNull(entry.tag(), "Server unexpectedly sent null registry data entry for " + entry.key());
if (registryKey.equals("trim_pattern")) {
final CompoundTag patternTag = (CompoundTag) entry.tag();
final StringTag templateItem = patternTag.getStringTag("template_item");
if (Protocol1_20_5To1_20_3.MAPPINGS.itemId(templateItem.getValue()) == -1) {
// Skip new items
continue;
}
}
final CompoundTag entryCompoundTag = new CompoundTag(); final CompoundTag entryCompoundTag = new CompoundTag();
entryCompoundTag.putString("name", entry.key()); entryCompoundTag.putString("name", entry.key());
entryCompoundTag.putInt("id", i); entryCompoundTag.putInt("id", i);
@ -154,6 +171,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
wrapper.user().get(SecureChatStorage.class).setEnforcesSecureChat(enforcesSecureChat); wrapper.user().get(SecureChatStorage.class).setEnforcesSecureChat(enforcesSecureChat);
}); });
handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking
handler(playerTrackerHandler());
} }
}); });
@ -183,19 +201,23 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
}); });
protocol.registerClientbound(ClientboundPackets1_20_5.ENTITY_PROPERTIES, wrapper -> { protocol.registerClientbound(ClientboundPackets1_20_5.ENTITY_PROPERTIES, wrapper -> {
wrapper.passthrough(Type.VAR_INT); // Entity ID final int entityId = wrapper.passthrough(Type.VAR_INT);
final int size = wrapper.passthrough(Type.VAR_INT); final int size = wrapper.passthrough(Type.VAR_INT);
int newSize = size; int newSize = size;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// From a registry int ID to a string // From a registry int ID to a string
int id = protocol.getMappingData().getAttributeMappings().getNewId(wrapper.read(Type.VAR_INT)); final int attributeId = wrapper.read(Type.VAR_INT);
final String attribute = AttributeMappings.attribute(id); final String attribute = Attributes1_20_5.idToKey(attributeId);
if ("horse.jump_strength".equals(attribute)) { int mappedId = protocol.getMappingData().getAttributeMappings().getNewId(attributeId);
// Jump strength only applies to horses in old versions if ("generic.jump_strength".equals(attribute)) {
id = -1; final EntityType type = tracker(wrapper.user()).entityType(entityId);
if (type == null || !type.isOrHasParent(EntityTypes1_20_5.HORSE)) {
// Jump strength only applies to horses in old versions
mappedId = -1;
}
} }
if (id == -1) { if (mappedId == -1) {
// Remove new attributes from the list // Remove new attributes from the list
newSize--; newSize--;
@ -227,25 +249,38 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().mapMetaType(typeId -> { filter().mapMetaType(typeId -> {
if (typeId == Types1_20_5.META_TYPES.particlesType.typeId()) {
return Types1_20_5.META_TYPES.particlesType;
}
int id = typeId; int id = typeId;
if (typeId >= Types1_20_5.META_TYPES.wolfVariantType.typeId()) {
id--;
}
if (typeId >= Types1_20_5.META_TYPES.armadilloState.typeId()) { if (typeId >= Types1_20_5.META_TYPES.armadilloState.typeId()) {
id--; id--;
} }
if (typeId >= Types1_20_5.META_TYPES.wolfVariantType.typeId()) { if (typeId >= Types1_20_5.META_TYPES.particlesType.typeId()) {
id--; id--;
} }
return Types1_20_3.META_TYPES.byId(id); return Types1_20_3.META_TYPES.byId(id);
}); });
registerMetaTypeHandler1_20_3( registerMetaTypeHandler1_20_3(
Types1_20_3.META_TYPES.itemType, Types1_20_3.META_TYPES.itemType,
Types1_20_3.META_TYPES.blockStateType, Types1_20_3.META_TYPES.blockStateType,
Types1_20_3.META_TYPES.optionalBlockStateType, Types1_20_3.META_TYPES.optionalBlockStateType,
Types1_20_3.META_TYPES.particleType, Types1_20_3.META_TYPES.particleType,
Types1_20_3.META_TYPES.componentType, null,
Types1_20_3.META_TYPES.optionalComponentType Types1_20_3.META_TYPES.componentType,
Types1_20_3.META_TYPES.optionalComponentType
); );
filter().type(EntityTypes1_20_5.LIVINGENTITY).index(10).handler((event, meta) -> {
final Particle[] particles = meta.value();
meta.setTypeAndValue(Types1_20_3.META_TYPES.varIntType, 0); // TODO
});
filter().type(EntityTypes1_20_5.MINECART_ABSTRACT).index(11).handler((event, meta) -> { filter().type(EntityTypes1_20_5.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
final int blockState = meta.value(); final int blockState = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
@ -256,6 +291,14 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
filter().type(EntityTypes1_20_5.WOLF).removeIndex(22); // Wolf variant filter().type(EntityTypes1_20_5.WOLF).removeIndex(22); // Wolf variant
} }
@Override
public void rewriteParticle(final Particle particle) {
super.rewriteParticle(particle);
if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) {
particle.removeArgument(0); // rgb
}
}
@Override @Override
public void onMappingDataLoaded() { public void onMappingDataLoaded() {
mapTypes(); mapTypes();

View File

@ -1,4 +1,4 @@
projectVersion=4.10.0-24w10a-SNAPSHOT projectVersion=4.10.0-24w11a-SNAPSHOT
# Smile emoji # Smile emoji
mcVersions=1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 mcVersions=1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10

View File

@ -3,7 +3,7 @@ metadata.format.version = "1.1"
[versions] [versions]
# ViaVersion # ViaVersion
viaver = "4.10.0-24w10a-SNAPSHOT" viaver = "4.10.0-24w11a-SNAPSHOT"
# Common provided # Common provided
netty = "4.0.20.Final" netty = "4.0.20.Final"

View File

@ -99,7 +99,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPa
Types1_20_5.META_TYPES.blockStateType, Types1_20_5.META_TYPES.blockStateType,
Types1_20_5.META_TYPES.optionalBlockStateType, Types1_20_5.META_TYPES.optionalBlockStateType,
Types1_20_5.META_TYPES.particleType, Types1_20_5.META_TYPES.particleType,
Types1_20_5.META_TYPES.componentType, null, Types1_20_5.META_TYPES.componentType,
Types1_20_5.META_TYPES.optionalComponentType Types1_20_5.META_TYPES.optionalComponentType
); );