Jump to content

Furnace animation delay


Recommended Posts

Posted

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
Posted (edited)


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
Posted
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

Posted (edited)

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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