Solved Smelt all items in hotbar

Discussion in 'Plugin Development' started by negative_codezZ, Dec 5, 2013.

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

    negative_codezZ

    Hello guys!

    I need to make a command that smelts all items in your hotbar. I was thinking looking for items such as ores, etc... and replacing them, but I figured this would take way too long. Anyone know any better way? Thanks in advance.
     
  2. Offline

    bartboy8

    negative_codezZ
    Credit to Njol for the iterating through smelting recipes code!
    Code:
    for(int i = 0;i<8;i++)
    {
    if(player.getInventory().getItem(i) != null)
    {
    ItemStack result = null;
    Iterator<Recipe> iter = Bukkit.recipeIterator();
    while (iter.hasNext()) {
      Recipe recipe = iter.next();
      if (!(recipe instanceof FurnaceRecipe)) continue;
      if (((FurnaceRecipe) recipe).getInput().getType() != player.getInventory().getItem(i)) continue;
      result = recipe.getResult();
      break;
    }
    if(result != null)
    {
    player.getInventory().setItem(i, result);
    }
    }
    }
     
    NathanWolf and Garris0n like this.
  3. Offline

    negative_codezZ

    Didn't work. Thanks though.
     
  4. Offline

    MrInspector

    What's your full code & plugin.yml you used for the code that he supplied you with?
     
  5. Offline

    negative_codezZ

    I am sorry. This is a private project and I will not be posting any code. No need to show my plugin.yml, I ran a test by sending a message to the player on the command, and it worked. The command works, it's just the function that he supplied me with that didn't work.
     
  6. Offline

    MrInspector

    Smelting items in a hotbar is a private project? lol, never knew people wanted to buy simple plugins .-.
     
  7. Offline

    Bart

    If you want help you need to post your code. If it's a private project then just send the relevant class files.
     
  8. Offline

    NathanWolf


    Cudos for supplying a complete solution (not sure why the OP says it's not working, but it looks like it ought to to me)

    However, I'm wondering if this handles multiple stacks of items properly? I think you'd want to check the count of the original itemstacks and create new ones with the right sizes using the Result. I didn't try it, but just reading the code it looks like this would smelt 64 blocks of ore into one ingot.. no?
     
  9. Offline

    negative_codezZ

    It is obviously not just that. This is part of a mini game.
     
  10. Offline

    MrInspector

    Err.. No one is going to copy it as I don't really have any use for it, but probably someone might.

    You can just do this if you're making the minigame which means if you add something to his inv you know what item it is.

    For example:

    Code:java
    1.  
    2. if(player.getInventory().getItem(new ItemStack(Material.IRON_ORE)){
    3. player.getInventory().removeItem(new ItemStack(Material.IRON_ORE));
    4. player.getInventory().addItem(new ItemStack(Material.IRON_INGOT));
    5.  
     
  11. Offline

    negative_codezZ

    That's the thing. I will have to do this for SO many items (Food, ores, etc..). That is TOO time consuming.
     
  12. Offline

    MrInspector

    Heh :/

    Well goodluck!
     
  13. Offline

    krazytraynz

    I use this for smelting ores, although you'd have to change it a bit as it uses the player's entire inventory. Not sure if it's exactly what you're looking for, but I hope it'll help.
    Code:java
    1. @SuppressWarnings("deprecation")
    2. public void smelt(Player p){
    3. ItemStack[] iss = p.getInventory().getContents();
    4. String[] ores = {"14", "15", "16", "56", "74", "73", "21", "129"};
    5. for(ItemStack i1 : iss){
    6. for(String s : ores){
    7. if(i1 != null){
    8. if(i1.getTypeId() == Integer.parseInt(s)){
    9. switch(i1.getType()){
    10. case IRON_ORE:
    11. i1.setType(Material.IRON_INGOT);
    12. continue;
    13. case GOLD_ORE:
    14. i1.setType(Material.GOLD_INGOT);
    15. continue;
    16. case DIAMOND_ORE:
    17. i1.setType(Material.DIAMOND);
    18. continue;
    19. case COAL_ORE:
    20. i1.setType(Material.COAL);
    21. continue;
    22. case REDSTONE_ORE:
    23. i1.setType(Material.REDSTONE);
    24. continue;
    25. case EMERALD_ORE:
    26. i1.setType(Material.EMERALD);
    27. continue;
    28. case LAPIS_ORE:
    29. i1.setType(Material.COCOA);
    30. MaterialData data = i1.getData();
    31. data.setData((byte)14);
    32. i1.setData(data);
    33. continue;
    34. case QUARTZ_ORE:
    35. i1.setType(Material.QUARTZ);
    36. continue;
    37. default:
    38. break;
    39. }
    40. p.playSound(p.getLocation(), Sound.FIRE, 1, 10);
    41. p.updateInventory();
    42. }
    43. }
    44. }
    45. }
    46. }
     
  14. Offline

    NathanWolf

    What about the code bartboy8 posted? You were really quick to dismiss that without providing any details about how it didn't work for you.

    It seems to do exactly what you want- using the recipes minecraft already knows about so you don't have to special-case every item you want to smelt..... :\
     
  15. Offline

    negative_codezZ

    Thank you! It worked!
     
Thread Status:
Not open for further replies.

Share This Page