Skip to content

Commit

Permalink
move static helper code to separate Helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
WaitingIdly committed Jul 22, 2024
1 parent 28e6dee commit 3d41c9b
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.alloySmelter.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.assemblingMachine.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void validate(GroovyLog.Msg msg) {
public @Nullable BlastFurnaceRecipe register() {
if (!validate()) return null;
ItemStack output2 = output.size() >= 2 ? output.get(1) : null;
BlastFurnaceRecipe recipe = new BlastFurnaceRecipe(TechReborn.getStackFromIIngredient(input.get(0)), input.size() == 2 ? TechReborn.getStackFromIIngredient(input.get(1)) : null, output.get(0), output2, time, perTick, neededHeat);
BlastFurnaceRecipe recipe = new BlastFurnaceRecipe(Helper.getStackFromIIngredient(input.get(0)), input.size() == 2 ? Helper.getStackFromIIngredient(input.get(1)) : null, output.get(0), output2, time, perTick, neededHeat);
ModSupport.TECH_REBORN.get().blastFurnace.add(recipe);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.centrifuge.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.chemicalReactor.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.compressor.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void validate(GroovyLog.Msg msg) {
ItemStack output2 = output.size() >= 2 ? output.get(1) : null;
ItemStack output3 = output.size() >= 3 ? output.get(2) : null;
ItemStack output4 = output.size() >= 4 ? output.get(3) : null;
DistillationTowerRecipe recipe = new DistillationTowerRecipe(TechReborn.getStackFromIIngredient(input.get(0)), input.size() >= 2 ? TechReborn.getStackFromIIngredient(input.get(1)) : null, output.get(0), output2, output3, output4, time, perTick, oreDict);
DistillationTowerRecipe recipe = new DistillationTowerRecipe(Helper.getStackFromIIngredient(input.get(0)), input.size() >= 2 ? Helper.getStackFromIIngredient(input.get(1)) : null, output.get(0), output2, output3, output4, time, perTick, oreDict);
ModSupport.TECH_REBORN.get().distillationTower.add(recipe);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.extractor.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.grinder.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.cleanroommc.groovyscript.compat.mods.techreborn;

import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import reborncore.api.praescriptum.ingredients.input.FluidStackInputIngredient;
import reborncore.api.praescriptum.ingredients.input.InputIngredient;
import reborncore.api.praescriptum.ingredients.input.ItemStackInputIngredient;
import reborncore.api.praescriptum.ingredients.input.OreDictionaryInputIngredient;

public class Helper {

public static ItemStack getStackFromIIngredient(IIngredient ingredient) {
if (ingredient instanceof OreDictIngredient oreDictIngredient) {
if (OreDictionary.doesOreNameExist(oreDictIngredient.getOreDict())) {
return OreDictionary.getOres(oreDictIngredient.getOreDict()).get(0).copy();
}
}
if (IngredientHelper.isItem(ingredient)) {
return IngredientHelper.toItemStack(ingredient);
}
if (ingredient.getMatchingStacks().length > 0) return ingredient.getMatchingStacks()[0];
return ItemStack.EMPTY;
}

public static InputIngredient<?> toInputIngredient(IIngredient ingredient) {
if (ingredient instanceof OreDictIngredient ore) return OreDictionaryInputIngredient.of(ore.getOreDict(), ore.getAmount());
if (ingredient instanceof FluidStack fluid) return FluidStackInputIngredient.of(fluid);
if (IngredientHelper.isItem(ingredient)) return ItemStackInputIngredient.of(IngredientHelper.toItemStack(ingredient));
return ItemStackInputIngredient.of(ItemStack.EMPTY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void validate(GroovyLog.Msg msg) {
public @Nullable ImplosionCompressorRecipe register() {
if (!validate()) return null;
ItemStack output2 = output.size() >= 2 ? output.get(1) : null;
ImplosionCompressorRecipe recipe = new ImplosionCompressorRecipe(TechReborn.getStackFromIIngredient(input.get(0)), input.size() >= 2 ? TechReborn.getStackFromIIngredient(input.get(1)) : null, output.get(0), output2, time, perTick);
ImplosionCompressorRecipe recipe = new ImplosionCompressorRecipe(Helper.getStackFromIIngredient(input.get(0)), input.size() >= 2 ? Helper.getStackFromIIngredient(input.get(1)) : null, output.get(0), output2, time, perTick);
ModSupport.TECH_REBORN.get().implosionCompressor.add(recipe);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void validate(GroovyLog.Msg msg) {
ItemStack output2 = output.size() >= 2 ? output.get(1) : null;
ItemStack output3 = output.size() >= 3 ? output.get(2) : null;
ItemStack output4 = output.size() >= 4 ? output.get(3) : null;
IndustrialElectrolyzerRecipe recipe = new IndustrialElectrolyzerRecipe(TechReborn.getStackFromIIngredient(input.get(0)), TechReborn.getStackFromIIngredient(input.get(1)), output.get(0), output2, output3, output4, time, perTick, oreDict);
IndustrialElectrolyzerRecipe recipe = new IndustrialElectrolyzerRecipe(Helper.getStackFromIIngredient(input.get(0)), Helper.getStackFromIIngredient(input.get(1)), output.get(0), output2, output3, output4, time, perTick, oreDict);
ModSupport.TECH_REBORN.get().industrialElectrolyzer.add(recipe);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void validate(GroovyLog.Msg msg) {
ItemStack output2 = output.size() >= 2 ? output.get(1) : null;
ItemStack output3 = output.size() >= 3 ? output.get(2) : null;
ItemStack output4 = output.size() >= 4 ? output.get(3) : null;
IndustrialGrinderRecipe recipe = new IndustrialGrinderRecipe(TechReborn.getStackFromIIngredient(input.get(0)), fluidInput.get(0), output.get(0), output2, output3, output4, time, perTick, oreDict);
IndustrialGrinderRecipe recipe = new IndustrialGrinderRecipe(Helper.getStackFromIIngredient(input.get(0)), fluidInput.get(0), output.get(0), output2, output3, output4, time, perTick, oreDict);
ModSupport.TECH_REBORN.get().industrialGrinder.add(recipe);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;
ItemStack output2 = output.size() >= 2 ? output.get(1) : null;
ItemStack output3 = output.size() >= 3 ? output.get(2) : null;
IndustrialSawmillRecipe recipe = new IndustrialSawmillRecipe(TechReborn.getStackFromIIngredient(input.get(0)), fluidInput.get(0), output.get(0), output2, output3, time, perTick, oreDict);
IndustrialSawmillRecipe recipe = new IndustrialSawmillRecipe(Helper.getStackFromIIngredient(input.get(0)), fluidInput.get(0), output.get(0), output2, output3, time, perTick, oreDict);
ModSupport.TECH_REBORN.get().industrialSawmill.add(recipe);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.plateBendingMachine.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.solidCanningMachine.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
package com.cleanroommc.groovyscript.compat.mods.techreborn;

import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import reborncore.api.praescriptum.ingredients.input.FluidStackInputIngredient;
import reborncore.api.praescriptum.ingredients.input.InputIngredient;
import reborncore.api.praescriptum.ingredients.input.ItemStackInputIngredient;
import reborncore.api.praescriptum.ingredients.input.OreDictionaryInputIngredient;

public class TechReborn extends ModPropertyContainer {

Expand Down Expand Up @@ -70,24 +60,4 @@ public TechReborn() {
addRegistry(wireMill);
}

public static ItemStack getStackFromIIngredient(IIngredient ingredient) {
if (ingredient instanceof OreDictIngredient oreDictIngredient) {
if (OreDictionary.doesOreNameExist(oreDictIngredient.getOreDict())) {
return OreDictionary.getOres(oreDictIngredient.getOreDict()).get(0).copy();
}
}
if (IngredientHelper.isItem(ingredient)) {
return IngredientHelper.toItemStack(ingredient);
}
if (ingredient.getMatchingStacks().length > 0) return ingredient.getMatchingStacks()[0];
return ItemStack.EMPTY;
}

public static InputIngredient<?> toInputIngredient(IIngredient ingredient) {
if (ingredient instanceof OreDictIngredient ore) return OreDictionaryInputIngredient.of(ore.getOreDict(), ore.getAmount());
if (ingredient instanceof FluidStack fluid) return FluidStackInputIngredient.of(fluid);
if (IngredientHelper.isItem(ingredient)) return ItemStackInputIngredient.of(IngredientHelper.toItemStack(ingredient));
return ItemStackInputIngredient.of(ItemStack.EMPTY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void validate(GroovyLog.Msg msg) {
@RecipeBuilderRegistrationMethod
public @Nullable VacuumFreezerRecipe register() {
if (!validate()) return null;
VacuumFreezerRecipe recipe = new VacuumFreezerRecipe(TechReborn.getStackFromIIngredient(input.get(0)), output.get(0), time, perTick);
VacuumFreezerRecipe recipe = new VacuumFreezerRecipe(Helper.getStackFromIIngredient(input.get(0)), output.get(0), time, perTick);
ModSupport.TECH_REBORN.get().vacuumFreezer.add(recipe);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void validate(GroovyLog.Msg msg) {
if (!validate()) return null;

Recipe recipe = Recipes.wireMill.createRecipe();
recipe.withInput(input.stream().map(TechReborn::toInputIngredient).collect(Collectors.toList()));
recipe.withInput(input.stream().map(Helper::toInputIngredient).collect(Collectors.toList()));
output.forEach(recipe::withOutput);
recipe.withEnergyCostPerTick(perTick);
recipe.withOperationDuration(time);
Expand Down

0 comments on commit 3d41c9b

Please sign in to comment.