diff --git a/dependencies.gradle b/dependencies.gradle index 414dfa16c..58a1f10c1 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/gradle.properties b/gradle.properties index ac888afbf..a861d660d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,6 +13,7 @@ debug_generate_and_crash = 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 a2e660f2c..25fda9093 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; @@ -82,6 +83,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, "aem"); 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..8093535e5 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/AdditionalEnchantedMiner.java @@ -0,0 +1,7 @@ +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..c48906629 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/WorkBenchPlus.java @@ -0,0 +1,100 @@ +package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import com.yogpc.qp.recipe.WorkbenchRecipe; +import com.yogpc.qp.tile.ItemDamage; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.jetbrains.annotations.Nullable; +import scala.Option; +import scala.collection.JavaConversions; +import scala.collection.Map; + +@RegistryDescription +public class WorkBenchPlus extends VirtualizedRegistry { + + @Override + public void onReload() { + removeScripted().forEach(recipe -> WorkbenchPlusRecipe.removeById(recipe.getLocation().toString())); + restoreFromBackup().forEach(WorkbenchPlusRecipe::addRecipe); + } + + @MethodDescription(example = @Example("item('quarryplus:quarry')")) + public Boolean 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 WorkbenchPlusRecipe(recipe.inputs(), recipe.getOutput(), recipe.energy(), recipe.location())); + } + }); + return WorkbenchPlusRecipe.removeByOutput(output); + } + + public Boolean removeById(String id) { + Map OptinalList = WorkbenchRecipe.getRecipeMap(); + ResourceLocation location = new ResourceLocation(id); + Option recipe = OptinalList.get(location); + if (recipe.isDefined()) addBackup(new WorkbenchPlusRecipe(recipe.get().inputs(), recipe.get().getOutput(), recipe.get().energy(), recipe.get().location())); + return WorkbenchPlusRecipe.removeById(id); + } + + public void removeAll() { + Map OptinalList = WorkbenchRecipe.getRecipeMap(); + Iterable iterable = JavaConversions.asJavaIterable(OptinalList.keys()); + iterable.forEach( + recipe -> removeById(recipe.toString()) + ); + } + + @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(not = "null", gte = 1 , lte = 27)) + @Property(property = "output", comp = @Comp(not = "null" , eq = 1)) + public class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(property = "energy", 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 AdditionalEnchantedMiner 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 WorkbenchPlusRecipe register() { + if (!validate()) return null; + WorkbenchPlusRecipe recipe = new WorkbenchPlusRecipe(this.input, this.output.get(0), this.energy, name); + addScripted(recipe); + WorkbenchPlusRecipe.addRecipe(recipe); + return recipe; + } + } +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/WorkbenchPlusRecipe.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/WorkbenchPlusRecipe.java new file mode 100644 index 000000000..8f3296e0c --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/additionalenchantedminer/WorkbenchPlusRecipe.java @@ -0,0 +1,69 @@ +package com.cleanroommc.groovyscript.compat.mods.additionalenchantedminer; + +import com.cleanroommc.groovyscript.api.IIngredient; +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 scala.Option; +import scala.collection.JavaConversions; +import scala.collection.Map; +import scala.collection.Seq; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static com.yogpc.qp.recipe.WorkbenchRecipe.addIngredientRecipe; + +public class WorkbenchPlusRecipe { + private final List> input; + private final ItemStack output; + private final Double energy; + private final ResourceLocation location; + + public WorkbenchPlusRecipe(Collection input, ItemStack output, Double energy , ResourceLocation location) { + + this.input = input.stream() + .map(i -> new IngredientWithCount(i.toMcIngredient(), i.getAmount())) + .map(Collections::singletonList) + .collect(Collectors.toList()); + this.output = output; + this.energy = energy; + this.location = location; + } + + public WorkbenchPlusRecipe(Seq> input, ItemStack output, Double energy , ResourceLocation location) { + this.input = JavaConversions.seqAsJavaList(input).stream() + .map(JavaConversions::seqAsJavaList) + .collect(Collectors.toList()); + this.output = output; + this.energy = energy; + this.location = location; + + } + + + public static WorkbenchPlusRecipe addRecipe(WorkbenchPlusRecipe recipe) { + addIngredientRecipe(recipe.location, recipe.output, recipe.energy, recipe.input, true); + return recipe; + } + + public static Boolean removeByOutput(ItemStack output) { + ItemDamage itemDamage = ItemDamage.apply(output); + WorkbenchRecipe.removeRecipe(itemDamage); + return true; + } + + public static Boolean removeById(String id) { + ResourceLocation resourceLocation = new ResourceLocation(id); + WorkbenchRecipe.removeRecipe(resourceLocation); + return true; + } + + public ResourceLocation getLocation() { + return location; + } +}