File size: 2,161 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package net.minecraft.recipebook;

import java.util.Iterator;
import net.minecraft.util.Mth;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.ShapedRecipe;

public interface PlaceRecipeHelper {
    static <T> void placeRecipe(int p_369532_, int p_361267_, Recipe<?> p_361929_, Iterable<T> p_367857_, PlaceRecipeHelper.Output<T> p_369633_) {
        if (p_361929_ instanceof ShapedRecipe shapedrecipe) {
            placeRecipe(p_369532_, p_361267_, shapedrecipe.getWidth(), shapedrecipe.getHeight(), p_367857_, p_369633_);
        } else {
            placeRecipe(p_369532_, p_361267_, p_369532_, p_361267_, p_367857_, p_369633_);
        }
    }

    static <T> void placeRecipe(int p_363279_, int p_367196_, int p_360764_, int p_364759_, Iterable<T> p_367701_, PlaceRecipeHelper.Output<T> p_369100_) {
        Iterator<T> iterator = p_367701_.iterator();
        int i = 0;

        for (int j = 0; j < p_367196_; j++) {
            boolean flag = (float)p_364759_ < (float)p_367196_ / 2.0F;
            int k = Mth.floor((float)p_367196_ / 2.0F - (float)p_364759_ / 2.0F);
            if (flag && k > j) {
                i += p_363279_;
                j++;
            }

            for (int l = 0; l < p_363279_; l++) {
                if (!iterator.hasNext()) {
                    return;
                }

                flag = (float)p_360764_ < (float)p_363279_ / 2.0F;
                k = Mth.floor((float)p_363279_ / 2.0F - (float)p_360764_ / 2.0F);
                int i1 = p_360764_;
                boolean flag1 = l < p_360764_;
                if (flag) {
                    i1 = k + p_360764_;
                    flag1 = k <= l && l < k + p_360764_;
                }

                if (flag1) {
                    p_369100_.addItemToSlot(iterator.next(), i, l, j);
                } else if (i1 == l) {
                    i += p_363279_ - l;
                    break;
                }

                i++;
            }
        }
    }

    @FunctionalInterface
    public interface Output<T> {
        void addItemToSlot(T p_363956_, int p_361316_, int p_365726_, int p_362457_);
    }
}