Skip to content

Commit

Permalink
add Nature's Aura compat (#147)
Browse files Browse the repository at this point in the history
* add natures aura

* dont need to store the ResourceLocation
  • Loading branch information
WaitingIdly authored Apr 6, 2024
1 parent b31f869 commit 8ea4da7
Show file tree
Hide file tree
Showing 10 changed files with 837 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,28 @@ dependencies {
if (project.debug_immersive_engineering.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:immersive_engineering-231951:2974106')
}
compileOnly rfg.deobf('curse.maven:patchouli-306770:3162874')
if (project.debug_roots.toBoolean() || project.debug_natures_aura.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:patchouli-306770:3162874')
}

compileOnly rfg.deobf('curse.maven:mystical_lib-277064:3483816')
if (project.debug_roots.toBoolean() || project.debug_arcane_archives.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:mystical_lib-277064:3483816')
}

compileOnly rfg.deobf('curse.maven:patchouli-306770:3162874')
compileOnly rfg.deobf('curse.maven:mystical_world-282940:3460961')
compileOnly rfg.deobf('curse.maven:roots-246183:3905074')
if (project.debug_roots.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:patchouli-306770:3162874')
runtimeOnly rfg.deobf('curse.maven:mystical_world-282940:3460961')
runtimeOnly rfg.deobf('curse.maven:roots-246183:3905074')
}

compileOnly rfg.deobf('curse.maven:natures-aura-306626:2882138')
if (project.debug_natures_aura.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:natures-aura-306626:2882138')
}

// gigaherz.lirelent.guidebook:Guidebook-1.12.2:2.9.1.s5
compileOnly rfg.deobf('curse.maven:guidebook-253874:2989594')
compileOnly rfg.deobf('curse.maven:arcane-archives-311357:3057332')
Expand Down
140 changes: 140 additions & 0 deletions examples/postInit/naturesaura.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

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

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

// Natural Altar Infusion:
// Converts an input itemstack into an itemstack in a multiblock structure, with an optional catalyst block, costing aura
// and taking a configurable duration.

mods.naturesaura.altar.removeByCatalyst(item('naturesaura:crushing_catalyst'))
mods.naturesaura.altar.removeByInput(item('minecraft:rotten_flesh'))
mods.naturesaura.altar.removeByName(resource('naturesaura:infused_iron'))
mods.naturesaura.altar.removeByOutput(item('minecraft:soul_sand'))
// mods.naturesaura.altar.removeAll()

mods.naturesaura.altar.recipeBuilder()
.name('demo')
.input(item('minecraft:clay'))
.catalyst(item('minecraft:clay'))
.output(item('minecraft:diamond'))
.aura(100)
.time(100)
.register()

mods.naturesaura.altar.recipeBuilder()
.name(resource('example:demo'))
.input(item('minecraft:clay'))
.output(item('minecraft:gold_ingot') * 8)
.aura(30)
.time(5)
.register()

mods.naturesaura.altar.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.output(item('minecraft:diamond'))
.catalyst(item('minecraft:clay'))
.aura(50)
.time(100)
.register()


// Offering to the Gods:
// Converts up to 16 times the input itemstack into output itemstacks by consuming a catalyst item from the ground in a
// multiblock structure.

// mods.naturesaura.offering.removeByCatalyst(item('naturesaura:calling_spirit'))
mods.naturesaura.offering.removeByInput(item('minecraft:nether_star'))
mods.naturesaura.offering.removeByName(resource('naturesaura:token_euphoria'))
mods.naturesaura.offering.removeByOutput(item('naturesaura:sky_ingot'))
// mods.naturesaura.offering.removeAll()

mods.naturesaura.offering.recipeBuilder()
.name('demo')
.input(item('minecraft:diamond'))
.catalyst(item('minecraft:clay'))
.output(item('minecraft:gold_ingot') * 8)
.register()

mods.naturesaura.offering.recipeBuilder()
.name(resource('example:demo'))
.input(item('minecraft:clay'))
.catalyst(item('minecraft:gold_ingot'))
.output(item('minecraft:diamond') * 8)
.register()

mods.naturesaura.offering.recipeBuilder()
.input(item('minecraft:gold_ingot') * 10)
.catalyst(item('minecraft:diamond'))
.output(item('minecraft:clay'))
.register()


// Ritual of the Forest:
// Converts multiple input items into an output itemstack after a duration when a sapling grows in the middle of a
// multiblock structure.

mods.naturesaura.ritual.removeByInput(item('naturesaura:infused_stone'))
mods.naturesaura.ritual.removeByName(resource('naturesaura:eye_improved'))
mods.naturesaura.ritual.removeByOutput(item('naturesaura:eye'))
mods.naturesaura.ritual.removeBySapling(item('minecraft:sapling:3'))
// mods.naturesaura.ritual.removeAll()

mods.naturesaura.ritual.recipeBuilder()
.name('demo')
.input(item('minecraft:clay'))
.output(item('minecraft:diamond'))
.time(100)
.sapling(item('minecraft:sapling:1'))
.register()

mods.naturesaura.ritual.recipeBuilder()
.name(resource('example:demo'))
.input(item('minecraft:clay'), item('minecraft:clay'), item('minecraft:clay'), item('minecraft:clay'))
.output(item('minecraft:gold_ingot'))
.time(15)
.sapling(item('minecraft:sapling:1'))
.register()

mods.naturesaura.ritual.recipeBuilder()
.input(item('minecraft:gold_ingot'), item('minecraft:clay'), item('minecraft:gold_ingot'), item('minecraft:clay'), item('minecraft:gold_ingot'), item('minecraft:clay'), item('minecraft:gold_ingot'), item('minecraft:clay'))
.output(item('minecraft:diamond') * 16)
.time(20)
.sapling(item('minecraft:sapling:3'))
.register()


// Altar of Birthing:
// Converts multiple input itemstacks into a summoned entity, costing aura and taking time.

mods.naturesaura.spawning.removeByEntity(entity('minecraft:polar_bear'))
mods.naturesaura.spawning.removeByEntity(resource('minecraft:cave_spider'))
mods.naturesaura.spawning.removeByInput(item('minecraft:bone'))
mods.naturesaura.spawning.removeByName(resource('naturesaura:cow'))
// mods.naturesaura.spawning.removeAll()

mods.naturesaura.spawning.recipeBuilder()
.name('demo')
.input(item('minecraft:clay'))
.entity(entity('minecraft:bat'))
.aura(100)
.time(100)
.register()

mods.naturesaura.spawning.recipeBuilder()
.name(resource('example:demo'))
.input(item('minecraft:mutton'))
.entity(entity('minecraft:wolf'))
.aura(30)
.time(5)
.register()

mods.naturesaura.spawning.recipeBuilder()
.input(item('minecraft:bone'), item('minecraft:dye:15') * 4)
.entity(resource('minecraft:skeleton'))
.aura(10)
.time(10)
.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_industrial_craft_2_experimental = false
debug_inspirations = false
debug_integrated_dynamics = false
debug_mekanism = false
debug_natures_aura = false
debug_packmode = false
debug_pyrotech = false
debug_roots = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.cleanroommc.groovyscript.compat.mods.integrateddynamics.IntegratedDynamics;
import com.cleanroommc.groovyscript.compat.mods.jei.JustEnoughItems;
import com.cleanroommc.groovyscript.compat.mods.mekanism.Mekanism;
import com.cleanroommc.groovyscript.compat.mods.naturesaura.NaturesAura;
import com.cleanroommc.groovyscript.compat.mods.pyrotech.PyroTech;
import com.cleanroommc.groovyscript.compat.mods.roots.Roots;
import com.cleanroommc.groovyscript.compat.mods.rustic.Rustic;
Expand Down Expand Up @@ -84,6 +85,7 @@ public class ModSupport implements IDynamicGroovyProperty {
public static final GroovyContainer<IntegratedDynamics> INTEGRATED_DYNAMICS = new InternalModContainer<>("integrateddynamics", "Integrated Dynamics", IntegratedDynamics::new, "id");
public static final GroovyContainer<JustEnoughItems> JEI = new InternalModContainer<>("jei", "Just Enough Items", JustEnoughItems::new, "hei");
public static final GroovyContainer<Mekanism> MEKANISM = new InternalModContainer<>("mekanism", "Mekanism", Mekanism::new);
public static final GroovyContainer<NaturesAura> NATURES_AURA = new InternalModContainer<>("naturesaura", "Nature's Aura", NaturesAura::new);
public static final GroovyContainer<PyroTech> PYROTECH = new InternalModContainer<>("pyrotech", "Pyrotech", PyroTech::new);
public static final GroovyContainer<Roots> ROOTS = new InternalModContainer<>("roots", "Roots 3", Roots::new);
public static final GroovyContainer<Rustic> RUSTIC = new InternalModContainer<>("rustic", "Rustic", Rustic::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package com.cleanroommc.groovyscript.compat.mods.naturesaura;

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.Alias;
import com.cleanroommc.groovyscript.helper.SimpleObjectStream;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.recipes.AltarRecipe;
import net.minecraft.util.ResourceLocation;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

@RegistryDescription
public class Altar extends VirtualizedRegistry<AltarRecipe> {

public Altar() {
super(Alias.generateOfClass(Altar.class).andGenerate("Infusion"));
}

@RecipeBuilderDescription(example = {
@Example(".name('demo').input(item('minecraft:clay')).catalyst(item('minecraft:clay')).output(item('minecraft:diamond')).aura(100).time(100)"),
@Example(".name(resource('example:demo')).input(item('minecraft:clay')).output(item('minecraft:gold_ingot') * 8).aura(30).time(5)"),
@Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:diamond')).catalyst(item('minecraft:clay')).aura(50).time(100)")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@Override
public void onReload() {
removeScripted().forEach(x -> NaturesAuraAPI.ALTAR_RECIPES.remove(x.name));
restoreFromBackup().forEach(x -> NaturesAuraAPI.ALTAR_RECIPES.put(x.name, x));
}

public void add(AltarRecipe recipe) {
if (recipe == null) return;
addScripted(recipe);
NaturesAuraAPI.ALTAR_RECIPES.put(recipe.name, recipe);
}

public boolean remove(AltarRecipe recipe) {
if (recipe == null) return false;
addBackup(recipe);
return NaturesAuraAPI.ALTAR_RECIPES.remove(recipe.name) != null;
}

@MethodDescription(example = @Example("resource('naturesaura:infused_iron')"))
public boolean removeByName(ResourceLocation name) {
if (name == null) return false;
var recipe = NaturesAuraAPI.ALTAR_RECIPES.remove(name);
if (recipe == null) return false;
addBackup(recipe);
return true;
}

@MethodDescription(description = "groovyscript.wiki.removeByInput", example = @Example("item('minecraft:rotten_flesh')"))
public boolean removeByInput(IIngredient input) {
return NaturesAuraAPI.ALTAR_RECIPES.entrySet().removeIf(r -> {
for (var item : r.getValue().input.getMatchingStacks()) {
if (input.test(item)) {
addBackup(r.getValue());
return true;
}
}
return false;
});
}

@MethodDescription(description = "groovyscript.wiki.removeByCatalyst", example = @Example("item('naturesaura:crushing_catalyst')"))
public boolean removeByCatalyst(IIngredient catalyst) {
return NaturesAuraAPI.ALTAR_RECIPES.entrySet().removeIf(r -> {
for (var item : r.getValue().catalyst.getMatchingStacks()) {
if (catalyst.test(item)) {
addBackup(r.getValue());
return true;
}
}
return false;
});
}

@MethodDescription(description = "groovyscript.wiki.removeByOutput", example = @Example("item('minecraft:soul_sand')"))
public boolean removeByOutput(IIngredient output) {
return NaturesAuraAPI.ALTAR_RECIPES.entrySet().removeIf(r -> {
if (output.test(r.getValue().output)) {
addBackup(r.getValue());
return true;
}
return false;
});
}

@MethodDescription(description = "groovyscript.wiki.removeAll", priority = 2000, example = @Example(commented = true))
public void removeAll() {
NaturesAuraAPI.ALTAR_RECIPES.values().forEach(this::addBackup);
NaturesAuraAPI.ALTAR_RECIPES.entrySet().clear();
}

@MethodDescription(description = "groovyscript.wiki.streamRecipes", type = MethodDescription.Type.QUERY)
public SimpleObjectStream<Map.Entry<ResourceLocation, AltarRecipe>> streamRecipes() {
return new SimpleObjectStream<>(NaturesAuraAPI.ALTAR_RECIPES.entrySet()).setRemover(x -> remove(x.getValue()));
}

@Property(property = "input", valid = @Comp("1"))
@Property(property = "output", valid = @Comp("1"))
public static class RecipeBuilder extends AbstractRecipeBuilder<AltarRecipe> {

@Property(valid = @Comp(value = "null", type = Comp.Type.NOT), defaultValue = "IIngredient.EMPTY")
private IIngredient catalyst = IIngredient.EMPTY;
@Property(valid = @Comp(value = "1", type = Comp.Type.GTE))
private int aura;
@Property(valid = @Comp(value = "1", type = Comp.Type.GTE))
private int time;

@RecipeBuilderMethodDescription
public RecipeBuilder catalyst(IIngredient catalyst) {
this.catalyst = catalyst;
return this;
}

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

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

@Override
public String getErrorMsg() {
return "Error adding Nature's Aura Altar Recipe";
}

public String getRecipeNamePrefix() {
return "groovyscript_altar_";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateName();
validateItems(msg, 1, 1, 1, 1);
validateFluids(msg);
msg.add(catalyst == null, "catalyst must not be null");
msg.add(aura <= 0, "aura must be greater than or equal to 1, yet it was {}", aura);
msg.add(time <= 0, "time must be greater than or equal to 1, yet it was {}", time);
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable AltarRecipe register() {
if (!validate()) return null;
AltarRecipe recipe = new AltarRecipe(name, input.get(0).toMcIngredient(), output.get(0), catalyst.toMcIngredient(), aura, time);
ModSupport.NATURES_AURA.get().altar.add(recipe);
return recipe;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.cleanroommc.groovyscript.compat.mods.naturesaura;

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

public class NaturesAura extends ModPropertyContainer {

public final Altar altar = new Altar();
public final Ritual ritual = new Ritual();
public final Offering offering = new Offering();
public final Spawning spawning = new Spawning();

public NaturesAura() {
addRegistry(altar);
addRegistry(ritual);
addRegistry(offering);
addRegistry(spawning);
}

}
Loading

0 comments on commit 8ea4da7

Please sign in to comment.