I am getting into scripting using tasks and I have a question about inheritance and how to go about doing this.
I have my main class:
public class Test extends Script {
ArrayList<Task> tasks = new ArrayList<Task>();
@Override
public void onStart() throws InterruptedException {
// Add tasks
tasks.add(new DropTask(this));
tasks.add(new CutTask(this));
}
@Override
public final int onLoop() throws InterruptedException {
tasks.forEach(tasks -> tasks.run());
return random(100,300);
}
}
And I have my task class:
public abstract class Task extends Test {
protected MethodProvider api;
public Task(MethodProvider api) {
this.api = api;
}
public abstract boolean canProcess();
public abstract void process();
public void run() {
if (canProcess())
process();
}
}
And I have my cutting task:
public class CutTask extends Task {
public CutTask(MethodProvider api) {
super(api);
}
@Override
public boolean canProcess() {
return !api.getInventory().isFull();
}
@Override
public void process() {
api.log("Chop tree task initiated!");
Entity tree = api.getObjects().closest(1276,1278);
if (tree != null && tree.interact("Chop down")) {
// Just testing
}
}
}
Now the above code is super basic while I get my feet wet again in scripting (I haven't scripted in over 6 years so I'm trying to jump start my memory).
Basically what I want to do is set a variable, most likely should be in the main class (Test), for the tree Entity. And I want to be able to access and edit this Entity variable from within the tasks themselves. My reasoning for this is that I want to be able to check in the task canProcess() that a tree has been selected, and if it has, that it still exists. This will allow my script to more quickly respond to when a tree is cut down, rather than relying on the cutting animation which often lags behind the actual tree being cut down.