aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/server/RecipeGridAligner.java
blob: 5ac9bbab816f2ac1e51345441564941db24075a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package me.shedaniel.rei.server;

import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.ShapedRecipe;
import net.minecraft.util.math.MathHelper;

import java.util.Iterator;

public interface RecipeGridAligner<T> {
    default void alignRecipeToGrid(int craftingGridWidth, int craftingGridHeight, int resultSlotIndex, Recipe<?> recipe, Iterator<T> iterator_1, int int_4) {
        int recipeWidth = craftingGridWidth;
        int recipeHeight = craftingGridHeight;
        if (recipe instanceof ShapedRecipe) {
            ShapedRecipe shapedRecipe = (ShapedRecipe) recipe;
            recipeWidth = shapedRecipe.getWidth();
            recipeHeight = shapedRecipe.getHeight();
        }
        
        int slotId = 0;
        
        for (int int_8 = 0; int_8 < craftingGridHeight; ++int_8) {
            if (slotId == resultSlotIndex) {
                ++slotId;
            }
            
            boolean boolean_1 = (float) recipeHeight < (float) craftingGridHeight / 2.0F;
            int int_9 = MathHelper.floor((float) craftingGridHeight / 2.0F - (float) recipeHeight / 2.0F);
            if (boolean_1 && int_9 > int_8) {
                slotId += craftingGridWidth;
                ++int_8;
            }
            
            for (int int_10 = 0; int_10 < craftingGridWidth; ++int_10) {
                if (!iterator_1.hasNext()) {
                    return;
                }
                
                boolean_1 = (float) recipeWidth < (float) craftingGridWidth / 2.0F;
                int_9 = MathHelper.floor((float) craftingGridWidth / 2.0F - (float) recipeWidth / 2.0F);
                int int_11 = recipeWidth;
                boolean boolean_2 = int_10 < recipeWidth;
                if (boolean_1) {
                    int_11 = int_9 + recipeWidth;
                    boolean_2 = int_9 <= int_10 && int_10 < int_9 + recipeWidth;
                }
                
                if (boolean_2) {
                    this.acceptAlignedInput(iterator_1, slotId, int_4, int_8, int_10);
                } else if (int_11 == int_10) {
                    slotId += craftingGridWidth - int_10;
                    break;
                }
                
                ++slotId;
            }
        }
        
    }
    
    void acceptAlignedInput(Iterator<T> var1, int var2, int var3, int var4, int var5);
}