Solved Furnace doesn't update with new items.

Discussion in 'Spigot Plugin Development' started by Masteroliw, Aug 13, 2018.

  1. I'm trying to update a furnace with new items, but it doesn't work.

    When I place a certain item in the furnace's smelting slot it will trigger the code in the InventoryClickEvent method. The code will make the fuel in the fuel spot lose a item in its stack and the result slot will get a new item that is just a renamed gold hoe.

    The only problem is that the fuel won't get updated and the gold hoe doesn't get put in the result slot.

    I have tried to use player.updateInventory(), but it bugs somewhat. And I have some other similar code that will sort of do the same thing but with no player looking in the furnace. So I can't call it.

    Here's some code:

    Code (Text):

    //Just visualize this being in the
    public void ininventory(InventoryClickEvent e) {
    //with some if statements.

    Furnace furnace = (Furnace) e.getInventory().getHolder();

    ItemStack item = new ItemStack(Material.GOLD_HOE, 1, (short) 1);
    ItemMeta meta = item.getItemMeta();

    meta.setDisplayName(ChatColor.RESET + "Tin Ingot");
    meta.setLocalizedName(ChatColor.RESET + "Tin Ingot");


    //doesn't work.

    //prints GOLD_HOE

    player.setItemOnCursor(new ItemStack(Material.AIR));
    if(furnace.getBurnTime() == 0) {
        furnace.setBurnTime((short) mentry.getValue());
        //Prints out the original amount, example: 64
        furnace.getInventory().getFuel().setAmount(furnace.getInventory().getFuel().getAmount() - 1);
        //Prints out 63
        //The thing that is supposed to work...
    } else {
        //The thing that is supposed to work...

    I'm wondering if there's something I have to call to have the furnace update its inventory that I have missed (Searched for a answer in the docs for hours), something else, or that it's just simply not possible.

    Edit: Checked if the instance of the furnace got the gold hoe after using setResult() in the result slot and the type it printed was GOLD_HOE, so it really must be something about the furnace not updating.

    Edit2: Well I found the solution.


    Using the furnace.update(); will result in the furnace updating its burntime and cooktime, but also will revert the inventory changes.

    So I guess the inventory is already updated when the changes are made. And update() is not necessary.

    So in a nutshell, use furnace.update(); before inserting items in the slots if you want to update the burntime and cooktime to change also, and not after.
    #1 Masteroliw, Aug 13, 2018
    Last edited: Aug 13, 2018