Skip to content

Commit d3c29aa

Browse files
committed
Merge remote-tracking branch 'origin/master-1.21-lts' into master-1.21
2 parents dee86d7 + 1ca732a commit d3c29aa

10 files changed

Lines changed: 482 additions & 36 deletions

File tree

.github/workflows/copilot-setup-steps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ jobs:
4545
- name: 'Build'
4646
run: ./gradlew build --no-daemon
4747
env:
48-
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
49-
MAVEN_KEY: ${{ secrets.MAVEN_KEY }}
48+
MAVEN_USERNAME: ${{ github.actor }}
49+
MAVEN_KEY: ${{ secrets.GITHUB_TOKEN }}
5050
GITHUB_USER: ${{ github.actor }}
5151
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5252
- name: 'Warmup for game test server'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ repo/*
1919
out/*
2020
keystore.jks
2121
.idea
22+
logs/
2223

2324
# Ignore mac-specific file(s)
2425
.DS_Store

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'net.darkhax.curseforgegradle' version '1.1.28'
44
id 'com.github.kt3k.coveralls' version '2.12.0'
55
id 'com.diffplug.spotless' version '6.25.0'
6-
id 'com.github.johnrengelman.shadow' version '7.1.2'
6+
id 'com.gradleup.shadow' version '8.3.8'
77
id 'com.modrinth.minotaur' version '2.+'
88
}
99

src/main/java/org/cyclops/integratedcrafting/core/CraftingHelpers.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,17 @@ public static <T, M> List<T> getIngredientRecipeInputs(IIngredientComponentStora
983983
IngredientCollectionPrototypeMap<T, M> simulatedExtractionMemory,
984984
IIngredientCollectionMutable<T, M> extractionMemoryReusable,
985985
boolean collectMissingIngredients, long recipeOutputQuantity) {
986+
return getIngredientRecipeInputs(storage, ingredientComponent, recipe, simulate, simulatedExtractionMemory,
987+
extractionMemoryReusable, collectMissingIngredients, recipeOutputQuantity, false);
988+
}
989+
990+
public static <T, M> Pair<List<T>, MissingIngredients<T, M>>
991+
getIngredientRecipeInputs(IIngredientComponentStorage<T, M> storage, IngredientComponent<T, M> ingredientComponent,
992+
IRecipeDefinition recipe, boolean simulate,
993+
IngredientCollectionPrototypeMap<T, M> simulatedExtractionMemory,
994+
IIngredientCollectionMutable<T, M> extractionMemoryReusable,
995+
boolean collectMissingIngredients, long recipeOutputQuantity,
996+
boolean skipReusableIngredients) {
986997
IIngredientMatcher<T, M> matcher = ingredientComponent.getMatcher();
987998

988999
// Quickly return if the storage is empty
@@ -1017,6 +1028,15 @@ public static <T, M> List<T> getIngredientRecipeInputs(IIngredientComponentStora
10171028
collectMissingIngredients ? Lists.newArrayList() : null;
10181029
for (int inputIndex = 0; inputIndex < inputAlternativePrototypes.size(); inputIndex++) {
10191030
IPrototypedIngredientAlternatives<T, M> inputPrototypes = inputAlternativePrototypes.get(inputIndex);
1031+
1032+
// If reusable ingredients should be skipped, treat them as empty (not needed yet).
1033+
// This is used when a job has dependencies, so that reusable ingredients remain available
1034+
// for other jobs to use, and will be extracted lazily in the update loop.
1035+
if (skipReusableIngredients && recipe.isInputReusable(ingredientComponent, inputIndex)) {
1036+
inputInstances.add(matcher.getEmptyInstance());
1037+
continue;
1038+
}
1039+
10201040
T firstInputInstance = null;
10211041
boolean setFirstInputInstance = false;
10221042
T inputInstance = null;
@@ -1311,6 +1331,15 @@ public static IMixedIngredients getRecipeInputsFromCraftingJobBuffer(CraftingJob
13111331
Map<IngredientComponent<?, ?>, IngredientCollectionPrototypeMap<?, ?>> simulatedExtractionMemories,
13121332
Map<IngredientComponent<?, ?>, IIngredientCollectionMutable<?, ?>> extractionMemoriesReusable,
13131333
boolean collectMissingIngredients, long recipeOutputQuantity) {
1334+
return getRecipeInputs(storageGetter, recipe, simulate, simulatedExtractionMemories, extractionMemoriesReusable,
1335+
collectMissingIngredients, recipeOutputQuantity, false);
1336+
}
1337+
1338+
public static Pair<Map<IngredientComponent<?, ?>, List<?>>, Map<IngredientComponent<?, ?>, MissingIngredients<?, ?>>>
1339+
getRecipeInputs(Function<IngredientComponent<?, ?>, IIngredientComponentStorage> storageGetter, IRecipeDefinition recipe, boolean simulate,
1340+
Map<IngredientComponent<?, ?>, IngredientCollectionPrototypeMap<?, ?>> simulatedExtractionMemories,
1341+
Map<IngredientComponent<?, ?>, IIngredientCollectionMutable<?, ?>> extractionMemoriesReusable,
1342+
boolean collectMissingIngredients, long recipeOutputQuantity, boolean skipReusableIngredients) {
13141343
// Determine available and missing ingredients
13151344
Map<IngredientComponent<?, ?>, List<?>> ingredientsAvailable = Maps.newIdentityHashMap();
13161345
Map<IngredientComponent<?, ?>, MissingIngredients<?, ?>> ingredientsMissing = Maps.newIdentityHashMap();
@@ -1328,7 +1357,7 @@ public static IMixedIngredients getRecipeInputsFromCraftingJobBuffer(CraftingJob
13281357
}
13291358
Pair<List<?>, MissingIngredients<?, ?>> subIngredients = getIngredientRecipeInputs(storage,
13301359
(IngredientComponent) ingredientComponent, recipe, simulate, simulatedExtractionMemory, extractionMemoryReusable,
1331-
collectMissingIngredients, recipeOutputQuantity);
1360+
collectMissingIngredients, recipeOutputQuantity, skipReusableIngredients);
13321361
List<?> subIngredientAvailable = subIngredients.getLeft();
13331362
MissingIngredients<?, ?> subIngredientsMissing = subIngredients.getRight();
13341363
if (subIngredientAvailable == null && !collectMissingIngredients) {

src/main/java/org/cyclops/integratedcrafting/core/CraftingJobHandler.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ public void fillCraftingJobBufferFromStorage(CraftingJob craftingJob, Function<I
244244
throw new IllegalStateException("Re-filling a non-empty crafting job buffer is illegal");
245245
}
246246
// Determine the ingredients to extract. We can not reuse the ingredientsStorage value from the crafting job, as this may have been modified due to job splitting.
247-
Pair<Map<IngredientComponent<?, ?>, List<?>>, Map<IngredientComponent<?, ?>, MissingIngredients<?, ?>>> inputResult = CraftingHelpers.getRecipeInputs(storageGetter, craftingJob.getRecipe(), false, Maps.newIdentityHashMap(), Maps.newIdentityHashMap(), true, craftingJob.getAmount());
247+
// If this job has dependencies, skip reusable ingredients so that they remain available for other jobs.
248+
// They will be lazily extracted in the update loop once the dependencies have finished.
249+
boolean skipReusableIngredients = !craftingJob.getDependencyCraftingJobs().isEmpty();
250+
Pair<Map<IngredientComponent<?, ?>, List<?>>, Map<IngredientComponent<?, ?>, MissingIngredients<?, ?>>> inputResult = CraftingHelpers.getRecipeInputs(storageGetter, craftingJob.getRecipe(), false, Maps.newIdentityHashMap(), Maps.newIdentityHashMap(), true, craftingJob.getAmount(), skipReusableIngredients);
248251
IMixedIngredients buffer = new MixedIngredients(inputResult.getLeft());
249252
craftingJob.setIngredientsStorageBuffer(CraftingHelpers.compressMixedIngredients(buffer));
250253
craftingJob.setLastMissingIngredients(inputResult.getRight());
@@ -457,35 +460,33 @@ public void update(INetwork network, int channel, PartPos targetPos) {
457460
// trigger a crafting job for them if no job is running yet.
458461
// This special case is needed because reusable ingredients are usually durability-based,
459462
// and may be consumed _during_ a bulk crafting job.
460-
if (pendingCraftingJob.getLastMissingIngredients().isEmpty()) {
461-
for (IngredientComponent<?, ?> component : inputs.getRight().keySet()) {
462-
MissingIngredients<?, ?> missingIngredients = inputs.getRight().get(component);
463-
for (MissingIngredients.Element<?, ?> element : missingIngredients.getElements()) {
464-
if (element.isInputReusable()) {
465-
IIngredientComponentStorage storage = CraftingHelpers.getNetworkStorage(network, channel, component, true);
466-
for (MissingIngredients.PrototypedWithRequested alternative : element.getAlternatives()) {
467-
// First check if we can extract it from storage.
468-
Object extractedFromStorage = storage.extract(alternative.getRequestedPrototype().getPrototype(), alternative.getRequestedPrototype().getCondition(), false);
469-
if (!((IIngredientMatcher) component.getMatcher()).isEmpty(extractedFromStorage)) {
470-
pendingCraftingJob.addToIngredientsStorageBuffer((IngredientComponent<? super Object, ? extends Object>) component, extractedFromStorage);
471-
break;
472-
}
473-
474-
// Try to start crafting jobs for each alternative until one of them succeeds.
475-
if (CraftingHelpers.isCrafting(craftingNetwork, channel,
476-
alternative.getRequestedPrototype().getComponent(), alternative.getRequestedPrototype().getPrototype(), alternative.getRequestedPrototype().getCondition())) {
477-
// Break loop if we have found an existing job for our dependency
478-
// This may occur if a crafting job was triggered in a parallelized job
479-
break;
480-
}
481-
CraftingJob craftingJob = CraftingHelpers.calculateAndScheduleCraftingJob(network, channel,
482-
alternative.getRequestedPrototype().getComponent(), alternative.getRequestedPrototype().getPrototype(), alternative.getRequestedPrototype().getCondition(), true, true,
483-
CraftingHelpers.getGlobalCraftingJobIdentifier(), null);
484-
if (craftingJob != null) {
485-
pendingCraftingJob.addDependency(craftingJob);
486-
// Break loop once we have found a valid job
487-
break;
488-
}
463+
for (IngredientComponent<?, ?> component : inputs.getRight().keySet()) {
464+
MissingIngredients<?, ?> missingIngredients = inputs.getRight().get(component);
465+
for (MissingIngredients.Element<?, ?> element : missingIngredients.getElements()) {
466+
if (element.isInputReusable()) {
467+
IIngredientComponentStorage storage = CraftingHelpers.getNetworkStorage(network, channel, component, true);
468+
for (MissingIngredients.PrototypedWithRequested alternative : element.getAlternatives()) {
469+
// First check if we can extract it from storage.
470+
Object extractedFromStorage = storage.extract(alternative.getRequestedPrototype().getPrototype(), alternative.getRequestedPrototype().getCondition(), false);
471+
if (!((IIngredientMatcher) component.getMatcher()).isEmpty(extractedFromStorage)) {
472+
pendingCraftingJob.addToIngredientsStorageBuffer((IngredientComponent<? super Object, ? extends Object>) component, extractedFromStorage);
473+
break;
474+
}
475+
476+
// Try to start crafting jobs for each alternative until one of them succeeds.
477+
if (CraftingHelpers.isCrafting(craftingNetwork, channel,
478+
alternative.getRequestedPrototype().getComponent(), alternative.getRequestedPrototype().getPrototype(), alternative.getRequestedPrototype().getCondition())) {
479+
// Break loop if we have found an existing job for our dependency
480+
// This may occur if a crafting job was triggered in a parallelized job
481+
break;
482+
}
483+
CraftingJob craftingJob = CraftingHelpers.calculateAndScheduleCraftingJob(network, channel,
484+
alternative.getRequestedPrototype().getComponent(), alternative.getRequestedPrototype().getPrototype(), alternative.getRequestedPrototype().getCondition(), true, true,
485+
CraftingHelpers.getGlobalCraftingJobIdentifier(), null);
486+
if (craftingJob != null) {
487+
pendingCraftingJob.addDependency(craftingJob);
488+
// Break loop once we have found a valid job
489+
break;
489490
}
490491
}
491492
}

0 commit comments

Comments
 (0)