Skip to content

Commit

Permalink
Finish GroovyScript integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Dec 26, 2024
1 parent 419affa commit 121e7b7
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- With [**Asgard Shield: Reloaded**](https://www.curseforge.com/minecraft/mc-mods/asgard-shield-reloaded) installed, giant swords and shields are added for Livingmetal and Biomass.
- With [**Blood Magic**](https://www.curseforge.com/minecraft/mc-mods/blood-magic) installed, blood containers like keepers and vessels can be used similarly to the sacrificial dagger to fill a blood altar with LP.
- With [**CraftTweaker**](https://www.curseforge.com/minecraft/mc-mods/crafttweaker) installed, altar ritual recipes can be added and removed. See [this example script](https://github.com/Elite-Modding-Team/HarkenScytheResharpened/blob/main/docs/crafttweaker/example.zs).
- With [**GroovyScript**](https://www.curseforge.com/minecraft/mc-mods/groovyscript) installed, altar ritual recipes can be added and removed. See [this example script](https://github.com/Elite-Modding-Team/HarkenScytheResharpened/blob/main/docs/groovyscript/example.groovy).

### 📖 In-game Guidebook

Expand Down
19 changes: 19 additions & 0 deletions docs/groovyscript/example.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mods.harkenscythe.bloodAltar.recipeBuilder()
.input(item('minecraft:cobblestone'))
.output(item('minecraft:gravel'))
.requiredBlood(42)
.register()

mods.harkenscythe.bloodAltar.removeByInput(item('minecraft:glass_bottle'))
mods.harkenscythe.bloodAltar.removeByOutput(item('harkenscythe:bloodweave_cloth'))
//mods.harkenscythe.bloodAltar.removeAll()

mods.harkenscythe.soulAltar.recipeBuilder()
.input(item('minecraft:gravel'))
.output(item('minecraft:sand'))
.requiredSouls(69)
.register()

mods.harkenscythe.soulAltar.removeByInput(item('minecraft:cookie'))
mods.harkenscythe.soulAltar.removeByOutput(item('harkenscythe:soul_cake'))
//mods.harkenscythe.soulAltar.removeAll()
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package mod.emt.harkenscythe.compat.groovyscript;

import javax.annotation.Nullable;

import net.minecraft.item.ItemStack;

import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
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 mod.emt.harkenscythe.HarkenScythe;
import mod.emt.harkenscythe.init.HSAltarRecipes;
import mod.emt.harkenscythe.recipe.HSRecipeBloodAltar;

@SuppressWarnings("unused")
@RegistryDescription(linkGenerator = HarkenScythe.MOD_ID)
public class HSGroovyScriptBloodAltarRecipes extends VirtualizedRegistry<HSRecipeBloodAltar>
{
public HSGroovyScriptBloodAltarRecipes()
{
super(Alias.generateOf("BloodAltar"));
}

@Override
public void onReload()
{
HSAltarRecipes.getBloodAltarRecipes().removeAll(removeScripted());
HSAltarRecipes.getBloodAltarRecipes().addAll(restoreFromBackup());
}

public void add(HSRecipeBloodAltar t)
{
HSAltarRecipes.getBloodAltarRecipes().add(t);
addScripted(t);
}

public boolean remove(HSRecipeBloodAltar t)
{
if (HSAltarRecipes.getBloodAltarRecipes().remove(t))
{
addBackup(t);
return true;
}
return false;
}

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

@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("item('harkenscythe:bloodweave_cloth')"))
public boolean removeByOutput(IIngredient output)
{
return HSAltarRecipes.getBloodAltarRecipes().removeIf(r -> {
if (output.test(r.getOutput()))
{
addBackup(r);
return true;
}
return false;
});
}

@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("item('minecraft:glass_bottle')"))
public boolean removeByInput(IIngredient input)
{
return HSAltarRecipes.getBloodAltarRecipes().removeIf(r -> {
if (input.test(r.getInput()))
{
addBackup(r);
return true;
}
return false;
});
}

@MethodDescription(type = MethodDescription.Type.REMOVAL, priority = 2000, example = @Example(commented = true))
public void removeAll()
{
HSAltarRecipes.getBloodAltarRecipes().forEach(this::addBackup);
HSAltarRecipes.getBloodAltarRecipes().clear();
}

@RecipeBuilderDescription(example = @Example(".input(item('minecraft:cobblestone')).output(item('minecraft:gravel')).requiredBlood(42)"))
public RecipeBuilder recipeBuilder()
{
return new RecipeBuilder();
}

@Property(property = "input", valid = @Comp("1"))
@Property(property = "output", valid = @Comp("1"))
public static class RecipeBuilder extends AbstractRecipeBuilder<HSRecipeBloodAltar>
{
@Property(valid = @Comp(type = Comp.Type.GTE, value = "1"))
private int requiredBlood;

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

@Override
public String getErrorMsg()
{
return "Error adding Harken Scythe Blood Altar ritual recipe";
}

@Override
public void validate(GroovyLog.Msg msg)
{
validateItems(msg, 1, 1, 1, 1);
msg.add(requiredBlood < 1, "requiredBlood must be 1 or greater");
}

@Override
@Nullable
@RecipeBuilderRegistrationMethod
public HSRecipeBloodAltar register()
{
if (!validate()) return null;
HSRecipeBloodAltar t = null;
for (ItemStack in : input.get(0).getMatchingStacks())
{
t = new HSRecipeBloodAltar(in, output.get(0), requiredBlood);
HSGroovyScriptPlugin.instance.bloodAltar.add(t);
}
return t;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mod.emt.harkenscythe.compat.groovyscript;

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

public class HSGroovyScriptContainer extends GroovyPropertyContainer
{
public final HSGroovyScriptBloodAltarRecipes bloodAltar = new HSGroovyScriptBloodAltarRecipes();
public final HSGroovyScriptSoulAltarRecipes soulAltar = new HSGroovyScriptSoulAltarRecipes();

public HSGroovyScriptContainer()
{
addPropertyFieldsOf(this, false);
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
package mod.emt.harkenscythe.compat.groovyscript;

import com.cleanroommc.groovyscript.GroovyScript;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.api.GroovyPlugin;
import com.cleanroommc.groovyscript.compat.mods.GroovyContainer;
import groovyjarjarantlr4.v4.runtime.misc.NotNull;
import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer;
import com.cleanroommc.groovyscript.documentation.linkgenerator.BasicLinkGenerator;
import com.cleanroommc.groovyscript.documentation.linkgenerator.LinkGeneratorHooks;
import mod.emt.harkenscythe.HarkenScythe;

public class HSGroovyScriptPlugin implements GroovyPlugin
{
@GroovyBlacklist
public static HSGroovyScriptContainer instance;

@Override
public @Nullable GroovyPropertyContainer createGroovyPropertyContainer()
{
if (instance == null) instance = new HSGroovyScriptContainer();
return instance;
}

@Override
public @NotNull String getModId()
public @Nonnull String getModId()
{
return HarkenScythe.MOD_ID;
}

@Override
public @NotNull String getContainerName()
public @Nonnull String getContainerName()
{
return HarkenScythe.NAME;
}

@Override
public void onCompatLoaded(GroovyContainer<?> container)
{
GroovyScript.LOGGER.info(HarkenScythe.NAME + " container loaded");
LinkGeneratorHooks.registerLinkGenerator(new HarkenScytheLinkGenerator());
}

private static class HarkenScytheLinkGenerator extends BasicLinkGenerator
{
@Override
public String id()
{
return HarkenScythe.MOD_ID;
}

@Override
protected String domain()
{
return "https://github.com/Elite-Modding-Team/HarkenScytheResharpened/";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package mod.emt.harkenscythe.compat.groovyscript;

import javax.annotation.Nullable;

import net.minecraft.item.ItemStack;

import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
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 mod.emt.harkenscythe.HarkenScythe;
import mod.emt.harkenscythe.init.HSAltarRecipes;
import mod.emt.harkenscythe.recipe.HSRecipeSoulAltar;

@SuppressWarnings("unused")
@RegistryDescription(linkGenerator = HarkenScythe.MOD_ID)
public class HSGroovyScriptSoulAltarRecipes extends VirtualizedRegistry<HSRecipeSoulAltar>
{
public HSGroovyScriptSoulAltarRecipes()
{
super(Alias.generateOf("SoulAltar"));
}

@Override
public void onReload()
{
HSAltarRecipes.getSoulAltarRecipes().removeAll(removeScripted());
HSAltarRecipes.getSoulAltarRecipes().addAll(restoreFromBackup());
}

public void add(HSRecipeSoulAltar t)
{
HSAltarRecipes.getSoulAltarRecipes().add(t);
addScripted(t);
}

public boolean remove(HSRecipeSoulAltar t)
{
if (HSAltarRecipes.getSoulAltarRecipes().remove(t))
{
addBackup(t);
return true;
}
return false;
}

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

@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("item('harkenscythe:soul_cake')"))
public boolean removeByOutput(IIngredient output)
{
return HSAltarRecipes.getSoulAltarRecipes().removeIf(r -> {
if (output.test(r.getOutput()))
{
addBackup(r);
return true;
}
return false;
});
}

@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("item('minecraft:cookie')"))
public boolean removeByInput(IIngredient input)
{
return HSAltarRecipes.getSoulAltarRecipes().removeIf(r -> {
if (input.test(r.getInput()))
{
addBackup(r);
return true;
}
return false;
});
}

@MethodDescription(type = MethodDescription.Type.REMOVAL, priority = 2000, example = @Example(commented = true))
public void removeAll()
{
HSAltarRecipes.getSoulAltarRecipes().forEach(this::addBackup);
HSAltarRecipes.getSoulAltarRecipes().clear();
}

@RecipeBuilderDescription(example = @Example(".input(item('minecraft:gravel')).output(item('minecraft:sand')).requiredSouls(69)"))
public RecipeBuilder recipeBuilder()
{
return new RecipeBuilder();
}

@Property(property = "input", valid = @Comp("1"))
@Property(property = "output", valid = @Comp("1"))
public static class RecipeBuilder extends AbstractRecipeBuilder<HSRecipeSoulAltar>
{
@Property(valid = @Comp(type = Comp.Type.GTE, value = "1"))
private int requiredSouls;

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

@Override
public String getErrorMsg()
{
return "Error adding Harken Scythe Soul Altar ritual recipe";
}

@Override
public void validate(GroovyLog.Msg msg)
{
validateItems(msg, 1, 1, 1, 1);
msg.add(requiredSouls < 1, "requiredSouls must be 1 or greater");
}

@Override
@Nullable
@RecipeBuilderRegistrationMethod
public HSRecipeSoulAltar register()
{
if (!validate()) return null;
HSRecipeSoulAltar t = null;
for (ItemStack in : input.get(0).getMatchingStacks())
{
t = new HSRecipeSoulAltar(in, output.get(0), requiredSouls);
HSGroovyScriptPlugin.instance.soulAltar.add(t);
}
return t;
}
}
}
Loading

0 comments on commit 121e7b7

Please sign in to comment.