diff --git a/dependencies.gradle b/dependencies.gradle index 3032a3425..0644fa3c2 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -28,6 +28,7 @@ // Sorted by alphabetical name of the `project.debug_[this]` value final def mod_dependencies = [ 'actually-additions-228404:3117927' : [project.debug_actually_additions], + 'additionalenchantedminer-282837:3851282' : [project.debug_additional_enchanted_miner], 'advancedmortars-283777:2780626' : [project.debug_adv_mortars], 'advanced-rocketry-236542:4671856' : [project.debug_advanced_rocketry], 'libvulpes-236541:3801015' : [project.debug_advanced_rocketry], diff --git a/examples/postInit/quarryplus.groovy b/examples/postInit/quarryplus.groovy new file mode 100644 index 000000000..e52b55f9c --- /dev/null +++ b/examples/postInit/quarryplus.groovy @@ -0,0 +1,19 @@ + +// Auto generated groovyscript example file +// MODS_LOADED: quarryplus + +log.info 'mod \'quarryplus\' detected, running script' + +// Work bench: +// Workbench for crafting items using electricity. + +mods.quarryplus.work_bench_plus.removeByOutput(item('quarryplus:quarry')) +// mods.quarryplus.work_bench_plus.removeAll() + +mods.quarryplus.work_bench_plus.recipeBuilder() + .output(item('minecraft:nether_star')) + .input(item('minecraft:diamond'),item('minecraft:gold_ingot')) + .energy(10000) + .register() + + diff --git a/gradle.properties b/gradle.properties index b73a02b66..d3731a005 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,6 +14,7 @@ debug_disable_cache = false # SECTION: debug mod compat debug_actually_additions = false +debug_additional_enchanted_miner = false debug_adv_mortars = false debug_advanced_rocketry = false debug_aether = false diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java index 650a3798d..e7aa6e988 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java @@ -4,6 +4,7 @@ import com.cleanroommc.groovyscript.api.GroovyBlacklist; import com.cleanroommc.groovyscript.api.GroovyPlugin; import com.cleanroommc.groovyscript.compat.mods.actuallyadditions.ActuallyAdditions; +import com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer.AdditionalEnchantedMiner; import com.cleanroommc.groovyscript.compat.mods.advancedmortars.AdvancedMortars; import com.cleanroommc.groovyscript.compat.mods.advancedrocketry.AdvancedRocketry; import com.cleanroommc.groovyscript.compat.mods.aetherlegacy.Aether; @@ -83,6 +84,7 @@ public class ModSupport { public static final ModSupport INSTANCE = new ModSupport(); // Just for Binding purposes public static final GroovyContainer ACTUALLY_ADDITIONS = new InternalModContainer<>("actuallyadditions", "Actually Additions", ActuallyAdditions::new, "aa"); + public static final GroovyContainer ADDITIONAL_ENCHANTED_MINER = new InternalModContainer<>("quarryplus", "Additional Enchanted Miner", AdditionalEnchantedMiner::new); public static final GroovyContainer ADVANCED_MORTARS = new InternalModContainer<>("advancedmortars", "Advanced Mortars", AdvancedMortars::new); public static final GroovyContainer ADVANCED_ROCKETRY = new InternalModContainer<>("advancedrocketry", "Advanced Rocketry", AdvancedRocketry::new); public static final GroovyContainer AETHER = new InternalModContainer<>("aether_legacy", "Aether Legacy", Aether::new, "aether"); diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/AdditionalEnchantedMiner.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/AdditionalEnchantedMiner.java new file mode 100644 index 000000000..6b26ecc4d --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/AdditionalEnchantedMiner.java @@ -0,0 +1,8 @@ +package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer; + +import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer; + +public class AdditionalEnchantedMiner extends GroovyPropertyContainer { + + public final WorkBenchPlus workBenchPlus = new WorkBenchPlus(); +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/WorkBenchPlus.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/WorkBenchPlus.java new file mode 100644 index 000000000..ed97f8ecc --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/WorkBenchPlus.java @@ -0,0 +1,123 @@ +package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import com.yogpc.qp.recipe.IngredientRecipe; +import com.yogpc.qp.recipe.WorkbenchRecipe; +import com.yogpc.qp.tile.ItemDamage; +import com.yogpc.qp.utils.IngredientWithCount; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.jetbrains.annotations.Nullable; +import scala.collection.JavaConversions; +import scala.collection.JavaConverters; +import scala.collection.Seq; +import scala.collection.SeqLike; +import scala.collection.convert.Decorators; +import scala.collection.immutable.Map; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +@RegistryDescription +public class WorkBenchPlus extends VirtualizedRegistry { + + @Override + public void onReload() { + removeScripted().forEach(recipe -> WorkbenchRecipe.removeRecipe(recipe.location())); + restoreFromBackup().forEach(recipe -> WorkbenchRecipe.addIngredientRecipe(recipe.location(), recipe.getOutput(), recipe.energy(), recipe.inputs(), recipe.hardCode(), recipe.showInJEI())); + } + + @MethodDescription(example = @Example("item('quarryplus:quarry')")) + public void removeByOutput(ItemStack output) { + ItemDamage itemDamage = ItemDamage.apply(output); + Map recipeMap = WorkbenchRecipe.getRecipeMap(); + Iterable iterable = JavaConversions.asJavaIterable(recipeMap.values()); + iterable.forEach(recipe -> { + if (recipe.key().equals(itemDamage)) { + addBackup(new IngredientRecipe(recipe.location(), recipe.getOutput(), recipe.energy(), recipe.showInJEI(), recipe.inputs(), recipe.hardCode())); + } + }); + WorkbenchRecipe.removeRecipe(ItemDamage.apply(output)); + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + Map recipeMap = WorkbenchRecipe.getRecipeMap(); + Iterable iterableLocation = JavaConversions.asJavaIterable(recipeMap.keys()); + Iterable iterableRecipe = JavaConversions.asJavaIterable(recipeMap.values()); + iterableLocation.forEach( + WorkbenchRecipe::removeRecipe + ); + iterableRecipe.forEach( + recipe -> addBackup(new IngredientRecipe(recipe.location(),recipe.getOutput(),recipe.energy(),recipe.showInJEI(),recipe.inputs(),recipe.hardCode())) + ); + } + + private void add(IngredientRecipe recipe) { + addScripted(recipe); + WorkbenchRecipe.addIngredientRecipe(recipe.location(), recipe.getOutput(), recipe.energy(), recipe.inputs(), recipe.hardCode(), recipe.showInJEI()); + } + + @RecipeBuilderDescription(example = @Example(".output(item('minecraft:nether_star')).input(item('minecraft:diamond'),item('minecraft:gold_ingot')).energy(10000)")) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Property(property = "input", comp = @Comp(gte = 1, lte = 27)) + @Property(property = "output", comp = @Comp(eq = 1)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(gt = 0)) + private double energy; + + @RecipeBuilderMethodDescription + public RecipeBuilder energy(double energy) { + this.energy = energy; + return this; + } + + @Override + public String getRecipeNamePrefix() { + return "additionalenchantedminer_workbenchplus_"; + } + + @Override + public String getErrorMsg() { + return "Error adding Additional Enchanted Miner WorkbenchPlus recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateName(); + validateItems(msg, 1, 27, 1, 1); + msg.add(energy <= 0, "energy must be an integer greater than 0, yet it was {}", energy); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable IngredientRecipe register() { + if (!validate()) return null; + //convert Java List to Scala Seq + List> inputJavaList = input.stream() + .map(i -> { + IngredientWithCount ingredient = new IngredientWithCount(i.toMcIngredient(), i.getAmount()); + return Collections.singletonList(ingredient); + }) + .collect(Collectors.toList()); + Seq> inputScalaList = JavaConverters.asScalaBufferConverter( + inputJavaList.stream() + .map(JavaConverters::asScalaBufferConverter) + .map(Decorators.AsScala::asScala) + .map(SeqLike::toSeq) + .collect(Collectors.toList())).asScala().toSeq(); + IngredientRecipe recipe = new IngredientRecipe(this.name, output.get(0), energy, true, inputScalaList, true); + ModSupport.ADDITIONAL_ENCHANTED_MINER.get().workBenchPlus.add(recipe); + return recipe; + } + } +} diff --git a/src/main/resources/assets/groovyscript/lang/en_us.lang b/src/main/resources/assets/groovyscript/lang/en_us.lang index 6105c243e..a9e26f740 100644 --- a/src/main/resources/assets/groovyscript/lang/en_us.lang +++ b/src/main/resources/assets/groovyscript/lang/en_us.lang @@ -174,6 +174,10 @@ groovyscript.wiki.actuallyadditions.treasure_chest.min.required=less than or equ groovyscript.wiki.actuallyadditions.treasure_chest.max.value=Sets the maximum stack size given when rolled groovyscript.wiki.actuallyadditions.treasure_chest.max.required=greater than or equal to the size of min +#Additional Enchanted Miner +groovyscript.wiki.quarryplus.work_bench_plus.title=Work bench +groovyscript.wiki.quarryplus.work_bench_plus.description=Workbench for crafting items using electricity. + # Advanced Mortars groovyscript.wiki.advancedmortars.mortar.title=Mortar groovyscript.wiki.advancedmortars.mortar.description=Uses any number of specific types of Mortars to convert multiple items into a single output with a possible chance output after a number of player interactions.