Changing time furnace takes to smelt items

Discussion in 'Spigot Plugin Development' started by DecisionsYT, Aug 5, 2018.

  1. Hey!

    I have been trying to figure out how I can alter the time it takes a furnace to smelt an item. By default, it is set to 200 ticks (10 seconds) per item. My goal is to reduce that time to 100 ticks (5 seconds) per item.

    I have been looking around on the docs and know that
    Code (Text):
    Furnace.setCookTime()
    has something to do with what I am trying to achieve. I am aware that this question has previously been asked about, however I am unable to find any working solutions for 1.13. I have looked at https://www.spigotmc.org/threads/change-furnace-brewer-faster.86919/ and https://bukkit.org/threads/change-furnace-brewing-speed.379418/ but unfortunately, I have had no luck in either of them.

    My initial guess to solve this problem I am having (but I'm not sure how I would go about doing it) would be to update the
    Code (Text):
    cookTime()
    every tick to be +1 of what it already is. But again, I'm not sure on that one.

    Any help is greatly appreciated. :)
     
  2. Hello ! I use this code for changing furnace time :

    Code (Java):
    @EventHandler
        public void onFurnaceBurn(FurnaceBurnEvent event) {
            startUpdate((Furnace )event.getBlock().getState(), 4);
        }
       
        private void startUpdate(final Furnace block, final int speed) {
           
            new BukkitRunnable() {
               
                public void run() {
                   
                    if ((block.getCookTime() > 0) || (block.getBurnTime() > 0)) {
                       
                        block.setCookTime((short)(block.getCookTime() + speed));
                        block.update();
                       
                    } else {
                        cancel();
                    }
                }
            }.runTaskTimer(UHC.getInstance(), 1L, 1L);
        }
     
  3. Hmm.. I tried that, but it didn't work. I got no error messages in the console.

    Just checking, I did implement it correctly right?
    Code (Text):
    public class Main extends JavaPlugin implements Listener {

        private static Main pl;

        public void onEnable(Main plugin) {
            new BlockListenerPlace(this);
            getServer().getPluginManager().registerEvents(this, this);
            pl = plugin;
        }

        @Override
        public void onDisable() {

        }

        private void startUpdate(final Furnace block, final int speed) {

            new BukkitRunnable() {

                @Override
                public void run() {

                    if ((block.getCookTime() > 0) || (block.getBurnTime() > 0)) {

                        block.setCookTime((short) (block.getCookTime() + speed));
                        block.update();

                    } else {
                        cancel();
                    }
                }
            }.runTaskTimer(Main.getInstance(), 1L, 1L);
        }

        private static Plugin getInstance() {
            return pl;
        }

        @EventHandler
        public void onFurnaceBurn(FurnaceBurnEvent event) {
            getServer().broadcastMessage("Debug");
            startUpdate((Furnace) event.getBlock().getState(), 4);
        }

    }
     
    As you can see, I even made a debug message in the onFurnaceBurn() event, however this was not triggered.


    EDIT: Hmm.. I just added a PlayerMoveEvent and that was not triggered. Perhaps I didn't implement my Listener correctly? I don't know what I did wrong though...

    EDIT 2: None of my listeners are working. I have tried them both inside the Main class and outside, all implemented correctly.

    EDIT 3: I have made my listeners work again by removing the .getInstance as it was messing with the onEnable() and replacing it with this. Now, every time the furnace uses up 1 coal (after smelting 8 blocks) it triggers the start update which lasts for one tick and doesn't repeat, and ends up cancelling itself.
     
    #3 DecisionsYT, Aug 5, 2018
    Last edited: Aug 5, 2018
  4. You have to add @Override in the top of on Enable function to fix listener error
     
  5. Why are you passing your Main class to the onEnable method? Remove it and make the static variable equal to 'this' instead.
     
  6. I have fixed that, however the actual code to increase the furnace speed does not work.
     
  7. Yeah just realised that. However the main problem still isn't solved. :(