Skip to content
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
19 changes: 19 additions & 0 deletions examples/postInit/quarryplus.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

// Auto generated groovyscript example file
// MODS_LOADED: quarryplus

log.info 'mod \'quarryplus\' detected, running script'

// groovyscript.wiki.quarryplus.work_bench_plus.title:
// groovyscript.wiki.quarryplus.work_bench_plus.description.

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()


Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class ModSupport {
public static final ModSupport INSTANCE = new ModSupport(); // Just for Binding purposes

public static final GroovyContainer<ActuallyAdditions> ACTUALLY_ADDITIONS = new InternalModContainer<>("actuallyadditions", "Actually Additions", ActuallyAdditions::new, "aa");
public static final GroovyContainer<AdditionalEnchantedMiner> ADDITIONAL_ENCHANTED_MINER = new InternalModContainer<>("quarryplus", "Additional Enchanted Miner", AdditionalEnchantedMiner::new, "aem");
public static final GroovyContainer<AdditionalEnchantedMiner> ADDITIONAL_ENCHANTED_MINER = new InternalModContainer<>("quarryplus", "Additional Enchanted Miner", AdditionalEnchantedMiner::new);
public static final GroovyContainer<AdvancedMortars> ADVANCED_MORTARS = new InternalModContainer<>("advancedmortars", "Advanced Mortars", AdvancedMortars::new);
public static final GroovyContainer<AdvancedRocketry> ADVANCED_ROCKETRY = new InternalModContainer<>("advancedrocketry", "Advanced Rocketry", AdvancedRocketry::new);
public static final GroovyContainer<Aether> AETHER = new InternalModContainer<>("aether_legacy", "Aether Legacy", Aether::new, "aether");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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.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;

Expand All @@ -18,12 +18,12 @@ public class WorkBenchPlus extends VirtualizedRegistry<WorkbenchPlusRecipe> {

@Override
public void onReload() {
removeScripted().forEach(recipe -> WorkbenchPlusRecipe.removeById(recipe.getLocation().toString()));
restoreFromBackup().forEach(WorkbenchPlusRecipe::addRecipe);
removeScripted().forEach(recipe -> WorkbenchRecipe.removeRecipe(recipe.getLocation()));
restoreFromBackup().forEach(ModSupport.ADDITIONAL_ENCHANTED_MINER.get().WorkBenchPlus::add);
}

@MethodDescription(example = @Example("item('quarryplus:quarry')"))
public Boolean removeByOutput(ItemStack output) {
public boolean removeByOutput(ItemStack output) {
ItemDamage itemDamage = ItemDamage.apply(output);
Map<ResourceLocation, WorkbenchRecipe> recipeMap = WorkbenchRecipe.getRecipeMap();
Iterable<WorkbenchRecipe> iterable = JavaConversions.asJavaIterable(recipeMap.values());
Expand All @@ -35,32 +35,29 @@ public Boolean removeByOutput(ItemStack output) {
return WorkbenchPlusRecipe.removeByOutput(output);
}

public Boolean removeById(String id) {
Map<ResourceLocation, WorkbenchRecipe> OptinalList = WorkbenchRecipe.getRecipeMap();
ResourceLocation location = new ResourceLocation(id);
Option<WorkbenchRecipe> 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);
}

@MethodDescription(priority = 2000,example = @Example(commented = true))
public void removeAll() {
Map<ResourceLocation, WorkbenchRecipe> OptinalList = WorkbenchRecipe.getRecipeMap();
Iterable<ResourceLocation> iterable = JavaConversions.asJavaIterable(OptinalList.keys());
iterable.forEach(
recipe -> removeById(recipe.toString())
Map<ResourceLocation, WorkbenchRecipe> recipeMap = WorkbenchRecipe.getRecipeMap();
Iterable<ResourceLocation> iterableRecipe = JavaConversions.asJavaIterable(recipeMap.keys());
iterableRecipe.forEach(
location -> WorkbenchPlusRecipe.removeById(location.toString())
);
}

private void add(WorkbenchPlusRecipe recipe) {
addScripted(recipe);
WorkbenchPlusRecipe.addRecipe(recipe);
}

@RecipeBuilderDescription(example =
@Example(".output(item('minecraft:nether_star')).input(item('minecraft:diamond'),item('minecraft:gold_ingot')).energy(10000)")
)
@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<WorkbenchPlusRecipe> {
@Property(property = "input", comp = @Comp(gte = 1 , lte = 27))
@Property(property = "output", comp = @Comp(eq = 1))
public static class RecipeBuilder extends AbstractRecipeBuilder<WorkbenchPlusRecipe> {

@Property(property = "energy", comp = @Comp(gt = 0))
@Property(comp = @Comp(gt = 0))
private double energy;

@RecipeBuilderMethodDescription
Expand All @@ -74,7 +71,6 @@ public String getRecipeNamePrefix() {
return "additionalenchantedminer_workbenchplus_";
}


@Override
public String getErrorMsg() {
return "Error adding Additional Enchanted Miner WorkbenchPlus recipe";
Expand All @@ -91,9 +87,8 @@ public void validate(GroovyLog.Msg msg) {
@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);
WorkbenchPlusRecipe recipe = new WorkbenchPlusRecipe(this.input, this.output.get(0), this.energy, super.name);
ModSupport.ADDITIONAL_ENCHANTED_MINER.get().WorkBenchPlus.add(recipe);
return recipe;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
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;
Expand Down Expand Up @@ -46,21 +44,20 @@ public WorkbenchPlusRecipe(Seq<Seq<IngredientWithCount>> input, ItemStack output
}


public static WorkbenchPlusRecipe addRecipe(WorkbenchPlusRecipe recipe) {
public static boolean addRecipe(WorkbenchPlusRecipe recipe) {
addIngredientRecipe(recipe.location, recipe.output, recipe.energy, recipe.input, true);
return recipe;
return true;
}

public static Boolean removeByOutput(ItemStack output) {
public static boolean removeByOutput(ItemStack output) {
ItemDamage itemDamage = ItemDamage.apply(output);
WorkbenchRecipe.removeRecipe(itemDamage);
return true;
}

public static Boolean removeById(String id) {
public static void removeById(String id) {
ResourceLocation resourceLocation = new ResourceLocation(id);
WorkbenchRecipe.removeRecipe(resourceLocation);
return true;
}

public ResourceLocation getLocation() {
Expand Down