3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-27 00:22:53 +01:00

Use enhanced switch in more places, fix typo (#831)

Dieser Commit ist enthalten in:
EnZaXD 2024-07-24 14:33:16 +02:00 committet von GitHub
Ursprung 99618af747
Commit 136678b0b7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
5 geänderte Dateien mit 42 neuen und 65 gelöschten Zeilen

Datei anzeigen

@ -27,8 +27,8 @@ public final class BukkitAdvancementCriteriaProvider extends AdvancementCriteria
private static final String[] EMPTY_CRITERIA = new String[0]; private static final String[] EMPTY_CRITERIA = new String[0];
@Override @Override
public String[] getCriteria(final String key) { public String[] getCriteria(final String advancementKey) {
final Advancement advancement = Bukkit.getAdvancement(NamespacedKey.fromString(key)); final Advancement advancement = Bukkit.getAdvancement(NamespacedKey.fromString(advancementKey));
return advancement == null ? EMPTY_CRITERIA : advancement.getCriteria().toArray(EMPTY_CRITERIA); return advancement == null ? EMPTY_CRITERIA : advancement.getCriteria().toArray(EMPTY_CRITERIA);
} }
} }

Datei anzeigen

@ -444,28 +444,30 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
} }
public int villagerDataToProfession(VillagerData data) { public int villagerDataToProfession(VillagerData data) {
return switch (data.profession()) { // Armorer switch (data.profession()) {
// Mason case 1: // Armorer
// Toolsmith case 10: // Mason
case 1, 10, 13, 14 -> // Weaponsmith case 13: // Toolsmith
3; // Blacksmith case 14: // Weaponsmith
// Butcher return 3; // Blacksmith
case 2, 8 -> // Leatherworker case 2: // Butcher
4; // Butcher case 8: // Leatherworker
// Cartographer return 4; // Butcher
case 3, 9 -> // Librarian case 3: // Cartographer
1; // Librarian case 9: // Librarian
case 4 -> // Cleric return 1; // Librarian
2; // Priest case 4: // Cleric
// Farmer return 2; // Priest
// Fisherman case 5: // Farmer
// Fletcher case 6: // Fisherman
case 5, 6, 7, 12 -> // Shepherd case 7: // Fletcher
0; // Farmer case 12: // Shepherd
// None return 0; // Farmer
// Nitwit case 0: // None
default -> 5; // Nitwit case 11: // Nitwit
}; default:
return 5; // Nitwit
}
} }
@Override @Override

Datei anzeigen

@ -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.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.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; 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;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ClientboundPackets1_19_3; 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<C
final String type = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); final String type = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
wrapper.passthrough(Types.STRING); // Recipe Identifier wrapper.passthrough(Types.STRING); // Recipe Identifier
switch (type) { switch (type) {
case "crafting_shapeless": { case "crafting_shapeless" -> {
wrapper.passthrough(Types.STRING); // Group wrapper.passthrough(Types.STRING); // Group
wrapper.read(Types.VAR_INT); // Crafting book category wrapper.read(Types.VAR_INT); // Crafting book category
final int ingredients = wrapper.passthrough(Types.VAR_INT); final int ingredients = wrapper.passthrough(Types.VAR_INT);
@ -84,9 +83,8 @@ public final class BlockItemPacketRewriter1_19_3 extends BackwardsItemRewriter<C
} }
} }
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result
break;
} }
case "crafting_shaped": { case "crafting_shaped" -> {
final int ingredients = wrapper.passthrough(Types.VAR_INT) * wrapper.passthrough(Types.VAR_INT); final int ingredients = wrapper.passthrough(Types.VAR_INT) * wrapper.passthrough(Types.VAR_INT);
wrapper.passthrough(Types.STRING); // Group wrapper.passthrough(Types.STRING); // Group
wrapper.read(Types.VAR_INT); // Crafting book category wrapper.read(Types.VAR_INT); // Crafting book category
@ -97,12 +95,8 @@ public final class BlockItemPacketRewriter1_19_3 extends BackwardsItemRewriter<C
} }
} }
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result
break;
} }
case "smelting": case "smelting", "campfire_cooking", "blasting", "smoking" -> {
case "campfire_cooking":
case "blasting":
case "smoking":
wrapper.passthrough(Types.STRING); // Group wrapper.passthrough(Types.STRING); // Group
wrapper.read(Types.VAR_INT); // Crafting book category wrapper.read(Types.VAR_INT); // Crafting book category
final Item[] items = wrapper.passthrough(Types.ITEM1_13_2_ARRAY); // Ingredients final Item[] items = wrapper.passthrough(Types.ITEM1_13_2_ARRAY); // Ingredients
@ -112,25 +106,13 @@ public final class BlockItemPacketRewriter1_19_3 extends BackwardsItemRewriter<C
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)); // Result
wrapper.passthrough(Types.FLOAT); // EXP wrapper.passthrough(Types.FLOAT); // EXP
wrapper.passthrough(Types.VAR_INT); // Cooking time wrapper.passthrough(Types.VAR_INT); // Cooking time
break; }
case "crafting_special_armordye": case "crafting_special_armordye", "crafting_special_bookcloning", "crafting_special_mapcloning",
case "crafting_special_bookcloning": "crafting_special_mapextending", "crafting_special_firework_rocket", "crafting_special_firework_star",
case "crafting_special_mapcloning": "crafting_special_firework_star_fade", "crafting_special_tippedarrow", "crafting_special_bannerduplicate",
case "crafting_special_mapextending": "crafting_special_shielddecoration", "crafting_special_shulkerboxcoloring", "crafting_special_suspiciousstew",
case "crafting_special_firework_rocket": "crafting_special_repairitem" -> wrapper.read(Types.VAR_INT); // Crafting book category
case "crafting_special_firework_star": default -> recipeRewriter.handleRecipeType(wrapper, type);
case "crafting_special_firework_star_fade":
case "crafting_special_tippedarrow":
case "crafting_special_bannerduplicate":
case "crafting_special_shielddecoration":
case "crafting_special_shulkerboxcoloring":
case "crafting_special_suspiciousstew":
case "crafting_special_repairitem":
wrapper.read(Types.VAR_INT); // Crafting book category
break;
default:
recipeRewriter.handleRecipeType(wrapper, type);
break;
} }
} }
}); });

Datei anzeigen

@ -78,21 +78,14 @@ public final class Protocol1_19_4To1_19_3 extends BackwardsProtocol<ClientboundP
@Override @Override
public void handleArgument(final PacketWrapper wrapper, final String argumentType) { public void handleArgument(final PacketWrapper wrapper, final String argumentType) {
switch (argumentType) { switch (argumentType) {
case "minecraft:heightmap": case "minecraft:heightmap" -> wrapper.write(Types.VAR_INT, 0);
wrapper.write(Types.VAR_INT, 0); case "minecraft:time" -> wrapper.read(Types.INT); // Minimum
break; case "minecraft:resource", "minecraft:resource_or_tag" -> {
case "minecraft:time":
wrapper.read(Types.INT); // Minimum
break;
case "minecraft:resource":
case "minecraft:resource_or_tag":
final String resource = wrapper.read(Types.STRING); final String resource = wrapper.read(Types.STRING);
// Replace damage types with... something // Replace damage types with... something
wrapper.write(Types.STRING, resource.equals("minecraft:damage_type") ? "minecraft:mob_effect" : resource); wrapper.write(Types.STRING, resource.equals("minecraft:damage_type") ? "minecraft:mob_effect" : resource);
break; }
default: default -> super.handleArgument(wrapper, argumentType);
super.handleArgument(wrapper, argumentType);
break;
} }
} }
}.registerDeclareCommands1_19(ClientboundPackets1_19_4.COMMANDS); }.registerDeclareCommands1_19(ClientboundPackets1_19_4.COMMANDS);

Datei anzeigen

@ -21,7 +21,7 @@ import com.viaversion.viaversion.api.platform.providers.Provider;
public class AdvancementCriteriaProvider implements Provider { public class AdvancementCriteriaProvider implements Provider {
public String[] getCriteria(final String advacementKey) { public String[] getCriteria(final String advancementKey) {
return new String[0]; return new String[0];
} }
} }