aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/api/EntryRegistry.java
blob: 9a811a1277111453858606742dbf4738f2fefbdf (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Roughly Enough Items by Danielshe.
 * Licensed under the MIT License.
 */

package me.shedaniel.rei.api;

import me.shedaniel.rei.api.annotations.ToBeRemoved;
import me.shedaniel.rei.utils.CollectionUtils;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import java.util.Collections;
import java.util.List;

public interface EntryRegistry {
    
    /**
     * Gets the current unmodifiable item list
     *
     * @return an unmodifiable item list
     */
    @Deprecated
    default List<Entry> getEntryList() {
        return Collections.unmodifiableList(getModifiableEntryList());
    }
    
    /**
     * Gets the current modifiable stacks list
     *
     * @return a stacks list
     */
    List<EntryStack> getStacksList();
    
    /**
     * Gets the current modifiable item list
     *
     * @return an modifiable item list
     */
    @Deprecated
    default List<Entry> getModifiableEntryList() {
        return CollectionUtils.map(getStacksList(), EntryStack::toEntry);
    }
    
    /**
     * Gets all possible stacks from an item
     *
     * @param item the item to find
     * @return the array of possible stacks
     */
    ItemStack[] getAllStacksFromItem(Item item);
    
    /**
     * Registers an new stack to the item list
     *
     * @param afterItem the stack to put after
     * @param stack     the stack to register
     */
    @Deprecated
    default void registerItemStack(Item afterItem, ItemStack stack) {
        registerEntryAfter(EntryStack.create(afterItem), EntryStack.create(stack));
    }
    
    @Deprecated
    default void registerFluid(Fluid fluid) {
        registerEntry(EntryStack.create(fluid));
    }
    
    default void registerEntry(EntryStack stack) {
        registerEntryAfter(null, stack);
    }
    
    void registerEntryAfter(EntryStack afterEntry, EntryStack stack);
    
    @ToBeRemoved
    @Deprecated
    default void registerItemStack(Item afterItem, ItemStack... stacks) {
        EntryStack afterStack = EntryStack.create(afterItem);
        for (int i = stacks.length - 1; i >= 0; i--) {
            ItemStack stack = stacks[i];
            if (stack != null && !stack.isEmpty())
                registerEntryAfter(afterStack, EntryStack.create(stack));
        }
    }
    
    /**
     * Registers multiple stacks to the item list
     *
     * @param afterStack the stack to put after
     * @param stacks     the stacks to register
     */
    default void registerEntriesAfter(EntryStack afterStack, EntryStack... stacks) {
        for (int i = stacks.length - 1; i >= 0; i--) {
            EntryStack stack = stacks[i];
            if (stack != null && !stack.isEmpty())
                registerEntryAfter(afterStack, stack);
        }
    }
    
    @ToBeRemoved
    @Deprecated
    default void registerItemStack(ItemStack... stacks) {
        registerItemStack(null, stacks);
    }
    
    /**
     * Registers multiple stacks to the item list
     *
     * @param stacks the stacks to register
     */
    default void registerEntries(EntryStack... stacks) {
        registerEntriesAfter(null, stacks);
    }
    
    @ToBeRemoved
    @Deprecated
    default boolean alreadyContain(ItemStack stack) {
        return alreadyContain(EntryStack.create(stack));
    }
    
    /**
     * Checks if a stack is already registered
     *
     * @param stack the stack to check
     * @return whether the stack has been registered
     */
    default boolean alreadyContain(EntryStack stack) {
        return CollectionUtils.anyMatchEqualsAll(getStacksList(), stack);
    }
    
}