Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Update data component ids
Dieser Commit ist enthalten in:
Ursprung
134c3559bf
Commit
251ab42c14
@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.FullMappings;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.util.Unit;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@ -160,6 +161,18 @@ public final class StructuredDataContainer {
|
||||
this.mappedNames = mappedNames;
|
||||
}
|
||||
|
||||
public void updateIds(final Protocol<?, ?, ?, ?> protocol, final Int2IntFunction rewriter) {
|
||||
for (final StructuredData<?> data : data.values()) {
|
||||
final int mappedId = rewriter.applyAsInt(data.id());
|
||||
if (mappedId == -1) {
|
||||
protocol.getLogger().warning("Could not find item data serializer for id " + data.id());
|
||||
continue;
|
||||
}
|
||||
|
||||
data.setId(mappedId);
|
||||
}
|
||||
}
|
||||
|
||||
public StructuredDataContainer copy() {
|
||||
final StructuredDataContainer copy = new StructuredDataContainer(new Reference2ObjectOpenHashMap<>(data));
|
||||
copy.lookup = this.lookup;
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.viaversion.viaversion.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.FullMappings;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
@ -50,16 +51,20 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
}
|
||||
|
||||
final MappingData mappingData = protocol.getMappingData();
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
if (mappingData != null) {
|
||||
if (mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getNewItemId(item.identifier()));
|
||||
}
|
||||
if (mappingData.getDataComponentSerializerMappings() != null) {
|
||||
item.dataContainer().setIdLookup(protocol, true);
|
||||
|
||||
final FullMappings dataComponentMappings = mappingData.getDataComponentSerializerMappings();
|
||||
if (dataComponentMappings != null) {
|
||||
dataContainer.setIdLookup(protocol, true);
|
||||
dataContainer.updateIds(protocol, dataComponentMappings::getNewId);
|
||||
}
|
||||
}
|
||||
|
||||
updateItemComponents(connection, item.dataContainer(), this::handleItemToClient, mappingData != null ? mappingData::getNewItemId : null);
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToClient, mappingData != null ? mappingData::getNewItemId : null);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -70,16 +75,20 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
}
|
||||
|
||||
final MappingData mappingData = protocol.getMappingData();
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
if (mappingData != null) {
|
||||
if (mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||
}
|
||||
if (mappingData.getDataComponentSerializerMappings() != null) {
|
||||
item.dataContainer().setIdLookup(protocol, false);
|
||||
|
||||
final FullMappings dataComponentMappings = mappingData.getDataComponentSerializerMappings();
|
||||
if (dataComponentMappings != null) {
|
||||
dataContainer.setIdLookup(protocol, false);
|
||||
dataContainer.updateIds(protocol, id -> dataComponentMappings.inverse().getNewId(id));
|
||||
}
|
||||
}
|
||||
|
||||
updateItemComponents(connection, item.dataContainer(), this::handleItemToServer, mappingData != null ? mappingData::getOldItemId : null);
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToServer, mappingData != null ? mappingData::getOldItemId : null);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren