[SOLVED] Furnace help (spitting out items)

Discussion in 'Plugin Development' started by asdfowkw, Feb 23, 2012.

Thread Status:
Not open for further replies.
  1. When i try to change my furnace type to BURNING_FURNACE it spits the items out.

    this is how i have right now

    Code:
    if(event.getAction() == Action.LEFT_CLICK_BLOCK){
               
                Block block = event.getClickedBlock();
               
                if(burning == false){
                   
                    BlockState getFurnace = block.getState();
                   
                    if(getFurnace instanceof Furnace){
                        Furnace myFurnace = (Furnace)getFurnace;
                        Material getInv0 = myFurnace.getInventory().getItem(0).getType();
                        MaterialData getInvData0 = myFurnace.getInventory().getItem(0).getData();
                        short getInvStack0 = (short) myFurnace.getInventory().getItem(0).getAmount();
                        Material getInv1 = myFurnace.getInventory().getItem(1).getType();
                        MaterialData getInvData1 = myFurnace.getInventory().getItem(1).getData();
                        short getInvStack1 = (short) myFurnace.getInventory().getItem(1).getAmount();
                        Material getInv2 = myFurnace.getInventory().getItem(2).getType();
                        MaterialData getInvData2 = myFurnace.getInventory().getItem(2).getData();
                        short getInvStack2 = (short) myFurnace.getInventory().getItem(2).getAmount();
                       
                        ItemStack inv0 = new ItemStack(getInv0, getInvStack0);
                       
                        short burnTime = (short) (200*getInvStack0);
                       
                        myFurnace.getInventory().clear();
                        myFurnace.getInventory().setItem(0, inv0);
                        myFurnace.setBurnTime(burnTime);
                        player.sendMessage("Inv1: " + getInv0 + "x" + getInvStack0);
                        player.sendMessage("Inv2: " + getInv1 + "x" + getInvStack1);
                        player.sendMessage("Inv3: " + getInv2 + "x" + getInvStack2);
                       
                        burning = true;
                    }
                }
    That code will actually put the item stack in and start burning.

    But if i add block.setType(Material.BURNING_FURNACE); between myFurnace.getInventory().clear() and myFurnace.getInventory().setItem(0, inv0); it will start burning but not readd the items...

    How can i make so it shows that it is a BURNING_FURNACE, AND readd the itemstack that was in it??
     
  2. Offline

    Shamebot

    Try to obtain a new BlockState after you update the block and set its inventory.
    You could simplify you code:
    Code:
    if(event.getAction() == Action.LEFT_CLICK_BLOCK){
           
                Block block = event.getClickedBlock();
           
                if(!burning){
               
                    BlockState getFurnace = block.getState();
               
                    if(getFurnace instanceof Furnace){
     
                        Furnace myFurnace = (Furnace)getFurnace;
                        ItemStack stack0 = myFurnace.getInventory().getItem(0);
                        ItemStack stack1 = myFurnace.getInventory().getItem(1);
                        ItemStack stack2 = myFurnace.getInventory().getItem(2);
                   
                        short burnTime = (short) (200*stack0.getAmount());
                   
                        myFurnace.getInventory().clear();
                        myFurnace.getInventory().setItem(0, stack0);
                        myFurnace.setBurnTime(burnTime);
                        player.sendMessage("Inv1: " + stack0.getType() + "x" + stack0.getAmount());
                        player.sendMessage("Inv2: " + stack1.getType() + "x" + stack1.getAmount());
                        player.sendMessage("Inv3: " + stack2.getType() + "x" + stack2.getAmount());
                   
                        burning = true;
                    }
                }
     
  3. It still dosnt show the "flames" on the furnace =/
     
  4. Offline

    Shamebot

    Did you try
    Code:
    myFurnace.getInventory().clear();
    block.setType(Material.BURNING_FURNACE);
    myFurnace = (Furnace)block.getState();
    myFurnace.getInventory().setItem(0, stack0);
    myFurnace.setBurnTime(burnTime);
    
    ?
     
  5. Thanks alot mate. Forgot to mention at the start that im totally new to java (been programming before but not java and not objectoriented).

    So its not that i only copy n paste, i DO understand the code when i see it, but i have hard to figure out how to solve it myself now in the beginning, but now i learned what u ment and i see how this was the solution.

    Thanks alot!
     
Thread Status:
Not open for further replies.

Share This Page