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.
* Random Things * uni <3 !!!! * dont log uni if no inputs
- Loading branch information
1 parent
73e8d24
commit 12e61c8
Showing
8 changed files
with
249 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,47 @@ | ||
|
||
// Auto generated groovyscript example file | ||
// MODS_LOADED: randomthings | ||
|
||
log.info 'mod \'randomthings\' detected, running script' | ||
|
||
// Anvil Crafting: | ||
// Converts two itemstacks into an itemstack in the Vanilla Anvil. | ||
|
||
mods.randomthings.anvil.removeByInput(item('randomthings:obsidianskull')) | ||
mods.randomthings.anvil.removeByOutput(item('randomthings:lavawader')) | ||
// mods.randomthings.anvil.removeAll() | ||
|
||
mods.randomthings.anvil.recipeBuilder() | ||
.input(item('minecraft:diamond_sword'), item('minecraft:boat')) | ||
.output(item('minecraft:diamond')) | ||
.cost(1) | ||
.register() | ||
|
||
mods.randomthings.anvil.recipeBuilder() | ||
.input(item('minecraft:iron_sword'), item('minecraft:boat')) | ||
.output(item('minecraft:gold_ingot') * 16) | ||
.cost(50) | ||
.register() | ||
|
||
|
||
// Imbuing Station: | ||
// Converts four itemstacks into an itemstack in the Random Things Imbuing Station. | ||
|
||
mods.randomthings.imbuing.removeByInput(item('minecraft:coal')) | ||
mods.randomthings.imbuing.removeByInput(item('minecraft:cobblestone')) | ||
mods.randomthings.imbuing.removeByOutput(item('randomthings:imbue:3')) | ||
// mods.randomthings.imbuing.removeAll() | ||
|
||
mods.randomthings.imbuing.recipeBuilder() | ||
.mainInput(item('minecraft:clay')) | ||
.input(item('minecraft:clay'), item('minecraft:gold_ingot'), item('minecraft:gold_block')) | ||
.output(item('minecraft:diamond') * 8) | ||
.register() | ||
|
||
mods.randomthings.imbuing.recipeBuilder() | ||
.mainInput(item('minecraft:diamond')) | ||
.input(item('minecraft:clay'), item('minecraft:gold_ingot'), item('minecraft:diamond')) | ||
.output(item('minecraft:gold_ingot')) | ||
.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
84 changes: 84 additions & 0 deletions
84
src/main/java/com/cleanroommc/groovyscript/compat/mods/randomthings/Anvil.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,84 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.randomthings; | ||
|
||
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.recipe.AbstractRecipeBuilder; | ||
import com.cleanroommc.groovyscript.registry.StandardListRegistry; | ||
import lumien.randomthings.recipes.anvil.AnvilRecipe; | ||
import lumien.randomthings.recipes.anvil.AnvilRecipeHandler; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collection; | ||
|
||
@RegistryDescription(admonition = { | ||
@Admonition(value = "groovyscript.wiki.randomthings.anvil.note0", type = Admonition.Type.TIP), | ||
@Admonition(value = "groovyscript.wiki.randomthings.anvil.note1", type = Admonition.Type.WARNING), | ||
@Admonition(value = "groovyscript.wiki.randomthings.anvil.note2", type = Admonition.Type.BUG, format = Admonition.Format.STANDARD), | ||
}) | ||
public class Anvil extends StandardListRegistry<AnvilRecipe> { | ||
|
||
@RecipeBuilderDescription(example = { | ||
@Example(".input(item('minecraft:diamond_sword'), item('minecraft:boat')).output(item('minecraft:diamond')).cost(1)"), | ||
@Example(".input(item('minecraft:iron_sword'), item('minecraft:boat')).output(item('minecraft:gold_ingot') * 16).cost(50)") | ||
}) | ||
public RecipeBuilder recipeBuilder() { | ||
return new RecipeBuilder(); | ||
} | ||
|
||
@Override | ||
public Collection<AnvilRecipe> getRecipes() { | ||
return AnvilRecipeHandler.getAllRecipes(); | ||
} | ||
|
||
@MethodDescription(example = @Example("item('randomthings:obsidianskull')")) | ||
public boolean removeByInput(IIngredient input) { | ||
return getRecipes().removeIf(r -> (input.test(r.getFirst()) || input.test(r.getSecond())) && doAddBackup(r)); | ||
} | ||
|
||
@MethodDescription(example = @Example("item('randomthings:lavawader')")) | ||
public boolean removeByOutput(IIngredient output) { | ||
return getRecipes().removeIf(r -> output.test(r.getOutput()) && doAddBackup(r)); | ||
} | ||
|
||
@Property(property = "input", comp = @Comp(eq = 2)) | ||
@Property(property = "output", comp = @Comp(eq = 1)) | ||
public static class RecipeBuilder extends AbstractRecipeBuilder<AnvilRecipe> { | ||
|
||
@Property(comp = @Comp(gt = 0)) | ||
private int cost; | ||
|
||
@RecipeBuilderMethodDescription | ||
public RecipeBuilder cost(int cost) { | ||
this.cost = cost; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getErrorMsg() { | ||
return "Error adding Random Things Anvil recipe"; | ||
} | ||
|
||
@Override | ||
public void validate(GroovyLog.Msg msg) { | ||
validateItems(msg, 2, 2, 1, 1); | ||
validateFluids(msg); | ||
msg.add(cost <= 0, "cost must be greater than 0, yet it was {}", cost); | ||
} | ||
|
||
@Override | ||
@RecipeBuilderRegistrationMethod | ||
public @Nullable AnvilRecipe register() { | ||
if (!validate()) return null; | ||
AnvilRecipe recipe = null; | ||
for (var input1 : input.get(0).getMatchingStacks()) { | ||
for (var input2 : input.get(1).getMatchingStacks()) { | ||
recipe = new AnvilRecipe(input1, input2, output.get(0), cost); | ||
ModSupport.RANDOM_THINGS.get().anvil.add(recipe); | ||
} | ||
} | ||
return recipe; | ||
} | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/com/cleanroommc/groovyscript/compat/mods/randomthings/Imbuing.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,90 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.randomthings; | ||
|
||
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.recipe.AbstractRecipeBuilder; | ||
import com.cleanroommc.groovyscript.registry.StandardListRegistry; | ||
import com.google.common.collect.Lists; | ||
import lumien.randomthings.recipes.imbuing.ImbuingRecipe; | ||
import lumien.randomthings.recipes.imbuing.ImbuingRecipeHandler; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.crafting.Ingredient; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
|
||
@RegistryDescription | ||
public class Imbuing extends StandardListRegistry<ImbuingRecipe> { | ||
|
||
@RecipeBuilderDescription(example = { | ||
@Example(".mainInput(item('minecraft:clay')).input(item('minecraft:clay'), item('minecraft:gold_ingot'), item('minecraft:gold_block')).output(item('minecraft:diamond') * 8)"), | ||
@Example(".mainInput(item('minecraft:diamond')).input(item('minecraft:clay'), item('minecraft:gold_ingot'), item('minecraft:diamond')).output(item('minecraft:gold_ingot'))") | ||
}) | ||
public RecipeBuilder recipeBuilder() { | ||
return new RecipeBuilder(); | ||
} | ||
|
||
@Override | ||
public Collection<ImbuingRecipe> getRecipes() { | ||
return ImbuingRecipeHandler.imbuingRecipes; | ||
} | ||
|
||
@MethodDescription(example = { | ||
@Example("item('minecraft:cobblestone')"), @Example("item('minecraft:coal')") | ||
}) | ||
public boolean removeByInput(IIngredient input) { | ||
return getRecipes().removeIf(r -> (input.test(r.toImbue()) || r.getIngredients().stream().anyMatch(input)) && doAddBackup(r)); | ||
} | ||
|
||
@MethodDescription(example = @Example("item('randomthings:imbue:3')")) | ||
public boolean removeByOutput(IIngredient output) { | ||
return getRecipes().removeIf(r -> output.test(r.getResult()) && doAddBackup(r)); | ||
} | ||
|
||
@Property(property = "input", comp = @Comp(eq = 3, unique = "groovyscript.wiki.randomthings.imbuing.input.required")) | ||
@Property(property = "output", comp = @Comp(eq = 1)) | ||
public static class RecipeBuilder extends AbstractRecipeBuilder<ImbuingRecipe> { | ||
|
||
@Property(comp = @Comp(not = "null")) | ||
private IIngredient mainInput; | ||
|
||
@RecipeBuilderMethodDescription | ||
public RecipeBuilder mainInput(IIngredient mainInput) { | ||
this.mainInput = mainInput; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getErrorMsg() { | ||
return "Error adding Random Things Imbuing recipe"; | ||
} | ||
|
||
@Override | ||
public void validate(GroovyLog.Msg msg) { | ||
validateItems(msg, 3, 3, 1, 1); | ||
validateFluids(msg); | ||
msg.add(mainInput == null, "mainInput must be defined"); | ||
var uni = input.stream().distinct().count(); | ||
msg.add(uni > 0 && uni < 3, "each input must be unique, yet only {}/3 of the inputs were unique. mainInput is not considered", uni); | ||
} | ||
|
||
@Override | ||
@RecipeBuilderRegistrationMethod | ||
public @Nullable ImbuingRecipe register() { | ||
if (!validate()) return null; | ||
ImbuingRecipe recipe = null; | ||
var cartesian = Lists.cartesianProduct(input.stream().map(IIngredient::toMcIngredient).map(Ingredient::getMatchingStacks).map(Arrays::asList).collect(Collectors.toList())); | ||
for (var toImbue : mainInput.getMatchingStacks()) { | ||
for (var stacks : cartesian) { | ||
recipe = new ImbuingRecipe(toImbue, output.get(0), stacks.toArray(new ItemStack[0])); | ||
ModSupport.RANDOM_THINGS.get().imbuing.add(recipe); | ||
} | ||
} | ||
return recipe; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/cleanroommc/groovyscript/compat/mods/randomthings/RandomThings.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,10 @@ | ||
package com.cleanroommc.groovyscript.compat.mods.randomthings; | ||
|
||
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer; | ||
|
||
public class RandomThings extends GroovyPropertyContainer { | ||
|
||
public final Imbuing imbuing = new Imbuing(); | ||
public final Anvil anvil = new Anvil(); | ||
|
||
} |
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