Solved Furnace setCookTime

Discussion in 'Plugin Development' started by Junrall, Mar 29, 2013.

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

    Junrall

    Hello,

    So, I'm not to familiar with manipulating furnace cook times. I've looked at several threads and have tried some of the examples. For the life of me I can't seem to figure out how to speed up the cook time. Whenever I smelt something, it smelts at the vanilla set time.

    Maybe I have it in the wrong event?

    Any insight on this would be much appreciated.

    Here is what I have.. very basic for testing purposes:
    Code:
     public void onBlockPlace(BlockPlaceEvent event) {
            Furnace furnace = (Furnace)event.getBlock().getState();
         
            furnace.setCookTime((short)10);
            furnace.update(true);
    }

    Thanks!
     
  2. Offline

    Compressions

    Junrall Why wouldn't you use FurnaceSmeltEvent?
     
  3. Offline

    Junrall

    Compressions
    The FurnaceSmeltEvent only takes place when the smelted item appears in the output of the furnace.
     
  4. Offline

    ZeusAllMighty11

    You don't have an @EventHandler annotation
     
    xXMaTTHDXx likes this.
  5. Offline

    number1_Master

    and did you register the events onEnable ?
     
  6. Offline

    Junrall

    ZeusAllMighty11
    I do have the @EventHandler annotation in place... I missed it when I copied the code to paste it here.

    number1_Master
    Yes, I have the listener registered within onEnable. To test that the event was firing, I sent a message to the chat whenever the furnace was placed... it worked.
     
  7. when you set the furnace to be cooking, you dont set the furnace to an burning state?
     
  8. Offline

    Junrall

    ferrybig
    I'm not trying to set the furnace to a cooking state... I'm trying to speed up the time it takes to cook something.
    I beleive that setting a furnace to a burning state just turns on the flame animation and furnace glow.

    Ok... I'm making good progress with this.
    As soon as I iron out some things I'll post it here.

    Here is what I came up with.
    The cook time counts downward from 200 to 0... 200 being the max.
    In the code below, I am cooking items twice as fast by setting setCookTime to 100. This means that the cook time will count downward from 200 to 100... cooking your items in half the time.
    The problem is... once cook time has reached 200, setCookTime it will automatically be reset back to 200. To solve this problem, setCookTime has to continually be set to 100 (or what ever number you choose).

    FurnaceBurnEvent triggers the the new cook time the moment the furnace fires up it's first flame.
    Because the furnace has already fired up, the next items in the stack will not cook at the new cook time.

    FurnaceSmeltEvent triggers the new cook time the moment a cooked item lands in the output of the furnace. This is used to set the cook time for any additional items in the stack.

    InventoryClickEvent detects if the two furnace slots have been clicked with an item under the cursor. If so, then this too will trigger the new cook time. This is to take care of an empty furnace that is still fired up.

    The example can be slimmed down a bit and a few more checks may need to be implemented... but it does work.;)

    Code:
      Short cooktime = (short)100;
     
      @EventHandler
        public void furnaceBurn(FurnaceBurnEvent event) {
            Furnace furnace = (Furnace) event.getBlock().getState();
            furnace.setCookTime(cooktime);
        }
     
        @EventHandler
        public void furnaceSmeltEvent(FurnaceSmeltEvent event) {
            Furnace furnace = (Furnace) event.getBlock().getState();
            furnace.setCookTime(cooktime);
        }
     
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            Block blocktype = event.getWhoClicked().getTargetBlock(null, 10);   
     
            if (blocktype.getType() == Material.FURNACE || blocktype.getType() == Material.BURNING_FURNACE) {
                if ((event.getSlot() == 0 || event.getSlot() == 1) && event.getCursor().getType() != Material.AIR) {
                    Furnace furnace = (Furnace) blocktype.getState();
                    furnace.setCookTime(cooktime);
                }
            }
        }
    EDIT: I was mistaken in saying that the cook time is counted from 0 to 200. It actually counts down to 0 from 200.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  9. Thanks a lot for this post, was very usefull for me! Here are some more informations : The code used to compute the time is here : http://goo.gl/RRhH97. cookTime is the number of ticks that are already elapsed.
    Here is the code I'm currently using based on the one posted before : https://gist.github.com/8321525
     
Thread Status:
Not open for further replies.

Share This Page