1.8.8 Setting a result of CraftItemEvent to an Itemstack

Discussion in 'Spigot Plugin Development' started by TryHart, Aug 4, 2021.

  1. Code (Text):
       
        @EventHandler
        public void onCraft(CraftItemEvent event) {
            List<ItemStack> fusion = new ArrayList<>();
            fusion.add(RecipesList.fusionchestplate());
            fusion.add(RecipesList.fusionhelmet());
            fusion.add(RecipesList.fusionboots());
            fusion.add(RecipesList.fusionlegs());
                 
                 Random random = new Random();
                 int choice = random.nextInt(fusion.size());
                 ItemStack fusionpiece = fusion.get(choice);
                 ItemStack fusioncraftitem = RecipesList.fusioncraftitem();
                 ItemMeta fusionitemmeta = RecipesList.fusioncraftitem().getItemMeta();
                 
            if (event.getRecipe().getResult().equals(RecipesList.fusionitemrecipe())){
                event.setResult(fusionpiece);
            }
        }
     
    I have this which doesnt work. thx
     
  2. Please provide more info, eg. what you want to happen, any error codes, what you have tried so far to fix it.
     
  3. You are using equals to compare itemstacks. Instead use isSimilar
     
  4. I want to set the result of the CraftItemEvent to be an Itemstack which is called fusionpiece, which is a random item from the ArrayList. it says: The method setResult(Event.Result) in the type InventoryInteractEvent is not applicable for the arguments (ItemStack). But i dunno what method to use to make it work with itemstacks.
     
  5. sorry, I didn't tell what is the problem. The problem is the result.
     
  6. Code (Java):
    event.getInventory().setResult()
     
  7. oh thx, I am actually so dumb :D
     
  8. What I would do instead is use PrepareItemCraftEvent, but ig the event that you are using works fine too