Skip to content

Commit 2b2384a

Browse files
committed
Remove new trim patterns in 1.20->1.19
Fixes #570
1 parent 643c6b1 commit 2b2384a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/BlockItemPackets1_20.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,28 @@
2323
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
2424
import com.viaversion.viaversion.api.minecraft.Position;
2525
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
26+
import com.viaversion.viaversion.api.minecraft.item.Item;
2627
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
2728
import com.viaversion.viaversion.api.type.Type;
2829
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
2930
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
31+
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
3032
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
3133
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type;
3234
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
3335
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4;
3436
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.rewriter.RecipeRewriter1_19_4;
3537
import com.viaversion.viaversion.rewriter.BlockRewriter;
38+
import com.viaversion.viaversion.util.Key;
39+
import java.util.Arrays;
40+
import java.util.HashSet;
41+
import java.util.Set;
42+
import org.checkerframework.checker.nullness.qual.Nullable;
3643

3744
public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1_19_4, ServerboundPackets1_19_4, Protocol1_19_4To1_20> {
3845

46+
private static final Set<String> NEW_TRIM_PATTERNS = new HashSet<>(Arrays.asList("host", "raiser", "shaper", "silence", "wayfinder"));
47+
3948
public BlockItemPackets1_20(final Protocol1_19_4To1_20 protocol) {
4049
super(protocol);
4150
}
@@ -140,6 +149,46 @@ public void register() {
140149
new RecipeRewriter1_19_4<>(protocol).register(ClientboundPackets1_19_4.DECLARE_RECIPES);
141150
}
142151

152+
@Override
153+
public @Nullable Item handleItemToClient(@Nullable final Item item) {
154+
if (item == null) {
155+
return null;
156+
}
157+
158+
super.handleItemToClient(item);
159+
160+
// Remove new trim tags
161+
final Tag trimTag;
162+
if (item.tag() != null && (trimTag = item.tag().get("Trim")) instanceof CompoundTag) {
163+
final Tag patternTag = ((CompoundTag) trimTag).get("pattern");
164+
if (patternTag instanceof StringTag) {
165+
final StringTag patternStringTag = (StringTag) patternTag;
166+
final String pattern = Key.stripMinecraftNamespace(patternStringTag.getValue());
167+
if (NEW_TRIM_PATTERNS.contains(pattern)) {
168+
item.tag().remove("Trim");
169+
item.tag().put(nbtTagName + "|Trim", trimTag);
170+
}
171+
}
172+
}
173+
return item;
174+
}
175+
176+
@Override
177+
public @Nullable Item handleItemToServer(@Nullable final Item item) {
178+
if (item == null) {
179+
return null;
180+
}
181+
182+
super.handleItemToServer(item);
183+
184+
// Add back original trim tag
185+
final Tag trimTag;
186+
if (item.tag() != null && (trimTag = item.tag().remove(nbtTagName + "|Trim")) != null) {
187+
item.tag().put("Trim", trimTag);
188+
}
189+
return item;
190+
}
191+
143192
private void handleBlockEntity(final BlockEntity blockEntity) {
144193
// Check for signs
145194
if (blockEntity.typeId() != 7 && blockEntity.typeId() != 8) {

0 commit comments

Comments
 (0)