diff --git a/src/main/java/gregtech/api/recipes/RecipeMaps.java b/src/main/java/gregtech/api/recipes/RecipeMaps.java index 4e446b68e56..740262300c1 100644 --- a/src/main/java/gregtech/api/recipes/RecipeMaps.java +++ b/src/main/java/gregtech/api/recipes/RecipeMaps.java @@ -270,7 +270,7 @@ public class RecipeMaps { */ @ZenProperty - public static final RecipeMap DISTILLERY_RECIPES = new RecipeMap<>("distillery", 1, 1, 0, 0, 1, 1, 1, 1, new IntCircuitRecipeBuilder()) + public static final RecipeMap DISTILLERY_RECIPES = new RecipeMap<>("distillery", 1, 1, 0, 1, 1, 1, 1, 1, new IntCircuitRecipeBuilder()) .setProgressBar(GuiTextures.PROGRESS_BAR_ARROW_MULTIPLE, MoveType.HORIZONTAL); /** diff --git a/src/main/java/gregtech/api/recipes/builders/UniversalDistillationRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/UniversalDistillationRecipeBuilder.java index 0e4ea2dfaa3..124421e720c 100644 --- a/src/main/java/gregtech/api/recipes/builders/UniversalDistillationRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/UniversalDistillationRecipeBuilder.java @@ -4,7 +4,9 @@ import gregtech.api.recipes.RecipeBuilder; import gregtech.api.recipes.RecipeMap; import gregtech.api.recipes.RecipeMaps; +import gregtech.api.util.GTUtility; import gregtech.api.util.ValidationResult; +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; public class UniversalDistillationRecipeBuilder extends RecipeBuilder { @@ -27,13 +29,46 @@ public UniversalDistillationRecipeBuilder copy() { @Override public void buildAndRegister() { - IntCircuitRecipeBuilder builder = RecipeMaps.DISTILLERY_RECIPES.recipeBuilder() - .fluidInputs(this.fluidInputs.toArray(new FluidStack[0])) - .duration(this.duration * 2) - .EUt(this.EUt / 4); - for (int i = 0; i < fluidOutputs.size(); i++) { - builder.copy().circuitMeta(i).fluidOutputs(this.fluidOutputs.get(i)).buildAndRegister(); + IntCircuitRecipeBuilder builder = RecipeMaps.DISTILLERY_RECIPES.recipeBuilder().copy().EUt(this.EUt / 4).circuitMeta(i + 1); + + int ratio = getRatioForDistillery(this.fluidInputs.get(0), this.fluidOutputs.get(i), this.outputs.size() > 0 ? this.outputs.get(0) : null); + + int recipeDuration = this.EUt > 16 ? (int) (this.duration * 2.8f) : this.duration * 2; + + boolean shouldDivide = ratio != 1; + + boolean fluidsDivisible = isFluidStackDivisibleForDistillery(this.fluidInputs.get(0), ratio) && + isFluidStackDivisibleForDistillery(this.fluidOutputs.get(i), ratio); + + FluidStack dividedInputFluid = new FluidStack(this.fluidInputs.get(0), Math.max(1, this.fluidInputs.get(0).amount / ratio)); + FluidStack dividedOutputFluid = new FluidStack(this.fluidOutputs.get(i), Math.max(1, this.fluidOutputs.get(i).amount / ratio)); + + if (shouldDivide && fluidsDivisible) + builder.fluidInputs(dividedInputFluid) + .fluidOutputs(dividedOutputFluid) + .duration(recipeDuration / ratio); + + else if (!shouldDivide) { + builder.fluidInputs(this.fluidInputs.get(0)) + .fluidOutputs(this.fluidOutputs.get(i)) + .outputs(this.outputs) + .duration(recipeDuration) + .buildAndRegister(); + continue; + } + + if (this.outputs.size() > 0) { + boolean itemsDivisible = GTUtility.isItemStackCountDivisible(this.outputs.get(0), ratio) && fluidsDivisible; + + if (fluidsDivisible && itemsDivisible) { + ItemStack stack = this.outputs.get(0).copy(); + stack.setCount(stack.getCount() / ratio); + + builder.outputs(stack); + } + } + builder.buildAndRegister(); } super.buildAndRegister(); @@ -44,4 +79,29 @@ public ValidationResult build() { new Recipe(inputs, outputs, chancedOutputs, fluidInputs, fluidOutputs, duration, EUt, hidden)); } + private int getRatioForDistillery(FluidStack fluidInput, FluidStack fluidOutput, ItemStack output) { + int[] divisors = new int[]{2, 5, 10, 25, 50}; + int ratio = -1; + + for (int divisor : divisors) { + + if (!(isFluidStackDivisibleForDistillery(fluidInput, divisor))) + continue; + + if (!(isFluidStackDivisibleForDistillery(fluidOutput, divisor))) + continue; + + if (output != null && !(GTUtility.isItemStackCountDivisible(output, divisor))) + continue; + + ratio = divisor; + } + + return Math.max(1, ratio); + } + + private boolean isFluidStackDivisibleForDistillery(FluidStack fluidStack, int divisor) { + return GTUtility.isFluidStackAmountDivisible(fluidStack, divisor) && fluidStack.amount / divisor >= 25; + } + } diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index cfd3c0be4ba..9c8e42fef22 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -865,4 +865,36 @@ public static boolean isCoverBehaviorItem(ItemStack itemStack) { } return false; } + + public static int getDecompositionReductionRatio(FluidStack fluidInput, FluidStack fluidOutput, ItemStack input, ItemStack output) { + int[] divisors = new int[]{2, 5, 10, 25, 50}; + int ratio = -1; + + for (int divisor : divisors) { + + if (!(isFluidStackAmountDivisible(fluidInput, divisor))) + continue; + + if (!(isFluidStackAmountDivisible(fluidOutput, divisor))) + continue; + + if (input != null && !(GTUtility.isItemStackCountDivisible(input, divisor))) + continue; + + if (output != null && !(GTUtility.isItemStackCountDivisible(output, divisor))) + continue; + + ratio = divisor; + } + + return Math.max(1, ratio); + } + + public static boolean isFluidStackAmountDivisible(FluidStack fluidStack, int divisor) { + return fluidStack.amount % divisor == 0 && fluidStack.amount % divisor != fluidStack.amount && fluidStack.amount / divisor != 0; + } + + public static boolean isItemStackCountDivisible(ItemStack itemStack, int divisor) { + return itemStack.getCount() % divisor == 0 && itemStack.getCount() % divisor != itemStack.getCount() && itemStack.getCount() / divisor != 0; + } } diff --git a/src/main/java/gregtech/loaders/recipe/chemistry/DistillationRecipes.java b/src/main/java/gregtech/loaders/recipe/chemistry/DistillationRecipes.java index 4e2c63c1ae6..1ed0239ff55 100644 --- a/src/main/java/gregtech/loaders/recipe/chemistry/DistillationRecipes.java +++ b/src/main/java/gregtech/loaders/recipe/chemistry/DistillationRecipes.java @@ -367,19 +367,19 @@ public static void init() { .duration(32).EUt(24).buildAndRegister(); DISTILLERY_RECIPES.recipeBuilder() - .circuitMeta(4) + .circuitMeta(5) .fluidInputs(OilLight.getFluid(300)) .fluidOutputs(Oil.getFluid(100)) .duration(16).EUt(24).buildAndRegister(); DISTILLERY_RECIPES.recipeBuilder() - .circuitMeta(4) + .circuitMeta(5) .fluidInputs(OilMedium.getFluid(200)) .fluidOutputs(Oil.getFluid(100)) .duration(16).EUt(24).buildAndRegister(); DISTILLERY_RECIPES.recipeBuilder() - .circuitMeta(4) + .circuitMeta(5) .fluidInputs(OilHeavy.getFluid(100)) .fluidOutputs(Oil.getFluid(100)) .duration(16).EUt(24).buildAndRegister();