@DylanSRT you could wrap your code in Event instances to replicate the looping behavior, they should be interrupted when a script stops/pauses.
execute(new Event() {
long ucAmount;
long seedAmount;
@Override
public void onStart() {
ucAmount = getInventory().getAmount(uc);
seedAmount = getInventory().getAmount(seed);
}
@Override
public int execute() {
if (getInventory().isItemSelected()) {
String selectedItem = getInventory().getSelectedItemName();
long selectedItemAmount = getInventory().getAmount(selectedItem);
if (patch.interact("Use")) {
Sleep.sleepUntil(() -> getInventory().getAmount(selectedItem) < selectedItemAmount,
3000 + 630 * getMap().realDistance(patch));
}
} else if (ucAmount == getInventory().getAmount(uc)) {
Item ucItem = getInventory().getItem(uc);
if (Objects.isNull(ucItem)) {
setFailed();
return -1;
} else if (ucItem.interact("Use")) {
Sleep.sleepUntil(getInventory()::isItemSelected, 2000);
}
} else if (seedAmount == getInventory().getAmount(seed)) {
Item seedItem = getInventory().getItem(seed);
if (Objects.isNull(seedItem)) {
setFailed();
return -1;
} else if (seedItem.interact("Use")) {
Sleep.sleepUntil(getInventory()::isItemSelected, 2000);
}
} else {
setFinished();
return -1;
}
return random(10, 100);
}
});
Check the API docs on Event, EventExecutor, ScriptExecutor for details
PS: Make sure you change the code to take into account the base where the ultracompost/seed cannot be used on the patch, otherwise it will loop until script is interrupted.