generated from CleanroomMC/TemplateDevEnv
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74a7797
commit 109b425
Showing
11 changed files
with
729 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Cyclic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
126 changes: 126 additions & 0 deletions
126
src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Dehydrator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Hydrator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.