From 8a485db5809f23fbc8a985aa61583a42c11cb2b2 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 10 Feb 2024 23:28:36 +0100 Subject: [PATCH 1/3] Replace tag instanceof checks/unchecked casts with helper methods --- .../configuration/AbstractViaConfig.java | 1 - .../data/entity/DimensionDataImpl.java | 16 +- .../protocol/ProtocolManagerImpl.java | 7 +- .../protocols/base/BaseProtocol1_16.java | 1 - .../Protocol1_10To1_9_3_4.java | 4 +- .../protocol1_11to1_10/EntityIdRewriter.java | 31 +- .../Protocol1_11To1_10.java | 33 +- .../Protocol1_12To1_11_1.java | 4 +- .../Protocol1_13_1To1_13.java | 2 +- .../packets/WorldPackets.java | 4 +- .../blockconnections/ConnectionData.java | 8 +- .../FireConnectionHandler.java | 1 - .../data/ComponentRewriter1_13.java | 4 +- .../data/EntityNameRewriter.java | 1 - .../data/MappingData.java | 17 +- .../data/ParticleRewriter.java | 2 +- .../data/SpawnEggRewriter.java | 1 - .../packets/EntityPackets.java | 2 +- .../packets/InventoryPackets.java | 301 +++++++++++------- .../packets/WorldPackets.java | 15 +- .../providers/BlockEntityProvider.java | 9 +- .../providers/PaintingProvider.java | 1 - .../blockentities/BannerHandler.java | 39 +-- .../providers/blockentities/BedHandler.java | 13 +- .../blockentities/CommandBlockHandler.java | 16 +- .../blockentities/FlowerPotHandler.java | 1 - .../providers/blockentities/SkullHandler.java | 20 +- .../blockentities/SpawnerHandler.java | 12 +- .../storage/BlockConnectionStorage.java | 3 +- .../Protocol1_14To1_13_2.java | 2 +- .../data/MappingData.java | 4 +- .../packets/InventoryPackets.java | 26 +- .../packets/PlayerPackets.java | 10 +- .../packets/WorldPackets.java | 6 +- .../packets/WorldPackets.java | 4 +- .../data/MappingData.java | 7 +- .../packets/WorldPackets.java | 4 +- .../Protocol1_16To1_15_2.java | 1 - .../packets/EntityPackets.java | 9 +- .../packets/InventoryPackets.java | 58 ++-- .../packets/WorldPackets.java | 35 +- .../packets/InventoryPackets.java | 3 +- .../packets/WorldPackets.java | 4 +- .../packets/WorldPackets.java | 17 +- .../Protocol1_19_1To1_19.java | 20 +- .../packets/EntityPackets.java | 1 - .../packets/EntityPackets.java | 3 +- .../packets/WorldPackets.java | 2 +- .../BlockItemPacketRewriter1_20_2.java | 14 +- .../BlockItemPacketRewriter1_20_3.java | 4 +- .../Protocol1_9_3To1_9_1_2.java | 4 +- .../protocol1_9to1_8/ItemRewriter.java | 26 +- .../protocol1_9to1_8/Protocol1_9To1_8.java | 20 +- .../protocol1_9to1_8/metadata/MetaIndex.java | 2 +- .../packets/EntityPackets.java | 7 +- .../packets/WorldPackets.java | 17 +- .../MovementTransmitterProvider.java | 1 - .../storage/ClientChunks.java | 1 - .../rewriter/ComponentRewriter.java | 36 +-- .../viaversion/rewriter/EntityRewriter.java | 19 +- .../rewriter/meta/MetaHandlerEvent.java | 3 +- .../viaversion/update/UpdateUtil.java | 2 - .../common/entities/EntityTypesTest.java | 2 +- gradle/libs.versions.toml | 2 +- 64 files changed, 495 insertions(+), 450 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java b/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java index bf07fb92d..144d8c0e3 100644 --- a/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java +++ b/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java @@ -18,7 +18,6 @@ package com.viaversion.viaversion.configuration; import com.google.gson.JsonElement; -import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.api.minecraft.WorldIdentifiers; import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions; diff --git a/common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java b/common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java index 0e6af9609..43facb934 100644 --- a/common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/data/entity/DimensionDataImpl.java @@ -18,9 +18,7 @@ package com.viaversion.viaversion.data.entity; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.api.data.entity.DimensionData; public final class DimensionDataImpl implements DimensionData { @@ -34,19 +32,17 @@ public final class DimensionDataImpl implements DimensionData { } public DimensionDataImpl(final CompoundTag dimensionData) { - final Tag height = dimensionData.get("height"); - if (height instanceof IntTag) { - this.height = ((NumberTag) height).asInt(); - } else { + final NumberTag height = dimensionData.getNumberTag("height"); + if (height == null) { throw new IllegalArgumentException("height missing in dimension data: " + dimensionData); } + this.height = height.asInt(); - final Tag minY = dimensionData.get("min_y"); - if (minY instanceof IntTag) { - this.minY = ((NumberTag) minY).asInt(); - } else { + final NumberTag minY = dimensionData.getNumberTag("min_y"); + if (minY == null) { throw new IllegalArgumentException("min_y missing in dimension data: " + dimensionData); } + this.minY = minY.asInt(); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java index f25b5cca2..d4e51d4a4 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java @@ -82,10 +82,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap; -import java.util.logging.Level; -import org.checkerframework.checker.nullness.qual.Nullable; -import us.myles.ViaVersion.api.protocol.ProtocolRegistry; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -106,6 +102,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Function; +import java.util.logging.Level; +import org.checkerframework.checker.nullness.qual.Nullable; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; public class ProtocolManagerImpl implements ProtocolManager { private static final Protocol BASE_PROTOCOL = new BaseProtocol(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseProtocol1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseProtocol1_16.java index 89449c67b..62b2b4fd8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseProtocol1_16.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseProtocol1_16.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.base; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; - import java.util.UUID; public class BaseProtocol1_16 extends BaseProtocol1_7 { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java index 200cb4dad..3454ee1ad 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java @@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_10to1_9_3; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; @@ -28,13 +29,12 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.protocols.protocol1_10to1_9_3.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker; 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; -import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/EntityIdRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/EntityIdRewriter.java index 0edf243b2..73b39c0f3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/EntityIdRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/EntityIdRewriter.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_11to1_10; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -115,12 +114,11 @@ public class EntityIdRewriter { } public static void toClient(CompoundTag tag, boolean backwards) { - Tag idTag = tag.get("id"); - if (idTag instanceof StringTag) { - StringTag id = (StringTag) idTag; - String newName = backwards ? oldToNewNames.inverse().get(id.getValue()) : oldToNewNames.get(id.getValue()); + StringTag idTag = tag.getStringTag("id"); + if (idTag != null) { + String newName = backwards ? oldToNewNames.inverse().get(idTag.getValue()) : oldToNewNames.get(idTag.getValue()); if (newName != null) { - id.setValue(newName); + idTag.setValue(newName); } } } @@ -132,9 +130,9 @@ public class EntityIdRewriter { public static void toClientSpawner(CompoundTag tag, boolean backwards) { if (tag == null) return; - Tag spawnDataTag = tag.get("SpawnData"); + CompoundTag spawnDataTag = tag.getCompoundTag("SpawnData"); if (spawnDataTag != null) { - toClient((CompoundTag) spawnDataTag, backwards); + toClient(spawnDataTag, backwards); } } @@ -144,7 +142,7 @@ public class EntityIdRewriter { public static void toClientItem(Item item, boolean backwards) { if (hasEntityTag(item)) { - toClient(item.tag().get("EntityTag"), backwards); + toClient(item.tag().getCompoundTag("EntityTag"), backwards); } if (item != null && item.amount() <= 0) item.setAmount(1); } @@ -156,13 +154,12 @@ public class EntityIdRewriter { public static void toServerItem(Item item, boolean backwards) { if (!hasEntityTag(item)) return; - CompoundTag entityTag = item.tag().get("EntityTag"); - Tag idTag = entityTag.get("id"); - if (idTag instanceof StringTag) { - StringTag id = (StringTag) idTag; - String newName = backwards ? oldToNewNames.get(id.getValue()) : oldToNewNames.inverse().get(id.getValue()); + CompoundTag entityTag = item.tag().getCompoundTag("EntityTag"); + StringTag idTag = entityTag.getStringTag("id"); + if (idTag != null) { + String newName = backwards ? oldToNewNames.get(idTag.getValue()) : oldToNewNames.inverse().get(idTag.getValue()); if (newName != null) { - id.setValue(newName); + idTag.setValue(newName); } } } @@ -173,7 +170,7 @@ public class EntityIdRewriter { CompoundTag tag = item.tag(); if (tag == null) return false; - Tag entityTag = tag.get("EntityTag"); - return entityTag instanceof CompoundTag && ((CompoundTag) entityTag).get("id") instanceof StringTag; + CompoundTag entityTag = tag.getCompoundTag("EntityTag"); + return entityTag != null && entityTag.getStringTag("id") != null; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java index cce340cd3..dd161f78f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java @@ -21,6 +21,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.protocol.AbstractProtocol; @@ -28,6 +29,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.protocols.protocol1_11to1_10.data.PotionColorMapping; import com.viaversion.viaversion.protocols.protocol1_11to1_10.metadata.MetadataRewriter1_11To1_10; @@ -35,8 +37,6 @@ import com.viaversion.viaversion.protocols.protocol1_11to1_10.packets.InventoryP import com.viaversion.viaversion.protocols.protocol1_11to1_10.storage.EntityTracker1_11; 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; -import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.util.Pair; @@ -193,13 +193,15 @@ public class Protocol1_11To1_10 extends AbstractProtocol { CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); - if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1) + if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1) { EntityIdRewriter.toClientSpawner(tag); + } - if (tag.contains("id")) + StringTag idTag = tag.getStringTag("id"); + if (idTag != null) { // Handle new identifier - ((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier((String) tag.get("id").getValue())); - + idTag.setValue(BlockEntityRewriter.toNewIdentifier(idTag.getValue())); + } }); } }); @@ -211,15 +213,18 @@ public class Protocol1_11To1_10 extends AbstractProtocol(2048); - ListTag blockConnectionMappings = MappingDataLoader.loadNBT("blockConnections.nbt").get("data"); + ListTag blockConnectionMappings = MappingDataLoader.loadNBT("blockConnections.nbt").getListTag("data"); for (Tag blockTag : blockConnectionMappings) { CompoundTag blockCompoundTag = (CompoundTag) blockTag; BlockData blockData = new BlockData(); @@ -198,11 +198,11 @@ public final class ConnectionData { blockData.put(connectionTypeId, attachingFaces); } - NumberTag idTag = blockCompoundTag.get("id"); + NumberTag idTag = blockCompoundTag.getNumberTag("id"); if (idTag != null) { blockConnectionData.put(idTag.asInt(), blockData); } else { - IntArrayTag idsTag = blockCompoundTag.get("ids"); + IntArrayTag idsTag = blockCompoundTag.getIntArrayTag("ids"); for (int id : idsTag.getValue()) { blockConnectionData.put(id, blockData); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FireConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FireConnectionHandler.java index aca84392b..418d7732b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FireConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FireConnectionHandler.java @@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.util.Key; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; - import java.util.HashSet; import java.util.Set; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ComponentRewriter1_13.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ComponentRewriter1_13.java index c289f4aff..f6c9130d1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ComponentRewriter1_13.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ComponentRewriter1_13.java @@ -62,8 +62,8 @@ public class ComponentRewriter1_13 extends Comp return; } - CompoundTag itemTag = tag.get("tag"); - NumberTag damageTag = tag.get("Damage"); + CompoundTag itemTag = tag.getCompoundTag("tag"); + NumberTag damageTag = tag.getNumberTag("Damage"); // Call item converter short damage = damageTag != null ? damageTag.asShort() : 0; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java index 7a1c23a0a..b31a7f25a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/EntityNameRewriter.java @@ -18,7 +18,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data; import com.viaversion.viaversion.util.Key; - import java.util.HashMap; import java.util.Map; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/MappingData.java index 0cb2aa354..4c96d655f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -28,18 +28,21 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.data.*; +import com.viaversion.viaversion.api.data.BiMappings; +import com.viaversion.viaversion.api.data.Int2IntMapBiMappings; +import com.viaversion.viaversion.api.data.MappingDataBase; +import com.viaversion.viaversion.api.data.MappingDataLoader; +import com.viaversion.viaversion.api.data.Mappings; import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.Int2IntBiHashMap; import com.viaversion.viaversion.util.Key; -import org.checkerframework.checker.nullness.qual.Nullable; - import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; +import org.checkerframework.checker.nullness.qual.Nullable; public class MappingData extends MappingDataBase { private final Map blockTags = new HashMap<>(); @@ -56,11 +59,11 @@ public class MappingData extends MappingDataBase { @Override protected void loadExtras(final CompoundTag data) { - loadTags(blockTags, data.get("block_tags")); - loadTags(itemTags, data.get("item_tags")); - loadTags(fluidTags, data.get("fluid_tags")); + loadTags(blockTags, data.getCompoundTag("block_tags")); + loadTags(itemTags, data.getCompoundTag("item_tags")); + loadTags(fluidTags, data.getCompoundTag("fluid_tags")); - CompoundTag legacyEnchantments = data.get("legacy_enchantments"); + CompoundTag legacyEnchantments = data.getCompoundTag("legacy_enchantments"); loadEnchantments(oldEnchantmentsIds, legacyEnchantments); // Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13 diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java index 260f0e235..c8c176cc0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java @@ -18,10 +18,10 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.WorldPackets; import java.util.ArrayList; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java index a75fe1aea..b06be07b3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/SpawnEggRewriter.java @@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.viaversion.viaversion.util.Key; - import java.util.Optional; public class SpawnEggRewriter { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java index 8b7255699..94adda082 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/EntityPackets.java @@ -18,6 +18,7 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; @@ -26,7 +27,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2; -import com.viaversion.viaversion.api.minecraft.ClientWorld; public class EntityPackets { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index d3e6be079..d5cea8d8f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -21,7 +21,6 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; -import com.github.steveice10.opennbt.tag.builtin.ShortTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.common.base.Joiner; @@ -284,85 +283,117 @@ public class InventoryPackets extends ItemRewriter> 4].palette(PaletteType.BLOCKS).setIdAt(x & 0xF, y & 0xF, z & 0xF, newId); } - final Tag idTag = tag.get("id"); - if (idTag instanceof StringTag) { + final StringTag idTag = tag.getStringTag("id"); + if (idTag != null) { // No longer block entities - final String id = Key.namespaced(((StringTag) idTag).getValue()); + final String id = Key.namespaced(idTag.getValue()); if (id.equals("minecraft:noteblock") || id.equals("minecraft:flower_pot")) { iterator.remove(); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java index efce76f69..2583f1d7d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java @@ -18,7 +18,7 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Position; @@ -59,14 +59,13 @@ public class BlockEntityProvider implements Provider { * @throws Exception Gotta throw that exception */ public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception { - Tag idTag = tag.get("id"); + StringTag idTag = tag.getStringTag("id"); if (idTag == null) return -1; - String id = (String) idTag.getValue(); - BlockEntityHandler handler = handlers.get(id); + BlockEntityHandler handler = handlers.get(idTag.getValue()); if (handler == null) { if (Via.getManager().isDebug()) { - Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag); + Via.getPlatform().getLogger().warning("Unhandled BlockEntity " + idTag.getValue() + " full tag: " + tag); } return -1; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java index 7bb83025f..e53f7ca47 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/PaintingProvider.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers; import com.viaversion.viaversion.api.platform.providers.Provider; import com.viaversion.viaversion.util.Key; - import java.util.HashMap; import java.util.Locale; import java.util.Map; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java index 292a11c40..e3c93e55a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java @@ -18,7 +18,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.blockentities; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; @@ -40,7 +39,7 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler { @Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); - Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z"))); + Position position = new Position(tag.getNumberTag("x").asInt(), tag.getNumberTag("y").asShort(), tag.getNumberTag("z").asInt()); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag); @@ -49,11 +48,8 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler { int blockId = storage.get(position).getOriginal(); - Tag base = tag.get("Base"); - int color = 0; - if (base instanceof NumberTag) { - color = ((NumberTag) base).asInt(); - } + NumberTag base = tag.getNumberTag("Base"); + int color = base != null ? base.asInt() : 0; // Standing banner if (blockId >= BANNER_START && blockId <= BANNER_STOP) { blockId += ((15 - color) * 16); @@ -64,27 +60,26 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler { Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag); } - Tag patterns = tag.get("Patterns"); - if (patterns instanceof ListTag) { - for (Tag pattern : (ListTag) patterns) { - if (pattern instanceof CompoundTag) { - Tag c = ((CompoundTag) pattern).get("Color"); - if (c instanceof IntTag) { - ((IntTag) c).setValue(15 - (int) c.getValue()); // Invert color id - } + ListTag patterns = tag.getListTag("Patterns"); + if (patterns != null) { + for (Tag pattern : patterns) { + if (!(pattern instanceof CompoundTag)) { + continue; + } + + CompoundTag patternTag = (CompoundTag) pattern; + NumberTag colorTag = patternTag.getNumberTag("Color"); + if (colorTag != null) { + patternTag.putInt("Color", 15 - colorTag.asInt()); // Invert color id } } } - Tag name = tag.get("CustomName"); - if (name instanceof StringTag) { - ((StringTag) name).setValue(ComponentUtil.legacyToJsonString(((StringTag) name).getValue())); + StringTag name = tag.getStringTag("CustomName"); + if (name != null) { + name.setValue(ComponentUtil.legacyToJsonString(name.getValue())); } return blockId; } - - private long getLong(NumberTag tag) { - return tag.asLong(); - } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java index 6ee0e2e85..b794aaf76 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Position; @@ -31,7 +30,7 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler { @Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); - Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z"))); + Position position = new Position(tag.getNumberTag("x").asInt(), tag.getNumberTag("y").asShort(), tag.getNumberTag("z").asInt()); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag); @@ -41,15 +40,11 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler { // RED_BED + FIRST_BED int blockId = storage.get(position).getOriginal() - 972 + 748; - Tag color = tag.get("color"); - if (color instanceof NumberTag) { - blockId += (((NumberTag) color).asInt() * 16); + NumberTag color = tag.getNumberTag("color"); + if (color != null) { + blockId += (color.asInt() * 16); } return blockId; } - - private long getLong(NumberTag tag) { - return tag.asLong(); - } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/CommandBlockHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/CommandBlockHandler.java index b808ecc80..89653af51 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/CommandBlockHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/CommandBlockHandler.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.viaversion.viaversion.api.Via; @@ -34,15 +33,16 @@ public class CommandBlockHandler implements BlockEntityProvider.BlockEntityHandl @Override public int transform(UserConnection user, CompoundTag tag) { - Tag name = tag.get("CustomName"); - if (name instanceof StringTag) { - ((StringTag) name).setValue(ComponentUtil.legacyToJsonString(((StringTag) name).getValue())); + StringTag name = tag.getStringTag("CustomName"); + if (name != null) { + name.setValue(ComponentUtil.legacyToJsonString(name.getValue())); } - Tag out = tag.get("LastOutput"); - if (out instanceof StringTag) { - JsonElement value = JsonParser.parseString(((StringTag) out).getValue()); + + StringTag out = tag.getStringTag("LastOutput"); + if (out != null) { + JsonElement value = JsonParser.parseString(out.getValue()); protocol.getComponentRewriter().processText(value); - ((StringTag) out).setValue(value.toString()); + out.setValue(value.toString()); } return -1; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java index 47827576d..d0dfdf2fd 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/FlowerPotHandler.java @@ -22,7 +22,6 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Pair; - import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java index 550c37758..56d0298c0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Position; @@ -33,7 +32,7 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { @Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); - Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z"))); + Position position = new Position(tag.getNumberTag("x").asInt(), tag.getNumberTag("y").asShort(), tag.getNumberTag("z").asInt()); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag); @@ -42,13 +41,14 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { int id = storage.get(position).getOriginal(); if (id >= SKULL_WALL_START && id <= SKULL_END) { - Tag skullType = tag.get("SkullType"); - if (skullType instanceof NumberTag) { - id += ((NumberTag) skullType).asInt() * 20; + NumberTag skullType = tag.getNumberTag("SkullType"); + if (skullType != null) { + id += skullType.asInt() * 20; } - Tag rot = tag.get("Rot"); - if (rot instanceof NumberTag) { - id += ((NumberTag) rot).asInt(); + + NumberTag rot = tag.getNumberTag("Rot"); + if (rot != null) { + id += rot.asInt(); } } else { Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag); @@ -57,8 +57,4 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { return id; } - - private long getLong(NumberTag tag) { - return tag.asLong(); - } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/SpawnerHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/SpawnerHandler.java index 4e92a5c79..7d3bf7511 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/SpawnerHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/blockentities/SpawnerHandler.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.block import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.EntityNameRewriter; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider; @@ -27,13 +26,12 @@ import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.BlockE public class SpawnerHandler implements BlockEntityProvider.BlockEntityHandler { @Override public int transform(UserConnection user, CompoundTag tag) { - Tag data = tag.get("SpawnData"); - if (data instanceof CompoundTag) { - Tag id = ((CompoundTag) data).get("id"); - if (id instanceof StringTag) { - ((StringTag) id).setValue(EntityNameRewriter.rewrite(((StringTag) id).getValue())); + CompoundTag data = tag.getCompoundTag("SpawnData"); + if (data != null) { + StringTag id = data.getStringTag("id"); + if (id != null) { + id.setValue(EntityNameRewriter.rewrite(id.getValue())); } - } // Always return -1 because the block is still the same id diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java index 50cf574b0..69b72b64d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java @@ -20,13 +20,12 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage; import com.google.common.collect.EvictingQueue; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.StorableObject; +import com.viaversion.viaversion.api.minecraft.Position; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; import java.util.Queue; - -import com.viaversion.viaversion.api.minecraft.Position; import org.checkerframework.checker.nullness.qual.Nullable; public class BlockConnectionStorage implements StorableObject { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java index 6dec33486..cd28caee9 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java @@ -18,6 +18,7 @@ package com.viaversion.viaversion.protocols.protocol1_14to1_13_2; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.misc.ParticleType; @@ -33,7 +34,6 @@ import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.Inventor import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.PlayerPackets; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.rewriter.CommandRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/data/MappingData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/data/MappingData.java index 30e858129..1dd8b7461 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/data/MappingData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/data/MappingData.java @@ -36,11 +36,11 @@ public class MappingData extends MappingDataBase { @Override public void loadExtras(final CompoundTag data) { final CompoundTag heightmap = MappingDataLoader.loadNBT("heightmap-1.14.nbt"); - final IntArrayTag motionBlocking = heightmap.get("motionBlocking"); + final IntArrayTag motionBlocking = heightmap.getIntArrayTag("motionBlocking"); this.motionBlocking = new IntOpenHashSet(motionBlocking.getValue()); if (Via.getConfig().isNonFullBlockLightFix()) { - final IntArrayTag nonFullBlocks = heightmap.get("nonFullBlocks"); + final IntArrayTag nonFullBlocks = heightmap.getIntArrayTag("nonFullBlocks"); this.nonFullBlocks = new IntOpenHashSet(nonFullBlocks.getValue()); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index e23aa54ea..16f16cc32 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -242,12 +242,10 @@ public class InventoryPackets extends ItemRewriter 50) { - listTag.setValue(listTag.getValue().subList(0, 50)); + if (Via.getConfig().isTruncate1_14Books() && pages != null) { + if (pages.size() > 50) { + pages.setValue(pages.getValue().subList(0, 50)); } } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java index 380573564..cee9b7723 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java @@ -22,6 +22,7 @@ import com.github.steveice10.opennbt.tag.builtin.LongArrayTag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.BlockFace; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; @@ -30,13 +31,12 @@ import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_13; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_14; +import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; -import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_14; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.util.CompactArrayUtil; import java.util.Arrays; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java index 58b378393..ff5ecca6b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java @@ -23,10 +23,10 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_14; -import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_15; +import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4; +import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import com.viaversion.viaversion.rewriter.BlockRewriter; public final class WorldPackets { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java index bbdd18d3d..2fc15e2ef 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/data/MappingData.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.data; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; -import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.api.data.MappingDataBase; import com.viaversion.viaversion.api.data.MappingDataLoader; @@ -39,12 +38,12 @@ public class MappingData extends MappingDataBase { dimensionRegistry = MappingDataLoader.loadNBTFromFile("dimension-registry-1.16.2.nbt"); // Data of each dimension - final ListTag dimensions = ((CompoundTag) dimensionRegistry.get("minecraft:dimension_type")).get("value"); + final ListTag dimensions = dimensionRegistry.getCompoundTag("minecraft:dimension_type").get("value"); for (final Tag dimension : dimensions) { final CompoundTag dimensionCompound = (CompoundTag) dimension; // Copy with an empty name - final CompoundTag dimensionData = new CompoundTag(((CompoundTag) dimensionCompound.get("element")).getValue()); - dimensionDataMap.put(((StringTag) dimensionCompound.get("name")).getValue(), dimensionData); + final CompoundTag dimensionData = dimensionCompound.getCompoundTag("element").copy(); + dimensionDataMap.put(dimensionCompound.getStringTag("name").getValue(), dimensionData); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java index 7cf2e7e42..73d39de29 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java @@ -25,11 +25,11 @@ import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16_2; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1; -import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; -import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16; import com.viaversion.viaversion.rewriter.BlockRewriter; import java.util.ArrayList; import java.util.List; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java index 222565f19..736db5ddf 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java @@ -48,7 +48,6 @@ import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.Key; - import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java index f8f4c5020..9b7b40316 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java @@ -17,7 +17,13 @@ */ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets; -import com.github.steveice10.opennbt.tag.builtin.*; +import com.github.steveice10.opennbt.tag.builtin.ByteTag; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.FloatTag; +import com.github.steveice10.opennbt.tag.builtin.IntTag; +import com.github.steveice10.opennbt.tag.builtin.ListTag; +import com.github.steveice10.opennbt.tag.builtin.LongTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.minecraft.WorldIdentifiers; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16; @@ -33,7 +39,6 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPacke import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16; import com.viaversion.viaversion.util.Key; - import java.util.Arrays; import java.util.UUID; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java index ff604e3db..b5781ddd4 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java @@ -20,7 +20,6 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntArrayTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; -import com.github.steveice10.opennbt.tag.builtin.LongTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; @@ -147,22 +146,22 @@ public class InventoryPackets extends ItemRewriter Target UUID targetUuid = UUID.fromString((String) targetUuidTag.getValue()); compoundTag.put("Target", new IntArrayTag(UUIDUtil.toIntArray(targetUuid))); - } else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) { + } else if (id.equals("minecraft:skull") && compoundTag.getCompoundTag("Owner") != null) { CompoundTag ownerTag = compoundTag.remove("Owner"); - StringTag ownerUuidTag = ownerTag.remove("Id"); - if (ownerUuidTag != null) { - UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue()); + Tag ownerUuidTag = ownerTag.remove("Id"); + if (ownerUuidTag instanceof StringTag) { + UUID ownerUuid = UUID.fromString(((StringTag) ownerUuidTag).getValue()); ownerTag.put("Id", new IntArrayTag(UUIDUtil.toIntArray(ownerUuid))); } @@ -129,21 +129,18 @@ public class WorldPackets { compoundTag.put("SkullOwner", skullOwnerTag); } else if (id.equals("minecraft:sign")) { for (int i = 1; i <= 4; i++) { - Tag line = compoundTag.get("Text" + i); - if (line instanceof StringTag) { - JsonElement text = protocol.getComponentRewriter().processText(((StringTag) line).getValue()); - compoundTag.put("Text" + i, new StringTag(text.toString())); + StringTag line = compoundTag.getStringTag("Text" + i); + if (line != null) { + JsonElement text = protocol.getComponentRewriter().processText(line.getValue()); + compoundTag.putString("Text" + i, text.toString()); } } } else if (id.equals("minecraft:mob_spawner")) { - Tag spawnDataTag = compoundTag.get("SpawnData"); - if (spawnDataTag instanceof CompoundTag) { - Tag spawnDataIdTag = ((CompoundTag) spawnDataTag).get("id"); - if (spawnDataIdTag instanceof StringTag) { - StringTag spawnDataIdStringTag = ((StringTag) spawnDataIdTag); - if (spawnDataIdStringTag.getValue().equals("minecraft:zombie_pigman")) { - spawnDataIdStringTag.setValue("minecraft:zombified_piglin"); - } + CompoundTag spawnDataTag = compoundTag.getCompoundTag("SpawnData"); + if (spawnDataTag != null) { + StringTag spawnDataIdTag = spawnDataTag.getStringTag("id"); + if (spawnDataIdTag != null && spawnDataIdTag.getValue().equals("minecraft:zombie_pigman")) { + spawnDataIdTag.setValue("minecraft:zombified_piglin"); } } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java index ed8e42fd7..d192259a1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/InventoryPackets.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; -import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; @@ -135,7 +134,7 @@ public final class InventoryPackets extends ItemRewriter blockEntities = new ArrayList<>(oldChunk.getBlockEntities().size()); for (final CompoundTag tag : oldChunk.getBlockEntities()) { - final NumberTag xTag = tag.get("x"); - final NumberTag yTag = tag.get("y"); - final NumberTag zTag = tag.get("z"); - final StringTag idTag = tag.get("id"); + final NumberTag xTag = tag.getNumberTag("x"); + final NumberTag yTag = tag.getNumberTag("y"); + final NumberTag zTag = tag.getNumberTag("z"); + final StringTag idTag = tag.getStringTag("id"); if (xTag == null || yTag == null || zTag == null || idTag == null) { continue; } @@ -203,8 +202,8 @@ public final class WorldPackets { private static void handleSpawners(int typeId, final CompoundTag tag) { if (typeId == 8) { - final Tag entity = tag.get("SpawnData"); - if (entity instanceof CompoundTag) { + final CompoundTag entity = tag.getCompoundTag("SpawnData"); + if (entity != null) { final CompoundTag spawnData = new CompoundTag(); tag.put("SpawnData", spawnData); spawnData.put("entity", entity); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java index 3719256e1..2156cd61e 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_1to1_19/Protocol1_19_1To1_19.java @@ -222,7 +222,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocolget("element").get("chat"); + CompoundTag chatData = chatType.getCompoundTag("element").getCompoundTag("chat"); boolean overlay = false; if (chatData == null) { - chatData = chatType.get("element").get("overlay"); + chatData = chatType.getCompoundTag("element").getCompoundTag("overlay"); if (chatData == null) { // Either narration or something we don't know return null; @@ -354,7 +354,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol entry : TextFormatting.FORMATTINGS.entrySet()) { - final Tag formattingTag = styleTag.get(entry.getKey()); + final NumberTag formattingTag = styleTag.getNumberTag(entry.getKey()); if (!(formattingTag instanceof ByteTag)) { continue; } - final boolean value = ((NumberTag) formattingTag).asBoolean(); + final boolean value = formattingTag.asBoolean(); final TextFormatting formatting = entry.getValue(); if (formatting == TextFormatting.OBFUSCATED) { style.setObfuscated(value); @@ -405,7 +405,7 @@ public final class Protocol1_19_1To1_19 extends AbstractProtocol arguments = new ArrayList<>(); if (parameters != null) { for (final Tag element : parameters) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/EntityPackets.java index f320cc951..a060102c6 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/packets/EntityPackets.java @@ -29,7 +29,6 @@ import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ClientboundPacke import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.Protocol1_19_3To1_19_1; import com.viaversion.viaversion.rewriter.EntityRewriter; - import java.util.BitSet; import java.util.UUID; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java index a632bad7c..939f3dcf8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java @@ -31,7 +31,6 @@ import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19; -import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; @@ -210,7 +209,7 @@ public final class EntityPackets extends EntityRewriter dimensionDataMap = new HashMap<>(dimensions.size()); final Map dimensionsMap = new HashMap<>(dimensions.size()); for (final Tag dimension : dimensions) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/WorldPackets.java index a2e08c4f4..5218d3bc1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/WorldPackets.java @@ -24,8 +24,8 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; +import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ServerboundPackets1_19; import com.viaversion.viaversion.rewriter.BlockRewriter; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java index 6e8ea65dd..b1285eedb 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/rewriter/BlockItemPacketRewriter1_20_2.java @@ -36,11 +36,11 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.rewriter.RecipeRewriter1_19_4; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.Protocol1_20_2To1_20; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2; -import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.ItemRewriter; @@ -441,14 +441,14 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex.java index 35e0fbee9..0b6743d6f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex.java @@ -17,8 +17,8 @@ */ package com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.util.Pair; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/EntityPackets.java index 7b4de94aa..5c752ff5d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -36,8 +36,11 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRew import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.util.Pair; import com.viaversion.viaversion.util.Triple; - -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; public class EntityPackets { public static final ValueTransformer toNewShort = new ValueTransformer(Type.SHORT) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 42198905f..6eedc83f7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -21,6 +21,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.minecraft.BlockFace; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; @@ -30,10 +31,11 @@ import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.chunk.BulkChunkType1_8; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_8; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1; import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8; -import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; @@ -43,8 +45,6 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.Effect; import com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.SoundEffect; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; -import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_8; -import com.viaversion.viaversion.api.type.types.chunk.BulkChunkType1_8; import java.util.ArrayList; import java.util.Optional; @@ -215,14 +215,15 @@ public class WorldPackets { if (action == 1) { // Update Spawner CompoundTag tag = wrapper.get(Type.NAMED_COMPOUND_TAG, 0); if (tag != null) { - if (tag.contains("EntityId")) { - String entity = (String) tag.get("EntityId").getValue(); + StringTag entityId = tag.getStringTag("EntityId"); + if (entityId != null) { + String entity = entityId.getValue(); CompoundTag spawn = new CompoundTag(); - spawn.put("id", new StringTag(entity)); + spawn.putString("id", entity); tag.put("SpawnData", spawn); } else { // EntityID does not exist CompoundTag spawn = new CompoundTag(); - spawn.put("id", new StringTag("AreaEffectCloud")); //Make spawners show up as empty when no EntityId is given. + spawn.putString("id", "AreaEffectCloud"); //Make spawners show up as empty when no EntityId is given. tag.put("SpawnData", spawn); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/MovementTransmitterProvider.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/MovementTransmitterProvider.java index 999800d0f..b293ef3e0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/MovementTransmitterProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/MovementTransmitterProvider.java @@ -26,7 +26,6 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker; - import java.util.logging.Level; public class MovementTransmitterProvider implements Provider { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/ClientChunks.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/ClientChunks.java index b95e22808..cf98ae9dd 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/ClientChunks.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/ClientChunks.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.storage; import com.google.common.collect.Sets; import com.viaversion.viaversion.api.connection.StorableObject; - import java.util.Set; public class ClientChunks implements StorableObject { diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java index 4b89aea46..808f225e9 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java @@ -267,24 +267,24 @@ public class ComponentRewriter { } protected void processCompoundTag(final CompoundTag tag) { - final Tag translate = tag.get("translate"); - if (translate instanceof StringTag) { - handleTranslate(tag, ((StringTag) translate)); + final StringTag translate = tag.getStringTag("translate"); + if (translate != null) { + handleTranslate(tag, translate); - final Tag with = tag.get("with"); - if (with instanceof ListTag) { - processListTag((ListTag) with); + final ListTag with = tag.getListTag("with"); + if (with != null) { + processListTag(with); } } - final Tag extra = tag.get("extra"); - if (extra instanceof ListTag) { - processListTag((ListTag) extra); + final ListTag extra = tag.getListTag("extra"); + if (extra != null) { + processListTag(extra); } - final Tag hoverEvent = tag.get("hoverEvent"); - if (hoverEvent instanceof CompoundTag) { - handleHoverEvent((CompoundTag) hoverEvent); + final CompoundTag hoverEvent = tag.getCompoundTag("hoverEvent"); + if (hoverEvent != null) { + handleHoverEvent(hoverEvent); } } @@ -294,19 +294,19 @@ public class ComponentRewriter { protected void handleHoverEvent(final CompoundTag hoverEventTag) { // To override if needed (don't forget to call super) - final Tag actionTag = hoverEventTag.get("action"); - if (!(actionTag instanceof StringTag)) { + final StringTag actionTag = hoverEventTag.getStringTag("action"); + if (actionTag == null) { return; } - final String action = ((StringTag) actionTag).getValue(); + final String action = actionTag.getValue(); if (action.equals("show_text")) { final Tag value = hoverEventTag.get("value"); processTag(value != null ? value : hoverEventTag.get("contents")); } else if (action.equals("show_entity")) { - final Tag contents = hoverEventTag.get("contents"); - if (contents instanceof CompoundTag) { - processTag(((CompoundTag) contents).get("name")); + final CompoundTag contents = hoverEventTag.getCompoundTag("contents"); + if (contents != null) { + processTag(contents.get("name")); } } } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index a21b44147..2c7cd3fed 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -18,10 +18,9 @@ package com.viaversion.viaversion.rewriter; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; +import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.github.steveice10.opennbt.tag.builtin.Tag; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; @@ -393,17 +392,17 @@ public abstract class EntityRewriter> 4); } else { Via.getPlatform().getLogger().warning("Height missing in dimension data: " + registryData); } - Tag minY = registryData.get("min_y"); - if (minY instanceof IntTag) { - tracker.setCurrentMinY(((IntTag) minY).asInt()); + NumberTag minY = registryData.getNumberTag("min_y"); + if (minY != null) { + tracker.setCurrentMinY(minY.asInt()); } else { Via.getPlatform().getLogger().warning("Min Y missing in dimension data: " + registryData); } @@ -466,12 +465,12 @@ public abstract class EntityRewriter dimensionDataMap = new HashMap<>(dimensions.size()); for (final Tag dimension : dimensions) { final CompoundTag dimensionCompound = (CompoundTag) dimension; final CompoundTag element = dimensionCompound.get("element"); - final String name = (String) dimensionCompound.get("name").getValue(); + final String name = dimensionCompound.getStringTag("name").getValue(); dimensionDataMap.put(name, new DimensionDataImpl(element)); } tracker(connection).setDimensions(dimensionDataMap); diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/meta/MetaHandlerEvent.java b/common/src/main/java/com/viaversion/viaversion/rewriter/meta/MetaHandlerEvent.java index 3828a6880..c42512b6c 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/meta/MetaHandlerEvent.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/meta/MetaHandlerEvent.java @@ -21,9 +21,8 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.data.entity.TrackedEntity; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import org.checkerframework.checker.nullness.qual.Nullable; - import java.util.List; +import org.checkerframework.checker.nullness.qual.Nullable; public interface MetaHandlerEvent { diff --git a/common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java b/common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java index b2092a570..db7eed9b5 100644 --- a/common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java @@ -21,7 +21,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.util.GsonUtil; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -29,7 +28,6 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.Locale; import java.util.UUID; - import org.checkerframework.checker.nullness.qual.Nullable; public final class UpdateUtil { diff --git a/common/src/test/java/com/viaversion/viaversion/common/entities/EntityTypesTest.java b/common/src/test/java/com/viaversion/viaversion/common/entities/EntityTypesTest.java index 2d5183dc7..8f7f3e11f 100644 --- a/common/src/test/java/com/viaversion/viaversion/common/entities/EntityTypesTest.java +++ b/common/src/test/java/com/viaversion/viaversion/common/entities/EntityTypesTest.java @@ -17,12 +17,12 @@ */ package com.viaversion.viaversion.common.entities; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_17; -import com.viaversion.viaversion.api.minecraft.entities.EntityType; import java.util.function.Function; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1fe077964..d9eb3ce36 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ metadata.format.version = "1.1" gson = "2.10.1" fastutil = "8.5.12" flare = "2.0.1" -vianbt = "4.0.1" +vianbt = "4.2.0" mcstructs = "2.4.2-SNAPSHOT" # Common provided From c7265abfe941988df3e8684526dc6eead6592dcf Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 10 Feb 2024 23:44:13 +0100 Subject: [PATCH 2/3] Add editorconfig --- .editorconfig | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..7730dd6b1 --- /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 cfc048ba5355fe8f441ce36df446bfb148136460 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 10 Feb 2024 17:58:54 +0100 Subject: [PATCH 3/3] Small random cleanup --- .../bukkit/util/CollisionChecker.java | 2 +- .../BukkitInventoryQuickMoveProvider.java | 6 +----- .../viaversion/legacy/bossbar/CommonBoss.java | 3 ++- .../protocol1_11to1_10/BlockEntityRewriter.java | 8 ++++---- .../AbstractFenceConnectionHandler.java | 2 +- .../AbstractStempConnectionHandler.java | 2 +- .../ChorusPlantConnectionHandler.java | 2 +- .../RedstoneConnectionHandler.java | 3 +-- .../data/ParticleRewriter.java | 7 ++++--- .../protocol1_13to1_12_2/data/RecipeData.java | 12 ++++-------- .../storage/InventoryTracker1_16.java | 2 +- .../Protocol1_19To1_18_2.java | 6 ++---- .../protocol1_9to1_8/Protocol1_9To1_8.java | 17 ++++++++++------- .../metadata/MetadataRewriter1_9To1_8.java | 2 +- .../protocol1_9to1_8/packets/PlayerPackets.java | 2 -- .../viaversion/rewriter/ItemRewriter.java | 2 +- .../com/viaversion/viaversion/SpongePlugin.java | 1 - .../handlers/SpongeChannelInitializer.java | 2 +- 18 files changed, 36 insertions(+), 45 deletions(-) diff --git a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/CollisionChecker.java b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/CollisionChecker.java index 5220aa2d1..9ce05d468 100644 --- a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/CollisionChecker.java +++ b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/util/CollisionChecker.java @@ -106,7 +106,7 @@ public class CollisionChecker { } private static class DummyList extends AbstractList { - private boolean any = false; + private boolean any; @Override public T get(int index) { diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java index f4ad544a5..11d432118 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java @@ -199,10 +199,6 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider private boolean isSupported() { int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion(); - if (protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion()) { - return true; // 1.8-1.11.2 - } - // this is not needed on 1.12+ servers - return false; + return protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion(); // 1.8-1.11.2, not needed with 1.12 } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java b/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java index 2f69eb4dd..a3ac22416 100644 --- a/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java +++ b/common/src/main/java/com/viaversion/viaversion/legacy/bossbar/CommonBoss.java @@ -31,6 +31,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_ import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumSet; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -56,7 +57,7 @@ public class CommonBoss implements BossBar { this.color = color == null ? BossColor.PURPLE : color; this.style = style == null ? BossStyle.SOLID : style; this.connections = new MapMaker().weakValues().makeMap(); - this.flags = new HashSet<>(); + this.flags = EnumSet.noneOf(BossFlag.class); this.visible = true; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/BlockEntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/BlockEntityRewriter.java index 06fa8f843..336929692 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/BlockEntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/BlockEntityRewriter.java @@ -22,7 +22,7 @@ import com.google.common.collect.HashBiMap; import com.viaversion.viaversion.util.Key; public class BlockEntityRewriter { - private static BiMap oldToNewNames = HashBiMap.create(); + private static final BiMap OLD_TO_NEW_NAMES = HashBiMap.create(); // Source: https://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2724507-1-11-nbt-changes-and-additions#AllTiles static { @@ -52,15 +52,15 @@ public class BlockEntityRewriter { } private static void rewrite(String oldName, String newName) { - oldToNewNames.put(oldName, Key.namespaced(newName)); + OLD_TO_NEW_NAMES.put(oldName, Key.namespaced(newName)); } public static BiMap inverse() { - return oldToNewNames.inverse(); + return OLD_TO_NEW_NAMES.inverse(); } public static String toNewIdentifier(String oldId) { - String newName = oldToNewNames.get(oldId); + String newName = OLD_TO_NEW_NAMES.get(oldId); if (newName != null) { return newName; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java index c50595e0b..f6a411cf8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java @@ -36,7 +36,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler { Arrays.fill(connectedBlockStates, -1); } - public ConnectionData.ConnectorInitAction getInitAction(final String key) { + ConnectionData.ConnectorInitAction getInitAction(final String key) { final AbstractFenceConnectionHandler handler = this; return blockData -> { if (key.equals(blockData.getMinecraftKey())) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java index 75d883958..22717e18b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java @@ -38,7 +38,7 @@ public abstract class AbstractStempConnectionHandler extends ConnectionHandler { this.baseStateId = ConnectionData.getId(baseStateId); } - public ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) { + ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) { final AbstractStempConnectionHandler handler = this; return blockData -> { if (blockData.getSavedBlockStateId() == baseStateId || blockId.equals(blockData.getMinecraftKey())) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java index f2413ff4f..af5dd0161 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java @@ -39,7 +39,7 @@ public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler endstone = ConnectionData.getId("minecraft:end_stone"); } - public ConnectionData.ConnectorInitAction getExtraAction() { + private ConnectionData.ConnectorInitAction getExtraAction() { return blockData -> { if (blockData.getMinecraftKey().equals("minecraft:chorus_flower")) { getBlockStates().add(blockData.getSavedBlockStateId()); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java index 3a9d1f369..592b6c6c7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java @@ -59,13 +59,12 @@ public class RedstoneConnectionHandler extends ConnectionHandler { private static int getState(String value) { switch (value) { case "none": + default: return 0; case "side": return 1; case "up": return 2; - default: - return 0; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java index c8c176cc0..21c6a37ec 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java @@ -99,7 +99,7 @@ public class ParticleRewriter { } NewParticle rewrite = particles.get(particleId); - return rewrite.handle(new Particle(rewrite.getId()), data); + return rewrite.handle(new Particle(rewrite.id()), data); } private static void add(int newId) { @@ -157,6 +157,7 @@ public class ParticleRewriter { }; } + @FunctionalInterface interface ParticleDataHandler { Particle handler(Particle particle, Integer[] data); } @@ -176,11 +177,11 @@ public class ParticleRewriter { return particle; } - public int getId() { + public int id() { return id; } - public ParticleDataHandler getHandler() { + public ParticleDataHandler handler() { return handler; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/RecipeData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/RecipeData.java index 981e115e1..3b5e0d048 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/RecipeData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/RecipeData.java @@ -31,20 +31,16 @@ public class RecipeData { public static void init() { InputStream stream = MappingData.class.getClassLoader() .getResourceAsStream("assets/viaversion/data/itemrecipes1_12_2to1_13.json"); - InputStreamReader reader = new InputStreamReader(stream); - try { + try (InputStreamReader reader = new InputStreamReader(stream)) { recipes = GsonUtil.getGson().fromJson( reader, new TypeToken>() { }.getType() ); - } finally { - try { - reader.close(); - } catch (IOException ignored) { - // Ignored - } + } catch (IOException e) { + throw new RuntimeException(e); } + // Ignored } public static class Recipe { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java index 287bd3b05..7a6a7e7cd 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java @@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage; import com.viaversion.viaversion.api.connection.StorableObject; public class InventoryTracker1_16 implements StorableObject { - private boolean inventoryOpen = false; + private boolean inventoryOpen; public boolean isInventoryOpen() { return inventoryOpen; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java index 9762ac282..b50b492f1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java @@ -61,7 +61,7 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol(this).register(ClientboundPackets1_18.STATISTICS); - final PacketHandler singleNullTextComponentMapper = wrapper -> { - wrapper.write(Type.COMPONENT, mapTextComponentIfNull(wrapper.read(Type.COMPONENT))); - }; + final PacketHandler singleNullTextComponentMapper = wrapper -> wrapper.write(Type.COMPONENT, mapTextComponentIfNull(wrapper.read(Type.COMPONENT))); registerClientbound(ClientboundPackets1_18.TITLE_TEXT, singleNullTextComponentMapper); registerClientbound(ClientboundPackets1_18.TITLE_SUBTITLE, singleNullTextComponentMapper); registerClientbound(ClientboundPackets1_18.ACTIONBAR, singleNullTextComponentMapper); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java index bae5c01fe..c40b0e824 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java @@ -98,13 +98,16 @@ public class Protocol1_9To1_8 extends AbstractProtocol { @ConfigDir(sharedRoot = false) private Path configDir; - @SuppressWarnings("SpongeInjection") @Inject SpongePlugin(final PluginContainer container, final Game game, final org.apache.logging.log4j.Logger logger) { this.container = container; diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeChannelInitializer.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeChannelInitializer.java index a25ec6ed1..29d456ba8 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeChannelInitializer.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeChannelInitializer.java @@ -52,7 +52,7 @@ public class SpongeChannelInitializer extends ChannelInitializer implem // Ensure ViaVersion is loaded if (Via.getAPI().getServerVersion().isKnown() && channel instanceof SocketChannel) { // channel can be LocalChannel on internal server - UserConnection info = new UserConnectionImpl((SocketChannel) channel); + UserConnection info = new UserConnectionImpl(channel); // init protocol new ProtocolPipelineImpl(info); // Add originals