Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distillery recipe changes #14

Merged
merged 4 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/recipes/RecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public class RecipeMaps {
*/

@ZenProperty
public static final RecipeMap<IntCircuitRecipeBuilder> DISTILLERY_RECIPES = new RecipeMap<>("distillery", 1, 1, 0, 0, 1, 1, 1, 1, new IntCircuitRecipeBuilder())
public static final RecipeMap<IntCircuitRecipeBuilder> DISTILLERY_RECIPES = new RecipeMap<>("distillery", 1, 1, 0, 1, 1, 1, 1, 1, new IntCircuitRecipeBuilder())
.setProgressBar(GuiTextures.PROGRESS_BAR_ARROW_MULTIPLE, MoveType.HORIZONTAL);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UniversalDistillationRecipeBuilder> {
Expand All @@ -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();
Expand All @@ -44,4 +79,29 @@ public ValidationResult<Recipe> 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;
}

}
32 changes: 32 additions & 0 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down