Solved Semi-Inconsistent times with setBurnTime for furnaces

Discussion in 'Plugin Development' started by Shuski, Jan 5, 2017.

Thread Status:
Not open for further replies.
  1. FIXED - See latest reply.


    I seem to be having a little problem with setting a furnace's burn time.
    Here's a table of results. Anything after 200 goes up by 5 seconds every 100 ticks (As expected). But values below 200 really struggle to make sense in my eyes...

    Using saplings as fuel.
    What burntime is set to in the plugin / how long it took to actually smelt.
    [​IMG]

    The gap between 100 and 200 is 10 seconds, yet the gap between every other nth 100 is 5 seconds thereafter...Also 200 should be 200 ticks right? The actually burn time should of been 10 seconds. I'm stumped.

    EDIT: Here's the code: http://pastebin.com/ELKEFBaH
     
    Last edited: Jan 5, 2017
  2. Offline

    Zombie_Striker

    @Shuski
    How can ten ticks (0.5 seconds) be equal to one-hunrdred ticks (5 seconds)? What is the actual output when you display the burntime?

    [Edit] Are you just counting the seconds, or are you getting these values by printing out the burntime?
     
  3. That's my problem. I set the burn time to 10ticks in the code, in game it takes 5 seconds to burn through that fuel for some reason. I'm either doing something wrong or this is a bug...

    It shows the furnace is on 10 tick burntime. It just takes 5 seconds for the fuel to burn. Going to record a video.
     
  4. Offline

    Zombie_Striker

    @Shuski
    I'll test this later. Maybe I might be able to see the problem/ figure out another way of doing this.
     
  5. Will test with other burnable items. Thank you for having a look.
     
  6. Offline

    Zombie_Striker

    @Shuski
    Using the code below, I got the following results:
    Code:
        @EventHandler
        public void onFurnaceBurn(FurnaceBurnEvent e) {
            final Furnace furnace = (Furnace) e.getBlock().getState();
            short burntime = 40;
            Bukkit.broadcastMessage("Furnacetime set to " + burntime);
            furnace.setBurnTime(burntime);
            furnace.update();
           
            //Time tester
            final Long time = System.currentTimeMillis();
            final StringBuilder sb = new StringBuilder();
            sb.append(
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    if (furnace.getBurnTime()==0){
                        Bukkit.broadcastMessage("Done after "
                                + ((double) System.currentTimeMillis() - time)
                                / 1000);
                        Bukkit.getScheduler().cancelTask(Integer.parseInt(sb.toString()));
                    }
                   
                }
            }, 0, 1));
        }
    1 = 15.09 seconds
    2 = 15.18 seconds
    3 = 15.27 seconds
    20 = 16 seconds
    40 = 17 seconds.

    Now, those last few decimals are not correct since it rely only on synced repeating tasks. that last only 1/20th of a second. Basically, everything looks like it should (though the first 20 are slightly off, though that may be that the schedulers are running before or after the furnace actually updates.)
     
  7. Perfect timing on the reply, I just fixed it, it now burns at the correct ticks-burn ratio. Thank you for going out your way to try and fix though, much appreciation.

    50 = 2.5 seconds.
    100 = 5 seconds.
    200 = 10 seconds.
    400 = 20 seconds.

    I was using the block instead of the event when setting the burn time. But I still don't see how setting the burntime on "furnace" wouldn't of worked. Here's fixed code for others:

    Code:
        // How fast fuel is consumed.
        @EventHandler
        public void onFurnaceBurn(FurnaceBurnEvent e) {
            Furnace furnace = (Furnace) e.getBlock().getState();
            FileConfiguration cfg = plugin.getConfig();
    
            String furnLoc = "furnaces." + furnace.getWorld().getName() + "," + furnace.getX() + "," + furnace.getY() + ","
                    + furnace.getZ();
    
            if (cfg.contains(furnLoc)) {
                //int storedModifier = cfg.getInt(furnLoc+".coal");
                //int configModifier = cfg.getInt("modifers.burntime");
                //int oldBurn = e.getBurnTime();
    
                //short burnTime = oldBurn * (storedModifier + (configModifier * 100));
                short burnTime = 200;
        
            
                Bukkit.broadcastMessage("START BT: " + e.getBurnTime());
    
                e.setBurnTime(burnTime);
                furnace.update();
            
                Bukkit.broadcastMessage(ChatColor.YELLOW + "Furn NEW BT: " + furnace.getBurnTime());
                Bukkit.broadcastMessage(ChatColor.BLUE + "Event NEW BT: " + e.getBurnTime());
            }
            else
                Bukkit.broadcastMessage("Furn: " + furnLoc + "Current BT: " + e.getBurnTime());
        }
    
     
    Last edited: Jan 5, 2017
  8. Offline

    Zombie_Striker

    @Shuski
    THATS WHY. This is furnace burn event, meaning this event is triggered BEFORE the event is even applied. That means it is still going to apply the burntime after you set the burntime. IDK why it would add the 15 seconds (I was testing on logs, which has a default of 15 seconds burntime) to the modified time (most likely, bukkit was written weirdly when it came to this event)

    So, we should have been using the event this whole time.

    If the problem has now been solved, mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page