Skip to content

Commit 1cf86b9

Browse files
committed
Merge pull request #267 from mezz/master
Fix up Integration for Forestry 4.1.0 using only the API
2 parents 4682dba + 28175a9 commit 1cf86b9

22 files changed

Lines changed: 758 additions & 353 deletions

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repositories {
4545
}
4646

4747
dependencies {
48-
compile "net.sengir.forestry:forestry_${config.minecraft.version}:${config.forestry.version}:dev"
48+
compile "net.sengir.forestry:forestry_${config.minecraft.version}:${config.forestry.version}:api"
4949
}
5050

5151
processResources

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ forge.version=10.13.4.1448-1.7.10
33

44
mod.version=0.9.4
55

6-
forestry.version=4.0.8.36
6+
forestry.version=4.1.0.43

src/main/java/modtweaker2/ModProps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ public class ModProps {
55
public static final String NAME = "Mod Tweaker 2", name = NAME;
66
public static final String MODID = "modtweaker2", modid = MODID;
77
public static final String VERSION = "0.9.4", version = VERSION;
8-
public static final String DEPENDENCIES = "required-after:MineTweaker3;after:Forestry@[4.0.3,);", dependencies = DEPENDENCIES;
8+
public static final String DEPENDENCIES = "required-after:MineTweaker3;after:Forestry@[4.1.0,);", dependencies = DEPENDENCIES;
99
}

src/main/java/modtweaker2/mods/forestry/ForestryHelper.java

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package modtweaker2.mods.forestry;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import forestry.api.recipes.ICraftingProvider;
7+
import forestry.api.recipes.IForestryRecipe;
8+
9+
import modtweaker2.helpers.LogHelper;
10+
import modtweaker2.utils.BaseListAddition;
11+
12+
public abstract class ForestryListAddition<T extends IForestryRecipe, C extends ICraftingProvider<T>> extends BaseListAddition<T> {
13+
private final C craftingProvider;
14+
15+
protected ForestryListAddition(String name, C craftingProvider) {
16+
super(name, new ArrayList<T>(craftingProvider.recipes()));
17+
this.craftingProvider = craftingProvider;
18+
}
19+
20+
protected ForestryListAddition(String name, C craftingProvider, List<T> recipes) {
21+
super(name, new ArrayList<T>(craftingProvider.recipes()), recipes);
22+
this.craftingProvider = craftingProvider;
23+
}
24+
25+
@Override
26+
protected abstract String getRecipeInfo(T recipe);
27+
28+
@Override
29+
public final void apply() {
30+
for (T recipe : recipes) {
31+
if (recipe != null) {
32+
if (craftingProvider.addRecipe(recipe)) {
33+
successful.add(recipe);
34+
} else {
35+
LogHelper.logError(String.format("Error adding %s Recipe for %s", name, getRecipeInfo(recipe)));
36+
}
37+
} else {
38+
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
39+
}
40+
}
41+
}
42+
43+
@Override
44+
public final void undo() {
45+
for (T recipe : successful) {
46+
if (recipe != null) {
47+
if (!craftingProvider.removeRecipe(recipe)) {
48+
LogHelper.logError(String.format("Error removing %s Recipe for %s", name, this.getRecipeInfo(recipe)));
49+
}
50+
} else {
51+
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
52+
}
53+
}
54+
}
55+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package modtweaker2.mods.forestry;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import forestry.api.recipes.ICraftingProvider;
7+
import forestry.api.recipes.IForestryRecipe;
8+
9+
import modtweaker2.helpers.LogHelper;
10+
import modtweaker2.utils.BaseListRemoval;
11+
12+
public abstract class ForestryListRemoval<T extends IForestryRecipe, C extends ICraftingProvider<T>> extends BaseListRemoval<T> {
13+
private final C craftingProvider;
14+
15+
public ForestryListRemoval(String name, C craftingProvider, List<T> recipes) {
16+
super(name, new ArrayList<T>(craftingProvider.recipes()), recipes);
17+
this.craftingProvider = craftingProvider;
18+
}
19+
20+
@Override
21+
protected abstract String getRecipeInfo(T recipe);
22+
23+
@Override
24+
public final void apply() {
25+
for (T recipe : recipes) {
26+
if (recipe != null) {
27+
if (craftingProvider.removeRecipe(recipe)) {
28+
successful.add(recipe);
29+
} else {
30+
LogHelper.logError(String.format("Error removing %s Recipe for %s", name, getRecipeInfo(recipe)));
31+
}
32+
} else {
33+
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
34+
}
35+
}
36+
}
37+
38+
@Override
39+
public final void undo() {
40+
for (T recipe : successful) {
41+
if (recipe != null) {
42+
if (!craftingProvider.addRecipe(recipe)) {
43+
LogHelper.logError(String.format("Error restoring %s Recipe for %s", name, getRecipeInfo(recipe)));
44+
}
45+
} else {
46+
LogHelper.logError(String.format("Error restoring %s Recipe: null object", name));
47+
}
48+
}
49+
}
50+
}

src/main/java/modtweaker2/mods/forestry/handlers/Carpenter.java

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import static modtweaker2.helpers.InputHelper.toShapedObjects;
99
import static modtweaker2.helpers.StackHelper.matches;
1010

11-
import java.util.ArrayList;
1211
import java.util.LinkedList;
1312
import java.util.List;
1413

@@ -17,18 +16,20 @@
1716
import minetweaker.api.item.IItemStack;
1817
import minetweaker.api.liquid.ILiquidStack;
1918
import modtweaker2.helpers.LogHelper;
20-
import modtweaker2.mods.forestry.ForestryHelper;
21-
import modtweaker2.utils.BaseListAddition;
22-
import modtweaker2.utils.BaseListRemoval;
23-
import net.minecraft.init.Blocks;
19+
import modtweaker2.mods.forestry.ForestryListAddition;
20+
import modtweaker2.mods.forestry.ForestryListRemoval;
21+
import modtweaker2.mods.forestry.recipes.CarpenterRecipe;
2422
import net.minecraft.item.ItemStack;
23+
24+
import modtweaker2.mods.forestry.recipes.DescriptiveRecipe;
2525
import stanhebben.zenscript.annotations.Optional;
2626
import stanhebben.zenscript.annotations.ZenClass;
2727
import stanhebben.zenscript.annotations.ZenMethod;
28-
import forestry.core.recipes.ShapedRecipeCustom;
29-
import forestry.factory.tiles.TileCarpenter;
30-
import forestry.factory.tiles.TileCarpenter.Recipe;
31-
import forestry.factory.tiles.TileCarpenter.RecipeManager;
28+
29+
import forestry.api.recipes.ICarpenterManager;
30+
import forestry.api.recipes.ICarpenterRecipe;
31+
import forestry.api.recipes.IDescriptiveRecipe;
32+
import forestry.api.recipes.RecipeManagers;
3233

3334
@ZenClass("mods.forestry.Carpenter")
3435
public class Carpenter {
@@ -47,7 +48,8 @@ public class Carpenter {
4748
*/
4849
@ZenMethod
4950
public static void addRecipe(IItemStack output, IIngredient[][] ingredients, int packagingTime, @Optional IItemStack box) {
50-
MineTweakerAPI.apply(new Add(new Recipe(packagingTime, null, toStack(box), ShapedRecipeCustom.createShapedRecipe(toStack(output), toShapedObjects(ingredients)) )));
51+
IDescriptiveRecipe craftRecipe = new DescriptiveRecipe(3, 3, toShapedObjects(ingredients), toStack(output), false);
52+
MineTweakerAPI.apply(new Add(new CarpenterRecipe(packagingTime, null, toStack(box), craftRecipe)));
5153
}
5254

5355
/**
@@ -61,44 +63,27 @@ public static void addRecipe(IItemStack output, IIngredient[][] ingredients, int
6163
*/
6264
@ZenMethod
6365
public static void addRecipe(IItemStack output, IIngredient[][] ingredients, ILiquidStack fluidInput, int packagingTime, @Optional IItemStack box) {
64-
MineTweakerAPI.apply(new Add(new Recipe(packagingTime, toFluid(fluidInput), toStack(box), ShapedRecipeCustom.createShapedRecipe(toStack(output), toShapedObjects(ingredients)) )));
66+
IDescriptiveRecipe craftRecipe = new DescriptiveRecipe(3, 3, toShapedObjects(ingredients), toStack(output), false);
67+
MineTweakerAPI.apply(new Add(new CarpenterRecipe(packagingTime, toFluid(fluidInput), toStack(box), craftRecipe)));
6568
}
6669

6770
@Deprecated
6871
@ZenMethod
6972
public static void addRecipe(int packagingTime, ILiquidStack liquid, IItemStack[] ingredients, IItemStack ingredient, IItemStack product) {
70-
ArrayList<ItemStack> stacks = new ArrayList<ItemStack>();
71-
for (ItemStack stack : toStacks(ingredients)) {
72-
if (stack != null) {
73-
stacks.add(stack);
74-
}
75-
if (stack == null) {
76-
stacks.add(new ItemStack(Blocks.air));
77-
}
78-
79-
}
80-
MineTweakerAPI.apply(new Add(new Recipe(packagingTime, toFluid(liquid), toStack(ingredient), new ShapedRecipeCustom(3, 3, toStacks(ingredients), toStack(product)))));
73+
IDescriptiveRecipe craftRecipe = new DescriptiveRecipe(3, 3, toStacks(ingredients), toStack(product), false);
74+
MineTweakerAPI.apply(new Add(new CarpenterRecipe(packagingTime, toFluid(liquid), toStack(ingredient), craftRecipe)));
8175
}
8276

83-
private static class Add extends BaseListAddition<Recipe> {
77+
private static class Add extends ForestryListAddition<ICarpenterRecipe, ICarpenterManager> {
8478

85-
public Add(Recipe recipe) {
86-
super(Carpenter.name, TileCarpenter.RecipeManager.recipes);
79+
public Add(ICarpenterRecipe recipe) {
80+
super(Carpenter.name, RecipeManagers.carpenterManager);
8781
recipes.add(recipe);
88-
89-
// The Carpenter has a list of valid Fluids, access them via
90-
// Reflection because of private
91-
if (recipe.getLiquid() != null)
92-
ForestryHelper.addCarpenterRecipeFluids(recipe.getLiquid().getFluid());
93-
94-
if(!RecipeManager.isBox(recipe.getBox())){
95-
ForestryHelper.addCarpenterRecipeBox(recipe.getBox());
96-
}
9782
}
9883

9984
@Override
100-
protected String getRecipeInfo(Recipe recipe) {
101-
return LogHelper.getStackDescription(recipe.getCraftingResult());
85+
protected String getRecipeInfo(ICarpenterRecipe recipe) {
86+
return LogHelper.getStackDescription(recipe.getCraftingGridRecipe().getRecipeOutput());
10287
}
10388
}
10489

@@ -112,15 +97,18 @@ protected String getRecipeInfo(Recipe recipe) {
11297
*/
11398
@ZenMethod
11499
public static void removeRecipe(IIngredient output, @Optional IIngredient liquid) {
115-
List<Recipe> recipes = new LinkedList<Recipe>();
100+
List<ICarpenterRecipe> recipes = new LinkedList<ICarpenterRecipe>();
116101

117-
for(Recipe recipe : RecipeManager.recipes) {
118-
if( recipe != null && recipe.getCraftingResult() != null && matches(output, toIItemStack(recipe.getCraftingResult())) ) {
119-
if (liquid != null) {
120-
if (matches(liquid, toILiquidStack(recipe.getLiquid())))
102+
for(ICarpenterRecipe recipe : RecipeManagers.carpenterManager.recipes()) {
103+
if (recipe != null) {
104+
ItemStack recipeResult = recipe.getCraftingGridRecipe().getRecipeOutput();
105+
if (recipeResult != null && matches(output, toIItemStack(recipeResult))) {
106+
if (liquid != null) {
107+
if (matches(liquid, toILiquidStack(recipe.getFluidResource())))
108+
recipes.add(recipe);
109+
} else {
121110
recipes.add(recipe);
122-
} else {
123-
recipes.add(recipe);
111+
}
124112
}
125113
}
126114
}
@@ -132,15 +120,15 @@ public static void removeRecipe(IIngredient output, @Optional IIngredient liquid
132120
}
133121
}
134122

135-
private static class Remove extends BaseListRemoval<Recipe> {
123+
private static class Remove extends ForestryListRemoval<ICarpenterRecipe, ICarpenterManager> {
136124

137-
public Remove(List<Recipe> recipes) {
138-
super(Carpenter.name, RecipeManager.recipes, recipes);
125+
public Remove(List<ICarpenterRecipe> recipes) {
126+
super(Carpenter.name, RecipeManagers.carpenterManager, recipes);
139127
}
140128

141129
@Override
142-
protected String getRecipeInfo(Recipe recipe) {
143-
return LogHelper.getStackDescription(recipe.getCraftingResult());
130+
protected String getRecipeInfo(ICarpenterRecipe recipe) {
131+
return LogHelper.getStackDescription(recipe.getCraftingGridRecipe().getRecipeOutput());
144132
}
145133
}
146134
}

src/main/java/modtweaker2/mods/forestry/handlers/Centrifuge.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
import minetweaker.api.item.IItemStack;
1515
import minetweaker.api.item.WeightedItemStack;
1616
import modtweaker2.helpers.LogHelper;
17-
import modtweaker2.utils.BaseListAddition;
18-
import modtweaker2.utils.BaseListRemoval;
17+
import modtweaker2.mods.forestry.ForestryListAddition;
18+
import modtweaker2.mods.forestry.ForestryListRemoval;
19+
import modtweaker2.mods.forestry.recipes.CentrifugeRecipe;
1920
import net.minecraft.item.ItemStack;
2021
import stanhebben.zenscript.annotations.ZenClass;
2122
import stanhebben.zenscript.annotations.ZenMethod;
23+
24+
import forestry.api.recipes.ICentrifugeManager;
2225
import forestry.api.recipes.ICentrifugeRecipe;
23-
import forestry.factory.tiles.TileCentrifuge.CentrifugeRecipe;
24-
import forestry.factory.tiles.TileCentrifuge.RecipeManager;
26+
import forestry.api.recipes.RecipeManagers;
2527

2628

2729
@ZenClass("mods.forestry.Centrifuge")
@@ -59,9 +61,9 @@ public static void addRecipe(int timePerItem, IItemStack itemInput, IItemStack[]
5961
MineTweakerAPI.apply(new Add(new CentrifugeRecipe(timePerItem, toStack(itemInput), products)));
6062
}
6163

62-
private static class Add extends BaseListAddition<ICentrifugeRecipe> {
64+
private static class Add extends ForestryListAddition<ICentrifugeRecipe, ICentrifugeManager> {
6365
public Add(ICentrifugeRecipe recipe) {
64-
super(Centrifuge.name, RecipeManager.recipes);
66+
super(Centrifuge.name, RecipeManagers.centrifugeManager);
6567
recipes.add(recipe);
6668
}
6769

@@ -82,7 +84,7 @@ protected String getRecipeInfo(ICentrifugeRecipe recipe) {
8284
public static void removeRecipe(IIngredient input) {
8385
List<ICentrifugeRecipe> recipes = new LinkedList<ICentrifugeRecipe>();
8486

85-
for(ICentrifugeRecipe recipe : RecipeManager.recipes) {
87+
for(ICentrifugeRecipe recipe : RecipeManagers.centrifugeManager.recipes()) {
8688
if(recipe != null && matches(input, toIItemStack(recipe.getInput()))) {
8789
recipes.add(recipe);
8890
}
@@ -95,10 +97,10 @@ public static void removeRecipe(IIngredient input) {
9597
}
9698
}
9799

98-
private static class Remove extends BaseListRemoval<ICentrifugeRecipe> {
100+
private static class Remove extends ForestryListRemoval<ICentrifugeRecipe, ICentrifugeManager> {
99101

100102
public Remove(List<ICentrifugeRecipe> recipes) {
101-
super(Centrifuge.name, RecipeManager.recipes, recipes);
103+
super(Centrifuge.name, RecipeManagers.centrifugeManager, recipes);
102104
}
103105

104106
@Override

0 commit comments

Comments
 (0)