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 Cyclic compat #194

Merged
merged 1 commit into from
Jul 23, 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
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ final def mod_dependencies = [
'chisel-235279:2915375' : [project.debug_chisel],
'ctm-267602:2915363' : [project.debug_chisel],
'compact-machines-224218:2707509' : [project.debug_compact_machines],
'cyclic-239286:4075832' : [project.debug_cyclic],
'brandons_core-231382:3408276' : [project.debug_draconic_evolution],
'draconic_evolution-223565:3431261' : [project.debug_draconic_evolution],
'redstone_flux-270789:2920436' : [project.debug_draconic_evolution, project.debug_thermal],
Expand Down
102 changes: 102 additions & 0 deletions examples/postInit/cyclicmagic.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

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

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

// DeHydrator:
// Converts an input itemstack into an output itemstack.

mods.cyclicmagic.dehydrator.removeByInput(item('minecraft:clay'))
mods.cyclicmagic.dehydrator.removeByOutput(item('minecraft:deadbush'))
// mods.cyclicmagic.dehydrator.removeAll()

mods.cyclicmagic.dehydrator.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.output(item('minecraft:clay'))
.register()

mods.cyclicmagic.dehydrator.recipeBuilder()
.input(ore('logWood'))
.output(item('minecraft:clay') * 8)
.time(100)
.water(30)
.register()


// Hydrator:
// Converts up to 4 input itemstacks and some amount of water into an output itemstack.

mods.cyclicmagic.hydrator.removeByInput(item('minecraft:dirt'))
mods.cyclicmagic.hydrator.removeByOutput(item('minecraft:clay_ball'))
// mods.cyclicmagic.hydrator.removeAll()

mods.cyclicmagic.hydrator.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.output(item('minecraft:clay'))
.register()

mods.cyclicmagic.hydrator.recipeBuilder()
.input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond'))
.output(item('minecraft:clay') * 8)
.water(100)
.register()


// Melter:
// Converts up to 4 input itemstacks into an output itemstack, while being placed above lava.

mods.cyclicmagic.melter.removeByInput(item('minecraft:snow'))
mods.cyclicmagic.melter.removeByOutput(fluid('amber'))
// mods.cyclicmagic.melter.removeAll()

mods.cyclicmagic.melter.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.fluidOutput(fluid('water') * 175)
.register()

mods.cyclicmagic.melter.recipeBuilder()
.input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond'))
.fluidOutput(fluid('lava') * 500)
.register()


// Packager:
// Converts up to 6 input itemstacks into an output itemstack.

mods.cyclicmagic.packager.removeByInput(item('minecraft:grass'))
mods.cyclicmagic.packager.removeByOutput(item('minecraft:melon_block'))
// mods.cyclicmagic.packager.removeAll()

mods.cyclicmagic.packager.recipeBuilder()
.input(item('minecraft:gold_ingot'))
.output(item('minecraft:clay'))
.register()

mods.cyclicmagic.packager.recipeBuilder()
.input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond'), item('minecraft:diamond_block'), item('minecraft:gold_block'))
.output(item('minecraft:clay') * 4)
.register()


// Solidifier:
// Converts up to 4 input itemstacks and an input fluidstack into an output itemstack.

mods.cyclicmagic.solidifier.removeByInput(fluid('water'))
mods.cyclicmagic.solidifier.removeByInput(item('minecraft:bucket'))
mods.cyclicmagic.solidifier.removeByOutput(item('cyclicmagic:crystallized_obsidian'))
// mods.cyclicmagic.solidifier.removeAll()

mods.cyclicmagic.solidifier.recipeBuilder()
.input(item('minecraft:clay'))
.fluidInput(fluid('water') * 175)
.output(item('minecraft:gold_ingot') * 3)
.register()

mods.cyclicmagic.solidifier.recipeBuilder()
.input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond'))
.fluidInput(fluid('lava') * 500)
.output(item('minecraft:clay') * 2)
.register()


1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ debug_botania = false
debug_calculator = false
debug_chisel = false
debug_compact_machines = false
debug_cyclic = false
debug_draconic_evolution = false
debug_enderio = false
debug_essentialcraft_4 = 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.botania.Botania;
import com.cleanroommc.groovyscript.compat.mods.calculator.Calculator;
import com.cleanroommc.groovyscript.compat.mods.chisel.Chisel;
import com.cleanroommc.groovyscript.compat.mods.cyclic.Cyclic;
import com.cleanroommc.groovyscript.compat.mods.compactmachines.CompactMachines;
import com.cleanroommc.groovyscript.compat.mods.draconicevolution.DraconicEvolution;
import com.cleanroommc.groovyscript.compat.mods.enderio.EnderIO;
Expand Down Expand Up @@ -81,6 +82,7 @@ public class ModSupport {
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");
public static final GroovyContainer<Cyclic> CYCLIC = new InternalModContainer<>("cyclicmagic", "Cyclic", Cyclic::new, "cyclic");
public static final GroovyContainer<DraconicEvolution> DRACONIC_EVOLUTION = new InternalModContainer<>("draconicevolution", "Draconic Evolution", DraconicEvolution::new, "de");
public static final GroovyContainer<EnderIO> ENDER_IO = new InternalModContainer<>("enderio", "Ender IO", EnderIO::new, "eio");
public static final GroovyContainer<EssentialCraft> ESSENTIALCRAFT = new InternalModContainer<>("essentialcraft", "EssentialCraft 4", EssentialCraft::new, "ec4");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cleanroommc.groovyscript.compat.mods.cyclic;

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

public class Cyclic extends GroovyPropertyContainer {

public final Dehydrator dehydrator = new Dehydrator();
public final Hydrator hydrator = new Hydrator();
public final Melter melter = new Melter();
public final Packager packager = new Packager();
public final Solidifier solidifier = new Solidifier();

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

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
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 com.lothrazar.cyclicmagic.block.dehydrator.RecipeDeHydrate;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.Nullable;

@RegistryDescription
public class Dehydrator extends VirtualizedRegistry<RecipeDeHydrate> {

@RecipeBuilderDescription(example = {
@Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay'))"),
@Example(".input(ore('logWood')).output(item('minecraft:clay') * 8).time(100).water(30)")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@Override
@GroovyBlacklist
public void onReload() {
RecipeDeHydrate.recipes.removeAll(removeScripted());
RecipeDeHydrate.recipes.addAll(restoreFromBackup());
}

public void add(RecipeDeHydrate recipe) {
if (recipe == null) return;
addScripted(recipe);
RecipeDeHydrate.recipes.add(recipe);
}

public boolean remove(RecipeDeHydrate recipe) {
if (recipe == null) return false;
addBackup(recipe);
RecipeDeHydrate.recipes.remove(recipe);
return true;
}

@MethodDescription(example = @Example("item('minecraft:clay')"))
public boolean removeByInput(IIngredient input) {
return RecipeDeHydrate.recipes.removeIf(recipe -> {
if (input.test(recipe.getRecipeInput())) {
addBackup(recipe);
return true;
}
return false;
});
}

@MethodDescription(example = @Example("item('minecraft:deadbush')"))
public boolean removeByOutput(IIngredient output) {
return RecipeDeHydrate.recipes.removeIf(recipe -> {
if (output.test(recipe.getRecipeOutput())) {
addBackup(recipe);
return true;
}
return false;
});
}

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

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

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

@Property(defaultValue = "100", valid = @Comp(value = "0", type = Comp.Type.GTE))
private int water = 100;
@Property(defaultValue = "10", valid = @Comp(value = "0", type = Comp.Type.GTE))
private int time = 10;

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

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

@Override
public String getErrorMsg() {
return "Error adding Cyclic Dehydrator recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 1, 1, 1);
validateFluids(msg);
msg.add(water < 0, "water must be a non-negative integer, yet it was {}", water);
msg.add(time < 0, "time must be a non-negative integer, yet it was {}", time);
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable RecipeDeHydrate register() {
if (!validate()) return null;
RecipeDeHydrate recipe = null;
for (ItemStack matchingStack : input.get(0).toMcIngredient().getMatchingStacks()) {
recipe = new RecipeDeHydrate(matchingStack, output.get(0), time, water);
ModSupport.CYCLIC.get().dehydrator.add(recipe);
}
return recipe;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.cleanroommc.groovyscript.compat.mods.cyclic;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
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 com.google.common.collect.Lists;
import com.lothrazar.cyclicmagic.block.hydrator.RecipeHydrate;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RegistryDescription
public class Hydrator extends VirtualizedRegistry<RecipeHydrate> {

@RecipeBuilderDescription(example = {
@Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay'))"),
@Example(".input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond')).output(item('minecraft:clay') * 8).water(100)")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@Override
@GroovyBlacklist
public void onReload() {
RecipeHydrate.recipes.removeAll(removeScripted());
RecipeHydrate.recipes.addAll(restoreFromBackup());
}

public void add(RecipeHydrate recipe) {
if (recipe == null) return;
addScripted(recipe);
RecipeHydrate.recipes.add(recipe);
}

public boolean remove(RecipeHydrate recipe) {
if (recipe == null) return false;
addBackup(recipe);
RecipeHydrate.recipes.remove(recipe);
return true;
}

@MethodDescription(example = @Example("item('minecraft:dirt')"))
public boolean removeByInput(IIngredient input) {
return RecipeHydrate.recipes.removeIf(recipe -> {
if (recipe.getRecipeInput().stream().anyMatch(input)) {
addBackup(recipe);
return true;
}
return false;
});
}

@MethodDescription(example = @Example("item('minecraft:clay_ball')"))
public boolean removeByOutput(IIngredient output) {
return RecipeHydrate.recipes.removeIf(recipe -> {
if (output.test(recipe.getRecipeOutput())) {
addBackup(recipe);
return true;
}
return false;
});
}

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

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

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

@Property(defaultValue = "25", valid = @Comp(value = "0", type = Comp.Type.GTE))
private int water = 25;

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

@Override
public String getErrorMsg() {
return "Error adding Cyclic Hydrator recipe";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 6, 1, 1);
validateFluids(msg);
msg.add(water < 0, "water must be a non-negative integer, yet it was {}", water);
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable RecipeHydrate register() {
if (!validate()) return null;
RecipeHydrate recipe = null;
List<List<ItemStack>> cartesian = Lists.cartesianProduct(input.stream().map(x -> Arrays.asList(x.toMcIngredient().getMatchingStacks())).collect(Collectors.toList()));
for (List<ItemStack> stacks : cartesian) {
recipe = new RecipeHydrate(stacks.toArray(new ItemStack[0]), output.get(0), water);
ModSupport.CYCLIC.get().hydrator.add(recipe);
}
return recipe;
}
}
}
Loading