How to get a craft result by a recipe

Discussion in 'Plugin Development' started by cdnyassuo34, Jan 28, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    cdnyassuo34

    Hello, I am creating a plugin that requiere a function that check the craft of a recipe (not clear at all but I don't know how to explain it fine)
    if anyone can help i'd be happy ^^
     
  2. Use CraftItemEvent?
     
  3. Offline

    cdnyassuo34

    oh no not that ^^ I want it to be able to find a result from the content of a chest (Crafting table shaped)
    I am trying to make an automatic Crafter which require to find a result from a random recipe
     
  4. Offline

    Zombie_Striker

    @cdnyassuo34
    Listen to PrepareItemCraftEvent. That is called right before the "result" is displayed when crafting an item.
     
    pietermantel likes this.
  5. Offline

    cdnyassuo34

    ok ... it's not supposed to be an event ... it's supposed to get the content of a chest and return the result of the content (shaped)
     
  6. Offline

    timtower Administrator Administrator Moderator

    You could use the content of the chest to throw a PrepareItemCraftEvent
     
  7. Offline

    cdnyassuo34

    oh ok ^^ i've tryied this but I just have no clue abourt how to create the event ,
    i've tryied this: prepareItemCraftEvent e = new PrepareItemCraftEvent(idk, view, false);
    but I don't know how to create a CraftingInventory and an InventoryView...
    in conlusion I don't know how to get a craft :| sorry about it ^^'
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Offline

    cdnyassuo34

    have what ? sorry I am a little bit slow ^^'
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    cdnyassuo34

    Code:java
    1. public class Crafter
    2. {
    3. Chest chest;
    4. Location loc;
    5. ArmorStand arm;
    6.  
    7. public Crafter(Location loc,Chest chest)
    8. {
    9. this.loc = loc;
    10. this.chest = chest;
    11. }
    12.  
    13. public void destroyArmorStand()
    14. {
    15. arm.remove();
    16. }
    17.  
    18. public void update()
    19. {
    20. Chest chest = (Chest) loc.getWorld().getBlockAt(loc).getState();
    21.  
    22. List<ItemStack> content = new ArrayList<ItemStack>();
    23.  
    24. if(chest.getInventory().getItem(0) != null) content.add(chest.getInventory().getItem(0));
    25. if(chest.getInventory().getItem(1) != null) content.add(chest.getInventory().getItem(1));
    26. if(chest.getInventory().getItem(2) != null) content.add(chest.getInventory().getItem(2));
    27. if(chest.getInventory().getItem(3) != null) content.add(chest.getInventory().getItem(3));
    28. if(chest.getInventory().getItem(4) != null) content.add(chest.getInventory().getItem(4));
    29. if(chest.getInventory().getItem(5) != null) content.add(chest.getInventory().getItem(5));
    30. if(chest.getInventory().getItem(6) != null) content.add(chest.getInventory().getItem(6));
    31. if(chest.getInventory().getItem(7) != null) content.add(chest.getInventory().getItem(7));
    32. if(chest.getInventory().getItem(8) != null) content.add(chest.getInventory().getItem(8));
    33.  
    34. }
    35.  
    36. public void getCraft(List<ItemStack> itms)
    37. {
    38. PrepareItemCraftEvent e = new PrepareItemCraftEvent(what, view, isRepair);
    39. }
    40.  
    41. }
     
  12. Offline

    KarimAKL

    @cdnyassuo34 You should create a loop for adding the contents, like this:
    Code:Java
    1. for (int i = 0; i < 9; i++) {
    2. ItemStack item = chest.getInventory().getItem(i);
    3. if (item != null) content.add(item);
    4. }

    This doesn't have anything to do with your problem though.
     
  13. Offline

    cdnyassuo34

    I mean that's not the best answer for this question but still a good tip ^^
     
Thread Status:
Not open for further replies.

Share This Page