|
23 | 23 | import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
24 | 24 | import com.viaversion.viaversion.api.minecraft.Position;
|
25 | 25 | import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
|
| 26 | +import com.viaversion.viaversion.api.minecraft.item.Item; |
26 | 27 | import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
27 | 28 | import com.viaversion.viaversion.api.type.Type;
|
28 | 29 | import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
29 | 30 | import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
| 31 | +import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; |
30 | 32 | import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
31 | 33 | import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type;
|
32 | 34 | import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
|
33 | 35 | import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4;
|
34 | 36 | import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.rewriter.RecipeRewriter1_19_4;
|
35 | 37 | 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; |
36 | 43 |
|
37 | 44 | public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1_19_4, ServerboundPackets1_19_4, Protocol1_19_4To1_20> {
|
38 | 45 |
|
| 46 | + private static final Set<String> NEW_TRIM_PATTERNS = new HashSet<>(Arrays.asList("host", "raiser", "shaper", "silence", "wayfinder")); |
| 47 | + |
39 | 48 | public BlockItemPackets1_20(final Protocol1_19_4To1_20 protocol) {
|
40 | 49 | super(protocol);
|
41 | 50 | }
|
@@ -140,6 +149,46 @@ public void register() {
|
140 | 149 | new RecipeRewriter1_19_4<>(protocol).register(ClientboundPackets1_19_4.DECLARE_RECIPES);
|
141 | 150 | }
|
142 | 151 |
|
| 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 | + |
143 | 192 | private void handleBlockEntity(final BlockEntity blockEntity) {
|
144 | 193 | // Check for signs
|
145 | 194 | if (blockEntity.typeId() != 7 && blockEntity.typeId() != 8) {
|
|
0 commit comments