-
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathHopper.java
More file actions
316 lines (268 loc) · 11.8 KB
/
Hopper.java
File metadata and controls
316 lines (268 loc) · 11.8 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
package com.blamejared.compat.betterwithmods;
import betterwithmods.api.tile.IHopperFilter;
import betterwithmods.common.BWRegistry;
import betterwithmods.common.registry.HopperFilter;
import betterwithmods.common.registry.HopperInteractions;
import com.blamejared.ModTweaker;
import com.blamejared.mtlib.helpers.LogHelper;
import com.blamejared.mtlib.utils.BaseAction;
import com.google.common.collect.Lists;
import crafttweaker.annotations.ModOnly;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@ZenClass("mods.betterwithmods.FilteredHopper")
@ModOnly("betterwithmods")
@ZenRegister
public class Hopper {
@ZenMethod
public static void addFilter(String name, IIngredient filter) {
ModTweaker.LATE_ADDITIONS.add(new AddFilter(name,CraftTweakerMC.getIngredient(filter)));
}
@ZenMethod
public static void addFilteredItem(String name, IIngredient item) {
addFilteredItem(name, new IIngredient[]{item});
}
@ZenMethod
public static void addFilteredItem(String name, IIngredient[] items) {
ModTweaker.LATE_ADDITIONS.add(new AddFilterItem(name,Arrays.stream(items).map(CraftTweakerMC::getIngredient).collect(Collectors.toList())));
}
@ZenMethod
public static void addFilterRecipe(String name, IIngredient input, IItemStack[] outputs, IItemStack[] secondary) {
ModTweaker.LATE_ADDITIONS.add(new AddHopperRecipe(name,
CraftTweakerMC.getIngredient(input),
Lists.newArrayList(CraftTweakerMC.getItemStacks(outputs)),
Lists.newArrayList(CraftTweakerMC.getItemStacks(secondary))));
}
@ZenMethod
public static void addSoulUseRecipe(String name, IIngredient input, int soulAmount, IItemStack[] outputs, IItemStack[] secondary) {
ModTweaker.LATE_ADDITIONS.add(new AddSoulUseRecipe(name,
CraftTweakerMC.getIngredient(input),
soulAmount,
Lists.newArrayList(CraftTweakerMC.getItemStacks(outputs)),
Lists.newArrayList(CraftTweakerMC.getItemStacks(secondary))));
}
@ZenMethod
public static void addSoulUrnRecipe(IIngredient input, IItemStack[] outputs, IItemStack[] secondary) {
ModTweaker.LATE_ADDITIONS.add(new AddSoulUrnRecipe(CraftTweakerMC.getIngredient(input),
Lists.newArrayList(CraftTweakerMC.getItemStacks(outputs)),
Lists.newArrayList(CraftTweakerMC.getItemStacks(secondary))));
}
@ZenMethod
public static void clearFilter(String name) {
ModTweaker.LATE_REMOVALS.add(new ClearFilter(name));
}
@ZenMethod
public static void removeRecipe(IItemStack[] outputs, IItemStack[] secondary) {
ModTweaker.LATE_REMOVALS.add(new RemoveHopperRecipe(Lists.newArrayList(CraftTweakerMC.getItemStacks(outputs)),
Lists.newArrayList(CraftTweakerMC.getItemStacks(secondary))));
}
@ZenMethod
public static void removeRecipeByInput(IItemStack input) {
ModTweaker.LATE_REMOVALS.add(new RemoveHopperRecipeByInput(CraftTweakerMC.getItemStack(input)));
}
@ZenMethod
public static void removeAll() {
ModTweaker.LATE_REMOVALS.add(new RemoveAll());
}
public static class AddFilter extends BaseAction {
Ingredient ingredient;
String filterName;
protected AddFilter(String filterName, Ingredient ingredient) {
super("Filtered Hopper");
this.filterName = filterName;
this.ingredient = ingredient;
}
@Override
protected String getRecipeInfo() {
return filterName+" ("+Arrays.toString(ingredient.getMatchingStacks())+")";
}
@Override
public void apply() {
if(BWRegistry.HOPPER_FILTERS.getFilter(filterName) != HopperFilter.NONE)
LogHelper.logWarning(String.format("Hopper Filter %s couldn't be added: Filter already exists", getRecipeInfo()));
else {
BWRegistry.HOPPER_FILTERS.addFilter(new HopperFilter(filterName, ingredient, Lists.newArrayList()));
LogHelper.logInfo(String.format("Successfully added Hopper Filter %s", getRecipeInfo()));
}
}
}
public static class ClearFilter extends BaseAction {
String filterName;
protected ClearFilter(String filterName) {
super("Filtered Hopper");
this.filterName = filterName;
}
@Override
protected String getRecipeInfo() {
return filterName;
}
@Override
public void apply() {
IHopperFilter filter = BWRegistry.HOPPER_FILTERS.getFilter(filterName);
if(filter == HopperFilter.NONE || !(filter instanceof HopperFilter))
LogHelper.logWarning(String.format("Hopper Filter %s couldn't be cleared: Filter doesn't exist or is not a modifiable filter.", getRecipeInfo()));
else {
((HopperFilter) filter).getFiltered().clear();
LogHelper.logInfo(String.format("Successfully cleared Hopper Filter %s", getRecipeInfo()));
}
}
}
public static class AddFilterItem extends BaseAction {
String filterName;
List<Ingredient> items;
protected AddFilterItem(String filterName, List<Ingredient> item) {
super("Filtered Hopper");
this.filterName = filterName;
this.items = item;
}
@Override
protected String getRecipeInfo() {
return String.format("%s - %s", items.stream().map(ingredient -> Arrays.toString(ingredient.getMatchingStacks())).collect(Collectors.joining(",")), filterName);
}
@Override
public void apply() {
IHopperFilter filter = BWRegistry.HOPPER_FILTERS.getFilter(filterName);
if(filter == HopperFilter.NONE || !(filter instanceof HopperFilter))
LogHelper.logWarning(String.format("Filtered items %s couldn't be added: Filter doesn't exist or is not a modifiable filter.", getRecipeInfo()));
else {
((HopperFilter) filter).getFiltered().addAll(items);
LogHelper.logInfo(String.format("Successfully added items %s", getRecipeInfo()));
}
}
}
public static class AddHopperRecipe extends BaseAction {
String filterName;
Ingredient input;
List<ItemStack> outputs;
List<ItemStack> secondary;
public AddHopperRecipe(String filterName, Ingredient input, List<ItemStack> outputs, List<ItemStack> secondary) {
super("Filtered Hopper");
this.filterName = filterName;
this.input = input;
this.outputs = outputs;
this.secondary = secondary;
}
@Override
protected String getRecipeInfo() {
return String.format("%s -> %s,%s in %s",
Arrays.toString(input.getMatchingStacks()),
outputs.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")),
secondary.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")),
filterName);
}
@Override
public void apply() {
HopperInteractions.addHopperRecipe(new HopperInteractions.HopperRecipe(filterName,input,outputs,secondary));
}
}
public static class AddSoulUseRecipe extends BaseAction {
String filterName;
Ingredient input;
int soulAmount;
List<ItemStack> outputs;
List<ItemStack> secondary;
public AddSoulUseRecipe(String filterName, Ingredient input, int soulAmount, List<ItemStack> outputs, List<ItemStack> secondary) {
super("Filtered Hopper");
this.filterName = filterName;
this.input = input;
this.soulAmount = soulAmount;
this.outputs = outputs;
this.secondary = secondary;
}
@Override
protected String getRecipeInfo() {
return String.format("%s -> %s,%s in %s with %s souls",
Arrays.toString(input.getMatchingStacks()),
outputs.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")),
secondary.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")),
filterName,
String.valueOf(soulAmount));
}
@Override
public void apply() {
HopperInteractions.addHopperRecipe(new HopperInteractions.SoulUseRecipe(filterName,input,soulAmount,outputs,secondary));
}
}
public static class AddSoulUrnRecipe extends BaseAction {
Ingredient input;
List<ItemStack> outputs;
List<ItemStack> secondary;
public AddSoulUrnRecipe(Ingredient input, List<ItemStack> outputs, List<ItemStack> secondary) {
super("Filtered Hopper");
this.input = input;
this.outputs = outputs;
this.secondary = secondary;
}
@Override
protected String getRecipeInfo() {
return String.format("%s -> %s,%s (soul urn)",
Arrays.toString(input.getMatchingStacks()),
outputs.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")),
secondary.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")));
}
@Override
public void apply() {
HopperInteractions.addHopperRecipe(new HopperInteractions.SoulUrnRecipe(input,outputs,secondary));
}
}
public static class RemoveHopperRecipe extends BaseAction {
List<ItemStack> outputs;
List<ItemStack> secondary;
public RemoveHopperRecipe(List<ItemStack> outputs, List<ItemStack> secondary) {
super("Filtered Hopper");
this.outputs = outputs;
this.secondary = secondary;
}
@Override
protected String getRecipeInfo() {
return String.format("%s,%s",
outputs.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")),
secondary.stream().map(ItemStack::getDisplayName).collect(Collectors.joining(",")));
}
@Override
public void apply() {
if (!HopperInteractions.remove(outputs,secondary)) {
LogHelper.logWarning(String.format("No recipes were removed for outputs %s", getRecipeInfo()));
} else {
LogHelper.logInfo(String.format("Successfully removed all recipes for %s", getRecipeInfo()));
}
}
}
public static class RemoveHopperRecipeByInput extends BaseAction {
ItemStack input;
public RemoveHopperRecipeByInput(ItemStack input) {
super("Filtered Hopper");
this.input = input;
}
@Override
protected String getRecipeInfo() {
return input.getDisplayName();
}
@Override
public void apply() {
if (!HopperInteractions.removeByInput(input)) {
LogHelper.logWarning(String.format("No recipes were removed for input %s", getRecipeInfo()));
} else {
LogHelper.logInfo(String.format("Successfully removed all recipes for %s", getRecipeInfo()));
}
}
}
public static class RemoveAll extends BaseAction {
public RemoveAll() {
super("Filtered Hopper");
}
@Override
public void apply() {
HopperInteractions.RECIPES.clear();
}
}
}