-
Notifications
You must be signed in to change notification settings - Fork 30
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
5489e20
fed0149
6cecfcb
71331e2
3641ccd
c5a023b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() | ||
|
||
|
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; | ||
brachy84 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Property(defaultValue = "determined automatically based on the input items") | ||
private boolean nbtSensitive = false; | ||
Comment on lines
+48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
} | ||
Wizzerinus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
@RecipeBuilderRegistrationMethod | ||
public @Nullable LightningInfusionRecipe register() { | ||
if (!validate()) return null; | ||
|
||
ItemStack centerItem = this.centerItem.getMatchingStacks()[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should loop for each of |
||
ItemStack[] inputs = input.stream().map(i -> i.getMatchingStacks()[0]).toArray(ItemStack[]::new); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while it is not currently on |
||
|
||
// 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(); | ||
Wizzerinus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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(); | ||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.