Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Update chemplant logic to catch up with new parallel helper logic
Browse files Browse the repository at this point in the history
  • Loading branch information
miozune committed Nov 14, 2023
1 parent 825151f commit c008aa8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.44.79:dev')
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.44.80:dev')
api("com.github.GTNewHorizons:bartworks:0.8.10:dev")

implementation('curse.maven:cofh-core-69162:2388751')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -539,7 +539,7 @@ public void receiveClientEvent(byte aEventID, byte aValue) {
}
}

private void damageCatalyst(ItemStack aStack, int minParallel) {
private void damageCatalyst(@Nonnull ItemStack aStack, int minParallel) {
// Awakened Draconium Coils with Tungstensteel Pipe Casings (or above) no longer consume catalysts.
if (!isCatalystDamageable()) return;
for (int i = 0; i < minParallel; i++) {
Expand All @@ -564,7 +564,6 @@ protected ProcessingLogic createProcessingLogic() {
return new ProcessingLogic() {

ItemStack catalystRecipe;
int maxParallelCatalyst;

@NotNull
@Override
Expand All @@ -591,37 +590,24 @@ protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) {
}

// checks if it has enough catalyst durability
maxParallelCatalyst = maxParallel;
if (catalystRecipe != null) {
maxParallelCatalyst = getCatalysts(inputItems, catalystRecipe, maxParallel);
maxParallel = getParallelLimitedByCatalyst(inputItems, catalystRecipe, maxParallel);
}
maxParallel = Math.min(maxParallel, maxParallelCatalyst);
return CheckRecipeResultRegistry.SUCCESSFUL;
}

@NotNull
@Override
protected GT_ParallelHelper createParallelHelper(@NotNull GT_Recipe recipe) {
return new GT_ParallelHelper() {

@Override
protected boolean tryConsumeRecipeInputs(GT_Recipe recipe, FluidStack[] fluids, ItemStack[] items,
int minParallel) {
if (catalystRecipe != null && getDamage(catalystRecipe) >= getMaxCatalystDurability()) {
return false;
}
boolean hasInputs = super.tryConsumeRecipeInputs(recipe, fluids, items, minParallel);
if (hasInputs && catalystRecipe != null) {
damageCatalyst(catalystRecipe, minParallel);
}
return hasInputs;
}
}.setRecipe(recipe).setItemInputs(inputItems).setFluidInputs(inputFluids)
.setAvailableEUt(availableVoltage * availableAmperage)
.setMachine(machine, protectItems, protectFluids)
.setRecipeLocked(recipeLockableMachine, isRecipeLocked).setMaxParallel(maxParallel)
.setEUtModifier(euModifier).enableBatchMode(batchSize).setConsumption(true)
.setOutputCalculation(true);
return super.createParallelHelper(recipe)
.setInputConsumer((recipeToConsume, amountMultiplier, aFluidInputs, aInputs) -> {
// Correct parallel is already calculated by ProcessingLogic#validateRecipe,
// so we don't need to set MaxParallelCalculator
recipeToConsume.consumeInput(amountMultiplier, aFluidInputs, aInputs);
if (catalystRecipe != null) {
damageCatalyst(catalystRecipe, amountMultiplier);
}
});
}
}.setMaxParallelSupplier(this::getMaxParallelRecipes);
}
Expand All @@ -641,18 +627,17 @@ public void updateSlots() {
}
}

private int getCatalysts(ItemStack[] aItemInputs, ItemStack aRecipeCatalyst, int aMaxParallel) {
private int getParallelLimitedByCatalyst(ItemStack[] aItemInputs, ItemStack aRecipeCatalyst, int aMaxParallel) {
if (!isCatalystDamageable()) {
return getMaxParallelRecipes();
return aMaxParallel;
}
int allowedParallel = 0;
for (final ItemStack aInput : aItemInputs) {
if (aRecipeCatalyst.isItemEqual(aInput)) {
int aDurabilityRemaining = getMaxCatalystDurability() - getDamage(aInput);
return Math.min(aMaxParallel, aDurabilityRemaining);
}
}
return allowedParallel;
return 0;
}

private ItemStack findCatalyst(ItemStack[] aItemInputs, ItemStack[] aRecipeInputs) {
Expand All @@ -672,11 +657,11 @@ private ItemStack findCatalyst(ItemStack[] aItemInputs, ItemStack[] aRecipeInput
return null;
}

private int getDamage(ItemStack aStack) {
private int getDamage(@Nonnull ItemStack aStack) {
return ItemGenericChemBase.getCatalystDamage(aStack);
}

private void setDamage(ItemStack aStack, int aAmount) {
private void setDamage(@Nonnull ItemStack aStack, int aAmount) {
ItemGenericChemBase.setCatalystDamage(aStack, aAmount);
}

Expand Down

0 comments on commit c008aa8

Please sign in to comment.