From 47b1508f66c8488b19dd342c7e51a8ce83008428 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Wed, 28 Aug 2024 15:55:40 +0200 Subject: [PATCH 01/70] Clean up LOGIN/STATUS/CONFIGURATION handlers (#876) --- .../protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java | 4 ++-- .../protocol/v1_19_1to1_19/Protocol1_19_1To1_19.java | 8 ++++---- .../protocol/v1_19_3to1_19_1/Protocol1_19_3To1_19_1.java | 6 +++--- .../protocol/v1_19to1_18_2/Protocol1_19To1_18_2.java | 8 ++++---- .../protocol/v1_20_2to1_20/Protocol1_20_2To1_20.java | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java index 348c60c3..c90c5b88 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java @@ -73,7 +73,7 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol { + registerClientbound(State.STATUS, ClientboundStatusPackets.STATUS_RESPONSE, wrapper -> { String original = wrapper.passthrough(Types.STRING); JsonObject object = GsonUtil.getGson().fromJson(original, JsonObject.class); JsonElement description = object.get("description"); @@ -116,7 +116,7 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol { + registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, wrapper -> { // Transform uuid to plain string UUID uuid = wrapper.read(Types.UUID); wrapper.write(Types.STRING, uuid.toString()); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_1to1_19/Protocol1_19_1To1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_1to1_19/Protocol1_19_1To1_19.java index 89a89324..b5f5bfd6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_1to1_19/Protocol1_19_1To1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_1to1_19/Protocol1_19_1To1_19.java @@ -297,7 +297,7 @@ public final class Protocol1_19_1To1_19 extends BackwardsProtocol { + registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, wrapper -> { // We can't set the internal state to configuration here as protocols down the line will expect the state to be play // Add this *before* sending the ack since the server might immediately answer wrapper.user().put(new ConfigurationPacketStorage()); @@ -88,7 +88,7 @@ public final class Protocol1_20_2To1_20 extends BackwardsProtocol { + registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.FINISH_CONFIGURATION, wrapper -> { wrapper.cancel(); wrapper.user().getProtocolInfo().setServerState(State.PLAY); wrapper.user().get(ConfigurationPacketStorage.class).setFinished(true); @@ -97,7 +97,7 @@ public final class Protocol1_20_2To1_20 extends BackwardsProtocol { + registerServerbound(State.LOGIN, ServerboundLoginPackets.HELLO, wrapper -> { wrapper.passthrough(Types.STRING); // Name // TODO Bad From db470405430a763cf666db18775836c5b1da8280 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 29 Aug 2024 19:18:43 +0200 Subject: [PATCH 02/70] Fix 1.21->1.20.5 enchantment lore format and add show_in_tooltip check Fixes #877 --- .../rewriters/StructuredEnchantmentRewriter.java | 14 ++++++++------ .../rewriter/BlockItemPacketRewriter1_21.java | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java index 900cfb2d..9a53020e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java @@ -84,7 +84,8 @@ public class StructuredEnchantmentRewriter { final Enchantments enchantments = enchantmentsData.value(); final List loreToAdd = new ArrayList<>(); - boolean changed = false; + boolean updatedLore = false; + boolean removedEnchantments = false; final ObjectIterator iterator = enchantments.enchantments().int2IntEntrySet().iterator(); final List updatedIds = new ArrayList<>(); @@ -101,13 +102,15 @@ public class StructuredEnchantmentRewriter { continue; } + removedEnchantments = true; + final Tag description = descriptionSupplier.get(id, level); - if (description != null) { - if (!changed) { + if (description != null && enchantments.showInTooltip()) { + if (!updatedLore) { // Backup original before doing modifications final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier()); - changed = true; + updatedLore = true; } loreToAdd.add(description); @@ -123,8 +126,7 @@ public class StructuredEnchantmentRewriter { enchantments.add(change.mappedId(), change.level()); } - if (loreToAdd.isEmpty()) { - // No removed enchantments + if (!removedEnchantments) { return; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java index 933fb0be..f86bceef 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java @@ -38,6 +38,7 @@ import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap; +import com.viaversion.viaversion.libs.mcstructs.core.TextFormatting; import com.viaversion.viaversion.libs.mcstructs.text.components.StringComponent; import com.viaversion.viaversion.libs.mcstructs.text.components.TranslationComponent; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; @@ -177,6 +178,8 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe } final var component = SerializerVersion.V1_20_5.toComponent(description); + component.getStyle().setItalic(false); + component.getStyle().setFormatting(TextFormatting.GRAY); component.getSiblings().add(new StringComponent(" ")); component.getSiblings().add(new TranslationComponent(EnchantmentRewriter.ENCHANTMENT_LEVEL_TRANSLATION.formatted(level))); From 678775ab9d3d63c30dcf8780e084d4b07a6499c4 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 29 Aug 2024 19:45:43 +0200 Subject: [PATCH 03/70] Move the iterator remove down --- .../api/rewriters/StructuredEnchantmentRewriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java index 9a53020e..54ca14db 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java @@ -114,8 +114,8 @@ public class StructuredEnchantmentRewriter { } loreToAdd.add(description); - iterator.remove(); } + iterator.remove(); } // Remove all first, then add the new ones From 4066b9b52b57cfb46b079d0e4a635eb9a6b78d99 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 29 Aug 2024 19:53:47 +0200 Subject: [PATCH 04/70] More cleanup to structured enchantment rewriter --- .../StructuredEnchantmentRewriter.java | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java index 54ca14db..9ac5d311 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java @@ -84,8 +84,8 @@ public class StructuredEnchantmentRewriter { final Enchantments enchantments = enchantmentsData.value(); final List loreToAdd = new ArrayList<>(); - boolean updatedLore = false; boolean removedEnchantments = false; + boolean updatedLore = false; final ObjectIterator iterator = enchantments.enchantments().int2IntEntrySet().iterator(); final List updatedIds = new ArrayList<>(); @@ -102,19 +102,19 @@ public class StructuredEnchantmentRewriter { continue; } - removedEnchantments = true; + if (!removedEnchantments) { + // Backup original before doing modifications + final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); + itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier()); + removedEnchantments = true; + } final Tag description = descriptionSupplier.get(id, level); if (description != null && enchantments.showInTooltip()) { - if (!updatedLore) { - // Backup original before doing modifications - final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); - itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier()); - updatedLore = true; - } - loreToAdd.add(description); + updatedLore = true; } + iterator.remove(); } @@ -126,37 +126,37 @@ public class StructuredEnchantmentRewriter { enchantments.add(change.mappedId(), change.level()); } - if (!removedEnchantments) { - return; - } - - // Add glint override if there are no enchantments left - final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); - if (!storedEnchant && enchantments.size() == 0) { - final StructuredData glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE); - if (glintOverride != null) { - tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value()); - } else { - tag.putBoolean(itemRewriter.nbtTagName("noglint"), true); + if (removedEnchantments) { + final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); + if (!storedEnchant && enchantments.size() == 0) { + // Add glint override if there are no enchantments left + final StructuredData glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE); + if (glintOverride != null) { + tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value()); + } else { + tag.putBoolean(itemRewriter.nbtTagName("noglint"), true); + } + data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true); + } + + if (enchantments.showInTooltip()) { + tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true); } - data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true); } - // Save original lore - final StructuredData loreData = data.getNonEmpty(StructuredDataKey.LORE); - if (loreData != null) { - final List loreList = Arrays.asList(loreData.value()); - itemRewriter.saveGenericTagList(tag, loreList, "lore"); - loreToAdd.addAll(loreList); - } else { - tag.putBoolean(itemRewriter.nbtTagName("nolore"), true); + if (updatedLore) { + // Save original lore + final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); + final StructuredData loreData = data.getNonEmpty(StructuredDataKey.LORE); + if (loreData != null) { + final List loreList = Arrays.asList(loreData.value()); + itemRewriter.saveGenericTagList(tag, loreList, "lore"); + loreToAdd.addAll(loreList); + } else { + tag.putBoolean(itemRewriter.nbtTagName("nolore"), true); + } + data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0])); } - - if (enchantments.showInTooltip()) { - tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true); - } - - data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0])); } private ListTag asTag(final Enchantments enchantments) { From a5d0e4baff02aad696cd5ee724d3d042263df073 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 30 Aug 2024 11:05:07 +0200 Subject: [PATCH 05/70] Strip new attributes in 1.21->1.20.5 item hover events --- .../rewriter/ComponentRewriter1_21.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/ComponentRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/ComponentRewriter1_21.java index e08c1338..834c463e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/ComponentRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/ComponentRewriter1_21.java @@ -23,9 +23,11 @@ import com.viaversion.nbt.tag.ListTag; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Attributes1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.AttributeModifierMappings1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.SerializerVersion; import com.viaversion.viaversion.util.TagUtil; import com.viaversion.viaversion.util.UUIDUtil; @@ -43,7 +45,17 @@ public final class ComponentRewriter1_21 extends TranslatableRewriter modifiers = attributeModifiers.getListTag("modifiers", CompoundTag.class); - for (final CompoundTag modifier : modifiers) { + int size = modifiers.size(); + for (int i = 0; i < size; i++) { + final CompoundTag modifier = modifiers.get(i); + final String type = Key.stripMinecraftNamespace(modifier.getString("type")); + if (Attributes1_20_5.keyToId(type) == -1) { + // Ignore new attributes + modifiers.remove(i--); + size--; + continue; + } + final String id = modifier.getString("id"); final UUID uuid = Protocol1_20_5To1_21.mapAttributeId(id); final String name = AttributeModifierMappings1_21.idToName(id); From 830ccce30304897d3ded2cfe88e0d9b85c6db49f Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 30 Aug 2024 19:45:02 +0200 Subject: [PATCH 06/70] Update VV usage --- .../BackwardsStructuredItemRewriter.java | 58 +++---------------- .../BlockItemPacketRewriter1_20_5.java | 15 ++++- 2 files changed, 21 insertions(+), 52 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java index 20548761..eb30e308 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java @@ -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 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 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 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 } From ffb98523e6a41a6f69362c898b332c635d988095 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Fri, 30 Aug 2024 21:05:03 +0200 Subject: [PATCH 07/70] Don't process component twice in 1.19.4->1.19.3 text display handler (#878) --- .../v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java index eb985ca7..9c787e61 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java @@ -167,9 +167,6 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter { // TODO Maybe spawn an extra entity to ride the armor stand for blocks and items From 0bac9201ac9139228e13f6147a1259d7d9383b45 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 8 Sep 2024 10:48:10 +0200 Subject: [PATCH 08/70] Don't remove configuration packet storage on login Needed with proxies if a server is doing nonstandard optimizations Fixes #881 --- .../rewriter/EntityPacketRewriter1_20_2.java | 2 +- .../storage/ConfigurationPacketStorage.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java index d4445f65..15efccdd 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java @@ -108,7 +108,7 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter { - final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().remove(ConfigurationPacketStorage.class); + final ConfigurationPacketStorage configurationPacketStorage = wrapper.user().get(ConfigurationPacketStorage.class); wrapper.passthrough(Types.INT); // Entity id wrapper.passthrough(Types.BOOLEAN); // Hardcore diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/storage/ConfigurationPacketStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/storage/ConfigurationPacketStorage.java index a3952ac4..41cde0cf 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/storage/ConfigurationPacketStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/storage/ConfigurationPacketStorage.java @@ -18,13 +18,13 @@ package com.viaversion.viabackwards.protocol.v1_20_2to1_20.storage; import com.google.common.base.Preconditions; +import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20; import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.packet.PacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4; -import com.viaversion.nbt.tag.CompoundTag; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.ArrayList; @@ -77,17 +77,21 @@ public final class ConfigurationPacketStorage implements StorableObject { public void sendQueuedPackets(final UserConnection connection) { // Send resource pack at the end + List packets = rawPackets; if (resourcePack != null) { - rawPackets.add(resourcePack); + packets = new ArrayList<>(rawPackets); + packets.add(resourcePack); resourcePack = null; } - for (final QueuedPacket queuedPacket : rawPackets) { + for (final QueuedPacket queuedPacket : packets) { + // Don't clear the list or use the original buffer, we might need them later if a server skips subsequent config phases + final ByteBuf buf = queuedPacket.buf().copy(); try { - final PacketWrapper packet = PacketWrapper.create(queuedPacket.packetType(), queuedPacket.buf(), connection); + final PacketWrapper packet = PacketWrapper.create(queuedPacket.packetType(), buf, connection); packet.send(Protocol1_20_2To1_20.class); } finally { - queuedPacket.buf().release(); + buf.release(); } } } From 66a174857347083332e4e73c00ac85b29d1285d8 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Thu, 12 Sep 2024 14:45:44 +0200 Subject: [PATCH 09/70] Remove transaction tracking (and cancelling) in 1.17->1.16.4 (#883) --- .../v1_17to1_16_4/Protocol1_17To1_16_4.java | 4 --- .../rewriter/BlockItemPacketRewriter1_17.java | 3 +- .../v1_17to1_16_4/storage/PingRequests.java | 34 ------------------- 3 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/storage/PingRequests.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/Protocol1_17To1_16_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/Protocol1_17To1_16_4.java index ba89d074..ade147b5 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/Protocol1_17To1_16_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/Protocol1_17To1_16_4.java @@ -24,7 +24,6 @@ import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.v1_17to1_16_4.rewriter.BlockItemPacketRewriter1_17; import com.viaversion.viabackwards.protocol.v1_17to1_16_4.rewriter.EntityPacketRewriter1_17; -import com.viaversion.viabackwards.protocol.v1_17to1_16_4.storage.PingRequests; import com.viaversion.viabackwards.protocol.v1_17to1_16_4.storage.PlayerLastCursorItem; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.RegistryType; @@ -170,8 +169,6 @@ public final class Protocol1_17To1_16_4 extends BackwardsProtocol. - */ -package com.viaversion.viabackwards.protocol.v1_17to1_16_4.storage; - -import com.viaversion.viaversion.api.connection.StorableObject; -import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet; -import com.viaversion.viaversion.libs.fastutil.ints.IntSet; - -public final class PingRequests implements StorableObject { - private final IntSet ids = new IntOpenHashSet(); - - public void addId(short id) { - ids.add(id); - } - - public boolean removeId(short id) { - return ids.remove(id); - } -} From 733bd9aa9b437538b50861a0002fb63269c6b720 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:51:23 +0200 Subject: [PATCH 10/70] Update Gradle Wrapper from 8.10 to 8.10.1 (#885) Signed-off-by: gradle-update-robot Co-authored-by: gradle-update-robot --- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2b189974..8e876e1c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=5b9c5eb3f9fc2c94abaea57d90bd78747ca117ddbbf96c859d3741181a12bf2a -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 36baf6ed24fd4141083f2b87a2f0f2699fce5db3 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sun, 15 Sep 2024 19:17:45 +0200 Subject: [PATCH 11/70] Fix body set equipment in 1.20.5->.3 if value is not the last (#886) --- .../rewriter/BlockItemPacketRewriter1_20_2.java | 1 - .../rewriter/EntityPacketRewriter1_20_5.java | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java index f2baf774..392cb6cb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java @@ -26,7 +26,6 @@ import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20; import com.viaversion.viabackwards.protocol.v1_20_2to1_20.provider.AdvancementCriteriaProvider; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.minecraft.ChunkPosition; import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index 4104f7c8..ac9c8b7e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -77,9 +77,12 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { From b376b52ce884f4fe0c62ae9a3e8f5bf5ca3cfbcd Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sun, 15 Sep 2024 22:09:03 +0200 Subject: [PATCH 12/70] Refactor dimension switch handling across all protocols (#884) --- .../api/rewriters/EntityRewriter.java | 1 - .../api/rewriters/EntityRewriterBase.java | 21 +++++++++++++++---- .../api/rewriters/LegacyEntityRewriter.java | 10 +++++---- .../v1_10to1_9_3/Protocol1_10To1_9_3.java | 5 +---- .../rewriter/BlockItemPacketRewriter1_10.java | 2 +- .../v1_11_1to1_11/Protocol1_11_1To1_11.java | 5 +---- .../v1_11to1_10/Protocol1_11To1_10.java | 5 +---- .../rewriter/BlockItemPacketRewriter1_11.java | 2 +- .../v1_12to1_11_1/Protocol1_12To1_11_1.java | 5 +---- .../rewriter/BlockItemPacketRewriter1_12.java | 2 +- .../rewriter/EntityPacketRewriter1_12.java | 3 +-- .../v1_13_1to1_13/Protocol1_13_1To1_13.java | 5 +---- .../rewriter/WorldPacketRewriter1_13_1.java | 2 +- .../v1_13to1_12_2/Protocol1_13To1_12_2.java | 5 +---- .../rewriter/BlockItemPacketRewriter1_13.java | 2 +- .../rewriter/EntityPacketRewriter1_13.java | 14 +++++++++---- .../v1_14to1_13_2/Protocol1_14To1_13_2.java | 5 +---- .../rewriter/BlockItemPacketRewriter1_14.java | 2 +- .../rewriter/EntityPacketRewriter1_14.java | 12 ++++++----- .../v1_15to1_14_4/Protocol1_15To1_14_4.java | 5 ++++- .../rewriter/EntityPacketRewriter1_15.java | 5 +++-- .../rewriter/EntityPacketRewriter1_16_2.java | 4 +++- .../v1_16to1_15_2/Protocol1_16To1_15_2.java | 6 ++---- .../rewriter/EntityPacketRewriter1_16.java | 11 +++++----- .../rewriter/EntityPacketRewriter1_17.java | 2 +- .../v1_9_3to1_9_1/Protocol1_9_3To1_9_1.java | 12 +++++------ 26 files changed, 78 insertions(+), 75 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java index c29b69de..242f4c67 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java @@ -127,7 +127,6 @@ public abstract class EntityRewriter intType) { - return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(intType, 0), entityType); + protected PacketHandler getTrackerHandler(EntityType entityType) { + return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(Types.VAR_INT, 0), entityType); + } + + protected PacketHandler getPlayerTrackerHandler() { + return wrapper -> { + final int entityId = wrapper.get(Types.INT, 0); + + final EntityTracker tracker = tracker(wrapper.user()); + tracker(wrapper.user()).setClientEntityId(entityId); + tracker.addEntity(entityId, tracker.playerType()); + }; } protected PacketHandler getDimensionHandler(int index) { return wrapper -> { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(this.protocol.getClass()); int dimensionId = wrapper.get(Types.INT, index); - clientWorld.setEnvironment(dimensionId); + if (clientWorld.setEnvironment(dimensionId)) { + tracker(wrapper.user()).clearEntities(); + } }; } } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java index 8728902e..08404a2f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java @@ -66,8 +66,10 @@ public abstract class LegacyEntityRewriter { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - clientWorld.setEnvironment(wrapper.get(Types.INT, 0)); + ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass()); + if (clientWorld.setEnvironment(wrapper.get(Types.INT, 0))) { + tracker(wrapper.user()).clearEntities(); + } }); } }); @@ -81,8 +83,8 @@ public abstract class LegacyEntityRewriter { - ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); - clientChunks.setEnvironment(wrapper.get(Types.INT, 1)); + ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass()); + clientWorld.setEnvironment(wrapper.get(Types.INT, 1)); final int entityId = wrapper.get(Types.INT, 0); addTrackedEntity(wrapper, entityId, playerType); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/Protocol1_10To1_9_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/Protocol1_10To1_9_3.java index d5eae4bc..a4ea27d4 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/Protocol1_10To1_9_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/Protocol1_10To1_9_3.java @@ -98,11 +98,8 @@ public class Protocol1_10To1_9_3 extends BackwardsProtocol { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_10To1_9_3.class); ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); Chunk chunk = wrapper.passthrough(type); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11_1to1_11/Protocol1_11_1To1_11.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11_1to1_11/Protocol1_11_1To1_11.java index 0c7482a9..0f128d3f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11_1to1_11/Protocol1_11_1To1_11.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11_1to1_11/Protocol1_11_1To1_11.java @@ -39,11 +39,8 @@ public class Protocol1_11_1To1_11 extends BackwardsProtocol { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_11To1_10.class); ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.10 Chunk type since nothing changed. Chunk chunk = wrapper.passthrough(type); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/Protocol1_12To1_11_1.java index 7ea21aa9..43831b8c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/Protocol1_12To1_11_1.java @@ -71,11 +71,8 @@ public class Protocol1_12To1_11_1 extends BackwardsProtocol { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_12To1_11_1.class); ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.9.4 Chunk type since nothing changed. Chunk chunk = wrapper.passthrough(type); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/rewriter/EntityPacketRewriter1_12.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/rewriter/EntityPacketRewriter1_12.java index b6a73f53..23d06457 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/rewriter/EntityPacketRewriter1_12.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/rewriter/EntityPacketRewriter1_12.java @@ -119,9 +119,8 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter { ShoulderTracker tracker = wrapper.user().get(ShoulderTracker.class); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/Protocol1_13_1To1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/Protocol1_13_1To1_13.java index d811253b..2ed9918f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/Protocol1_13_1To1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/Protocol1_13_1To1_13.java @@ -203,10 +203,7 @@ public class Protocol1_13_1To1_13 extends BackwardsProtocol blockRewriter = BlockRewriter.legacy(protocol); protocol.registerClientbound(ClientboundPackets1_13.LEVEL_CHUNK, wrapper -> { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_13_1To1_13.class); Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment())); blockRewriter.handleChunk(chunk); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/Protocol1_13To1_12_2.java index 8d07e4f7..3a2b0c1f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/Protocol1_13To1_12_2.java @@ -114,11 +114,8 @@ public class Protocol1_13To1_12_2 extends BackwardsProtocol { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_13To1_12_2.class); ChunkType1_9_3 type_old = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); ChunkType1_13 type = ChunkType1_13.forEnvironment(clientWorld.getEnvironment()); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java index 0d9bc3ef..b103e23b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java @@ -27,6 +27,7 @@ import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.ParticleIdMapping import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.BackwardsBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.NoteBlockStorage; import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.PlayerPositionStorage1_13; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; @@ -172,7 +173,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter { int motive = wrapper.read(Types.VAR_INT); String title = PaintingNames1_13.getStringId(motive); @@ -188,10 +189,15 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter { - wrapper.user().get(BackwardsBlockStorage.class).clear(); - wrapper.user().get(NoteBlockStorage.class).clear(); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_13To1_12_2.class); + int dimensionId = wrapper.get(Types.INT, 0); + + if (clientWorld.setEnvironment(dimensionId)) { + tracker(wrapper.user()).clearEntities(); + wrapper.user().get(BackwardsBlockStorage.class).clear(); + wrapper.user().get(NoteBlockStorage.class).clear(); + } }); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/Protocol1_14To1_13_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/Protocol1_14To1_13_2.java index 7af0a097..08bf1d42 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/Protocol1_14To1_13_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/Protocol1_14To1_13_2.java @@ -162,11 +162,8 @@ public class Protocol1_14To1_13_2 extends BackwardsProtocol { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_14To1_13_2.class); Chunk chunk = wrapper.read(ChunkType1_14.TYPE); wrapper.write(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()), chunk); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java index 6141fd35..8e1ad70c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java @@ -304,8 +304,8 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty(); wrapper.write(Types.UNSIGNED_BYTE, difficulty); @@ -329,14 +329,16 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_14To1_13_2.class); int dimensionId = wrapper.get(Types.INT, 0); - clientWorld.setEnvironment(dimensionId); + + if (clientWorld.setEnvironment(dimensionId)) { + tracker(wrapper.user()).clearEntities(); + wrapper.user().get(ChunkLightStorage.class).clear(); + } short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty(); wrapper.write(Types.UNSIGNED_BYTE, difficulty); - - wrapper.user().get(ChunkLightStorage.class).clear(); }); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/Protocol1_15To1_14_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/Protocol1_15To1_14_4.java index eedaa693..b0ad6fe8 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/Protocol1_15To1_14_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/Protocol1_15To1_14_4.java @@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.v1_15to1_14_4.storage.ImmediateRespa import com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter.BlockItemPacketRewriter1_15; import com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter.EntityPacketRewriter1_15; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.RegistryType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; @@ -102,8 +103,10 @@ public class Protocol1_15To1_14_4 extends BackwardsProtocol { boolean immediateRespawn = !wrapper.read(Types.BOOLEAN); // Inverted @@ -138,7 +139,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Entity data is no longer sent in 1.15, so we have to send an empty one - handler(getTrackerHandler(EntityTypes1_15.PLAYER, Types.VAR_INT)); + handler(getTrackerHandler(EntityTypes1_15.PLAYER)); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/EntityPacketRewriter1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/EntityPacketRewriter1_16_2.java index 1721b191..5034b24c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/EntityPacketRewriter1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/EntityPacketRewriter1_16_2.java @@ -101,13 +101,15 @@ public class EntityPacketRewriter1_16_2 extends EntityRewriter { CompoundTag dimensionData = wrapper.read(Types.NAMED_COMPOUND_TAG); wrapper.write(Types.STRING, getDimensionFromData(dimensionData)); + + tracker(wrapper.user()).clearEntities(); }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java index c90c5b88..97336dbe 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java @@ -168,14 +168,12 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol { - ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); - clientChunks.setEnvironment(wrapper.get(Types.INT, 1)); - tracker(wrapper.user()).addEntity(wrapper.get(Types.INT, 0), EntityTypes1_16.PLAYER); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_16To1_15_2.class); + clientWorld.setEnvironment(wrapper.get(Types.INT, 1)); wrapper.write(Types.STRING, "default"); // Level type diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java index bac9d0e5..3da39f89 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java @@ -100,7 +100,7 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter { CompoundTag registry = wrapper.get(Types.NAMED_COMPOUND_TAG, 0); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_9_3to1_9_1/Protocol1_9_3To1_9_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_9_3to1_9_1/Protocol1_9_3To1_9_1.java index 3415876b..8e5595b1 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_9_3to1_9_1/Protocol1_9_3To1_9_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_9_3to1_9_1/Protocol1_9_3To1_9_1.java @@ -71,7 +71,7 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_9_3To1_9_1.class); ChunkType1_9_3 newType = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); ChunkType1_9_1 oldType = ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment()); // Get the old type to not write Block Entities @@ -89,10 +89,10 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol { - ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_9_3To1_9_1.class); int dimensionId = wrapper.get(Types.INT, 1); - clientChunks.setEnvironment(dimensionId); + clientWorld.setEnvironment(dimensionId); }); } }); @@ -103,7 +103,7 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_9_3To1_9_1.class); int dimensionId = wrapper.get(Types.INT, 0); clientWorld.setEnvironment(dimensionId); @@ -117,8 +117,6 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol Date: Wed, 25 Sep 2024 17:11:36 +0200 Subject: [PATCH 13/70] Bump gradle-update/update-gradle-wrapper-action from 1 to 2 (#889) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/update-gradle-wrapper.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-gradle-wrapper.yml b/.github/workflows/update-gradle-wrapper.yml index 925038fa..a6ed992b 100644 --- a/.github/workflows/update-gradle-wrapper.yml +++ b/.github/workflows/update-gradle-wrapper.yml @@ -11,4 +11,4 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - name: Update Gradle Wrapper - uses: gradle-update/update-gradle-wrapper-action@v1 + uses: gradle-update/update-gradle-wrapper-action@v2 From 1d1e9bc0400a0d23e071f3a4060f85b79c75733f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 29 Sep 2024 04:19:27 +0200 Subject: [PATCH 14/70] Update Gradle Wrapper from 8.10.1 to 8.10.2 (#891) Signed-off-by: gradle-update-robot Co-authored-by: gradle-update-robot --- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8e876e1c..fb602ee2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip +distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From f4253641e1e9219774c7fc1ed828cd5dff6d32ce Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 29 Sep 2024 13:42:26 +0200 Subject: [PATCH 15/70] Update VV usage --- .../BackwardsStructuredItemRewriter.java | 20 +++------ .../StructuredEnchantmentRewriter.java | 42 ++++++++++--------- .../BlockItemPacketRewriter1_20_5.java | 13 +++--- .../rewriter/BlockItemPacketRewriter1_21.java | 8 ++-- 4 files changed, 38 insertions(+), 45 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java index eb30e308..1a4818c0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java @@ -20,14 +20,12 @@ package com.viaversion.viabackwards.api.rewriters; import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.IntTag; import com.viaversion.nbt.tag.ListTag; -import com.viaversion.nbt.tag.NumberTag; import com.viaversion.nbt.tag.Tag; 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.minecraft.Particle; -import com.viaversion.viaversion.api.minecraft.data.StructuredData; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -86,12 +84,12 @@ public class BackwardsStructuredItemRewriter customData = item.dataContainer().getNonEmpty(StructuredDataKey.CUSTOM_DATA); - return customData != null ? customData.value() : null; - } - protected void saveListTag(CompoundTag tag, ListTag original, String name) { // Multiple places might try to backup data String backupName = nbtTagName(name); diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java index 9ac5d311..9686bb09 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java @@ -25,7 +25,6 @@ import com.viaversion.nbt.tag.Tag; import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.utils.ChatUtil; import com.viaversion.viaversion.api.data.Mappings; -import com.viaversion.viaversion.api.minecraft.data.StructuredData; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -66,23 +65,19 @@ public class StructuredEnchantmentRewriter { public void handleToServer(final Item item) { final StructuredDataContainer data = item.dataContainer(); - final StructuredData customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA); - if (customData == null) { - return; + final CompoundTag customData = data.get(StructuredDataKey.CUSTOM_DATA); + if (customData != null) { + rewriteEnchantmentsToServer(data, customData, StructuredDataKey.ENCHANTMENTS); + rewriteEnchantmentsToServer(data, customData, StructuredDataKey.STORED_ENCHANTMENTS); } - - final CompoundTag tag = customData.value(); - rewriteEnchantmentsToServer(data, tag, StructuredDataKey.ENCHANTMENTS); - rewriteEnchantmentsToServer(data, tag, StructuredDataKey.STORED_ENCHANTMENTS); } public void rewriteEnchantmentsToClient(final StructuredDataContainer data, final StructuredDataKey key, final IdRewriteFunction rewriteFunction, final DescriptionSupplier descriptionSupplier, final boolean storedEnchant) { - final StructuredData enchantmentsData = data.getNonEmpty(key); - if (enchantmentsData == null || enchantmentsData.value().size() == 0) { + final Enchantments enchantments = data.get(key); + if (enchantments == null || enchantments.size() == 0) { return; } - final Enchantments enchantments = enchantmentsData.value(); final List loreToAdd = new ArrayList<>(); boolean removedEnchantments = false; boolean updatedLore = false; @@ -104,7 +99,7 @@ public class StructuredEnchantmentRewriter { if (!removedEnchantments) { // Backup original before doing modifications - final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); + final CompoundTag customData = customData(data); itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier()); removedEnchantments = true; } @@ -127,12 +122,12 @@ public class StructuredEnchantmentRewriter { } if (removedEnchantments) { - final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); + final CompoundTag tag = customData(data); if (!storedEnchant && enchantments.size() == 0) { // Add glint override if there are no enchantments left - final StructuredData glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE); + final Boolean glintOverride = data.get(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE); if (glintOverride != null) { - tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value()); + tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride); } else { tag.putBoolean(itemRewriter.nbtTagName("noglint"), true); } @@ -146,10 +141,10 @@ public class StructuredEnchantmentRewriter { if (updatedLore) { // Save original lore - final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); - final StructuredData loreData = data.getNonEmpty(StructuredDataKey.LORE); - if (loreData != null) { - final List loreList = Arrays.asList(loreData.value()); + final CompoundTag tag = customData(data); + final Tag[] lore = data.get(StructuredDataKey.LORE); + if (lore != null) { + final List loreList = Arrays.asList(lore); itemRewriter.saveGenericTagList(tag, loreList, "lore"); loreToAdd.addAll(loreList); } else { @@ -159,6 +154,15 @@ public class StructuredEnchantmentRewriter { } } + private CompoundTag customData(final StructuredDataContainer data) { + CompoundTag tag = data.get(StructuredDataKey.CUSTOM_DATA); + if (tag == null) { + tag = new CompoundTag(); + data.set(StructuredDataKey.CUSTOM_DATA, tag); + } + return tag; + } + private ListTag asTag(final Enchantments enchantments) { final ListTag listTag = new ListTag<>(CompoundTag.class); for (final Int2IntMap.Entry entry : enchantments.enchantments().int2IntEntrySet()) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index 6d16ccdc..ad93a2d9 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -30,7 +30,6 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Holder; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.SoundEvent; -import com.viaversion.viaversion.api.minecraft.data.StructuredData; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -363,25 +362,25 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem // 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 loreData = data.getNonEmpty(StructuredDataKey.LORE); - if (loreData != null) { - for (final Tag tag : loreData.value()) { + final Tag[] lore = data.get(StructuredDataKey.LORE); + if (lore != null) { + for (final Tag tag : lore) { protocol.getComponentRewriter().processTag(connection, tag); } } // In 1.20.6, some items have default values which are not written into the components - if (item.identifier() == 1105 && !data.contains(StructuredDataKey.FIREWORKS)) { + if (item.identifier() == 1105 && !data.has(StructuredDataKey.FIREWORKS)) { data.set(StructuredDataKey.FIREWORKS, new Fireworks(1, new FireworkExplosion[0])); } - final StructuredData customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA); + final CompoundTag customData = data.get(StructuredDataKey.CUSTOM_DATA); final Item oldItem = vvProtocol.getItemRewriter().toOldItem(connection, item, DATA_CONVERTER); if (customData != null) { // We later don't know which tags are custom data and which are not because the VV conversion // keeps converted data, so we backup the original custom data and restore it later - oldItem.tag().put(nbtTagName(), customData.value().copy()); + oldItem.tag().put(nbtTagName(), customData.copy()); } if (oldItem.tag() != null && oldItem.tag().isEmpty()) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java index f86bceef..02091d06 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java @@ -28,7 +28,6 @@ import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPa import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.OpenScreenStorage; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.PlayerRotationStorage; import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.api.minecraft.data.StructuredData; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -195,7 +194,7 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe downgradeItemData(item); final StructuredDataContainer dataContainer = item.dataContainer(); - if (dataContainer.contains(StructuredDataKey.RARITY)) { + if (dataContainer.has(StructuredDataKey.RARITY)) { return item; } @@ -233,12 +232,11 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe } private void rewriteEnchantmentToServer(final EnchantmentsPaintingsStorage storage, final Item item, final StructuredDataKey key) { - final StructuredData enchantmentsData = item.dataContainer().getNonEmpty(key); - if (enchantmentsData == null) { + final Enchantments enchantments = item.dataContainer().get(key); + if (enchantments == null) { return; } - final Enchantments enchantments = enchantmentsData.value(); final List updatedIds = new ArrayList<>(); for (final Int2IntMap.Entry entry : enchantments.enchantments().int2IntEntrySet()) { final int id = entry.getIntKey(); From 904c83f3418ed34aaa18659cd05976f7e58fb9f0 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Wed, 2 Oct 2024 10:43:15 +0200 Subject: [PATCH 16/70] Define as Sponge plugin for ViaSponge (#892) --- .../kotlin/vb.base-conventions.gradle.kts | 4 +- build.gradle.kts | 1 + settings.gradle.kts | 1 + .../resources/META-INF/sponge_plugins.json | 62 +++++++++++++++++++ universal/build.gradle.kts | 1 + 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 sponge/src/main/resources/META-INF/sponge_plugins.json diff --git a/build-logic/src/main/kotlin/vb.base-conventions.gradle.kts b/build-logic/src/main/kotlin/vb.base-conventions.gradle.kts index 377b40a1..0d4094c9 100644 --- a/build-logic/src/main/kotlin/vb.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/vb.base-conventions.gradle.kts @@ -5,7 +5,7 @@ plugins { tasks { // Variable replacements processResources { - filesMatching(listOf("plugin.yml", "fabric.mod.json")) { + filesMatching(listOf("plugin.yml", "META-INF/sponge_plugins.json", "fabric.mod.json")) { expand("version" to project.version, "description" to project.description, "url" to "https://viaversion.com/backwards") } } @@ -22,4 +22,4 @@ tasks { java { javaTarget(17) withSourcesJar() -} \ No newline at end of file +} diff --git a/build.gradle.kts b/build.gradle.kts index f32152e1..f5f6243f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,6 +14,7 @@ val main = setOf( projects.viabackwardsCommon, projects.viabackwardsBukkit, projects.viabackwardsVelocity, + projects.viabackwardsSponge, projects.viabackwardsFabric ).map { it.dependencyProject } diff --git a/settings.gradle.kts b/settings.gradle.kts index c6d9406c..312d288c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,6 +24,7 @@ includeBuild("build-logic") setupViaSubproject("common") setupViaSubproject("bukkit") setupViaSubproject("velocity") +setupViaSubproject("sponge") setupViaSubproject("fabric") setupSubproject("viabackwards") { diff --git a/sponge/src/main/resources/META-INF/sponge_plugins.json b/sponge/src/main/resources/META-INF/sponge_plugins.json new file mode 100644 index 00000000..3490a648 --- /dev/null +++ b/sponge/src/main/resources/META-INF/sponge_plugins.json @@ -0,0 +1,62 @@ +{ + "loader": { + "name": "java_plain", + "version": "1.0" + }, + "license": "GNU GPLv3", + "global": { + "version": "${version}", + "links": { + "source": "https://github.com/ViaVersion/ViaBackwards", + "issues": "https://github.com/ViaVersion/ViaBackwards/issues" + }, + "contributors": [ + { + "name": "Matsv", + "description": "Maintainer" + }, + { + "name": "kennytv", + "description": "Maintainer" + }, + { + "name": "Gerrygames", + "description": "Contributor" + }, + { + "name": "creeper123123321", + "description": "Contributor" + }, + { + "name": "ForceUpdate1", + "description": "Contributor" + }, + { + "name": "EnZaXD", + "description": "Maintainer" + } + ], + "dependencies": [ + { + "id": "spongeapi", + "version": "8.0.0" + }, + { + "id": "viasponge", + "version": "1.1.0" + }, + { + "id": "viaversion", + "version": "[5.0.4-SNAPSHOT,)" + } + ] + }, + "plugins": [ + { + "id": "viabackwards", + "name": "ViaBackwards", + "entrypoint": "com.viaversion.sponge.util.DummyEntrypoint", + "description": "${description}" + } + ] +} diff --git a/universal/build.gradle.kts b/universal/build.gradle.kts index b33b8178..3dbd030c 100644 --- a/universal/build.gradle.kts +++ b/universal/build.gradle.kts @@ -8,6 +8,7 @@ dependencies { api(projects.viabackwardsBukkit) api(projects.viabackwardsVelocity) api(projects.viabackwardsFabric) + api(projects.viabackwardsSponge) } tasks { From cb9179c8736107e9573efe87012816e5429a01a4 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Thu, 10 Oct 2024 12:45:14 +0200 Subject: [PATCH 17/70] Update required ViaFabric version, don't require fabric-loader (#895) --- fabric/src/main/resources/fabric.mod.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 07e51b96..592c14bc 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -26,8 +26,7 @@ ] }, "depends": { - "fabricloader": ">=0.14.0", - "viafabric": ">=0.4.10" + "viafabric": ">=0.4.14" }, "custom": { "modmenu:api": true, From a08de7ccc3a91d14dbe82bf32b2f18611a89db07 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 14 Oct 2024 17:25:39 +0200 Subject: [PATCH 18/70] 5.0.4 Release --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a0191ef8..8dc06750 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -projectVersion=5.0.4-SNAPSHOT +projectVersion=5.0.4 # Smile emoji mcVersions=1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 From 752c5fc48b883b35ffea9ff1f966139fc1e9ad3d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 16 Aug 2024 12:18:05 +0200 Subject: [PATCH 19/70] Bump version to 5.1.0-SNAPSHOT --- .../com/viaversion/viabackwards/api/ViaBackwardsPlatform.java | 2 +- gradle.properties | 2 +- gradle/libs.versions.toml | 2 +- settings.gradle.kts | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java index 4ab92280..7991e13c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -69,7 +69,7 @@ import java.util.logging.Logger; public interface ViaBackwardsPlatform { - String MINIMUM_VV_VERSION = "5.0.4"; + String MINIMUM_VV_VERSION = "5.1.0"; /** * Initialize ViaBackwards. diff --git a/gradle.properties b/gradle.properties index 8dc06750..c00f23c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -projectVersion=5.0.4 +projectVersion=5.1.0-SNAPSHOT # Smile emoji mcVersions=1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9212a8c8..a84ae215 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "5.0.4-SNAPSHOT" +viaver = "5.1.0-SNAPSHOT" # Common provided netty = "4.0.20.Final" diff --git a/settings.gradle.kts b/settings.gradle.kts index 312d288c..2e2365f6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,6 +4,7 @@ rootProject.name = "viabackwards-parent" dependencyResolutionManagement { repositories { + mavenLocal() maven("https://repo.viaversion.com") maven("https://repo.papermc.io/repository/maven-public/") mavenCentral() From 5cd34e6fa8cb834a4f4117678224a79bed7c8791 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 16 Aug 2024 13:01:50 +0200 Subject: [PATCH 20/70] WIP 24w33a --- .../api/ViaBackwardsPlatform.java | 2 + .../template/BlockItemPacketRewriter1_99.java | 14 +- .../template/EntityPacketRewriter1_99.java | 1 + .../protocol/template/Protocol1_98To1_99.java | 4 +- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 146 +++++++++++++++++ .../BlockItemPacketRewriter1_21_2.java | 136 ++++++++++++++++ .../rewriter/EntityPacketRewriter1_21_2.java | 150 ++++++++++++++++++ 7 files changed, 444 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java index 7991e13c..e6f6ff9d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -54,6 +54,7 @@ import com.viaversion.viabackwards.protocol.v1_19_1to1_19.Protocol1_19_1To1_19; import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20_2; import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3; import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5; import com.viaversion.viabackwards.protocol.v1_9_3to1_9_1.Protocol1_9_3To1_9_1; import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3; @@ -141,6 +142,7 @@ public interface ViaBackwardsPlatform { protocolManager.registerProtocol(new Protocol1_20_5To1_20_3(), ProtocolVersion.v1_20_3, ProtocolVersion.v1_20_5); protocolManager.registerProtocol(new Protocol1_21To1_20_5(), ProtocolVersion.v1_20_5, ProtocolVersion.v1_21); + protocolManager.registerProtocol(new Protocol1_21_2To1_21(), ProtocolVersion.v1_21, ProtocolVersion.v1_21_2); } /** diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java index 58db1cab..bf0987f5 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java @@ -20,11 +20,11 @@ package com.viaversion.viabackwards.protocol.template; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_21; -import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.RecipeRewriter1_21_2; import com.viaversion.viaversion.rewriter.BlockRewriter; // To replace if needed: @@ -52,19 +52,19 @@ final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter< blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new); blockRewriter.registerBlockEntityData(ClientboundPackets1_21.BLOCK_ENTITY_DATA); - // registerOpenWindow(ClientboundPackets1_21.OPEN_WINDOW); + // registerOpenScreen(ClientboundPackets1_21.OPEN_SCREEN); registerCooldown(ClientboundPackets1_21.COOLDOWN); - registerSetContent1_17_1(ClientboundPackets1_21.CONTAINER_SET_CONTENT); - registerSetSlot1_17_1(ClientboundPackets1_21.CONTAINER_SET_SLOT); + registerSetContent1_21_2(ClientboundPackets1_21.CONTAINER_SET_CONTENT); + registerSetSlot1_21_2(ClientboundPackets1_21.CONTAINER_SET_SLOT); registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS); registerSetEquipment(ClientboundPackets1_21.SET_EQUIPMENT); - registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK); + registerContainerClick1_21_2(ServerboundPackets1_20_5.CONTAINER_CLICK); registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS); registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT); registerContainerSetData(ClientboundPackets1_21.CONTAINER_SET_DATA); registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES); - registerExplosion(ClientboundPackets1_21.EXPLODE); + registerExplosion1_21_2(ClientboundPackets1_21.EXPLODE); - new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES); + new RecipeRewriter1_21_2<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java index 806bf705..2ab161fb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java @@ -66,6 +66,7 @@ final class EntityPacketRewriter1_99 extends EntityRewriter(this).register(ClientboundPackets1_21.AWARD_STATS); - //new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21.ENTITY_PROPERTIES); + //new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21.UPDATE_ATTRIBUTES); // Registers translatable mappings (missing a whole bunch still) - //translatableRewriter.registerOpenWindow(ClientboundPackets1_21.OPEN_WINDOW); // Handled by registerOpenWindow in item rewriters + //translatableRewriter.registerOpenScreen(ClientboundPackets1_21.OPEN_SCREEN); // Handled by registerOpenScreen in item rewriters translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_ACTION_BAR_TEXT); translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_TITLE_TEXT); translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_SUBTITLE_TEXT); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java new file mode 100644 index 00000000..8ab65028 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -0,0 +1,146 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21; + +import com.viaversion.viabackwards.api.BackwardsProtocol; +import com.viaversion.viabackwards.api.data.BackwardsMappingData; +import com.viaversion.viabackwards.api.rewriters.SoundRewriter; +import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.BlockItemPacketRewriter1_21_2; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; +import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.data.entity.EntityTrackerBase; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.Protocol1_21To1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; +import com.viaversion.viaversion.rewriter.AttributeRewriter; +import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType; +import com.viaversion.viaversion.rewriter.StatisticsRewriter; +import com.viaversion.viaversion.rewriter.TagRewriter; + +import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap; + +public final class Protocol1_21_2To1_21 extends BackwardsProtocol { + + public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.21.2", "1.21", Protocol1_21To1_21_2.class); + private final EntityPacketRewriter1_21_2 entityRewriter = new EntityPacketRewriter1_21_2(this); + private final BlockItemPacketRewriter1_21_2 itemRewriter = new BlockItemPacketRewriter1_21_2(this); + private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); + private final TagRewriter tagRewriter = new TagRewriter<>(this); + + public Protocol1_21_2To1_21() { + super(ClientboundPacket1_21_2.class, ClientboundPacket1_21.class, ServerboundPacket1_21_2.class, ServerboundPacket1_20_5.class); + } + + @Override + protected void registerPackets() { + super.registerPackets(); + + tagRewriter.registerGeneric(ClientboundPackets1_21_2.UPDATE_TAGS); + tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21.UPDATE_TAGS); + + final SoundRewriter soundRewriter = new SoundRewriter<>(this); + soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND); + soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND_ENTITY); + soundRewriter.registerStopSound(ClientboundPackets1_21_2.STOP_SOUND); + + new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS); + new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES); + + translatableRewriter.registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT); + translatableRewriter.registerBossEvent(ClientboundPackets1_21_2.BOSS_EVENT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISCONNECT); + translatableRewriter.registerTabList(ClientboundPackets1_21_2.TAB_LIST); + translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21_2.PLAYER_COMBAT_KILL); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SYSTEM_CHAT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISGUISED_CHAT); + translatableRewriter.registerPing(); + + registerServerbound(ServerboundPackets1_20_5.CLIENT_INFORMATION, this::clientInformation); + registerServerbound(ServerboundConfigurationPackets1_20_5.CLIENT_INFORMATION, this::clientInformation); + + cancelClientbound(ClientboundPackets1_21_2.MOVE_MINECART_ALONG_TRACK); // TODO + } + + private void clientInformation(final PacketWrapper wrapper) { + wrapper.passthrough(Types.STRING); // Locale + wrapper.passthrough(Types.BYTE); // View distance + wrapper.passthrough(Types.VAR_INT); // Chat visibility + wrapper.passthrough(Types.BOOLEAN); // Chat colors + wrapper.passthrough(Types.BYTE); // Skin parts + wrapper.passthrough(Types.VAR_INT); // Main hand + wrapper.passthrough(Types.BOOLEAN); // Text filtering enabled + wrapper.passthrough(Types.BOOLEAN); // Allow listing + wrapper.write(Types.VAR_INT, 0); // Particle status, assume 'all' + } + + @Override + public void init(final UserConnection user) { + addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER)); + } + + @Override + public BackwardsMappingData getMappingData() { + return MAPPINGS; + } + + @Override + public EntityPacketRewriter1_21_2 getEntityRewriter() { + return entityRewriter; + } + + @Override + public BlockItemPacketRewriter1_21_2 getItemRewriter() { + return itemRewriter; + } + + @Override + public TranslatableRewriter getComponentRewriter() { + return translatableRewriter; + } + + @Override + public TagRewriter getTagRewriter() { + return tagRewriter; + } + + @Override + protected PacketTypesProvider createPacketTypesProvider() { + return new SimplePacketTypesProvider<>( + packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class), + packetTypeMap(mappedClientboundPacketType, ClientboundPacket1_21.class, ClientboundConfigurationPackets1_21.class), + packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class), + packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class) + ); + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java new file mode 100644 index 00000000..87e206f2 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -0,0 +1,136 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; + +import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +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_21; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.rewriter.BlockRewriter; + +import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.downgradeItemData; +import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.updateItemData; + +public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItemRewriter { + + public BlockItemPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) { + super(protocol, + Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY, + Types1_21_2.ITEM_COST, Types1_21_2.OPTIONAL_ITEM_COST, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, + Types1_21_2.PARTICLE, Types1_21.PARTICLE + ); + } + + @Override + public void registerPackets() { + final BlockRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); + blockRewriter.registerBlockEvent(ClientboundPackets1_21_2.BLOCK_EVENT); + blockRewriter.registerBlockUpdate(ClientboundPackets1_21_2.BLOCK_UPDATE); + blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_2.SECTION_BLOCKS_UPDATE); + blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_2.LEVEL_EVENT, 2001); + blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_2.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new); + blockRewriter.registerBlockEntityData(ClientboundPackets1_21_2.BLOCK_ENTITY_DATA); + + registerCooldown(ClientboundPackets1_21_2.COOLDOWN); + registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS); + registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT); + registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS); + registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT); + registerLevelParticles1_20_5(ClientboundPackets1_21_2.LEVEL_PARTICLES); + registerExplosion1_21_2(ClientboundPackets1_21_2.EXPLODE); + + protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT, wrapper -> { + updateContainerId(wrapper); + wrapper.passthrough(Types.VAR_INT); // State id + Item[] items = wrapper.read(itemArrayType()); + wrapper.write(mappedItemArrayType(), items); + for (int i = 0; i < items.length; i++) { + items[i] = handleItemToClient(wrapper.user(), items[i]); + } + passthroughClientboundItem(wrapper); + }); + protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_SLOT, wrapper -> { + updateContainerId(wrapper); + wrapper.passthrough(Types.VAR_INT); // State id + wrapper.passthrough(Types.SHORT); // Slot id + passthroughClientboundItem(wrapper); + }); + protocol.registerClientbound(ClientboundPackets1_21_2.SET_HELD_SLOT, ClientboundPackets1_21.SET_CARRIED_ITEM); + protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_CLOSE, this::updateContainerId); + protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_DATA, this::updateContainerId); + protocol.registerClientbound(ClientboundPackets1_21_2.HORSE_SCREEN_OPEN, this::updateContainerId); + protocol.registerClientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, this::updateContainerId); + protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLOSE, this::updateContainerIdServerbound); + protocol.registerServerbound(ServerboundPackets1_20_5.PLACE_RECIPE, this::updateContainerIdServerbound); + protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLICK, wrapper -> { + updateContainerIdServerbound(wrapper); + wrapper.passthrough(Types.VAR_INT); // State id + wrapper.passthrough(Types.SHORT); // Slot + wrapper.passthrough(Types.BYTE); // Button + wrapper.passthrough(Types.VAR_INT); // Mode + final int length = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < length; i++) { + wrapper.passthrough(Types.SHORT); // Slot + passthroughServerboundItem(wrapper); + } + passthroughServerboundItem(wrapper); + }); + + protocol.registerClientbound(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY, ClientboundPackets1_21.CONTAINER_SET_SLOT, wrapper -> { + wrapper.write(Types.BYTE, (byte) -2); // Player inventory + wrapper.write(Types.VAR_INT, 0); // 0 state id + final int slot = wrapper.read(Types.VAR_INT); + wrapper.write(Types.SHORT, (short) slot); + }); + } + + private void updateContainerId(final PacketWrapper wrapper) { + final int containerId = wrapper.read(Types.VAR_INT); + wrapper.write(Types.UNSIGNED_BYTE, (short) containerId); + } + + private void updateContainerIdServerbound(final PacketWrapper wrapper) { + final short containerId = wrapper.read(Types.UNSIGNED_BYTE); + final int intId = (byte) containerId; + wrapper.write(Types.VAR_INT, intId); + } + + @Override + public Item handleItemToClient(final UserConnection connection, final Item item) { + super.handleItemToClient(connection, item); + downgradeItemData(item); + return item; + } + + @Override + public Item handleItemToServer(final UserConnection connection, final Item item) { + super.handleItemToServer(connection, item); + updateItemData(item); + return item; + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java new file mode 100644 index 00000000..bce3eb0f --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -0,0 +1,150 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; + +import com.viaversion.viabackwards.api.rewriters.EntityRewriter; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viaversion.api.minecraft.RegistryEntry; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.version.Types1_21; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.util.Key; + +import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.EntityPacketRewriter1_21_2.updateEnchantmentAttributes; + +public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + + public EntityPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) { + super(protocol, Types1_21.ENTITY_DATA_TYPES.optionalComponentType, Types1_21.ENTITY_DATA_TYPES.booleanType); + } + + @Override + public void registerPackets() { + registerTrackerWithData1_19(ClientboundPackets1_21_2.ADD_ENTITY, EntityTypes1_20_5.FALLING_BLOCK); + registerSetEntityData(ClientboundPackets1_21_2.SET_ENTITY_DATA, Types1_21_2.ENTITY_DATA_LIST, Types1_21.ENTITY_DATA_LIST); + registerRemoveEntities(ClientboundPackets1_21_2.REMOVE_ENTITIES); + + protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> { + final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); + final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY); + if (registryKey.equals("enchantment")) { + updateEnchantmentAttributes(entries, protocol.getMappingData().getAttributeMappings()); + } + + handleRegistryData1_20_5(wrapper.user(), registryKey, entries); + }); + + protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, new PacketHandlers() { + @Override + public void register() { + map(Types.INT); // Entity id + map(Types.BOOLEAN); // Hardcore + map(Types.STRING_ARRAY); // World List + map(Types.VAR_INT); // Max players + map(Types.VAR_INT); // View distance + map(Types.VAR_INT); // Simulation distance + map(Types.BOOLEAN); // Reduced debug info + map(Types.BOOLEAN); // Show death screen + map(Types.BOOLEAN); // Limited crafting + map(Types.VAR_INT); // Dimension key + map(Types.STRING); // World + map(Types.LONG); // Seed + map(Types.BYTE); // Gamemode + map(Types.BYTE); // Previous gamemode + map(Types.BOOLEAN); // Debug + map(Types.BOOLEAN); // Flat + map(Types.OPTIONAL_GLOBAL_POSITION); // Last death location + map(Types.VAR_INT); // Portal cooldown + handler(worldDataTrackerHandlerByKey1_20_5(3)); + handler(playerTrackerHandler()); + read(Types.VAR_INT); // Sea level + } + }); + + protocol.registerClientbound(ClientboundPackets1_21_2.RESPAWN, wrapper -> { + final int dimensionId = wrapper.passthrough(Types.VAR_INT); + final String world = wrapper.passthrough(Types.STRING); + wrapper.passthrough(Types.LONG); // Seed + wrapper.passthrough(Types.BYTE); // Gamemode + wrapper.passthrough(Types.BYTE); // Previous gamemode + wrapper.passthrough(Types.BOOLEAN); // Debug + wrapper.passthrough(Types.BOOLEAN); // Flat + wrapper.passthrough(Types.OPTIONAL_GLOBAL_POSITION); // Last death location + wrapper.passthrough(Types.VAR_INT); // Portal cooldown + + wrapper.read(Types.VAR_INT); // Sea level + trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); + }); + + protocol.appendServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS, wrapper -> { + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + fixOnGround(wrapper); + }); + protocol.appendServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> { + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + wrapper.passthrough(Types.FLOAT); // Yaw + wrapper.passthrough(Types.FLOAT); // Pitch + fixOnGround(wrapper); + }); + protocol.appendServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> { + wrapper.passthrough(Types.FLOAT); // Yaw + wrapper.passthrough(Types.FLOAT); // Pitch + fixOnGround(wrapper); + }); + protocol.appendServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, this::fixOnGround); + } + + private void fixOnGround(final PacketWrapper wrapper) { + final boolean data = wrapper.read(Types.BOOLEAN); + wrapper.write(Types.UNSIGNED_BYTE, data ? (short) 1 : 0); // Carries more data now + } + + @Override + protected void registerRewrites() { + filter().mapDataType(Types1_21.ENTITY_DATA_TYPES::byId); + registerEntityDataTypeHandler1_20_3( + Types1_21.ENTITY_DATA_TYPES.itemType, + Types1_21.ENTITY_DATA_TYPES.blockStateType, + Types1_21.ENTITY_DATA_TYPES.optionalBlockStateType, + Types1_21.ENTITY_DATA_TYPES.particleType, + Types1_21.ENTITY_DATA_TYPES.particlesType, + Types1_21.ENTITY_DATA_TYPES.componentType, + Types1_21.ENTITY_DATA_TYPES.optionalComponentType + ); + registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11); + + filter().type(EntityTypes1_20_5.SALMON).removeIndex(17); // Data type + } + + @Override + public EntityType typeFromId(final int type) { + return EntityTypes1_20_5.getTypeFromId(type); + } +} From 5269a610d1fb3cf11e73ad5c17ee76f233033aea Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 16 Aug 2024 13:51:52 +0200 Subject: [PATCH 21/70] More work --- .../BlockItemPacketRewriter1_21_2.java | 91 ++++++++++++++++++ .../data/mappings-1.21.2to1.21.nbt | Bin 0 -> 881 bytes 2 files changed, 91 insertions(+) create mode 100644 common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 87e206f2..2dd45bc6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -20,7 +20,10 @@ package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.HolderSet; +import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.minecraft.item.StructuredItem; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; @@ -31,7 +34,9 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPac import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.RecipeRewriter1_21_2; import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.SoundRewriter; import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.downgradeItemData; import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.updateItemData; @@ -107,6 +112,92 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem final int slot = wrapper.read(Types.VAR_INT); wrapper.write(Types.SHORT, (short) slot); }); + + protocol.registerClientbound(ClientboundPackets1_21_2.EXPLODE, wrapper -> { + wrapper.passthrough(Types.DOUBLE); // Center X + wrapper.passthrough(Types.DOUBLE); // Center Y + wrapper.passthrough(Types.DOUBLE); // Center Z + + // TODO + wrapper.write(Types.FLOAT, 0F); // Power + wrapper.write(Types.VAR_INT, 0); // No blocks affected + + double knockbackX = 0; + double knockbackY = 0; + double knockbackZ = 0; + if (wrapper.read(Types.BOOLEAN)) { + knockbackX = wrapper.read(Types.DOUBLE); + knockbackY = wrapper.read(Types.DOUBLE); + knockbackZ = wrapper.read(Types.DOUBLE); + } + wrapper.write(Types.FLOAT, (float) knockbackX); + wrapper.write(Types.FLOAT, (float) knockbackY); + wrapper.write(Types.FLOAT, (float) knockbackZ); + + wrapper.write(Types.VAR_INT, 0); // Block interaction type + + final Particle explosionParticle = wrapper.read(Types1_21.PARTICLE); + rewriteParticle(wrapper.user(), explosionParticle); + // As small and large explosion particle + wrapper.write(Types1_21_2.PARTICLE, explosionParticle); + wrapper.write(Types1_21_2.PARTICLE, explosionParticle); + + new SoundRewriter<>(protocol).soundHolderHandler().handle(wrapper); + }); + + new RecipeRewriter1_21_2<>(protocol) { + @Override + protected void handleIngredient(final PacketWrapper wrapper) { + wrapper.write(mappedItemArrayType(), ingredient(wrapper)); + } + + @Override + public void handleCraftingShaped(final PacketWrapper wrapper) { + wrapper.passthrough(Types.STRING); // Group + wrapper.passthrough(Types.VAR_INT); // Crafting book category + wrapper.passthrough(Types.VAR_INT); // Width + wrapper.passthrough(Types.VAR_INT); // Height + + final int ingredients = wrapper.read(Types.VAR_INT); + for (int i = 0; i < ingredients; i++) { + wrapper.write(mappedItemArrayType(), ingredient(wrapper)); + } + + wrapper.write(mappedItemType(), rewrite(wrapper.user(), wrapper.read(itemType()))); // Result + wrapper.passthrough(Types.BOOLEAN); // Show notification + } + + @Override + public void handleCraftingShapeless(final PacketWrapper wrapper) { + wrapper.passthrough(Types.STRING); // Group + wrapper.passthrough(Types.VAR_INT); // Crafting book category + + // Move below + final Item result = rewrite(wrapper.user(), wrapper.read(itemType())); + + final int ingredients = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < ingredients; i++) { + wrapper.write(mappedItemArrayType(), ingredient(wrapper)); + } + + wrapper.write(mappedItemType(), result); + } + + private Item[] ingredient(final PacketWrapper wrapper) { + final HolderSet ingredient = wrapper.read(Types.HOLDER_SET).rewrite(id -> protocol.getMappingData().getNewItemId(id)); + if (ingredient.hasTagKey()) { + // TODO + return new Item[]{new StructuredItem(1, 1)}; + } + + final int[] ids = ingredient.ids(); + final Item[] items = new Item[ids.length]; + for (int i = 0; i < ids.length; i++) { + items[i] = new StructuredItem(ids[i], 1); + } + return items; + } + }.register1_20_5(ClientboundPackets1_21_2.UPDATE_RECIPES); } private void updateContainerId(final PacketWrapper wrapper) { diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt new file mode 100644 index 0000000000000000000000000000000000000000..1e876217234a8408c6526f1ae5096ec722034d69 GIT binary patch literal 881 zcmZXS-A)@Z5QR^&*|6P|pCpC!zkPy;3!p-93tVtj^#LL$8HC0DX>CC8J}vhM-iJO3 z9PeTT8%y7X$H#MK#*TpiOBYfaoo4`AF?!P^pPd=2te60Cs)|D9fAqBgr~56m^*jjB zG0y?S2(^{8DGj$PY3oHA{_3HvEIpR!8Ims0IV4BqhTM^RifmqsI)7_nxW$75@{inB z#ORv*JexONyT=XJ?r-l(M?8@KKsX>9WaQn#N3L2BY|?dyhkdpdD{D(VJzpFJepF8A zA-GTpul^)%wMd%;q(hu9J9S+nBJW5{dgMJ>CM#r>tdTxpeHfAtWSy{9jL1jwiF_ts z$XD|1x%BVMIw)nP3z--xwMzIxWph9nH3ozYKOk55vLA@stT5wnuB@8O^0de^$?U{l z71H<=*lniV^C{g7Uh4L#16QzH)gfnGy=10RF%d@YFO8>s+C;`WV Date: Wed, 21 Aug 2024 18:29:23 +0200 Subject: [PATCH 22/70] Working 24w34a --- .../BackwardsStructuredItemRewriter.java | 1 + .../api/rewriters/TranslatableRewriter.java | 3 +- .../template/BlockItemPacketRewriter1_99.java | 55 +++++++------- .../template/EntityPacketRewriter1_99.java | 16 ++--- .../protocol/template/Protocol1_98To1_99.java | 68 +++++++++--------- .../BlockItemPacketRewriter1_20_5.java | 1 + .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 3 +- .../BlockItemPacketRewriter1_21_2.java | 35 ++++++++- .../rewriter/EntityPacketRewriter1_21_2.java | 41 +++++++++++ .../storage/InventoryStateIdStorage.java | 33 +++++++++ .../data/mappings-1.21.2to1.21.nbt | Bin 881 -> 937 bytes .../data/translation-mappings.json | 39 +++++++++- gradle.properties | 4 +- 13 files changed, 223 insertions(+), 76 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/InventoryStateIdStorage.java diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java index 1a4818c0..e5a81d90 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java @@ -35,6 +35,7 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.rewriter.StructuredItemRewriter; import java.util.ArrayList; import java.util.List; +import java.util.function.Function; import org.checkerframework.checker.nullness.qual.Nullable; public class BackwardsStructuredItemRewriter extends Compo super(protocol, type); final Map translatableMappings = getTranslatableMappings(version); if (translatableMappings == null) { - protocol.getLogger().warning("Missing " + version + " translatables!"); + ViaBackwards.getPlatform().getLogger().warning("Missing " + version + " translatables!"); this.translatables = new HashMap<>(); } else { this.translatables = translatableMappings; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java index bf0987f5..b9c27c8a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java @@ -19,11 +19,11 @@ package com.viaversion.viabackwards.protocol.template; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; -import com.viaversion.viaversion.api.type.types.version.Types1_21; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.RecipeRewriter1_21_2; import com.viaversion.viaversion.rewriter.BlockRewriter; @@ -31,10 +31,10 @@ import com.viaversion.viaversion.rewriter.BlockRewriter; // ChunkType1_20_2 // RecipeRewriter1_20_3 // Types1_21 -final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter { +final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter { public BlockItemPacketRewriter1_99(final Protocol1_98To1_99 protocol) { - super(protocol, Types1_21.ITEM, Types1_21.ITEM_ARRAY); + super(protocol, Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY); /*super(protocol, Types1_21.ITEM, Types1_21.ITEM_ARRAY, Types1_OLD.ITEM, Types1_OLD.ITEM_ARRAY, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST, @@ -44,27 +44,28 @@ final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter< @Override public void registerPackets() { - final BlockRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); - blockRewriter.registerBlockEvent(ClientboundPackets1_21.BLOCK_EVENT); - blockRewriter.registerBlockUpdate(ClientboundPackets1_21.BLOCK_UPDATE); - blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21.SECTION_BLOCKS_UPDATE); - blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21.LEVEL_EVENT, 2001); - blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new); - blockRewriter.registerBlockEntityData(ClientboundPackets1_21.BLOCK_ENTITY_DATA); + final BlockRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); + blockRewriter.registerBlockEvent(ClientboundPackets1_21_2.BLOCK_EVENT); + blockRewriter.registerBlockUpdate(ClientboundPackets1_21_2.BLOCK_UPDATE); + blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_2.SECTION_BLOCKS_UPDATE); + blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_2.LEVEL_EVENT, 2001); + blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_2.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new); + blockRewriter.registerBlockEntityData(ClientboundPackets1_21_2.BLOCK_ENTITY_DATA); - // registerOpenScreen(ClientboundPackets1_21.OPEN_SCREEN); - registerCooldown(ClientboundPackets1_21.COOLDOWN); - registerSetContent1_21_2(ClientboundPackets1_21.CONTAINER_SET_CONTENT); - registerSetSlot1_21_2(ClientboundPackets1_21.CONTAINER_SET_SLOT); - registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS); - registerSetEquipment(ClientboundPackets1_21.SET_EQUIPMENT); - registerContainerClick1_21_2(ServerboundPackets1_20_5.CONTAINER_CLICK); - registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS); - registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT); - registerContainerSetData(ClientboundPackets1_21.CONTAINER_SET_DATA); - registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES); - registerExplosion1_21_2(ClientboundPackets1_21.EXPLODE); + // registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN); + protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, this::passthroughClientboundItem); + registerCooldown1_21_2(ClientboundPackets1_21_2.COOLDOWN); + registerSetContent1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT); + registerSetSlot1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_SLOT); + registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS); + registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT); + registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS); + registerContainerSetData(ClientboundPackets1_21_2.CONTAINER_SET_DATA); + registerLevelParticles1_20_5(ClientboundPackets1_21_2.LEVEL_PARTICLES); + registerExplosion1_21_2(ClientboundPackets1_21_2.EXPLODE); + registerContainerClick1_21_2(ServerboundPackets1_21_2.CONTAINER_CLICK); + registerSetCreativeModeSlot(ServerboundPackets1_21_2.SET_CREATIVE_MODE_SLOT); - new RecipeRewriter1_21_2<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES); + new RecipeRewriter1_21_2<>(protocol).register1_20_5(ClientboundPackets1_21_2.UPDATE_RECIPES); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java index 2ab161fb..94fc157b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java @@ -25,14 +25,14 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; import com.viaversion.viaversion.util.Key; // Replace if needed // Types1_OLD // Types1_21 -final class EntityPacketRewriter1_99 extends EntityRewriter { +final class EntityPacketRewriter1_99 extends EntityRewriter { public EntityPacketRewriter1_99(final Protocol1_98To1_99 protocol) { super(protocol, Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType, Types1_20_5.ENTITY_DATA_TYPES.booleanType); @@ -40,9 +40,9 @@ final class EntityPacketRewriter1_99 extends EntityRewriter { @@ -51,7 +51,7 @@ final class EntityPacketRewriter1_99 extends EntityRewriter { + protocol.registerClientbound(ClientboundPackets1_21_2.RESPAWN, wrapper -> { final int dimensionId = wrapper.passthrough(Types.VAR_INT); final String world = wrapper.passthrough(Types.STRING); trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); // Tracks world height and name for chunk data and entity (un)tracking diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java index f5cbb975..649021c7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java @@ -27,12 +27,12 @@ import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvide import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -42,51 +42,51 @@ import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap; // Placeholders to replace (in the entire package): // Protocol1_98To1_99, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99 // Protocol1_20_5To1_21 (the ViaVersion protocol class the mappings depend on) -// ClientboundPacket1_21 -// ServerboundPacket1_20_5 +// ClientboundPacket1_21_2 +// ServerboundPacket1_21_2 // ClientboundConfigurationPackets1_21 // ServerboundConfigurationPackets1_20_5 // EntityTypes1_20_5 (UNMAPPED type) // 1.99, 1.98 -final class Protocol1_98To1_99 extends BackwardsProtocol { +final class Protocol1_98To1_99 extends BackwardsProtocol { // ViaBackwards uses its own mappings and also needs a translatablerewriter for translation mappings public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.99", "1.98", Protocol1_20_5To1_21.class); private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this); private final BlockItemPacketRewriter1_99 itemRewriter = new BlockItemPacketRewriter1_99(this); - private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); - private final TagRewriter tagRewriter = new TagRewriter<>(this); + private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); + private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_98To1_99() { - super(ClientboundPacket1_21.class, ClientboundPacket1_21.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class); + super(ClientboundPacket1_21_2.class, ClientboundPacket1_21_2.class, ServerboundPacket1_21_2.class, ServerboundPacket1_21_2.class); } @Override protected void registerPackets() { super.registerPackets(); - tagRewriter.registerGeneric(ClientboundPackets1_21.UPDATE_TAGS); + tagRewriter.registerGeneric(ClientboundPackets1_21_2.UPDATE_TAGS); tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21.UPDATE_TAGS); - final SoundRewriter soundRewriter = new SoundRewriter<>(this); - soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND); - soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND_ENTITY); - soundRewriter.registerStopSound(ClientboundPackets1_21.STOP_SOUND); + final SoundRewriter soundRewriter = new SoundRewriter<>(this); + soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND); + soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND_ENTITY); + soundRewriter.registerStopSound(ClientboundPackets1_21_2.STOP_SOUND); - new StatisticsRewriter<>(this).register(ClientboundPackets1_21.AWARD_STATS); - //new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21.UPDATE_ATTRIBUTES); + new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS); + //new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES); // Registers translatable mappings (missing a whole bunch still) - //translatableRewriter.registerOpenScreen(ClientboundPackets1_21.OPEN_SCREEN); // Handled by registerOpenScreen in item rewriters - translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_ACTION_BAR_TEXT); - translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_TITLE_TEXT); - translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_SUBTITLE_TEXT); - translatableRewriter.registerBossEvent(ClientboundPackets1_21.BOSS_EVENT); - translatableRewriter.registerComponentPacket(ClientboundPackets1_21.DISCONNECT); - translatableRewriter.registerTabList(ClientboundPackets1_21.TAB_LIST); - translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21.PLAYER_COMBAT_KILL); - translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SYSTEM_CHAT); - translatableRewriter.registerComponentPacket(ClientboundPackets1_21.DISGUISED_CHAT); + //translatableRewriter.registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN); // Handled by registerOpenScreen in item rewriters + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT); + translatableRewriter.registerBossEvent(ClientboundPackets1_21_2.BOSS_EVENT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISCONNECT); + translatableRewriter.registerTabList(ClientboundPackets1_21_2.TAB_LIST); + translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21_2.PLAYER_COMBAT_KILL); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SYSTEM_CHAT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISGUISED_CHAT); translatableRewriter.registerPing(); } @@ -111,22 +111,22 @@ final class Protocol1_98To1_99 extends BackwardsProtocol getComponentRewriter() { + public TranslatableRewriter getComponentRewriter() { return translatableRewriter; } @Override - public TagRewriter getTagRewriter() { + public TagRewriter getTagRewriter() { return tagRewriter; } @Override - protected PacketTypesProvider createPacketTypesProvider() { + protected PacketTypesProvider createPacketTypesProvider() { return new SimplePacketTypesProvider<>( - packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class), - packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class), - packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class), - packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class) + packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class), + packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class), + packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class), + packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class) ); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index ad93a2d9..3d0c5a64 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -50,6 +50,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPac import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.StructuredDataConverter; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.util.Key; +import java.util.function.Function; import org.checkerframework.checker.nullness.qual.Nullable; public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItemRewriter { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 8ab65028..856bc3f0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -35,6 +35,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPac import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; import com.viaversion.viaversion.protocols.v1_21to1_21_2.Protocol1_21To1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; @@ -138,7 +139,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol createPacketTypesProvider() { return new SimplePacketTypesProvider<>( packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class), - packetTypeMap(mappedClientboundPacketType, ClientboundPacket1_21.class, ClientboundConfigurationPackets1_21.class), + packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class), packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class), packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class) ); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 2dd45bc6..15eab7c6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -19,7 +19,9 @@ package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.data.MappingData; import com.viaversion.viaversion.api.minecraft.HolderSet; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -61,13 +63,31 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_2.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new); blockRewriter.registerBlockEntityData(ClientboundPackets1_21_2.BLOCK_ENTITY_DATA); - registerCooldown(ClientboundPackets1_21_2.COOLDOWN); registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS); registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT); registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS); registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT); registerLevelParticles1_20_5(ClientboundPackets1_21_2.LEVEL_PARTICLES); - registerExplosion1_21_2(ClientboundPackets1_21_2.EXPLODE); + + protocol.registerClientbound(ClientboundPackets1_21_2.COOLDOWN, wrapper -> { + final MappingData mappingData = protocol.getMappingData(); + final String itemIdentifier = wrapper.read(Types.STRING); + final int id = mappingData.getFullItemMappings().id(itemIdentifier); + if (id != -1) { + final int mappedId = mappingData.getFullItemMappings().getNewId(id); + wrapper.write(Types.VAR_INT, mappedId); + } else { + wrapper.cancel(); + } + }); + + protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, ClientboundPackets1_21.CONTAINER_SET_SLOT, wrapper -> { + wrapper.write(Types.BYTE, (byte) -1); // Player inventory + wrapper.write(Types.VAR_INT, wrapper.user().get(InventoryStateIdStorage.class).stateId()); // State id; re-use the last known one + wrapper.write(Types.SHORT, (short) -1); // Cursor + final Item item = wrapper.passthrough(Types1_21_2.ITEM); + handleItemToClient(wrapper.user(), item); + }); protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT, wrapper -> { updateContainerId(wrapper); @@ -106,6 +126,17 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem passthroughServerboundItem(wrapper); }); + protocol.registerServerbound(ServerboundPackets1_20_5.USE_ITEM_ON, wrapper -> { + wrapper.passthrough(Types.VAR_INT); // Hand + wrapper.passthrough(Types.BLOCK_POSITION1_14); // Block position + wrapper.passthrough(Types.VAR_INT); // Direction + wrapper.passthrough(Types.FLOAT); // X + wrapper.passthrough(Types.FLOAT); // Y + wrapper.passthrough(Types.FLOAT); // Z + wrapper.passthrough(Types.BOOLEAN); // Inside + wrapper.write(Types.BOOLEAN, false); // World border hit + }); + protocol.registerClientbound(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY, ClientboundPackets1_21.CONTAINER_SET_SLOT, wrapper -> { wrapper.write(Types.BYTE, (byte) -2); // Player inventory wrapper.write(Types.VAR_INT, 0); // 0 state id diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index bce3eb0f..e82a71c9 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -32,6 +32,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfi import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; import com.viaversion.viaversion.util.Key; +import java.util.BitSet; import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.EntityPacketRewriter1_21_2.updateEnchantmentAttributes; @@ -119,6 +120,46 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM); + final int entries = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < entries; i++) { + wrapper.passthrough(Types.UUID); + if (actions.get(0)) { + wrapper.passthrough(Types.STRING); // Player Name + + final int properties = wrapper.passthrough(Types.VAR_INT); + for (int j = 0; j < properties; j++) { + wrapper.passthrough(Types.STRING); // Name + wrapper.passthrough(Types.STRING); // Value + wrapper.passthrough(Types.OPTIONAL_STRING); // Signature + } + } + if (actions.get(1) && wrapper.passthrough(Types.BOOLEAN)) { + wrapper.passthrough(Types.UUID); // Session UUID + wrapper.passthrough(Types.PROFILE_KEY); + } + if (actions.get(2)) { + wrapper.passthrough(Types.VAR_INT); // Gamemode + } + if (actions.get(3)) { + wrapper.passthrough(Types.BOOLEAN); // Listed + } + if (actions.get(4)) { + wrapper.passthrough(Types.VAR_INT); // Latency + } + if (actions.get(5)) { + wrapper.passthrough(Types.TAG); // Display name + } + + // New one + if (actions.get(6)) { + actions.clear(6); + wrapper.read(Types.VAR_INT); // List order + } + } + }); } private void fixOnGround(final PacketWrapper wrapper) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/InventoryStateIdStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/InventoryStateIdStorage.java new file mode 100644 index 00000000..0f6064fa --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/InventoryStateIdStorage.java @@ -0,0 +1,33 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; + +public final class InventoryStateIdStorage implements StorableObject { + + private int stateId = -1; + + public int stateId() { + return stateId; + } + + public void setStateId(final int stateId) { + this.stateId = stateId; + } +} diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt index 1e876217234a8408c6526f1ae5096ec722034d69..fbb9c28bbd954e09ff8a5836f3a198697a978217 100644 GIT binary patch delta 125 zcmey!wvv59i6|EX12ZcSvjOpQAbtVFFDKT@fFxL!0y!W_ki;_}ez9@UW=4BEZU&~r r5(Wkab|4l7Vlf~V2Vw~zmI7jFAeI3tD#-^j*#9E|AYXKH3DaKy(~li< delta 69 zcmZ3<{*i4$2`4)P12ZcSvrX)j0dZKCf&@11+RP|#&CS4+Si%701F<*|O8~JXP_QH) KBsh5u(_a9o6bqXG diff --git a/common/src/main/resources/assets/viabackwards/data/translation-mappings.json b/common/src/main/resources/assets/viabackwards/data/translation-mappings.json index d0e0c23f..2537fbfc 100644 --- a/common/src/main/resources/assets/viabackwards/data/translation-mappings.json +++ b/common/src/main/resources/assets/viabackwards/data/translation-mappings.json @@ -1,4 +1,41 @@ { + "1.21.2": { + "attribute.name.tempt_range": "Mob Tempt Range", + "commands.schedule.macro": "Can't schedule a macro", + "commands.setidletimeout.success.disabled": "The player idle timeout is now disabled", + "dataPack.minecart_improvements.description": "Improved movement for Minecarts", + "dataPack.minecart_improvements.name": "Minecart Improvements", + "dataPack.redstone_experiments.description": "Experimental Redstone changes", + "dataPack.redstone_experiments.name": "Redstone Experiments", + "death.attack.mace_smash": "%1$s was smashed by %2$s", + "death.attack.mace_smash.item": "%1$s was smashed by %2$s with %3$s", + "gamerule.minecartMaxSpeed": "Minecart max speed", + "gamerule.minecartMaxSpeed.description": "Maximum default speed of a moving Minecart on land", + "gui.abuseReport.name.comment_box_label": "Please describe why you want to report this name:", + "gui.abuseReport.reason.sexually_inappropriate": "Sexually inappropriate", + "gui.abuseReport.reason.sexually_inappropriate.description": "Skins that are graphic in nature relating to sexual acts, sexual organs, and sexual violence.", + "item.minecraft.bordure_indented_banner_pattern": "Bordure Indented Banner Pattern", + "item.minecraft.bundle.empty.description": "Can hold a mixed stack of items", + "item.minecraft.bundle.full": "Full", + "item.minecraft.creeper_banner_pattern.new": "Creeper Charge Banner Pattern", + "item.minecraft.field_masoned_banner_pattern": "Field Masoned Banner Pattern", + "item.minecraft.flow_banner_pattern.new": "Flow Banner Pattern", + "item.minecraft.flower_banner_pattern.new": "Flower Charge Banner Pattern", + "item.minecraft.globe_banner_pattern.new": "Globe Banner Pattern", + "item.minecraft.guster_banner_pattern.new": "Guster Banner Pattern", + "item.minecraft.mojang_banner_pattern.new": "Thing Banner Pattern", + "item.minecraft.piglin_banner_pattern.new": "Snout Banner Pattern", + "item.minecraft.skull_banner_pattern.new": "Skull Charge Banner Pattern", + "optimizeWorld.confirm.proceed": "Create Backup and Optimize", + "options.inactivityFpsLimit": "Reduce FPS when", + "options.inactivityFpsLimit.afk": "AFK", + "options.inactivityFpsLimit.afk.tooltip": "Limits framerate to 30 when the game is not getting any player input for more than a minute. Further limits it to 10 after 9 more minutes.", + "options.inactivityFpsLimit.minimized": "Minimized", + "options.inactivityFpsLimit.minimized.tooltip": "Limits framerate only when the game window is minimized.", + "options.rotateWithMinecart": "Rotate with Minecarts", + "options.rotateWithMinecart.tooltip": "If the player's view should rotate with a turning Minecart. Only available in worlds with the 'Minecart Improvements' experimental setting turned on.", + "subtitles.item.bundle.insert_fail": "Bundle full" + }, "1.21": { "argument.entity.selector.nearestEntity": "Nearest entity", "attribute.name.generic.burning_time": "Burning Time", @@ -4691,4 +4728,4 @@ "entity.MinecartChest.name": "Minecart with Chest", "attribute.name.generic.armorToughness": "Armor Toughness" } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index c00f23c5..a9e4f680 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ projectVersion=5.1.0-SNAPSHOT # Smile emoji -mcVersions=1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 -mcVersionRange=1.10-1.21.1 +mcVersions=1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 +mcVersionRange=1.10-1.21.2 velocityVersion=3.3 From ff94019b08cc4e0bd35366025169716b18782e11 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 21 Aug 2024 19:07:14 +0200 Subject: [PATCH 23/70] Actually track inventory state id --- .../protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java | 2 ++ .../rewriter/BlockItemPacketRewriter1_21_2.java | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 856bc3f0..4ca0d38e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.BlockItemPacketRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; @@ -108,6 +109,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { updateContainerId(wrapper); - wrapper.passthrough(Types.VAR_INT); // State id - Item[] items = wrapper.read(itemArrayType()); + + final int stateId = wrapper.passthrough(Types.VAR_INT); + wrapper.user().get(InventoryStateIdStorage.class).setStateId(stateId); + + final Item[] items = wrapper.read(itemArrayType()); wrapper.write(mappedItemArrayType(), items); for (int i = 0; i < items.length; i++) { items[i] = handleItemToClient(wrapper.user(), items[i]); @@ -101,7 +104,10 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem }); protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_SLOT, wrapper -> { updateContainerId(wrapper); - wrapper.passthrough(Types.VAR_INT); // State id + + final int stateId = wrapper.passthrough(Types.VAR_INT); + wrapper.user().get(InventoryStateIdStorage.class).setStateId(stateId); + wrapper.passthrough(Types.SHORT); // Slot id passthroughClientboundItem(wrapper); }); From 4bcc213f1b69793d998db3d0b87951786e20bfd3 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 25 Aug 2024 12:03:56 +0200 Subject: [PATCH 24/70] Handle item tags in recipe ingredients --- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 12 +++- .../BlockItemPacketRewriter1_21_2.java | 15 ++++- .../v1_21_2to1_21/storage/ItemTagStorage.java | 56 +++++++++++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/ItemTagStorage.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 4ca0d38e..2b8ae84b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -24,6 +24,7 @@ import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.BlockItemPacketRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; @@ -65,8 +66,8 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol soundRewriter = new SoundRewriter<>(this); soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND); @@ -94,6 +95,12 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol protocol.getMappingData().getNewItemId(id)); if (ingredient.hasTagKey()) { - // TODO - return new Item[]{new StructuredItem(1, 1)}; + final ItemTagStorage tagStorage = wrapper.user().get(ItemTagStorage.class); + final int[] tagEntries = tagStorage.itemTag(ingredient.tagKey()); + if (tagEntries == null || tagEntries.length == 0) { + // Most cannot be empty; add a dummy ingredient, though this would only come from bad data + return new Item[]{new StructuredItem(1, 1)}; + } + + final Item[] items = new Item[tagEntries.length]; + for (int i = 0; i < tagEntries.length; i++) { + items[i] = new StructuredItem(tagEntries[i], 1); + } + return items; } final int[] ids = ingredient.ids(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/ItemTagStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/ItemTagStorage.java new file mode 100644 index 00000000..fcc6de84 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/ItemTagStorage.java @@ -0,0 +1,56 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.util.Key; +import java.util.HashMap; +import java.util.Map; +import org.checkerframework.checker.nullness.qual.Nullable; + +public final class ItemTagStorage implements StorableObject { + + private Map itemTags = new HashMap<>(); + + public int @Nullable [] itemTag(final String key) { + return itemTags.get(Key.stripMinecraftNamespace(key)); + } + + public void readItemTags(final PacketWrapper wrapper) { + final int length = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < length; i++) { + final String registryKey = wrapper.passthrough(Types.STRING); + final int tagsSize = wrapper.passthrough(Types.VAR_INT); + + final boolean itemRegistry = Key.stripMinecraftNamespace(registryKey).equals("item"); + if (itemRegistry) { + this.itemTags = new HashMap<>(tagsSize); + } + + for (int j = 0; j < tagsSize; j++) { + final String key = wrapper.passthrough(Types.STRING); + final int[] ids = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE); + if (itemRegistry) { + this.itemTags.put(Key.stripMinecraftNamespace(key), ids); + } + } + } + } +} From 6b690a02183b8d03919fdcbedb93157224da39b7 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 28 Aug 2024 16:08:11 +0200 Subject: [PATCH 25/70] Remove baby entity data from changed water animals --- .../protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java | 2 +- .../v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 2b8ae84b..7089b55e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -96,7 +96,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol Date: Fri, 30 Aug 2024 14:32:12 +0200 Subject: [PATCH 26/70] Handle item hover events --- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 4 +- .../rewriter/ComponentRewriter1_21_2.java | 73 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 7089b55e..e1ef7871 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -22,6 +22,7 @@ import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.BlockItemPacketRewriter1_21_2; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.ComponentRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; @@ -44,7 +45,6 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; import com.viaversion.viaversion.rewriter.AttributeRewriter; -import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -55,7 +55,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); + private final TranslatableRewriter translatableRewriter = new ComponentRewriter1_21_2(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_21_2To1_21() { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java new file mode 100644 index 00000000..08a1b2d3 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java @@ -0,0 +1,73 @@ +/* + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; + +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.util.SerializerVersion; +import com.viaversion.viaversion.util.TagUtil; + +public final class ComponentRewriter1_21_2 extends TranslatableRewriter { + + public ComponentRewriter1_21_2(final Protocol1_21_2To1_21 protocol) { + super(protocol, ReadType.NBT); + } + + @Override + protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, final CompoundTag componentsTag) { + super.handleShowItem(connection, itemTag, componentsTag); + if (componentsTag == null) { + return; + } + + // TODO attribute types + + final CompoundTag instrument = TagUtil.getNamespacedCompoundTag(componentsTag, "instrument"); + if (instrument != null) { + instrument.remove("description"); + } + + final CompoundTag useRemainder = TagUtil.getNamespacedCompoundTag(componentsTag, "use_remainder"); + final CompoundTag food = TagUtil.getNamespacedCompoundTag(componentsTag, "food"); + if (food != null) { + if (useRemainder != null) { + food.put("using_converts_to", useRemainder); + } + food.putFloat("eat_seconds", 1.6F); + } + + TagUtil.removeNamespaced(componentsTag, "repairable"); + TagUtil.removeNamespaced(componentsTag, "enchantable"); + TagUtil.removeNamespaced(componentsTag, "consumable"); + TagUtil.removeNamespaced(componentsTag, "use_remainder"); + TagUtil.removeNamespaced(componentsTag, "use_cooldown"); + } + + @Override + protected SerializerVersion inputSerializerVersion() { + return SerializerVersion.V1_20_5; + } + + @Override + protected SerializerVersion outputSerializerVersion() { + return SerializerVersion.V1_20_5; + } +} From be28d0c3e8c8af592c0d727e760a81082f379e89 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 4 Sep 2024 18:01:28 +0200 Subject: [PATCH 27/70] 24w36a, mostly --- .../rewriter/ComponentRewriter1_21_2.java | 4 + .../rewriter/EntityPacketRewriter1_21_2.java | 92 +++++++++++++++++- .../data/mappings-1.21.2to1.21.nbt | Bin 937 -> 993 bytes 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java index 08a1b2d3..cd4ce9ed 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java @@ -59,6 +59,10 @@ public final class ComponentRewriter1_21_2 extends TranslatableRewriter { + protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_POSITION, wrapper -> { + final int teleportId = wrapper.read(Types.VAR_INT); + + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + + double movementX = wrapper.read(Types.DOUBLE); + double movementY = wrapper.read(Types.DOUBLE); + double movementZ = wrapper.read(Types.DOUBLE); + + // Unpack y and x rot + final byte yaw = wrapper.read(Types.BYTE); + final byte pitch = wrapper.read(Types.BYTE); + wrapper.write(Types.FLOAT, yaw * 360F / 256F); + wrapper.write(Types.FLOAT, pitch * 360F / 256F); + + // Just keep the new values in there + final int relativeArguments = wrapper.read(Types.INT); + wrapper.write(Types.BYTE, (byte) relativeArguments); + wrapper.write(Types.VAR_INT, teleportId); + + if (true) { + return; // TODO + } + + // Send alongside separate entity motion + wrapper.send(Protocol1_21_2To1_21.class); + wrapper.cancel(); + + if ((relativeArguments & 1 << 4) != 0) { + // Rotate delta + } + + // Delta x, y, z + if ((relativeArguments & 1 << 5) != 0) { + //movementX += currentMovementX; + } + if ((relativeArguments & 1 << 6) != 0) { + //movementY += currentMovementY; + } + if ((relativeArguments & 1 << 7) != 0) { + //movementZ += currentMovementZ; + } + + final PacketWrapper entityMotionPacket = wrapper.create(ClientboundPackets1_21_2.MOVE_ENTITY_POS); + entityMotionPacket.write(Types.VAR_INT, tracker(wrapper.user()).clientEntityId()); + entityMotionPacket.write(Types.SHORT, (short) (movementX * 8000)); + entityMotionPacket.write(Types.SHORT, (short) (movementY * 8000)); + entityMotionPacket.write(Types.SHORT, (short) (movementZ * 8000)); + entityMotionPacket.send(Protocol1_21_2To1_21.class); + }); + + // Now also sent by the player if not in a vehicle, but we can't emulate that here, and otherwise only used in predicates + protocol.registerServerbound(ServerboundPackets1_20_5.PLAYER_INPUT, wrapper -> { + final float sideways = wrapper.read(Types.FLOAT); + final float forward = wrapper.read(Types.FLOAT); + final byte flags = wrapper.read(Types.BYTE); + + byte updatedFlags = 0; + if (forward < 0) { + updatedFlags |= 1; + } else if (forward > 0) { + updatedFlags |= 1 << 1; + } + + if (sideways < 0) { + updatedFlags |= 1 << 2; + } else if (sideways > 0) { + updatedFlags |= 1 << 3; + } + + if ((flags & 1) != 0) { + updatedFlags |= 1 << 4; + } + if ((flags & 2) != 0) { + updatedFlags |= 1 << 5; + } + + // Sprinting we don't know... + + wrapper.write(Types.BYTE, updatedFlags); + }); + + protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS, wrapper -> { wrapper.passthrough(Types.DOUBLE); // X wrapper.passthrough(Types.DOUBLE); // Y wrapper.passthrough(Types.DOUBLE); // Z fixOnGround(wrapper); }); - protocol.appendServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> { + protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> { wrapper.passthrough(Types.DOUBLE); // X wrapper.passthrough(Types.DOUBLE); // Y wrapper.passthrough(Types.DOUBLE); // Z @@ -114,12 +198,12 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> { wrapper.passthrough(Types.FLOAT); // Yaw wrapper.passthrough(Types.FLOAT); // Pitch fixOnGround(wrapper); }); - protocol.appendServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, this::fixOnGround); + protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, this::fixOnGround); protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE, wrapper -> { final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM); diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt index fbb9c28bbd954e09ff8a5836f3a198697a978217..1d91b1d8ba45c37ae43c4a29068500c30e2939c4 100644 GIT binary patch delta 160 zcmZ3<{*ZmbPkVoE2ByRk1_lOpAbtSE4;dJkvVgdVfq_*3h(&-{6sV{qAEf9%5I_`y z6%}vRV02}4cY+zh15yLT96&4v#Nt3K0mPC(EDgjmKr9QyazHE(#0oHjc|ZnFp1~x; K0%ojX`U?P){T^%p delta 127 zcmaFJzLI^yPyIk{2ByRk1_lOJAbtSE4}nY}AQl5+aiC;LK1lLE5P%eHwqSH+w6}w4 mVh4(e0x?iAgE$aN0I?JhO9QbCOfx%3GYkMFL?=IC`U?POfgd6O From d0eeae92d3a3e971a0a63066d767f3457827b0e3 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 5 Sep 2024 09:34:37 +0200 Subject: [PATCH 28/70] 24w37a --- .../rewriter/ComponentRewriter1_21_2.java | 7 ++----- .../rewriter/EntityPacketRewriter1_21_2.java | 11 +++++------ .../data/mappings-1.21.2to1.21.nbt | Bin 993 -> 1009 bytes 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java index cd4ce9ed..f981716b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java @@ -63,15 +63,12 @@ public final class ComponentRewriter1_21_2 extends TranslatableRewriter~*2?GNI9}u$xF~{W7j0%%iGx6{OIf_8pl6;Wt~*2?GNI4-m5hF$WNf0kJp`O8~JX5K9BG3=qo#u^bS~1F-^7 aV@W=c!Sf#ofHXUZh5;a7bn^=)PDTJ&b{J>? From f2fcc9d02f9440baedeb4956c1702b17e77d85bb Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 18 Sep 2024 16:34:34 +0200 Subject: [PATCH 29/70] 24w38a --- .../v1_16to1_15_2/Protocol1_16To1_15_2.java | 2 +- .../v1_19to1_18_2/Protocol1_19To1_18_2.java | 2 +- .../v1_20_2to1_20/Protocol1_20_2To1_20.java | 2 +- .../Protocol1_20_5To1_20_3.java | 2 +- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 16 ++++++++++++++++ .../BlockItemPacketRewriter1_21_2.java | 13 +++++++++++++ .../data/mappings-1.21.2to1.21.nbt | Bin 1009 -> 1145 bytes 7 files changed, 33 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java index 97336dbe..136bf0fe 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java @@ -116,7 +116,7 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol { + registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> { // Transform uuid to plain string UUID uuid = wrapper.read(Types.UUID); wrapper.write(Types.STRING, uuid.toString()); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/Protocol1_19To1_18_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/Protocol1_19To1_18_2.java index dcdafec9..72fa8864 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/Protocol1_19To1_18_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/Protocol1_19To1_18_2.java @@ -291,7 +291,7 @@ public final class Protocol1_19To1_18_2 extends BackwardsProtocol { + registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> { // We can't set the internal state to configuration here as protocols down the line will expect the state to be play // Add this *before* sending the ack since the server might immediately answer wrapper.user().put(new ConfigurationPacketStorage()); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/Protocol1_20_5To1_20_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/Protocol1_20_5To1_20_3.java index 285a17f4..8b15675c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/Protocol1_20_5To1_20_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/Protocol1_20_5To1_20_3.java @@ -157,7 +157,7 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol { + registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> { wrapper.passthrough(Types.UUID); // UUID wrapper.passthrough(Types.STRING); // Name diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index e1ef7871..92dfd66d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -29,10 +29,12 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.data.entity.EntityTrackerBase; +import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; @@ -93,6 +95,20 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { + wrapper.passthrough(Types.UUID); // UUID + wrapper.passthrough(Types.STRING); // Name + + final int properties = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < properties; i++) { + wrapper.passthrough(Types.STRING); // Name + wrapper.passthrough(Types.STRING); // Value + wrapper.passthrough(Types.OPTIONAL_STRING); // Signature + } + + wrapper.write(Types.BOOLEAN, true); // Strict error handling. Always enabled for newer clients, so mimic that behavior + }); } private void storeTags(final PacketWrapper wrapper) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index d848dc27..60145e58 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -245,6 +245,19 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem } return items; } + + @Override + public void handleRecipeType(final PacketWrapper wrapper, final String type) { + if (type.equals("crafting_transmute")) { + wrapper.read(Types.STRING); // Group + wrapper.read(Types.VAR_INT); // Crafting book category + wrapper.read(Types.HOLDER_SET); // Input + wrapper.read(Types.HOLDER_SET); // Material + wrapper.read(Types.VAR_INT); // Result item ID + } else { + super.handleRecipeType(wrapper, type); + } + } }.register1_20_5(ClientboundPackets1_21_2.UPDATE_RECIPES); } diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt index 19f807f36f95caa9a578cabae88bcd6fdb4672fb..5510154e6f8198dc39332f8d11dcda1d29067bcc 100644 GIT binary patch delta 235 zcmbu&ISztg6h-03FQ|#yQm`8m5_f>LwFM2mmAz{qj1CM^xB*xYl~Um$gcbObuY0+t zTlMSf>Ac^FI{G4Fi7X5(5h6m21SvAyaK{5r Date: Sat, 21 Sep 2024 12:47:40 +0200 Subject: [PATCH 30/70] Convert attributes in item hover event --- .../v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java | 2 +- .../v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 60145e58..6c8b8614 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -156,7 +156,7 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem wrapper.passthrough(Types.DOUBLE); // Center Y wrapper.passthrough(Types.DOUBLE); // Center Z - // TODO + // The server will already send block changes separately wrapper.write(Types.FLOAT, 0F); // Power wrapper.write(Types.VAR_INT, 0); // No blocks affected diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java index f981716b..e97a0c54 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java @@ -38,7 +38,7 @@ public final class ComponentRewriter1_21_2 extends TranslatableRewriter Date: Wed, 25 Sep 2024 18:11:09 +0200 Subject: [PATCH 31/70] 24w39a --- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 15 +++ .../rewriter/EntityPacketRewriter1_21_2.java | 103 ++++++++++++++++-- .../data/mappings-1.21.2to1.21.nbt | Bin 1145 -> 1513 bytes 3 files changed, 110 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 92dfd66d..27285a85 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -109,6 +109,21 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { + wrapper.passthrough(Types.LONG); // Game time + + long dayTime = wrapper.read(Types.LONG); + final boolean daylightCycle = wrapper.read(Types.BOOLEAN); + if (!daylightCycle) { + if (dayTime == 0) { + dayTime = -1; + } else { + dayTime = -dayTime; + } + } + wrapper.write(Types.LONG, dayTime); + }); } private void storeTags(final PacketWrapper wrapper) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 4994bb01..363f3bfb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -22,7 +22,8 @@ import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2; +import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; @@ -30,10 +31,13 @@ import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.api.type.types.version.Types1_21_2; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; import com.viaversion.viaversion.util.Key; +import java.util.ArrayList; import java.util.BitSet; +import java.util.List; import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.EntityPacketRewriter1_21_2.updateEnchantmentAttributes; @@ -45,9 +49,37 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + final int entityId = wrapper.passthrough(Types.VAR_INT); + wrapper.passthrough(Types.UUID); // Entity UUID + final int entityTypeId = wrapper.passthrough(Types.VAR_INT); + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + wrapper.passthrough(Types.BYTE); // Pitch + wrapper.passthrough(Types.BYTE); // Yaw + wrapper.passthrough(Types.BYTE); // Head yaw + wrapper.passthrough(Types.VAR_INT); // Data + getSpawnTrackerWithDataHandler1_19(EntityTypes1_21_2.FALLING_BLOCK).handle(wrapper); + + final EntityType type = EntityTypes1_21_2.getTypeFromId(entityTypeId); + if (type.isOrHasParent(EntityTypes1_21_2.ABSTRACT_BOAT)) { + wrapper.send(Protocol1_21_2To1_21.class); + wrapper.cancel(); + + // Add boat type to entity data + final List data = new ArrayList<>(); + final int boatType = type.isOrHasParent(EntityTypes1_21_2.ABSTRACT_CHEST_BOAT) ? chestBoatTypeFromEntityType(type) : boatTypeFromEntityType(type); + data.add(new EntityData(11, Types1_21.ENTITY_DATA_TYPES.varIntType, boatType)); + + final PacketWrapper entityDataPacket = wrapper.create(ClientboundPackets1_21.SET_ENTITY_DATA); + entityDataPacket.write(Types.VAR_INT, entityId); + entityDataPacket.write(Types1_21.ENTITY_DATA_LIST, data); + entityDataPacket.send(Protocol1_21_2To1_21.class); + } + }); protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> { final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); @@ -152,6 +184,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { final float sideways = wrapper.read(Types.FLOAT); final float forward = wrapper.read(Types.FLOAT); @@ -245,6 +278,54 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriterQve%xXlyp|2;PC7ghOxv zF2ND(_`b+SCi(2V`SUWr>~FA(RvVoKX6CH3CiPV~jg!Po2KLJ+rM|WD>_q#jkp6A_ zM9PaDCk@EZ@DQMg5G9mR!6~XZ$0e>%gY-AiLUzlijXOM`k4HS?1+N(34MU9Zjv3}i zkV1kjNa$o!UXV0rkRh|IPY$!JC3U2-|BHFU1qXFVT#0>+4sMX&=^oX+qgs;R;|Vc7 WFh<^IsKVH}Pdi>X`RD7cUV3}N>?NcC delta 12 TcmaFK{gY$EamLN&%$t}1CNu>P From 49febd1e63886cf84b2d010df3906d3a37640375 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 26 Sep 2024 18:08:15 +0200 Subject: [PATCH 32/70] Fix vehicle exiting --- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 2 ++ .../rewriter/EntityPacketRewriter1_21_2.java | 34 ++++++++++++++++--- .../storage/SneakingStorage.java | 34 +++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 27285a85..678bd123 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -26,6 +26,7 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.ComponentRewr import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; @@ -149,6 +150,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { + wrapper.passthrough(Types.VAR_INT); + final int action = wrapper.passthrough(Types.VAR_INT); + if (action == 0) { + wrapper.user().get(SneakingStorage.class).setPlayerCommandTrackedSneaking(true); + } else if (action == 1) { + wrapper.user().get(SneakingStorage.class).setPlayerCommandTrackedSneaking(false); + } + }); + // Now also sent by the player if not in a vehicle, but we can't emulate that here, and otherwise only used in predicates - // TODO Why leaving vehicle no worky protocol.registerServerbound(ServerboundPackets1_20_5.PLAYER_INPUT, wrapper -> { final float sideways = wrapper.read(Types.FLOAT); final float forward = wrapper.read(Types.FLOAT); final byte flags = wrapper.read(Types.BYTE); byte updatedFlags = 0; - if (forward < 0) { + if (forward > 0) { updatedFlags |= 1; - } else if (forward > 0) { + } else if (forward < 0) { updatedFlags |= 1 << 1; } @@ -203,16 +214,29 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java new file mode 100644 index 00000000..2ab7cd9a --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java @@ -0,0 +1,34 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; + +public final class SneakingStorage implements StorableObject { + private boolean playerCommandTrackedSneaking; + + public void setPlayerCommandTrackedSneaking(final boolean playerCommandTrackedSneaking) { + this.playerCommandTrackedSneaking = playerCommandTrackedSneaking; + } + + public boolean setSneaking(final boolean sneaking) { + final boolean changed = this.playerCommandTrackedSneaking != sneaking; + this.playerCommandTrackedSneaking = sneaking; + return changed; + } +} From d3be34adc99fbe10fce8b09e824921dd281a4f36 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 2 Oct 2024 21:42:52 +0200 Subject: [PATCH 33/70] Very WIP 24w40a --- .../BlockItemPacketRewriter1_21_2.java | 112 +++++------------- .../rewriter/EntityPacketRewriter1_21_2.java | 73 ++++++++++-- .../data/mappings-1.21.2to1.21.nbt | Bin 1513 -> 6318 bytes 3 files changed, 90 insertions(+), 95 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 6c8b8614..dc631302 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -20,13 +20,10 @@ package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; -import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.data.MappingData; -import com.viaversion.viaversion.api.minecraft.HolderSet; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.item.Item; -import com.viaversion.viaversion.api.minecraft.item.StructuredItem; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; @@ -37,7 +34,6 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPac import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; -import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.RecipeRewriter1_21_2; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter; @@ -116,9 +112,7 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_CLOSE, this::updateContainerId); protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_DATA, this::updateContainerId); protocol.registerClientbound(ClientboundPackets1_21_2.HORSE_SCREEN_OPEN, this::updateContainerId); - protocol.registerClientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, this::updateContainerId); protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLOSE, this::updateContainerIdServerbound); - protocol.registerServerbound(ServerboundPackets1_20_5.PLACE_RECIPE, this::updateContainerIdServerbound); protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLICK, wrapper -> { updateContainerIdServerbound(wrapper); wrapper.passthrough(Types.VAR_INT); // State id @@ -183,82 +177,36 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem new SoundRewriter<>(protocol).soundHolderHandler().handle(wrapper); }); - new RecipeRewriter1_21_2<>(protocol) { - @Override - protected void handleIngredient(final PacketWrapper wrapper) { - wrapper.write(mappedItemArrayType(), ingredient(wrapper)); - } - - @Override - public void handleCraftingShaped(final PacketWrapper wrapper) { - wrapper.passthrough(Types.STRING); // Group - wrapper.passthrough(Types.VAR_INT); // Crafting book category - wrapper.passthrough(Types.VAR_INT); // Width - wrapper.passthrough(Types.VAR_INT); // Height - - final int ingredients = wrapper.read(Types.VAR_INT); - for (int i = 0; i < ingredients; i++) { - wrapper.write(mappedItemArrayType(), ingredient(wrapper)); - } - - wrapper.write(mappedItemType(), rewrite(wrapper.user(), wrapper.read(itemType()))); // Result - wrapper.passthrough(Types.BOOLEAN); // Show notification - } - - @Override - public void handleCraftingShapeless(final PacketWrapper wrapper) { - wrapper.passthrough(Types.STRING); // Group - wrapper.passthrough(Types.VAR_INT); // Crafting book category - - // Move below - final Item result = rewrite(wrapper.user(), wrapper.read(itemType())); - - final int ingredients = wrapper.passthrough(Types.VAR_INT); - for (int i = 0; i < ingredients; i++) { - wrapper.write(mappedItemArrayType(), ingredient(wrapper)); - } - - wrapper.write(mappedItemType(), result); - } - - private Item[] ingredient(final PacketWrapper wrapper) { - final HolderSet ingredient = wrapper.read(Types.HOLDER_SET).rewrite(id -> protocol.getMappingData().getNewItemId(id)); - if (ingredient.hasTagKey()) { - final ItemTagStorage tagStorage = wrapper.user().get(ItemTagStorage.class); - final int[] tagEntries = tagStorage.itemTag(ingredient.tagKey()); - if (tagEntries == null || tagEntries.length == 0) { - // Most cannot be empty; add a dummy ingredient, though this would only come from bad data - return new Item[]{new StructuredItem(1, 1)}; - } - - final Item[] items = new Item[tagEntries.length]; - for (int i = 0; i < tagEntries.length; i++) { - items[i] = new StructuredItem(tagEntries[i], 1); - } - return items; - } - - final int[] ids = ingredient.ids(); - final Item[] items = new Item[ids.length]; - for (int i = 0; i < ids.length; i++) { - items[i] = new StructuredItem(ids[i], 1); - } - return items; - } - - @Override - public void handleRecipeType(final PacketWrapper wrapper, final String type) { - if (type.equals("crafting_transmute")) { - wrapper.read(Types.STRING); // Group - wrapper.read(Types.VAR_INT); // Crafting book category - wrapper.read(Types.HOLDER_SET); // Input - wrapper.read(Types.HOLDER_SET); // Material - wrapper.read(Types.VAR_INT); // Result item ID - } else { - super.handleRecipeType(wrapper, type); - } - } - }.register1_20_5(ClientboundPackets1_21_2.UPDATE_RECIPES); + protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_ADD, null, wrapper -> { + // TODO + wrapper.cancel(); + }); + protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_REMOVE, null, wrapper -> { + // TODO + wrapper.cancel(); + }); + protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_SETTINGS, null, wrapper -> { + // TODO + wrapper.cancel(); + }); + protocol.registerClientbound(ClientboundPackets1_21_2.UPDATE_RECIPES, wrapper -> { + wrapper.cancel(); // TODO + }); + protocol.registerClientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, wrapper -> { + this.updateContainerId(wrapper); + final int recipeDisplay = wrapper.read(Types.VAR_INT); + wrapper.cancel(); // TODO + }); + protocol.registerServerbound(ServerboundPackets1_20_5.PLACE_RECIPE, wrapper -> { + this.updateContainerIdServerbound(wrapper); + final int recipeDisplayId = wrapper.read(Types.VAR_INT); + wrapper.cancel(); // TODO + }); + protocol.registerServerbound(ServerboundPackets1_20_5.RECIPE_BOOK_SEEN_RECIPE, wrapper -> { + this.updateContainerIdServerbound(wrapper); + final int recipeDisplayId = wrapper.read(Types.VAR_INT); + wrapper.cancel(); // TODO + }); } private void updateContainerId(final PacketWrapper wrapper) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index f92c589b..3fc6294a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -21,7 +21,6 @@ import com.viaversion.nbt.tag.Tag; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; -import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; @@ -36,13 +35,11 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; -import com.viaversion.viaversion.util.Key; +import com.viaversion.viaversion.rewriter.RegistryDataRewriter; import java.util.ArrayList; import java.util.BitSet; import java.util.List; -import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.EntityPacketRewriter1_21_2.updateEnchantmentAttributes; - public final class EntityPacketRewriter1_21_2 extends EntityRewriter { public EntityPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) { @@ -83,15 +80,9 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { - final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); - final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY); - if (registryKey.equals("enchantment")) { - updateEnchantmentAttributes(entries, protocol.getMappingData().getAttributeMappings()); - } - - handleRegistryData1_20_5(wrapper.user(), registryKey, entries); - }); + final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol); + registryDataRewriter.addEnchantmentEffectRewriter("change_item_damage", tag -> tag.putString("type", "damage_item")); + protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle); protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, new PacketHandlers() { @Override @@ -135,6 +126,42 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + wrapper.passthrough(Types.VAR_INT); // Entity ID + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + + // Unused + wrapper.read(Types.DOUBLE); // Delta movement X + wrapper.read(Types.DOUBLE); // Delta movement Y + wrapper.read(Types.DOUBLE); // Delta movement Z + + updateRotation(wrapper); + }); + + protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_ROTATION, ClientboundPackets1_21.PLAYER_POSITION, wrapper -> { + // TODO Send PLAYER_LOOK_AT via currently tracked location + wrapper.cancel(); + }); + + protocol.registerClientbound(ClientboundPackets1_21_2.TELEPORT_ENTITY, wrapper -> { + wrapper.passthrough(Types.VAR_INT); // Entity ID + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + + double movementX = wrapper.read(Types.DOUBLE); + double movementY = wrapper.read(Types.DOUBLE); + double movementZ = wrapper.read(Types.DOUBLE); + + // Pack y and x rot + updateRotation(wrapper); + + final int relativeArguments = wrapper.read(Types.VAR_INT); + // TODO Similar to player position + }); + protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_POSITION, wrapper -> { final int teleportId = wrapper.read(Types.VAR_INT); @@ -302,6 +329,14 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + if (event.index() > 7) { + event.cancel(); + } + }); + filter().type(EntityTypes1_21_2.ABSTRACT_BOAT).addIndex(11); // Boat type filter().type(EntityTypes1_21_2.SALMON).removeIndex(17); // Data type filter().type(EntityTypes1_21_2.DOLPHIN).removeIndex(16); // Baby @@ -384,5 +428,8 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter*=1I>Dl-X|L_M> zeDY@c^}BxWn4YCxBqTE@bgO9Ob0QL`mxhr{K6SKcYqnktNqtr;6!i3vajh;gwjm%v zBOM4yxaeFkzt$i@&8FZl(TaJPkJVU<`*8|S;TfF8zi5Z|ffq#@sI}n;Mq$8223gRd z#xo*KL6JGj5ff>CO{8TLO-7w*RU@P2#%AH;`n4?c{0@e$mIkK$waI6i^<@ku;@Q}`4f#HaBYJcNhw zSv-Qz;q&+c9>o`N8js;|dE~=NCa;+Rw9tu`U(*zm-paMMAF;8{6Io2) z7azwj*kCN8_I|oSAXhWU)!!9ab1DAJCL>)-8q2Z4PK#&_|9$iIW(3{<5nwHDb=1p@ z(pQ}C+bz7z_w5$m;C;KTVdFHT1!@yUu^7GJWR?MJ!G3UJ3a6qR#*_Fu*hKPUJda=D z6`aAJz-Ezu<3DWN4#dGp7huB$*x-Tt@FHFk33j0ydohTE;A9SJV6%qlOPI|aUhkbA zYrMeIK(l&J+U}-3Zo1h`_qpjIH+|eqpLNsc-1K=jJ>#aYmeRmdH_f=|NjLpTDGe@h z(~WMr)lK)P)O$(2)ETy(^*?&l_4p>IZrGcg?Tl$P)FkynO$aBGaKsD8wQyVur<8CM zi#i!O;hfV^orrGW6Jl1K$KEb%_3ip2jnv{t)$tIQc`IuA%SY`}hHV2o_X` z1r?@`;n}zVY2?7SM);>-(S%>}7J>@Wa;QLcfv1zqf==3tIz)EjM zy>0xmw{>1`N(XEjH&Ik|5wWwSG|U4)h_flgcBpG4TIV|lsGhS8+o<`KAZvUO0}D?_RGywdK_-097{u6Z-13@fK3Hv9Lvi?cto;ZKMmK zCT|gYhu+itAXAiT13d9Mbb2BQYG6q~RT-aVTu-fyXRuLiae zJKcI!o4cUlFh=0jq4Vy%f@ax9DpNb*S^os(y$K3YM-1zb^9CPs8;m(AQ?J>!WsHp1 z{@|2FPR)cNG@)gvBMS8jKux%+KMal!CwAo^I0thHP$A~K{Hy=3Kd%w zQ_gJXXDqu<*nP6l?Q%PDXtMN_QP78rx@Bk?eg|9rV?)~f0crIDqB`w#$P0$I17=b4 zoU~?Z!>N3>kk7FhhV99M?t4g)K7Z8%Ue#)$d*lDVW8uE44d8WUmOIFqDy@7`ptbUI z<$Lnl)Z$QI+Bq$&7b85PbV+MG*2#a-K`o<4_i9I@gBdM%RAu%gq|Ki>q!ltoZZsmH zcz1`)@n`SOJ6SzFvcSz6V!^1tOH9@8-jhhk!gJnpAfHdGHj+tc_P62X_4d{FeYdVn zsDXt#=|WZK_vDMk=zwMwblb^J$lS_`cWAj$#uZh!Ir+)z%AMl<>hCQoH_=zyt)YxI zLS9$ALt5OL2P|DXs%qV#vmsSx*HmUX-rMwCN++|sW17hrvNgj}JxX@;RQE_tRsXnc z=W{BzGcN6w<8da^(u>7$OII^$s}_=7-L?JRlFwTzkAPK0MAdM)r4`a{ezHgA`&)3j z9^GE5y|<&cw)XzKrUu^I(N|k~U`#LCQTL9%cu#HVA!AgHuCFs$UQgw)c{AqSL;tR&Y`3(@%A77=PyG4a<&p!FTCTEWMO??N z0-L;|y+pZ`Z)AyNIhy@e{#aFoz2&U!mabQ2^+}^U=F8afQw=4j&WiqwmYN!KI3Dlp zmU(WW@`f2IXtcR?l+z^44c)TTy?2DDsGw>VmCTeny#>fRn%?%vy< zx6*3)@64r{*P7co3mcpVnMwCFjHKNCDiNnAL49Q@Rw9rs^AyXqk*$PwQ%-QFZ|a!Fj|0Y4 z3b_}L;W2fTyOT@yylJzYDOH`BHdoE$Ig5^sTTbru?Uv^EoQ1vkOy4VmVH9$mkiGt@;~h9ypI3? delta 425 zcmXxgJ1;|V7{~F)xoDl9Hcp}o31VoZB2j`xVpEA!2e;WE!GLHDES(HYc;14#6vw3l zi^NdxgT*B=SupWEn)4)|;h+5ST>gIMJ+?RKnx Date: Sun, 6 Oct 2024 13:40:49 +0200 Subject: [PATCH 34/70] Start working on recipes --- .../template/BlockItemPacketRewriter1_99.java | 7 +- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 2 + .../BlockItemPacketRewriter1_21_2.java | 41 +- .../v1_21_2to1_21/storage/RecipeStorage.java | 406 ++++++++++++++++++ 4 files changed, 445 insertions(+), 11 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java index b9c27c8a..acf3390c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java @@ -24,8 +24,8 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; -import com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.RecipeRewriter1_21_2; import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter; // To replace if needed: // ChunkType1_20_2 @@ -66,6 +66,9 @@ final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter< registerContainerClick1_21_2(ServerboundPackets1_21_2.CONTAINER_CLICK); registerSetCreativeModeSlot(ServerboundPackets1_21_2.SET_CREATIVE_MODE_SLOT); - new RecipeRewriter1_21_2<>(protocol).register1_20_5(ClientboundPackets1_21_2.UPDATE_RECIPES); + final RecipeDisplayRewriter recipeRewriter = new RecipeDisplayRewriter<>(protocol); + recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_2.UPDATE_RECIPES); + recipeRewriter.registerRecipeBookAdd(ClientboundPackets1_21_2.RECIPE_BOOK_ADD); + recipeRewriter.registerPlaceGhostRecipe(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 678bd123..857c984f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -26,6 +26,7 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.ComponentRewr import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; @@ -151,6 +152,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { - // TODO + final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class); + recipeStorage.clearRecipes(); + + final int size = wrapper.read(Types.VAR_INT); + for (int i = 0; i < size; i++) { + recipeStorage.readRecipe(wrapper); + } + recipeStorage.sendRecipes(wrapper.user()); wrapper.cancel(); }); - protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_REMOVE, null, wrapper -> { - // TODO - wrapper.cancel(); + protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_REMOVE, ClientboundPackets1_21.RECIPE, wrapper -> { + final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class); + final int[] ids = wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE); + recipeStorage.lockRecipes(wrapper, ids); }); protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_SETTINGS, null, wrapper -> { - // TODO + final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class); + final boolean[] settings = new boolean[RecipeStorage.RECIPE_BOOK_SETTINGS]; + for (int i = 0; i < RecipeStorage.RECIPE_BOOK_SETTINGS; i++) { + settings[i] = wrapper.read(Types.BOOLEAN); + } + recipeStorage.setRecipeBookSettings(settings); + wrapper.cancel(); }); protocol.registerClientbound(ClientboundPackets1_21_2.UPDATE_RECIPES, wrapper -> { - wrapper.cancel(); // TODO + // Inputs for furnaces etc., hardcoded in earlier versions + final int size = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < size; i++) { + wrapper.read(Types.STRING); // Recipe group + wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE); // Items + } + + final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class); + recipeStorage.readStoneCutterRecipes(wrapper); + + // Send later with the recipe book init + wrapper.cancel(); }); protocol.registerClientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, wrapper -> { this.updateContainerId(wrapper); - final int recipeDisplay = wrapper.read(Types.VAR_INT); wrapper.cancel(); // TODO }); protocol.registerServerbound(ServerboundPackets1_20_5.PLACE_RECIPE, wrapper -> { this.updateContainerIdServerbound(wrapper); - final int recipeDisplayId = wrapper.read(Types.VAR_INT); wrapper.cancel(); // TODO }); protocol.registerServerbound(ServerboundPackets1_20_5.RECIPE_BOOK_SEEN_RECIPE, wrapper -> { this.updateContainerIdServerbound(wrapper); - final int recipeDisplayId = wrapper.read(Types.VAR_INT); wrapper.cancel(); // TODO }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java new file mode 100644 index 00000000..010cddb3 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java @@ -0,0 +1,406 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage; + +import com.google.common.base.Preconditions; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viaversion.api.connection.StorableObject; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.HolderSet; +import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.minecraft.item.StructuredItem; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import java.util.ArrayList; +import java.util.List; + +public final class RecipeStorage implements StorableObject { + + // Pairs of open + filtering for: Crafting, furnace, blast furnace, smoker + public static final int RECIPE_BOOK_SETTINGS = 4 * 2; + private final List recipes = new ArrayList<>(); + private final List stoneCutterRecipes = new ArrayList<>(); + private boolean[] recipeBookSettings = new boolean[RECIPE_BOOK_SETTINGS]; + private final Protocol1_21_2To1_21 protocol; + private int highestIndex; + + public RecipeStorage(final Protocol1_21_2To1_21 protocol) { + this.protocol = protocol; + } + + abstract static class Recipe { + protected int index; + private Integer group; + private int category; + private boolean locked; + + abstract void write(PacketWrapper wrapper); + + void writeGroup(final PacketWrapper wrapper) { + wrapper.write(Types.STRING, group != null ? Integer.toString(group) : ""); + } + + void writeIngredients(final PacketWrapper wrapper, final Item[][] ingredients) { + wrapper.write(Types.VAR_INT, ingredients.length); + for (final Item[] ingredient : ingredients) { + writeIngredient(wrapper, ingredient); + } + } + + void writeIngredient(final PacketWrapper wrapper, final Item[] ingredient) { + final Item[] copy = new Item[ingredient.length]; + for (int i = 0; i < ingredient.length; i++) { + copy[i] = ingredient[i].copy(); + } + wrapper.write(Types1_21_2.ITEM_ARRAY, copy); + } + + void writeResult(final PacketWrapper wrapper, final Item result) { + wrapper.write(Types1_21_2.ITEM, result.copy()); + } + + void writeCategory(final PacketWrapper wrapper) { + wrapper.write(Types.VAR_INT, 0); // TODO + } + + int category() { + return category; + } + } + + public void sendRecipes(final UserConnection connection) { + // Add stonecutter recipes from update_recipes + final List recipes = new ArrayList<>(this.recipes); + for (final StoneCutterRecipe recipe : stoneCutterRecipes) { + recipe.index = ++highestIndex; + recipes.add(recipe); + } + + // Since the server only sends unlocked recipes, we need to re-send all recipes in UPDATE_RECIPES + final PacketWrapper updateRecipesPacket = PacketWrapper.create(ClientboundPackets1_21.UPDATE_RECIPES, connection); + updateRecipesPacket.write(Types.VAR_INT, recipes.size()); + for (final Recipe recipe : recipes) { + updateRecipesPacket.write(Types.STRING, Integer.toString(recipe.index)); // Use index as the recipe identifier + recipe.write(updateRecipesPacket); + } + updateRecipesPacket.send(Protocol1_21_2To1_21.class); + + sendUnlockedRecipes(connection, recipes); + } + + public void lockRecipes(final PacketWrapper wrapper, final int[] ids) { + for (final int id : ids) { + recipes.get(id).locked = true; + } + + wrapper.write(Types.VAR_INT, 2); // Remove recipes + for (final boolean recipeBookSetting : recipeBookSettings) { + wrapper.write(Types.BOOLEAN, recipeBookSetting); + } + + final String[] recipeKeys = new String[ids.length]; + for (int i = 0; i < ids.length; i++) { + recipeKeys[i] = Integer.toString(ids[i]); + } + wrapper.write(Types.STRING_ARRAY, recipeKeys); + } + + private void sendUnlockedRecipes(final UserConnection connection, final List recipes) { + // TODO Not working? + final PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_21.RECIPE, connection); + wrapper.write(Types.VAR_INT, 0); // Init recipes + + for (final boolean recipeBookSetting : recipeBookSettings) { + wrapper.write(Types.BOOLEAN, recipeBookSetting); + } + + // Use index as the recipe identifier. We only know the unlocked ones, so send all + final String[] recipeKeys = new String[recipes.size()]; + for (int i = 0; i < recipes.size(); i++) { + recipeKeys[i] = Integer.toString(i); + } + wrapper.write(Types.STRING_ARRAY, recipeKeys); + + wrapper.write(Types.STRING_ARRAY, new String[0]); // Highlights // TODO + wrapper.send(Protocol1_21_2To1_21.class); + } + + public void readRecipe(final PacketWrapper wrapper) { + final int id = wrapper.read(Types.VAR_INT); + final int type = wrapper.passthrough(Types.VAR_INT); + final Recipe recipe = switch (type) { + case 0 -> readShapeless(wrapper); + case 1 -> readShaped(wrapper); + case 2 -> readFurnace(wrapper); + case 3 -> readStoneCutter(wrapper); + case 4 -> readSmithing(wrapper); + default -> null; + }; + + final Integer group = wrapper.read(Types.OPTIONAL_VAR_INT); + final int category = wrapper.read(Types.VAR_INT); + if (wrapper.read(Types.BOOLEAN)) { + final int ingredientsSize = wrapper.read(Types.VAR_INT); + for (int j = 0; j < ingredientsSize; j++) { + //handleIngredient(wrapper); // Items //TODO + wrapper.read(Types.HOLDER_SET); + } + } + final byte flags = wrapper.read(Types.BYTE); + + if (recipe != null) { + recipe.index = id; + recipe.group = group; + recipe.category = category; + } + highestIndex = Math.max(highestIndex, id); + } + + private Recipe readShapeless(final PacketWrapper wrapper) { + final Item[][] ingredients = readSlotDisplayList(wrapper); + final Item result = readSingleSlotDisplay(wrapper); + readSlotDisplay(wrapper); // Crafting station + return add(new ShapelessRecipe(ingredients, result)); + } + + private Recipe readShaped(final PacketWrapper wrapper) { + final int width = wrapper.passthrough(Types.VAR_INT); + final int height = wrapper.passthrough(Types.VAR_INT); + final Item[][] ingredients = readSlotDisplayList(wrapper); + final Item result = readSingleSlotDisplay(wrapper); + readSlotDisplay(wrapper); // Crafting station + return add(new ShapedRecipe(width, height, ingredients, result)); + } + + private Recipe readFurnace(final PacketWrapper wrapper) { + final Item[] ingredient = readSlotDisplay(wrapper); + readSlotDisplay(wrapper); // Fuel + final Item result = readSingleSlotDisplay(wrapper); + readSlotDisplay(wrapper); // Crafting station + return add(new FurnaceRecipe(ingredient, result)); + } + + private Recipe readStoneCutter(final PacketWrapper wrapper) { + // Use values from UPDATE_RECIPES instead + readSlotDisplay(wrapper); // Result + readSlotDisplay(wrapper); // Crafting station + return null; + } + + private Recipe readSmithing(final PacketWrapper wrapper) { + // TODO Combine with update_recipes + readSlotDisplay(wrapper); // Result + readSlotDisplay(wrapper); // Crafting station + return null; + } + + private Recipe add(final Recipe recipe) { + recipes.add(recipe); + return recipe; + } + + private Item[][] readSlotDisplayList(final PacketWrapper wrapper) { + final int size = wrapper.passthrough(Types.VAR_INT); + final Item[][] ingredients = new Item[size][]; + for (int i = 0; i < size; i++) { + ingredients[i] = readSlotDisplay(wrapper); + } + return ingredients; + } + + private Item readSingleSlotDisplay(final PacketWrapper wrapper) { + final Item[] items = readSlotDisplay(wrapper); + return items.length == 0 ? new StructuredItem(1, 1) : items[0]; + } + + private Item[] readSlotDisplay(final PacketWrapper wrapper) { + // empty, any_fuel, smithing_trim are empty + final int type = wrapper.read(Types.VAR_INT); + return switch (type) { + case 2 -> { + final int id = wrapper.read(Types.VAR_INT); + if (id == 0) { + protocol.getLogger().warning("Empty item id in recipe"); + yield new Item[0]; + } + yield new Item[]{new StructuredItem(rewriteItemId(id), 1)}; + } + case 3 -> { + final Item item = wrapper.read(Types1_21_2.ITEM); + protocol.getItemRewriter().handleItemToClient(wrapper.user(), item); + if (item.isEmpty()) { + protocol.getLogger().warning("Empty item in recipe"); + yield new Item[0]; + } + yield new Item[]{item}; + } + case 4 -> { + wrapper.read(Types.STRING); // Tag key // TODO + yield new Item[0]; + } + case 6 -> readSlotDisplayList(wrapper)[0]; // Composite + default -> new Item[0]; + }; + } + + private int rewriteItemId(final int id) { + return protocol.getMappingData().getNewItemId(id); + } + + public void readStoneCutterRecipes(final PacketWrapper wrapper) { + stoneCutterRecipes.clear(); + final int stonecutterRecipesSize = wrapper.read(Types.VAR_INT); + for (int i = 0; i < stonecutterRecipesSize; i++) { + // The ingredients are what's actually used in client prediction, they're the important part + final Item[] ingredient = readHolderSet(wrapper); + // TODO Probably not actually the result, might have to combine with update_recipes + final Item result = readSingleSlotDisplay(wrapper); + stoneCutterRecipes.add(new StoneCutterRecipe(ingredient, result)); + } + } + + private Item[] readHolderSet(final PacketWrapper wrapper) { + final HolderSet holderSet = wrapper.read(Types.HOLDER_SET); + if (holderSet.hasTagKey()) { + return new Item[]{new StructuredItem(1, 1)}; // TODO + } + + final int[] ids = holderSet.ids(); + for (int i = 0; i < ids.length; i++) { + ids[i] = rewriteItemId(ids[i]); + } + + final Item[] ingredient = new Item[ids.length]; + for (int i = 0; i < ingredient.length; i++) { + ingredient[i] = new StructuredItem(ids[i], 1); + } + return ingredient; + } + + private static final class ShapelessRecipe extends Recipe { + private static final int SERIALIZER_ID = 1; + private final Item[][] ingredients; + private final Item result; + + private ShapelessRecipe(final Item[][] ingredients, final Item result) { + this.ingredients = ingredients; + this.result = result; + } + + @Override + public void write(final PacketWrapper wrapper) { + wrapper.write(Types.VAR_INT, SERIALIZER_ID); + writeGroup(wrapper); + writeCategory(wrapper); + writeIngredients(wrapper, ingredients); + writeResult(wrapper, result); + } + } + + private static final class ShapedRecipe extends Recipe { + private static final int SERIALIZER_ID = 0; + private final int width; + private final int height; + private final Item[][] ingredients; + private final Item result; + + private ShapedRecipe(final int width, final int height, final Item[][] ingredients, final Item result) { + this.width = width; + this.height = height; + this.ingredients = ingredients; + this.result = result; + } + + @Override + public void write(final PacketWrapper wrapper) { + wrapper.write(Types.VAR_INT, SERIALIZER_ID); + writeGroup(wrapper); + writeCategory(wrapper); + wrapper.write(Types.VAR_INT, width); + wrapper.write(Types.VAR_INT, height); + Preconditions.checkArgument(width * height == ingredients.length, "Invalid shaped recipe"); + // No length prefix + for (final Item[] ingredient : ingredients) { + writeIngredient(wrapper, ingredient); + } + writeResult(wrapper, result); + wrapper.write(Types.BOOLEAN, false); // Doesn't matter for the init + } + } + + private static final class FurnaceRecipe extends Recipe { + private final Item[] ingredient; + private final Item result; + + private FurnaceRecipe(final Item[] ingredient, final Item result) { + this.ingredient = ingredient; + this.result = result; + } + + @Override + public void write(final PacketWrapper wrapper) { + wrapper.write(Types.VAR_INT, serializerId()); + writeGroup(wrapper); + writeCategory(wrapper); + writeIngredient(wrapper, ingredient); + writeResult(wrapper, result); + wrapper.write(Types.FLOAT, 0F); // XP + wrapper.write(Types.VAR_INT, 200); // Cooking time, determined by the client in 1.21.2 + } + + private int serializerId() { + return switch (category()) { + case 4, 5, 6 -> 15; // Furnace food, bocks, misc + case 7, 8 -> 16; // Blast furnace blocks, misc + case 9 -> 17; // Smoker + case 12 -> 18; // Campfire + default -> 15; + }; + } + } + + private static final class StoneCutterRecipe extends Recipe { + private static final int SERIALIZER_ID = 19; + private final Item[] ingredient; + private final Item result; + + private StoneCutterRecipe(final Item[] ingredient, final Item result) { + this.ingredient = ingredient; + this.result = result; + } + + @Override + public void write(final PacketWrapper wrapper) { + wrapper.write(Types.VAR_INT, SERIALIZER_ID); + writeGroup(wrapper); + writeIngredient(wrapper, ingredient); + writeResult(wrapper, result); + } + } + + public void setRecipeBookSettings(final boolean[] recipeBookSettings) { + this.recipeBookSettings = recipeBookSettings; + } + + public void clearRecipes() { + recipes.clear(); + highestIndex = 0; + } +} From 5646d04ba99045aea0066bb4254dcc2e57dc62eb Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 8 Oct 2024 17:32:11 +0200 Subject: [PATCH 35/70] 1.21.2-pre1 --- .../BlockItemPacketRewriter1_21_2.java | 31 ++++++- .../v1_21_2to1_21/storage/RecipeStorage.java | 50 ++++++++--- .../data/mappings-1.21.2to1.21.nbt | Bin 6318 -> 6356 bytes .../data/translation-mappings.json | 79 +++++++++++++++++- 4 files changed, 145 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 73f1132d..64be2e24 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -180,12 +180,16 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_ADD, null, wrapper -> { final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class); - recipeStorage.clearRecipes(); - final int size = wrapper.read(Types.VAR_INT); for (int i = 0; i < size; i++) { recipeStorage.readRecipe(wrapper); } + + final boolean replace = wrapper.read(Types.BOOLEAN); + if (replace) { + recipeStorage.clearRecipes(); + } + recipeStorage.sendRecipes(wrapper.user()); wrapper.cancel(); }); @@ -243,6 +247,29 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem wrapper.write(Types.VAR_INT, intId); } + @Override + public void rewriteParticle(final UserConnection connection, final Particle particle) { + super.rewriteParticle(connection, particle); + + final String identifier = protocol.getMappingData().getParticleMappings().mappedIdentifier(particle.id()); + if (identifier.equals("minecraft:dust_color_transition")) { + argbToVector(particle, 0); + argbToVector(particle, 3); + } else if (identifier.equals("minecraft:dust")) { + argbToVector(particle, 0); + } + } + + private void argbToVector(final Particle particle, final int index) { + final int argb = particle.removeArgument(index).getValue(); + final float r = ((argb >> 16) & 0xFF) / 255F; + final float g = ((argb >> 8) & 0xFF) / 255F; + final float b = (argb & 0xFF) / 255F; + particle.add(index, Types.FLOAT, r); + particle.add(index + 1, Types.FLOAT, g); + particle.add(index + 2, Types.FLOAT, b); + } + @Override public Item handleItemToClient(final UserConnection connection, final Item item) { super.handleItemToClient(connection, item); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java index 010cddb3..6ab60e7f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java @@ -36,10 +36,10 @@ public final class RecipeStorage implements StorableObject { // Pairs of open + filtering for: Crafting, furnace, blast furnace, smoker public static final int RECIPE_BOOK_SETTINGS = 4 * 2; private final List recipes = new ArrayList<>(); + private final List tempRecipes = new ArrayList<>(); private final List stoneCutterRecipes = new ArrayList<>(); private boolean[] recipeBookSettings = new boolean[RECIPE_BOOK_SETTINGS]; private final Protocol1_21_2To1_21 protocol; - private int highestIndex; public RecipeStorage(final Protocol1_21_2To1_21 protocol) { this.protocol = protocol; @@ -86,6 +86,17 @@ public final class RecipeStorage implements StorableObject { } public void sendRecipes(final UserConnection connection) { + // Fill from temp recipes so we can clear before if needed + if (!tempRecipes.isEmpty()) { + this.recipes.addAll(tempRecipes); + tempRecipes.clear(); + } + + int highestIndex = -1; + for (final Recipe recipe : recipes) { + highestIndex = Math.max(highestIndex, recipe.index); + } + // Add stonecutter recipes from update_recipes final List recipes = new ArrayList<>(this.recipes); for (final StoneCutterRecipe recipe : stoneCutterRecipes) { @@ -170,7 +181,6 @@ public final class RecipeStorage implements StorableObject { recipe.group = group; recipe.category = category; } - highestIndex = Math.max(highestIndex, id); } private Recipe readShapeless(final PacketWrapper wrapper) { @@ -194,25 +204,31 @@ public final class RecipeStorage implements StorableObject { readSlotDisplay(wrapper); // Fuel final Item result = readSingleSlotDisplay(wrapper); readSlotDisplay(wrapper); // Crafting station - return add(new FurnaceRecipe(ingredient, result)); + final int duration = wrapper.read(Types.VAR_INT); + final float experience = wrapper.read(Types.FLOAT); + return add(new FurnaceRecipe(ingredient, result, duration, experience)); } private Recipe readStoneCutter(final PacketWrapper wrapper) { // Use values from UPDATE_RECIPES instead + readSlotDisplay(wrapper); // Input readSlotDisplay(wrapper); // Result readSlotDisplay(wrapper); // Crafting station return null; } private Recipe readSmithing(final PacketWrapper wrapper) { - // TODO Combine with update_recipes + // TODO Combine with update_recipes? + readSlotDisplay(wrapper); // Template + readSlotDisplay(wrapper); // Base + readSlotDisplay(wrapper); // Addition readSlotDisplay(wrapper); // Result readSlotDisplay(wrapper); // Crafting station return null; } private Recipe add(final Recipe recipe) { - recipes.add(recipe); + tempRecipes.add(recipe); return recipe; } @@ -255,7 +271,18 @@ public final class RecipeStorage implements StorableObject { wrapper.read(Types.STRING); // Tag key // TODO yield new Item[0]; } - case 6 -> readSlotDisplayList(wrapper)[0]; // Composite + case 5 -> { + readSlotDisplay(wrapper); // Base + readSlotDisplay(wrapper); // Material + readSlotDisplay(wrapper); // Pattern + yield new Item[0]; + } + case 6 -> { + readSlotDisplay(wrapper); // Input + readSlotDisplay(wrapper); // Remainder + yield new Item[0]; + } + case 7 -> readSlotDisplayList(wrapper)[0]; // Composite default -> new Item[0]; }; } @@ -348,10 +375,14 @@ public final class RecipeStorage implements StorableObject { private static final class FurnaceRecipe extends Recipe { private final Item[] ingredient; private final Item result; + private final float experience; + private final int cookingTime; - private FurnaceRecipe(final Item[] ingredient, final Item result) { + private FurnaceRecipe(final Item[] ingredient, final Item result, final int cookingTime, final float experience) { this.ingredient = ingredient; this.result = result; + this.experience = experience; + this.cookingTime = cookingTime; } @Override @@ -361,8 +392,8 @@ public final class RecipeStorage implements StorableObject { writeCategory(wrapper); writeIngredient(wrapper, ingredient); writeResult(wrapper, result); - wrapper.write(Types.FLOAT, 0F); // XP - wrapper.write(Types.VAR_INT, 200); // Cooking time, determined by the client in 1.21.2 + wrapper.write(Types.FLOAT, experience); + wrapper.write(Types.VAR_INT, cookingTime); } private int serializerId() { @@ -401,6 +432,5 @@ public final class RecipeStorage implements StorableObject { public void clearRecipes() { recipes.clear(); - highestIndex = 0; } } diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.21.2to1.21.nbt index b0f42eb504d81860cc35376c2e671d12b6e03114..41081c86edd27382a13a926595d853b36536a38f 100644 GIT binary patch delta 124 zcmZ2yc*SsoA-7ZtHv>~*2?GOz0uWyU;>$q%5Qra5cIWmoXY62LV5$Y;Rt5$Z4j|?P zVi_QoWnf@c1!7Gg)&iPQk`L6Q@E-_(^rg*vxIgena4-m#X6j{>rsyS=CMD&h#uwxl H0A(2f>*^Y* delta 86 zcmca&xXy5cA-7mEHv>~*2?GOz91uSM;)e_jjHQ#kxxKWRY8V)pS{N8u*nyY>h^2v8 chJk@q1&B3(SQDtXBp;-A^BL|BJWLD>0F!hLQvd(} diff --git a/common/src/main/resources/assets/viabackwards/data/translation-mappings.json b/common/src/main/resources/assets/viabackwards/data/translation-mappings.json index 2537fbfc..ada31d1f 100644 --- a/common/src/main/resources/assets/viabackwards/data/translation-mappings.json +++ b/common/src/main/resources/assets/viabackwards/data/translation-mappings.json @@ -1,40 +1,113 @@ { "1.21.2": { "attribute.name.tempt_range": "Mob Tempt Range", + "block.minecraft.creaking_heart": "Creaking Heart", + "block.minecraft.pale_hanging_moss": "Pale Hanging Moss", + "block.minecraft.pale_moss_block": "Pale Moss Block", + "block.minecraft.pale_moss_carpet": "Pale Moss Carpet", + "block.minecraft.pale_oak_button": "Pale Oak Button", + "block.minecraft.pale_oak_door": "Pale Oak Door", + "block.minecraft.pale_oak_fence": "Pale Oak Fence", + "block.minecraft.pale_oak_fence_gate": "Pale Oak Fence Gate", + "block.minecraft.pale_oak_hanging_sign": "Pale Oak Hanging Sign", + "block.minecraft.pale_oak_leaves": "Pale Oak Leaves", + "block.minecraft.pale_oak_log": "Pale Oak Log", + "block.minecraft.pale_oak_planks": "Pale Oak Planks", + "block.minecraft.pale_oak_pressure_plate": "Pale Oak Pressure Plate", + "block.minecraft.pale_oak_sapling": "Pale Oak Sapling", + "block.minecraft.pale_oak_sign": "Pale Oak Sign", + "block.minecraft.pale_oak_slab": "Pale Oak Slab", + "block.minecraft.pale_oak_stairs": "Pale Oak Stairs", + "block.minecraft.pale_oak_trapdoor": "Pale Oak Trapdoor", + "block.minecraft.pale_oak_wood": "Pale Oak Wood", + "block.minecraft.potted_pale_oak_sapling": "Potted Pale Oak Sapling", + "block.minecraft.stripped_pale_oak_log": "Stripped Pale Oak Log", + "block.minecraft.stripped_pale_oak_wood": "Stripped Pale Oak Wood", + "commands.drop.no_loot_table.block": "Block %s has no loot table", + "commands.rotate.success": "Rotated %s", "commands.schedule.macro": "Can't schedule a macro", "commands.setidletimeout.success.disabled": "The player idle timeout is now disabled", + "container.beehive.bees": "Bees: %s / %s", + "container.beehive.honey": "Honey: %s / %s", "dataPack.minecart_improvements.description": "Improved movement for Minecarts", "dataPack.minecart_improvements.name": "Minecart Improvements", "dataPack.redstone_experiments.description": "Experimental Redstone changes", "dataPack.redstone_experiments.name": "Redstone Experiments", + "dataPack.winter_drop.description": "New features and content for the Winter Drop", + "dataPack.winter_drop.name": "Winter Drop", "death.attack.mace_smash": "%1$s was smashed by %2$s", "death.attack.mace_smash.item": "%1$s was smashed by %2$s with %3$s", + "entity.minecraft.creaking": "Creaking", + "entity.minecraft.creaking_transient": "Creaking", + "entity.minecraft.pale_oak_boat": "Pale Oak Boat", + "entity.minecraft.pale_oak_chest_boat": "Pale Oak Boat with Chest", + "gamerule.disablePlayerMovementCheck": "Disable player movement check", "gamerule.minecartMaxSpeed": "Minecart max speed", - "gamerule.minecartMaxSpeed.description": "Maximum default speed of a moving Minecart on land", + "gamerule.minecartMaxSpeed.description": "Maximum default speed of a moving Minecart on land.", "gui.abuseReport.name.comment_box_label": "Please describe why you want to report this name:", "gui.abuseReport.reason.sexually_inappropriate": "Sexually inappropriate", "gui.abuseReport.reason.sexually_inappropriate.description": "Skins that are graphic in nature relating to sexual acts, sexual organs, and sexual violence.", + "item.minecraft.black_bundle": "Black Bundle", + "item.minecraft.blue_bundle": "Blue Bundle", "item.minecraft.bordure_indented_banner_pattern": "Bordure Indented Banner Pattern", + "item.minecraft.brown_bundle": "Brown Bundle", "item.minecraft.bundle.empty.description": "Can hold a mixed stack of items", "item.minecraft.bundle.full": "Full", + "item.minecraft.creaking_spawn_egg": "Creaking Spawn Egg", "item.minecraft.creeper_banner_pattern.new": "Creeper Charge Banner Pattern", + "item.minecraft.cyan_bundle": "Cyan Bundle", "item.minecraft.field_masoned_banner_pattern": "Field Masoned Banner Pattern", "item.minecraft.flow_banner_pattern.new": "Flow Banner Pattern", "item.minecraft.flower_banner_pattern.new": "Flower Charge Banner Pattern", "item.minecraft.globe_banner_pattern.new": "Globe Banner Pattern", + "item.minecraft.gray_bundle": "Gray Bundle", + "item.minecraft.green_bundle": "Green Bundle", "item.minecraft.guster_banner_pattern.new": "Guster Banner Pattern", + "item.minecraft.light_blue_bundle": "Light Blue Bundle", + "item.minecraft.light_gray_bundle": "Light Gray Bundle", + "item.minecraft.lime_bundle": "Lime Bundle", + "item.minecraft.magenta_bundle": "Magenta Bundle", "item.minecraft.mojang_banner_pattern.new": "Thing Banner Pattern", + "item.minecraft.orange_bundle": "Orange Bundle", + "item.minecraft.pale_oak_boat": "Pale Oak Boat", + "item.minecraft.pale_oak_chest_boat": "Pale Oak Boat with Chest", "item.minecraft.piglin_banner_pattern.new": "Snout Banner Pattern", + "item.minecraft.pink_bundle": "Pink Bundle", + "item.minecraft.purple_bundle": "Purple Bundle", + "item.minecraft.red_bundle": "Red Bundle", "item.minecraft.skull_banner_pattern.new": "Skull Charge Banner Pattern", + "item.minecraft.white_bundle": "White Bundle", + "item.minecraft.yellow_bundle": "Yellow Bundle", + "mco.create.world.failed": "Failed to create world!", + "mco.errorMessage.initialize.failed": "Failed to initialize Realm", + "mco.upload.failed.too_big.description": "The selected world is too big. The maximum allowed size is %s.", + "mco.upload.failed.too_big.title": "World too big", "optimizeWorld.confirm.proceed": "Create Backup and Optimize", + "options.accessibility.high_contrast_block_outline": "High Contrast Block Outlines", + "options.accessibility.high_contrast_block_outline.tooltip": "Enhances the block outline contrast of targeted block.", "options.inactivityFpsLimit": "Reduce FPS when", "options.inactivityFpsLimit.afk": "AFK", "options.inactivityFpsLimit.afk.tooltip": "Limits framerate to 30 when the game is not getting any player input for more than a minute. Further limits it to 10 after 9 more minutes.", "options.inactivityFpsLimit.minimized": "Minimized", "options.inactivityFpsLimit.minimized.tooltip": "Limits framerate only when the game window is minimized.", "options.rotateWithMinecart": "Rotate with Minecarts", - "options.rotateWithMinecart.tooltip": "If the player's view should rotate with a turning Minecart. Only available in worlds with the 'Minecart Improvements' experimental setting turned on.", - "subtitles.item.bundle.insert_fail": "Bundle full" + "options.rotateWithMinecart.tooltip": "Whether the player's view should rotate with a turning Minecart. Only available in worlds with the 'Minecart Improvements' experimental setting turned on.", + "resourcePack.runtime_failure": "Resource pack error detected", + "subtitles.block.creaking_heart.hurt": "Creaking Heart screams", + "subtitles.block.creaking_heart.spawn": "Creaking Heart awakens", + "subtitles.entity.creaking.activate": "Creaking activates", + "subtitles.entity.creaking.ambient": "Creaking creaks", + "subtitles.entity.creaking.angry": "Creaking sees player", + "subtitles.entity.creaking.attack": "Creaking attacks", + "subtitles.entity.creaking.deactivate": "Creaking deactivates", + "subtitles.entity.creaking.death": "Creaking dies", + "subtitles.entity.creaking.freeze": "Creaking stops", + "subtitles.entity.creaking.spawn": "Creaking lives", + "subtitles.entity.creaking.sway": "Creaking is shielded", + "subtitles.entity.creaking.unfreeze": "Creaking moves", + "subtitles.entity.parrot.imitate.creaking": "Parrot creaks", + "subtitles.item.bundle.insert_fail": "Bundle full", + "subtitles.ui.hud.bubble_pop": "Breath meter dropping" }, "1.21": { "argument.entity.selector.nearestEntity": "Nearest entity", From c57b238b86033f1991fdb956dc0b91424387b336 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 8 Oct 2024 17:43:23 +0200 Subject: [PATCH 36/70] Recipes mostly work now --- .../rewriter/BlockItemPacketRewriter1_21_2.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 64be2e24..92131188 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -37,6 +37,7 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter; +import com.viaversion.viaversion.util.Key; import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.downgradeItemData; import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.updateItemData; @@ -224,15 +225,17 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem }); protocol.registerClientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, wrapper -> { this.updateContainerId(wrapper); - wrapper.cancel(); // TODO + wrapper.cancel(); // Full recipe display, this doesn't look mappable }); protocol.registerServerbound(ServerboundPackets1_20_5.PLACE_RECIPE, wrapper -> { this.updateContainerIdServerbound(wrapper); - wrapper.cancel(); // TODO + + final String recipe = Key.stripMinecraftNamespace(wrapper.read(Types.STRING)); + wrapper.write(Types.VAR_INT, Integer.parseInt(recipe)); }); protocol.registerServerbound(ServerboundPackets1_20_5.RECIPE_BOOK_SEEN_RECIPE, wrapper -> { - this.updateContainerIdServerbound(wrapper); - wrapper.cancel(); // TODO + final String recipe = Key.stripMinecraftNamespace(wrapper.read(Types.STRING)); + wrapper.write(Types.VAR_INT, Integer.parseInt(recipe)); }); } From 16eca5f6aa72ce732f939a9a2a0f3241adbae43a Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 11 Oct 2024 16:32:04 +0200 Subject: [PATCH 37/70] 1.21.2-pre3 --- .../v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java | 2 +- .../v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 92131188..0bba1db1 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -210,7 +210,7 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem wrapper.cancel(); }); protocol.registerClientbound(ClientboundPackets1_21_2.UPDATE_RECIPES, wrapper -> { - // Inputs for furnaces etc., hardcoded in earlier versions + // Inputs for furnaces etc. Old clients get these from the full recipes final int size = wrapper.passthrough(Types.VAR_INT); for (int i = 0; i < size; i++) { wrapper.read(Types.STRING); // Recipe group diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 3fc6294a..8cb19cca 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -418,6 +418,8 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter Date: Wed, 16 Oct 2024 10:26:32 +0200 Subject: [PATCH 38/70] Sort recipes --- .../v1_21_2to1_21/storage/RecipeStorage.java | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java index 6ab60e7f..eecb0e2e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/RecipeStorage.java @@ -29,12 +29,17 @@ import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_21_2; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +// Mostly a lost cause as the server will not send all the necessary data. +// Recipe displays can also be different from the actual recipe - at the end of the same, +// the server will still properly handle inputs, but we can't fully reconstruct the recipe book. public final class RecipeStorage implements StorableObject { // Pairs of open + filtering for: Crafting, furnace, blast furnace, smoker public static final int RECIPE_BOOK_SETTINGS = 4 * 2; + private static final String[] EMPTY_STRINGS = new String[0]; private final List recipes = new ArrayList<>(); private final List tempRecipes = new ArrayList<>(); private final List stoneCutterRecipes = new ArrayList<>(); @@ -46,9 +51,13 @@ public final class RecipeStorage implements StorableObject { } abstract static class Recipe { + private static final int FOOD_CRAFTING_BOOK_CATEGORY = 0; + private static final int BLOCKS_CRAFTING_BOOK_CATEGORY = 1; + private static final int MISC_CRAFTING_BOOK_CATEGORY = 2; protected int index; private Integer group; private int category; + private boolean highlight; private boolean locked; abstract void write(PacketWrapper wrapper); @@ -77,7 +86,14 @@ public final class RecipeStorage implements StorableObject { } void writeCategory(final PacketWrapper wrapper) { - wrapper.write(Types.VAR_INT, 0); // TODO + // TODO Doesn't translate exactly + final int craftingBookCategory = switch (category) { + case 4, 9, 12 -> FOOD_CRAFTING_BOOK_CATEGORY; + case 0, 5, 7, 10 -> BLOCKS_CRAFTING_BOOK_CATEGORY; + case 1, 2, 3, 6, 8, 11 -> MISC_CRAFTING_BOOK_CATEGORY; + default -> MISC_CRAFTING_BOOK_CATEGORY; + }; + wrapper.write(Types.VAR_INT, craftingBookCategory); } int category() { @@ -104,11 +120,14 @@ public final class RecipeStorage implements StorableObject { recipes.add(recipe); } + // Sort by id + recipes.sort(Comparator.comparingInt(a -> a.index)); + // Since the server only sends unlocked recipes, we need to re-send all recipes in UPDATE_RECIPES final PacketWrapper updateRecipesPacket = PacketWrapper.create(ClientboundPackets1_21.UPDATE_RECIPES, connection); updateRecipesPacket.write(Types.VAR_INT, recipes.size()); for (final Recipe recipe : recipes) { - updateRecipesPacket.write(Types.STRING, Integer.toString(recipe.index)); // Use index as the recipe identifier + updateRecipesPacket.write(Types.STRING, identifier(recipe.index)); recipe.write(updateRecipesPacket); } updateRecipesPacket.send(Protocol1_21_2To1_21.class); @@ -116,6 +135,11 @@ public final class RecipeStorage implements StorableObject { sendUnlockedRecipes(connection, recipes); } + private static String identifier(final int recipeIndex) { + // Use index as the recipe identifier, add leading zeros to keept it sorted + return String.format("%06d", recipeIndex); + } + public void lockRecipes(final PacketWrapper wrapper, final int[] ids) { for (final int id : ids) { recipes.get(id).locked = true; @@ -128,13 +152,12 @@ public final class RecipeStorage implements StorableObject { final String[] recipeKeys = new String[ids.length]; for (int i = 0; i < ids.length; i++) { - recipeKeys[i] = Integer.toString(ids[i]); + recipeKeys[i] = identifier(ids[i]); } wrapper.write(Types.STRING_ARRAY, recipeKeys); } private void sendUnlockedRecipes(final UserConnection connection, final List recipes) { - // TODO Not working? final PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_21.RECIPE, connection); wrapper.write(Types.VAR_INT, 0); // Init recipes @@ -144,12 +167,16 @@ public final class RecipeStorage implements StorableObject { // Use index as the recipe identifier. We only know the unlocked ones, so send all final String[] recipeKeys = new String[recipes.size()]; + final List highlightRecipes = new ArrayList<>(); for (int i = 0; i < recipes.size(); i++) { - recipeKeys[i] = Integer.toString(i); + recipeKeys[i] = identifier(i); + if (recipes.get(i).highlight) { + highlightRecipes.add(recipeKeys[i]); + } } wrapper.write(Types.STRING_ARRAY, recipeKeys); - wrapper.write(Types.STRING_ARRAY, new String[0]); // Highlights // TODO + wrapper.write(Types.STRING_ARRAY, highlightRecipes.toArray(EMPTY_STRINGS)); wrapper.send(Protocol1_21_2To1_21.class); } @@ -170,7 +197,7 @@ public final class RecipeStorage implements StorableObject { if (wrapper.read(Types.BOOLEAN)) { final int ingredientsSize = wrapper.read(Types.VAR_INT); for (int j = 0; j < ingredientsSize; j++) { - //handleIngredient(wrapper); // Items //TODO + //handleIngredient(wrapper); // Items //TODO ? wrapper.read(Types.HOLDER_SET); } } @@ -180,6 +207,7 @@ public final class RecipeStorage implements StorableObject { recipe.index = id; recipe.group = group; recipe.category = category; + recipe.highlight = (flags & 2) != 0; } } @@ -268,7 +296,7 @@ public final class RecipeStorage implements StorableObject { yield new Item[]{item}; } case 4 -> { - wrapper.read(Types.STRING); // Tag key // TODO + wrapper.read(Types.STRING); // Tag key // TODO Probably not even worth the effort yield new Item[0]; } case 5 -> { @@ -306,7 +334,7 @@ public final class RecipeStorage implements StorableObject { private Item[] readHolderSet(final PacketWrapper wrapper) { final HolderSet holderSet = wrapper.read(Types.HOLDER_SET); if (holderSet.hasTagKey()) { - return new Item[]{new StructuredItem(1, 1)}; // TODO + return new Item[]{new StructuredItem(1, 1)}; // TODO Probably not even worth the effort } final int[] ids = holderSet.ids(); From 1b9d53af2af73ffa5b4264c42f384d61f8c8214b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 17 Oct 2024 19:44:37 +0200 Subject: [PATCH 39/70] Create tag if needed --- .../rewriter/BlockItemPacketRewriter1_20_5.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index 3d0c5a64..16f764e7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -381,10 +381,11 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem if (customData != null) { // We later don't know which tags are custom data and which are not because the VV conversion // keeps converted data, so we backup the original custom data and restore it later + if (oldItem.tag() == null) { + oldItem.setTag(new CompoundTag()); + } oldItem.tag().put(nbtTagName(), customData.copy()); - } - - if (oldItem.tag() != null && oldItem.tag().isEmpty()) { + } else if (oldItem.tag() != null && oldItem.tag().isEmpty()) { // Improve item equality checks by removing empty tags oldItem.setTag(null); } From 545365786f729b3157f296f216793bcab1ca9e6c Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Fri, 18 Oct 2024 21:57:06 +0200 Subject: [PATCH 40/70] Handle PLAYER_ROTATION packet using PLAYER_LOOK_AT --- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 2 + .../rewriter/EntityPacketRewriter1_21_2.java | 53 +++++++++++++++++-- .../v1_21_2to1_21/storage/PlayerStorage.java | 42 +++++++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/PlayerStorage.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 857c984f..a6182aec 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -26,6 +26,7 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.ComponentRewr import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; import com.viaversion.viaversion.api.connection.UserConnection; @@ -153,6 +154,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { - // TODO Send PLAYER_LOOK_AT via currently tracked location - wrapper.cancel(); + protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_ROTATION, ClientboundPackets1_21.PLAYER_LOOK_AT, wrapper -> { + wrapper.passthrough(Types.FLOAT); // Y rot + wrapper.passthrough(Types.FLOAT); // X rot + + final double yaw = Math.toRadians(wrapper.get(Types.FLOAT, 0)); + final double pitch = Math.toRadians(wrapper.get(Types.FLOAT, 1)); + + final double factor = -Math.cos(-pitch); + final double deltaX = Math.sin(-yaw - (float) Math.PI) * factor; + final double deltaY = Math.sin(-pitch); + final double deltaZ = Math.cos(-yaw - (float) Math.PI) * factor; + + final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); + wrapper.write(Types.VAR_INT, 0); // From anchor + wrapper.write(Types.DOUBLE, storage.x() + deltaX); // X + wrapper.write(Types.DOUBLE, storage.y() + deltaY); // Y + wrapper.write(Types.DOUBLE, storage.z() + deltaZ); // Z + wrapper.write(Types.BOOLEAN, false); // At entity + + final PacketWrapper entityMotionPacket = PacketWrapper.create(ServerboundPackets1_21_2.MOVE_PLAYER_ROT, wrapper.user()); + entityMotionPacket.write(Types.FLOAT, wrapper.get(Types.FLOAT, 0)); + entityMotionPacket.write(Types.FLOAT, wrapper.get(Types.FLOAT, 1)); + entityMotionPacket.write(Types.UNSIGNED_BYTE, (short) 0); // On ground and horizontal collision + entityMotionPacket.sendToServer(Protocol1_21_2To1_21.class); }); protocol.registerClientbound(ClientboundPackets1_21_2.TELEPORT_ENTITY, wrapper -> { @@ -176,6 +198,10 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { wrapper.passthrough(Types.DOUBLE); // X @@ -279,13 +308,31 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { wrapper.passthrough(Types.FLOAT); // Yaw wrapper.passthrough(Types.FLOAT); // Pitch fixOnGround(wrapper); + + final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); + storage.setRotation(wrapper); }); protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, this::fixOnGround); + protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_VEHICLE, wrapper -> { + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + wrapper.passthrough(Types.FLOAT); // Yaw + wrapper.passthrough(Types.FLOAT); // Pitch + + final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); + storage.setCoordinates(wrapper, false); + storage.setRotation(wrapper); + }); protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE, wrapper -> { final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/PlayerStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/PlayerStorage.java new file mode 100644 index 00000000..1a71e0eb --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/PlayerStorage.java @@ -0,0 +1,42 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage; + +import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.type.Types; + +public final class PlayerStorage extends PlayerPositionStorage { + + private float yaw; + private float pitch; + + public float yaw() { + return yaw; + } + + public float pitch() { + return pitch; + } + + public void setRotation(final PacketWrapper wrapper) { + this.yaw = wrapper.get(Types.FLOAT, 0); + this.pitch = wrapper.get(Types.FLOAT, 1); + } + +} From 30d3b0d02e05dd5590d4fd6ff85a9cc2330f8d70 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Fri, 18 Oct 2024 23:05:41 +0200 Subject: [PATCH 41/70] Handle new relative arguments in PLAYER_POSITION and TELEPORT_ENTITY --- .../rewriter/EntityPacketRewriter1_21_2.java | 89 ++++++++++++------- .../v1_21_2to1_21/storage/PlayerStorage.java | 28 ++++++ 2 files changed, 84 insertions(+), 33 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 60745ad9..b4212635 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -181,7 +181,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { @@ -198,44 +198,16 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { @@ -299,7 +271,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { wrapper.passthrough(Types.DOUBLE); // X @@ -310,7 +282,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { @@ -330,7 +302,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter Date: Fri, 18 Oct 2024 23:20:36 +0200 Subject: [PATCH 42/70] Always use correct PROFILE_ACTIONS_ENUM from VV types --- .../v1_19_3to1_19_1/rewriter/EntityPacketRewriter1_19_3.java | 4 +--- .../protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java | 4 ++-- .../v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/EntityPacketRewriter1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/EntityPacketRewriter1_19_3.java index 1eee8dd7..97ffe708 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/EntityPacketRewriter1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/EntityPacketRewriter1_19_3.java @@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19 import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; -import com.viaversion.viaversion.api.type.types.BitSetType; import com.viaversion.viaversion.api.type.types.version.Types1_19; import com.viaversion.viaversion.api.type.types.version.Types1_19_3; import com.viaversion.viaversion.libs.gson.JsonElement; @@ -45,7 +44,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class EntityPacketRewriter1_19_3 extends EntityRewriter { - private static final BitSetType PROFILE_ACTIONS_ENUM_TYPE = new BitSetType(6); private static final int[] PROFILE_ACTIONS = {2, 3, 4, 5}; // Ignore initialize chat; add player already handled before private static final int ADD_PLAYER = 0; private static final int INITIALIZE_CHAT = 1; @@ -123,7 +121,7 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter { wrapper.cancel(); - final BitSet actions = wrapper.read(PROFILE_ACTIONS_ENUM_TYPE); + final BitSet actions = wrapper.read(Types.PROFILE_ACTIONS_ENUM1_19_3); final int entries = wrapper.read(Types.VAR_INT); if (actions.get(ADD_PLAYER)) { // Special case, as we need to write everything into one action diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java index 40b72057..9fdc0ae0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java @@ -283,7 +283,7 @@ public final class Protocol1_20_3To1_20_2 extends BackwardsProtocol { - final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM); + final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM1_19_3); final int entries = wrapper.passthrough(Types.VAR_INT); for (int i = 0; i < entries; i++) { wrapper.passthrough(Types.UUID); @@ -416,4 +416,4 @@ public final class Protocol1_20_3To1_20_2 extends BackwardsProtocol { - final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM); + final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM1_21_2); final int entries = wrapper.passthrough(Types.VAR_INT); for (int i = 0; i < entries; i++) { wrapper.passthrough(Types.UUID); From c7324b1b354052e89ba14df59f13345c06147bef Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Sat, 19 Oct 2024 01:19:22 +0200 Subject: [PATCH 43/70] Use SET_ENTITY_MOTION and EXPLODE for delta movement translation --- .../rewriter/EntityPacketRewriter1_21_2.java | 65 ++++++++++++++----- .../v1_21_2to1_21/storage/PlayerStorage.java | 22 ------- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 21477e34..4b177ee4 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -18,10 +18,14 @@ package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; import com.viaversion.nbt.tag.Tag; +import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; +import com.viaversion.viaversion.api.minecraft.Holder; +import com.viaversion.viaversion.api.minecraft.Particle; +import com.viaversion.viaversion.api.minecraft.SoundEvent; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; @@ -43,6 +47,8 @@ import java.util.List; public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + private boolean warned = ViaBackwards.getConfig().suppressEmulationWarnings(); + public EntityPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) { super(protocol, Types1_21.ENTITY_DATA_TYPES.optionalComponentType, Types1_21.ENTITY_DATA_TYPES.booleanType); } @@ -181,6 +187,10 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter Date: Sat, 19 Oct 2024 01:47:38 +0200 Subject: [PATCH 44/70] Emulate CLIENT_TICK_END packet --- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 8 +++ .../task/ClientEndTickPacketTask.java | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/ClientEndTickPacketTask.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index a6182aec..d7ca0ec0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -29,8 +29,11 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.ClientEndTickPacketTask; +import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; +import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; @@ -147,6 +150,11 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol. + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.task; + +import com.viaversion.viabackwards.ViaBackwards; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.packet.State; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; +import io.netty.channel.Channel; +import java.util.logging.Level; + +public final class ClientEndTickPacketTask implements Runnable { + + @Override + public void run() { + for (final UserConnection user : Via.getManager().getConnectionManager().getConnections()) { + if (user.getProtocolInfo().getClientState() != State.PLAY || !user.getProtocolInfo().getPipeline().contains(Protocol1_21_2To1_21.class)) { + continue; + } + final Channel channel = user.getChannel(); + channel.eventLoop().submit(() -> { + if (!channel.isActive()) { + return; + } + try { + final PacketWrapper clientTickEndPacket = PacketWrapper.create(ServerboundPackets1_21_2.CLIENT_TICK_END, user); + clientTickEndPacket.sendToServer(Protocol1_21_2To1_21.class); + } catch (Throwable t) { + ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending client tick end packet.", t); + } + }); + } + } +} From 4d4f66a1a249a0b39cef7455143d35435faa9f42 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Sat, 19 Oct 2024 02:28:26 +0200 Subject: [PATCH 45/70] Emulate PLAYER_INPUT packet as well --- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 6 +- .../rewriter/EntityPacketRewriter1_21_2.java | 44 +++++++++- .../v1_21_2to1_21/storage/PlayerStorage.java | 87 +++++++++++++++++-- .../storage/SneakingStorage.java | 34 -------- ...etTask.java => PlayerPacketsTickTask.java} | 12 ++- 5 files changed, 134 insertions(+), 49 deletions(-) delete mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java rename common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/{ClientEndTickPacketTask.java => PlayerPacketsTickTask.java} (78%) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index d7ca0ec0..921833c6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -28,8 +28,7 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryState import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage; -import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.SneakingStorage; -import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.ClientEndTickPacketTask; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.PlayerPacketsTickTask; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; @@ -152,7 +151,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { wrapper.passthrough(Types.VAR_INT); final int action = wrapper.passthrough(Types.VAR_INT); + + final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); if (action == 0) { - wrapper.user().get(SneakingStorage.class).setPlayerCommandTrackedSneaking(true); + storage.setPlayerCommandTrackedSneaking(true); } else if (action == 1) { - wrapper.user().get(SneakingStorage.class).setPlayerCommandTrackedSneaking(false); + storage.setPlayerCommandTrackedSneaking(false); + } else if (action == 3) { + storage.setPlayerCommandTrackedSprinting(true); + } else if (action == 4) { + storage.setPlayerCommandTrackedSprinting(false); } }); @@ -263,7 +269,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + final int vehicleId = wrapper.passthrough(Types.VAR_INT); + final int[] passengerIds = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE); + final ClientVehicleStorage storage = wrapper.user().get(ClientVehicleStorage.class); + if (storage != null && vehicleId == storage.vehicleId()) { + wrapper.user().remove(ClientVehicleStorage.class); + } + + final int clientEntityId = tracker(wrapper.user()).clientEntityId(); + for (final int passenger : passengerIds) { + if (passenger == clientEntityId) { + wrapper.user().put(new ClientVehicleStorage(vehicleId)); + break; + } + } + }); + protocol.appendClientbound(ClientboundPackets1_21_2.REMOVE_ENTITIES, wrapper -> { + final ClientVehicleStorage vehicleStorage = wrapper.user().get(ClientVehicleStorage.class); + if (vehicleStorage == null) { + return; + } + + final int[] entityIds = wrapper.get(Types.VAR_INT_ARRAY_PRIMITIVE, 0); + for (final int entityId : entityIds) { + if (entityId == vehicleStorage.vehicleId()) { + wrapper.user().remove(ClientVehicleStorage.class); + break; + } + } + }); } private void updateRotation(PacketWrapper wrapper) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/PlayerStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/PlayerStorage.java index 80fa87a9..5061c211 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/PlayerStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/PlayerStorage.java @@ -18,14 +18,77 @@ package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage; import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; public final class PlayerStorage extends PlayerPositionStorage { + private static final PlayerInput EMPTY = new PlayerInput(false, false, false, false, false, false, false); + private static final float PLAYER_JUMP_HEIGHT = 0.42F; private float yaw; private float pitch; + private boolean playerCommandTrackedSneaking; + private boolean playerCommandTrackedSprinting; + + private PlayerInput lastInput = EMPTY; + private double prevX; + private double prevY; + private double prevZ; + + public void setPosition(PacketWrapper wrapper) { + setX(wrapper.get(Types.DOUBLE, 0)); + setY(wrapper.get(Types.DOUBLE, 1)); + setZ(wrapper.get(Types.DOUBLE, 2)); + } + + public void tick(final UserConnection user) { + final double deltaX = x() - prevX; + final double deltaY = y() - prevY; + final double deltaZ = z() - prevZ; + + final double magnitude = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ); + double directionX = magnitude > 0 ? deltaX / magnitude : 0; + double directionZ = magnitude > 0 ? deltaZ / magnitude : 0; + + directionX = Math.max(-1, Math.min(1, directionX)); + directionZ = Math.max(-1, Math.min(1, directionZ)); + + final double angle = Math.toRadians(-yaw); + final double newDirectionX = directionX * Math.cos(angle) - directionZ * Math.sin(angle); + final double newDirectionZ = directionX * Math.sin(angle) + directionZ * Math.cos(angle); + + final boolean forward = newDirectionZ >= 0.65F; + final boolean backwards = newDirectionZ <= -0.65F; + final boolean left = newDirectionX >= 0.65F; + final boolean right = newDirectionX <= -0.65F; + final boolean jump = Math.abs(deltaY - PLAYER_JUMP_HEIGHT) <= 1E-4F; + + final PlayerInput input = new PlayerInput(forward, backwards, left, right, jump, playerCommandTrackedSneaking, playerCommandTrackedSprinting); + if (!lastInput.equals(input)) { + final PacketWrapper playerInputPacket = PacketWrapper.create(ServerboundPackets1_21_2.PLAYER_INPUT, user); + byte flags = 0; + flags = (byte) (flags | (input.forward() ? 1 : 0)); + flags = (byte) (flags | (input.backward() ? 2 : 0)); + flags = (byte) (flags | (input.left() ? 4 : 0)); + flags = (byte) (flags | (input.right() ? 8 : 0)); + flags = (byte) (flags | (input.jump() ? 16 : 0)); + flags = (byte) (flags | (input.sneak() ? 32 : 0)); + flags = (byte) (flags | (input.sprint() ? 64 : 0)); + playerInputPacket.write(Types.BYTE, flags); + + playerInputPacket.sendToServer(Protocol1_21_2To1_21.class); + lastInput = input; + } + + this.prevX = x(); + this.prevY = y(); + this.prevZ = z(); + } + public float yaw() { return yaw; } @@ -34,15 +97,27 @@ public final class PlayerStorage extends PlayerPositionStorage { return pitch; } - public void setPosition(PacketWrapper wrapper) { - setX(wrapper.get(Types.DOUBLE, 0)); - setY(wrapper.get(Types.DOUBLE, 1)); - setZ(wrapper.get(Types.DOUBLE, 2)); - } - public void setRotation(final PacketWrapper wrapper) { this.yaw = wrapper.get(Types.FLOAT, 0); this.pitch = wrapper.get(Types.FLOAT, 1); } + public void setPlayerCommandTrackedSneaking(final boolean playerCommandTrackedSneaking) { + this.playerCommandTrackedSneaking = playerCommandTrackedSneaking; + } + + public void setPlayerCommandTrackedSprinting(final boolean playerCommandTrackedSprinting) { + this.playerCommandTrackedSprinting = playerCommandTrackedSprinting; + } + + public boolean setSneaking(final boolean sneaking) { + final boolean changed = this.playerCommandTrackedSneaking != sneaking; + this.playerCommandTrackedSneaking = sneaking; + return changed; + } + + public record PlayerInput(boolean forward, boolean backward, boolean left, boolean right, boolean jump, + boolean sneak, boolean sprint) { + } + } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java deleted file mode 100644 index 2ab7cd9a..00000000 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/storage/SneakingStorage.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards - * 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 . - */ -package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage; - -import com.viaversion.viaversion.api.connection.StorableObject; - -public final class SneakingStorage implements StorableObject { - private boolean playerCommandTrackedSneaking; - - public void setPlayerCommandTrackedSneaking(final boolean playerCommandTrackedSneaking) { - this.playerCommandTrackedSneaking = playerCommandTrackedSneaking; - } - - public boolean setSneaking(final boolean sneaking) { - final boolean changed = this.playerCommandTrackedSneaking != sneaking; - this.playerCommandTrackedSneaking = sneaking; - return changed; - } -} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/ClientEndTickPacketTask.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/PlayerPacketsTickTask.java similarity index 78% rename from common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/ClientEndTickPacketTask.java rename to common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/PlayerPacketsTickTask.java index 5bb7037e..791593e5 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/ClientEndTickPacketTask.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/task/PlayerPacketsTickTask.java @@ -19,15 +19,17 @@ package com.viaversion.viabackwards.protocol.v1_21_2to1_21.task; import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.ClientVehicleStorage; import io.netty.channel.Channel; import java.util.logging.Level; -public final class ClientEndTickPacketTask implements Runnable { +public final class PlayerPacketsTickTask implements Runnable { @Override public void run() { @@ -40,6 +42,14 @@ public final class ClientEndTickPacketTask implements Runnable { if (!channel.isActive()) { return; } + try { + if (!user.has(ClientVehicleStorage.class)) { + final PlayerStorage playerStorage = user.get(PlayerStorage.class); + playerStorage.tick(user); + } + } catch (Throwable t) { + ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending player input packet.", t); + } try { final PacketWrapper clientTickEndPacket = PacketWrapper.create(ServerboundPackets1_21_2.CLIENT_TICK_END, user); clientTickEndPacket.sendToServer(Protocol1_21_2To1_21.class); From 1c7017a0562a2f8a99e3d941a55fbb5695dfe753 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 19 Oct 2024 12:55:59 +0200 Subject: [PATCH 46/70] Pass position/rotation values directly, fix relative position and rotation handling --- .../storage/EntityPositionHandler.java | 6 +- .../storage/EntityPositionStorage.java | 20 +- .../storage/PlayerPositionStorage.java | 22 +-- .../rewriter/EntityPacketRewriter1_13.java | 16 +- .../rewriter/EntityPacketRewriter1_21_2.java | 173 ++++++++++-------- .../v1_21_2to1_21/storage/PlayerStorage.java | 12 +- 6 files changed, 132 insertions(+), 117 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionHandler.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionHandler.java index 70741e84..0d53c9d6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionHandler.java @@ -75,7 +75,11 @@ public class EntityPositionHandler { } } - positionStorage.setCoordinates(x, y, z, relative); + if (relative) { + positionStorage.addRelativePosition(x, y, z); + } else { + positionStorage.setPosition(x, y, z); + } } public EntityPositionStorage getStorage(UserConnection user, int entityId) { diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionStorage.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionStorage.java index 38df14f5..698715ed 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionStorage.java @@ -34,15 +34,15 @@ public abstract class EntityPositionStorage { return z; } - public void setCoordinates(double x, double y, double z, boolean relative) { - if (relative) { - this.x += x; - this.y += y; - this.z += z; - } else { - this.x = x; - this.y = y; - this.z = z; - } + public void setPosition(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public void addRelativePosition(double relX, double relY, double relZ) { + this.x += relX; + this.y += relY; + this.z += relZ; } } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/PlayerPositionStorage.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/PlayerPositionStorage.java index 2e87dd61..7d70e3bb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/PlayerPositionStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/PlayerPositionStorage.java @@ -18,8 +18,6 @@ package com.viaversion.viabackwards.api.entities.storage; import com.viaversion.viaversion.api.connection.StorableObject; -import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.type.Types; public abstract class PlayerPositionStorage implements StorableObject { private double x; @@ -53,19 +51,15 @@ public abstract class PlayerPositionStorage implements StorableObject { this.z = z; } - public void setCoordinates(PacketWrapper wrapper, boolean relative) { - setCoordinates(wrapper.get(Types.DOUBLE, 0), wrapper.get(Types.DOUBLE, 1), wrapper.get(Types.DOUBLE, 2), relative); + public void setPosition(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; } - public void setCoordinates(double x, double y, double z, boolean relative) { - if (relative) { - this.x += x; - this.y += y; - this.z += z; - } else { - this.x = x; - this.y = y; - this.z = z; - } + public void addRelativePosition(double relX, double relY, double relZ) { + this.x += relX; + this.y += relY; + this.z += relZ; } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java index b103e23b..a1e8cf27 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java @@ -31,10 +31,11 @@ import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; -import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_12; +import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_12; @@ -237,14 +238,11 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter wrapper.user().get(PlayerPositionStorage1_13.class).setCoordinates(wrapper, false)); - } + PacketHandler movementRemapper = wrapper -> { + final double x = wrapper.passthrough(Types.DOUBLE); + final double y = wrapper.passthrough(Types.DOUBLE); + final double z = wrapper.passthrough(Types.DOUBLE); + wrapper.user().get(PlayerPositionStorage1_13.class).setPosition(x, y, z); }; protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS, movementRemapper); // Player Position protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS_ROT, movementRemapper); // Player Position And Look (serverbound) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 811c9135..4e5df52e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -47,6 +47,15 @@ import java.util.List; public final class EntityPacketRewriter1_21_2 extends EntityRewriter { + private static final int REL_X = 0; + private static final int REL_Y = 1; + private static final int REL_Z = 2; + private static final int REL_Y_ROT = 3; + private static final int REL_X_ROT = 4; + private static final int REL_DELTA_X = 5; + private static final int REL_DELTA_Y = 6; + private static final int REL_DELTA_Z = 7; + private static final int REL_ROTATE_DELTA = 8; private boolean warned = ViaBackwards.getConfig().suppressEmulationWarnings(); public EntityPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) { @@ -144,20 +153,22 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { - wrapper.passthrough(Types.FLOAT); // Y rot - wrapper.passthrough(Types.FLOAT); // X rot + final float yaw = wrapper.passthrough(Types.FLOAT); + final float pitch = wrapper.passthrough(Types.FLOAT); - final double yaw = Math.toRadians(wrapper.get(Types.FLOAT, 0)); - final double pitch = Math.toRadians(wrapper.get(Types.FLOAT, 1)); + final double yRadians = Math.toRadians(yaw); + final double xRadians = Math.toRadians(pitch); - final double factor = -Math.cos(-pitch); - final double deltaX = Math.sin(-yaw - (float) Math.PI) * factor; - final double deltaY = Math.sin(-pitch); - final double deltaZ = Math.cos(-yaw - (float) Math.PI) * factor; + final double factor = -Math.cos(-xRadians); + final double deltaX = Math.sin(-yRadians - (float) Math.PI) * factor; + final double deltaY = Math.sin(-xRadians); + final double deltaZ = Math.cos(-yRadians - (float) Math.PI) * factor; final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); wrapper.write(Types.VAR_INT, 0); // From anchor @@ -167,46 +178,48 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { wrapper.passthrough(Types.VAR_INT); // Entity ID - wrapper.passthrough(Types.DOUBLE); // X - wrapper.passthrough(Types.DOUBLE); // Y - wrapper.passthrough(Types.DOUBLE); // Z + final double x = wrapper.passthrough(Types.DOUBLE); + final double y = wrapper.passthrough(Types.DOUBLE); + final double z = wrapper.passthrough(Types.DOUBLE); - double movementX = wrapper.read(Types.DOUBLE); - double movementY = wrapper.read(Types.DOUBLE); - double movementZ = wrapper.read(Types.DOUBLE); + final double movementX = wrapper.read(Types.DOUBLE); + final double movementY = wrapper.read(Types.DOUBLE); + final double movementZ = wrapper.read(Types.DOUBLE); - // Pack y and x rot - updateRotation(wrapper); + final float yaw = wrapper.read(Types.FLOAT); + final float pitch = wrapper.read(Types.FLOAT); + writePackedRotation(wrapper, yaw, pitch); - final int relativeArguments = wrapper.read(Types.VAR_INT); + final int relativeArguments = wrapper.read(Types.INT); // Send alongside separate entity motion wrapper.send(Protocol1_21_2To1_21.class); wrapper.cancel(); - handleRelativeArguments(wrapper, relativeArguments, movementX, movementY, movementZ); + + handleRelativeArguments(wrapper, x, y, z, yaw, pitch, relativeArguments, movementX, movementY, movementZ); }); protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_POSITION, wrapper -> { final int teleportId = wrapper.read(Types.VAR_INT); - wrapper.passthrough(Types.DOUBLE); // X - wrapper.passthrough(Types.DOUBLE); // Y - wrapper.passthrough(Types.DOUBLE); // Z + final double x = wrapper.passthrough(Types.DOUBLE); + final double y = wrapper.passthrough(Types.DOUBLE); + final double z = wrapper.passthrough(Types.DOUBLE); - double movementX = wrapper.read(Types.DOUBLE); - double movementY = wrapper.read(Types.DOUBLE); - double movementZ = wrapper.read(Types.DOUBLE); + final double movementX = wrapper.read(Types.DOUBLE); + final double movementY = wrapper.read(Types.DOUBLE); + final double movementZ = wrapper.read(Types.DOUBLE); - wrapper.passthrough(Types.FLOAT); // Y rot - wrapper.passthrough(Types.FLOAT); // X rot + final float yaw = wrapper.passthrough(Types.FLOAT); + final float pitch = wrapper.passthrough(Types.FLOAT); // Just keep the new values in there final int relativeArguments = wrapper.read(Types.INT); @@ -216,7 +229,8 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { @@ -280,45 +294,45 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { - wrapper.passthrough(Types.DOUBLE); // X - wrapper.passthrough(Types.DOUBLE); // Y - wrapper.passthrough(Types.DOUBLE); // Z + final double x = wrapper.passthrough(Types.DOUBLE); + final double y = wrapper.passthrough(Types.DOUBLE); + final double z = wrapper.passthrough(Types.DOUBLE); fixOnGround(wrapper); final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); - storage.setPosition(wrapper); + storage.setPosition(x, y, z); }); protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> { - wrapper.passthrough(Types.DOUBLE); // X - wrapper.passthrough(Types.DOUBLE); // Y - wrapper.passthrough(Types.DOUBLE); // Z - wrapper.passthrough(Types.FLOAT); // Yaw - wrapper.passthrough(Types.FLOAT); // Pitch + final double x = wrapper.passthrough(Types.DOUBLE); + final double y = wrapper.passthrough(Types.DOUBLE); + final double z = wrapper.passthrough(Types.DOUBLE); + final float yaw = wrapper.passthrough(Types.FLOAT); + final float pitch = wrapper.passthrough(Types.FLOAT); fixOnGround(wrapper); final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); - storage.setPosition(wrapper); - storage.setRotation(wrapper); + storage.setPosition(x, y, z); + storage.setRotation(yaw, pitch); }); protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> { - wrapper.passthrough(Types.FLOAT); // Yaw - wrapper.passthrough(Types.FLOAT); // Pitch + final float yaw = wrapper.passthrough(Types.FLOAT); + final float pitch = wrapper.passthrough(Types.FLOAT); fixOnGround(wrapper); final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); - storage.setRotation(wrapper); + storage.setRotation(yaw, pitch); }); protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, this::fixOnGround); protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_VEHICLE, wrapper -> { - wrapper.passthrough(Types.DOUBLE); // X - wrapper.passthrough(Types.DOUBLE); // Y - wrapper.passthrough(Types.DOUBLE); // Z - wrapper.passthrough(Types.FLOAT); // Yaw - wrapper.passthrough(Types.FLOAT); // Pitch + final double x = wrapper.passthrough(Types.DOUBLE); + final double y = wrapper.passthrough(Types.DOUBLE); + final double z = wrapper.passthrough(Types.DOUBLE); + final float yaw = wrapper.passthrough(Types.FLOAT); + final float pitch = wrapper.passthrough(Types.FLOAT); final PlayerStorage storage = wrapper.user().get(PlayerStorage.class); - storage.setPosition(wrapper); - storage.setRotation(wrapper); + storage.setPosition(x, y, z); + storage.setRotation(yaw, pitch); }); protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE, wrapper -> { @@ -393,30 +407,39 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter Date: Sat, 19 Oct 2024 13:17:13 +0200 Subject: [PATCH 47/70] Handle player info components in 1.20.5->1.20.3 --- .../viabackwards/protocol/template/Protocol1_98To1_99.java | 1 + .../protocol/v1_20_5to1_20_3/Protocol1_20_5To1_20_3.java | 1 + .../v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java index 649021c7..77da1cad 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java @@ -87,6 +87,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 4e5df52e..0a806352 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -336,7 +336,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { - final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM1_21_2); + final BitSet actions = wrapper.passthroughAndMap(Types.PROFILE_ACTIONS_ENUM1_21_2, Types.PROFILE_ACTIONS_ENUM1_19_3); final int entries = wrapper.passthrough(Types.VAR_INT); for (int i = 0; i < entries; i++) { wrapper.passthrough(Types.UUID); From 2ce11704ba296aea52e96158d50f354d751b7ae5 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 20 Oct 2024 19:09:55 +0200 Subject: [PATCH 48/70] Register tasks in the right place --- .../com/viaversion/viabackwards/BukkitPlugin.java | 12 +++--------- .../viabackwards/api/ViaBackwardsPlatform.java | 8 ++++++++ .../protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java | 8 -------- .../v1_21_2to1_21/task/PlayerPacketsTickTask.java | 1 + .../com/viaversion/viabackwards/ViaFabricAddon.java | 1 + .../com/viaversion/viabackwards/VelocityPlugin.java | 1 + 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viabackwards/BukkitPlugin.java b/bukkit/src/main/java/com/viaversion/viabackwards/BukkitPlugin.java index fd5946fb..9e91ea5f 100644 --- a/bukkit/src/main/java/com/viaversion/viabackwards/BukkitPlugin.java +++ b/bukkit/src/main/java/com/viaversion/viabackwards/BukkitPlugin.java @@ -36,19 +36,13 @@ public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform { public BukkitPlugin() { Via.getManager().addEnableListener(() -> init(new File(getDataFolder(), "config.yml"))); + Via.getManager().addPostEnableListener(this::enable); } @Override - public void onEnable() { - if (Via.getManager().getInjector().lateProtocolVersionSetting()) { - // Enable in the next tick - Via.getPlatform().runSync(this::enable, 1); - } else { - enable(); - } - } + public void enable() { + ViaBackwardsPlatform.super.enable(); - private void enable() { final ProtocolVersion protocolVersion = Via.getAPI().getServerVersion().highestSupportedProtocolVersion(); if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_17)) { new PlayerItemDropListener(this).register(); diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java index e6f6ff9d..1e09a521 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -55,6 +55,7 @@ import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20 import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3; import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; +import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.PlayerPacketsTickTask; import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5; import com.viaversion.viabackwards.protocol.v1_9_3to1_9_1.Protocol1_9_3To1_9_1; import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3; @@ -145,6 +146,13 @@ public interface ViaBackwardsPlatform { protocolManager.registerProtocol(new Protocol1_21_2To1_21(), ProtocolVersion.v1_21, ProtocolVersion.v1_21_2); } + default void enable() { + final ProtocolVersion protocolVersion = Via.getAPI().getServerVersion().highestSupportedProtocolVersion(); + if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_21_2)) { + Via.getPlatform().runRepeatingSync(new PlayerPacketsTickTask(), 1L); + } + } + /** * Logger provided by the platform. * diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 921833c6..296f2906 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -28,11 +28,8 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryState import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage; -import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.PlayerPacketsTickTask; -import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; -import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; @@ -149,11 +146,6 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { if (!channel.isActive()) { diff --git a/fabric/src/main/java/com/viaversion/viabackwards/ViaFabricAddon.java b/fabric/src/main/java/com/viaversion/viabackwards/ViaFabricAddon.java index b1afc86f..ef900318 100644 --- a/fabric/src/main/java/com/viaversion/viabackwards/ViaFabricAddon.java +++ b/fabric/src/main/java/com/viaversion/viabackwards/ViaFabricAddon.java @@ -35,6 +35,7 @@ public class ViaFabricAddon implements ViaBackwardsPlatform, Runnable { Path configDirPath = FabricLoader.getInstance().getConfigDir().resolve("ViaBackwards"); configDir = configDirPath.toFile(); this.init(new File(getDataFolder(), "config.yml")); + this.enable(); } @Override diff --git a/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java b/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java index f7dcb0fb..65257643 100644 --- a/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java +++ b/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java @@ -52,6 +52,7 @@ public class VelocityPlugin implements ViaBackwardsPlatform { public void onProxyStart(ProxyInitializeEvent event) { this.logger = new LoggerWrapper(loggerSlf4j); Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml"))); + Via.getManager().addPostEnableListener(this::enable); } @Override From a0f2a8595e68ab438339261d2a19d7c0ddaf9568 Mon Sep 17 00:00:00 2001 From: RK_01 <50594595+RaphiMC@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:25:43 +0200 Subject: [PATCH 49/70] Fix PLAYER_INFO_UPDATE display name data type (#5) --- .../v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 0a806352..088e46c7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -364,7 +364,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter Date: Tue, 22 Oct 2024 10:26:05 +0200 Subject: [PATCH 50/70] Fix CLIENT_INFORMATION skin flags data type (#4) --- .../protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 296f2906..053b6ed6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -139,7 +139,7 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol Date: Tue, 22 Oct 2024 18:10:18 +0200 Subject: [PATCH 51/70] Back to onenable tasks --- .../com/viaversion/viabackwards/BukkitPlugin.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bukkit/src/main/java/com/viaversion/viabackwards/BukkitPlugin.java b/bukkit/src/main/java/com/viaversion/viabackwards/BukkitPlugin.java index 9e91ea5f..32d3f77a 100644 --- a/bukkit/src/main/java/com/viaversion/viabackwards/BukkitPlugin.java +++ b/bukkit/src/main/java/com/viaversion/viabackwards/BukkitPlugin.java @@ -36,7 +36,16 @@ public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform { public BukkitPlugin() { Via.getManager().addEnableListener(() -> init(new File(getDataFolder(), "config.yml"))); - Via.getManager().addPostEnableListener(this::enable); + } + + @Override + public void onEnable() { + if (Via.getManager().getInjector().lateProtocolVersionSetting()) { + // Enable in the next tick + Via.getPlatform().runSync(this::enable, 1); + } else { + enable(); + } } @Override From afb8384319d1030c1a69ae6a68ea197384a81bc1 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 22 Oct 2024 18:42:43 +0200 Subject: [PATCH 52/70] Enable bundle feature --- .../protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java index 053b6ed6..484c67ce 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/Protocol1_21_2To1_21.java @@ -51,6 +51,7 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacke import com.viaversion.viaversion.rewriter.AttributeRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; +import com.viaversion.viaversion.util.ArrayUtil; import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap; @@ -96,6 +97,11 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol { + final String[] enabledFeatures = wrapper.read(Types.STRING_ARRAY); + wrapper.write(Types.STRING_ARRAY, ArrayUtil.add(enabledFeatures, "bundle")); + }); + cancelClientbound(ClientboundPackets1_21_2.MOVE_MINECART_ALONG_TRACK); // TODO registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> { From 4f119d26d7be7f94c8bc66f753c8995640dc9644 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Wed, 23 Oct 2024 16:27:14 +0200 Subject: [PATCH 53/70] Update version ranges in gradle.properties --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index a9e4f680..e2c1b405 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ projectVersion=5.1.0-SNAPSHOT # Smile emoji -mcVersions=1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 -mcVersionRange=1.10-1.21.2 +mcVersions=1.21.3,1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 +mcVersionRange=1.10-1.21.3 velocityVersion=3.3 From b1f4a88050ba7c3dae327567181aa7441152a96d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 23 Oct 2024 21:26:12 +0200 Subject: [PATCH 54/70] Fix 1.20.5->1.20.3 darkness effect transition --- .../rewriter/EntityPacketRewriter1_20_5.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index ac9c8b7e..9775c982 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -243,14 +243,26 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { wrapper.passthrough(Types.VAR_INT); // Entity ID - wrapper.passthrough(Types.VAR_INT); // Effect ID + final int effectId = wrapper.passthrough(Types.VAR_INT); final int amplifier = wrapper.read(Types.VAR_INT); wrapper.write(Types.BYTE, (byte) MathUtil.clamp(amplifier, Byte.MIN_VALUE, Byte.MAX_VALUE)); wrapper.passthrough(Types.VAR_INT); // Duration wrapper.passthrough(Types.BYTE); // Flags - wrapper.write(Types.OPTIONAL_COMPOUND_TAG, null); // Add empty factor data + + if (effectId == 32) { // Darkness, keep a stable effect + final CompoundTag factorData = new CompoundTag(); + factorData.putInt("padding_duration", 22); + factorData.putBoolean("had_effect_last_tick", true); + factorData.putFloat("factor_previous_frame", 0); + factorData.putFloat("factor_start", 1); + factorData.putFloat("factor_target", 1); + factorData.putFloat("factor_current", 1); + wrapper.write(Types.OPTIONAL_COMPOUND_TAG, factorData); + } else { + wrapper.write(Types.OPTIONAL_COMPOUND_TAG, null); + } }); protocol.registerClientbound(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES, wrapper -> { From 0a6d143d92af33412d3672cd34b0acbfcb973b01 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 24 Oct 2024 16:56:54 +0200 Subject: [PATCH 55/70] Remove baby index via parent type --- .../v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 088e46c7..57812113 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -575,9 +575,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter Date: Fri, 25 Oct 2024 18:09:02 +0200 Subject: [PATCH 56/70] Update ChunkSectionLightImpl call --- .../v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java index f129b965..8fe48094 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java @@ -369,7 +369,7 @@ public class BlockItemPacketRewriter1_14 extends BackwardsItemRewriter Date: Fri, 25 Oct 2024 18:09:24 +0200 Subject: [PATCH 57/70] 5.1.0 Release --- gradle.properties | 2 +- gradle/libs.versions.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index e2c1b405..3af05c37 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -projectVersion=5.1.0-SNAPSHOT +projectVersion=5.1.0 # Smile emoji mcVersions=1.21.3,1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a84ae215..1ccc51c4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "5.1.0-SNAPSHOT" +viaver = "5.1.0" # Common provided netty = "4.0.20.Final" From 927ffaf20a06e1fe2419aa1fe17e5e7c91dccb00 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sat, 26 Oct 2024 14:07:13 +0200 Subject: [PATCH 58/70] Correctly update action bits in PLAYER_INFO_UPDATE in 1.21.2->1.21 (#899) --- .../rewriter/EntityPacketRewriter1_21_2.java | 11 ++++++++++- gradle.properties | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 57812113..7b62ea6c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -336,7 +336,16 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { - final BitSet actions = wrapper.passthroughAndMap(Types.PROFILE_ACTIONS_ENUM1_21_2, Types.PROFILE_ACTIONS_ENUM1_19_3); + final BitSet actions = wrapper.read(Types.PROFILE_ACTIONS_ENUM1_21_2); + // We need to recreate the BitSet field itself to remove the new action + final BitSet updatedActions = new BitSet(6); + for (int i = 0; i < 6; i++) { + if (actions.get(i)) { + updatedActions.set(i); + } + } + wrapper.write(Types.PROFILE_ACTIONS_ENUM1_19_3, updatedActions); + final int entries = wrapper.passthrough(Types.VAR_INT); for (int i = 0; i < entries; i++) { wrapper.passthrough(Types.UUID); diff --git a/gradle.properties b/gradle.properties index 3af05c37..a03f4081 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -projectVersion=5.1.0 +projectVersion=5.1.1-SNAPSHOT # Smile emoji mcVersions=1.21.3,1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 From 8af8319839280bfe434a04b2cd11a0fa313ab90f Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 27 Oct 2024 23:25:00 +0100 Subject: [PATCH 59/70] Small cleanup --- .../api/ViaBackwardsPlatform.java | 2 +- .../api/rewriters/EntityRewriter.java | 14 +++--- .../api/rewriters/SoundRewriter.java | 17 ++------ .../template/EntityPacketRewriter1_99.java | 43 ++++++++----------- .../rewriter/EntityPacketRewriter1_21.java | 6 ++- gradle/libs.versions.toml | 2 +- settings.gradle.kts | 1 - 7 files changed, 32 insertions(+), 53 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java index 1e09a521..d878aadb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -71,7 +71,7 @@ import java.util.logging.Logger; public interface ViaBackwardsPlatform { - String MINIMUM_VV_VERSION = "5.1.0"; + String MINIMUM_VV_VERSION = "5.1.1"; /** * Initialize ViaBackwards. diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java index 242f4c67..ca85e27c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriter.java @@ -25,7 +25,6 @@ import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_14; @@ -105,14 +104,11 @@ public abstract class EntityRewriter trackAndMapEntity(wrapper)); - } + protocol.registerClientbound(packetType, wrapper -> { + wrapper.passthrough(Types.VAR_INT); // Entity ID + wrapper.passthrough(Types.UUID); // Entity UUID + wrapper.passthrough(Types.VAR_INT); // Entity Type + trackAndMapEntity(wrapper); }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java index f739f4c4..a86dc273 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java @@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.minecraft.SoundEvent; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; public class SoundRewriter extends com.viaversion.viaversion.rewriter.SoundRewriter { @@ -36,22 +35,14 @@ public class SoundRewriter extends com.viaversi } public void registerNamedSound(final C packetType) { - protocol.registerClientbound(packetType, new PacketHandlers() { - @Override - public void register() { - map(Types.STRING); // Sound identifier - handler(getNamedSoundHandler()); - } + protocol.registerClientbound(packetType, wrapper -> { + wrapper.passthrough(Types.STRING); // Sound identifier + getNamedSoundHandler().handle(wrapper); }); } public void registerStopSound(final C packetType) { - protocol.registerClientbound(packetType, new PacketHandlers() { - @Override - public void register() { - handler(getStopSoundHandler()); - } - }); + protocol.registerClientbound(packetType, wrapper -> getStopSoundHandler().handle(wrapper)); } public PacketHandler getNamedSoundHandler() { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java index 94fc157b..51cfdd3d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/EntityPacketRewriter1_99.java @@ -18,16 +18,14 @@ package com.viaversion.viabackwards.protocol.template; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; -import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; -import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; -import com.viaversion.viaversion.util.Key; +import com.viaversion.viaversion.rewriter.RegistryDataRewriter; // Replace if needed // Types1_OLD @@ -44,30 +42,23 @@ final class EntityPacketRewriter1_99 extends EntityRewriter { - final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); - final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY); - handleRegistryData1_20_5(wrapper.user(), registryKey, entries); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data - }); + final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol); + protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle); - protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, new PacketHandlers() { - @Override - public void register() { - map(Types.INT); // Entity id - map(Types.BOOLEAN); // Hardcore - map(Types.STRING_ARRAY); // World List - map(Types.VAR_INT); // Max players - map(Types.VAR_INT); // View distance - map(Types.VAR_INT); // Simulation distance - map(Types.BOOLEAN); // Reduced debug info - map(Types.BOOLEAN); // Show death screen - map(Types.BOOLEAN); // Limited crafting - map(Types.VAR_INT); // Dimension key - map(Types.STRING); // World - handler(worldDataTrackerHandlerByKey1_20_5(3)); // Tracks world height and name for chunk data and entity (un)tracking - handler(playerTrackerHandler()); - } + protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, wrapper -> { + final int entityId = wrapper.passthrough(Types.INT); // Entity id + wrapper.passthrough(Types.BOOLEAN); // Hardcore + wrapper.passthrough(Types.STRING_ARRAY); // World List + wrapper.passthrough(Types.VAR_INT); // Max players + wrapper.passthrough(Types.VAR_INT); // View distance + wrapper.passthrough(Types.VAR_INT); // Simulation distance + wrapper.passthrough(Types.BOOLEAN); // Reduced debug info + wrapper.passthrough(Types.BOOLEAN); // Show death screen + wrapper.passthrough(Types.BOOLEAN); // Limited crafting + final int dimensionId = wrapper.passthrough(Types.VAR_INT); + final String world = wrapper.passthrough(Types.STRING); + trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); + trackPlayer(wrapper.user(), entityId); }); protocol.registerClientbound(ClientboundPackets1_21_2.RESPAWN, wrapper -> { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java index 98b98000..f04f15a3 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java @@ -40,6 +40,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.rewriter.RegistryDataRewriter; import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.KeyMappings; import java.util.HashMap; @@ -64,6 +65,7 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter { final String key = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY); @@ -99,7 +101,7 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter Date: Mon, 28 Oct 2024 11:28:12 +0100 Subject: [PATCH 60/70] Use new ParticleRewriter (#901) --- .../BackwardsStructuredItemRewriter.java | 7 +-- .../api/rewriters/EntityRewriterBase.java | 6 +- .../template/BlockItemPacketRewriter1_99.java | 2 - .../protocol/template/Protocol1_98To1_99.java | 13 +++++ .../v1_13_1to1_13/Protocol1_13_1To1_13.java | 9 +++ .../rewriter/EntityPacketRewriter1_13_1.java | 4 +- .../rewriter/ItemPacketRewriter1_13_1.java | 3 - .../v1_14to1_13_2/Protocol1_14To1_13_2.java | 11 +++- .../rewriter/BlockItemPacketRewriter1_14.java | 10 ++-- .../rewriter/EntityPacketRewriter1_14.java | 6 +- .../v1_15to1_14_4/Protocol1_15To1_14_4.java | 9 ++- .../Protocol1_16_2To1_16_1.java | 11 +++- .../BlockItemPacketRewriter1_16_2.java | 2 - .../v1_16to1_15_2/Protocol1_16To1_15_2.java | 17 ++++-- .../rewriter/BlockItemPacketRewriter1_16.java | 16 +++--- .../rewriter/EntityPacketRewriter1_16.java | 6 +- .../v1_17to1_16_4/Protocol1_17To1_16_4.java | 7 +++ .../rewriter/BlockItemPacketRewriter1_17.java | 2 +- .../rewriter/EntityPacketRewriter1_17.java | 7 ++- .../v1_18to1_17_1/Protocol1_18To1_17_1.java | 8 ++- .../rewriter/EntityPacketRewriter1_18.java | 8 +-- .../Protocol1_19_3To1_19_1.java | 12 +++- .../BlockItemPacketRewriter1_19_3.java | 1 - .../Protocol1_19_4To1_19_3.java | 11 +++- .../BlockItemPacketRewriter1_19_4.java | 3 +- .../v1_19to1_18_2/Protocol1_19To1_18_2.java | 14 +++-- .../rewriter/BlockItemPacketRewriter1_19.java | 2 +- .../rewriter/EntityPacketRewriter1_19.java | 10 ++-- .../v1_20_2to1_20/Protocol1_20_2To1_20.java | 11 +++- .../BlockItemPacketRewriter1_20_2.java | 1 - .../Protocol1_20_3To1_20_2.java | 21 ++++--- .../BlockItemPacketRewriter1_20_3.java | 10 ++-- .../Protocol1_20_5To1_20_3.java | 7 +++ .../BlockItemPacketRewriter1_20_5.java | 7 +-- .../v1_20to1_19_4/Protocol1_20To1_19_4.java | 12 +++- .../rewriter/BlockItemPacketRewriter1_20.java | 11 ++-- .../v1_21_2to1_21/Protocol1_21_2To1_21.java | 9 +++ .../BlockItemPacketRewriter1_21_2.java | 29 +--------- .../rewriter/ParticleRewriter1_21_2.java | 57 +++++++++++++++++++ .../v1_21to1_20_5/Protocol1_21To1_20_5.java | 12 ++++ .../rewriter/BlockItemPacketRewriter1_21.java | 5 +- 41 files changed, 282 insertions(+), 127 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ParticleRewriter1_21_2.java diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java index e5a81d90..9869c7b9 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/BackwardsStructuredItemRewriter.java @@ -25,7 +25,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.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -35,7 +34,6 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.rewriter.StructuredItemRewriter; import java.util.ArrayList; import java.util.List; -import java.util.function.Function; import org.checkerframework.checker.nullness.qual.Nullable; public class BackwardsStructuredItemRewriter itemType, Type itemArrayType, Type mappedItemType, Type mappedItemArrayType, - Type itemCostType, Type optionalItemCostType, Type mappedItemCostType, Type mappedOptionalItemCostType, - Type particleType, Type mappedParticleType + Type itemCostType, Type optionalItemCostType, Type mappedItemCostType, Type mappedOptionalItemCostType ) { - super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, itemCostType, optionalItemCostType, mappedItemCostType, mappedOptionalItemCostType, particleType, mappedParticleType); + super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, itemCostType, optionalItemCostType, mappedItemCostType, mappedOptionalItemCostType); } public BackwardsStructuredItemRewriter(final T protocol, final Type itemType, final Type itemArrayType, final Type mappedItemType, final Type mappedItemArrayType) { diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java index a720700f..a0c6be46 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java @@ -185,7 +185,7 @@ public abstract class EntityRewriterBase { @@ -54,6 +57,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this, Types1_21_2.PARTICLE/*, Types1_OLD.PARTICLE*/); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -89,6 +93,10 @@ final class Protocol1_98To1_99 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TranslatableRewriter getComponentRewriter() { return translatableRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/Protocol1_13_1To1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/Protocol1_13_1To1_13.java index 2ed9918f..1ad6880d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/Protocol1_13_1To1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/Protocol1_13_1To1_13.java @@ -41,6 +41,7 @@ import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.v1_13to1_13_1.Protocol1_13To1_13_1; import com.viaversion.viaversion.rewriter.ComponentRewriter; +import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.util.ComponentUtil; @@ -50,6 +51,7 @@ public class Protocol1_13_1To1_13 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -72,6 +74,8 @@ public class Protocol1_13_1To1_13 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + public TranslatableRewriter translatableRewriter() { return translatableRewriter; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/EntityPacketRewriter1_13_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/EntityPacketRewriter1_13_1.java index b63a5bad..88e0a038 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/EntityPacketRewriter1_13_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/EntityPacketRewriter1_13_1.java @@ -22,8 +22,8 @@ import com.viaversion.viabackwards.protocol.v1_13_1to1_13.Protocol1_13_1To1_13; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; -import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; +import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_13; @@ -138,7 +138,7 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter { @@ -45,6 +46,7 @@ public class Protocol1_14To1_13_2 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); public Protocol1_14To1_13_2() { @@ -63,6 +65,8 @@ public class Protocol1_14To1_13_2 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TranslatableRewriter getComponentRewriter() { return translatableRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java index 8fe48094..6629d7f0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java @@ -18,6 +18,9 @@ package com.viaversion.viabackwards.protocol.v1_14to1_13_2.rewriter; import com.google.common.collect.ImmutableSet; +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.ListTag; +import com.viaversion.nbt.tag.StringTag; import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter; import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; @@ -35,8 +38,8 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; -import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; +import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13; @@ -45,9 +48,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13_2; import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.libs.gson.JsonObject; -import com.viaversion.nbt.tag.CompoundTag; -import com.viaversion.nbt.tag.ListTag; -import com.viaversion.nbt.tag.StringTag; import com.viaversion.viaversion.libs.gson.JsonParseException; import com.viaversion.viaversion.libs.mcstructs.text.utils.TextUtils; import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13; @@ -430,8 +430,6 @@ public class BlockItemPacketRewriter1_14 extends BackwardsItemRewriter { - rewriteParticle(event.user(), (Particle) data.getValue()); + protocol.getParticleRewriter().rewriteParticle(event.user(), (Particle) data.getValue()); }); filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, data) -> { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/Protocol1_15To1_14_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/Protocol1_15To1_14_4.java index b0ad6fe8..d0cce1a7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/Protocol1_15To1_14_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/Protocol1_15To1_14_4.java @@ -21,9 +21,9 @@ import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; -import com.viaversion.viabackwards.protocol.v1_15to1_14_4.storage.ImmediateRespawnStorage; import com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter.BlockItemPacketRewriter1_15; import com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter.EntityPacketRewriter1_15; +import com.viaversion.viabackwards.protocol.v1_15to1_14_4.storage.ImmediateRespawnStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.RegistryType; @@ -37,6 +37,7 @@ import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPac import com.viaversion.viaversion.protocols.v1_14_4to1_15.Protocol1_14_4To1_15; import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; import com.viaversion.viaversion.rewriter.ComponentRewriter; +import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -45,6 +46,7 @@ public class Protocol1_15To1_14_4 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -124,6 +126,11 @@ public class Protocol1_15To1_14_4 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TagRewriter getTagRewriter() { return tagRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/Protocol1_16_2To1_16_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/Protocol1_16_2To1_16_1.java index a78d15c5..e9313f29 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/Protocol1_16_2To1_16_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/Protocol1_16_2To1_16_1.java @@ -21,8 +21,8 @@ import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; -import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.rewriter.CommandRewriter1_16_2; import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.rewriter.BlockItemPacketRewriter1_16_2; +import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.rewriter.CommandRewriter1_16_2; import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.rewriter.EntityPacketRewriter1_16_2; import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.storage.BiomeStorage; import com.viaversion.viaversion.api.connection.UserConnection; @@ -38,6 +38,7 @@ import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.Protocol1_16_1To1_16_ import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ServerboundPackets1_16_2; import com.viaversion.viaversion.rewriter.ComponentRewriter; +import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.util.ProtocolLogger; @@ -48,6 +49,7 @@ public class Protocol1_16_2To1_16_1 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -67,6 +69,8 @@ public class Protocol1_16_2To1_16_1 extends BackwardsProtocol soundRewriter = new SoundRewriter<>(this); @@ -151,6 +155,11 @@ public class Protocol1_16_2To1_16_1 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TagRewriter getTagRewriter() { return tagRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/BlockItemPacketRewriter1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/BlockItemPacketRewriter1_16_2.java index bd371d0f..2f437f56 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/BlockItemPacketRewriter1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/BlockItemPacketRewriter1_16_2.java @@ -114,8 +114,6 @@ public class BlockItemPacketRewriter1_16_2 extends BackwardsItemRewriter handleItemToServer(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2))); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java index 136bf0fe..8cd66bf9 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/Protocol1_16To1_15_2.java @@ -19,14 +19,14 @@ package com.viaversion.viabackwards.protocol.v1_16to1_15_2; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; -import com.viaversion.viabackwards.protocol.v1_16to1_15_2.rewriter.TranslatableRewriter1_16; import com.viaversion.viabackwards.protocol.v1_16to1_15_2.data.BackwardsMappingData1_16; -import com.viaversion.viabackwards.protocol.v1_16to1_15_2.rewriter.CommandRewriter1_16; -import com.viaversion.viabackwards.protocol.v1_16to1_15_2.storage.PlayerAttributesStorage; -import com.viaversion.viabackwards.protocol.v1_16to1_15_2.storage.WorldNameTracker; import com.viaversion.viabackwards.protocol.v1_16to1_15_2.rewriter.BlockItemPacketRewriter1_16; +import com.viaversion.viabackwards.protocol.v1_16to1_15_2.rewriter.CommandRewriter1_16; import com.viaversion.viabackwards.protocol.v1_16to1_15_2.rewriter.EntityPacketRewriter1_16; +import com.viaversion.viabackwards.protocol.v1_16to1_15_2.rewriter.TranslatableRewriter1_16; +import com.viaversion.viabackwards.protocol.v1_16to1_15_2.storage.PlayerAttributesStorage; import com.viaversion.viabackwards.protocol.v1_16to1_15_2.storage.PlayerSneakStorage; +import com.viaversion.viabackwards.protocol.v1_16to1_15_2.storage.WorldNameTracker; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.RegistryType; @@ -43,6 +43,7 @@ import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPacke import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16; +import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.util.GsonUtil; @@ -53,6 +54,7 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter1_16 translatableRewriter = new TranslatableRewriter1_16(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -71,6 +73,8 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol { @@ -196,6 +200,11 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TagRewriter getTagRewriter() { return tagRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/rewriter/BlockItemPacketRewriter1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/rewriter/BlockItemPacketRewriter1_16.java index a5976495..69970dc4 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/rewriter/BlockItemPacketRewriter1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16to1_15_2/rewriter/BlockItemPacketRewriter1_16.java @@ -17,12 +17,18 @@ */ package com.viaversion.viabackwards.protocol.v1_16to1_15_2.rewriter; +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.IntArrayTag; +import com.viaversion.nbt.tag.ListTag; +import com.viaversion.nbt.tag.LongArrayTag; +import com.viaversion.nbt.tag.StringTag; +import com.viaversion.nbt.tag.Tag; import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter; import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter; import com.viaversion.viabackwards.api.rewriters.MapColorRewriter; +import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.storage.BiomeStorage; import com.viaversion.viabackwards.protocol.v1_16to1_15_2.Protocol1_16To1_15_2; import com.viaversion.viabackwards.protocol.v1_16to1_15_2.data.MapColorMappings1_15_2; -import com.viaversion.viabackwards.protocol.v1_16_2to1_16_1.storage.BiomeStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; @@ -33,12 +39,6 @@ import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_15; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16; import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14; -import com.viaversion.nbt.tag.CompoundTag; -import com.viaversion.nbt.tag.IntArrayTag; -import com.viaversion.nbt.tag.ListTag; -import com.viaversion.nbt.tag.LongArrayTag; -import com.viaversion.nbt.tag.StringTag; -import com.viaversion.nbt.tag.Tag; import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.ItemPacketRewriter1_16; @@ -179,8 +179,6 @@ public class BlockItemPacketRewriter1_16 extends BackwardsItemRewriter particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -254,6 +256,11 @@ public final class Protocol1_17To1_16_4 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TagRewriter getTagRewriter() { return tagRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/BlockItemPacketRewriter1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/BlockItemPacketRewriter1_17.java index ad4c87a2..10fbb3ef 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/BlockItemPacketRewriter1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/BlockItemPacketRewriter1_17.java @@ -204,7 +204,7 @@ public final class BlockItemPacketRewriter1_17 extends BackwardsItemRewriter { @@ -42,6 +42,7 @@ public final class Protocol1_18To1_17_1 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -151,6 +152,11 @@ public final class Protocol1_18To1_17_1 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TranslatableRewriter getComponentRewriter() { return translatableRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/EntityPacketRewriter1_18.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/EntityPacketRewriter1_18.java index 685ec209..7e060fdc 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/EntityPacketRewriter1_18.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/EntityPacketRewriter1_18.java @@ -17,6 +17,9 @@ */ package com.viaversion.viabackwards.protocol.v1_18to1_17_1.rewriter; +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.ListTag; +import com.viaversion.nbt.tag.StringTag; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.protocol.v1_18to1_17_1.Protocol1_18To1_17_1; import com.viaversion.viaversion.api.minecraft.Particle; @@ -28,9 +31,6 @@ import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_17; import com.viaversion.viaversion.api.type.types.version.Types1_18; import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPackets1_18; -import com.viaversion.nbt.tag.CompoundTag; -import com.viaversion.nbt.tag.ListTag; -import com.viaversion.nbt.tag.StringTag; import com.viaversion.viaversion.util.TagUtil; public final class EntityPacketRewriter1_18 extends EntityRewriter { @@ -110,7 +110,7 @@ public final class EntityPacketRewriter1_18 extends EntityRewriter particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -95,6 +96,8 @@ public final class Protocol1_19_3To1_19_1 extends BackwardsProtocol soundRewriter = new SoundRewriter<>(this); soundRewriter.registerStopSound(ClientboundPackets1_19_3.STOP_SOUND); registerClientbound(ClientboundPackets1_19_3.SOUND, wrapper -> { @@ -412,6 +415,11 @@ public final class Protocol1_19_3To1_19_1 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public EntityPacketRewriter1_19_3 getEntityRewriter() { return entityRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/BlockItemPacketRewriter1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/BlockItemPacketRewriter1_19_3.java index c42800b7..ea0147bf 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/BlockItemPacketRewriter1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/BlockItemPacketRewriter1_19_3.java @@ -54,7 +54,6 @@ public final class BlockItemPacketRewriter1_19_3 extends BackwardsItemRewriter particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -74,6 +76,8 @@ public final class Protocol1_19_4To1_19_3 extends BackwardsProtocol(this) { @Override public void handleArgument(final PacketWrapper wrapper, final String argumentType) { @@ -123,6 +127,11 @@ public final class Protocol1_19_4To1_19_3 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public EntityPacketRewriter1_19_4 getEntityRewriter() { return entityRewriter; @@ -137,4 +146,4 @@ public final class Protocol1_19_4To1_19_3 extends BackwardsProtocol getTagRewriter() { return tagRewriter; } -} \ No newline at end of file +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/BlockItemPacketRewriter1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/BlockItemPacketRewriter1_19_4.java index ea85e512..ed281470 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/BlockItemPacketRewriter1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/BlockItemPacketRewriter1_19_4.java @@ -73,7 +73,6 @@ public final class BlockItemPacketRewriter1_19_4 extends BackwardsItemRewriter recipeRewriter = new RecipeRewriter1_19_3<>(protocol) { @Override @@ -121,4 +120,4 @@ public final class BlockItemPacketRewriter1_19_4 extends BackwardsItemRewriter particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -386,6 +387,11 @@ public final class Protocol1_19To1_18_2 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TagRewriter getTagRewriter() { return tagRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/BlockItemPacketRewriter1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/BlockItemPacketRewriter1_19.java index a9254766..4f6b491e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/BlockItemPacketRewriter1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/BlockItemPacketRewriter1_19.java @@ -141,7 +141,7 @@ public final class BlockItemPacketRewriter1_19 extends BackwardsItemRewriter= 8) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/Protocol1_20_2To1_20.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/Protocol1_20_2To1_20.java index e240ba0d..422fdd2b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/Protocol1_20_2To1_20.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/Protocol1_20_2To1_20.java @@ -17,6 +17,7 @@ */ package com.viaversion.viabackwards.protocol.v1_20_2to1_20; +import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; @@ -36,7 +37,6 @@ import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.exception.CancelException; import com.viaversion.viaversion.exception.InformativeException; -import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4; @@ -46,6 +46,7 @@ import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundConfi import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundPackets1_20_2; import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2; import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPackets1_20_2; +import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import java.util.UUID; @@ -54,6 +55,7 @@ public final class Protocol1_20_2To1_20 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_20_2To1_20() { @@ -71,6 +73,8 @@ public final class Protocol1_20_2To1_20 extends BackwardsProtocol { final int slot = wrapper.read(Types.VAR_INT); wrapper.write(Types.BYTE, (byte) slot); @@ -225,6 +229,11 @@ public final class Protocol1_20_2To1_20 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TagRewriter getTagRewriter() { return tagRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java index 392cb6cb..15bede89 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java @@ -69,7 +69,6 @@ public final class BlockItemPacketRewriter1_20_2 extends BackwardsItemRewriter { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java index 9fdc0ae0..699c2b89 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/Protocol1_20_3To1_20_2.java @@ -17,6 +17,7 @@ */ package com.viaversion.viabackwards.protocol.v1_20_3to1_20_2; +import com.viaversion.nbt.tag.Tag; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; @@ -36,21 +37,21 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.libs.fastutil.Pair; -import com.viaversion.nbt.tag.Tag; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.rewriter.CommandRewriter1_19_4; -import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundConfigurationPackets1_20_2; -import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundPacket1_20_2; -import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundPackets1_20_2; -import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2; -import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPacket1_20_2; -import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPackets1_20_2; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.Protocol1_20_2To1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundConfigurationPackets1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPacket1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_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_20to1_20_2.packet.ClientboundConfigurationPackets1_20_2; +import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundPacket1_20_2; +import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ClientboundPackets1_20_2; +import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2; +import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPacket1_20_2; +import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPackets1_20_2; import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType; +import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.util.ComponentUtil; @@ -64,6 +65,7 @@ public final class Protocol1_20_3To1_20_2 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -392,6 +394,11 @@ public final class Protocol1_20_3To1_20_2 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public EntityPacketRewriter1_20_3 getEntityRewriter() { return entityRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java index b8023f40..3defb021 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/rewriter/BlockItemPacketRewriter1_20_3.java @@ -17,21 +17,19 @@ */ package com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.rewriter; -import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter; import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20_2; import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; 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.protocols.v1_20to1_20_2.packet.ServerboundPacket1_20_2; -import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPackets1_20_2; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPacket1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; +import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPacket1_20_2; +import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundPackets1_20_2; import com.viaversion.viaversion.rewriter.BlockRewriter; public final class BlockItemPacketRewriter1_20_3 extends BackwardsItemRewriter { @@ -87,7 +85,7 @@ public final class BlockItemPacketRewriter1_20_3 extends BackwardsItemRewriter particleRewriter = new ParticleRewriter<>(this); private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -247,6 +249,11 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TranslatableRewriter getComponentRewriter() { return translatableRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index 16f764e7..d3072043 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -50,7 +50,6 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPac import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.StructuredDataConverter; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.util.Key; -import java.util.function.Function; import org.checkerframework.checker.nullness.qual.Nullable; public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItemRewriter { @@ -108,7 +107,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem // Move it to the beginning, move out arguments here final Particle particle = wrapper.read(Types1_20_5.PARTICLE); - rewriteParticle(wrapper.user(), particle); + protocol.getParticleRewriter().rewriteParticle(wrapper.user(), particle); if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) { // Remove color argument final int color = particle.removeArgument(0).getValue(); @@ -144,8 +143,8 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem final Particle smallExplosionParticle = wrapper.passthroughAndMap(Types1_20_5.PARTICLE, Types1_20_3.PARTICLE); final Particle largeExplosionParticle = wrapper.passthroughAndMap(Types1_20_5.PARTICLE, Types1_20_3.PARTICLE); - rewriteParticle(wrapper.user(), smallExplosionParticle); - rewriteParticle(wrapper.user(), largeExplosionParticle); + protocol.getParticleRewriter().rewriteParticle(wrapper.user(), smallExplosionParticle); + protocol.getParticleRewriter().rewriteParticle(wrapper.user(), largeExplosionParticle); final Holder soundEventHolder = wrapper.read(Types.SOUND_EVENT); if (soundEventHolder.isDirect()) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/Protocol1_20To1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/Protocol1_20To1_19_4.java index e8a941ae..cadae68d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/Protocol1_20To1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/Protocol1_20To1_19_4.java @@ -26,12 +26,12 @@ import com.viaversion.viabackwards.protocol.v1_20to1_19_4.rewriter.EntityPacketR import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.RegistryType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ServerboundPackets1_19_4; import com.viaversion.viaversion.rewriter.ComponentRewriter; +import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.util.ArrayUtil; @@ -42,6 +42,7 @@ public final class Protocol1_20To1_19_4 extends BackwardsProtocol translatableRewriter = new TranslatableRewriter<>(this, ComponentRewriter.ReadType.JSON); private final EntityPacketRewriter1_20 entityRewriter = new EntityPacketRewriter1_20(this); private final BlockItemPacketRewriter1_20 itemRewriter = new BlockItemPacketRewriter1_20(this); + private final ParticleRewriter particleRewriter = new ParticleRewriter<>(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_20To1_19_4() { @@ -60,6 +61,8 @@ public final class Protocol1_20To1_19_4 extends BackwardsProtocol(this).register(ClientboundPackets1_19_4.AWARD_STATS); translatableRewriter.registerComponentPacket(ClientboundPackets1_19_4.SET_ACTION_BAR_TEXT); @@ -108,6 +111,11 @@ public final class Protocol1_20To1_19_4 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TranslatableRewriter getComponentRewriter() { return translatableRewriter; @@ -117,4 +125,4 @@ public final class Protocol1_20To1_19_4 extends BackwardsProtocol getTagRewriter() { return tagRewriter; } -} \ No newline at end of file +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/rewriter/BlockItemPacketRewriter1_20.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/rewriter/BlockItemPacketRewriter1_20.java index a25f34da..7d9e4d6d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/rewriter/BlockItemPacketRewriter1_20.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/rewriter/BlockItemPacketRewriter1_20.java @@ -17,6 +17,10 @@ */ package com.viaversion.viabackwards.protocol.v1_20to1_19_4.rewriter; +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.ListTag; +import com.viaversion.nbt.tag.StringTag; +import com.viaversion.nbt.tag.Tag; import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter; import com.viaversion.viabackwards.protocol.v1_20to1_19_4.Protocol1_20To1_19_4; import com.viaversion.viabackwards.protocol.v1_20to1_19_4.storage.BackSignEditStorage; @@ -28,10 +32,6 @@ import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; -import com.viaversion.nbt.tag.CompoundTag; -import com.viaversion.nbt.tag.ListTag; -import com.viaversion.nbt.tag.StringTag; -import com.viaversion.nbt.tag.Tag; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ServerboundPackets1_19_4; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.rewriter.RecipeRewriter1_19_4; @@ -100,7 +100,6 @@ public final class BlockItemPacketRewriter1_20 extends BackwardsItemRewriter { wrapper.passthrough(Types.BOOLEAN); // Reset/clear @@ -232,4 +231,4 @@ public final class BlockItemPacketRewriter1_20 extends BackwardsItemRewriter translatableRewriter = new ComponentRewriter1_21_2(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -79,6 +81,8 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol(this).register(ClientboundPackets1_21_2.AWARD_STATS); new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES); @@ -176,6 +180,11 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol getComponentRewriter() { return translatableRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 0bba1db1..9e8dac22 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -47,8 +47,7 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem public BlockItemPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) { super(protocol, Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY, - Types1_21_2.ITEM_COST, Types1_21_2.OPTIONAL_ITEM_COST, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, - Types1_21_2.PARTICLE, Types1_21.PARTICLE + Types1_21_2.ITEM_COST, Types1_21_2.OPTIONAL_ITEM_COST, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST ); } @@ -66,7 +65,6 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT); registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS); registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT); - registerLevelParticles1_20_5(ClientboundPackets1_21_2.LEVEL_PARTICLES); protocol.registerClientbound(ClientboundPackets1_21_2.COOLDOWN, wrapper -> { final MappingData mappingData = protocol.getMappingData(); @@ -171,7 +169,7 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem wrapper.write(Types.VAR_INT, 0); // Block interaction type final Particle explosionParticle = wrapper.read(Types1_21.PARTICLE); - rewriteParticle(wrapper.user(), explosionParticle); + protocol.getParticleRewriter().rewriteParticle(wrapper.user(), explosionParticle); // As small and large explosion particle wrapper.write(Types1_21_2.PARTICLE, explosionParticle); wrapper.write(Types1_21_2.PARTICLE, explosionParticle); @@ -250,29 +248,6 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem wrapper.write(Types.VAR_INT, intId); } - @Override - public void rewriteParticle(final UserConnection connection, final Particle particle) { - super.rewriteParticle(connection, particle); - - final String identifier = protocol.getMappingData().getParticleMappings().mappedIdentifier(particle.id()); - if (identifier.equals("minecraft:dust_color_transition")) { - argbToVector(particle, 0); - argbToVector(particle, 3); - } else if (identifier.equals("minecraft:dust")) { - argbToVector(particle, 0); - } - } - - private void argbToVector(final Particle particle, final int index) { - final int argb = particle.removeArgument(index).getValue(); - final float r = ((argb >> 16) & 0xFF) / 255F; - final float g = ((argb >> 8) & 0xFF) / 255F; - final float b = (argb & 0xFF) / 255F; - particle.add(index, Types.FLOAT, r); - particle.add(index + 1, Types.FLOAT, g); - particle.add(index + 2, Types.FLOAT, b); - } - @Override public Item handleItemToClient(final UserConnection connection, final Item item) { super.handleItemToClient(connection, item); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ParticleRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ParticleRewriter1_21_2.java new file mode 100644 index 00000000..a5ac14e1 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ParticleRewriter1_21_2.java @@ -0,0 +1,57 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter; + +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.Particle; +import com.viaversion.viaversion.api.protocol.Protocol; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.version.Types1_21; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.rewriter.ParticleRewriter; + +public final class ParticleRewriter1_21_2 extends ParticleRewriter { + + public ParticleRewriter1_21_2(final Protocol protocol) { + super(protocol, Types1_21_2.PARTICLE, Types1_21.PARTICLE); + } + + @Override + public void rewriteParticle(final UserConnection connection, final Particle particle) { + super.rewriteParticle(connection, particle); + + final String identifier = protocol.getMappingData().getParticleMappings().mappedIdentifier(particle.id()); + if (identifier.equals("minecraft:dust_color_transition")) { + argbToVector(particle, 0); + argbToVector(particle, 3); + } else if (identifier.equals("minecraft:dust")) { + argbToVector(particle, 0); + } + } + + private void argbToVector(final Particle particle, final int index) { + final int argb = particle.removeArgument(index).getValue(); + final float r = ((argb >> 16) & 0xFF) / 255F; + final float g = ((argb >> 8) & 0xFF) / 255F; + final float b = (argb & 0xFF) / 255F; + particle.add(index, Types.FLOAT, r); + particle.add(index + 1, Types.FLOAT, g); + particle.add(index + 2, Types.FLOAT, b); + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java index e18759c8..2dfafe16 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/Protocol1_21To1_20_5.java @@ -34,6 +34,8 @@ import com.viaversion.viaversion.api.minecraft.item.data.ChatType; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.version.Types1_20_5; +import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5; @@ -45,6 +47,7 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.util.ArrayUtil; @@ -56,6 +59,7 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this, Types1_21.PARTICLE, Types1_20_5.PARTICLE); private final TranslatableRewriter translatableRewriter = new ComponentRewriter1_21(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -75,6 +79,9 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol(this).register(ClientboundPackets1_21.AWARD_STATS); translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_ACTION_BAR_TEXT); @@ -206,6 +213,11 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol getParticleRewriter() { + return particleRewriter; + } + @Override public TranslatableRewriter getComponentRewriter() { return translatableRewriter; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java index 02091d06..4be17c25 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java @@ -63,8 +63,7 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe public BlockItemPacketRewriter1_21(final Protocol1_21To1_20_5 protocol) { super(protocol, Types1_21.ITEM, Types1_21.ITEM_ARRAY, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY, - Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_20_5.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST, - Types1_21.PARTICLE, Types1_20_5.PARTICLE + Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_20_5.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST ); } @@ -85,8 +84,6 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK); registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS); registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT); - registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES); - registerExplosion(ClientboundPackets1_21.EXPLODE); protocol.registerClientbound(ClientboundPackets1_21.OPEN_SCREEN, wrapper -> { wrapper.passthrough(Types.VAR_INT); // Id From 5a576d66b49b2adbc2d71e022fd7d0070c10f99c Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 28 Oct 2024 12:21:57 +0100 Subject: [PATCH 61/70] Update item type in area effect cloud particles in 1.13.2->1.13.1 --- .../rewriter/EntityPacketRewriter1_13_2.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_2to1_13_1/rewriter/EntityPacketRewriter1_13_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_2to1_13_1/rewriter/EntityPacketRewriter1_13_2.java index c77eed48..ef40175d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_2to1_13_1/rewriter/EntityPacketRewriter1_13_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_2to1_13_1/rewriter/EntityPacketRewriter1_13_2.java @@ -18,9 +18,12 @@ package com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.rewriter; import com.viaversion.viabackwards.protocol.v1_13_2to1_13_1.Protocol1_13_2To1_13_1; +import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; +import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType; +import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13_2; @@ -47,11 +50,7 @@ public class EntityPacketRewriter1_13_2 { map(Types.SHORT); // 11 - Velocity Z map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 12 - Entity data - handler(wrapper -> { - for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { - entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId())); - } - }); + handler(EntityPacketRewriter1_13_2::updateEntityData); } }); @@ -67,11 +66,7 @@ public class EntityPacketRewriter1_13_2 { map(Types.BYTE); // 6 - Pitch map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 7 - Entity data - handler(wrapper -> { - for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { - entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId())); - } - }); + handler(EntityPacketRewriter1_13_2::updateEntityData); } }); @@ -81,13 +76,23 @@ public class EntityPacketRewriter1_13_2 { map(Types.VAR_INT); // 0 - Entity ID map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 1 - Entity data list - handler(wrapper -> { - for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { - entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId())); - } - }); + handler(EntityPacketRewriter1_13_2::updateEntityData); } }); } + private static void updateEntityData(final PacketWrapper wrapper) { + for (final EntityData data : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { + final EntityDataType dataType = Types1_13.ENTITY_DATA_TYPES.byId(data.dataType().typeId()); + data.setDataType(dataType); + + if (dataType == Types1_13.ENTITY_DATA_TYPES.particleType) { + final Particle particle = data.value(); + if (particle.id() == 27) { + final Item item = particle.getArgument(0).getValue(); + particle.set(0, Types.ITEM1_13, item); + } + } + } + } } From d2d1d0014f86f8d49293382f25a450026a140b9c Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 29 Oct 2024 12:45:56 +0100 Subject: [PATCH 62/70] Remove instrument registry Some older clients don't like unknown registries --- .../rewriter/EntityPacketRewriter1_21_2.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 7b62ea6c..4f8b4486 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -24,6 +24,7 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viaversion.api.minecraft.Holder; import com.viaversion.viaversion.api.minecraft.Particle; +import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.SoundEvent; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2; @@ -41,6 +42,7 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.ClientVehicleStorage; import com.viaversion.viaversion.rewriter.RegistryDataRewriter; +import com.viaversion.viaversion.util.Key; import java.util.ArrayList; import java.util.BitSet; import java.util.List; @@ -98,7 +100,16 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter tag.putString("type", "damage_item")); - protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle); + protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> { + final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); + if (registryKey.equals("instrument")) { + wrapper.cancel(); + return; + } + + final RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY); + wrapper.write(Types.REGISTRY_ENTRY_ARRAY, registryDataRewriter.handle(wrapper.user(), registryKey, entries)); + }); protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, new PacketHandlers() { @Override From 80b530a3684b115f3eeb08863fa216a94ed8b649 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 29 Oct 2024 13:33:16 +0100 Subject: [PATCH 63/70] Fix trail particle handling --- .../rewriter/ParticleRewriter1_21_2.java | 7 ++++++- .../data/mappings-1.21.2to1.21.nbt | Bin 6356 -> 6356 bytes 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ParticleRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ParticleRewriter1_21_2.java index a5ac14e1..f40f0c06 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ParticleRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ParticleRewriter1_21_2.java @@ -34,14 +34,19 @@ public final class ParticleRewriter1_21_2 extends ParticleRewriterj5$2=1F``TmV$s1w8-& delta 25 dcmca&c*Sr-8z0YqAYfo%&;!w%C-FIP0RXRH4Ilsj From 368f450e113737e84d7fa8a7fc9ef4ac9409ebd7 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 29 Oct 2024 13:38:01 +0100 Subject: [PATCH 64/70] Remove lock item data in component rewriter --- .../protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java index e97a0c54..acc69d51 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/ComponentRewriter1_21_2.java @@ -65,6 +65,7 @@ public final class ComponentRewriter1_21_2 extends TranslatableRewriter Date: Tue, 29 Oct 2024 15:00:34 +0100 Subject: [PATCH 65/70] Add gradle task to quickly test/debug code changes (#902) --- .gitignore | 3 +++ common/build.gradle.kts | 24 ++++++++++++++++++++++++ gradle/libs.versions.toml | 3 ++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ab25b348..316241dc 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,6 @@ nbdist/ nbactions.xml nb-configuration.xml .nb-gradle/ + +### Run Folder (ViaProxy) ### +common/run/ diff --git a/common/build.gradle.kts b/common/build.gradle.kts index bb927cf6..d326ad8f 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -24,3 +24,27 @@ dependencies { java { withJavadocJar() } + +// Task to quickly test/debug code changes using https://github.com/ViaVersion/ViaProxy +// For further instructions see the ViaProxy repository README +tasks.register("runViaProxy") { + dependsOn(tasks.shadowJar) + + val viaProxyConfiguration = configurations.create("viaProxy") + viaProxyConfiguration.dependencies.add(dependencies.create(rootProject.libs.viaProxy.get().copy().setTransitive(false))) + + mainClass.set("net.raphimc.viaproxy.ViaProxy") + classpath = viaProxyConfiguration + workingDir = file("run") + + doFirst { + val jarsDir = file("$workingDir/jars") + jarsDir.mkdirs() + file("$jarsDir/${project.name}.jar").writeBytes(tasks.shadowJar.get().archiveFile.get().asFile.readBytes()) + } + + doLast { + file("$workingDir/jars/${project.name}.jar").delete() + file("$workingDir/logs").deleteRecursively() + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3c46969e..29850cb3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ checkerQual = "3.39.0" paper = "1.16.5-R0.1-SNAPSHOT" velocity = "3.1.1" fabricLoader = "0.11.6" - +viaProxy = "3.3.5-SNAPSHOT" [libraries] @@ -31,3 +31,4 @@ checkerQual = { group = "org.checkerframework", name = "checker-qual", version.r paper = { group = "com.destroystokyo.paper", name = "paper-api", version.ref = "paper" } velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" } fabricLoader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fabricLoader" } +viaProxy = { group = "net.raphimc", name = "ViaProxy", version.ref = "viaProxy" } From 562651cd9df742bf87ceb290b8ab51334415acf6 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Wed, 30 Oct 2024 10:20:24 +0100 Subject: [PATCH 66/70] [ci skip] Add component rewriter to template (#903) --- .../template/ComponentRewriter1_99.java | 48 +++++++++++++++++++ .../protocol/template/Protocol1_98To1_99.java | 6 +-- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java new file mode 100644 index 00000000..1a27d30b --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java @@ -0,0 +1,48 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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 . + */ +package com.viaversion.viabackwards.protocol.template; + +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.viabackwards.api.BackwardsProtocol; +import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.util.SerializerVersion; + +public class ComponentRewriter1_99 extends TranslatableRewriter { + + public ComponentRewriter1_99(final BackwardsProtocol protocol) { + super(protocol, ReadType.NBT); + } + + @Override + protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, final CompoundTag componentsTag) { + super.handleShowItem(connection, itemTag, componentsTag); + if (componentsTag == null) { + return; + } + + // Remove or update data from componentsTag + // New added data which is not handled otherwise needs to be removed to prevent errors on the client + } + + @Override + protected SerializerVersion inputSerializerVersion() { + return SerializerVersion.V1_20_5; + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java index ae0d0ae8..39865c8b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java @@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.template; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; -import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; @@ -34,7 +33,6 @@ import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; -import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType; import com.viaversion.viaversion.rewriter.ParticleRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -58,7 +56,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this, Types1_21_2.PARTICLE/*, Types1_OLD.PARTICLE*/); - private final TranslatableRewriter translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT); + private final ComponentRewriter1_99 translatableRewriter = new ComponentRewriter1_99(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_98To1_99() { @@ -125,7 +123,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol getComponentRewriter() { + public ComponentRewriter1_99 getComponentRewriter() { return translatableRewriter; } From 16aa6a51a20e0bbe38655ce91115edf44e5fa251 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 30 Oct 2024 10:20:56 +0100 Subject: [PATCH 67/70] Fix issues with creaking entity data Fixes #904 --- .../rewriter/EntityPacketRewriter1_21_2.java | 10 ++-------- .../data/mappings-1.21.2to1.21.nbt | Bin 6356 -> 6387 bytes 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java index 4f8b4486..0b19f6ac 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/EntityPacketRewriter1_21_2.java @@ -587,12 +587,6 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter { - if (event.index() > 7) { - event.cancel(); - } - }); - filter().type(EntityTypes1_21_2.ABSTRACT_BOAT).addIndex(11); // Boat type filter().type(EntityTypes1_21_2.SALMON).removeIndex(17); // Data type filter().type(EntityTypes1_21_2.AGEABLE_WATER_CREATURE).removeIndex(16); // Baby @@ -609,7 +603,7 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewritercoE From c7a5de11768299efc48515b4a84314c9a73f20d5 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 30 Oct 2024 16:52:52 +0100 Subject: [PATCH 68/70] Write inventory id as unsigned byte... --- .../v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 9e8dac22..40376f97 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -139,7 +139,7 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem }); protocol.registerClientbound(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY, ClientboundPackets1_21.CONTAINER_SET_SLOT, wrapper -> { - wrapper.write(Types.BYTE, (byte) -2); // Player inventory + wrapper.write(Types.UNSIGNED_BYTE, (short) -2); // Player inventory wrapper.write(Types.VAR_INT, 0); // 0 state id final int slot = wrapper.read(Types.VAR_INT); wrapper.write(Types.SHORT, (short) slot); From 7b5ee01929b4fff6b11d8f72ec5c6a2c6cd63952 Mon Sep 17 00:00:00 2001 From: RK_01 <50594595+RaphiMC@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:05:57 +0100 Subject: [PATCH 69/70] Fix SET_CURSOR_ITEM container id type (#905) --- .../v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java index 40376f97..3f4c08d6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_2to1_21/rewriter/BlockItemPacketRewriter1_21_2.java @@ -79,7 +79,7 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem }); protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, ClientboundPackets1_21.CONTAINER_SET_SLOT, wrapper -> { - wrapper.write(Types.BYTE, (byte) -1); // Player inventory + wrapper.write(Types.UNSIGNED_BYTE, (short) -1); // Player inventory wrapper.write(Types.VAR_INT, wrapper.user().get(InventoryStateIdStorage.class).stateId()); // State id; re-use the last known one wrapper.write(Types.SHORT, (short) -1); // Cursor final Item item = wrapper.passthrough(Types1_21_2.ITEM); From d6c27add17a627f9ca7ed646a0ce7299263db344 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 30 Oct 2024 21:07:30 +0100 Subject: [PATCH 70/70] Add viaproxy jvm flags --- common/build.gradle.kts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/build.gradle.kts b/common/build.gradle.kts index d326ad8f..87c49fa6 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -36,6 +36,11 @@ tasks.register("runViaProxy") { mainClass.set("net.raphimc.viaproxy.ViaProxy") classpath = viaProxyConfiguration workingDir = file("run") + jvmArgs = listOf("-DskipUpdateCheck") + + if (System.getProperty("viaproxy.gui.autoStart") != null) { + jvmArgs("-Dviaproxy.gui.autoStart") + } doFirst { val jarsDir = file("$workingDir/jars")