Jump to content

Furnace animation delay


Mofo0

Recommended Posts

My script is using a furnace and I am currently using if (!myPlayer().isAnimating()) to check if I am already using the furnace. It works most of the time but it occasionally breaks and tries to restart the crafting while it already is crafting. I am guessing it is because there is a small delay between the smithing animations so the script will think the player is not animating. I have experimented with sleeps and seen into getAnimationDelay() but cannot figure it out.

 

Any help is appreciated :)

  • Like 1
Link to comment
Share on other sites


public class Timer {

private long period;

private long start;

public Timer(long period) {

this.period = period;

this.start = System.currentTimeMillis();

}

public long getElapsed() {

return System.currentTimeMillis() - this.start;

}

public long getRemaining() {

return this.period - this.getElapsed();

}

public boolean isRunning() {

return this.getElapsed() <= this.period;

}

public void setPeriod(long period) {

this.period = period;

}

public void reset() {

this.start = System.currentTimeMillis();

}

public static String format(long milliSeconds) {

long secs = milliSeconds / 1000L;

return String.format("%02d:%02d:%02d", secs / 3600L,

secs % 3600L / 60L, secs % 60L);

}

}


//method

public boolean isSmithing() {

boolean isSmith = false;

Timer timer = new Timer(1800);

while (timer.isRunning() && !isSmith) {

isSmith = myPlayer().getAnimation() != -1 ? true : isSmith;

}

return isSmith;

}

Edited by Sinatra
  • Like 3
Link to comment
Share on other sites

public class Timer {
   private long period;
   private long start;
   public Timer(long period) {
       this.period = period;
       this.start = System.currentTimeMillis();
   }
   public long getElapsed() {
       return System.currentTimeMillis() - this.start;
   }
   public long getRemaining() {
       return this.period - this.getElapsed();
   }
   public boolean isRunning() {
       return this.getElapsed() <= this.period;
   }
   public void setPeriod(long period) {
       this.period = period;
   }
   public void reset() {
       this.start = System.currentTimeMillis();
   }
   public static String format(long milliSeconds) {
       long secs = milliSeconds / 1000L;
       return String.format("%02d:%02d:%02d", secs / 3600L,
               secs % 3600L / 60L, secs % 60L);
   }
}
//method

public boolean isSmithing() {
    boolean isSmith = false;
    Timer timer = new Timer(1800);
    while (timer.isRunning() && !isSmith) {
         isSmith = myPlayer().getAnimation() != -1 ? true : isSmith;
    }
    return isSmith;
}

 

 

Add a timer

 

Thanks for the help, I'll try this out

Link to comment
Share on other sites

My script is using a furnace and I am currently using if (!myPlayer().isAnimating()) to check if I am already using the furnace. It works most of the time but it occasionally breaks and tries to restart the crafting while it already is crafting. I am guessing it is because there is a small delay between the smithing animations so the script will think the player is not animating. I have experimented with sleeps and seen into getAnimationDelay() but cannot figure it out.

 

Any help is appreciated smile.png

 

Just do a really long ConditionalSleep.

 

For example if you are smelting Gold bars you could do something like:

private final ConditionalSleep SMELTING_SLEEP = new ConditionalSleep(100_000) {

    @Override
    public boolean condition() throws InterruptedException {
            return !getInventory().contains("Gold ore");
    }
};

When you start smelting, you can call:

SMELTING_SLEEP.sleep();

And it will then sleep for up to 100 seconds, or until the inventory no longer contains Gold Ore

Edited by Explv
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...