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:
Ursprung
a5d0e4baff
Commit
830ccce303
@ -26,7 +26,6 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.data.MappedItem;
|
||||
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.data.StructuredData;
|
||||
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.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntFunction;
|
||||
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -68,33 +66,9 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
updateItemDataComponentTypeIds(dataContainer, 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.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;
|
||||
if (mappedItem == null) {
|
||||
// Just rewrite the id
|
||||
@ -102,7 +76,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
item.setIdentifier(mappingData.getNewItemId(item.identifier()));
|
||||
}
|
||||
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToClient, itemIdRewriter, blockIdRewriter);
|
||||
updateItemDataComponents(connection, item, true);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -122,7 +96,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
tag.putBoolean(nbtTagName("added_custom_name"), true);
|
||||
}
|
||||
|
||||
updateItemComponents(connection, dataContainer, this::handleItemToClient, itemIdRewriter, blockIdRewriter);
|
||||
updateItemDataComponents(connection, item, true);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -132,21 +106,14 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
return item;
|
||||
}
|
||||
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
final StructuredDataContainer dataContainer = item.dataContainer();
|
||||
if (mappingData != null) {
|
||||
if (mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||
}
|
||||
updateItemDataComponentTypeIds(dataContainer, false);
|
||||
|
||||
final FullMappings dataComponentMappings = mappingData.getDataComponentSerializerMappings();
|
||||
if (dataComponentMappings != null) {
|
||||
dataContainer.setIdLookup(protocol, false);
|
||||
dataContainer.updateIds(protocol, id -> dataComponentMappings.inverse().getNewId(id));
|
||||
}
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
if (mappingData != null && mappingData.getItemMappings() != null) {
|
||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||
}
|
||||
|
||||
|
||||
final CompoundTag tag = customTag(item);
|
||||
if (tag != null) {
|
||||
final Tag originalId = tag.remove(nbtTagName("id"));
|
||||
@ -156,14 +123,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
restoreTextComponents(item);
|
||||
|
||||
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);
|
||||
updateItemDataComponents(connection, item, false);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -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.version.Types1_20_3;
|
||||
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.ServerboundPackets1_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;
|
||||
}
|
||||
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
item.dataContainer().setIdLookup(protocol, true);
|
||||
enchantmentRewriter.handleToClient(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
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
if (item.identifier() == 1105 && !data.contains(StructuredDataKey.FIREWORKS)) {
|
||||
data.set(StructuredDataKey.FIREWORKS, new Fireworks(1, new FireworkExplosion[0]));
|
||||
}
|
||||
@ -383,7 +392,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren