Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Rustic compat #146

Merged
merged 5 commits into from
Apr 6, 2024
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
5 changes: 5 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ dependencies {
runtimeOnly 'curse.maven:thaumic_jei-285492:2705304'
}

compileOnly rfg.deobf('curse.maven:rustic-256141:3107974')
if (project.debug_rustic.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:rustic-256141:3107974')
}

compileOnly rfg.deobf('curse.maven:astralsorcery-sorcery-241721:3044416')
if (project.debug_astral.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:astralsorcery-sorcery-241721:3044416')
Expand Down
102 changes: 102 additions & 0 deletions examples/postInit/rustic.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

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

import net.minecraft.potion.PotionEffect

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

// Alchemy Condenser:
// Converts some number of input itemstacks and a fluidstack into a single output stack after a time in a small multiblock
// structure, with a basic and advanced tier.

mods.rustic.alchemy.removeByInput(item('minecraft:sugar'))
mods.rustic.alchemy.removeByOutput(item('rustic:elixir').withNbt(['ElixirEffects': [['Effect': 'minecraft:night_vision', 'Duration': 3600, 'Amplifier': 0]]]))
// mods.rustic.alchemy.removeAll()

mods.rustic.alchemy.recipeBuilder()
.input(item('minecraft:stone'), item('minecraft:gold_ingot'))
.output(item('minecraft:clay') * 4)
.time(20)
.register()

mods.rustic.alchemy.recipeBuilder()
.input(item('minecraft:stone'), item('minecraft:gold_ingot'), item('minecraft:diamond'))
.bottle(item('minecraft:torch'))
.advanced()
.effect(new PotionEffect(potion('minecraft:night_vision'), 3600, 1))
.register()

mods.rustic.alchemy.recipeBuilder()
.input(item('minecraft:stone'), item('minecraft:stone'), item('minecraft:stone'))
.modifier(item('minecraft:clay'))
.fluidInput(fluid('lava') * 500)
.advanced()
.output(item('minecraft:diamond'))
.register()

mods.rustic.alchemy.recipeBuilder()
.input(item('minecraft:cobblestone'), item('minecraft:cobblestone'))
.fluidInput(fluid('lava') * 25)
.bottle(item('minecraft:bucket'))
.output(item('minecraft:lava_bucket'))
.register()


// Brewing Barrel:
// Converts a fluid into another fluid after a long period of time. If the fluid is an instanceof FluidBooze, has a
// variable Quality that can be refined through further cycles of conversion.

mods.rustic.brewing_barrel.removeByInput(fluid('ironberryjuice'))
mods.rustic.brewing_barrel.removeByOutput(fluid('ale'))
// mods.rustic.brewing_barrel.removeAll()

mods.rustic.brewing_barrel.recipeBuilder()
.fluidInput(fluid('ironberryjuice'))
.fluidOutput(fluid('lava'))
.register()

mods.rustic.brewing_barrel.recipeBuilder()
.fluidInput(fluid('water'))
.fluidOutput(fluid('lava'))
.register()


// Crushing Tub:
// Convert items into a fluidstacks and optionally itemstacks when any entity, typically a player, lands atop it.

mods.rustic.crushing_tub.removeByInput(item('rustic:wildberries'))
mods.rustic.crushing_tub.removeByOutput(fluid('ironberryjuice'))
mods.rustic.crushing_tub.removeByOutput(item('minecraft:sugar'))
// mods.rustic.crushing_tub.removeAll()

mods.rustic.crushing_tub.recipeBuilder()
.input(item('minecraft:stone'))
.fluidOutput(fluid('lava') * 50)
.register()

mods.rustic.crushing_tub.recipeBuilder()
.input(item('minecraft:clay'))
.fluidOutput(fluid('lava') * 20)
.byproduct(item('minecraft:gold_ingot') * 4)
.register()


// Drying Basin:
// Converts fluids into itemstacks over time.

mods.rustic.evaporating_basin.removeByInput(fluid('ironberryjuice'))
// mods.rustic.evaporating_basin.removeByOutput(item('rustic:dust_tiny_iron'))
// mods.rustic.evaporating_basin.removeAll()

mods.rustic.evaporating_basin.recipeBuilder()
.fluidInput(fluid('water') * 200)
.output(item('minecraft:clay'))
.register()

mods.rustic.evaporating_basin.recipeBuilder()
.fluidInput(fluid('lava') * 50)
.output(item('minecraft:iron_ingot'))
.register()


1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ debug_mekanism = false
debug_packmode = false
debug_pyrotech = false
debug_roots = false
debug_rustic = false
debug_thaum = false
debug_thermal = false
debug_tinkers = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.cleanroommc.groovyscript.compat.mods.mekanism.Mekanism;
import com.cleanroommc.groovyscript.compat.mods.pyrotech.PyroTech;
import com.cleanroommc.groovyscript.compat.mods.roots.Roots;
import com.cleanroommc.groovyscript.compat.mods.rustic.Rustic;
import com.cleanroommc.groovyscript.compat.mods.tcomplement.TinkersComplement;
import com.cleanroommc.groovyscript.compat.mods.thaumcraft.Thaumcraft;
import com.cleanroommc.groovyscript.compat.mods.thermalexpansion.ThermalExpansion;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class ModSupport implements IDynamicGroovyProperty {
public static final GroovyContainer<Mekanism> MEKANISM = new InternalModContainer<>("mekanism", "Mekanism", Mekanism::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);
public static final GroovyContainer<Thaumcraft> THAUMCRAFT = new InternalModContainer<>("thaumcraft", "Thaumcraft", Thaumcraft::new, "tc", "thaum");
public static final GroovyContainer<ThermalExpansion> THERMAL_EXPANSION = new InternalModContainer<>("thermalexpansion", "Thermal Expansion", ThermalExpansion::new, "te", "thermal");
public static final GroovyContainer<TinkersComplement> TINKERS_COMPLEMENT = new InternalModContainer<>("tcomplement", "Tinkers Complement", TinkersComplement::new, "tcomp", "tinkerscomplement");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package com.cleanroommc.groovyscript.compat.mods.rustic;

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 net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.Nullable;
import rustic.common.crafting.ICondenserRecipe;
import rustic.common.crafting.Recipes;
import rustic.common.items.ModItems;
import rustic.common.util.ElixirUtils;

import java.util.Collection;

@RegistryDescription
public class Alchemy extends VirtualizedRegistry<ICondenserRecipe> {

public Alchemy() {
super(Alias.generateOfClass(Alchemy.class).andGenerate("Condenser"));
}

@RecipeBuilderDescription(example = {
@Example(".input(item('minecraft:stone'), item('minecraft:gold_ingot')).output(item('minecraft:clay') * 4).time(20)"),
@Example(value = ".input(item('minecraft:stone'), item('minecraft:gold_ingot'), item('minecraft:diamond')).bottle(item('minecraft:torch')).advanced().effect(new PotionEffect(potion('minecraft:night_vision'), 3600, 1))", imports = "net.minecraft.potion.PotionEffect"),
@Example(".input(item('minecraft:stone'), item('minecraft:stone'), item('minecraft:stone')).modifier(item('minecraft:clay')).fluidInput(fluid('lava') * 500).advanced().output(item('minecraft:diamond'))"),
@Example(".input(item('minecraft:cobblestone'), item('minecraft:cobblestone')).fluidInput(fluid('lava') * 25).bottle(item('minecraft:bucket')).output(item('minecraft:lava_bucket'))")
})
public static RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@Override
public void onReload() {
Recipes.condenserRecipes.removeAll(removeScripted());
Recipes.condenserRecipes.addAll(restoreFromBackup());
}

public void add(ICondenserRecipe recipe) {
Recipes.condenserRecipes.add(recipe);
addScripted(recipe);
}

public boolean remove(ICondenserRecipe recipe) {
addBackup(recipe);
return Recipes.condenserRecipes.remove(recipe);
}

@MethodDescription(description = "groovyscript.wiki.removeByOutput", example = @Example("item('rustic:elixir').withNbt(['ElixirEffects': [['Effect': 'minecraft:night_vision', 'Duration': 3600, 'Amplifier': 0]]])"))
public boolean removeByOutput(IIngredient output) {
return Recipes.condenserRecipes.removeIf(entry -> {
if (output.test(entry.getResult())) {
addBackup(entry);
return true;
}
return false;
});
}

@MethodDescription(description = "groovyscript.wiki.removeByInput", example = @Example("item('minecraft:sugar')"))
public boolean removeByInput(IIngredient input) {
return Recipes.condenserRecipes.removeIf(entry -> {
if (entry.getInputs().stream().flatMap(Collection::stream).anyMatch(input)) {
addBackup(entry);
return true;
}
return false;
});
}

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

@MethodDescription(description = "groovyscript.wiki.streamRecipes", type = MethodDescription.Type.QUERY)
public SimpleObjectStream<ICondenserRecipe> streamRecipes() {
return new SimpleObjectStream<>(Recipes.condenserRecipes).setRemover(this::remove);
}

@Property(property = "input", valid = {@Comp(value = "1", type = Comp.Type.GTE), @Comp(value = "2 or 3", type = Comp.Type.LTE)})
@Property(property = "fluidInput", defaultValue = "fluid('water') * 125", valid = {@Comp(value = "0", type = Comp.Type.GTE), @Comp(value = "1", type = Comp.Type.LTE)})
@Property(property = "output", valid = {@Comp(value = "0", type = Comp.Type.GTE), @Comp(value = "1", type = Comp.Type.LTE)})
public static class RecipeBuilder extends AbstractRecipeBuilder<ICondenserRecipe> {

@Property(defaultValue = "IIngredient.EMPTY")
private IIngredient modifier = IIngredient.EMPTY;
@Property(defaultValue = "IIngredient.EMPTY")
private IIngredient bottle = IIngredient.EMPTY;
@Property(defaultValue = "400")
private int time = 400;
@Property
private boolean advanced;

@RecipeBuilderMethodDescription
public RecipeBuilder effect(PotionEffect effect) {
var output = new ItemStack(ModItems.ELIXIR);
ElixirUtils.addEffect(effect, output);
this.output.add(output);
return this;
}

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

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

@RecipeBuilderMethodDescription
public RecipeBuilder advanced() {
this.advanced = !advanced;
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder advanced(boolean advanced) {
this.advanced = advanced;
return this;
}

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

@Override
public String getErrorMsg() {
return "Error adding Rustic Alchemy recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, advanced ? 3 : 2, 1, 1);
msg.add(msg.hasSubMessages(), "advanced requires a maximum of 3 inputs, while basic requires a maximum of 2 inputs");
validateFluids(msg, 0, 1, 0, 0);
msg.add(!modifier.isEmpty() && !advanced, "modifier can only be defined if advanced is true");
msg.add(time <= 0, "time must be an integer greater than 0, yet it was {}", time);
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable ICondenserRecipe register() {
if (!validate()) return null;

ICondenserRecipe recipe = new CondenserRecipe(output.get(0), input, modifier, bottle,
fluidInput.isEmpty() ? new FluidStack(FluidRegistry.WATER, 125) : fluidInput.getOrEmpty(0),
time, advanced);

ModSupport.RUSTIC.get().alchemy.add(recipe);
return recipe;
}
}

}
Loading