mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-20 20:32:18 +00:00
ModTweaker2 Rework
- Revised base classes for IUndoableAction - Reordered lots of code, so stuck actions should be less frequent - Added wildcard support to many "remove" methods - Started working on exist & duplicate checks
This commit is contained in:
1 parent
f5034b04d8
commit
da33cc6fab
112 files changed
+4596
-3522
No files matched your search
@@ -1,15 +1,21 @@
|
||||
package modtweaker2.mods.forestry.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toFluid;
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStacks;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.mods.forestry.ForestryHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
@@ -24,7 +30,11 @@ import forestry.factory.gadgets.MachineCarpenter.RecipeManager;
|
||||
|
||||
@ZenClass("mods.forestry.Carpenter")
|
||||
public class Carpenter {
|
||||
|
||||
public static final String name = "Forestry Carpenter";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(int packagingTime, ILiquidStack liquid, IItemStack[] ingredients, IItemStack ingredient, IItemStack product) {
|
||||
ArrayList<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
@@ -45,10 +55,11 @@ public class Carpenter {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
private static class Add extends BaseListAddition<Recipe> {
|
||||
|
||||
public Add(Recipe recipe) {
|
||||
super("Forestry Carpenter", MachineCarpenter.RecipeManager.recipes, recipe);
|
||||
super(Carpenter.name, MachineCarpenter.RecipeManager.recipes);
|
||||
recipes.add(recipe);
|
||||
|
||||
// The Carpenter has a list of valid Fluids, access them via
|
||||
// Relfection because of private
|
||||
@@ -59,37 +70,43 @@ public class Carpenter {
|
||||
ForestryHelper.addCarpenterRecipeBox(recipe.getBox());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(){
|
||||
return ((MachineCarpenter.Recipe) recipe).getCraftingResult().getDisplayName();
|
||||
protected String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getCraftingResult());
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove(MachineCarpenter.RecipeManager.recipes, toStack(output)));
|
||||
public static void removeRecipe(IIngredient output) {
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
|
||||
for(Recipe recipe : RecipeManager.recipes) {
|
||||
if(recipe != null && recipe.getCraftingResult() != null && matches(output, toIItemStack(recipe.getCraftingResult()))) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Carpenter.name, output.toString()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval {
|
||||
private static class Remove extends BaseListRemoval<Recipe> {
|
||||
|
||||
public Remove(List list, ItemStack stack) {
|
||||
super("Forestry Carpenter", list, stack);
|
||||
public Remove(List<Recipe> recipes) {
|
||||
super(Carpenter.name, RecipeManager.recipes, recipes);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r.getCraftingResult() != null && r.getCraftingResult().isItemEqual(stack)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
super.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(){
|
||||
return "Removed recipe for: " + stack.getDisplayName();
|
||||
protected String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getCraftingResult());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,18 @@
|
||||
package modtweaker2.mods.forestry.handlers;
|
||||
|
||||
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 minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -19,6 +25,10 @@ import forestry.factory.gadgets.MachineCentrifuge.RecipeManager;
|
||||
@ZenClass("mods.forestry.Centrifuge")
|
||||
public class Centrifuge {
|
||||
|
||||
public static final String name = "Forestry Centrifuge";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(int timePerItem, IItemStack itemInput, IItemStack[] output, int[] chances) {
|
||||
HashMap<ItemStack, Integer> products = new HashMap<ItemStack, Integer>();
|
||||
@@ -31,47 +41,47 @@ public class Centrifuge {
|
||||
MineTweakerAPI.apply(new Add(new Recipe(timePerItem, toStack(itemInput), products)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IItemStack itemInput) {
|
||||
MineTweakerAPI.apply(new Remove(RecipeManager.recipes, toStack(itemInput)));
|
||||
private static class Add extends BaseListAddition<Recipe> {
|
||||
|
||||
public Add(Recipe recipe) {
|
||||
super(Centrifuge.name, RecipeManager.recipes);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.resource);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient input) {
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
|
||||
for(Recipe recipe : RecipeManager.recipes) {
|
||||
if(recipe != null && matches(input, toIItemStack(recipe.resource))) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Centrifuge.name, input.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Implements the actions to add the recipe
|
||||
*/
|
||||
private static class Add extends BaseListAddition {
|
||||
private static class Remove extends BaseListRemoval<Recipe> {
|
||||
|
||||
public Add(Recipe recipe) {
|
||||
super("Forestry Centrifuge", RecipeManager.recipes, recipe);
|
||||
}
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return " Input:" + ((Recipe) recipe).resource.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Implements the actions to remove the recipe
|
||||
*/
|
||||
private static class Remove extends BaseListRemoval {
|
||||
|
||||
public Remove(List list, ItemStack input) {
|
||||
super("Forestry Centrifuge", RecipeManager.recipes, input);
|
||||
public Remove(List<Recipe> recipes) {
|
||||
super(Centrifuge.name, RecipeManager.recipes, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r.matches(stack)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
super.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return " Input:" + stack.getDisplayName();
|
||||
protected String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,179 @@
|
||||
package modtweaker2.mods.forestry.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.getFluid;
|
||||
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.StackHelper.matches;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import forestry.factory.gadgets.MachineFermenter;
|
||||
import forestry.factory.gadgets.MachineFermenter.Recipe;
|
||||
import forestry.factory.gadgets.MachineFermenter.RecipeManager;
|
||||
|
||||
@ZenClass("mods.forestry.Fermenter")
|
||||
public class Fermenter {
|
||||
|
||||
public static final String name = "Forestry 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))));
|
||||
MachineFermenter.RecipeManager.recipeFluidInputs.add(getFluid(liquid));
|
||||
MachineFermenter.RecipeManager.recipeFluidOutputs.add(getFluid(output));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
private static class Add extends BaseListAddition<Recipe> {
|
||||
public Add(Recipe recipe) {
|
||||
super("Forestry Fermenter", MachineFermenter.RecipeManager.recipes, recipe);
|
||||
super(Fermenter.name, RecipeManager.recipes);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return ((Recipe) recipe).output.getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IItemStack input) {
|
||||
MineTweakerAPI.apply(new Remove(MachineFermenter.RecipeManager.recipes, toStack(input)));
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval {
|
||||
|
||||
public Remove(List list, ItemStack stack) {
|
||||
super(list, stack);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r != null && r.resource != null && r.resource.isItemEqual(stack)) {
|
||||
recipes.add(r);
|
||||
|
||||
}
|
||||
}
|
||||
super.apply();
|
||||
// add liquids to valid input / output
|
||||
for(Recipe recipe : successful) {
|
||||
RecipeManager.recipeFluidInputs.add(recipe.liquid.getFluid());
|
||||
RecipeManager.recipeFluidOutputs.add(recipe.output.getFluid());
|
||||
}
|
||||
|
||||
super.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
super.undo();
|
||||
|
||||
// Tidy up valid inputs
|
||||
for(Iterator<Fluid> iter = RecipeManager.recipeFluidInputs.iterator(); iter.hasNext();) {
|
||||
boolean found = false;
|
||||
Fluid fluid = iter.next();
|
||||
for(Recipe recipe : list) {
|
||||
if(recipe != null && recipe.liquid != null && recipe.liquid.getFluid().equals(fluid)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Tidy up valid outputs
|
||||
for(Iterator<Fluid> iter = RecipeManager.recipeFluidOutputs.iterator(); iter.hasNext();) {
|
||||
boolean found = false;
|
||||
Fluid fluid = iter.next();
|
||||
for(Recipe recipe : list) {
|
||||
if(recipe != null && recipe.output != null && recipe.output.getFluid().equals(fluid)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.output);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient input) {
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
|
||||
for(Recipe recipe : RecipeManager.recipes) {
|
||||
// check for input items
|
||||
if(recipe != null && recipe.resource != null && matches(input, toIItemStack(recipe.resource))) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
// check for input liquids
|
||||
if(recipe != null && recipe.resource != null && matches(input, toILiquidStack(recipe.liquid))) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Fermenter.name, input.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval<Recipe> {
|
||||
|
||||
public Remove(List<Recipe> recipes) {
|
||||
super(Fermenter.name, RecipeManager.recipes, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
super.apply();
|
||||
|
||||
// Tidy up valid inputs
|
||||
for(Iterator<Fluid> iter = RecipeManager.recipeFluidInputs.iterator(); iter.hasNext();) {
|
||||
boolean found = false;
|
||||
Fluid fluid = iter.next();
|
||||
for(Recipe recipe : list) {
|
||||
if(recipe != null && recipe.liquid != null && recipe.liquid.getFluid().equals(fluid)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Tidy up valid outputs
|
||||
for(Iterator<Fluid> iter = RecipeManager.recipeFluidOutputs.iterator(); iter.hasNext();) {
|
||||
boolean found = false;
|
||||
Fluid fluid = iter.next();
|
||||
for(Recipe recipe : list) {
|
||||
if(recipe != null && recipe.output != null && recipe.output.getFluid().equals(fluid)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
// add liquids to valid input / output
|
||||
for(Recipe recipe : successful) {
|
||||
RecipeManager.recipeFluidInputs.add(recipe.liquid.getFluid());
|
||||
RecipeManager.recipeFluidOutputs.add(recipe.output.getFluid());
|
||||
}
|
||||
|
||||
super.undo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
package modtweaker2.mods.forestry.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import forestry.factory.gadgets.MachineMoistener;
|
||||
@@ -17,6 +22,10 @@ import forestry.factory.gadgets.MachineMoistener.RecipeManager;
|
||||
|
||||
@ZenClass("mods.forestry.Moistener")
|
||||
public class Moistener {
|
||||
|
||||
public static final String name = "Forestry Moistener";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(int timePerItem, IItemStack resource, IItemStack product) {
|
||||
@@ -24,37 +33,45 @@ public class Moistener {
|
||||
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
private static class Add extends BaseListAddition<Recipe> {
|
||||
public Add(Recipe recipe) {
|
||||
super("Forestry Moistener", MachineMoistener.RecipeManager.recipes, recipe);
|
||||
super(Moistener.name, MachineMoistener.RecipeManager.recipes);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return ((Recipe) recipe).product.getDisplayName();
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.product);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IItemStack output) {
|
||||
MineTweakerAPI.apply(new Remove(MachineMoistener.RecipeManager.recipes, toStack(output)));
|
||||
public static void removeRecipe(IIngredient output) {
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
|
||||
for (Recipe recipe : RecipeManager.recipes) {
|
||||
if (recipe != null && recipe.product != null && matches(output, toIItemStack(recipe.product))) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Moistener.name, output.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval {
|
||||
|
||||
public Remove(List list, ItemStack stack) {
|
||||
super(list, stack);
|
||||
|
||||
private static class Remove extends BaseListRemoval<Recipe> {
|
||||
public Remove(List<Recipe> recipes) {
|
||||
super(Moistener.name, RecipeManager.recipes, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r.product != null && r.product.isItemEqual(stack)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
super.apply();
|
||||
}
|
||||
@Override
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.product);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,23 @@ 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.toStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStacks;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import forestry.factory.gadgets.MachineSqueezer;
|
||||
@@ -22,6 +27,10 @@ import forestry.factory.gadgets.MachineSqueezer.RecipeManager;
|
||||
|
||||
@ZenClass("mods.forestry.Squeezer")
|
||||
public class Squeezer {
|
||||
|
||||
public static final String name = "Forestry Squeezer";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(int timePerItem, IItemStack[] resources, ILiquidStack liquid, IItemStack remnants, int chance) {
|
||||
@@ -30,38 +39,53 @@ public class Squeezer {
|
||||
MachineSqueezer.RecipeManager.recipeInputs.addAll(Arrays.asList(toStacks(resources)));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
private static class Add extends BaseListAddition<Recipe> {
|
||||
public Add(Recipe recipe) {
|
||||
super("Forestry Squeezer", MachineSqueezer.RecipeManager.recipes, recipe);
|
||||
super(Squeezer.name, MachineSqueezer.RecipeManager.recipes);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return ((Recipe) recipe).liquid.getLocalizedName();
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.liquid);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(ILiquidStack liquid) {
|
||||
MineTweakerAPI.apply(new Remove(MachineSqueezer.RecipeManager.recipes, toFluid(liquid)));
|
||||
public static void removeRecipe(IIngredient liquid) {
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r != null && r.liquid != null && matches(liquid, toILiquidStack(r.liquid))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Squeezer.name, liquid.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval {
|
||||
|
||||
public Remove(List list, FluidStack liquid) {
|
||||
super(list, liquid);
|
||||
private static class Remove extends BaseListRemoval<Recipe> {
|
||||
public Remove(List<Recipe> recipes) {
|
||||
super(Squeezer.name, MachineSqueezer.RecipeManager.recipes, recipes);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r.liquid != null && r.liquid.isFluidEqual(fluid)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
super.apply();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.liquid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,18 @@ 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.StackHelper.matches;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import forestry.factory.gadgets.MachineStill;
|
||||
@@ -18,6 +22,10 @@ import forestry.factory.gadgets.MachineStill.RecipeManager;
|
||||
|
||||
@ZenClass("mods.forestry.Still")
|
||||
public class Still {
|
||||
|
||||
public static final String name = "Forestry Still";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(int timePerUnit, ILiquidStack input, ILiquidStack output) {
|
||||
@@ -29,37 +37,46 @@ public class Still {
|
||||
MachineStill.RecipeManager.recipeFluidOutputs.add(getFluid(output));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition {
|
||||
private static class Add extends BaseListAddition<Recipe> {
|
||||
public Add(Recipe recipe) {
|
||||
super("Forestry Still", MachineStill.RecipeManager.recipes, recipe);
|
||||
super("Forestry Still", MachineStill.RecipeManager.recipes);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
return ((Recipe) recipe).output.getLocalizedName();
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.output);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(ILiquidStack output, ILiquidStack input) {
|
||||
MineTweakerAPI.apply(new Remove(MachineStill.RecipeManager.recipes, toFluid(input)));
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r != null && r.output != null && matches(output, toILiquidStack(r.output))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", Still.name, output.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval {
|
||||
|
||||
public Remove(List list, FluidStack input) {
|
||||
super(list, input);
|
||||
private static class Remove extends BaseListRemoval<Recipe> {
|
||||
public Remove(List<Recipe> recipes) {
|
||||
super(Still.name, RecipeManager.recipes, recipes);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r.output != null && r.output.isFluidEqual(fluid)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
super.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,19 @@
|
||||
package modtweaker2.mods.forestry.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toFluid;
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -21,18 +27,20 @@ import forestry.factory.gadgets.MachineFabricator.Smelting;
|
||||
|
||||
@ZenClass("mods.forestry.ThermionicFabricator")
|
||||
public class ThermionicFabricator {
|
||||
|
||||
public static final String nameSmelting = "Forestry Thermionic Fabricator (Smelting)";
|
||||
public static final String nameCasting = "Forestry Thermionic Fabricator (Casting)";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//first production step: smelting item into liquid
|
||||
@ZenMethod
|
||||
public static void addSmelting(IItemStack itemInput, int meltingPoint, int fluidOutput) {
|
||||
//The machines internal tank accept only liquid glass, therefor this function only accept the amount and hardcode the fluid to glass
|
||||
MineTweakerAPI.apply(new Add(new Smelting(toStack(itemInput), FluidRegistry.getFluidStack("glass", fluidOutput), meltingPoint)));
|
||||
MineTweakerAPI.apply(new AddSmelting(new Smelting(toStack(itemInput), FluidRegistry.getFluidStack("glass", fluidOutput), meltingPoint)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeSmelting(IItemStack itemInput) {
|
||||
MineTweakerAPI.apply(new Remove(toStack(itemInput), RecipeManager.smeltings, RecipeType.Smelting));
|
||||
}
|
||||
|
||||
|
||||
//second step: casting liquid + objetcs + plan into result
|
||||
@ZenMethod
|
||||
@@ -44,86 +52,95 @@ public class ThermionicFabricator {
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new Add(new Recipe(toStack(plan), toFluid(fluidInput), new ShapedRecipeCustom(3, 3, flatList, toStack(product)))));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeCasts(IItemStack product) {
|
||||
MineTweakerAPI.apply(new Remove(toStack(product), RecipeManager.recipes, RecipeType.Casting));
|
||||
MineTweakerAPI.apply(new AddCast(new Recipe(toStack(plan), toFluid(fluidInput), new ShapedRecipeCustom(3, 3, flatList, toStack(product)))));
|
||||
}
|
||||
|
||||
/*
|
||||
Implements the actions to add a recipe
|
||||
Since the machine has two crafting Steps, this is a constructors for both
|
||||
*/
|
||||
private static class Add extends BaseListAddition {
|
||||
private static class AddSmelting extends BaseListAddition<Smelting> {
|
||||
|
||||
public Add(Smelting recipe) {
|
||||
super("Forestry Thermionic Fabricator (Smelting)", RecipeManager.smeltings, recipe);
|
||||
public AddSmelting(Smelting recipe) {
|
||||
super(ThermionicFabricator.nameSmelting, RecipeManager.smeltings);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
public Add(Recipe recipe) {
|
||||
super("Forestry Thermionic Fabricator (Casting)", RecipeManager.recipes, recipe);
|
||||
@Override
|
||||
public String getRecipeInfo(Smelting recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getResource());
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddCast extends BaseListAddition<Recipe> {
|
||||
|
||||
public AddCast(Recipe recipe) {
|
||||
super(ThermionicFabricator.nameCasting, RecipeManager.recipes);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getPlan());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeSmelting(IIngredient itemInput) {
|
||||
List<Smelting> recipes = new LinkedList<Smelting>();
|
||||
|
||||
for (Smelting r : RecipeManager.smeltings) {
|
||||
if (r != null && r.getResource() != null && matches(itemInput, toIItemStack(r.getResource()))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new RemoveSmelting(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", ThermionicFabricator.nameSmelting, itemInput.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void removeCasts(IIngredient product) {
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
|
||||
for (Recipe r : RecipeManager.recipes) {
|
||||
if (r != null && r.asIRecipe().getRecipeOutput() != null && matches(product, toIItemStack(r.asIRecipe().getRecipeOutput()))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new RemoveCasts(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", ThermionicFabricator.nameSmelting, product.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveSmelting extends BaseListRemoval<Smelting> {
|
||||
public RemoveSmelting(List<Smelting> recipes) {
|
||||
super(ThermionicFabricator.nameSmelting, RecipeManager.smeltings, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
if (recipe instanceof Smelting)
|
||||
return " Input:" + ((Smelting) recipe).getResource().getDisplayName();
|
||||
else
|
||||
return "Output: " + ((Recipe) recipe).asIRecipe().getRecipeOutput().getDisplayName();
|
||||
public String getRecipeInfo(Smelting recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getResource());
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveCasts extends BaseListRemoval<Recipe> {
|
||||
public RemoveCasts(List<Recipe> recipes) {
|
||||
super(ThermionicFabricator.nameCasting, RecipeManager.recipes, recipes);
|
||||
}
|
||||
|
||||
/*
|
||||
Implements the actions to remove recipes
|
||||
*/
|
||||
private static class Remove extends BaseListRemoval {
|
||||
private final RecipeType type;
|
||||
|
||||
public Remove(ItemStack input, List list, RecipeType type) {
|
||||
super(String.format("Forestry Thermionic Fabricator (%s)", type.toString()), list, input);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
switch(type) {
|
||||
case Smelting:
|
||||
for (Object r : list) {
|
||||
if (((Smelting)r).getResource() != null && ((Smelting)r).getResource().isItemEqual(stack)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Casting:
|
||||
for (Object r : list) {
|
||||
if (((Recipe)r).asIRecipe().getRecipeOutput() != null && ((Recipe)r).asIRecipe().getRecipeOutput().isItemEqual(stack)) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
super.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo() {
|
||||
switch(type) {
|
||||
case Smelting:
|
||||
return " Input:" + stack.getDisplayName(); // + " -- Output:" + ((Smelting) recipe).getProduct().getLocalizedName();
|
||||
|
||||
case Casting:
|
||||
return " Output:" + stack.getDisplayName(); // + " -- Output:" + ((Recipe) recipe).asIRecipe().getIngredients()[0].getDisplayName();
|
||||
}
|
||||
|
||||
return stack.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
public enum RecipeType {
|
||||
Smelting,
|
||||
Casting
|
||||
@Override
|
||||
public String getRecipeInfo(Recipe recipe) {
|
||||
return InputHelper.getStackDescription(recipe.getPlan());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user