Prepare proper banner id tracking, small other fixes

This commit is contained in:
Nassim Jahnke 2024-04-09 12:37:36 +02:00
parent 7932b79080
commit 99f29e2597
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
5 changed files with 61 additions and 7 deletions

View File

@ -60,4 +60,11 @@ public final class ReceivedMessagesStorage implements StorableObject {
public void resetUnacknowledgedCount() { public void resetUnacknowledgedCount() {
unacknowledged = 0; unacknowledged = 0;
} }
public void clear() {
this.size = 0;
this.unacknowledged = 0;
this.lastSignature = null;
Arrays.fill(this.signatures, null);
}
} }

View File

@ -32,6 +32,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_20_3; import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.storage.ReceivedMessagesStorage;
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.ClientboundPacket1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPacket1_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;
@ -167,6 +168,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
final String dimensionKey = wrapper.read(Type.STRING); final String dimensionKey = wrapper.read(Type.STRING);
final DimensionData data = tracker(wrapper.user()).dimensionData(dimensionKey); final DimensionData data = tracker(wrapper.user()).dimensionData(dimensionKey);
wrapper.write(Type.VAR_INT, data.id()); wrapper.write(Type.VAR_INT, data.id());
wrapper.user().get(ReceivedMessagesStorage.class).clear();
}); });
map(Type.STRING); // World map(Type.STRING); // World
map(Type.LONG); // Seed map(Type.LONG); // Seed

View File

@ -412,11 +412,11 @@ public final class StructuredDataConverter {
tag.put("effects", effectsTag); tag.put("effects", effectsTag);
}); });
register(StructuredDataKey.BANNER_PATTERNS, (data, tag) -> { register(StructuredDataKey.BANNER_PATTERNS, (data, tag) -> {
final ListTag<CompoundTag> originalPatterns = new ListTag<>(CompoundTag.class);
if (backupInconvertibleData) { if (backupInconvertibleData) {
// Backup whole data if one of the entries is inconvertible // Backup whole data if one of the entries is inconvertible
// Since we don't want to break the order of the entries // Since we don't want to break the order of the entries
if (Arrays.stream(data).anyMatch(layer -> layer.pattern().isDirect())) { if (Arrays.stream(data).anyMatch(layer -> layer.pattern().isDirect() || BannerPatterns1_20_5.idToKey(layer.pattern().id()) == null)) {
final ListTag<CompoundTag> originalPatterns = new ListTag<>(CompoundTag.class);
for (final BannerPatternLayer layer : data) { for (final BannerPatternLayer layer : data) {
final CompoundTag layerTag = new CompoundTag(); final CompoundTag layerTag = new CompoundTag();
final CompoundTag patternTag = new CompoundTag(); final CompoundTag patternTag = new CompoundTag();
@ -428,18 +428,23 @@ public final class StructuredDataConverter {
originalPatterns.add(layerTag); originalPatterns.add(layerTag);
} }
getBackupTag(tag).put("banner_patterns", originalPatterns); getBackupTag(tag).put("banner_patterns", originalPatterns);
return;
} }
} }
final ListTag<CompoundTag> patternsTag = new ListTag<>(CompoundTag.class); final ListTag<CompoundTag> patternsTag = new ListTag<>(CompoundTag.class);
for (final BannerPatternLayer layer : data) { for (final BannerPatternLayer layer : data) {
final String pattern = BannerPatterns1_20_5.fullIdToCompact(BannerPatterns1_20_5.idToKey(layer.pattern().id())); if (layer.pattern().isDirect()) {
if (pattern == null) {
continue; continue;
} }
final String key = BannerPatterns1_20_5.idToKey(layer.pattern().id());
if (key == null) {
continue;
}
final String compactKey = BannerPatterns1_20_5.fullIdToCompact(key);
final CompoundTag patternTag = new CompoundTag(); final CompoundTag patternTag = new CompoundTag();
patternTag.putString("Pattern", pattern); patternTag.putString("Pattern", compactKey);
patternTag.putInt("Color", layer.dyeColor()); patternTag.putInt("Color", layer.dyeColor());
patternsTag.add(patternTag); patternsTag.add(patternTag);
} }

View File

@ -0,0 +1,33 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
//TODO Item rewriting doesn't have user connection context yet. That's a fairly disruptive change, so it'll be done later
// Replace BannerPatterns1_20_5.idToKey
public final class BannerPatternStorage implements StorableObject {
private final Int2ObjectMap<String> bannerPatterns = new Int2ObjectOpenHashMap<>();
public Int2ObjectMap<String> bannerPatterns() {
return bannerPatterns;
}
}

View File

@ -536,7 +536,13 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue())); data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue()));
} else if (mappings.isItemParticle(id)) { } else if (mappings.isItemParticle(id)) {
Particle.ParticleData<Item> data = particle.getArgument(0); Particle.ParticleData<Item> data = particle.getArgument(0);
data.setValue(handleItemToClient(data.getValue())); Item item = handleItemToClient(data.getValue());
if (mappedItemType() != null && itemType() != mappedItemType()) {
// Replace the type
particle.set(0, mappedItemType(), item);
} else {
data.setValue(item);
}
} }
particle.setId(protocol.getMappingData().getNewParticleId(id)); particle.setId(protocol.getMappingData().getNewParticleId(id));