/
ModRegistry.java
204 lines (176 loc) · 7.64 KB
/
ModRegistry.java
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package mezz.jei.util;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import mezz.jei.JeiHelpers;
import mezz.jei.RecipeRegistry;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.IItemRegistry;
import mezz.jei.api.IJeiHelpers;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.gui.IAdvancedGuiHandler;
import mezz.jei.api.ingredients.IIngredientRegistry;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeRegistryPlugin;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import mezz.jei.api.recipe.transfer.IRecipeTransferRegistry;
import mezz.jei.gui.RecipeClickableArea;
import mezz.jei.plugins.jei.description.ItemDescriptionRecipe;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
public class ModRegistry implements IModRegistry {
private final IJeiHelpers jeiHelpers;
private final IItemRegistry itemRegistry;
private final IIngredientRegistry ingredientRegistry;
private final List<IRecipeCategory> recipeCategories = new ArrayList<IRecipeCategory>();
private final List<IRecipeHandler> recipeHandlers = new ArrayList<IRecipeHandler>();
private final List<IAdvancedGuiHandler<?>> advancedGuiHandlers = new ArrayList<IAdvancedGuiHandler<?>>();
private final List<Object> recipes = new ArrayList<Object>();
private final RecipeTransferRegistry recipeTransferRegistry;
private final Multimap<Class<? extends GuiContainer>, RecipeClickableArea> recipeClickableAreas = HashMultimap.create();
private final Multimap<String, ItemStack> craftItemsForCategories = HashMultimap.create();
private final List<IRecipeRegistryPlugin> recipeRegistryPlugins = new ArrayList<IRecipeRegistryPlugin>();
public ModRegistry(JeiHelpers jeiHelpers, IItemRegistry itemRegistry, IIngredientRegistry ingredientRegistry) {
this.jeiHelpers = jeiHelpers;
this.itemRegistry = itemRegistry;
this.ingredientRegistry = ingredientRegistry;
this.recipeTransferRegistry = new RecipeTransferRegistry(jeiHelpers.getStackHelper(), jeiHelpers.recipeTransferHandlerHelper());
}
@Override
public IJeiHelpers getJeiHelpers() {
return jeiHelpers;
}
@Override
public IItemRegistry getItemRegistry() {
return itemRegistry;
}
@Override
public IIngredientRegistry getIngredientRegistry() {
return ingredientRegistry;
}
@Override
public void addRecipeCategories(@Nullable IRecipeCategory... recipeCategories) {
if (recipeCategories != null) {
Collections.addAll(this.recipeCategories, recipeCategories);
}
}
@Override
public void addRecipeHandlers(@Nullable IRecipeHandler... recipeHandlers) {
if (recipeHandlers != null) {
Collections.addAll(this.recipeHandlers, recipeHandlers);
}
}
@Override
public void addRecipes(@Nullable List recipes) {
if (recipes != null) {
this.recipes.addAll(recipes);
}
}
@Override
public void addRecipeClickArea(@Nullable Class<? extends GuiContainer> guiClass, int xPos, int yPos, int width, int height, @Nullable String... recipeCategoryUids) {
if (guiClass == null) {
NullPointerException e = new NullPointerException();
Log.error("Tried to add a RecipeClickArea with null guiClass.", e);
return;
}
if (recipeCategoryUids == null) {
NullPointerException e = new NullPointerException();
Log.error("Tried to add a RecipeClickArea with null recipeCategoryUids.", e);
return;
}
if (recipeCategoryUids.length == 0) {
NullPointerException e = new NullPointerException();
Log.error("Tried to add a RecipeClickArea with empty list of recipeCategoryUids.", e);
return;
}
RecipeClickableArea recipeClickableArea = new RecipeClickableArea(yPos, yPos + height, xPos, xPos + width, recipeCategoryUids);
this.recipeClickableAreas.put(guiClass, recipeClickableArea);
}
@Override
public void addRecipeCategoryCraftingItem(@Nullable ItemStack craftingItem, @Nullable String... recipeCategoryUids) {
if (craftingItem == null) {
NullPointerException e = new NullPointerException();
Log.error("Tried to add a RecipeCategoryCraftingItem with null craftingItem.", e);
return;
}
if (craftingItem.getItem() == null) {
NullPointerException e = new NullPointerException();
Log.error("Tried to add a RecipeCategoryCraftingItem with null item in the craftingItem.", e);
return;
}
if (recipeCategoryUids == null) {
NullPointerException e = new NullPointerException();
Log.error("Tried to add a RecipeCategoryCraftingItem with null recipeCategoryUids.", e);
return;
}
if (recipeCategoryUids.length == 0) {
NullPointerException e = new NullPointerException();
Log.error("Tried to add a RecipeCategoryCraftingItem with an empty list of recipeCategoryUids.", e);
return;
}
for (String recipeCategoryUid : recipeCategoryUids) {
if (recipeCategoryUid == null) {
IllegalArgumentException e = new IllegalArgumentException();
Log.error("Tried to add a RecipeCategoryCraftingItem with null recipeCategoryUid.", e);
} else {
this.craftItemsForCategories.put(recipeCategoryUid, craftingItem);
}
}
}
@Override
public void addAdvancedGuiHandlers(@Nullable IAdvancedGuiHandler<?>... advancedGuiHandlers) {
if (advancedGuiHandlers != null) {
Collections.addAll(this.advancedGuiHandlers, advancedGuiHandlers);
}
}
@Override
public void addDescription(@Nullable List<ItemStack> itemStacks, @Nullable String... descriptionKeys) {
if (itemStacks == null || itemStacks.size() == 0) {
IllegalArgumentException e = new IllegalArgumentException();
Log.error("Tried to add description with no itemStacks.", e);
return;
}
if (descriptionKeys == null) {
IllegalArgumentException e = new IllegalArgumentException();
Log.error("Tried to add a null descriptionKey for itemStacks {}.", itemStacks, e);
return;
}
if (descriptionKeys.length == 0) {
IllegalArgumentException e = new IllegalArgumentException();
Log.error("Tried to add an empty list of descriptionKeys for itemStacks {}.", itemStacks, e);
return;
}
IGuiHelper guiHelper = jeiHelpers.getGuiHelper();
List<ItemDescriptionRecipe> recipes = ItemDescriptionRecipe.create(guiHelper, itemStacks, descriptionKeys);
this.recipes.addAll(recipes);
}
@Override
public void addDescription(@Nullable ItemStack itemStack, @Nullable String... descriptionKeys) {
addDescription(Collections.singletonList(itemStack), descriptionKeys);
}
@Override
public IRecipeTransferRegistry getRecipeTransferRegistry() {
return recipeTransferRegistry;
}
@Override
public void addRecipeRegistryPlugin(@Nullable IRecipeRegistryPlugin recipeRegistryPlugin) {
if (recipeRegistryPlugin == null) {
NullPointerException e = new NullPointerException();
Log.error("Tried to add null recipeRegistryPlugin.", e);
return;
}
Log.info("Added recipe registry plugin: {}", recipeRegistryPlugin.getClass());
recipeRegistryPlugins.add(recipeRegistryPlugin);
}
public List<IAdvancedGuiHandler<?>> getAdvancedGuiHandlers() {
return advancedGuiHandlers;
}
public RecipeRegistry createRecipeRegistry(StackHelper stackHelper, IIngredientRegistry ingredientRegistry) {
List<IRecipeTransferHandler> recipeTransferHandlers = recipeTransferRegistry.getRecipeTransferHandlers();
return new RecipeRegistry(stackHelper, recipeCategories, recipeHandlers, recipeTransferHandlers, recipes, recipeClickableAreas, craftItemsForCategories, ingredientRegistry, recipeRegistryPlugins);
}
}