From 136678b0b72f4a435b3071626643e6cbfb788a4d Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Wed, 24 Jul 2024 14:33:16 +0200 Subject: [PATCH] Use enhanced switch in more places, fix typo (#831) --- .../BukkitAdvancementCriteriaProvider.java | 4 +- .../rewriter/EntityPacketRewriter1_14.java | 46 ++++++++++--------- .../BlockItemPacketRewriter1_19_3.java | 38 ++++----------- .../Protocol1_19_4To1_19_3.java | 17 ++----- .../provider/AdvancementCriteriaProvider.java | 2 +- 5 files changed, 42 insertions(+), 65 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viabackwards/provider/BukkitAdvancementCriteriaProvider.java b/bukkit/src/main/java/com/viaversion/viabackwards/provider/BukkitAdvancementCriteriaProvider.java index ed4c05d6..d7a9090d 100644 --- a/bukkit/src/main/java/com/viaversion/viabackwards/provider/BukkitAdvancementCriteriaProvider.java +++ b/bukkit/src/main/java/com/viaversion/viabackwards/provider/BukkitAdvancementCriteriaProvider.java @@ -27,8 +27,8 @@ public final class BukkitAdvancementCriteriaProvider extends AdvancementCriteria private static final String[] EMPTY_CRITERIA = new String[0]; @Override - public String[] getCriteria(final String key) { - final Advancement advancement = Bukkit.getAdvancement(NamespacedKey.fromString(key)); + public String[] getCriteria(final String advancementKey) { + final Advancement advancement = Bukkit.getAdvancement(NamespacedKey.fromString(advancementKey)); return advancement == null ? EMPTY_CRITERIA : advancement.getCriteria().toArray(EMPTY_CRITERIA); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java index 4ca7f9f7..2cb6d610 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java @@ -444,28 +444,30 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter // Weaponsmith - 3; // Blacksmith - // Butcher - case 2, 8 -> // Leatherworker - 4; // Butcher - // Cartographer - case 3, 9 -> // Librarian - 1; // Librarian - case 4 -> // Cleric - 2; // Priest - // Farmer - // Fisherman - // Fletcher - case 5, 6, 7, 12 -> // Shepherd - 0; // Farmer - // None - // Nitwit - default -> 5; // Nitwit - }; + switch (data.profession()) { + case 1: // Armorer + case 10: // Mason + case 13: // Toolsmith + case 14: // Weaponsmith + return 3; // Blacksmith + case 2: // Butcher + case 8: // Leatherworker + return 4; // Butcher + case 3: // Cartographer + case 9: // Librarian + return 1; // Librarian + case 4: // Cleric + return 2; // Priest + case 5: // Farmer + case 6: // Fisherman + case 7: // Fletcher + case 12: // Shepherd + return 0; // Farmer + case 0: // None + case 11: // Nitwit + default: + return 5; // Nitwit + } } @Override diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/BlockItemPacketRewriter1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/BlockItemPacketRewriter1_19_3.java index 0fe9abb3..c42800b7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/BlockItemPacketRewriter1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_3to1_19_1/rewriter/BlockItemPacketRewriter1_19_3.java @@ -21,7 +21,6 @@ import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter; import com.viaversion.viabackwards.protocol.v1_19_3to1_19_1.Protocol1_19_3To1_19_1; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ClientboundPackets1_19_3; @@ -73,7 +72,7 @@ public final class BlockItemPacketRewriter1_19_3 extends BackwardsItemRewriter { wrapper.passthrough(Types.STRING); // Group wrapper.read(Types.VAR_INT); // Crafting book category final int ingredients = wrapper.passthrough(Types.VAR_INT); @@ -84,9 +83,8 @@ public final class BlockItemPacketRewriter1_19_3 extends BackwardsItemRewriter { final int ingredients = wrapper.passthrough(Types.VAR_INT) * wrapper.passthrough(Types.VAR_INT); wrapper.passthrough(Types.STRING); // Group wrapper.read(Types.VAR_INT); // Crafting book category @@ -97,12 +95,8 @@ public final class BlockItemPacketRewriter1_19_3 extends BackwardsItemRewriter { wrapper.passthrough(Types.STRING); // Group wrapper.read(Types.VAR_INT); // Crafting book category final Item[] items = wrapper.passthrough(Types.ITEM1_13_2_ARRAY); // Ingredients @@ -112,25 +106,13 @@ public final class BlockItemPacketRewriter1_19_3 extends BackwardsItemRewriter wrapper.read(Types.VAR_INT); // Crafting book category + default -> recipeRewriter.handleRecipeType(wrapper, type); } } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/Protocol1_19_4To1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/Protocol1_19_4To1_19_3.java index b7f73bc5..2c0c4de3 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/Protocol1_19_4To1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/Protocol1_19_4To1_19_3.java @@ -78,21 +78,14 @@ public final class Protocol1_19_4To1_19_3 extends BackwardsProtocol wrapper.write(Types.VAR_INT, 0); + case "minecraft:time" -> wrapper.read(Types.INT); // Minimum + case "minecraft:resource", "minecraft:resource_or_tag" -> { final String resource = wrapper.read(Types.STRING); // Replace damage types with... something wrapper.write(Types.STRING, resource.equals("minecraft:damage_type") ? "minecraft:mob_effect" : resource); - break; - default: - super.handleArgument(wrapper, argumentType); - break; + } + default -> super.handleArgument(wrapper, argumentType); } } }.registerDeclareCommands1_19(ClientboundPackets1_19_4.COMMANDS); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/provider/AdvancementCriteriaProvider.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/provider/AdvancementCriteriaProvider.java index 4a5274e3..eea475f6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/provider/AdvancementCriteriaProvider.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/provider/AdvancementCriteriaProvider.java @@ -21,7 +21,7 @@ import com.viaversion.viaversion.api.platform.providers.Provider; public class AdvancementCriteriaProvider implements Provider { - public String[] getCriteria(final String advacementKey) { + public String[] getCriteria(final String advancementKey) { return new String[0]; } }