3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 16:12:43 +01:00

Update VV usage

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-08-30 19:45:02 +02:00
Ursprung a5d0e4baff
Commit 830ccce303
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
2 geänderte Dateien mit 21 neuen und 52 gelöschten Zeilen

Datei anzeigen

@ -26,7 +26,6 @@ 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.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
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;
@ -35,7 +34,6 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntFunction;
import com.viaversion.viaversion.rewriter.StructuredItemRewriter; import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -68,33 +66,9 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
} }
final StructuredDataContainer dataContainer = item.dataContainer(); final StructuredDataContainer dataContainer = item.dataContainer();
updateItemDataComponentTypeIds(dataContainer, true);
final BackwardsMappingData mappingData = protocol.getMappingData(); 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.getComponentRewriter() != null) {
// Handle name and lore components
updateComponent(connection, item, StructuredDataKey.ITEM_NAME, "item_name");
updateComponent(connection, item, StructuredDataKey.CUSTOM_NAME, "custom_name");
final StructuredData<Tag[]> loreData = dataContainer.getNonEmpty(StructuredDataKey.LORE);
if (loreData != null) {
for (final Tag tag : loreData.value()) {
protocol.getComponentRewriter().processTag(connection, tag);
}
}
}
Int2IntFunction itemIdRewriter = null;
Int2IntFunction blockIdRewriter = null;
if (mappingData != null) {
itemIdRewriter = mappingData.getItemMappings() != null ? mappingData::getNewItemId : null;
blockIdRewriter = mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null;
}
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
@ -102,7 +76,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
item.setIdentifier(mappingData.getNewItemId(item.identifier())); item.setIdentifier(mappingData.getNewItemId(item.identifier()));
} }
updateItemComponents(connection, dataContainer, this::handleItemToClient, itemIdRewriter, blockIdRewriter); updateItemDataComponents(connection, item, true);
return item; return item;
} }
@ -122,7 +96,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
tag.putBoolean(nbtTagName("added_custom_name"), true); tag.putBoolean(nbtTagName("added_custom_name"), true);
} }
updateItemComponents(connection, dataContainer, this::handleItemToClient, itemIdRewriter, blockIdRewriter); updateItemDataComponents(connection, item, true);
return item; return item;
} }
@ -132,21 +106,14 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
return item; return item;
} }
final BackwardsMappingData mappingData = protocol.getMappingData();
final StructuredDataContainer dataContainer = item.dataContainer(); final StructuredDataContainer dataContainer = item.dataContainer();
if (mappingData != null) { updateItemDataComponentTypeIds(dataContainer, false);
if (mappingData.getItemMappings() != null) {
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
}
final FullMappings dataComponentMappings = mappingData.getDataComponentSerializerMappings(); final BackwardsMappingData mappingData = protocol.getMappingData();
if (dataComponentMappings != null) { if (mappingData != null && mappingData.getItemMappings() != null) {
dataContainer.setIdLookup(protocol, false); item.setIdentifier(mappingData.getOldItemId(item.identifier()));
dataContainer.updateIds(protocol, id -> dataComponentMappings.inverse().getNewId(id));
}
} }
final CompoundTag tag = customTag(item); final CompoundTag tag = customTag(item);
if (tag != null) { if (tag != null) {
final Tag originalId = tag.remove(nbtTagName("id")); final Tag originalId = tag.remove(nbtTagName("id"));
@ -156,14 +123,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
} }
restoreTextComponents(item); restoreTextComponents(item);
updateItemDataComponents(connection, item, false);
Int2IntFunction itemIdRewriter = null;
Int2IntFunction blockIdRewriter = null;
if (mappingData != null) {
itemIdRewriter = mappingData.getItemMappings() != null ? mappingData::getOldItemId : null;
blockIdRewriter = mappingData.getBlockMappings() != null ? mappingData::getOldBlockId : null;
}
updateItemComponents(connection, dataContainer, this::handleItemToServer, itemIdRewriter, blockIdRewriter);
return item; return item;
} }

Datei anzeigen

@ -41,7 +41,6 @@ import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
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.libs.fastutil.ints.Int2IntFunction;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPacket1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPacket1_20_3;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPackets1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ServerboundPackets1_20_3;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3;
@ -355,13 +354,23 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
return null; return null;
} }
final StructuredDataContainer data = item.dataContainer();
item.dataContainer().setIdLookup(protocol, true); item.dataContainer().setIdLookup(protocol, true);
enchantmentRewriter.handleToClient(item); enchantmentRewriter.handleToClient(item);
super.handleItemToClient(connection, item); super.handleItemToClient(connection, item);
// Text components since we skip the usual rewrite method
updateComponent(connection, item, StructuredDataKey.ITEM_NAME, "item_name");
updateComponent(connection, item, StructuredDataKey.CUSTOM_NAME, "custom_name");
final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE);
if (loreData != null) {
for (final Tag tag : loreData.value()) {
protocol.getComponentRewriter().processTag(connection, tag);
}
}
// In 1.20.6, some items have default values which are not written into the components // In 1.20.6, some items have default values which are not written into the components
final StructuredDataContainer data = item.dataContainer();
if (item.identifier() == 1105 && !data.contains(StructuredDataKey.FIREWORKS)) { if (item.identifier() == 1105 && !data.contains(StructuredDataKey.FIREWORKS)) {
data.set(StructuredDataKey.FIREWORKS, new Fireworks(1, new FireworkExplosion[0])); data.set(StructuredDataKey.FIREWORKS, new Fireworks(1, new FireworkExplosion[0]));
} }
@ -383,7 +392,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
} }
@Override @Override
protected void updateItemComponents(final UserConnection connection, final StructuredDataContainer container, final ItemHandler itemHandler, @Nullable final Int2IntFunction idRewriter, @Nullable final Int2IntFunction blockIdRewriter) { protected void updateItemDataComponents(final UserConnection connection, final Item item, final boolean clientbound) {
// Items and data within components are handled in this protocol // Items and data within components are handled in this protocol
} }