Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7950

RecipeBook click ignores ExactChoice

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • PlaceholderAPI, Multiverse-Core, ProtocolLib, Essentials, PlugManX (PlugMan).

    • CraftBukkit version 4376-Spigot-e65d67a-2702c5c (MC: 1.21.3) (Implementing API version 1.21.3-R0.1-SNAPSHOT)
    • Custom plugin
    • Yes

      For some reason this internal NMS code (I think it's this one) does match the wrong ingredients, ignoring "exact choice" recipe ingredients and puts the vanilla item instead (in case it's available in the player inventory).

      // ServerGamePacketListenerImpl#handlePlaceRecipe(...)ServerPlayer serverPlayer = ((CraftPlayer) e.getPlayer()).getHandle();
      AbstractContainerMenu containerMenu = serverPlayer.containerMenu;
      if (containerMenu instanceof RecipeBookMenu bookMenu)
      {
          ServerLevel serverLevel = ((CraftWorld) e.getPlayer().getWorld()).getHandle();
          Scheduler.sync(() -> {
              RecipeBookMenu.PostPlaceAction postPlaceAction = bookMenu.handlePlacement(handle.useMaxItems(), false, recipeHolder, serverLevel, serverPlayer.getInventory());
              if (postPlaceAction == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE)
              {
                  serverPlayer.connection.send(new ClientboundPlaceGhostRecipePacket(serverPlayer.containerMenu.containerId, recipeFromDisplay.display().display()));
              }
          });
      } 

      This is a simple code I used to make these videos.

      Player player = Bukkit.getPlayer("LoneDev");
      org.bukkit.inventory.ShapedRecipe recipe = new org.bukkit.inventory.ShapedRecipe(new NamespacedKey("test", "test_exact_choice"), new org.bukkit.inventory.ItemStack(Material.BARRIER));
      recipe.shape( "ccc",  "xix",  "xix");
      org.bukkit.inventory.ItemStack exact = new org.bukkit.inventory.ItemStack(Material.DIAMOND);
      ItemMeta meta = exact.getItemMeta();
      meta.setDisplayName("test item");
      exact.setItemMeta(meta);
      recipe.setIngredient('c', new RecipeChoice.ExactChoice(exact));
      recipe.setIngredient('i', new RecipeChoice.MaterialChoice(Material.STICK));
      
      org.bukkit.inventory.ItemStack aaa = exact.clone();
      aaa.setAmount(32);
      player.getInventory().addItem(aaa);
      
      if(Bukkit.getRecipe(recipe.getKey()) != null)
          Bukkit.removeRecipe(recipe.getKey());
      Bukkit.addRecipe(recipe); 

       

      Paper seems to have implemented a fix on 1.21.1 and it works fine.
      Here is their patch: https://github.com/PaperMC/Paper/blob/ver/1.21.1/patches/server/0277-Improve-exact-choice-recipe-ingredients.patch

      I bet something similar can be implemented in 1.21.3 on Spigot.
      I have no clue why Mojang didn't implement that in the first place since recipebook was introduced.
       

            Unassigned Unassigned
            LoneDev LoneDev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: