mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-26 23:23:05 +00:00
Fix up Integration for Forestry 4.1.0 using only the API
This commit is contained in:
1 parent
4682dba3e6
commit
28175a9e95
22 files changed
+758
-353
No files matched your search
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -7,7 +8,6 @@ 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;
|
||||
@@ -18,18 +18,20 @@ import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import modtweaker2.mods.forestry.ForestryListAddition;
|
||||
import modtweaker2.mods.forestry.ForestryListRemoval;
|
||||
import modtweaker2.mods.forestry.recipes.FermenterRecipe;
|
||||
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.tiles.TileFermenter.Recipe;
|
||||
import forestry.factory.tiles.TileFermenter.RecipeManager;
|
||||
import forestry.api.recipes.IFermenterManager;
|
||||
import forestry.api.recipes.IFermenterRecipe;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
|
||||
@ZenClass("mods.forestry.Fermenter")
|
||||
public class Fermenter {
|
||||
@@ -51,87 +53,41 @@ public class Fermenter {
|
||||
*/
|
||||
@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))));
|
||||
MineTweakerAPI.apply(new Add(new FermenterRecipe(toStack(resource), fermentationValue, fluidOutputModifier, getFluid(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))));
|
||||
MineTweakerAPI.apply(new Add(new FermenterRecipe(toStack(resource), fermentationValue, fluidOutputModifier, getFluid(fluidOutput), toFluid(fluidInput))));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition<Recipe> {
|
||||
public Add(Recipe recipe) {
|
||||
super(Fermenter.name, RecipeManager.recipes);
|
||||
|
||||
private static class Add extends ForestryListAddition<IFermenterRecipe, IFermenterManager> {
|
||||
public Add(IFermenterRecipe recipe) {
|
||||
super(Fermenter.name, RecipeManagers.fermenterManager);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void 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 LogHelper.getStackDescription(recipe.output);
|
||||
public String getRecipeInfo(IFermenterRecipe recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getOutput());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient input) {
|
||||
List<Recipe> recipes = new LinkedList<Recipe>();
|
||||
List<IFermenterRecipe> recipes = new LinkedList<IFermenterRecipe>();
|
||||
|
||||
for(Recipe recipe : RecipeManager.recipes) {
|
||||
for(IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) {
|
||||
// check for input items
|
||||
if(recipe != null && recipe.resource != null && matches(input, toIItemStack(recipe.resource))) {
|
||||
if(recipe != null && recipe.getResource() != null && matches(input, toIItemStack(recipe.getResource()))) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
// check for input liquids
|
||||
if(recipe != null && recipe.resource != null && matches(input, toILiquidStack(recipe.liquid))) {
|
||||
if(recipe != null && recipe.getResource() != null && matches(input, toILiquidStack(recipe.getFluidResource()))) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
@@ -142,61 +98,16 @@ public class Fermenter {
|
||||
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();
|
||||
}
|
||||
}
|
||||
private static class Remove extends ForestryListRemoval<IFermenterRecipe, IFermenterManager> {
|
||||
|
||||
public Remove(List<IFermenterRecipe> recipes) {
|
||||
super(Fermenter.name, RecipeManagers.fermenterManager, recipes);
|
||||
}
|
||||
|
||||
|
||||
@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 LogHelper.getStackDescription(recipe.output);
|
||||
protected String getRecipeInfo(IFermenterRecipe recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getOutput());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user