Skip to content

Commit cf3eea4

Browse files
authored
Merge pull request #758 from democat3457/patch-1
Fix flipped bwm anvil recipe
2 parents 7b66643 + c0a095d commit cf3eea4

1 file changed

Lines changed: 79 additions & 4 deletions

File tree

  • src/main/java/com/blamejared/compat/betterwithmods

src/main/java/com/blamejared/compat/betterwithmods/Anvil.java

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public static void addShaped(IItemStack output, IIngredient[][] inputs) {
3131
ModTweaker.LATE_ADDITIONS.add(new AddShaped(output, inputs));
3232
}
3333

34+
@ZenMethod
35+
public static void addShapedFixed(IItemStack output, IIngredient[][] inputs) {
36+
ModTweaker.LATE_ADDITIONS.add(new AddShapedFixed(output, inputs));
37+
}
38+
3439
@ZenMethod
3540
public static void addShapeless(IItemStack output, IIngredient[] inputs) {
3641
ModTweaker.LATE_ADDITIONS.add(new AddShapeless(output, inputs));
@@ -41,6 +46,11 @@ public static void removeShaped(IItemStack output, @Optional IIngredient[][] ing
4146
ModTweaker.LATE_REMOVALS.add(new RemoveShaped(output, ingredients));
4247
}
4348

49+
@ZenMethod
50+
public static void removeShapedFixed(IItemStack output, @Optional IIngredient[][] ingredients) {
51+
ModTweaker.LATE_REMOVALS.add(new RemoveShapedFixed(output, ingredients));
52+
}
53+
4454
@ZenMethod
4555
public static void removeShapeless(IItemStack output, @Optional IIngredient[] ingredients) {
4656
ModTweaker.LATE_REMOVALS.add(new RemoveShapeless(output, ingredients));
@@ -53,8 +63,8 @@ public static void removeAll() {
5363

5464
public static class AddShaped extends BaseAction {
5565

56-
private final IItemStack output;
57-
private final IIngredient[][] ingredients;
66+
protected final IItemStack output;
67+
protected final IIngredient[][] ingredients;
5868

5969
public AddShaped(IItemStack output, IIngredient[][] ingredients) {
6070
super("Add Anvil Shaped Recipe");
@@ -73,6 +83,18 @@ protected String getRecipeInfo() {
7383
}
7484
}
7585

86+
public static class AddShapedFixed extends AddShaped {
87+
88+
public AddShapedFixed(IItemStack output, IIngredient[][] ingredients) {
89+
super(output, ingredients);
90+
}
91+
92+
@Override
93+
public void apply() {
94+
AnvilRecipes.addSteelShapedRecipe(new ResourceLocation("crafttweaker", this.name), InputHelper.toStack(output), toShapedAnvilObjectsFixed(ingredients));
95+
}
96+
}
97+
7698
public static class AddShapeless extends BaseAction {
7799

78100
private final IItemStack output;
@@ -122,10 +144,37 @@ public static Object[] toShapedAnvilObjects(IIngredient[][] ingredients) {
122144
}
123145
}
124146

147+
public static Object[] toShapedAnvilObjectsFixed(IIngredient[][] ingredients) {
148+
if(ingredients == null)
149+
return null;
150+
else {
151+
ArrayList<Object> prep = new ArrayList<>();
152+
char chr = 'a';
153+
for(int x = 0; x < 4; x++) {
154+
StringBuilder matrix = new StringBuilder();
155+
for(int y = 0; y < 4; y++) {
156+
if(x < ingredients.length && ingredients[x] != null && y < ingredients[x].length) {
157+
if(ingredients[x][y] != null) {
158+
prep.add(chr);
159+
prep.add(InputHelper.toObject(ingredients[x][y]));
160+
matrix.append(chr);
161+
chr++;
162+
} else {
163+
matrix.append(' ');
164+
}
165+
}
166+
}
167+
if(matrix.length() > 0)
168+
prep.add(x, matrix.toString());
169+
}
170+
return prep.toArray();
171+
}
172+
}
173+
125174
public static class RemoveShaped extends BaseAction {
126175

127-
private final IItemStack output;
128-
private final IIngredient[][] ingredients;
176+
protected final IItemStack output;
177+
protected final IIngredient[][] ingredients;
129178

130179
protected RemoveShaped(IItemStack output, IIngredient[][] ingredients) {
131180
super("Remove Shaped Anvil");
@@ -159,6 +208,32 @@ protected String getRecipeInfo() {
159208
}
160209
}
161210

211+
public static class RemoveShapedFixed extends RemoveShaped {
212+
213+
protected RemoveShapedFixed(IItemStack output, IIngredient[][] ingredients) {
214+
super(output, ingredients);
215+
}
216+
217+
@Override
218+
public void apply() {
219+
if(ingredients != null) {
220+
IRecipe removal = new ShapedAnvilRecipe(new ResourceLocation("crafttweaker", this.name), InputHelper.toStack(output), toShapedAnvilObjectsFixed(ingredients));
221+
for(Iterator<IRecipe> iterator = AnvilCraftingManager.ANVIL_CRAFTING.iterator(); iterator.hasNext(); ) {
222+
IRecipe recipe = iterator.next();
223+
if(recipe.getRecipeOutput().isItemEqual(removal.getRecipeOutput()) && removal.getIngredients().equals(recipe.getIngredients()))
224+
iterator.remove();
225+
}
226+
} else {
227+
for(Iterator<IRecipe> iterator = AnvilCraftingManager.ANVIL_CRAFTING.iterator(); iterator.hasNext(); ) {
228+
IRecipe recipe = iterator.next();
229+
if(recipe.getRecipeOutput().isItemEqual(InputHelper.toStack(output))) {
230+
iterator.remove();
231+
}
232+
}
233+
}
234+
}
235+
}
236+
162237
public static class RemoveShapeless extends BaseAction {
163238

164239
private final IItemStack output;

0 commit comments

Comments
 (0)