Skip to content

added lightningcraft compat #283

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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 @@ -84,6 +84,7 @@ final def mod_dependencies = [
'integrated-dynamics-236307:3159505' : [project.debug_integrated_dynamics],
'lazy-ae2-322347:3254160' : [project.debug_lazy_ae2],
'libnine-322344:3509087' : [project.debug_lazy_ae2],
'lightningcraft-237422:2872478' : [project.debug_lightningcraft],
'magneticraft-224808:3791484' : [project.debug_magneticraft],
'modelloader-277663:2744735' : [project.debug_magneticraft],
'mekanism-268560:2835175' : [project.debug_mekanism],
Expand Down
40 changes: 40 additions & 0 deletions examples/postInit/lightningcraft.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

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

log.info 'mod \'lightningcraft\' detected, running script'

// Lightning Crusher:
// Consumes LE to convert 1 input itemstack into an output itemstack.

mods.lightningcraft.crusher.removeByInput(item('minecraft:saddle'))
mods.lightningcraft.crusher.removeByOutput(item('minecraft:redstone'))
// mods.lightningcraft.crusher.removeAll()

mods.lightningcraft.crusher.recipeBuilder()
.input(item('minecraft:diamond_block'))
.output(item('minecraft:nether_star'))
.register()


// Lightning Infusion Table:
// Consumes LE to convert up to 5 input itemstacks into an output itemstack.

mods.lightningcraft.infusion.removeByOutput(item('minecraft:diamond'))
// mods.lightningcraft.infusion.removeAll()

mods.lightningcraft.infusion.recipeBuilder()
.centerItem(item('minecraft:clay'))
.input(item('minecraft:gold_ingot'), item('minecraft:gold_ingot'), item('minecraft:iron_ingot'), item('minecraft:iron_ingot'))
.output(item('minecraft:nether_star'))
.le(500)
.register()

mods.lightningcraft.infusion.recipeBuilder()
.centerItem(item('minecraft:clay'))
.input(item('minecraft:gold_ingot'), item('minecraft:potion').withNbt(['Potion': 'minecraft:leaping']))
.output(item('minecraft:diamond_block'))
.le(200)
.register()


1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ debug_inspirations = false
debug_integrated_dynamics = false

debug_lazy_ae2 = false
debug_lightningcraft = false

debug_magneticraft = false
debug_mekanism = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.cleanroommc.groovyscript.compat.mods.integrateddynamics.IntegratedDynamics;
import com.cleanroommc.groovyscript.compat.mods.jei.JustEnoughItems;
import com.cleanroommc.groovyscript.compat.mods.lazyae2.LazyAE2;
import com.cleanroommc.groovyscript.compat.mods.lightningcraft.LightningCraft;
import com.cleanroommc.groovyscript.compat.mods.magneticraft.Magneticraft;
import com.cleanroommc.groovyscript.compat.mods.mekanism.Mekanism;
import com.cleanroommc.groovyscript.compat.mods.mysticalagriculture.MysticalAgriculture;
Expand Down Expand Up @@ -124,6 +125,7 @@ public class ModSupport {
public static final GroovyContainer<Mekanism> MEKANISM = new InternalModContainer<>("mekanism", "Mekanism", Mekanism::new);
public static final GroovyContainer<MysticalAgriculture> MYSTICAL_AGRICULTURE = new InternalModContainer<>("mysticalagriculture", "Mystical Agriculture", MysticalAgriculture::new);
public static final GroovyContainer<LazyAE2> LAZYAE2 = new InternalModContainer<>("threng", "LazyAE2", LazyAE2::new, "lazyae2");
public static final GroovyContainer<LightningCraft> LIGHTNINGCRAFT = new InternalModContainer<>("lightningcraft", "LightningCraft", LightningCraft::new);
public static final GroovyContainer<NaturesAura> NATURES_AURA = new InternalModContainer<>("naturesaura", "Nature's Aura", NaturesAura::new);
public static final GroovyContainer<PneumaticCraft> PNEUMATIC_CRAFT = new InternalModContainer<>("pneumaticcraft", "PneumaticCraft: Repressurized", PneumaticCraft::new);
public static final GroovyContainer<PrimalTech> PRIMAL_TECH = new InternalModContainer<>("primal_tech", "Primal Tech", PrimalTech::new, "primaltech");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.cleanroommc.groovyscript.compat.mods.lightningcraft;

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 net.minecraft.item.ItemStack;
import org.jetbrains.annotations.Nullable;
import sblectric.lightningcraft.api.recipes.LightningCrusherRecipe;
import sblectric.lightningcraft.recipes.LightningCrusherRecipes;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@RegistryDescription
public class Crusher extends StandardListRegistry<LightningCrusherRecipe> {

@Override
public Collection<LightningCrusherRecipe> getRecipes() {
return LightningCrusherRecipes.instance().getRecipeList();
}

@MethodDescription(example = @Example("item('minecraft:saddle')"))
public boolean removeByInput(IIngredient input) {
return getRecipes().removeIf(r -> r.getInput().stream().anyMatch(input) && doAddBackup(r));
}

@MethodDescription(example = @Example("item('minecraft:redstone')"))
public boolean removeByOutput(IIngredient output) {
return getRecipes().removeIf(r -> output.test(r.getOutput()) && doAddBackup(r));
}

@RecipeBuilderDescription(example = @Example(".input(item('minecraft:diamond_block')).output(item('minecraft:nether_star'))"))
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

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

@Override
public String getErrorMsg() {
return "Error adding LightningCraft Crusher recipe";
}

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

@Override
protected int getMaxItemInput() {
return 1;
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable LightningCrusherRecipe register() {
if (!validate()) return null;
List<ItemStack> inputs = Arrays.asList(input.get(0).getMatchingStacks());
LightningCrusherRecipe recipe = new LightningCrusherRecipe(output.get(0), inputs);
ModSupport.LIGHTNINGCRAFT.get().crusher.add(recipe);
return recipe;
}
}

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

import com.cleanroommc.groovyscript.GroovyScriptConfig;
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 net.minecraft.item.ItemStack;
import org.jetbrains.annotations.Nullable;
import sblectric.lightningcraft.api.recipes.LightningInfusionRecipe;
import sblectric.lightningcraft.recipes.LightningInfusionRecipes;

import java.util.Collection;

@RegistryDescription
public class Infusion extends StandardListRegistry<LightningInfusionRecipe> {

@Override
public Collection<LightningInfusionRecipe> getRecipes() {
return LightningInfusionRecipes.instance().getRecipeList();
}

@MethodDescription(example = @Example("item('minecraft:diamond')"))
public boolean removeByOutput(IIngredient output) {
return getRecipes().removeIf(r -> output.test(r.getOutput()) && doAddBackup(r));
}

@RecipeBuilderDescription(example = {
@Example(".centerItem(item('minecraft:clay')).input(item('minecraft:gold_ingot'), item('minecraft:gold_ingot'), item('minecraft:iron_ingot'), item('minecraft:iron_ingot')).output(item('minecraft:nether_star')).le(500)"),
@Example(".centerItem(item('minecraft:clay')).input(item('minecraft:gold_ingot'), item('minecraft:potion').withNbt(['Potion': 'minecraft:leaping'])).output(item('minecraft:diamond_block')).le(200)"),
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@Property(property = "input", comp = @Comp(gte = 0, lte = 4))
@Property(property = "output", comp = @Comp(eq = 1))
public static class RecipeBuilder extends AbstractRecipeBuilder<LightningInfusionRecipe> {

@Property()
private IIngredient centerItem = null;

@Property(comp = @Comp(gte = 0), defaultValue = "-1")
private int le = -1;

@Property(defaultValue = "determined automatically based on the input items")
private boolean nbtSensitive = false;
Comment on lines +48 to +49
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why having this be directly configurable by the player is required? if it can be automatically determined, why not simply not expose it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are cases where it's automatically configured value is wrong. For example, if you want to allow only input item that has no NBT in it (say, it's some tool that stores durability in NBT). You need to enable nbtSensitive = true, and there's not really another way to do it


private boolean nbtSensitiveChanged = false;

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

@RecipeBuilderMethodDescription(field = "le")
public RecipeBuilder cost(int le) {
this.le = le;
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder nbtSensitive(boolean nbtSensitive) {
this.nbtSensitive = nbtSensitive;
nbtSensitiveChanged = true;
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder centerItem(IIngredient centerItem) {
this.centerItem = centerItem;
return this;
}

@Override
public String getErrorMsg() {
return "Error adding LightningCraft Infusion Table recipe";
}

@Override
protected int getMaxItemInput() {
// recipes with more than 1 item in some slot don't get recognized
return 1;
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 0, 4, 1, 1);
validateFluids(msg);
msg.add(centerItem == null, "Center item must not be null");
msg.add(centerItem != null && centerItem.getMatchingStacks().length == 0, "Center item must not have a matching item");
msg.add(le < 0, "LE cost must be positive");
for (IIngredient it : this.input) {
msg.add(it == null || it.getMatchingStacks().length == 0, "All inputs must have a matching item");
}
if (GroovyScriptConfig.compat.checkInputStackCounts && centerItem != null) {
msg.add(centerItem.getAmount() > 1, "Expected stack size of 1 for {}, got {}", centerItem, centerItem.getAmount());
}
}

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

ItemStack centerItem = this.centerItem.getMatchingStacks()[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should loop for each of getMatchingStacks() instead of only taking the first.

ItemStack[] inputs = input.stream().map(i -> i.getMatchingStacks()[0]).toArray(ItemStack[]::new);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while it is not currently on main and is still just in the Betweenlands PR, IngredientHelper.cartesianProductItemStacks would be very useful here to, once again, use all values of getMatchingStacks() instead of just the first.


// check if any input items have NBT to enable NBT sensitive mode automatically
if (!nbtSensitiveChanged) {
if (centerItem.hasTagCompound()) {
nbtSensitive = true;
} else {
for (ItemStack i : inputs) {
if (i.hasTagCompound()) {
nbtSensitive = true;
break;
}
}
}
}

LightningInfusionRecipe recipe = new LightningInfusionRecipe(output.get(0), le, centerItem, (Object[]) inputs);
if (nbtSensitive) recipe.setNBTSensitive();
ModSupport.LIGHTNINGCRAFT.get().infusion.add(recipe);
return recipe;
}
}

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

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

public class LightningCraft extends GroovyPropertyContainer {

public final Infusion infusion = new Infusion();
public final Crusher crusher = new Crusher();

}
11 changes: 11 additions & 0 deletions src/main/resources/assets/groovyscript/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,17 @@ groovyscript.wiki.threng.etcher.top.value=Sets the top slot of the recipe
groovyscript.wiki.threng.etcher.bottom.value=Sets the bottom slot of the recipe


# LightningCraft
groovyscript.wiki.lightningcraft.crusher.title=Lightning Crusher
groovyscript.wiki.lightningcraft.crusher.description=Consumes LE to convert 1 input itemstack into an output itemstack

groovyscript.wiki.lightningcraft.infusion.title=Lightning Infusion Table
groovyscript.wiki.lightningcraft.infusion.description=Consumes LE to convert up to 5 input itemstacks into an output itemstack
groovyscript.wiki.lightningcraft.infusion.centerItem.value=Sets the center slot of the recipe
groovyscript.wiki.lightningcraft.infusion.le.value=Sets the LE cost for the recipe
groovyscript.wiki.lightningcraft.infusion.nbtSensitive.value=Sets whether the recipe inputs require a specific NBT tag


# Magneticraft
groovyscript.wiki.magneticraft.crushing_table.title=Crushing Table
groovyscript.wiki.magneticraft.crushing_table.description=Converts an input itemstack into an output itemstack when placed on top of the Crushing Table and interacted with by a Hammer which has
Expand Down