mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-21 16:47:57 +01:00
Update data component ids
This commit is contained in:
parent
6f8da18f65
commit
3749a5d5da
@ -25,6 +25,7 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
|
|||||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||||
import com.viaversion.viabackwards.api.data.MappedItem;
|
import com.viaversion.viabackwards.api.data.MappedItem;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
|
import com.viaversion.viaversion.api.data.FullMappings;
|
||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||||
@ -53,12 +54,17 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
final StructuredDataContainer data = item.dataContainer();
|
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||||
data.setIdLookup(protocol, true);
|
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||||
|
if (mappingData != null && mappingData.getDataComponentSerializerMappings() != null) {
|
||||||
|
final FullMappings mappings = mappingData.getDataComponentSerializerMappings();
|
||||||
|
dataContainer.setIdLookup(protocol, true);
|
||||||
|
dataContainer.updateIds(protocol, mappings::getNewId);
|
||||||
|
}
|
||||||
|
|
||||||
if (protocol.getTranslatableRewriter() != null) {
|
if (protocol.getTranslatableRewriter() != null) {
|
||||||
// Handle name and lore components
|
// Handle name and lore components
|
||||||
final StructuredData<Tag> customNameData = data.getNonEmpty(StructuredDataKey.CUSTOM_NAME);
|
final StructuredData<Tag> customNameData = dataContainer.getNonEmpty(StructuredDataKey.CUSTOM_NAME);
|
||||||
if (customNameData != null) {
|
if (customNameData != null) {
|
||||||
final Tag originalName = customNameData.value().copy();
|
final Tag originalName = customNameData.value().copy();
|
||||||
protocol.getTranslatableRewriter().processTag(connection, customNameData.value());
|
protocol.getTranslatableRewriter().processTag(connection, customNameData.value());
|
||||||
@ -67,7 +73,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE);
|
final StructuredData<Tag[]> loreData = dataContainer.getNonEmpty(StructuredDataKey.LORE);
|
||||||
if (loreData != null) {
|
if (loreData != null) {
|
||||||
for (final Tag tag : loreData.value()) {
|
for (final Tag tag : loreData.value()) {
|
||||||
protocol.getTranslatableRewriter().processTag(connection, tag);
|
protocol.getTranslatableRewriter().processTag(connection, tag);
|
||||||
@ -75,7 +81,6 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
|
||||||
final MappedItem mappedItem = mappingData != null ? mappingData.getMappedItem(item.identifier()) : null;
|
final MappedItem mappedItem = mappingData != null ? mappingData.getMappedItem(item.identifier()) : null;
|
||||||
if (mappedItem == null) {
|
if (mappedItem == null) {
|
||||||
// Just rewrite the id
|
// Just rewrite the id
|
||||||
@ -83,7 +88,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
item.setIdentifier(mappingData.getNewItemId(item.identifier()));
|
item.setIdentifier(mappingData.getNewItemId(item.identifier()));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateItemComponents(connection, item.structuredData(), this::handleItemToClient, mappingData != null ? mappingData::getNewItemId : null);
|
updateItemComponents(connection, dataContainer, this::handleItemToClient, mappingData != null ? mappingData::getNewItemId : null);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,17 +98,17 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
item.setIdentifier(mappedItem.id());
|
item.setIdentifier(mappedItem.id());
|
||||||
|
|
||||||
// Add custom model data
|
// Add custom model data
|
||||||
if (mappedItem.customModelData() != null && !data.contains(StructuredDataKey.CUSTOM_MODEL_DATA)) {
|
if (mappedItem.customModelData() != null && !dataContainer.contains(StructuredDataKey.CUSTOM_MODEL_DATA)) {
|
||||||
data.set(StructuredDataKey.CUSTOM_MODEL_DATA, mappedItem.customModelData());
|
dataContainer.set(StructuredDataKey.CUSTOM_MODEL_DATA, mappedItem.customModelData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set custom name - only done if there is no original one
|
// Set custom name - only done if there is no original one
|
||||||
if (!data.contains(StructuredDataKey.CUSTOM_NAME)) {
|
if (!dataContainer.contains(StructuredDataKey.CUSTOM_NAME)) {
|
||||||
data.set(StructuredDataKey.CUSTOM_NAME, mappedItem.tagName());
|
dataContainer.set(StructuredDataKey.CUSTOM_NAME, mappedItem.tagName());
|
||||||
tag.putBoolean(nbtTagName("customName"), true);
|
tag.putBoolean(nbtTagName("customName"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateItemComponents(connection, item.structuredData(), this::handleItemToClient, mappingData::getNewItemId);
|
updateItemComponents(connection, dataContainer, this::handleItemToClient, mappingData::getNewItemId);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,12 +119,19 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
}
|
}
|
||||||
|
|
||||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||||
if (mappingData != null && mappingData.getItemMappings() != null) {
|
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||||
|
if (mappingData != null) {
|
||||||
|
if (mappingData.getItemMappings() != null) {
|
||||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||||
}
|
}
|
||||||
|
|
||||||
final StructuredDataContainer data = item.dataContainer();
|
final FullMappings dataComponentMappings = mappingData.getDataComponentSerializerMappings();
|
||||||
data.setIdLookup(protocol, false);
|
if (dataComponentMappings != null) {
|
||||||
|
dataContainer.setIdLookup(protocol, false);
|
||||||
|
dataContainer.updateIds(protocol, id -> dataComponentMappings.inverse().getNewId(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
final CompoundTag tag = customTag(item);
|
final CompoundTag tag = customTag(item);
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
@ -130,7 +142,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
|||||||
}
|
}
|
||||||
|
|
||||||
restoreDisplayTag(item);
|
restoreDisplayTag(item);
|
||||||
updateItemComponents(connection, item.structuredData(), this::handleItemToServer, mappingData != null ? mappingData::getOldItemId : null);
|
updateItemComponents(connection, dataContainer, this::handleItemToServer, mappingData != null ? mappingData::getOldItemId : null);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ metadata.format.version = "1.1"
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
# ViaVersion
|
# ViaVersion
|
||||||
viaver = "5.0.0-24w21a-SNAPSHOT"
|
viaver = "5.0.0-24w21b-SNAPSHOT"
|
||||||
|
|
||||||
# Common provided
|
# Common provided
|
||||||
netty = "4.0.20.Final"
|
netty = "4.0.20.Final"
|
||||||
|
Loading…
Reference in New Issue
Block a user