diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java index fe3c4fbcb..07ca7374c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/BlockItemPacketRewriter1_21_2.java @@ -207,12 +207,12 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter< rewriter.setCurrentRecipeIdentifier(recipeIdentifier); rewriter.handleRecipeType(wrapper, serializerTypeIdentifier); } + rewriter.finalizeRecipes(); // These are used for client predictions, such as what items can be used as fuel in a furnace protocol.getMappingData().writeInputs(wrapper); - // TODO Stonecutter ingredients - wrapper.write(Types.VAR_INT, 0); + rewriter.writeStoneCutterRecipes(wrapper); }); protocol.registerClientbound(ClientboundPackets1_21.RECIPE, ClientboundPackets1_21_2.RECIPE_BOOK_ADD, wrapper -> { @@ -332,18 +332,6 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter< return item; } - private int recipeDisplay(String type) { - type = Key.stripMinecraftNamespace(type); - return switch (type) { - case "crafting_shapeless" -> 0; - case "crafting_shaped" -> 1; - case "furnace" -> 2; - case "stonecutter" -> 3; - case "smithing" -> 4; - default -> 0; - }; - } - private void updateContainerId(final PacketWrapper wrapper) { // Container id handling was always a bit whack with most reading them as unsigned bytes, some as bytes, some already as var ints. // In VV they're generally read as unsigned bytesto not have to look the type up every time, but we need to make sure they're diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/RecipeRewriter1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/RecipeRewriter1_21_2.java index f9561f0a2..f62bab323 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/RecipeRewriter1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/rewriter/RecipeRewriter1_21_2.java @@ -18,10 +18,8 @@ package com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter; import com.viaversion.viaversion.api.connection.StorableObject; -import com.viaversion.viaversion.api.data.MappingData; import com.viaversion.viaversion.api.minecraft.HolderSet; import com.viaversion.viaversion.api.minecraft.item.Item; -import com.viaversion.viaversion.api.minecraft.item.StructuredItem; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Types; @@ -29,12 +27,10 @@ import com.viaversion.viaversion.api.type.types.version.Types1_21_2; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; import com.viaversion.viaversion.util.Key; -import it.unimi.dsi.fastutil.ints.IntArrayList; -import it.unimi.dsi.fastutil.ints.IntCollection; -import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,12 +39,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; // Use directly as a connection storage. Slightly weird, but easiest and closed off from other packages final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3 implements StorableObject { - private static final int FALLBACK_CATEGORY = 3; // TODO ? - private final List shapelessRecipes = new ArrayList<>(); - private final List shapedRecipes = new ArrayList<>(); - private final List smithingRecipes = new ArrayList<>(); private final List stoneCutterRecipes = new ArrayList<>(); - private final List furnaceRecipes = new ArrayList<>(); private final Object2IntMap recipeGroups = new Object2IntOpenHashMap<>(); private final Map recipesByKey = new HashMap<>(); private final List recipes = new ArrayList<>(); @@ -75,35 +66,21 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3 void addRecipe(final List list, final T recipe) { - list.add(recipe); + private void addRecipe(final Recipe recipe) { recipes.add(recipe); recipesByKey.put(currentRecipeIdentifier, recipe); } @Override public void handleSmithingTransform(final PacketWrapper wrapper) { - final IntList template = new IntArrayList(); - readIngredientToList(wrapper, template); - //smithingTemplate.addAll(template); - readIngredient(wrapper); - readIngredient(wrapper); - //readIngredientToList(wrapper, smithingBase); - //readIngredientToList(wrapper, smithingAddition); - final Item result = rewrite(wrapper.user(), wrapper.read(itemType())); - - // TODO Correct ingredients? - final Item[] ingredients = new Item[template.size()]; - for (int i = 0; i < template.size(); i++) { - ingredients[i] = new StructuredItem(template.getInt(i), 1); - } - - final SmithingRecipe recipe = new SmithingRecipe(recipesByKey.size(), currentRecipeIdentifier, ingredients, result); - addRecipe(smithingRecipes, recipe); + readIngredient(wrapper); // Template + readIngredient(wrapper); // Base + readIngredient(wrapper); // Addition + wrapper.read(itemType()); // Result } @Override @@ -111,9 +88,6 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3= 0 && displayId < recipes.size() ? recipes.get(displayId) : null; } + public void writeStoneCutterRecipes(final PacketWrapper wrapper) { + wrapper.write(Types.VAR_INT, stoneCutterRecipes.size()); + for (final StoneCutterRecipe recipe : stoneCutterRecipes) { + final HolderSet ingredient = toHolderSet(recipe.ingredient()); + wrapper.write(Types.HOLDER_SET, ingredient); + writeItemDisplay(wrapper, recipe.result()); + } + } + + public void finalizeRecipes() { + // Need to be sorted alphabetically + stoneCutterRecipes.sort(Comparator.comparing(recipe -> recipe.identifier)); + } + interface Recipe { int SLOT_DISPLAY_EMPTY = 0; int SLOT_DISPLAY_ANY_FUEL = 1; @@ -239,9 +218,7 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3