From dca8ecf1db8ec904208d6566804082afc8dbee87 Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:28:40 +0100 Subject: [PATCH 1/4] Fix notes color from note block being wrong in 1.13->1.12 (#680) Closes https://github.com/ViaVersion/ViaBackwards/issues/679 --- .../Protocol1_12_2To1_13.java | 3 ++ .../packets/BlockItemPackets1_13.java | 19 +++++++ .../packets/EntityPackets1_13.java | 6 ++- .../storage/NoteBlockStorage.java | 50 +++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/NoteBlockStorage.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java index e3eec36c..fc34c976 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/Protocol1_12_2To1_13.java @@ -29,6 +29,7 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.PlayerP import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.packets.SoundPackets1_13; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; +import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.TabCompleteStorage; import com.viaversion.viaversion.api.Via; @@ -124,6 +125,8 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol= 483 && blockId <= 498) blockId = blockId - 483 + 219; + if (blockId == 25) { // Note block + final NoteBlockStorage noteBlockStorage = wrapper.user().get(NoteBlockStorage.class); + + final Position position = wrapper.get(Type.POSITION1_8, 0); + final Pair update = noteBlockStorage.getNoteBlockUpdate(position); + if (update != null) { // Use values from block state update + wrapper.set(Type.UNSIGNED_BYTE, 0, update.key().shortValue()); + wrapper.set(Type.UNSIGNED_BYTE, 1, update.value().shortValue()); + } + } + wrapper.set(Type.VAR_INT, 0, blockId); }); } @@ -189,6 +203,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit int blockState = wrapper.read(Type.VAR_INT); Position position = wrapper.get(Type.POSITION1_8, 0); + // Note block special treatment + if (blockState >= 249 && blockState <= 748) { // Note block states id range + wrapper.user().get(NoteBlockStorage.class).storeNoteBlockUpdate(position, blockState); + } + // Store blocks BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class); storage.checkAndStore(position, blockState); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java index c12b4590..b07c224d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java @@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityType import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.PaintingMapping; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.ParticleMapping; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; +import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.NoteBlockStorage; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.PlayerPositionStorage1_13; import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.entities.EntityType; @@ -197,7 +198,10 @@ public class EntityPackets1_13 extends LegacyEntityRewriter wrapper.user().get(BackwardsBlockStorage.class).clear()); + handler(wrapper -> { + wrapper.user().get(BackwardsBlockStorage.class).clear(); + wrapper.user().get(NoteBlockStorage.class).clear(); + }); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/NoteBlockStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/NoteBlockStorage.java new file mode 100644 index 00000000..a31725c6 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/NoteBlockStorage.java @@ -0,0 +1,50 @@ +/* + * 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.protocol1_12_2to1_13.storage; + +import com.viaversion.viaversion.api.connection.StorableObject; +import com.viaversion.viaversion.api.minecraft.Position; +import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap; +import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap; +import com.viaversion.viaversion.util.Pair; + +public class NoteBlockStorage implements StorableObject { + + private static final int MAX_NOTE_ID = 24; + + private final Object2IntMap noteBlockUpdates = new Object2IntOpenHashMap<>(); + + public void storeNoteBlockUpdate(final Position position, final int blockStateId) { + noteBlockUpdates.put(position, blockStateId); + } + + public Pair getNoteBlockUpdate(final Position position) { + if (!noteBlockUpdates.containsKey(position)) { + return null; + } + int relativeBlockState = noteBlockUpdates.removeInt(position) - 249; + relativeBlockState = relativeBlockState / 2; // Get rid of powered state + + return new Pair<>(relativeBlockState / MAX_NOTE_ID + 1, relativeBlockState % MAX_NOTE_ID + 1); + } + + public void clear() { + noteBlockUpdates.clear(); + } + +} From e9c3889c820522a1eaf86f61e17fa26fb0dd3885 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 11 Feb 2024 10:39:06 +0100 Subject: [PATCH 2/4] Add editorconfig --- .editorconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..7730dd6b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +insert_final_newline = false +tab_width = 4 + +[*.java] +ij_java_class_count_to_use_import_on_demand = 999999 +ij_java_names_count_to_use_import_on_demand = 999999 +ij_java_imports_layout = *,|,$* +ij_java_generate_final_locals = true +ij_java_generate_final_parameters = true \ No newline at end of file From 9241213fb543761beebe3770219419885f49ae9d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 11 Feb 2024 10:42:44 +0100 Subject: [PATCH 3/4] Replace tag instanceof/unchecked casts with helper methods --- .../viabackwards/api/BackwardsProtocol.java | 2 +- .../api/entities/storage/EntityData.java | 10 +- .../storage/EntityPositionHandler.java | 2 +- .../api/rewriters/EnchantmentRewriter.java | 25 +- .../api/rewriters/EntityRewriterBase.java | 12 +- .../api/rewriters/ItemRewriter.java | 34 ++- .../api/rewriters/ItemRewriterBase.java | 18 +- .../rewriters/LegacyBlockItemRewriter.java | 39 ++-- .../rewriters/LegacyEnchantmentRewriter.java | 59 +++-- .../packets/BlockItemPackets1_11.java | 20 +- .../packets/EntityPackets1_11.java | 2 +- .../data/ShoulderTracker.java | 4 +- .../packets/BlockItemPackets1_12.java | 2 +- .../packets/EntityPackets1_12.java | 11 +- .../packets/EntityPackets1_11_1.java | 2 +- .../packets/ItemPackets1_11_1.java | 9 +- .../block_entity_handlers/BannerHandler.java | 17 +- .../block_entity_handlers/BedHandler.java | 3 +- .../FlowerPotHandler.java | 6 +- .../block_entity_handlers/PistonHandler.java | 21 +- .../block_entity_handlers/SkullHandler.java | 5 +- .../block_entity_handlers/SpawnerHandler.java | 13 +- .../data/EntityNameRewrites.java | 1 - .../data/NamedSoundMapping.java | 1 - .../data/ParticleMapping.java | 166 ++++++------- .../packets/BlockItemPackets1_13.java | 220 +++++++++--------- .../packets/EntityPackets1_13.java | 4 +- .../BackwardsBlockEntityProvider.java | 17 +- .../packets/BlockItemPackets1_14.java | 8 +- .../packets/EntityPackets1_14.java | 2 +- .../Protocol1_13To1_13_1.java | 2 +- .../packets/EntityPackets1_15.java | 4 +- .../packets/EntityPackets1_14_1.java | 2 +- .../chat/TranslatableRewriter1_16.java | 36 +-- .../packets/BlockItemPackets1_16.java | 38 ++- .../packets/EntityPackets1_16.java | 6 +- .../packets/BlockItemPackets1_16_2.java | 18 +- .../packets/EntityPackets1_16_2.java | 11 +- .../packets/BlockItemPackets1_17.java | 2 +- .../packets/EntityPackets1_17.java | 18 +- .../packets/BlockItemPackets1_18.java | 28 ++- .../packets/EntityPackets1_18.java | 11 +- .../Protocol1_17To1_17_1.java | 8 +- .../Protocol1_18_2To1_19.java | 1 - .../packets/BlockItemPackets1_19.java | 4 +- .../packets/EntityPackets1_19.java | 10 +- .../packets/EntityPackets1_19_3.java | 7 +- .../packets/EntityPackets1_19_4.java | 9 +- .../packets/BlockItemPackets1_20.java | 36 +-- .../packets/EntityPackets1_20.java | 13 +- .../Protocol1_19To1_19_1.java | 4 +- .../packets/EntityPackets1_19_1.java | 2 +- .../BlockItemPacketRewriter1_20_3.java | 6 +- .../rewriter/EntityPacketRewriter1_20_3.java | 12 +- .../storage/SpawnPositionStorage.java | 1 - .../BlockItemPacketRewriter1_20_2.java | 26 +-- .../Protocol1_9_1_2To1_9_3_4.java | 5 +- .../chunks/BlockEntity.java | 70 +++--- .../packets/EntityPackets1_10.java | 2 +- 59 files changed, 565 insertions(+), 562 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/BackwardsProtocol.java b/common/src/main/java/com/viaversion/viabackwards/api/BackwardsProtocol.java index 70f278f5..819e9bfb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/BackwardsProtocol.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/BackwardsProtocol.java @@ -27,7 +27,7 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import org.checkerframework.checker.nullness.qual.Nullable; public abstract class BackwardsProtocol - extends AbstractProtocol { + extends AbstractProtocol { protected BackwardsProtocol() { } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java index 0478b123..126acf79 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityData.java @@ -112,11 +112,11 @@ public class EntityData { @Override public String toString() { return "EntityData{" + - "id=" + id + - ", mobName='" + key + '\'' + - ", replacementId=" + replacementId + - ", defaultMeta=" + defaultMeta + - '}'; + "id=" + id + + ", mobName='" + key + '\'' + + ", replacementId=" + replacementId + + ", defaultMeta=" + defaultMeta + + '}'; } @FunctionalInterface 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 b7d64610..e05b3135 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 @@ -43,7 +43,7 @@ public class EntityPositionHandler { public void cacheEntityPosition(PacketWrapper wrapper, boolean create, boolean relative) throws Exception { cacheEntityPosition(wrapper, - wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), create, relative); + wrapper.get(Type.DOUBLE, 0), wrapper.get(Type.DOUBLE, 1), wrapper.get(Type.DOUBLE, 2), create, relative); } public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) throws Exception { diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java index ff2e33a8..18d0a775 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EnchantmentRewriter.java @@ -21,7 +21,6 @@ import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.util.ComponentUtil; @@ -57,10 +56,10 @@ public class EnchantmentRewriter { CompoundTag tag = item.tag(); if (tag == null) return; - if (tag.get("Enchantments") instanceof ListTag) { + if (tag.getListTag("Enchantments") != null) { rewriteEnchantmentsToClient(tag, false); } - if (tag.get("StoredEnchantments") instanceof ListTag) { + if (tag.getListTag("StoredEnchantments") != null) { rewriteEnchantmentsToClient(tag, true); } } @@ -79,17 +78,16 @@ public class EnchantmentRewriter { public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) { String key = storedEnchant ? "StoredEnchantments" : "Enchantments"; - ListTag enchantments = tag.get(key); + ListTag enchantments = tag.getListTag(key); List loreToAdd = new ArrayList<>(); boolean changed = false; Iterator iterator = enchantments.iterator(); while (iterator.hasNext()) { CompoundTag enchantmentEntry = (CompoundTag) iterator.next(); - Tag idTag = enchantmentEntry.get("id"); - if (!(idTag instanceof StringTag)) continue; + StringTag idTag = enchantmentEntry.getStringTag("id"); - String enchantmentId = ((StringTag) idTag).getValue(); + String enchantmentId = idTag.getValue(); String remappedName = enchantmentMappings.get(enchantmentId); if (remappedName != null) { if (!changed) { @@ -100,7 +98,8 @@ public class EnchantmentRewriter { iterator.remove(); - int level = ((NumberTag) enchantmentEntry.get("lvl")).asInt(); + NumberTag levelTag = enchantmentEntry.getNumberTag("lvl"); + int level = levelTag != null ? levelTag.asInt() : 1; String loreValue = remappedName + " " + getRomanNumber(level); if (jsonFormat) { loreValue = ComponentUtil.legacyToJsonString(loreValue); @@ -112,19 +111,19 @@ public class EnchantmentRewriter { if (!loreToAdd.isEmpty()) { // Add dummy enchant for the glow effect if there are no actual enchantments left - if (!storedEnchant && enchantments.size() == 0) { + if (!storedEnchant && enchantments.isEmpty()) { CompoundTag dummyEnchantment = new CompoundTag(); - dummyEnchantment.put("id", new StringTag()); - dummyEnchantment.put("lvl", new ShortTag((short) 0)); + dummyEnchantment.putString("id", ""); + dummyEnchantment.putShort("lvl", (short) 0); enchantments.add(dummyEnchantment); } - CompoundTag display = tag.get("display"); + CompoundTag display = tag.getCompoundTag("display"); if (display == null) { tag.put("display", display = new CompoundTag()); } - ListTag loreTag = display.get("Lore"); + ListTag loreTag = display.getListTag("Lore"); if (loreTag == null) { display.put("Lore", loreTag = new ListTag(StringTag.class)); } else { 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 6b51a43e..9a8800c9 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 @@ -177,12 +177,12 @@ public abstract class EntityRewriterBase { MetaType type = meta.metaType(); diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java index 9754a193..c98cf953 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java @@ -34,7 +34,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import org.checkerframework.checker.nullness.qual.Nullable; public class ItemRewriter> extends ItemRewriterBase { + T extends BackwardsProtocol> extends ItemRewriterBase { public ItemRewriter(T protocol, Type itemType, Type itemArrayType) { super(protocol, itemType, itemArrayType, true); @@ -46,25 +46,23 @@ public class ItemRewriter> extends ItemRewriter { + T extends BackwardsProtocol> extends ItemRewriter { protected final String nbtTagName; protected final boolean jsonNameFormat; @@ -58,7 +58,7 @@ public abstract class ItemRewriterBase> extends ItemRewriterBase { + T extends BackwardsProtocol> extends ItemRewriterBase { private static final Map> LEGACY_MAPPINGS = new HashMap<>(); protected final Int2ObjectMap replacementData; // Raw id -> mapped data @@ -134,21 +132,22 @@ public abstract class LegacyBlockItemRewriter tags = new HashMap<>(); for (CompoundTag tag : chunk.getBlockEntities()) { - Tag xTag; - Tag yTag; - Tag zTag; - if ((xTag = tag.get("x")) == null || (yTag = tag.get("y")) == null || (zTag = tag.get("z")) == null) { + NumberTag xTag; + NumberTag yTag; + NumberTag zTag; + if ((xTag = tag.getNumberTag("x")) == null + || (yTag = tag.getNumberTag("y")) == null + || (zTag = tag.getNumberTag("z")) == null) { continue; } - Pos pos = new Pos( - ((NumberTag) xTag).asInt() & 0xF, - ((NumberTag) yTag).asInt(), - ((NumberTag) zTag).asInt() & 0xF); + Pos pos = new Pos(xTag.asInt() & 0xF, yTag.asInt(), zTag.asInt() & 0xF); tags.put(pos, tag); // Handle given Block Entities @@ -263,9 +261,9 @@ public abstract class LegacyBlockItemRewriter lore = new ArrayList<>(); for (Tag enchantmentEntry : enchantments.copy()) { - Tag idTag = ((CompoundTag) enchantmentEntry).get("id"); + if (!(enchantmentEntry instanceof CompoundTag)) { + continue; + } + + CompoundTag entryTag = (CompoundTag) enchantmentEntry; + NumberTag idTag = entryTag.getNumberTag("id"); if (idTag == null) continue; - short newId = ((NumberTag) idTag).asShort(); + short newId = idTag.asShort(); String enchantmentName = enchantmentMappings.get(newId); if (enchantmentName != null) { enchantments.remove(enchantmentEntry); - short level = ((NumberTag) ((CompoundTag) enchantmentEntry).get("lvl")).asShort(); + NumberTag levelTag = entryTag.getNumberTag("lvl"); + short level = levelTag != null ? levelTag.asShort() : 1; if (hideLevelForEnchants != null && hideLevelForEnchants.contains(newId)) { lore.add(new StringTag(enchantmentName)); } else { @@ -69,33 +74,32 @@ public class LegacyEnchantmentRewriter { } } if (!lore.isEmpty()) { - if (!storedEnchant && enchantments.size() == 0) { + if (!storedEnchant && enchantments.isEmpty()) { CompoundTag dummyEnchantment = new CompoundTag(); - dummyEnchantment.put("id", new ShortTag((short) 0)); - dummyEnchantment.put("lvl", new ShortTag((short) 0)); + dummyEnchantment.putShort("id", (short) 0); + dummyEnchantment.putShort("lvl", (short) 0); enchantments.add(dummyEnchantment); tag.put(nbtTagName + "|dummyEnchant", new ByteTag()); - IntTag hideFlags = tag.get("HideFlags"); + NumberTag hideFlags = tag.getNumberTag("HideFlags"); if (hideFlags == null) { hideFlags = new IntTag(); } else { - tag.put(nbtTagName + "|oldHideFlags", new IntTag(hideFlags.asByte())); + tag.putInt(nbtTagName + "|oldHideFlags", hideFlags.asByte()); } int flags = hideFlags.asByte() | 1; - hideFlags.setValue(flags); - tag.put("HideFlags", hideFlags); + tag.putInt("HideFlags", flags); } tag.put(nbtTagName + "|" + key, remappedEnchantments); - CompoundTag display = tag.get("display"); + CompoundTag display = tag.getCompoundTag("display"); if (display == null) { tag.put("display", display = new CompoundTag()); } - ListTag loreTag = display.get("Lore"); + ListTag loreTag = display.getListTag("Lore"); if (loreTag == null) { display.put("Lore", loreTag = new ListTag(StringTag.class)); } @@ -108,38 +112,45 @@ public class LegacyEnchantmentRewriter { public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) { String key = storedEnchant ? "StoredEnchantments" : "ench"; ListTag remappedEnchantments = tag.remove(nbtTagName + "|" + key); - ListTag enchantments = tag.get(key); + ListTag enchantments = tag.getListTag(key); if (enchantments == null) { enchantments = new ListTag(CompoundTag.class); } if (!storedEnchant && tag.remove(nbtTagName + "|dummyEnchant") != null) { for (Tag enchantment : enchantments.copy()) { - short id = ((NumberTag) ((CompoundTag) enchantment).get("id")).asShort(); - short level = ((NumberTag) ((CompoundTag) enchantment).get("lvl")).asShort(); + if (!(enchantment instanceof CompoundTag)) { + continue; + } + + CompoundTag entryTag = (CompoundTag) enchantment; + NumberTag idTag = entryTag.getNumberTag("id"); + NumberTag levelTag = entryTag.getNumberTag("lvl"); + short id = idTag != null ? idTag.asShort() : 0; + short level = levelTag != null ? levelTag.asShort() : 0; if (id == 0 && level == 0) { enchantments.remove(enchantment); } } - IntTag hideFlags = tag.remove(nbtTagName + "|oldHideFlags"); - if (hideFlags != null) { - tag.put("HideFlags", new IntTag(hideFlags.asByte())); + Tag hideFlags = tag.remove(nbtTagName + "|oldHideFlags"); + if (hideFlags instanceof IntTag) { + tag.putInt("HideFlags", ((IntTag) hideFlags).asByte()); } else { tag.remove("HideFlags"); } } - CompoundTag display = tag.get("display"); + CompoundTag display = tag.getCompoundTag("display"); // A few null checks just to be safe, though they shouldn't actually be - ListTag lore = display != null ? display.get("Lore") : null; + ListTag lore = display != null ? display.getListTag("Lore") : null; for (Tag enchantment : remappedEnchantments.copy()) { enchantments.add(enchantment); - if (lore != null && lore.size() != 0) { + if (lore != null && !lore.isEmpty()) { lore.remove(lore.get(0)); } } - if (lore != null && lore.size() == 0) { + if (lore != null && lore.isEmpty()) { display.remove("Lore"); if (display.isEmpty()) { tag.remove("display"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index 158e0eab..e7aee953 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -33,15 +33,11 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.minecraft.item.DataItem; 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.Type; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_11to1_10.EntityIdRewriter; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; @@ -181,12 +177,12 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter entry : backupTag) { if (entry.getValue() instanceof CompoundTag) { - CompoundTag nestedTag = compoundTag.get(entry.getKey()); + CompoundTag nestedTag = compoundTag.getCompoundTag(entry.getKey()); handleNbtToServer(nestedTag, (CompoundTag) entry.getValue()); } else { compoundTag.put(entry.getKey(), fromIntArrayTag((IntArrayTag) entry.getValue())); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java index 0985ff92..5693b8e6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java @@ -24,11 +24,10 @@ import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStor import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker; import com.viaversion.viabackwards.utils.Block; import com.viaversion.viaversion.api.data.entity.StoredEntityData; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12; import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_12; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; @@ -271,8 +270,8 @@ public class EntityPackets1_12 extends LegacyEntityRewriter= BANNER_START && blockId <= BANNER_STOP) { int color = (blockId - BANNER_START) >> 4; - tag.put("Base", new IntTag((15 - color))); + tag.putInt("Base", 15 - color); } // Wall banners else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) { int color = (blockId - WALL_BANNER_START) >> 2; - tag.put("Base", new IntTag((15 - color))); + tag.putInt("Base", 15 - color); } else { ViaBackwards.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag); } // Invert colors - Tag patternsTag = tag.get("Patterns"); - if (patternsTag instanceof ListTag) { - for (Tag pattern : (ListTag) patternsTag) { + ListTag patternsTag = tag.getListTag("Patterns"); + if (patternsTag != null) { + for (Tag pattern : patternsTag) { if (!(pattern instanceof CompoundTag)) continue; - IntTag c = ((CompoundTag) pattern).get("Color"); - c.setValue(15 - c.asInt()); // Invert color id + CompoundTag patternTag = (CompoundTag) pattern; + NumberTag colorTag = patternTag.getNumberTag("Color"); + patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java index 98b76b99..fa12bc46 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java @@ -21,7 +21,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { @@ -30,7 +29,7 @@ public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEn int offset = blockId - 748; int color = offset >> 4; - tag.put("color", new IntTag(color)); + tag.putInt("color", color); return tag; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java index c29b3531..8309cd03 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java @@ -23,8 +23,6 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.util.Pair; public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { @@ -75,8 +73,8 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { Pair item = getOrDefault(blockId); - tag.put("Item", new StringTag(item.key())); - tag.put("Data", new IntTag(item.value())); + tag.putString("Item", item.key()); + tag.putInt("Data", item.value()); return tag; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java index ed047f20..63d3fddd 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java @@ -22,21 +22,22 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.Backw import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.data.MappingDataLoader; +import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap; +import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; -import java.util.HashMap; import java.util.Map; import java.util.StringJoiner; public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { - private final Map pistonIds = new HashMap<>(); + private final Object2IntMap pistonIds = new Object2IntOpenHashMap<>(); public PistonHandler() { + pistonIds.defaultReturnValue(-1); if (Via.getConfig().isServersideBlockConnections()) { Map keyToId = ConnectionData.getKeyToId(); for (Map.Entry entry : keyToId.entrySet()) { @@ -77,29 +78,29 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc @Override public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { - CompoundTag blockState = tag.get("blockState"); + CompoundTag blockState = tag.getCompoundTag("blockState"); if (blockState == null) return tag; String dataFromTag = getDataFromTag(blockState); if (dataFromTag == null) return tag; - Integer id = pistonIds.get(dataFromTag); - if (id == null) { + int id = pistonIds.getInt(dataFromTag); + if (id == -1) { //TODO see why this could be null and if this is bad return tag; } - tag.put("blockId", new IntTag(id >> 4)); - tag.put("blockData", new IntTag(id & 15)); + tag.putInt("blockId", id >> 4); + tag.putInt("blockData", id & 15); return tag; } // The type hasn't actually been updated in the blockstorage, so we need to construct it private String getDataFromTag(CompoundTag tag) { - StringTag name = tag.get("Name"); + StringTag name = tag.getStringTag("Name"); if (name == null) return null; - CompoundTag properties = tag.get("Properties"); + CompoundTag properties = tag.getCompoundTag("Properties"); if (properties == null) return name.getValue(); StringJoiner joiner = new StringJoiner(",", name.getValue() + "[", "]"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java index 9724dbeb..59e695f4 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java @@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler; import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; public class SkullHandler implements BackwardsBlockEntityHandler { @@ -33,7 +32,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler { byte type = (byte) Math.floor(diff / 20f); // Set type - tag.put("SkullType", new ByteTag(type)); + tag.putByte("SkullType", type); // Remove wall skulls if (pos < 4) { @@ -41,7 +40,7 @@ public class SkullHandler implements BackwardsBlockEntityHandler { } // Add rotation for normal skulls - tag.put("Rot", new ByteTag((byte) ((pos - 4) & 255))); + tag.putByte("Rot", (byte) ((pos - 4) & 255)); return tag; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java index 9a0a3ab7..b2ac7ea8 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java @@ -23,19 +23,16 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.Backw import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { @Override public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { - Tag dataTag = tag.get("SpawnData"); - if (dataTag instanceof CompoundTag) { - CompoundTag data = (CompoundTag) dataTag; - Tag idTag = data.get("id"); - if (idTag instanceof StringTag) { - StringTag s = (StringTag) idTag; - s.setValue(EntityNameRewrites.rewrite(s.getValue())); + CompoundTag dataTag = tag.getCompoundTag("SpawnData"); + if (dataTag != null) { + StringTag idTag = dataTag.getStringTag("id"); + if (idTag != null) { + idTag.setValue(EntityNameRewrites.rewrite(idTag.getValue())); } } return tag; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/EntityNameRewrites.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/EntityNameRewrites.java index ed3eee1c..486fdec6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/EntityNameRewrites.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/EntityNameRewrites.java @@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data; import com.viaversion.viaversion.util.Key; - import java.util.HashMap; import java.util.Map; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java index c0a930ee..168fd21d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java @@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter; import com.viaversion.viaversion.util.Key; - import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/ParticleMapping.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/ParticleMapping.java index 0b1775c3..1535ef84 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/ParticleMapping.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/data/ParticleMapping.java @@ -55,94 +55,94 @@ public class ParticleMapping { }; particles = new ParticleData[]{ - rewrite(16), // (0->16) minecraft:ambient_entity_effect -> mobSpellAmbient - rewrite(20), // (1->20) minecraft:angry_villager -> angryVillager - rewrite(35), // (2->35) minecraft:barrier -> barrier - rewrite(37, blockHandler), - // (3->37) minecraft:block -> blockcrack - rewrite(4), // (4->4) minecraft:bubble -> bubble - rewrite(29), // (5->29) minecraft:cloud -> cloud - rewrite(9), // (6->9) minecraft:crit -> crit - rewrite(44), // (7->44) minecraft:damage_indicator -> damageIndicator‌ - rewrite(42), // (8->42) minecraft:dragon_breath -> dragonbreath - rewrite(19), // (9->19) minecraft:dripping_lava -> dripLava - rewrite(18), // (10->18) minecraft:dripping_water -> dripWater - rewrite(30, new ParticleHandler() { - @Override - public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception { - float r = wrapper.read(Type.FLOAT); - float g = wrapper.read(Type.FLOAT); - float b = wrapper.read(Type.FLOAT); - float scale = wrapper.read(Type.FLOAT); + rewrite(16), // (0->16) minecraft:ambient_entity_effect -> mobSpellAmbient + rewrite(20), // (1->20) minecraft:angry_villager -> angryVillager + rewrite(35), // (2->35) minecraft:barrier -> barrier + rewrite(37, blockHandler), + // (3->37) minecraft:block -> blockcrack + rewrite(4), // (4->4) minecraft:bubble -> bubble + rewrite(29), // (5->29) minecraft:cloud -> cloud + rewrite(9), // (6->9) minecraft:crit -> crit + rewrite(44), // (7->44) minecraft:damage_indicator -> damageIndicator‌ + rewrite(42), // (8->42) minecraft:dragon_breath -> dragonbreath + rewrite(19), // (9->19) minecraft:dripping_lava -> dripLava + rewrite(18), // (10->18) minecraft:dripping_water -> dripWater + rewrite(30, new ParticleHandler() { + @Override + public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception { + float r = wrapper.read(Type.FLOAT); + float g = wrapper.read(Type.FLOAT); + float b = wrapper.read(Type.FLOAT); + float scale = wrapper.read(Type.FLOAT); - wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3 - wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4 - wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5 - wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6 - wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle + wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3 + wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4 + wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5 + wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6 + wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle - return null; - } + return null; + } - @Override - public int[] rewrite(Protocol1_12_2To1_13 protocol, List> data) { - return null; - } - }), // (11->30) minecraft:dust -> reddust - rewrite(13), // (12->13) minecraft:effect -> spell - rewrite(41), // (13->41) minecraft:elder_guardian -> mobappearance - rewrite(10), // (14->10) minecraft:enchanted_hit -> magicCrit‌ - rewrite(25), // (15->25) minecraft:enchant -> enchantmenttable - rewrite(43), // (16->43) minecraft:end_rod -> endRod - rewrite(15), // (17->15) minecraft:entity_effect -> mobSpell - rewrite(2), // (18->2) minecraft:explosion_emitter -> hugeexplosion - rewrite(1), // (19->1) minecraft:explosion -> largeexplode - rewrite(46, blockHandler), - // (20->46) minecraft:falling_dust -> fallingdust - rewrite(3), // (21->3) minecraft:firework -> fireworksSpark - rewrite(6), // (22->6) minecraft:fishing -> wake - rewrite(26), // (23->26) minecraft:flame -> flame - rewrite(21), // (24->21) minecraft:happy_villager -> happyVillager - rewrite(34), // (25->34) minecraft:heart -> heart - rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell - rewrite(36, new ParticleHandler() { - @Override - public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception { - return rewrite(protocol, wrapper.read(Type.ITEM1_13)); - } + @Override + public int[] rewrite(Protocol1_12_2To1_13 protocol, List> data) { + return null; + } + }), // (11->30) minecraft:dust -> reddust + rewrite(13), // (12->13) minecraft:effect -> spell + rewrite(41), // (13->41) minecraft:elder_guardian -> mobappearance + rewrite(10), // (14->10) minecraft:enchanted_hit -> magicCrit‌ + rewrite(25), // (15->25) minecraft:enchant -> enchantmenttable + rewrite(43), // (16->43) minecraft:end_rod -> endRod + rewrite(15), // (17->15) minecraft:entity_effect -> mobSpell + rewrite(2), // (18->2) minecraft:explosion_emitter -> hugeexplosion + rewrite(1), // (19->1) minecraft:explosion -> largeexplode + rewrite(46, blockHandler), + // (20->46) minecraft:falling_dust -> fallingdust + rewrite(3), // (21->3) minecraft:firework -> fireworksSpark + rewrite(6), // (22->6) minecraft:fishing -> wake + rewrite(26), // (23->26) minecraft:flame -> flame + rewrite(21), // (24->21) minecraft:happy_villager -> happyVillager + rewrite(34), // (25->34) minecraft:heart -> heart + rewrite(14), // (26->14) minecraft:instant_effect -> instantSpell + rewrite(36, new ParticleHandler() { + @Override + public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception { + return rewrite(protocol, wrapper.read(Type.ITEM1_13)); + } - @Override - public int[] rewrite(Protocol1_12_2To1_13 protocol, List> data) { - return rewrite(protocol, (Item) data.get(0).getValue()); - } + @Override + public int[] rewrite(Protocol1_12_2To1_13 protocol, List> data) { + return rewrite(protocol, (Item) data.get(0).getValue()); + } - private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) { - Item item = protocol.getItemRewriter().handleItemToClient(newItem); - return new int[]{item.identifier(), item.data()}; - } - }), // (27->36) minecraft:item -> iconcrack - rewrite(33), // (28->33) minecraft:item_slime -> slime - rewrite(31), // (29->31) minecraft:item_snowball -> snowballpoof - rewrite(12), // (30->12) minecraft:large_smoke -> largesmoke - rewrite(27), // (31->27) minecraft:lava -> lava - rewrite(22), // (32->22) minecraft:mycelium -> townaura - rewrite(23), // (33->23) minecraft:note -> note - rewrite(0), // (34->0) minecraft:poof -> explode - rewrite(24), // (35->24) minecraft:portal -> portal - rewrite(39), // (36->39) minecraft:rain -> droplet - rewrite(11), // (37->11) minecraft:smoke -> smoke - rewrite(48), // (38->48) minecraft:spit -> spit - rewrite(12), // (39->-1) minecraft:squid_ink -> squid_ink -> large_smoke - rewrite(45), // (40->45) minecraft:sweep_attack -> sweepAttack‌ - rewrite(47), // (41->47) minecraft:totem_of_undying -> totem - rewrite(7), // (42->7) minecraft:underwater -> suspended‌ - rewrite(5), // (43->5) minecraft:splash -> splash - rewrite(17), // (44->17) minecraft:witch -> witchMagic - rewrite(4), // (45->4) minecraft:bubble_pop -> bubble - rewrite(4), // (46->4) minecraft:current_down -> bubble - rewrite(4), // (47->4) minecraft:bubble_column_up -> bubble - rewrite(18), // (48->-1) minecraft:nautilus -> nautilus -> dripWater - rewrite(18), // (49->18) minecraft:dolphin -> dripWater + private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) { + Item item = protocol.getItemRewriter().handleItemToClient(newItem); + return new int[]{item.identifier(), item.data()}; + } + }), // (27->36) minecraft:item -> iconcrack + rewrite(33), // (28->33) minecraft:item_slime -> slime + rewrite(31), // (29->31) minecraft:item_snowball -> snowballpoof + rewrite(12), // (30->12) minecraft:large_smoke -> largesmoke + rewrite(27), // (31->27) minecraft:lava -> lava + rewrite(22), // (32->22) minecraft:mycelium -> townaura + rewrite(23), // (33->23) minecraft:note -> note + rewrite(0), // (34->0) minecraft:poof -> explode + rewrite(24), // (35->24) minecraft:portal -> portal + rewrite(39), // (36->39) minecraft:rain -> droplet + rewrite(11), // (37->11) minecraft:smoke -> smoke + rewrite(48), // (38->48) minecraft:spit -> spit + rewrite(12), // (39->-1) minecraft:squid_ink -> squid_ink -> large_smoke + rewrite(45), // (40->45) minecraft:sweep_attack -> sweepAttack‌ + rewrite(47), // (41->47) minecraft:totem_of_undying -> totem + rewrite(7), // (42->7) minecraft:underwater -> suspended‌ + rewrite(5), // (43->5) minecraft:splash -> splash + rewrite(17), // (44->17) minecraft:witch -> witchMagic + rewrite(4), // (45->4) minecraft:bubble_pop -> bubble + rewrite(4), // (46->4) minecraft:current_down -> bubble + rewrite(4), // (47->4) minecraft:bubble_column_up -> bubble + rewrite(18), // (48->-1) minecraft:nautilus -> nautilus -> dripWater + rewrite(18), // (49->18) minecraft:dolphin -> dripWater }; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 2ee04a6e..6cb587c7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -46,7 +46,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; @@ -58,7 +57,6 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.SpawnEggRew import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Pair; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -78,16 +76,16 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit public static boolean isDamageable(int id) { return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel - || id == 261 // bow - || id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes - || id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe - || id >= 290 && id <= 294 // hoes - || id >= 298 && id <= 317 // armors - || id == 346 // fishing rod - || id == 359 // shears - || id == 398 // carrot on a stick - || id == 442 // shield - || id == 443; // elytra + || id == 261 // bow + || id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes + || id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe + || id >= 290 && id <= 294 // hoes + || id >= 298 && id <= 317 // armors + || id == 346 // fishing rod + || id == 359 // shears + || id == 398 // carrot on a stick + || id == 442 // shield + || id == 443; // elytra } @Override @@ -171,11 +169,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit } wrapper.set(Type.NAMED_COMPOUND_TAG, 0, - provider.transform( - wrapper.user(), - wrapper.get(Type.POSITION1_8, 0), - wrapper.get(Type.NAMED_COMPOUND_TAG, 0) - )); + provider.transform( + wrapper.user(), + wrapper.get(Type.POSITION1_8, 0), + wrapper.get(Type.NAMED_COMPOUND_TAG, 0) + )); }); } }); @@ -189,7 +187,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit blockStorage.getBlocks().entrySet().removeIf(entry -> { Position position = entry.getKey(); return position.x() >= chunkMinX && position.z() >= chunkMinZ - && position.x() <= chunkMaxX && position.z() <= chunkMaxZ; + && position.x() <= chunkMaxX && position.z() <= chunkMaxZ; }); }); @@ -235,9 +233,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit int chunkZ = wrapper.get(Type.INT, 1); int block = record.getBlockId(); Position position = new Position( - record.getSectionX() + (chunkX * 16), - record.getY(), - record.getSectionZ() + (chunkZ * 16)); + record.getSectionX() + (chunkX * 16), + record.getY(), + record.getSectionZ() + (chunkZ * 16)); // Store if needed storage.checkAndStore(position, block); @@ -284,15 +282,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class); BackwardsBlockStorage storage = wrapper.user().get(BackwardsBlockStorage.class); for (CompoundTag tag : chunk.getBlockEntities()) { - Tag idTag = tag.get("id"); + StringTag idTag = tag.getStringTag("id"); if (idTag == null) continue; - String id = (String) idTag.getValue(); + String id = idTag.getValue(); // Ignore if we don't handle it if (!provider.isHandled(id)) continue; - int sectionIndex = ((NumberTag) tag.get("y")).asInt() >> 4; + int sectionIndex = tag.getNumberTag("y").asInt() >> 4; if (sectionIndex < 0 || sectionIndex > 15) { // 1.17 chunks continue; @@ -300,9 +298,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit ChunkSection section = chunk.getSections()[sectionIndex]; - int x = ((NumberTag) tag.get("x")).asInt(); - int y = ((NumberTag) tag.get("y")).asInt(); - int z = ((NumberTag) tag.get("z")).asInt(); + int x = tag.getNumberTag("x").asInt(); + int y = tag.getNumberTag("y").asInt(); + int z = tag.getNumberTag("z").asInt(); Position position = new Position(x, (short) y, z); int block = section.palette(PaletteType.BLOCKS).idAt(x & 0xF, y & 0xF, z & 0xF); @@ -328,9 +326,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit // Check if the block is a flower if (FlowerPotHandler.isFlowah(block)) { Position pos = new Position( - (x + (chunk.getX() << 4)), - (short) (y + (i << 4)), - (z + (chunk.getZ() << 4)) + (x + (chunk.getX() << 4)), + (short) (y + (i << 4)), + (z + (chunk.getZ() << 4)) ); // Store block storage.checkAndStore(pos, block); @@ -508,7 +506,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit // Use tag to get original ID and data Tag originalIdTag; - if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) != null) { + if (tag != null && (originalIdTag = tag.remove(extraNbtTag)) instanceof NumberTag) { rawId = ((NumberTag) originalIdTag).asInt(); gotRawIdFromTag = true; } @@ -545,15 +543,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit if (tag != null) { if (isDamageable(item.identifier())) { Tag damageTag = tag.remove("Damage"); - if (!gotRawIdFromTag && damageTag instanceof IntTag) { - item.setData((short) (int) damageTag.getValue()); + if (!gotRawIdFromTag && damageTag instanceof NumberTag) { + item.setData(((NumberTag) damageTag).asShort()); } } if (item.identifier() == 358) { // map Tag mapTag = tag.remove("map"); - if (!gotRawIdFromTag && mapTag instanceof IntTag) { - item.setData((short) (int) mapTag.getValue()); + if (!gotRawIdFromTag && mapTag instanceof NumberTag) { + item.setData(((NumberTag) mapTag).asShort()); } } @@ -561,11 +559,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit invertShieldAndBannerId(item, tag); // Display Name now uses JSON - CompoundTag display = tag.get("display"); + CompoundTag display = tag.getCompoundTag("display"); if (display != null) { - StringTag name = display.get("Name"); + StringTag name = display.getStringTag("Name"); if (name != null) { - display.put(extraNbtTag + "|Name", new StringTag(name.getValue())); + display.putString(extraNbtTag + "|Name", name.getValue()); name.setValue(protocol.jsonToLegacy(name.getValue())); } } @@ -588,7 +586,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit } if (!tag.contains("EntityTag")) { CompoundTag entityTag = new CompoundTag(); - entityTag.put("id", new StringTag(eggEntityId.get())); + entityTag.putString("id", eggEntityId.get()); tag.put("EntityTag", entityTag); } return 0x17f0000; // 383 << 16; @@ -599,8 +597,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit private void rewriteCanPlaceToClient(CompoundTag tag, String tagName) { // The tag was manually created incorrectly so ignore rewriting it - if (!(tag.get(tagName) instanceof ListTag)) return; - ListTag blockTag = tag.get(tagName); + ListTag blockTag = tag.getListTag(tagName); if (blockTag == null) return; ListTag newCanPlaceOn = new ListTag(StringTag.class); @@ -608,7 +605,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit for (Tag oldTag : blockTag) { Object value = oldTag.getValue(); String[] newValues = value instanceof String ? - BlockIdData.fallbackReverseMapping.get(Key.stripMinecraftNamespace((String) value)) : null; + BlockIdData.fallbackReverseMapping.get(Key.stripMinecraftNamespace((String) value)) : null; if (newValues != null) { for (String newValue : newValues) { newCanPlaceOn.add(new StringTag(newValue)); @@ -623,7 +620,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit //TODO un-ugly all of this private void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnch) { String key = storedEnch ? "StoredEnchantments" : "Enchantments"; - ListTag enchantments = tag.get(key); + ListTag enchantments = tag.getListTag(key); if (enchantments == null) return; ListTag noMapped = new ListTag(CompoundTag.class); @@ -631,14 +628,18 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit List lore = new ArrayList<>(); boolean hasValidEnchants = false; for (Tag enchantmentEntryTag : enchantments.copy()) { - CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag; - Tag idTag = enchantmentEntry.get("id"); - if (!(idTag instanceof StringTag)) { + if (!(enchantmentEntryTag instanceof CompoundTag)) { continue; } - String newId = (String) idTag.getValue(); - NumberTag levelTag = enchantmentEntry.get("lvl"); + CompoundTag enchantmentEntry = (CompoundTag) enchantmentEntryTag; + StringTag idTag = enchantmentEntry.getStringTag("id"); + if (idTag == null) { + continue; + } + + String newId = idTag.getValue(); + NumberTag levelTag = enchantmentEntry.getNumberTag("lvl"); if (levelTag == null) { continue; } @@ -683,48 +684,47 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit } CompoundTag newEntry = new CompoundTag(); - newEntry.put("id", new ShortTag(oldId)); - newEntry.put("lvl", new ShortTag(level)); + newEntry.putShort("id", oldId); + newEntry.putShort("lvl", level); newEnchantments.add(newEntry); } } // Put here to hide empty enchantment from 1.14 rewrites if (!storedEnch && !hasValidEnchants) { - IntTag hideFlags = tag.get("HideFlags"); + NumberTag hideFlags = tag.getNumberTag("HideFlags"); if (hideFlags == null) { hideFlags = new IntTag(); tag.put(extraNbtTag + "|DummyEnchant", new ByteTag()); } else { - tag.put(extraNbtTag + "|OldHideFlags", new IntTag(hideFlags.asByte())); + tag.putInt(extraNbtTag + "|OldHideFlags", hideFlags.asByte()); } - if (newEnchantments.size() == 0) { + if (newEnchantments.isEmpty()) { CompoundTag enchEntry = new CompoundTag(); - enchEntry.put("id", new ShortTag((short) 0)); - enchEntry.put("lvl", new ShortTag((short) 0)); + enchEntry.putShort("id", (short) 0); + enchEntry.putShort("lvl", (short) 0); newEnchantments.add(enchEntry); } int value = hideFlags.asByte() | 1; - hideFlags.setValue(value); - tag.put("HideFlags", hideFlags); + tag.putInt("HideFlags", value); } if (noMapped.size() != 0) { tag.put(extraNbtTag + "|" + key, noMapped); if (!lore.isEmpty()) { - CompoundTag display = tag.get("display"); + CompoundTag display = tag.getCompoundTag("display"); if (display == null) { tag.put("display", display = new CompoundTag()); } - ListTag loreTag = display.get("Lore"); + ListTag loreTag = display.getListTag("Lore"); if (loreTag == null) { display.put("Lore", loreTag = new ListTag(StringTag.class)); tag.put(extraNbtTag + "|DummyLore", new ByteTag()); - } else if (loreTag.size() != 0) { + } else if (!loreTag.isEmpty()) { ListTag oldLore = new ListTag(StringTag.class); for (Tag value : loreTag) { oldLore.add(value.copy()); @@ -755,11 +755,11 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit // NBT Additions if (isDamageable(item.identifier())) { if (tag == null) item.setTag(tag = new CompoundTag()); - tag.put("Damage", new IntTag(item.data())); + tag.putInt("Damage", item.data()); } if (item.identifier() == 358) { // map if (tag == null) item.setTag(tag = new CompoundTag()); - tag.put("map", new IntTag(item.data())); + tag.putInt("map", item.data()); } // NBT Changes @@ -768,13 +768,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit invertShieldAndBannerId(item, tag); // Display Name now uses JSON - Tag display = tag.get("display"); - if (display instanceof CompoundTag) { - CompoundTag displayTag = (CompoundTag) display; - StringTag name = displayTag.get("Name"); + CompoundTag display = tag.getCompoundTag("display"); + if (display != null) { + StringTag name = display.getStringTag("Name"); if (name != null) { - StringTag via = displayTag.remove(extraNbtTag + "|Name"); - name.setValue(via != null ? via.getValue() : ComponentUtil.legacyToJsonString(name.getValue())); + Tag via = display.remove(extraNbtTag + "|Name"); + name.setValue(via instanceof StringTag ? ((StringTag) via).getValue() : ComponentUtil.legacyToJsonString(name.getValue())); } } @@ -787,9 +786,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit // Handle SpawnEggs if (item.identifier() == 383) { - CompoundTag entityTag = tag.get("EntityTag"); + CompoundTag entityTag = tag.getCompoundTag("EntityTag"); StringTag identifier; - if (entityTag != null && (identifier = entityTag.get("id")) != null) { + if (entityTag != null && (identifier = entityTag.getStringTag("id")) != null) { rawId = SpawnEggRewriter.getSpawnEggId(identifier.getValue()); if (rawId == -1) { rawId = 25100288; // Bat fallback @@ -823,8 +822,10 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit int newId = -1; if (protocol.getMappingData().getItemMappings().inverse().getNewId(rawId) == -1) { if (!isDamageable(item.identifier()) && item.identifier() != 358) { // Map - if (tag == null) item.setTag(tag = new CompoundTag()); - tag.put(extraNbtTag, new IntTag(originalId)); // Data will be lost, saving original id + if (tag == null) { + item.setTag(tag = new CompoundTag()); + } + tag.putInt(extraNbtTag, originalId); // Data will be lost, saving original id } if (item.identifier() == 229) { // purple shulker box @@ -851,11 +852,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit } private void rewriteCanPlaceToServer(CompoundTag tag, String tagName) { - if (!(tag.get(tagName) instanceof ListTag)) return; + if (tag.getListTag(tagName) == null) return; + ListTag blockTag = tag.remove(extraNbtTag + "|" + tagName); if (blockTag != null) { tag.put(tagName, blockTag.copy()); - } else if ((blockTag = tag.get(tagName)) != null) { + } else if ((blockTag = tag.getListTag(tagName)) != null) { ListTag newCanPlaceOn = new ListTag(StringTag.class); for (Tag oldTag : blockTag) { Object value = oldTag.getValue(); @@ -882,15 +884,15 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit private void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnch) { String key = storedEnch ? "StoredEnchantments" : "Enchantments"; - ListTag enchantments = tag.get(storedEnch ? key : "ench"); + ListTag enchantments = tag.getListTag(storedEnch ? key : "ench"); if (enchantments == null) return; ListTag newEnchantments = new ListTag(CompoundTag.class); boolean dummyEnchant = false; if (!storedEnch) { - IntTag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags"); - if (hideFlags != null) { - tag.put("HideFlags", new IntTag(hideFlags.asByte())); + Tag hideFlags = tag.remove(extraNbtTag + "|OldHideFlags"); + if (hideFlags instanceof IntTag) { + tag.putInt("HideFlags", ((NumberTag) hideFlags).asByte()); dummyEnchant = true; } else if (tag.remove(extraNbtTag + "|DummyEnchant") != null) { tag.remove("HideFlags"); @@ -899,42 +901,50 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit } for (Tag enchEntry : enchantments) { - CompoundTag enchantmentEntry = new CompoundTag(); - short oldId = ((NumberTag) ((CompoundTag) enchEntry).get("id")).asShort(); - short level = ((NumberTag) ((CompoundTag) enchEntry).get("lvl")).asShort(); - if (dummyEnchant && oldId == 0 && level == 0) { - continue; //Skip dummy enchatment + if (!(enchEntry instanceof CompoundTag)) { + continue; } + + CompoundTag entryTag = (CompoundTag) enchEntry; + NumberTag idTag = entryTag.getNumberTag("id"); + NumberTag levelTag = entryTag.getNumberTag("lvl"); + CompoundTag enchantmentEntry = new CompoundTag(); + short oldId = idTag != null ? idTag.asShort() : 0; + short level = levelTag != null ? levelTag.asShort() : 0; + if (dummyEnchant && oldId == 0 && level == 0) { + continue; // Skip dummy enchatment + } + String newId = Protocol1_13To1_12_2.MAPPINGS.getOldEnchantmentsIds().get(oldId); if (newId == null) { newId = "viaversion:legacy/" + oldId; } - enchantmentEntry.put("id", new StringTag(newId)); + enchantmentEntry.putString("id", newId); - enchantmentEntry.put("lvl", new ShortTag(level)); + enchantmentEntry.putShort("lvl", level); newEnchantments.add(enchantmentEntry); } - ListTag noMapped = tag.remove(extraNbtTag + "|Enchantments"); - if (noMapped != null) { - for (Tag value : noMapped) { + Tag noMapped = tag.remove(extraNbtTag + "|Enchantments"); + if (noMapped instanceof ListTag) { + for (Tag value : ((ListTag) noMapped)) { newEnchantments.add(value); } } - CompoundTag display = tag.get("display"); + CompoundTag display = tag.getCompoundTag("display"); if (display == null) { tag.put("display", display = new CompoundTag()); } - ListTag oldLore = tag.remove(extraNbtTag + "|OldLore"); - if (oldLore != null) { - ListTag lore = display.get("Lore"); + Tag oldLore = tag.remove(extraNbtTag + "|OldLore"); + if (oldLore instanceof ListTag) { + ListTag lore = display.getListTag("Lore"); if (lore == null) { tag.put("Lore", lore = new ListTag()); } - lore.setValue(oldLore.getValue()); + lore.setValue(((ListTag) oldLore).getValue()); } else if (tag.remove(extraNbtTag + "|DummyLore") != null) { display.remove("Lore"); if (display.isEmpty()) { @@ -951,24 +961,22 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit private void invertShieldAndBannerId(Item item, CompoundTag tag) { if (item.identifier() != 442 && item.identifier() != 425) return; - Tag blockEntityTag = tag.get("BlockEntityTag"); - if (!(blockEntityTag instanceof CompoundTag)) return; + CompoundTag blockEntityTag = tag.getCompoundTag("BlockEntityTag"); + if (blockEntityTag == null) return; - CompoundTag blockEntityCompoundTag = (CompoundTag) blockEntityTag; - Tag base = blockEntityCompoundTag.get("Base"); - if (base instanceof IntTag) { - IntTag baseTag = (IntTag) base; - baseTag.setValue(15 - baseTag.asInt()); // invert color id + NumberTag base = blockEntityTag.getNumberTag("Base"); + if (base != null) { + blockEntityTag.putInt("Base", 15 - base.asInt()); // Invert color id } - Tag patterns = blockEntityCompoundTag.get("Patterns"); - if (patterns instanceof ListTag) { - ListTag patternsTag = (ListTag) patterns; - for (Tag pattern : patternsTag) { + ListTag patterns = blockEntityTag.getListTag("Patterns"); + if (patterns != null) { + for (Tag pattern : patterns) { if (!(pattern instanceof CompoundTag)) continue; - IntTag colorTag = ((CompoundTag) pattern).get("Color"); - colorTag.setValue(15 - colorTag.asInt()); // Invert color id + CompoundTag patternTag = (CompoundTag) pattern; + NumberTag colorTag = patternTag.getNumberTag("Color"); + patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id } } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java index b07c224d..2814d62f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java @@ -231,8 +231,8 @@ public class EntityPackets1_13 extends LegacyEntityRewriter { private static final ChatColor[] COLORS = { - new ChatColor("black", 0x000000), - new ChatColor("dark_blue", 0x0000aa), - new ChatColor("dark_green", 0x00aa00), - new ChatColor("dark_aqua", 0x00aaaa), - new ChatColor("dark_red", 0xaa0000), - new ChatColor("dark_purple", 0xaa00aa), - new ChatColor("gold", 0xffaa00), - new ChatColor("gray", 0xaaaaaa), - new ChatColor("dark_gray", 0x555555), - new ChatColor("blue", 0x5555ff), - new ChatColor("green", 0x55ff55), - new ChatColor("aqua", 0x55ffff), - new ChatColor("red", 0xff5555), - new ChatColor("light_purple", 0xff55ff), - new ChatColor("yellow", 0xffff55), - new ChatColor("white", 0xffffff) + new ChatColor("black", 0x000000), + new ChatColor("dark_blue", 0x0000aa), + new ChatColor("dark_green", 0x00aa00), + new ChatColor("dark_aqua", 0x00aaaa), + new ChatColor("dark_red", 0xaa0000), + new ChatColor("dark_purple", 0xaa00aa), + new ChatColor("gold", 0xffaa00), + new ChatColor("gray", 0xaaaaaa), + new ChatColor("dark_gray", 0x555555), + new ChatColor("blue", 0x5555ff), + new ChatColor("green", 0x55ff55), + new ChatColor("aqua", 0x55ffff), + new ChatColor("red", 0xff5555), + new ChatColor("light_purple", 0xff55ff), + new ChatColor("yellow", 0xffff55), + new ChatColor("white", 0xffffff) }; public TranslatableRewriter1_16(Protocol1_15_2To1_16 protocol) { @@ -97,8 +97,8 @@ public class TranslatableRewriter1_16 extends TranslatableRewriter> 8)) * rDiff * rDiff) - + (4 * gDiff * gDiff) - + ((2 + ((255 - rAverage) >> 8)) * bDiff * bDiff); + + (4 * gDiff * gDiff) + + ((2 + ((255 - rAverage) >> 8)) * bDiff * bDiff); if (closest == null || diff < smallestDiff) { closest = color; smallestDiff = diff; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index 3b1ac5e7..f5b0c635 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -252,7 +252,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit } private void handleBlockEntity(CompoundTag tag) { - StringTag idTag = tag.get("id"); + StringTag idTag = tag.getStringTag("id"); if (idTag == null) return; String id = idTag.getValue(); @@ -262,7 +262,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit // Target -> target_uuid UUID targetUuid = UUIDUtil.fromIntArray((int[]) targetUuidTag.getValue()); - tag.put("target_uuid", new StringTag(targetUuid.toString())); + tag.putString("target_uuid", targetUuid.toString()); } else if (id.equals("minecraft:skull")) { Tag skullOwnerTag = tag.remove("SkullOwner"); if (!(skullOwnerTag instanceof CompoundTag)) return; @@ -271,7 +271,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit Tag ownerUuidTag = skullOwnerCompoundTag.remove("Id"); if (ownerUuidTag instanceof IntArrayTag) { UUID ownerUuid = UUIDUtil.fromIntArray((int[]) ownerUuidTag.getValue()); - skullOwnerCompoundTag.put("Id", new StringTag(ownerUuid.toString())); + skullOwnerCompoundTag.putString("Id", ownerUuid.toString()); } // SkullOwner -> Owner @@ -297,22 +297,21 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit CompoundTag tag = item.tag(); if (item.identifier() == 771 && tag != null) { - Tag ownerTag = tag.get("SkullOwner"); - if (ownerTag instanceof CompoundTag) { - CompoundTag ownerCompundTag = (CompoundTag) ownerTag; - Tag idTag = ownerCompundTag.get("Id"); - if (idTag instanceof IntArrayTag) { - UUID ownerUuid = UUIDUtil.fromIntArray((int[]) idTag.getValue()); - ownerCompundTag.put("Id", new StringTag(ownerUuid.toString())); + CompoundTag ownerTag = tag.getCompoundTag("SkullOwner"); + if (ownerTag != null) { + IntArrayTag idTag = ownerTag.getIntArrayTag("Id"); + if (idTag != null) { + UUID ownerUuid = UUIDUtil.fromIntArray(idTag.getValue()); + ownerTag.putString("Id", ownerUuid.toString()); } } } // Handle hover event changes in written book pages if (item.identifier() == 759 && tag != null) { - Tag pagesTag = tag.get("pages"); - if (pagesTag instanceof ListTag) { - for (Tag page : ((ListTag) pagesTag)) { + ListTag pagesTag = tag.getListTag("pages"); + if (pagesTag != null) { + for (Tag page : pagesTag) { if (!(page instanceof StringTag)) { continue; } @@ -338,13 +337,12 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit CompoundTag tag = item.tag(); if (identifier == 771 && tag != null) { - Tag ownerTag = tag.get("SkullOwner"); - if (ownerTag instanceof CompoundTag) { - CompoundTag ownerCompundTag = (CompoundTag) ownerTag; - Tag idTag = ownerCompundTag.get("Id"); - if (idTag instanceof StringTag) { - UUID ownerUuid = UUID.fromString((String) idTag.getValue()); - ownerCompundTag.put("Id", new IntArrayTag(UUIDUtil.toIntArray(ownerUuid))); + CompoundTag ownerTag = tag.getCompoundTag("SkullOwner"); + if (ownerTag != null) { + StringTag idTag = ownerTag.getStringTag("Id"); + if (idTag != null) { + UUID ownerUuid = UUID.fromString(idTag.getValue()); + ownerTag.put("Id", new IntArrayTag(UUIDUtil.toIntArray(ownerUuid))); } } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java index edd47dc5..5749219b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java @@ -118,9 +118,9 @@ public class EntityPackets1_16 extends EntityRewriter 0 ? textures.get(0) : null; + CompoundTag first = !textures.isEmpty() ? textures.get(0) : null; if (first == null) return; // Make the client cache the skinprofile over this uuid int hashCode = first.get("Value").getValue().hashCode(); int[] uuidIntArray = {hashCode, 0, 0, 0}; //TODO split texture in 4 for a lower collision chance - skullOwnerCompoundTag.put("Id", new IntArrayTag(uuidIntArray)); + skullOwnerTag.put("Id", new IntArrayTag(uuidIntArray)); } } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java index bb9b6d08..54f681b0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/EntityPackets1_16_2.java @@ -29,10 +29,13 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_16; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.*; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets; - import java.util.Set; public class EntityPackets1_16_2 extends EntityRewriter { @@ -114,13 +117,13 @@ public class EntityPackets1_16_2 extends EntityRewriter { - NumberTag tag = compound.get("y"); + NumberTag tag = compound.getNumberTag("y"); return tag != null && (tag.asInt() < 0 || tag.asInt() > 255); }); }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java index 1a22bfaf..5b018c6e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java @@ -29,7 +29,11 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.api.type.types.version.Types1_17; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.*; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; @@ -177,7 +181,7 @@ public final class EntityPackets1_17 extends EntityRewriter 256 || logicalHeight.asInt() > 256) { if (warn && !warned) { ViaBackwards.getPlatform().getLogger().warning("Custom worlds heights are NOT SUPPORTED for 1.16 players and older and may lead to errors!"); @@ -215,8 +219,8 @@ public final class EntityPackets1_17 extends EntityRewriter { final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user()); final ChunkType1_18 chunkType = new ChunkType1_18(tracker.currentWorldSectionHeight(), - MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), - MathUtil.ceilLog2(tracker.biomesSent())); + MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), + MathUtil.ceilLog2(tracker.biomesSent())); final Chunk oldChunk = wrapper.read(chunkType); final ChunkSection[] sections = oldChunk.getSections(); final BitSet mask = new BitSet(oldChunk.getSections().length); @@ -210,14 +208,14 @@ public final class BlockItemPackets1_18 extends ItemRewriter { @@ -68,8 +71,8 @@ public final class EntityPackets1_18 extends EntityRewriter MAX_TITLE_LENGTH) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java index a3599b9c..2298b5f1 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/Protocol1_18_2To1_19.java @@ -56,7 +56,6 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.util.Pair; - import java.time.Instant; import java.util.List; import java.util.UUID; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/BlockItemPackets1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/BlockItemPackets1_19.java index 6cbc0809..4483c1a2 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/BlockItemPackets1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/BlockItemPackets1_19.java @@ -142,8 +142,8 @@ public final class BlockItemPackets1_19 extends ItemRewriter { final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user()); final ChunkType1_18 chunkType = new ChunkType1_18(tracker.currentWorldSectionHeight(), - MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), - MathUtil.ceilLog2(tracker.biomesSent())); + MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), + MathUtil.ceilLog2(tracker.biomesSent())); final Chunk chunk = wrapper.passthrough(chunkType); for (final ChunkSection section : chunk.getSections()) { final DataPalette blockPalette = section.palette(PaletteType.BLOCKS); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java index e5f08a58..70d1b981 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/EntityPackets1_19.java @@ -33,7 +33,11 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_18; import com.viaversion.viaversion.api.type.types.version.Types1_19; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.*; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19; @@ -149,7 +153,7 @@ public final class EntityPackets1_19 extends EntityRewriter { final int data = (int) meta.getValue(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java index 32fd40c2..229b3cb4 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/EntityPackets1_19_3.java @@ -39,10 +39,9 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; -import org.checkerframework.checker.nullness.qual.Nullable; - import java.util.BitSet; import java.util.UUID; +import org.checkerframework.checker.nullness.qual.Nullable; public final class EntityPackets1_19_3 extends EntityRewriter { @@ -83,7 +82,7 @@ public final class EntityPackets1_19_3 extends EntityRewriter { // Sitting pose added diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java index 46154cee..4b568f25 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java @@ -28,7 +28,10 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_19_3; import com.viaversion.viaversion.api.type.types.version.Types1_19_4; import com.viaversion.viaversion.libs.gson.JsonElement; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.*; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; @@ -69,7 +72,7 @@ public final class EntityPackets1_19_4 extends EntityRewriter { final int blockState = meta.value(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/BlockItemPackets1_20.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/BlockItemPackets1_20.java index d1aed948..8e7f51e6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/BlockItemPackets1_20.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_4to1_20/packets/BlockItemPackets1_20.java @@ -158,15 +158,15 @@ public final class BlockItemPackets1_20 extends ItemRewriter { private final Set newTrimPatterns = Sets.newHashSet("host_armor_trim_smithing_template", "raiser_armor_trim_smithing_template", - "silence_armor_trim_smithing_template", "shaper_armor_trim_smithing_template", "wayfinder_armor_trim_smithing_template"); + "silence_armor_trim_smithing_template", "shaper_armor_trim_smithing_template", "wayfinder_armor_trim_smithing_template"); private static final Quaternion Y_FLIPPED_ROTATION = new Quaternion(0, 1, 0, 0); public EntityPackets1_20(final Protocol1_19_4To1_20 protocol) { @@ -81,16 +80,18 @@ public final class EntityPackets1_20 extends EntityRewriter { final CompoundTag registry = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - ListTag values; + final ListTag values; // A 1.20 server can't send this element, and the 1.20 client still works, if the element is missing // on a 1.19.4 client there is an exception, so in case the 1.20 server doesn't send the element we put in an original 1.20 element - if (registry.contains("minecraft:trim_pattern")) { - values = ((CompoundTag) registry.get("minecraft:trim_pattern")).get("value"); + final CompoundTag trimPatternTag = registry.getCompoundTag("minecraft:trim_pattern"); + if (trimPatternTag != null) { + values = trimPatternTag.getListTag("value"); } else { final CompoundTag trimPatternRegistry = Protocol1_19_4To1_20.MAPPINGS.getTrimPatternRegistry().copy(); registry.put("minecraft:trim_pattern", trimPatternRegistry); values = trimPatternRegistry.get("value"); } + for (final Tag entry : values) { final CompoundTag element = ((CompoundTag) entry).get("element"); final StringTag templateItem = element.get("template_item"); @@ -124,7 +125,7 @@ public final class EntityPackets1_20 extends EntityRewriter meta.setMetaType(Types1_19_4.META_TYPES.byId(meta.metaType().typeId()))); registerMetaTypeHandler(Types1_19_4.META_TYPES.itemType, Types1_19_4.META_TYPES.blockStateType, Types1_19_4.META_TYPES.optionalBlockStateType, - Types1_19_4.META_TYPES.particleType, Types1_19_4.META_TYPES.componentType, Types1_19_4.META_TYPES.optionalComponentType); + Types1_19_4.META_TYPES.particleType, Types1_19_4.META_TYPES.componentType, Types1_19_4.META_TYPES.optionalComponentType); filter().type(EntityTypes1_19_4.MINECART_ABSTRACT).index(11).handler((event, meta) -> { final int blockState = meta.value(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java index 45caedda..91e8fe7f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/Protocol1_19To1_19_1.java @@ -103,7 +103,7 @@ public final class Protocol1_19To1_19_1 extends BackwardsProtocolget("element").get("chat"); + chatType = chatType.getCompoundTag("element").getCompoundTag("chat"); if (chatType == null) { return null; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/packets/EntityPackets1_19_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/packets/EntityPackets1_19_1.java index 2167a65f..b7a254f2 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/packets/EntityPackets1_19_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19to1_19_1/packets/EntityPackets1_19_1.java @@ -19,8 +19,8 @@ package com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.packets; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19; import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19; import com.viaversion.viaversion.api.type.types.version.Types1_19; import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPackets1_19_1; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/BlockItemPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/BlockItemPacketRewriter1_20_3.java index 5e3adbec..98d1f5d1 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/BlockItemPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/rewriter/BlockItemPacketRewriter1_20_3.java @@ -120,9 +120,9 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/storage/SpawnPositionStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/storage/SpawnPositionStorage.java index 9c14541e..38eecdd8 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/storage/SpawnPositionStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_2to1_20_3/storage/SpawnPositionStorage.java @@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_20_2to1_20_3.storage; import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.libs.fastutil.Pair; - import java.util.Objects; public class SpawnPositionStorage implements StorableObject { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java index 4d1f5baa..dcd1f78d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/rewriter/BlockItemPacketRewriter1_20_2.java @@ -34,8 +34,8 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2; @@ -108,13 +108,13 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user()); final Type chunkType = new ChunkType1_20_2(tracker.currentWorldSectionHeight(), - MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()), - MathUtil.ceilLog2(tracker.biomesSent())); + MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()), + MathUtil.ceilLog2(tracker.biomesSent())); final Chunk chunk = wrapper.read(chunkType); final Type newChunkType = new ChunkType1_18(tracker.currentWorldSectionHeight(), - MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), - MathUtil.ceilLog2(tracker.biomesSent())); + MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), + MathUtil.ceilLog2(tracker.biomesSent())); wrapper.write(newChunkType, chunk); for (final ChunkSection section : chunk.getSections()) { @@ -399,16 +399,16 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter types = new HashMap<>(); + private static final Map TYPES = new HashMap<>(); static { - types.put("MobSpawner", 1); - types.put("Control", 2); - types.put("Beacon", 3); - types.put("Skull", 4); - types.put("FlowerPot", 5); - types.put("Banner", 6); - types.put("UNKNOWN", 7); - types.put("EndGateway", 8); - types.put("Sign", 9); + TYPES.put("MobSpawner", 1); + TYPES.put("Control", 2); + TYPES.put("Beacon", 3); + TYPES.put("Skull", 4); + TYPES.put("FlowerPot", 5); + TYPES.put("Banner", 6); + TYPES.put("UNKNOWN", 7); + TYPES.put("EndGateway", 8); + TYPES.put("Sign", 9); } - public static void handle(List tags, UserConnection connection) { + public static void handle(List tags, UserConnection connection) throws Exception { for (CompoundTag tag : tags) { - try { - if (!tag.contains("id")) - throw new Exception("NBT tag not handled because the id key is missing"); - - String id = (String) tag.get("id").getValue(); - if (!types.containsKey(id)) - throw new Exception("Not handled id: " + id); - - int newId = types.get(id); - if (newId == -1) - continue; - - int x = ((NumberTag) tag.get("x")).asInt(); - int y = ((NumberTag) tag.get("y")).asInt(); - int z = ((NumberTag) tag.get("z")).asInt(); - - Position pos = new Position(x, (short) y, z); - - updateBlockEntity(pos, (short) newId, tag, connection); - } catch (Exception e) { - if (Via.getManager().isDebug()) { - Via.getPlatform().getLogger().warning("Block Entity: " + e.getMessage() + ": " + tag); - } + StringTag idTag = tag.getStringTag("id"); + if (idTag == null) { + continue; } + + String id = idTag.getValue(); + if (!TYPES.containsKey(id)) { + continue; + } + + int newId = TYPES.get(id); + if (newId == -1) { + continue; + } + + int x = tag.getNumberTag("x").asInt(); + int y = tag.getNumberTag("y").asInt(); + int z = tag.getNumberTag("z").asInt(); + + Position pos = new Position(x, (short) y, z); + + updateBlockEntity(pos, (short) newId, tag, connection); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets1_10.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets1_10.java index 3dc40faf..5dbf9e92 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets1_10.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_9_4to1_10/packets/EntityPackets1_10.java @@ -23,10 +23,10 @@ import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import com.viaversion.viabackwards.utils.Block; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12; -import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; From b60464296b563eba2d83653513ddc9ee17fc323d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 12 Feb 2024 11:02:55 +0100 Subject: [PATCH 4/4] Small cleanups --- .../api/exceptions/RemovedValueException.java | 34 -------- .../api/rewriters/ItemRewriter.java | 3 +- .../api/rewriters/ItemRewriterBase.java | 2 +- .../block_entity_handlers/BannerHandler.java | 3 +- .../block_entity_handlers/BedHandler.java | 3 +- .../FlowerPotHandler.java | 3 +- .../block_entity_handlers/PistonHandler.java | 3 +- .../block_entity_handlers/SkullHandler.java | 3 +- .../block_entity_handlers/SpawnerHandler.java | 3 +- .../packets/BlockItemPackets1_13.java | 2 +- .../packets/PlayerPacket1_13.java | 12 ++- .../BackwardsBlockEntityProvider.java | 5 +- .../storage/BackwardsBlockStorage.java | 7 +- .../storage/PlayerPositionStorage1_13.java | 3 - .../packets/BlockItemPackets1_16_2.java | 4 +- .../Protocol1_19_1To1_19_3.java | 84 ++++++++----------- .../viaversion/viabackwards/utils/Block.java | 5 -- .../viabackwards/utils/ChatUtil.java | 2 +- .../viaversion/viabackwards/SpongePlugin.java | 2 - .../viabackwards/VelocityPlugin.java | 1 - 20 files changed, 59 insertions(+), 125 deletions(-) delete mode 100644 common/src/main/java/com/viaversion/viabackwards/api/exceptions/RemovedValueException.java diff --git a/common/src/main/java/com/viaversion/viabackwards/api/exceptions/RemovedValueException.java b/common/src/main/java/com/viaversion/viabackwards/api/exceptions/RemovedValueException.java deleted file mode 100644 index 91c32b9d..00000000 --- a/common/src/main/java/com/viaversion/viabackwards/api/exceptions/RemovedValueException.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.api.exceptions; - -import java.io.IOException; - -public class RemovedValueException extends IOException { - - /** - * May be cached since it is never actually printed, only checked. - */ - public static final RemovedValueException EX = new RemovedValueException() { - @Override - public Throwable fillInStackTrace() { - return this; - } - }; -} diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java index c98cf953..e78d7d62 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java @@ -29,6 +29,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import org.checkerframework.checker.nullness.qual.Nullable; @@ -118,7 +119,7 @@ public class ItemRewriter itemType, Type itemArrayType, boolean jsonNameFormat) { + protected ItemRewriterBase(T protocol, Type itemType, Type itemArrayType, boolean jsonNameFormat) { super(protocol, itemType, itemArrayType); this.jsonNameFormat = jsonNameFormat; nbtTagName = "VB|" + protocol.getClass().getSimpleName(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BannerHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BannerHandler.java index 0823a154..ee766d85 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BannerHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BannerHandler.java @@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; @@ -34,7 +33,7 @@ public class BannerHandler implements BackwardsBlockEntityHandler { private static final int BANNER_STOP = 7109; @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { // Normal banners if (blockId >= BANNER_START && blockId <= BANNER_STOP) { int color = (blockId - BANNER_START) >> 4; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java index fa12bc46..25042c25 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java @@ -19,13 +19,12 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { int offset = blockId - 748; int color = offset >> 4; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java index 8309cd03..cf60ae3a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java @@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -70,7 +69,7 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB // TODO THIS IS NEVER CALLED BECAUSE ITS NO LONGER A BLOCK ENTITY :( @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { Pair item = getOrDefault(blockId); tag.putString("Item", item.key()); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java index 63d3fddd..50fdf223 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java @@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.data.MappingDataLoader; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap; @@ -77,7 +76,7 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc } @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { CompoundTag blockState = tag.getCompoundTag("blockState"); if (blockState == null) return tag; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java index 59e695f4..2774a86f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java @@ -19,14 +19,13 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; public class SkullHandler implements BackwardsBlockEntityHandler { private static final int SKULL_START = 5447; @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { int diff = blockId - SKULL_START; int pos = diff % 20; byte type = (byte) Math.floor(diff / 20f); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java index b2ac7ea8..8d589189 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java @@ -20,14 +20,13 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityNameRewrites; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { CompoundTag dataTag = tag.getCompoundTag("SpawnData"); if (dataTag != null) { StringTag idTag = dataTag.getStringTag("id"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 6cb587c7..a568340a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -711,7 +711,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit tag.putInt("HideFlags", value); } - if (noMapped.size() != 0) { + if (!noMapped.isEmpty()) { tag.put(extraNbtTag + "|" + key, noMapped); if (!lore.isEmpty()) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java index fc87aa9a..1ffba60c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -61,12 +61,10 @@ public class PlayerPacket1_13 extends RewriterBase { public void register() { handler(packetWrapper -> { packetWrapper.cancel(); - packetWrapper.create(0x02, new PacketHandler() { // Plugin response - @Override - public void handle(PacketWrapper newWrapper) throws Exception { - newWrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id - newWrapper.write(Type.BOOLEAN, false); // Success - } + // Plugin response + packetWrapper.create(0x02, wrapper -> { + wrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id + wrapper.write(Type.BOOLEAN, false); // Success }).sendToServer(Protocol1_12_2To1_13.class); }); } @@ -392,7 +390,7 @@ public class PlayerPacket1_13 extends RewriterBase { if (type == 0) { //Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089 //The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either. - //Maybe older versions used this and we need to implement this? The issues is that we would have to save the command block types + //Maybe older versions used this and we need to implement this? The issue is that we would have to save the command block types wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK); wrapper.cancel(); ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java index 64dcfc62..1daf268d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java @@ -80,7 +80,7 @@ public class BackwardsBlockEntityProvider implements Provider { return tag; } - return handler.transform(user, blockId, tag); + return handler.transform(blockId, tag); } /** @@ -102,6 +102,7 @@ public class BackwardsBlockEntityProvider implements Provider { @FunctionalInterface public interface BackwardsBlockEntityHandler { - CompoundTag transform(UserConnection user, int blockId, CompoundTag tag); + + CompoundTag transform(int blockId, CompoundTag tag); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java index e7ed334d..c62080d2 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java @@ -24,6 +24,7 @@ import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet; import com.viaversion.viaversion.libs.fastutil.ints.IntSet; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.checkerframework.checker.nullness.qual.Nullable; public class BackwardsBlockStorage implements StorableObject { // This BlockStorage is very exclusive (; @@ -77,11 +78,7 @@ public class BackwardsBlockStorage implements StorableObject { blocks.put(position, block); } - public boolean isWelcome(int block) { - return WHITELIST.contains(block); - } - - public Integer get(Position position) { + public @Nullable Integer get(Position position) { return blocks.get(position); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java index f3de9337..0ae11884 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java @@ -20,7 +20,4 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage; import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage; public class PlayerPositionStorage1_13 extends PlayerPositionStorage { - - public PlayerPositionStorage1_13() { - } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java index 25112222..9990865a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java @@ -103,9 +103,7 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr public void register() { map(Type.POSITION1_14); map(Type.UNSIGNED_BYTE); - handler(wrapper -> { - handleBlockEntity(wrapper.passthrough(Type.NAMED_COMPOUND_TAG)); - }); + handler(wrapper -> handleBlockEntity(wrapper.passthrough(Type.NAMED_COMPOUND_TAG))); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java index 805cc41e..6c81a856 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java @@ -37,6 +37,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3; import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider; import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata; import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; @@ -59,6 +60,7 @@ import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.Pair; import java.util.BitSet; import java.util.List; +import org.checkerframework.checker.nullness.qual.Nullable; public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol { @@ -91,60 +93,19 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol soundRewriter = new SoundRewriter<>(this); soundRewriter.registerStopSound(ClientboundPackets1_19_3.STOP_SOUND); registerClientbound(ClientboundPackets1_19_3.SOUND, wrapper -> { - final int soundId = wrapper.read(Type.VAR_INT) - 1; // Normalize the id - if (soundId != -1) { - final int mappedId = MAPPINGS.getSoundMappings().getNewId(soundId); - if (mappedId == -1) { - wrapper.cancel(); - return; - } - - wrapper.write(Type.VAR_INT, mappedId); - return; - } - - String soundIdentifier = wrapper.read(Type.STRING); - wrapper.read(Type.OPTIONAL_FLOAT); // Fixed range - final String mappedIdentifier = MAPPINGS.getMappedNamedSound(soundIdentifier); + final String mappedIdentifier = rewriteSound(wrapper); if (mappedIdentifier != null) { - if (mappedIdentifier.isEmpty()) { - wrapper.cancel(); - return; - } - - soundIdentifier = mappedIdentifier; + wrapper.write(Type.STRING, mappedIdentifier); + wrapper.setPacketType(ClientboundPackets1_19_1.NAMED_SOUND); } - - wrapper.write(Type.STRING, soundIdentifier); - wrapper.setPacketType(ClientboundPackets1_19_1.NAMED_SOUND); }); registerClientbound(ClientboundPackets1_19_3.ENTITY_SOUND, wrapper -> { - final int soundId = wrapper.read(Type.VAR_INT) - 1; // Normalize the id - if (soundId != -1) { - final int mappedId = MAPPINGS.getSoundMappings().getNewId(soundId); - if (mappedId == -1) { - wrapper.cancel(); - return; - } - - wrapper.write(Type.VAR_INT, mappedId); + final String mappedIdentifier = rewriteSound(wrapper); + if (mappedIdentifier == null) { return; } - // Convert the resource location to the corresponding integer id - String soundIdentifier = wrapper.read(Type.STRING); - wrapper.read(Type.OPTIONAL_FLOAT); // Fixed range - final String mappedIdentifier = MAPPINGS.getMappedNamedSound(soundIdentifier); - if (mappedIdentifier != null) { - if (mappedIdentifier.isEmpty()) { - wrapper.cancel(); - return; - } - - soundIdentifier = mappedIdentifier; - } - - final int mappedId = MAPPINGS.mappedSound(soundIdentifier); + final int mappedId = MAPPINGS.mappedSound(mappedIdentifier); if (mappedId == -1) { wrapper.cancel(); return; @@ -387,6 +348,35 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol(?>§[0-fk-or])*(§r|\\Z))|(?>(?>§[0-f])*(§[0-f]))"); private static final Pattern UNUSED_COLOR_PATTERN_PREFIX = Pattern.compile("(?>(?>§[0-fk-or])*(§r))|(?>(?>§[0-f])*(§[0-f]))"); diff --git a/sponge/src/main/java/com/viaversion/viabackwards/SpongePlugin.java b/sponge/src/main/java/com/viaversion/viabackwards/SpongePlugin.java index e29164cc..13a6b061 100644 --- a/sponge/src/main/java/com/viaversion/viabackwards/SpongePlugin.java +++ b/sponge/src/main/java/com/viaversion/viabackwards/SpongePlugin.java @@ -21,7 +21,6 @@ package com.viaversion.viabackwards; import com.google.inject.Inject; import com.viaversion.viabackwards.api.ViaBackwardsPlatform; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.data.MappingDataLoader; import com.viaversion.viaversion.sponge.util.LoggerWrapper; import java.io.File; import java.nio.file.Path; @@ -39,7 +38,6 @@ public class SpongePlugin implements ViaBackwardsPlatform { @ConfigDir(sharedRoot = false) private Path configPath; - @SuppressWarnings("SpongeInjection") @Inject SpongePlugin(final org.apache.logging.log4j.Logger logger) { this.logger = new LoggerWrapper(logger); diff --git a/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java b/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java index 07629011..87ac645a 100644 --- a/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java +++ b/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java @@ -28,7 +28,6 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.viaversion.viabackwards.api.ViaBackwardsPlatform; import com.viaversion.viabackwards.utils.VersionInfo; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.data.MappingDataLoader; import com.viaversion.viaversion.velocity.util.LoggerWrapper; import java.io.File; import java.nio.file.Path;