Compare commits

...
9 Commits
23 changed files with 202 additions and 35 deletions

No files matched your search

@@ -22,6 +22,7 @@
*/
package com.viaversion.viaversion.api.minecraft;
import com.google.common.base.Preconditions;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
@@ -40,6 +41,7 @@ public interface HolderSet {
* @return a new holder set
*/
static HolderSet of(final String tagKey) {
Preconditions.checkNotNull(tagKey);
return new HolderSetImpl.Tag(tagKey);
}
@@ -50,6 +52,7 @@ public interface HolderSet {
* @return a new holder set
*/
static HolderSet of(final int[] ids) {
Preconditions.checkNotNull(ids);
return new HolderSetImpl.Ids(ids);
}
@@ -56,8 +56,8 @@ public record AttackRange(float minRange, float maxRange,
@Override
public void write(final Ops ops, final AttackRange AttackRange) {
ops.writeMap(map -> map
.writeOptional("min_range", Types.FLOAT, AttackRange.minRange, 0F)
.writeOptional("max_range", Types.FLOAT, AttackRange.maxRange, 3F)
.writeOptional("min_reach", Types.FLOAT, AttackRange.minRange, 0F)
.writeOptional("max_reach", Types.FLOAT, AttackRange.maxRange, 3F)
.writeOptional("min_creative_reach", Types.FLOAT, AttackRange.minCreativeRange, 0F)
.writeOptional("max_creative_reach", Types.FLOAT, AttackRange.maxCreativeRange, 5F)
.writeOptional("hitbox_margin", Types.FLOAT, AttackRange.hitboxMargin, 0.3F)
@@ -24,18 +24,11 @@ package com.viaversion.viaversion.api.minecraft.item.data;
import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.minecraft.RegistryKey;
import com.viaversion.viaversion.api.minecraft.codec.Ops;
import com.viaversion.viaversion.api.type.TransformingType;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.HolderSetType;
public record ProvidesBannerPatterns(HolderSet patterns) {
public static final Type<ProvidesBannerPatterns> TYPE = new TransformingType<>(Types.HOLDER_SET, ProvidesBannerPatterns.class, ProvidesBannerPatterns::new, ProvidesBannerPatterns::patterns) {
@Override
public void write(final Ops ops, final ProvidesBannerPatterns value) {
ops.writeMap(map -> map.write("items", new HolderSetType(RegistryKey.of("banner_pattern")), value.patterns));
}
};
public static final Type<ProvidesBannerPatterns> TYPE = TransformingType.of(new HolderSetType(RegistryKey.of("banner_pattern")), ProvidesBannerPatterns.class, ProvidesBannerPatterns::new, ProvidesBannerPatterns::patterns);
}
@@ -22,6 +22,8 @@
*/
package com.viaversion.viaversion.api.rewriter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.util.KeyMappings;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -31,4 +33,6 @@ public interface RegistryDataRewriter {
KeyMappings getMappings(String registryKey);
boolean shouldRemoveRegistry(String registryKey);
void updateDialog(UserConnection connection, CompoundTag tag);
}
@@ -107,6 +107,7 @@ import com.viaversion.viaversion.api.type.types.math.LowPrecisionVectorType;
import com.viaversion.viaversion.api.type.types.math.QuaternionType;
import com.viaversion.viaversion.api.type.types.math.Vector3fType;
import com.viaversion.viaversion.api.type.types.math.VectorType;
import com.viaversion.viaversion.api.type.types.misc.CompoundTagHolderType;
import com.viaversion.viaversion.api.type.types.misc.CompoundTagType;
import com.viaversion.viaversion.api.type.types.misc.GameProfileType;
import com.viaversion.viaversion.api.type.types.misc.HolderSetType;
@@ -207,6 +208,7 @@ public final class Types {
public static final Type<CompoundTag[]> NAMED_COMPOUND_TAG_ARRAY = new ArrayType<>(Types.NAMED_COMPOUND_TAG);
public static final Type<CompoundTag> COMPOUND_TAG = new CompoundTagType();
public static final Type<CompoundTag> OPTIONAL_COMPOUND_TAG = CompoundTagType.OptionalCompoundTagType.type();
public static final HolderType<CompoundTag> TRUSTED_COMPOUND_TAG_HOLDER = new CompoundTagHolderType();
public static final Type<Tag> TAG = new TagType();
public static final Type<Tag[]> TAG_ARRAY = new ArrayType<>(TAG);
@@ -0,0 +1,40 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.type.types.misc;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.type.Types;
import io.netty.buffer.ByteBuf;
public final class CompoundTagHolderType extends HolderType<CompoundTag> {
@Override
public CompoundTag readDirect(final ByteBuf buffer) {
return Types.TRUSTED_COMPOUND_TAG.read(buffer);
}
@Override
public void writeDirect(final ByteBuf buffer, final CompoundTag value) {
Types.TRUSTED_COMPOUND_TAG.write(buffer, value);
}
}
@@ -37,6 +37,11 @@ public class DebugSubCmd implements ViaSubCommand {
return "Toggle various debug modes.";
}
@Override
public String usage() {
return "debug [clear|pre|post], or debug <add|remove> <packet>";
}
@Override
public boolean execute(ViaCommandSender sender, String[] args) {
final DebugHandler debug = Via.getManager().debugHandler();
@@ -49,11 +54,11 @@ public class DebugSubCmd implements ViaSubCommand {
debug.clearPacketTypesToLog();
sendMessage(sender, "&6Cleared packet types to log");
return true;
} else if (args[0].equalsIgnoreCase("logpretransform")) {
} else if (args[0].equalsIgnoreCase("pre")) {
debug.setLogPrePacketTransform(!debug.logPrePacketTransform());
sendMessage(sender, "&6Pre transform packet logging is now %s", (debug.logPrePacketTransform() ? "&aenabled" : "&cdisabled"));
return true;
} else if (args[0].equalsIgnoreCase("logposttransform")) {
} else if (args[0].equalsIgnoreCase("post")) {
debug.setLogPostPacketTransform(!debug.logPostPacketTransform());
sendMessage(sender, "&6Post transform packet logging is now %s", (debug.logPostPacketTransform() ? "&aenabled" : "&cdisabled"));
return true;
@@ -75,7 +80,7 @@ public class DebugSubCmd implements ViaSubCommand {
@Override
public List<String> onTabComplete(final ViaCommandSender sender, final String[] args) {
if (args.length == 1) {
return Arrays.asList("clear", "logposttransform", "add", "remove");
return Arrays.asList("clear", "pre", "post", "add", "remove");
}
return Collections.emptyList();
}
@@ -37,7 +37,7 @@ public class DisplayLeaksSubCmd implements ViaSubCommand {
@Override
public String usage() {
return "displayleaks <level>";
return "displayleaks [level]";
}
@Override
@@ -116,6 +116,8 @@ public class ItemHasherBase implements ItemHasher {
entry.setValue(clientProvidedHash);
}
}
originalItem.setAmount(clientItem.amount());
return originalItem;
}
@@ -599,11 +599,12 @@ public class PacketWrapperImpl implements PacketWrapper {
@Override
public void consumeReadsOnly(final Runnable runnable) {
final boolean previous = this.allActionsRead;
this.allActionsRead = true;
try {
runnable.run();
} finally {
this.allActionsRead = false;
this.allActionsRead = previous;
}
}
@@ -47,6 +47,7 @@ import com.viaversion.viaversion.protocols.v1_21_11to26_1.packet.ServerboundPack
import com.viaversion.viaversion.protocols.v1_21_11to26_1.rewriter.BlockItemPacketRewriter26_1;
import com.viaversion.viaversion.protocols.v1_21_11to26_1.rewriter.ComponentRewriter26_1;
import com.viaversion.viaversion.protocols.v1_21_11to26_1.rewriter.EntityPacketRewriter26_1;
import com.viaversion.viaversion.protocols.v1_21_11to26_1.storage.TagsSent;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundPackets1_21_6;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ClientboundConfigurationPackets1_21_9;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ServerboundConfigurationPackets1_21_9;
@@ -93,6 +94,13 @@ public final class Protocol1_21_11To26_1 extends AbstractProtocol<ClientboundPac
sendSoundVariants(wrapper, "cow_sound_variant", MAPPINGS.cowSoundVariants());
sendSoundVariants(wrapper, "pig_sound_variant", MAPPINGS.pigSoundVariants());
sendSoundVariants(wrapper, "chicken_sound_variant", MAPPINGS.chickenSoundVariants());
// Make sure the client gets damage types and banner patterns, even if the server doesn't send tags
if (!wrapper.user().has(TagsSent.class)) {
final PacketWrapper tagsPacket = wrapper.create(ClientboundConfigurationPackets1_21_9.UPDATE_TAGS);
tagsPacket.write(Types.VAR_INT, 0);
tagsPacket.send(Protocol1_21_11To26_1.class, false);
}
});
addRequiredRegistryEntries();
@@ -136,8 +144,8 @@ public final class Protocol1_21_11To26_1 extends AbstractProtocol<ClientboundPac
});
registerClientbound(ClientboundConfigurationPackets1_21_9.REGISTRY_DATA, registryDataRewriter::handle);
tagRewriter.registerGeneric(ClientboundPackets1_21_11.UPDATE_TAGS);
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21_9.UPDATE_TAGS);
registerClientbound(ClientboundPackets1_21_11.UPDATE_TAGS, this::handleTags);
registerClientbound(ClientboundConfigurationPackets1_21_9.UPDATE_TAGS, this::handleTags);
componentRewriter.registerOpenScreen1_14(ClientboundPackets1_21_11.OPEN_SCREEN);
componentRewriter.registerComponentPacket(ClientboundPackets1_21_11.SET_ACTION_BAR_TEXT);
@@ -179,6 +187,11 @@ public final class Protocol1_21_11To26_1 extends AbstractProtocol<ClientboundPac
cancelServerbound(ServerboundPackets26_1.SET_GAME_RULE);
}
private void handleTags(final PacketWrapper wrapper) {
tagRewriter.handleGeneric(wrapper);
wrapper.user().put(new TagsSent());
}
private void sendSoundVariants(final PacketWrapper wrapper, final String key, final CompoundTag tag) {
final PacketWrapper clocksPacket = wrapper.create(ClientboundConfigurationPackets1_21_9.REGISTRY_DATA);
clocksPacket.write(Types.STRING, key);
@@ -43,6 +43,7 @@ import com.viaversion.viaversion.protocols.v1_21_11to26_1.Protocol1_21_11To26_1;
import com.viaversion.viaversion.protocols.v1_21_11to26_1.packet.ServerboundPacket26_1;
import com.viaversion.viaversion.protocols.v1_21_11to26_1.packet.ServerboundPackets26_1;
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.rewriter.RecipeDisplayRewriter1_21_5;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ClientboundConfigurationPackets1_21_9;
import com.viaversion.viaversion.protocols.v1_21_9to1_21_11.packet.ClientboundPacket1_21_11;
import com.viaversion.viaversion.protocols.v1_21_9to1_21_11.packet.ClientboundPackets1_21_11;
import com.viaversion.viaversion.rewriter.BlockRewriter;
@@ -92,6 +93,8 @@ public final class BlockItemPacketRewriter26_1 extends StructuredItemRewriter<Cl
registerMerchantOffers1_20_5(ClientboundPackets1_21_11.MERCHANT_OFFERS);
registerContainerClick1_21_5(ServerboundPackets26_1.CONTAINER_CLICK);
registerSetCreativeModeSlot1_21_5(ServerboundPackets26_1.SET_CREATIVE_MODE_SLOT);
registerShowDialog(ClientboundPackets1_21_11.SHOW_DIALOG);
registerShowDialogDirect(ClientboundConfigurationPackets1_21_9.SHOW_DIALOG);
final RecipeDisplayRewriter<ClientboundPacket1_21_11> recipeRewriter = new RecipeDisplayRewriter1_21_5<>(protocol);
recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_11.UPDATE_RECIPES);
@@ -0,0 +1,23 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2026 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 <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.v1_21_11to26_1.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
public final class TagsSent implements StorableObject {
}
@@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.v1_21_6to1_21_7.rewriter;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_21_5;
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.rewriter.RecipeDisplayRewriter1_21_5;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundConfigurationPackets1_21_6;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPacket1_21_6;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPackets1_21_6;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundPacket1_21_6;
@@ -54,6 +55,8 @@ public final class BlockItemPacketRewriter1_21_7 extends StructuredItemRewriter<
registerMerchantOffers1_20_5(ClientboundPackets1_21_6.MERCHANT_OFFERS);
registerContainerClick1_21_5(ServerboundPackets1_21_6.CONTAINER_CLICK);
registerSetCreativeModeSlot1_21_5(ServerboundPackets1_21_6.SET_CREATIVE_MODE_SLOT);
registerShowDialog(ClientboundPackets1_21_6.SHOW_DIALOG);
registerShowDialogDirect(ClientboundConfigurationPackets1_21_6.SHOW_DIALOG);
final RecipeDisplayRewriter<ClientboundPacket1_21_6> recipeRewriter = new RecipeDisplayRewriter1_21_5<>(protocol);
recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_6.UPDATE_RECIPES);
@@ -31,6 +31,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_21_5;
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.rewriter.RecipeDisplayRewriter1_21_5;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundConfigurationPackets1_21_6;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPacket1_21_6;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ClientboundPackets1_21_6;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundPackets1_21_6;
@@ -68,6 +69,8 @@ public final class BlockItemPacketRewriter1_21_9 extends StructuredItemRewriter<
registerMerchantOffers1_20_5(ClientboundPackets1_21_6.MERCHANT_OFFERS);
registerContainerClick1_21_5(ServerboundPackets1_21_6.CONTAINER_CLICK);
registerSetCreativeModeSlot1_21_5(ServerboundPackets1_21_6.SET_CREATIVE_MODE_SLOT);
registerShowDialog(ClientboundPackets1_21_6.SHOW_DIALOG);
registerShowDialogDirect(ClientboundConfigurationPackets1_21_6.SHOW_DIALOG);
final RecipeDisplayRewriter<ClientboundPacket1_21_6> recipeRewriter = new RecipeDisplayRewriter1_21_5<>(protocol);
recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_6.UPDATE_RECIPES);
@@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_21_5;
import com.viaversion.viaversion.protocols.v1_21_4to1_21_5.rewriter.RecipeDisplayRewriter1_21_5;
import com.viaversion.viaversion.protocols.v1_21_5to1_21_6.packet.ServerboundPackets1_21_6;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ClientboundConfigurationPackets1_21_9;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ClientboundPacket1_21_9;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ClientboundPackets1_21_9;
import com.viaversion.viaversion.protocols.v1_21_7to1_21_9.packet.ServerboundPacket1_21_9;
@@ -64,6 +65,8 @@ public final class BlockItemPacketRewriter1_21_11 extends StructuredItemRewriter
registerMerchantOffers1_20_5(ClientboundPackets1_21_9.MERCHANT_OFFERS);
registerContainerClick1_21_5(ServerboundPackets1_21_6.CONTAINER_CLICK);
registerSetCreativeModeSlot1_21_5(ServerboundPackets1_21_6.SET_CREATIVE_MODE_SLOT);
registerShowDialog(ClientboundPackets1_21_9.SHOW_DIALOG);
registerShowDialogDirect(ClientboundConfigurationPackets1_21_9.SHOW_DIALOG);
final RecipeDisplayRewriter<ClientboundPacket1_21_9> recipeRewriter = new RecipeDisplayRewriter1_21_5<>(protocol);
recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_9.UPDATE_RECIPES);
@@ -126,7 +126,6 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
final ItemHasherBase itemHasher = itemHasher(connection);
final HashedItem originalHashedItem = itemHasher.originalHashedItem(customDataHash, item);
if (originalHashedItem != null) {
originalHashedItem.setAmount(item.amount());
return originalHashedItem;
}
}
@@ -43,7 +43,7 @@ public class RecipeDisplayRewriter<C extends ClientboundPacketType> {
slotDisplayHandlers.put("item", this::handleItemId);
slotDisplayHandlers.put("item_stack", this::handleItem);
slotDisplayHandlers.put("tag", wrapper -> wrapper.passthrough(Types.STRING));
slotDisplayHandlers.put("dye", this::handleDyeSlotDisplay);
slotDisplayHandlers.put("dyed", this::handleDyedSlotDisplay);
slotDisplayHandlers.put("smithing_trim", this::handleSmithingTrimSlotDisplay);
slotDisplayHandlers.put("with_remainder", this::handleWithRemainderSlotDisplay);
slotDisplayHandlers.put("composite", this::handleSlotDisplayList);
@@ -143,14 +143,17 @@ public class RecipeDisplayRewriter<C extends ClientboundPacketType> {
final FullMappings mappings = protocol.getMappingData().getSlotDisplayMappings();
final int type = wrapper.read(Types.VAR_INT);
final int mappedType = mappings.getNewId(type);
if (mappedType == -1) {
// Write dummy
if (mappedType != -1) {
wrapper.write(Types.VAR_INT, mappedType);
runSlotDisplayHandler(wrapper, mappings, type);
} else {
// Write a dummy item if needed
wrapper.write(Types.VAR_INT, 0);
return;
wrapper.consumeReadsOnly(() -> runSlotDisplayHandler(wrapper, mappings, type));
}
}
wrapper.write(Types.VAR_INT, mappedType);
private void runSlotDisplayHandler(final PacketWrapper wrapper, final FullMappings mappings, final int type) {
final String identifier = mappings.identifier(type); // use the original type
final SlotDisplayConsumer handler = slotDisplayHandlers.get(Key.stripMinecraftNamespace(identifier));
if (handler != null) {
@@ -182,7 +185,7 @@ public class RecipeDisplayRewriter<C extends ClientboundPacketType> {
wrapper.write(Types.VAR_INT, mappedDataComponentType);
}
protected void handleDyeSlotDisplay(final PacketWrapper wrapper) {
protected void handleDyedSlotDisplay(final PacketWrapper wrapper) {
handleSlotDisplay(wrapper); // Dye
handleSlotDisplay(wrapper); // Target
}
@@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.data.entity.DimensionData;
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.rewriter.ComponentRewriter;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.DimensionDataImpl;
import com.viaversion.viaversion.util.Key;
@@ -82,6 +83,7 @@ public class RegistryDataRewriter implements com.viaversion.viaversion.api.rewri
case "trim_material" -> updateTrimMaterials(entries);
case "jukebox_song" -> updateJukeboxSongs(entries);
case "worldgen/biome" -> updateBiomes(entries);
case "dialog" -> updateDialogs(connection, entries);
}
final BiConsumer<String, CompoundTag> registryEntryHandler = this.registryEntryHandlers.get(key);
@@ -158,6 +160,54 @@ public class RegistryDataRewriter implements com.viaversion.viaversion.api.rewri
}
}
public void updateDialogs(final UserConnection connection, final RegistryEntry[] entries) {
if (protocol.getMappingData() != null && protocol.getMappingData().getFullItemMappings() == null) {
return;
}
for (final RegistryEntry entry : entries) {
if (entry.tag() != null) {
updateDialog(connection, (CompoundTag) entry.tag());
}
}
}
@Override
public void updateDialog(final UserConnection connection, final CompoundTag tag) {
final ListTag<CompoundTag> bodiesTag = tag.getListTag("body", CompoundTag.class);
if (bodiesTag == null) {
final CompoundTag bodyTag = tag.getCompoundTag("body");
if (bodyTag != null) {
updateDialogBody(connection, bodyTag); // inlined
}
return;
}
for (final CompoundTag entry : bodiesTag) {
updateDialogBody(connection, entry);
}
}
public void updateDialogBody(final UserConnection connection, final CompoundTag tag) {
final String type = tag.getString("type");
if (!Key.equals(type, "item")) {
return;
}
final StringTag itemTag = tag.getStringTag("item");
if (itemTag != null) {
final String mappedId = protocol.getMappingData().getFullItemMappings().mappedIdentifier(itemTag.getValue());
if (mappedId != null) {
itemTag.setValue(mappedId);
}
return;
}
final ComponentRewriter componentRewriter = protocol.getComponentRewriter();
if (componentRewriter != null) {
componentRewriter.handleShowItem(connection, tag.getCompoundTag("item"));
}
}
public void updateEnchantments(final UserConnection connection, final RegistryEntry[] entries) {
final List<String> identifiers = new ArrayList<>(entries.length);
for (final RegistryEntry entry : entries) {
@@ -60,7 +60,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
* Rewrites an item to the client, including item hash tracking if necessary.
*
* @param connection user connection
* @param item item
* @param item item
* @return the rewritten item, can be the same or a new object
* @see #handleItemDataComponentsToClient(UserConnection, Item, StructuredDataContainer)
* @see #handleItemToServer(UserConnection, Item)
@@ -112,9 +112,10 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
return;
}
// Always has to be AFTER any modification - Use the custom_data hash as a key to the original hashes.
// Always has to be AFTER any modification - Use the custom_data hash as a key to the original data (excluding amount, as that will simply be when copying).
// This is much easier/cheaper than tracking via the full hashed item, as collisions are both acceptable and still unlikely.
final CompoundTag originalHashes = new CompoundTag();
originalHashes.putInt("id", originalHashedItem.identifier());
for (final Int2IntMap.Entry entry : originalHashedItem.dataHashesById().int2IntEntrySet()) {
originalHashes.putInt(Integer.toString(entry.getIntKey()), entry.getIntValue());
}
@@ -169,8 +170,8 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
* Always remember to call the super method.
*
* @param connection user connection
* @param item item to update
* @param container item data container
* @param item item to update
* @param container item data container
*/
protected void handleItemDataComponentsToClient(final UserConnection connection, final Item item, final StructuredDataContainer container) {
if (protocol.getComponentRewriter() != null) {
@@ -288,8 +289,8 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
/**
* Stores inconvertible data in a backup tag. Called before data component modification to the item.
*
* @param connection user connection
* @param item item to save data for
* @param connection user connection
* @param item item to save data for
* @param dataContainer item data container
*/
protected void backupInconvertibleData(final UserConnection connection, final Item item, final StructuredDataContainer dataContainer, final CompoundTag backupTag) {
@@ -298,8 +299,8 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
/**
* Restored inconvertible backup data from the item. Called after rewritables and before the remaining data component modification.
*
* @param item item
* @param container item data container
* @param item item
* @param container item data container
* @param customData custom data tag
*/
protected void restoreBackupData(final Item item, final StructuredDataContainer container, final CompoundTag customData) {
@@ -394,4 +395,20 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
passthroughLengthPrefixedItem(wrapper);
});
}
public void registerShowDialog(C packetType) {
protocol.registerClientbound(packetType, wrapper -> {
final Holder<CompoundTag> holder = wrapper.passthrough(Types.TRUSTED_COMPOUND_TAG_HOLDER);
if (holder.isDirect()) {
protocol.getRegistryDataRewriter().updateDialog(wrapper.user(), holder.value());
}
});
}
public void registerShowDialogDirect(C packetType) {
protocol.registerClientbound(packetType, wrapper -> {
final CompoundTag dialogTag = wrapper.passthrough(Types.TRUSTED_COMPOUND_TAG);
protocol.getRegistryDataRewriter().updateDialog(wrapper.user(), dialogTag);
});
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
projectVersion=5.8.0
projectVersion=5.8.1
# Smile emoji (note that modrinth may not have added the version on release yet)
mcVersions=26.1, 1.21.11, 1.21.10, 1.21.9, 1.21.8, 1.21.7, 1.21.6, 1.21.5, 1.21.4, 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, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9
+1 -1
View File
@@ -6,7 +6,7 @@ gson = "2.13.2"
snakeYaml = "2.5"
fastutil = "8.5.15"
vianbt = "5.2.0"
mcstructs = "5-3.2.2-SNAPSHOT"
mcstructs = "5-3.3.1-SNAPSHOT"
# Common provided
netty = "4.0.20.Final"