diff --git a/src/main/java/modtweaker2/mods/botania/handlers/Lexicon.java b/src/main/java/modtweaker2/mods/botania/handlers/Lexicon.java index 5b8e72c..b0b910e 100644 --- a/src/main/java/modtweaker2/mods/botania/handlers/Lexicon.java +++ b/src/main/java/modtweaker2/mods/botania/handlers/Lexicon.java @@ -7,6 +7,8 @@ import static modtweaker2.helpers.InputHelper.toStack; import java.util.ArrayList; import java.util.List; +import net.minecraft.item.ItemStack; +import net.minecraft.init.Blocks; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; @@ -359,7 +361,7 @@ public class Lexicon { } @ZenMethod - public static void addEntry(String entry, String catagory) { + public static void addEntry(String entry, String catagory, IItemStack stack) { LexiconCategory lexiconCategory=BotaniaHelper.findCatagory(catagory); if(lexiconCategory==null) { @@ -367,6 +369,7 @@ public class Lexicon { return; } LexiconEntry lexiconEntry=new LexiconEntry(entry,lexiconCategory); + lexiconEntry.setIcon(toStack(stack)); MineTweakerAPI.apply(new AddEntry(lexiconEntry)); } @ZenMethod diff --git a/src/main/java/modtweaker2/mods/forestry/handlers/Carpenter.java b/src/main/java/modtweaker2/mods/forestry/handlers/Carpenter.java index ee499ce..c5756d6 100644 --- a/src/main/java/modtweaker2/mods/forestry/handlers/Carpenter.java +++ b/src/main/java/modtweaker2/mods/forestry/handlers/Carpenter.java @@ -2,8 +2,10 @@ package modtweaker2.mods.forestry.handlers; import static modtweaker2.helpers.InputHelper.toFluid; import static modtweaker2.helpers.InputHelper.toIItemStack; +import static modtweaker2.helpers.InputHelper.toILiquidStack; import static modtweaker2.helpers.InputHelper.toStack; import static modtweaker2.helpers.InputHelper.toStacks; +import static modtweaker2.helpers.InputHelper.toShapedObjects; import static modtweaker2.helpers.StackHelper.matches; import java.util.ArrayList; @@ -20,6 +22,7 @@ import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import forestry.core.utils.ShapedRecipeCustom; @@ -34,6 +37,20 @@ public class Carpenter { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /** + * Adds a shaped recipe for the Carpenter + * + * @param output recipe output + * @param fluidInput recipe fluid amount + * @param ingredients recipe ingredients + * @param packagingTime time per crafting operation + * @param box recipes casting item (optional) + */ + @ZenMethod + public static void addRecipe(IItemStack output, int packagingTime, IIngredient[][] ingredients, @Optional ILiquidStack fluidInput, @Optional IItemStack box) { + MineTweakerAPI.apply(new Add(new Recipe(packagingTime, toFluid(fluidInput), toStack(box), ShapedRecipeCustom.createShapedRecipe(toStack(output), toShapedObjects(ingredients)) ))); + } + @ZenMethod public static void addRecipe(int packagingTime, ILiquidStack liquid, IItemStack[] ingredients, IItemStack ingredient, IItemStack product) { ArrayList stacks = new ArrayList(); @@ -78,13 +95,23 @@ public class Carpenter { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /** + * Removes a recipe for the Carpenter + * + * @param ingredient item input + */ @ZenMethod - public static void removeRecipe(IIngredient output) { + public static void removeRecipe(IIngredient output, @Optional IIngredient liquid) { List recipes = new LinkedList(); for(Recipe recipe : RecipeManager.recipes) { - if(recipe != null && recipe.getCraftingResult() != null && matches(output, toIItemStack(recipe.getCraftingResult()))) { - recipes.add(recipe); + if( recipe != null && recipe.getCraftingResult() != null && matches(output, toIItemStack(recipe.getCraftingResult())) ) { + if (liquid != null) { + if (matches(liquid, toILiquidStack(recipe.getLiquid()))) + recipes.add(recipe); + } else { + recipes.add(recipe); + } } } diff --git a/src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java b/src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java index 1ae25e2..bb764cc 100644 --- a/src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java +++ b/src/main/java/modtweaker2/mods/forestry/handlers/Fermenter.java @@ -6,9 +6,12 @@ import static modtweaker2.helpers.InputHelper.toILiquidStack; import static modtweaker2.helpers.InputHelper.toStack; import static modtweaker2.helpers.StackHelper.matches; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; @@ -17,9 +20,14 @@ import minetweaker.api.liquid.ILiquidStack; import modtweaker2.helpers.LogHelper; import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; +import modtweaker2.utils.BaseMapAddition; +import modtweaker2.utils.BaseMapRemoval; +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; +import forestry.api.fuels.FermenterFuel; +import forestry.api.fuels.FuelManager; import forestry.factory.gadgets.MachineFermenter.Recipe; import forestry.factory.gadgets.MachineFermenter.RecipeManager; @@ -30,9 +38,26 @@ public class Fermenter { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - @ZenMethod - public static void addRecipe(IItemStack resource, ILiquidStack liquid, int fermentationValue, float modifier, ILiquidStack output) { - MineTweakerAPI.apply(new Add(new Recipe(toStack(resource), fermentationValue, modifier, toFluid(output), toFluid(liquid)))); + + /** + * Adds a fermenter recipe. Amount of fluid output is calculated: fermentationValue * fluidOutputModifier + * Note: the actual consumption of fluid input depends on the fermentation fuel + * + * @param fluidOutput type of fluid produced + * @param fluidInput type of fluid required in input + * @param resource organic item + * @param fermentationValue amount of inputFluid on organic item requires + * @param fluidOutputModifier Output multiplier (this is usually a from the input fluid + */ + @ZenMethod + public static void addRecipe(ILiquidStack fluidOutput, IItemStack resource, ILiquidStack fluidInput, int fermentationValue, float fluidOutputModifier) { + MineTweakerAPI.apply(new Add(new Recipe(toStack(resource), fermentationValue, fluidOutputModifier, toFluid(fluidOutput), toFluid(fluidInput)))); + } + + @Deprecated + @ZenMethod + public static void addRecipe(IItemStack resource, ILiquidStack fluidInput, int fermentationValue, float fluidOutputModifier, ILiquidStack fluidOutput) { + MineTweakerAPI.apply(new Add(new Recipe(toStack(resource), fermentationValue, fluidOutputModifier, toFluid(fluidOutput), toFluid(fluidInput)))); } private static class Add extends BaseListAddition { @@ -175,4 +200,67 @@ public class Fermenter { return LogHelper.getStackDescription(recipe.output); } } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Adds fermenter fuel. + * Note: the actual consumption of fluid input depends on the fermentation fuel + * + * @param item Item that is a valid fuel for the fermenter + * @param fermentPerCycle How much is fermeted per work cycle, i.e. how much fluid of the input is consumed. + * @param burnDuration Amount of work cycles a single item of this fuel lasts before expiring. + */ + @ZenMethod + public static void addFuel(IItemStack item, int fermentPerCycle, int burnDuration) { + MineTweakerAPI.apply(new AddFuel(new FermenterFuel(toStack(item), fermentPerCycle, burnDuration))); + } + + private static class AddFuel extends BaseMapAddition { + public AddFuel(FermenterFuel fuelEntry) { + super(Fermenter.name, FuelManager.fermenterFuel); + recipes.put(fuelEntry.item, fuelEntry); + } + + @Override + public String getRecipeInfo(Entry fuelEntry) { + return LogHelper.getStackDescription(fuelEntry.getKey()); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Removes a fermenter fuel. + * + * @param fermenterItem Item that is a valid fuel for the fermenter + */ + @ZenMethod + public static void removeFuel(IIngredient fermenterItem) { + Map fuelItems = new HashMap(); + + for(Entry fuelItem : FuelManager.fermenterFuel.entrySet()) { + if(fuelItem != null && matches(fermenterItem, toIItemStack(fuelItem.getValue().item))) { + fuelItems.put(fuelItem.getKey(), fuelItem.getValue()); + } + } + + if(!fuelItems.isEmpty()) { + MineTweakerAPI.apply(new RemoveFuel(fuelItems)); + } else { + LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Fermenter.name, fermenterItem.toString())); + } + } + + private static class RemoveFuel extends BaseMapRemoval { + public RemoveFuel(Map recipes) { + super(Fermenter.name, FuelManager.fermenterFuel, recipes); + } + + @Override + public String getRecipeInfo(Entry fuelEntry) { + return LogHelper.getStackDescription(fuelEntry.getKey()); + } + } } + diff --git a/src/main/java/modtweaker2/mods/forestry/handlers/Moistener.java b/src/main/java/modtweaker2/mods/forestry/handlers/Moistener.java index 52400e5..0749ece 100644 --- a/src/main/java/modtweaker2/mods/forestry/handlers/Moistener.java +++ b/src/main/java/modtweaker2/mods/forestry/handlers/Moistener.java @@ -4,17 +4,26 @@ import static modtweaker2.helpers.InputHelper.toIItemStack; import static modtweaker2.helpers.InputHelper.toStack; import static modtweaker2.helpers.StackHelper.matches; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import net.minecraft.item.ItemStack; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; import modtweaker2.helpers.LogHelper; import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; +import modtweaker2.utils.BaseMapAddition; +import modtweaker2.utils.BaseMapRemoval; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; +import forestry.api.fuels.FermenterFuel; +import forestry.api.fuels.FuelManager; +import forestry.api.fuels.MoistenerFuel; import forestry.factory.gadgets.MachineMoistener; import forestry.factory.gadgets.MachineMoistener.Recipe; import forestry.factory.gadgets.MachineMoistener.RecipeManager; @@ -73,4 +82,70 @@ public class Moistener { return LogHelper.getStackDescription(recipe.product); } } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Adds moistener fuel. + * + * @param item The item to use + * @param product The item that leaves the moistener's working slot (i.e. mouldy wheat, decayed wheat, mulch) + * @param moistenerValue How much this item contributes to the final product of the moistener (i.e. mycelium) + * @param stage What stage this product represents. Resources with lower stage value will be consumed first. (First Stage is 0) + */ + @ZenMethod + public static void addFuel(IItemStack item, IItemStack product, int moistenerValue, int stage) { + if(stage >= 0) { + MineTweakerAPI.apply(new AddFuel(new MoistenerFuel(toStack(item), toStack(product), moistenerValue, stage))); + } else { + LogHelper.logWarning(String.format("No %s Recipe add for %s. Stage parameter must positive!", Moistener.name, item.toString())); + } + } + + private static class AddFuel extends BaseMapAddition { + public AddFuel(MoistenerFuel fuelEntry) { + super(Moistener.name, FuelManager.moistenerResource); + recipes.put(fuelEntry.item, fuelEntry); + } + + @Override + public String getRecipeInfo(Entry fuelEntry) { + return LogHelper.getStackDescription(fuelEntry.getKey()); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Removes a moistener fuel. + * + * @param moistenerItem Item that is a valid fuel for the moistener + */ + @ZenMethod + public static void removeFuel(IIngredient moistenerItem) { + Map fuelItems = new HashMap(); + + for(Entry fuelItem : FuelManager.moistenerResource.entrySet()) { + if(fuelItem != null && matches(moistenerItem, toIItemStack(fuelItem.getValue().item))) { + fuelItems.put(fuelItem.getKey(), fuelItem.getValue()); + } + } + + if(!fuelItems.isEmpty()) { + MineTweakerAPI.apply(new RemoveFuel(fuelItems)); + } else { + LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Moistener.name, moistenerItem.toString())); + } + } + + private static class RemoveFuel extends BaseMapRemoval { + public RemoveFuel(Map recipes) { + super(Moistener.name, FuelManager.moistenerResource, recipes); + } + + @Override + public String getRecipeInfo(Entry fuelEntry) { + return LogHelper.getStackDescription(fuelEntry.getKey()); + } + } } diff --git a/src/main/java/modtweaker2/mods/forestry/handlers/Squeezer.java b/src/main/java/modtweaker2/mods/forestry/handlers/Squeezer.java index 27156bb..a376cf5 100644 --- a/src/main/java/modtweaker2/mods/forestry/handlers/Squeezer.java +++ b/src/main/java/modtweaker2/mods/forestry/handlers/Squeezer.java @@ -3,6 +3,7 @@ package modtweaker2.mods.forestry.handlers; import static modtweaker2.helpers.InputHelper.getFluid; import static modtweaker2.helpers.InputHelper.toFluid; import static modtweaker2.helpers.InputHelper.toILiquidStack; +import static modtweaker2.helpers.InputHelper.toIItemStack; import static modtweaker2.helpers.InputHelper.toStack; import static modtweaker2.helpers.InputHelper.toStacks; import static modtweaker2.helpers.StackHelper.matches; @@ -14,10 +15,12 @@ import java.util.List; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IIngredient; import minetweaker.api.item.IItemStack; +import minetweaker.api.item.WeightedItemStack; import minetweaker.api.liquid.ILiquidStack; import modtweaker2.helpers.LogHelper; import modtweaker2.utils.BaseListAddition; import modtweaker2.utils.BaseListRemoval; +import stanhebben.zenscript.annotations.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import forestry.factory.gadgets.MachineSqueezer; @@ -30,10 +33,37 @@ public class Squeezer { public static final String name = "Forestry Squeezer"; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - + /** + * Adds a recipe without additional item output + * + * @param fluidOutput recipe fluid amount + * @param ingredients recipe ingredients + * @param timePerItem time per crafting operation + */ @ZenMethod + public static void addRecipe(ILiquidStack fluidOutput, int timePerItem, IItemStack[] ingredients) { + MineTweakerAPI.apply(new Add( new Recipe(timePerItem, toStacks(ingredients), toFluid(fluidOutput), null, 0) )); + } + + /** + * Adds a recipe with additional item output + * + * @param fluidOutput recipe fluid amount + * @param itemOutput recipe output + * @param ingredients recipe ingredients + * @param timePerItem time per crafting operation + */ + @ZenMethod + public static void addRecipe(ILiquidStack fluidOutput, WeightedItemStack itemOutput, int timePerItem, IItemStack[] ingredients) { + MineTweakerAPI.apply(new Add( new Recipe(timePerItem, toStacks(ingredients), toFluid(fluidOutput), toStack(itemOutput.getStack()), (int) itemOutput.getPercent()) )); + } + + @ZenMethod + @Deprecated public static void addRecipe(int timePerItem, IItemStack[] resources, ILiquidStack liquid, IItemStack remnants, int chance) { MineTweakerAPI.apply(new Add(new Recipe(timePerItem, toStacks(resources), toFluid(liquid), toStack(remnants), chance))); + + //TODO: this should definitiv solved somehow better MachineSqueezer.RecipeManager.recipeFluids.add(getFluid(liquid)); MachineSqueezer.RecipeManager.recipeInputs.addAll(Arrays.asList(toStacks(resources))); } @@ -52,13 +82,36 @@ public class Squeezer { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /** + * Removes a recipe for the Centrifuge + * + * @param liquid liquid output + * @param ingredients list of ingredients + */ @ZenMethod - public static void removeRecipe(IIngredient liquid) { + public static void removeRecipe(IIngredient liquid, @Optional IIngredient[] ingredients) { List recipes = new LinkedList(); for (Recipe r : RecipeManager.recipes) { if (r != null && r.liquid != null && matches(liquid, toILiquidStack(r.liquid))) { - recipes.add(r); + // optional check for ingredients + if (ingredients != null) { + boolean matched = false; + for (int i = 0; i < ingredients.length; i++) { + if ( matches(ingredients[i], toIItemStack(r.resources[i])) ) + matched = true; + else { + matched = false; + // if one ingredients doesn't match abort all further checks + break; + } + } + // if some ingredient doesn't match, the last one is false + if (matched) + recipes.add(r); + } else { + recipes.add(r); + } } } diff --git a/src/main/java/modtweaker2/mods/thaumcraft/handlers/Research.java b/src/main/java/modtweaker2/mods/thaumcraft/handlers/Research.java index e4447c0..10bc287 100644 --- a/src/main/java/modtweaker2/mods/thaumcraft/handlers/Research.java +++ b/src/main/java/modtweaker2/mods/thaumcraft/handlers/Research.java @@ -4,6 +4,7 @@ import static modtweaker2.helpers.InputHelper.toStack; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; import minetweaker.api.player.IPlayer; +import modtweaker2.helpers.InputHelper; import modtweaker2.mods.thaumcraft.ThaumcraftHelper; import modtweaker2.mods.thaumcraft.research.AddPage; import modtweaker2.mods.thaumcraft.research.AddPrereq; @@ -77,14 +78,20 @@ public class Research { @ZenMethod public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, String domain, String path) { - MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, new ResourceLocation(domain, path)))); + MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, new ResourceLocation(domain, path)), null, null)); } @ZenMethod public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, IItemStack item) { - MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, toStack(item)))); + MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, toStack(item)),null, null)); } + + @ZenMethod + public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, IItemStack item, IItemStack[] triggers, String[] entTriggers) { + + MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, toStack(item)), InputHelper.toStacks(triggers), entTriggers)); + } @ZenMethod public static void addPage(String key, String unlocalized) { diff --git a/src/main/java/modtweaker2/mods/thaumcraft/research/AddResearch.java b/src/main/java/modtweaker2/mods/thaumcraft/research/AddResearch.java index d05c288..ceb9888 100644 --- a/src/main/java/modtweaker2/mods/thaumcraft/research/AddResearch.java +++ b/src/main/java/modtweaker2/mods/thaumcraft/research/AddResearch.java @@ -5,44 +5,54 @@ import thaumcraft.api.research.ResearchCategories; import thaumcraft.api.research.ResearchItem; public class AddResearch implements IUndoableAction { - String key; - String tab; - ResearchItem research; + String key; + String tab; + ResearchItem research; + ItemStack[] itemTriggers; + String[] entityTriggers; - public AddResearch(ResearchItem res) { - research = res; - tab = research.category; - key = research.key; - } + public AddResearch(ResearchItem res, ItemStack[] triggers, String[] entTriggers) { + research = res; + tab = research.category; + key = research.key; + itemTriggers = triggers; + entityTriggers = entTriggers; + } - @Override - public void apply() { - research.registerResearchItem(); - } + @Override + public void apply() { + if (itemTriggers != null) { + research = research.setItemTriggers(itemTriggers); + } + if (entityTriggers != null) { + research = research.setEntityTriggers(entityTriggers); + } + research.registerResearchItem(); + } - @Override - public String describe() { - return "Registering Research: " + key; - } + @Override + public String describe() { + return "Registering Research: " + key; + } - @Override - public boolean canUndo() { - return tab != null && key != null; - } + @Override + public boolean canUndo() { + return tab != null && key != null; + } - @Override - public void undo() { - ResearchCategories.researchCategories.get(tab).research.remove(key); - } + @Override + public void undo() { + ResearchCategories.researchCategories.get(tab).research.remove(key); + } - @Override - public String describeUndo() { - return "Removing Research: " + key; - } + @Override + public String describeUndo() { + return "Removing Research: " + key; + } - @Override - public String getOverrideKey() { - return null; - } + @Override + public String getOverrideKey() { + return null; + } } \ No newline at end of file