Solved Change Furnace/Brewing Speed

Discussion in 'Plugin Development' started by AngryCupcake274, Aug 14, 2015.

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

    AngryCupcake274

    Hello all,
    I am creating a plugin with faster brewing and furnace speeds. I have set the furnace speed to half, but is there a way to just have it cook twice as fast instead of setting it to half done.

    Second: how would you go about making a faster brewing stand? Here is my broken code.
    Code:
        @EventHandler
        public void onBrewing(BrewEvent e) {
           
            BrewingStand brewingstand = (BrewingStand) e.getBlock().getState();
            brewingstand.setBrewingTime(0);
           
        }
     
  2. Offline

    Zombie_Striker

    @AngryCupcake274
    What does that method do at this point?

    Also, can you show how you set the furnace speed to half? (I have never worked with this method before)
     
  3. Offline

    AngryCupcake274

    @Zombie_Striker the method is supposed to have the furnace 'arrow' thingy go twice as fast.

    Here is my furnace code for half finished already (when item is about to start smelting, it will already be half done):
    Code:
        @EventHandler
        public void onFurnaceBurn(FurnaceBurnEvent e) {
           
            Furnace furnace = (Furnace) e.getBlock().getState();
            furnace.setCookTime((short) 100);
           
        }
       
        @EventHandler
        public void onFurnaceSmelt(FurnaceSmeltEvent e) {
           
            Furnace furnace = (Furnace) e.getBlock().getState();
            furnace.setCookTime((short) 100);
           
        }
       
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onClick(InventoryClickEvent e) {
           
            Block block = e.getWhoClicked().getTargetBlock(null, 10);
           
            if (block.getType().equals(Material.FURNACE) || block.getType().equals(Material.BURNING_FURNACE)) {
               
                if ((e.getSlot() == 0 || e.getSlot() == 1) && !e.getCursor().getType().equals(Material.AIR)) {
                   
                    Furnace furnace = (Furnace) block.getState();
                    furnace.setCookTime((short) 100);
                   
                }
            }
        }
     
  4. Offline

    Zombie_Striker

    @AngryCupcake274
    Since I don't know if there is an event that fires once the furnance "ticks", Try the following:
    1. Create an array of blocks that are furnacnes
    2. create a hashmap that takes in a block, Integer (the block being the furnance, the int being the cook time)
    3. create a repeating task and "Hack" the furnance cook time
    Code:
    Hashmap#set(Furnance, Hashmap#get(Furnance)+2);setCookTime(Hashmap#get(Furnance));
    What this does is add +2 every tick. This is a hack, but it will work.
     
  5. Offline

    AngryCupcake274

    @Zombie_Striker how do you get all the furnaces to a HashMap? I've never done anything like this before.
     
  6. Offline

    Zombie_Striker

    @AngryCupcake274
    For loops.
    Code:
    for(Block b : FurnanceArray){
       if(b instanceof Furnance){
           Furnace f = (Furnace)b;
           int cooktime = HashMap.get(b);// since the hasmap takes in blocks, give it the block instance
       }
    }
     
  7. Offline

    AngryCupcake274

    @Zombie_Striker so when there is a furnace burning or smelted (using my listeners), I just add that furnace to the array if it doesn't already exist?

    If so, how do I go about with the Brewing Stand thing?
     
  8. Offline

    Zombie_Striker

    Code:
    HashMap<Block,Integert> Hashmap = new HashMap<Block,Integer>();
    ArrayList<Block> ArrayList = new ArrayList<Block>();
    
    // in onEnable
    getServer()).getscheduler().scheduleSyncRepeatingTask(JavaPluigin class,new Runnable(){
    
    public void run(){
    for(Block b : Array){
       if(b instanceof Furnance){
           Furnace f = (Furnace)b;
           int cooktime = HashMap.get(b);// since the hasmap takes in blocks, give it the block instance
          if(f.getInventory().get(0) != null && f./*getting the amount of burn time*/ > 0){
               HashMap.set(f,Hashmap.get(f)+2);
               f.setBurntime(Hashmap.get(f));
             }
       }
    }
    }
    }
    ),0,1L);
    
    //In onPlayerInteract
    if(event.getBlock() != null && event.getblock().getType == Material.FURNANCE
    && !ArrayList.contains(event.getBlock)){
    Hashmap.put(event.getblock(),0);
    ArrayList.add(event.getBlock);
    }
    For brewing stands, you can just copy-and-past everything, but change Furnances to BrewingStands.
     
  9. Offline

    AngryCupcake274

    @Zombie_Striker I modified your code a little bit to work with server reloads, and it removes the need for a Map. PM me if you want the code for this (completed).
     
Thread Status:
Not open for further replies.

Share This Page