Skip to content
TheChatArchiveThe Chat Archive
Mistralmistral-medium· Mistral AIHugging Face Arena Human Preference 55K

How do I add a minecraft crafting recipe with nbt data in fabric mod?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with DeepSeekdeepseek-llm-67b-chat’s answer.
  1. User

    How do I add a minecraft crafting recipe with nbt data in fabric mod?

  2. Mistral Assistant

    Adding a crafting recipe with NBT data in a Fabric mod involves several steps. Here's a general outline of the process:

    1. Create a new class for your crafting recipe that extends the SimpleCraftingRecipe class or one of its subclasses. This class should define the inputs and outputs of the recipe, as well as any NBT data that should be applied to the output.
    2. Define the inputs and outputs of the recipe using Ingredient and ItemStack objects, respectively. For example, you might create an Ingredient that matches any wooden planks and an ItemStack that represents a stick with a specific NBT tag.
    3. Apply the NBT data to the output ItemStack using the NBTCompound class. This class allows you to create and modify NBT data, which can then be added to an ItemStack using the setTag method.
    4. Register the recipe with the game using the CraftingRecipeRegistry class. This class provides several methods for registering different types of recipes, including shaped and shapeless recipes. You can use the register method to register your recipe, passing in a unique identifier and an instance of your recipe class.

    Here's some example code to get you started:

    import net.minecraft.item.ItemStack;
    import net.minecraft.item.Items;
    import net.minecraft.nbt.NBTCompound;
    import net.minecraft.nbt.NBTUtil;
    import net.minecraft.network.PacketByteBuf;
    import net.minecraft.recipe.Ingredient;
    import net.minecraft.recipe.RecipeSerializer;
    import net.minecraft.recipe.RecipeType;
    import net.minecraft.util.Identifier;
    import net.minecraft.util.collection.DefaultedList;
    import net.minecraft.util.registry.Registry;
    import net.minecraft.world.World;
    import net.minecraftforge.common.util.INBTSerializable;
    import net.minecraftforge.registries.RegistryObject;
    
    public class NBTCraftingRecipe extends SimpleCraftingRecipe {
      private final Ingredient input;
      private final ItemStack output;
    
      public NBTCraftingRecipe(Identifier id, Ingredient input, ItemStack output) {
        super(id, DefaultedList.ofSize(9, Ingredient.EMPTY), output);
        this.input = input;
        this.output = output;
      }
    
      @Override
      public boolean matches(CraftingInventory inv, World world) {
        return input.test(inv.getStack(0));
      }
    
      @Override
      public ItemStack craft(CraftingInventory inv) {
        ItemStack stack = output.copy();
        stack.setCount(1);
        if (stack.hasNbt()) {
          NBTCompound nbt = stack.getNbt();
          NBTUtil.merge(nbt, input.getMatchingStacks()[0].getNbt());
        } else {
          stack.setNbt(input.getMatchingStacks()[0].getNbt().copy());
        }
        return stack;
      }
    
      @Override
      public boolean fits(int width, int height) {
        return width * height >= 1;
      }
    
      @Override
      public RecipeSerializer<?> getSerializer() {
        return ModRecipeSerializers.NBT_CRAFTING_RECIPE;
      }
    
      public static class Serializer implements RecipeSerializer<NBTCraftingRecipe> {
        @Override
        public NBTCraftingRecipe read(Identifier id, PacketByteBuf buf) {
          Ingredient input = Ingredient.fromPacket(buf);
          ItemStack output = buf.readItemStack();
          NBTCompound nbt = buf.readNbt();
          if (nbt != null) {
            output.setNbt(nbt);
          }
          return new NBTCraftingRecipe(id, input, output);
        }
    
        @Override
        public NBTCraftingRecipe read(Identifier id, JsonObject json) {
          Ingredient input = Ingredient.
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.