Skip to content

Commit

Permalink
add Botanic Additions compat (#200)
Browse files Browse the repository at this point in the history
Co-authored-by: brachy84 <[email protected]>
  • Loading branch information
WaitingIdly and brachy84 authored Jul 23, 2024
1 parent a6fd8d9 commit fc8ae84
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ final def mod_dependencies = [
'guidebook-253874:2989594' : [project.debug_arcane_archives],
'mystical_lib-277064:3483816' : [project.debug_arcane_archives, project.debug_roots],
'astralsorcery-sorcery-241721:3044416' : [project.debug_astral],
'baubles-227083:2518667' : [project.debug_astral, project.debug_botania, project.debug_essentialcraft_4, project.debug_extra_botany, project.debug_thaum],
'baubles-227083:2518667' : [project.debug_astral, project.debug_botania, project.debug_botanic_additions, project.debug_essentialcraft_4, project.debug_extra_botany, project.debug_thaum],
'the-aurorian-352137:4981736' : [project.debug_aurorian],
'avaritia_1_10-261348:3143349' : [project.debug_avaritia],
'atum-2-59621:3116599' : [project.debug_atum],
'bwm-core-294335:2624990' : [project.debug_better_with_mods],
'bwm-suite-246760:3289033' : [project.debug_better_with_mods],
'blood-magic-224791:2822288' : [project.debug_blood_magic],
'guide-api-228832:2645992' : [project.debug_blood_magic, project.debug_woot],
'botania-225643:3330934' : [project.debug_botania, project.debug_extra_botany],
'botania-225643:3330934' : [project.debug_botania, project.debug_botanic_addition, project.debug_extra_botany],
'botanic-additions-310637:2939405' : [project.debug_botanic_additions],
'hammer-lib-247401:5259462' : [project.debug_botanic_additions],
'calculator-225104:2847174' : [project.debug_calculator],
'sonar-core-239418:2645156' : [project.debug_calculator],
'chisel-235279:2915375' : [project.debug_chisel],
Expand Down
27 changes: 27 additions & 0 deletions examples/postInit/botanicadds.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

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

println 'mod \'botanicadds\' detected, running script'

// Gaia Plate:
// Converts an number of input items into an output itemstack, consuming a given amount of mana when dropped in-world atop
// a Gaia Agglomeration Plate as part of a multiblock structure.

mods.botanicadds.gaia_plate.removeByInput(item('botania:manaresource'))
mods.botanicadds.gaia_plate.removeByOutput(item('botanicadds:gaiasteel_ingot'))
// mods.botanicadds.gaia_plate.removeAll()

mods.botanicadds.gaia_plate.recipeBuilder()
.input(item('minecraft:diamond'))
.output(item('minecraft:gold_ingot') * 16)
.mana(1000)
.register()

mods.botanicadds.gaia_plate.recipeBuilder()
.input(item('minecraft:diamond_block'), item('minecraft:gold_block'), item('minecraft:clay'))
.output(item('minecraft:gold_ingot'))
.mana(100)
.register()


1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ debug_avaritia = false
debug_better_with_mods = false
debug_blood_magic = false
debug_botania = false
debug_botanic_additions = false
debug_calculator = false
debug_chisel = false
debug_compact_machines = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.cleanroommc.groovyscript.compat.mods.betterwithmods.BetterWithMods;
import com.cleanroommc.groovyscript.compat.mods.bloodmagic.BloodMagic;
import com.cleanroommc.groovyscript.compat.mods.botania.Botania;
import com.cleanroommc.groovyscript.compat.mods.botanicadditions.BotanicAdditions;
import com.cleanroommc.groovyscript.compat.mods.calculator.Calculator;
import com.cleanroommc.groovyscript.compat.mods.chisel.Chisel;
import com.cleanroommc.groovyscript.compat.mods.cyclic.Cyclic;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class ModSupport {
public static final GroovyContainer<BetterWithMods> BETTER_WITH_MODS = new InternalModContainer<>("betterwithmods", "Better With Mods", BetterWithMods::new);
public static final GroovyContainer<BloodMagic> BLOOD_MAGIC = new InternalModContainer<>("bloodmagic", "Blood Magic: Alchemical Wizardry", BloodMagic::new, "bm");
public static final GroovyContainer<Botania> BOTANIA = new InternalModContainer<>("botania", "Botania", Botania::new);
public static final GroovyContainer<BotanicAdditions> BOTANIC_ADDITIONS = new InternalModContainer<>("botanicadds", "Botanic Additions", BotanicAdditions::new);
public static final GroovyContainer<Calculator> CALCULATOR = new InternalModContainer<>("calculator", "Calculator", Calculator::new);
public static final GroovyContainer<Chisel> CHISEL = new InternalModContainer<>("chisel", "Chisel", Chisel::new);
public static final GroovyContainer<CompactMachines> COMPACT_MACHINES = new InternalModContainer<>("compactmachines3", "Compact Machines 3", CompactMachines::new, "compactmachines");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.cleanroommc.groovyscript.compat.mods.botanicadditions;

import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;

public class BotanicAdditions extends GroovyPropertyContainer {

public final GaiaPlate gaiaPlate = new GaiaPlate();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.cleanroommc.groovyscript.compat.mods.botanicadditions;

import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.helper.SimpleObjectStream;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import org.jetbrains.annotations.Nullable;
import tk.zeitheron.botanicadds.api.GaiaPlateRecipes;

@RegistryDescription
public class GaiaPlate extends VirtualizedRegistry<GaiaPlateRecipes.RecipeGaiaPlate> {

@RecipeBuilderDescription(example = {
@Example(".input(item('minecraft:diamond')).output(item('minecraft:gold_ingot') * 16).mana(1000)"),
@Example(".input(item('minecraft:diamond_block'), item('minecraft:gold_block'), item('minecraft:clay')).output(item('minecraft:gold_ingot')).mana(100)")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@Override
public void onReload() {
GaiaPlateRecipes.gaiaRecipes.removeAll(removeScripted());
GaiaPlateRecipes.gaiaRecipes.addAll(restoreFromBackup());
}

public void add(GaiaPlateRecipes.RecipeGaiaPlate recipe) {
if (recipe != null) {
addScripted(recipe);
GaiaPlateRecipes.gaiaRecipes.add(recipe);
}
}

public boolean remove(GaiaPlateRecipes.RecipeGaiaPlate recipe) {
if (GaiaPlateRecipes.gaiaRecipes.removeIf(r -> r == recipe)) {
addBackup(recipe);
return true;
}
return false;
}

@MethodDescription(example = @Example("item('botanicadds:gaiasteel_ingot')"))
public boolean removeByOutput(IIngredient output) {
return GaiaPlateRecipes.gaiaRecipes.removeIf(r -> {
if (output.test(r.getOutput())) {
addBackup(r);
return true;
}
return false;
});
}

@MethodDescription(example = @Example("item('botania:manaresource')"))
public boolean removeByInput(IIngredient input) {
return GaiaPlateRecipes.gaiaRecipes.removeIf(r -> {
for (Object ingredient : r.getInputs()) {
if ((ingredient instanceof String s && (input instanceof OreDictIngredient ore && ore.getOreDict().equals(s) || OreDictionary.getOres(s, false).stream().anyMatch(input))) ||
(ingredient instanceof ItemStack is && input.test(is))) {
addBackup(r);
return true;
}
}
return false;
});
}

@MethodDescription(type = MethodDescription.Type.QUERY)
public SimpleObjectStream<GaiaPlateRecipes.RecipeGaiaPlate> streamRecipes() {
return new SimpleObjectStream<>(GaiaPlateRecipes.gaiaRecipes).setRemover(this::remove);
}

@MethodDescription(priority = 2000, example = @Example(commented = true))
public void removeAll() {
GaiaPlateRecipes.gaiaRecipes.forEach(this::addBackup);
GaiaPlateRecipes.gaiaRecipes.clear();
}

@Property(property = "input", valid = @Comp("1"))
@Property(property = "output", valid = {@Comp(value = "1", type = Comp.Type.GTE), @Comp(value = "Integer.MAX_VALUE", type = Comp.Type.LTE)})
public static class RecipeBuilder extends AbstractRecipeBuilder<GaiaPlateRecipes.RecipeGaiaPlate> {

@Property(defaultValue = "1", valid = @Comp(value = "1", type = Comp.Type.GTE))
private int mana = 1;

@RecipeBuilderMethodDescription
public RecipeBuilder mana(int mana) {
this.mana = mana;
return this;
}

@Override
public String getErrorMsg() {
return "Error adding Botanic Additions Gaia Plate recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, Integer.MAX_VALUE, 1, 1);
validateFluids(msg);
msg.add(mana <= 0, "mana must be a positive integer greater than 0, yet it was {}", mana);
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable GaiaPlateRecipes.RecipeGaiaPlate register() {
if (!validate()) return null;
Object[] inputs = input.stream()
.map(i -> i instanceof OreDictIngredient ? ((OreDictIngredient) i).getOreDict() : i.getMatchingStacks()[0])
.toArray();
GaiaPlateRecipes.RecipeGaiaPlate recipe = new GaiaPlateRecipes.RecipeGaiaPlate(output.get(0), mana, inputs);
ModSupport.BOTANIC_ADDITIONS.get().gaiaPlate.add(recipe);
return recipe;
}
}

}
6 changes: 6 additions & 0 deletions src/main/resources/assets/groovyscript/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ groovyscript.wiki.botania.rune_altar.input.required=that `input` IIngredients ca
groovyscript.wiki.botania.rune_altar.mana.value=Sets the mana cost of processing the recipe


# Botanic Additions
groovyscript.wiki.botanicadds.gaia_plate.title=Gaia Plate
groovyscript.wiki.botanicadds.gaia_plate.description=Converts an number of input items into an output itemstack, consuming a given amount of mana when dropped in-world atop a Gaia Agglomeration Plate as part of a multiblock structure.
groovyscript.wiki.botanicadds.gaia_plate.mana.value=Sets the mana cost of processing the recipe


# Calculator
groovyscript.wiki.calculator.algorithm_separator.title=Algorithm Separator
groovyscript.wiki.calculator.algorithm_separator.description=Converts an input itemstack into two output itemstacks.
Expand Down

0 comments on commit fc8ae84

Please sign in to comment.