Skip to content

Commit

Permalink
add Alchemistry compat (#133)
Browse files Browse the repository at this point in the history
* alchemistry compat

* remove a critical skill issue

* did a bad and forgot a description

* add some basic add methods
  • Loading branch information
WaitingIdly authored Mar 14, 2024
1 parent 3385225 commit 4f1ec82
Show file tree
Hide file tree
Showing 12 changed files with 1,057 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ dependencies {
runtimeOnly rfg.deobf('curse.maven:avaritia_1_10-261348:3143349')
}

compileOnly rfg.deobf("curse.maven:shadowfacts-forgelin-248453:2785465")
compileOnly rfg.deobf("curse.maven:alchemylib-293426:2761706")
compileOnly rfg.deobf("curse.maven:alchemistry-293425:3186612")
if (project.debug_alchemistry.toBoolean()) {
runtimeOnly rfg.deobf('curse.maven:shadowfacts-forgelin-248453:2785465')
runtimeOnly rfg.deobf('curse.maven:alchemylib-293426:2761706')
runtimeOnly rfg.deobf('curse.maven:alchemistry-293425:3186612')
}

compileOnly rfg.deobf("curse.maven:ctm-267602:2915363")
compileOnly rfg.deobf("curse.maven:chisel-235279:2915375")
if (project.debug_chisel.toBoolean()) {
Expand Down
127 changes: 127 additions & 0 deletions examples/postInit/alchemistry.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@

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

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

// groovyscript.wiki.alchemistry.atomizer.title:
// groovyscript.wiki.alchemistry.atomizer.description

mods.alchemistry.atomizer.removeByInput(fluid('water'))
// mods.alchemistry.atomizer.removeByOutput(item('alchemistry:compound:7'))
// mods.alchemistry.atomizer.removeAll()

mods.alchemistry.atomizer.recipeBuilder()
.fluidInput(fluid('water') * 125)
.output(item('minecraft:clay'))
.register()

mods.alchemistry.atomizer.recipeBuilder()
.fluidInput(fluid('lava') * 500)
.output(item('minecraft:gold_ingot'))
.reversible()
.register()


// groovyscript.wiki.alchemistry.combiner.title:
// groovyscript.wiki.alchemistry.combiner.description

mods.alchemistry.combiner.removeByInput(element('carbon'))
mods.alchemistry.combiner.removeByOutput(item('minecraft:glowstone'))
// mods.alchemistry.combiner.removeAll()

mods.alchemistry.combiner.recipeBuilder()
.input(item('minecraft:gold_ingot') * 2, item('minecraft:gold_ingot') * 2, item('minecraft:gold_ingot') * 2, item('minecraft:gold_ingot') * 2, item('minecraft:gold_ingot') * 2, item('minecraft:gold_ingot') * 2, item('minecraft:gold_ingot') * 2, item('minecraft:gold_ingot') * 2, item('minecraft:gold_ingot') * 2)
.output(item('minecraft:gold_block') * 2)
.register()

mods.alchemistry.combiner.recipeBuilder()
.input(ItemStack.EMPTY, ItemStack.EMPTY, item('minecraft:clay'))
.output(item('minecraft:gold_ingot'))
.register()


// groovyscript.wiki.alchemistry.dissolver.title:
// groovyscript.wiki.alchemistry.dissolver.description

mods.alchemistry.dissolver.removeByInput(item('alchemistry:compound:1'))
// mods.alchemistry.dissolver.removeAll()

mods.alchemistry.dissolver.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.probabilityOutput(item('minecraft:clay'))
.reversible()
.rolls(1)
.register()

mods.alchemistry.dissolver.recipeBuilder()
.input(item('minecraft:diamond'))
.probabilityOutput(30, item('minecraft:clay'))
.probabilityOutput(30, item('minecraft:clay'))
.probabilityOutput(30, item('minecraft:clay'))
.rolls(10)
.register()


// groovyscript.wiki.alchemistry.electrolyzer.title:
// groovyscript.wiki.alchemistry.electrolyzer.description

// mods.alchemistry.electrolyzer.removeByInput(fluid('water'))
mods.alchemistry.electrolyzer.removeByInput(element('calcium_carbonate'))
mods.alchemistry.electrolyzer.removeByOutput(element('chlorine'))
// mods.alchemistry.electrolyzer.removeAll()

mods.alchemistry.electrolyzer.recipeBuilder()
.fluidInput(fluid('lava') * 100)
.output(item('minecraft:clay'))
.register()

mods.alchemistry.electrolyzer.recipeBuilder()
.fluidInput(fluid('water') * 100)
.input(item('minecraft:gold_ingot'))
.consumptionChance(100)
.output(item('minecraft:gold_nugget') * 4)
.output(item('minecraft:gold_nugget') * 4)
.output(item('minecraft:gold_nugget') * 4)
.output(item('minecraft:gold_nugget') * 4)
.chance(50)
.chance(50)
.register()


// groovyscript.wiki.alchemistry.evaporator.title:
// groovyscript.wiki.alchemistry.evaporator.description

mods.alchemistry.evaporator.removeByInput(fluid('lava'))
mods.alchemistry.evaporator.removeByOutput(item('alchemistry:mineral_salt'))
// mods.alchemistry.evaporator.removeAll()

mods.alchemistry.evaporator.recipeBuilder()
.fluidInput(fluid('lava') * 100)
.output(item('minecraft:redstone') * 8)
.register()

mods.alchemistry.evaporator.recipeBuilder()
.fluidInput(fluid('water') * 10)
.output(item('minecraft:clay'))
.register()


// groovyscript.wiki.alchemistry.liquifier.title:
// groovyscript.wiki.alchemistry.liquifier.description

mods.alchemistry.liquifier.removeByInput(element('water'))
// mods.alchemistry.liquifier.removeByOutput(fluid('water'))
// mods.alchemistry.liquifier.removeAll()

mods.alchemistry.liquifier.recipeBuilder()
.input(element('carbon') * 32)
.fluidOutput(fluid('water') * 1000)
.register()

mods.alchemistry.liquifier.recipeBuilder()
.input(item('minecraft:magma'))
.fluidOutput(fluid('lava') * 750)
.register()


1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
debug_actually_additions = false
debug_adv_mortars = false
debug_aether = false
debug_alchemistry = false
debug_applied_energistics_2 = false
debug_astral = false
debug_avaritia = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.cleanroommc.groovyscript.compat.mods.actuallyadditions.ActuallyAdditions;
import com.cleanroommc.groovyscript.compat.mods.advancedmortars.AdvancedMortars;
import com.cleanroommc.groovyscript.compat.mods.aetherlegacy.Aether;
import com.cleanroommc.groovyscript.compat.mods.alchemistry.Alchemistry;
import com.cleanroommc.groovyscript.compat.mods.appliedenergistics2.AppliedEnergistics2;
import com.cleanroommc.groovyscript.compat.mods.astralsorcery.AstralSorcery;
import com.cleanroommc.groovyscript.compat.mods.avaritia.Avaritia;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class ModSupport implements IDynamicGroovyProperty {
public static final GroovyContainer<ActuallyAdditions> ACTUALLY_ADDITIONS = new InternalModContainer<>("actuallyadditions", "Actually Additions", ActuallyAdditions::new, "aa");
public static final GroovyContainer<AdvancedMortars> ADVANCED_MORTARS = new InternalModContainer<>("advancedmortars", "Advanced Mortars", AdvancedMortars::new);
public static final GroovyContainer<Aether> AETHER = new InternalModContainer<>("aether_legacy", "The Aether", Aether::new, "aether");
public static final GroovyContainer<Alchemistry> ALCHEMISTRY = new InternalModContainer<>("alchemistry", "Alchemistry", Alchemistry::new);
public static final GroovyContainer<AppliedEnergistics2> APPLIED_ENERGISTICS_2 = new InternalModContainer<>("appliedenergistics2", "Applied Energistics 2", AppliedEnergistics2::new, "ae2");
public static final GroovyContainer<AstralSorcery> ASTRAL_SORCERY = new InternalModContainer<>("astralsorcery", "Astral Sorcery", AstralSorcery::new, "astral");
public static final GroovyContainer<Avaritia> AVARITIA = new InternalModContainer<>("avaritia", "Avaritia", Avaritia::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.cleanroommc.groovyscript.compat.mods.alchemistry;

import al132.alchemistry.chemistry.ChemicalCompound;
import al132.alchemistry.chemistry.ChemicalElement;
import al132.alchemistry.chemistry.CompoundRegistry;
import al132.alchemistry.chemistry.ElementRegistry;
import com.cleanroommc.groovyscript.api.Result;
import com.cleanroommc.groovyscript.compat.mods.ModPropertyContainer;
import com.cleanroommc.groovyscript.gameobjects.GameObjectHandlerManager;

public class Alchemistry extends ModPropertyContainer {

public final Atomizer atomizer = new Atomizer();
public final Combiner combiner = new Combiner();
public final Dissolver dissolver = new Dissolver();
public final Electrolyzer electrolyzer = new Electrolyzer();
public final Evaporator evaporator = new Evaporator();
public final Liquifier liquifier = new Liquifier();

public Alchemistry() {
addRegistry(atomizer);
addRegistry(combiner);
addRegistry(dissolver);
addRegistry(electrolyzer);
addRegistry(evaporator);
addRegistry(liquifier);
// TODO:
// Compound Creation and Element Creation
}

@Override
public void initialize() {
GameObjectHandlerManager.registerGameObjectHandler("alchemistry", "element", (s, args) -> {
String parsedName = s.trim().toLowerCase().replace(" ", "_");
ChemicalCompound compound = CompoundRegistry.INSTANCE.get(parsedName);
if (compound == null || compound.toItemStack(1).isEmpty()) {
ChemicalElement element = ElementRegistry.INSTANCE.get(parsedName);
if (element == null || element.toItemStack(1).isEmpty()) {
return Result.error();
}
return Result.some(element.toItemStack(1));
}
return Result.some(compound.toItemStack(1));
});
}

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

import al132.alchemistry.recipes.AtomizerRecipe;
import al132.alchemistry.recipes.LiquifierRecipe;
import al132.alchemistry.recipes.ModRecipes;
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.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.Nullable;

@RegistryDescription
public class Atomizer extends VirtualizedRegistry<AtomizerRecipe> {

@Override
public void onReload() {
removeScripted().forEach(recipe -> ModRecipes.INSTANCE.getAtomizerRecipes().removeIf(r -> r == recipe));
ModRecipes.INSTANCE.getAtomizerRecipes().addAll(restoreFromBackup());
}

@RecipeBuilderDescription(example = {
@Example(".fluidInput(fluid('water') * 125).output(item('minecraft:clay'))"),
@Example(".fluidInput(fluid('lava') * 500).output(item('minecraft:gold_ingot')).reversible()")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public AtomizerRecipe add(FluidStack input, ItemStack output) {
return new RecipeBuilder().fluidInput(input).output(output).register();
}

public AtomizerRecipe add(AtomizerRecipe recipe) {
if (recipe != null) {
addScripted(recipe);
ModRecipes.INSTANCE.getAtomizerRecipes().add(recipe);
}
return recipe;
}

public boolean remove(AtomizerRecipe recipe) {
if (ModRecipes.INSTANCE.getAtomizerRecipes().removeIf(r -> r == recipe)) {
addBackup(recipe);
return true;
}
return false;
}

@MethodDescription(description = "groovyscript.wiki.removeByOutput", example = @Example(value = "item('alchemistry:compound:7')", commented = true))
public boolean removeByOutput(IIngredient output) {
return ModRecipes.INSTANCE.getAtomizerRecipes().removeIf(r -> {
if (output.test(r.getOutput())) {
addBackup(r);
return true;
}
return false;
});
}

@MethodDescription(description = "groovyscript.wiki.removeByInput", example = @Example("fluid('water')"))
public boolean removeByInput(FluidStack input) {
return ModRecipes.INSTANCE.getAtomizerRecipes().removeIf(r -> {
if (r.getInput().isFluidEqual(input)) {
addBackup(r);
return true;
}
return false;
});
}

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

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

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

@Property
private boolean reversible;

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

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

@Override
public String getErrorMsg() {
return "Error adding Alchemistry Atomizer recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 0, 0, 1, 1);
validateFluids(msg, 1, 1, 0, 0);
}

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

AtomizerRecipe recipe = new AtomizerRecipe(false, fluidInput.get(0), output.get(0));
if (reversible) ModSupport.ALCHEMISTRY.get().liquifier.add(new LiquifierRecipe(output.get(0), fluidInput.get(0)));
ModSupport.ALCHEMISTRY.get().atomizer.add(recipe);
return recipe;
}
}
}
Loading

0 comments on commit 4f1ec82

Please sign in to comment.