-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Autocrafting tasks
- Loading branch information
Showing
122 changed files
with
3,627 additions
and
367 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
9 changes: 9 additions & 0 deletions
9
...afting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/PatternType.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; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
@API(status = API.Status.STABLE, since = "2.0.0-milestone.4.12") | ||
public enum PatternType { | ||
INTERNAL, | ||
EXTERNAL | ||
} |
9 changes: 0 additions & 9 deletions
9
...utocrafting-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/TaskId.java
This file was deleted.
Oops, something went wrong.
8 changes: 7 additions & 1 deletion
8
...api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/calculation/Amount.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
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
5 changes: 4 additions & 1 deletion
5
...m/refinedmods/refinedstorage/api/autocrafting/calculation/CraftingCalculatorListener.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
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
2 changes: 1 addition & 1 deletion
2
...-api/src/main/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatus.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
2 changes: 1 addition & 1 deletion
2
.../main/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusListener.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
2 changes: 1 addition & 1 deletion
2
.../main/java/com/refinedmods/refinedstorage/api/autocrafting/status/TaskStatusProvider.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
84 changes: 84 additions & 0 deletions
84
...c/main/java/com/refinedmods/refinedstorage/api/autocrafting/task/AbstractTaskPattern.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,84 @@ | ||
package com.refinedmods.refinedstorage.api.autocrafting.task; | ||
|
||
import com.refinedmods.refinedstorage.api.autocrafting.Pattern; | ||
import com.refinedmods.refinedstorage.api.core.Action; | ||
import com.refinedmods.refinedstorage.api.resource.ResourceKey; | ||
import com.refinedmods.refinedstorage.api.resource.list.MutableResourceList; | ||
import com.refinedmods.refinedstorage.api.resource.list.MutableResourceListImpl; | ||
import com.refinedmods.refinedstorage.api.resource.list.ResourceList; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
abstract class AbstractTaskPattern { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTaskPattern.class); | ||
|
||
protected final Pattern pattern; | ||
protected final Map<Integer, Map<ResourceKey, Long>> ingredients = new HashMap<>(); | ||
|
||
protected AbstractTaskPattern(final Pattern pattern, final TaskPlan.PatternPlan plan) { | ||
this.pattern = pattern; | ||
for (final Map.Entry<Integer, Map<ResourceKey, Long>> entry : plan.ingredients().entrySet()) { | ||
final Map<ResourceKey, Long> possibilitiesCopy = new LinkedHashMap<>(entry.getValue()); | ||
ingredients.put(entry.getKey(), possibilitiesCopy); | ||
} | ||
} | ||
|
||
abstract boolean step(MutableResourceList internalStorage, ExternalPatternInputSink externalPatternInputSink); | ||
|
||
abstract long interceptInsertion(ResourceKey resource, long amount); | ||
|
||
protected final boolean extractAll(final ResourceList inputs, | ||
final MutableResourceList internalStorage, | ||
final Action action) { | ||
for (final ResourceKey inputResource : inputs.getAll()) { | ||
final long inputAmount = inputs.get(inputResource); | ||
final long inInternalStorage = internalStorage.get(inputResource); | ||
if (inInternalStorage < inputAmount) { | ||
return false; | ||
} | ||
if (action == Action.EXECUTE) { | ||
internalStorage.remove(inputResource, inputAmount); | ||
LOGGER.debug("Extracted {}x {} from internal storage", inputAmount, inputResource); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
protected final ResourceList calculateIterationInputs(final Action action) { | ||
final MutableResourceList iterationInputs = MutableResourceListImpl.create(); | ||
for (final Map.Entry<Integer, Map<ResourceKey, Long>> ingredient : ingredients.entrySet()) { | ||
final int ingredientIndex = ingredient.getKey(); | ||
if (!calculateIterationInputs(ingredient, ingredientIndex, iterationInputs, action)) { | ||
throw new IllegalStateException(); | ||
} | ||
} | ||
return iterationInputs; | ||
} | ||
|
||
private boolean calculateIterationInputs(final Map.Entry<Integer, Map<ResourceKey, Long>> ingredient, | ||
final int ingredientIndex, | ||
final MutableResourceList iterationInputs, | ||
final Action action) { | ||
long needed = pattern.ingredients().get(ingredientIndex).amount(); | ||
for (final Map.Entry<ResourceKey, Long> possibility : ingredient.getValue().entrySet()) { | ||
final long available = Math.min(needed, possibility.getValue()); | ||
if (available == 0) { | ||
continue; | ||
} | ||
iterationInputs.add(possibility.getKey(), available); | ||
if (action == Action.EXECUTE) { | ||
possibility.setValue(possibility.getValue() - available); | ||
} | ||
needed -= available; | ||
if (needed == 0) { | ||
break; | ||
} | ||
} | ||
return needed == 0; | ||
} | ||
} |
Oops, something went wrong.