Skip to content

Commit

Permalink
Constraints on input stack size for recipe builder (#222)
Browse files Browse the repository at this point in the history
* Max input capacity: part 1 done (roughly 40% mods)

* Max input capacity: crafting grids, fix NPEs, config

* mark the finished things in gradle

* more work on this

* finished the remaining mods

* this actually works

* refactor, add vanilla furnace

* fix a compile error

* PR fixes

* PR fixes (2)
  • Loading branch information
Wizzerinus authored Oct 6, 2024
1 parent 040a6cd commit 5d177a5
Show file tree
Hide file tree
Showing 115 changed files with 667 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public static class Compat {
@Config.Comment("Enables DE energy core compat. Config is mainly for other mods compat.")
public boolean draconicEvolutionEnergyCore = true;

@Config.Comment("Validate input stack sizes when adding recipes, i.e. disallow adding recipes with input stack size > 1 when the machine's code doesn't check for input count. Disable if you want to write such recipes anyway.")
public boolean checkInputStackCounts = true;

@Config.Name("ExtendedCrafting recipe maker makes grs recipes")
@Config.Comment("If this is true, the recipe maker from ExtendedCrafting will produce a script for GroovyScript instead of CraftTweaker.")
public boolean extendedCraftingRecipeMakerMakesGrsRecipes = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
import com.cleanroommc.groovyscript.compat.mods.astralsorcery.AstralSorcery;
import com.cleanroommc.groovyscript.compat.mods.atum.Atum;
import com.cleanroommc.groovyscript.compat.mods.botaniatweaks.BotaniaTweaks;
import com.cleanroommc.groovyscript.compat.mods.theaurorian.TheAurorian;
import com.cleanroommc.groovyscript.compat.mods.avaritia.Avaritia;
import com.cleanroommc.groovyscript.compat.mods.betterwithmods.BetterWithMods;
import com.cleanroommc.groovyscript.compat.mods.bloodmagic.BloodMagic;
import com.cleanroommc.groovyscript.compat.mods.botania.Botania;
import com.cleanroommc.groovyscript.compat.mods.botanicadditions.BotanicAdditions;
import com.cleanroommc.groovyscript.compat.mods.calculator.Calculator;
import com.cleanroommc.groovyscript.compat.mods.chisel.Chisel;
import com.cleanroommc.groovyscript.compat.mods.cyclic.Cyclic;
import com.cleanroommc.groovyscript.compat.mods.compactmachines.CompactMachines;
import com.cleanroommc.groovyscript.compat.mods.cyclic.Cyclic;
import com.cleanroommc.groovyscript.compat.mods.draconicevolution.DraconicEvolution;
import com.cleanroommc.groovyscript.compat.mods.enderio.EnderIO;
import com.cleanroommc.groovyscript.compat.mods.essentialcraft.EssentialCraft;
Expand Down Expand Up @@ -53,6 +52,7 @@
import com.cleanroommc.groovyscript.compat.mods.tcomplement.TinkersComplement;
import com.cleanroommc.groovyscript.compat.mods.techreborn.TechReborn;
import com.cleanroommc.groovyscript.compat.mods.thaumcraft.Thaumcraft;
import com.cleanroommc.groovyscript.compat.mods.theaurorian.TheAurorian;
import com.cleanroommc.groovyscript.compat.mods.thermalexpansion.ThermalExpansion;
import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.TinkersConstruct;
import com.cleanroommc.groovyscript.compat.mods.woot.Woot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public RecipeBuilder type(Lens type) {
return this;
}

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

@Override
public String getErrorMsg() {
return "Error adding Actually Additions Atomic Reconstructor recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public RecipeBuilder outputDisplay(IBlockState outputDisplay) {
return this;
}

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

@Override
public String getErrorMsg() {
return "Error adding Actually Additions Compost recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public RecipeBuilder chance(int chance) {
return this;
}

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

@Override
public String getErrorMsg() {
return "Error adding Actually Additions Crusher recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ public RecipeBuilder blue(float blue) {
return this;
}

@Override
protected int getMaxItemInput() {
// More than 1 item cannot be placed on the Empowerer or Display Stands
return 1;
}

@Override
public String getErrorMsg() {
return "Error adding Actually Additions Empowerer recipe";
Expand All @@ -168,6 +174,7 @@ public void validate(GroovyLog.Msg msg) {
validateItems(msg, 4, 4, 1, 1);
validateFluids(msg);
msg.add(mainInput == null, "mainInput must be defined");
msg.add(IngredientHelper.overMaxSize(mainInput, 1), "mainInput must have a stack size of 1");
msg.add(energyPerStand < 0, "energyPerStand must be a non negative integer, yet it was {}", energyPerStand);
msg.add(time <= 0, "time must be an integer greater than 0, yet it was {}", time);
msg.add(red < 0 || red > 1, "red must be a float between 0 and 1, yet it was {}", red);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public RecipeBuilder time(int time) {
return this;
}

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

@Override
public String getErrorMsg() {
return "Error adding Aether Enchanter Recipe";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.cleanroommc.groovyscript.compat.mods.aetherlegacy;

import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
import com.gildedgames.the_aether.api.enchantments.AetherEnchantmentFuel;
import net.minecraft.item.ItemStack;
Expand All @@ -18,6 +20,12 @@ public EnchanterFuel() {

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("item('minecraft:blaze_rod'), 1000"))
public void add(ItemStack fuel, int timeGiven) {
if (IngredientHelper.overMaxSize(fuel, 1)) {
GroovyLog.msg("Error adding Enchanter Fuel").error()
.add("Fuel must have stack size of 1, got {}", fuel.getCount())
.post();
return;
}
AetherEnchantmentFuel enchantmentFuel = new AetherEnchantmentFuel(fuel, timeGiven);
add(enchantmentFuel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public RecipeBuilder time(int time) {
return this;
}

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

@Override
public String getErrorMsg() {
return "Error adding Aether Freezer Recipe";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.cleanroommc.groovyscript.compat.mods.aetherlegacy;

import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
import com.gildedgames.the_aether.api.freezables.AetherFreezableFuel;
import net.minecraft.item.ItemStack;
Expand All @@ -18,6 +20,12 @@ public FreezerFuel() {

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("item('minecraft:packed_ice'), 1000"))
public void add(ItemStack fuel, int timeGiven) {
if (IngredientHelper.overMaxSize(fuel, 1)) {
GroovyLog.msg("Error adding Freezer Fuel").error()
.add("Fuel must have stack size of 1, got {}", fuel.getCount())
.post();
return;
}
AetherFreezableFuel freezableFuel = new AetherFreezableFuel(fuel, timeGiven);
add(freezableFuel);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.cleanroommc.groovyscript.compat.mods.appliedenergistics2;

import appeng.api.AEApi;
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.documentation.annotations.Example;
import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription;
import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription;
import com.cleanroommc.groovyscript.core.mixin.appliedenergistics2.MatterCannonAmmoRegistryAccessor;
import com.cleanroommc.groovyscript.helper.Alias;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -27,6 +29,12 @@ public void onReload() {

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("item('minecraft:clay'), 10000"))
public void add(ItemStack item, double value) {
if (IngredientHelper.overMaxSize(item, 1)) {
GroovyLog.msg("Error adding Cannon Ammo").error()
.add("Item must have stack size of 1, got {}", item.getCount())
.post();
return;
}
addScripted(Pair.of(item, value));
((MatterCannonAmmoRegistryAccessor) AEApi.instance().registries().matterCannon()).getDamageModifiers().put(item, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public RecipeBuilder bottom(ItemStack bottom) {
return this;
}

@Override
protected int getMaxItemInput() {
// More than 1 item cannot be placed in the machine's slots
return 1;
}

@Override
public String getErrorMsg() {
return "Error adding Applied Energistics 2 Inscriber recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public RecipeBuilder secondaryChance(float chance) {
return this;
}

@Override
protected int getMaxItemInput() {
// More than 1 item cannot be placed
return 1;
}

@Override
public String getErrorMsg() {
return "Error adding Astral Sorcery Grindstone recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public RecipeBuilder time(int time) {
return this;
}

@Override
protected int getMaxItemInput() {
// More than 1 item cannot be placed
return 1;
}

@Override
public String getErrorMsg() {
return "Error adding Astral Infusion recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.core.mixin.astralsorcery.WellLiquefactionAccessor;
import com.cleanroommc.groovyscript.helper.SimpleObjectStream;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.IRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import hellfirepvp.astralsorcery.common.base.WellLiquefaction;
Expand Down Expand Up @@ -177,6 +178,7 @@ public boolean validate() {
}
if (this.output == null) out.add("No output specified.").error();
if (this.catalyst == null) out.add("No catalyst specified.").error();
if (IngredientHelper.overMaxSize(this.catalyst, 1)) out.add("Catalyst must have a stack size of 1.").error();

out.postIfNotEmpty();
return out.getLevel() != Level.ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void validate(GroovyLog.Msg msg) {
validateItems(msg, 0, Integer.MAX_VALUE, 0, 0);
validateFluids(msg);
msg.add(IngredientHelper.isEmpty(filter), "filter must be defined");
msg.add(IngredientHelper.overMaxSize(filter, 1), "Filter must have stack size of 1, got {}", filter.getAmount());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public String getErrorMsg() {
return "Error adding Better With Mods Kiln recipe";
}

@Override
protected int getMaxItemInput() {
// Uses blocks to craft
return 1;
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 0, 0, 1, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public String getErrorMsg() {
return "Error adding Better With Mods Mill recipe";
}

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

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 3, 1, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public String getErrorMsg() {
return "Error adding Better With Mods Saw recipe";
}

@Override
protected int getMaxItemInput() {
// Uses blocks to craft
return 1;
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 0, 0, 1, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ public String getErrorMsg() {
return "Error adding Better With Mods Turntable recipe";
}

@Override
protected int getMaxItemInput() {
// Uses blocks to craft
return 1;
}

@Override
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 0, 0, 0, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public RecipeBuilder texture(String texture) {
return this;
}

@Override
protected int getMaxItemInput() {
// More than 1 item cannot be placed in the Ashes's slots
return 1;
}

@Override
public String getErrorMsg() {
return "Error adding Blood Magic Alchemy Array recipe";
Expand All @@ -168,6 +174,7 @@ public String getErrorMsg() {
public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 1, 1, 1);
msg.add(catalyst == null, "Must have a catalyst ItemStack but didn't find any!");
msg.add(IngredientHelper.overMaxSize(catalyst, 1), "Catalyst must have a stack size of 1!");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public RecipeBuilder tier(int tier) {
return minimumTier(tier);
}

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

@Override
public String getErrorMsg() {
return "Error adding Blood Magic Alchemy Table recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public RecipeBuilder drainRate(int drainRate) {
return this;
}

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

@Override
public String getErrorMsg() {
return "Error adding Blood Magic Blood Altar recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Collection;
import java.util.Collections;

@RegistryDescription
@RegistryDescription(admonition = @Admonition(value = "groovyscript.wiki.bloodmagic.tartaric_forge.note", type = Admonition.Type.WARNING))
public class TartaricForge extends StandardListRegistry<RecipeTartaricForge> {

@RecipeBuilderDescription(example = {
Expand Down Expand Up @@ -125,6 +125,11 @@ public RecipeBuilder drain(int drain) {
return soulDrain(drain);
}

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

@Override
public String getErrorMsg() {
return "Error adding Blood Magic Tartaric Forge recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public boolean removeByInputs(IIngredient... inputs) {
@Property(property = "output", comp = @Comp(eq = 1))
public class RecipeBuilder extends AbstractRecipeBuilder<RecipePetals> {

@Override
protected int getMaxItemInput() {
// Each slot of Apothecary can only contain 1 item
return 1;
}

@Override
public String getErrorMsg() {
return "Error adding Botania Apothecary recipe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public RecipeBuilder useConjuration() {
return catalyst(RecipeManaInfusion.conjurationState);
}

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

@Override
public String getErrorMsg() {
return "Error adding Botania Mana Infusion recipe";
Expand Down
Loading

0 comments on commit 5d177a5

Please sign in to comment.