-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…itor Autocrafting monitor support for tasks
- Loading branch information
Showing
72 changed files
with
2,288 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...c/main/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting.status; | ||
|
||
import com.refinedmods.refinedstorage.api.autocrafting.task.ExternalPatternInputSinkKey; | ||
import com.refinedmods.refinedstorage.api.autocrafting.task.TaskId; | ||
import com.refinedmods.refinedstorage.api.core.CoreValidations; | ||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
|
||
public class TaskStatusBuilder { | ||
private final TaskStatus.TaskInfo info; | ||
private final Map<ResourceKey, MutableItem> items = new LinkedHashMap<>(); | ||
|
||
public TaskStatusBuilder(final TaskId id, final ResourceKey resource, final long amount, final long startTime) { | ||
this.info = new TaskStatus.TaskInfo(id, resource, amount, startTime); | ||
} | ||
|
||
public TaskStatusBuilder stored(final ResourceKey resource, final long stored) { | ||
CoreValidations.validateLargerThanZero(stored, "Stored"); | ||
get(resource).stored += stored; | ||
return this; | ||
} | ||
|
||
public TaskStatusBuilder processing(final ResourceKey resource, | ||
final long processing, | ||
@Nullable final ExternalPatternInputSinkKey sinkKey) { | ||
CoreValidations.validateLargerThanZero(processing, "Processing"); | ||
get(resource).processing += processing; | ||
get(resource).sinkKey = sinkKey; | ||
return this; | ||
} | ||
|
||
public TaskStatusBuilder scheduled(final ResourceKey resource, final long scheduled) { | ||
CoreValidations.validateLargerThanZero(scheduled, "Crafting"); | ||
get(resource).scheduled += scheduled; | ||
return this; | ||
} | ||
|
||
public TaskStatusBuilder crafting(final ResourceKey resource, final long crafting) { | ||
CoreValidations.validateLargerThanZero(crafting, "Crafting"); | ||
get(resource).crafting += crafting; | ||
return this; | ||
} | ||
|
||
public TaskStatusBuilder rejected(final ResourceKey resource) { | ||
get(resource).type = TaskStatus.ItemType.REJECTED; | ||
return this; | ||
} | ||
|
||
public TaskStatusBuilder noneFound(final ResourceKey resource) { | ||
get(resource).type = TaskStatus.ItemType.NONE_FOUND; | ||
return this; | ||
} | ||
|
||
public TaskStatusBuilder locked(final ResourceKey resource) { | ||
get(resource).type = TaskStatus.ItemType.LOCKED; | ||
return this; | ||
} | ||
|
||
private MutableItem get(final ResourceKey resource) { | ||
return items.computeIfAbsent(resource, key -> new MutableItem(TaskStatus.ItemType.NORMAL)); | ||
} | ||
|
||
public TaskStatus build(final double percentageCompleted) { | ||
return new TaskStatus(info, percentageCompleted, items.entrySet().stream().map(entry -> new TaskStatus.Item( | ||
entry.getKey(), | ||
entry.getValue().type, | ||
entry.getValue().sinkKey, | ||
entry.getValue().stored, | ||
entry.getValue().processing, | ||
entry.getValue().scheduled, | ||
entry.getValue().crafting | ||
)).toList()); | ||
} | ||
|
||
private static class MutableItem { | ||
private TaskStatus.ItemType type; | ||
private long stored; | ||
private long processing; | ||
@Nullable | ||
private ExternalPatternInputSinkKey sinkKey; | ||
private long scheduled; | ||
private long crafting; | ||
|
||
private MutableItem(final TaskStatus.ItemType type) { | ||
this.type = type; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ava/com/refinedmods/refinedstorage/api/autocrafting/task/ExternalPatternInputSinkKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting.task; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@FunctionalInterface | ||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.12") | ||
public interface ExternalPatternInputSinkKey { | ||
String getName(); | ||
} |
Oops, something went wrong.