forked from EnigmaticaModpacks/Enigmatica2Expert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.zs
359 lines (309 loc) · 10.7 KB
/
utils.zs
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
Bunch of handy utilities for zenscript
Author: https://github.com/Krutoy242
*/
#priority 4000
import crafttweaker.data.IData;
import crafttweaker.item.IIngredient;
import crafttweaker.item.IItemStack;
import crafttweaker.oredict.IOreDictEntry;
import crafttweaker.recipes.IRecipeFunction;
zenClass Utils {
var DEBUG as bool = false;
static modPreference as string[] = [
"minecraft",
"thermalfoundation",
"immersiveengineering",
"ic2",
"mekanism",
"appliedenergistics2",
"actuallyadditions",
"tconstruct",
"chisel",
] as string[];
zenConstructor() { }
function getSomething(oreName as string, entryNames as string[]) as IItemStack { return getSomething(oreName, entryNames, 1); }
function getSomething(oreName as string, entryNames as string[], amount as int) as IItemStack {
if (isNull(oreName)) return null;
// Find with JAOPCA
val JOREoutput = mods.jaopca.JAOPCA.getOre(oreName);
var something as IItemStack = null;
if (!isNull(JOREoutput)) {
var k = 0;
while k < entryNames.length && isNull(something) {
something = JOREoutput.getItemStack(entryNames[k]);
k += 1;
}
}
// Find with Oredict
if (isNull(something)) {
for str in entryNames {
val oreItems = oreDict[str~oreName].items;
if (oreItems.length>0) {
for preffer in modPreference {
for item in oreItems {
if(item.definition.id.startsWith(preffer))
return countOutput(item * amount, oreName);
}
}
return countOutput(oreDict[str~oreName].firstItem * amount, oreName);
}
}
}
// Find with smelting
if (isNull(something) && entryNames has "any") {
val oreItems = oreDict['ore'~oreName].items;
if (oreItems.length>0) {
something = smelt(oreDict['ore'~oreName]);
}
}
return isNull(something) ? null : countOutput(something * amount, oreName);
}
# Return result of smelting in vanilla furnace
function smelt(input as IIngredient) as IItemStack {
for r in furnace.all {
if (r.input has input || input has r.input) return r.output;
}
return null;
}
function compact(a as IIngredient, b as IIngredient) as void {
recipes.addShapeless(b.itemArray[0].anyAmount(), [a,a,a,a,a,a,a,a,a]);
recipes.addShapeless(a.itemArray[0] * 9, [b]);
}
function ingredientFromArrayByRegex(regex as string) as IIngredient {
var items = itemUtils.getItemsByRegexRegistryName(regex);
if (!isNull(items) && items.length > 0) {
if (items.length == 1) return items[0];
var result = items[0] as IIngredient;
for i in 1 to items.length {
result = result | items[i];
}
return result;
}
return null;
}
# ########################
# Removing item everywhere
# ########################
function rh(ingr as IIngredient) as void { rh(ingr, true); }
function rh(ingr as IIngredient, removeOredict as bool) as void {
if (isNull(ingr)) return;
for item in ingr.items {
if(removeOredict) {
for ore in item.ores {
ore.remove(item);
}
}
val actualItem = (item.damage == 0 && item.isDamageable)
? item.anyDamage()
: item;
furnace.remove(<*>, actualItem);
furnace.remove(actualItem);
recipes.remove(actualItem);
if (DEBUG) log('purged: ' ~ actualItem.commandString, item.displayName);
}
}
# ########################
# Conditional Loging
# ########################
function log(a as string) as void {log(a,null,null);}
function log(a as string, b as string) as void {log(a,b,null);}
function log(a as string, b as string, c as string) as void {
if (DEBUG) print(
(!isNull(a) ? a : "") ~
(!isNull(b) ? " " ~ b : "") ~
(!isNull(c) ? " " ~ c : ""));
}
function log(arr as string[]) as void {
if (DEBUG) {
if (isNull(arr) || arr.length <=0) {
print("");
return;
}
var s = "";
for str in arr {
s = s ~ " " ~ str;
}
print(s);
}
}
# ########################
# Graph
# ########################
function graph(map as string[], keys as string[][string]) as string[][double[string]] { return graph(map, null, keys); }
function graph(map as string[], options as IData, keys as string[][string]) as string[][double[string]] {
if (isNull(map) || map.length <= 0) {
logger.logWarning("utils.graph() first argument should be non-empty string[].");
return {};
}
# Determine max dimensions
var height = map.length;
var width = 0;
for line in map {
width = max(width, line.length);
}
if (width <= 0) {
logger.logWarning("utils.graph() first argument should content at least one non-empty string");
return {};
}
# Compute min-max for each dimension
val dopt = D(options);
var minX = dopt.getDouble("x.min" , 0.0d);
var maxX = dopt.getDouble("x.max" , 1.0d);
var minY = dopt.getDouble("y.min" , 0.0d);
var maxY = dopt.getDouble("y.max" , 1.0d);
var stepX= dopt.get("x.step");
var stepY= dopt.get("y.step");
# Determine doulbe steps
var intervalX = (maxX - minX) / (max(1, width - 1) as double);
var intervalY = (maxY - minY) / (max(1, height - 1) as double);
# Write result
var result as string[][double[string]] = {};
var resultLen = 0;
for y in 0 to map.length {
for x in 0 to map[y].length {
var c = map[y][x];
if (c != " " && !isNull(keys[c])) {
var X = intervalX * x + minX;
var Y = maxY - intervalY * y;
if(!isNull(stepX)) X = ((X / stepX.asDouble()) as int) as double * stepX.asDouble();
if(!isNull(stepY)) Y = ((Y / stepY.asDouble()) as int) as double * stepY.asDouble();
result[{x: X, y: Y} as double[string]] = keys[c];
resultLen += 1;
}
}
}
if (resultLen <= 0) logger.logWarning("utils.graph() graph cant find any valid key");
return result;
}
static defaultEmount as double[string] = {
"Amber" : 2.0d,
"Amethyst" : 2.0d,
"Apatite" : 10.0d,
"Aquamarine" : 4.0d,
"CertusQuartz" : 3.0d,
"ChargedCertusQuartz" : 2.0d,
"Coal" : 5.0d,
"Diamond" : 2.0d,
"DimensionalShard" : 3.0d,
"Emerald" : 2.0d,
"Glowstone" : 4.0d,
"Lapis" : 10.0d,
"Malachite" : 2.0d,
"Peridot" : 2.0d,
"Quartz" : 3.0d,
"QuartzBlack" : 2.0d,
"quicksilver" : 2.0d,
"Redstone" : 10.0d,
"Ruby" : 2.0d,
"Sapphire" : 2.0d,
"Tanzanite" : 2.0d,
"Topaz" : 2.0d,
} as double[string];
function countOutput(item as IItemStack, oreName as string) as IItemStack {
val def = defaultEmount[oreName];
if(isNull(def)) return amountClamp(item);
val d = def as double;
if (d != 0.0d) {
return item * min(64, (((item.amount as double - 1.0d) * (d*0.75d) + d) as int));
}
return amountClamp(item);
}
function amountClamp(item as IItemStack) as IItemStack {
if(isNull(item)) return null;
if(item.amount==1) return item.anyAmount();
return item * min(64, item.amount);
}
# Turn one item into another but keep all tags
var upgradeFnc as IRecipeFunction = function(out, ins, cInfo){
if(ins has "marked" && !isNull(ins.marked) && ins.marked.hasTag) {
var tag = ins.marked.tag;
return out.withTag(tag);
}
return out;
};
# Try to get item by string. If fail - return second vaiant
function tryCatch(first as string, meta as int, second as IItemStack) as IItemStack {
val item = itemUtils.getItem(first, meta);
return isNull(item) ? second : item;
}
function tryCatch(first as string, second as IItemStack) as IItemStack {
return tryCatch(first, 0, second);
}
function tryCatch(first as IItemStack, second as IItemStack) as IItemStack {
return isNull(first) ? second : first;
}
# Safe get item with nbt tag and amount
function get(id as string ) as IItemStack {return get(id, 0, 1, null);}
function get(id as string, meta as short ) as IItemStack {return get(id, meta, 1, null);}
function get(id as string, meta as short, amount as int ) as IItemStack {return get(id, meta, amount, null);}
function get(id as string, meta as short, amount as int, nbt as IData) as IItemStack {
val item = itemUtils.getItem(id, meta);
if(isNull(item)) return null;
return isNull(nbt)
? (amount > 1 ? item * amount : item)
: (amount > 1 ? item * amount : item).withTag(nbt);
}
# Clear Fluid tag on item preserving other tags
function clearFluid(input as IItemStack) as void {
clearFluid(input, "Fluid Clearing " ~ input.definition.id.replaceAll(":", "_") ~ "_" ~ input.damage);
}
function clearFluid(input as IItemStack, recipeName as string) as void {
recipes.addShapeless(recipeName,
input, [input.marked("marked")],
function(out, ins, cInfo) {
if(ins has "marked" && !isNull(ins.marked) && ins.marked.hasTag) {
var tag = ins.marked.tag;
if (!isNull(tag.Fluid)) {
# Usual tanks
tag = tag - "Fluid";
} else
if (!isNull(tag.tank)) {
# Open Blocks
tag = tag - "tank";
} else
if (!isNull(tag.FluidName) && !isNull(tag.Amount)) {
# Black hole or other
tag = tag - "FluidName" - "Amount";
}
if(tag == {} as IData) return out;
return out.withTag(tag);
}
return out;
}, null);
}
function sortInt(list as int[]) as int[] {
if(isNull(list)) return null;
if(list.length == 1) return [0];
var sorted = [] as int[];
for i in 0 to list.length {
var g_v = 0;
var g_i = i;
for j in 0 to list.length {
if(list[j] >= g_v && !(sorted has j)) {
g_v = list[j];
g_i = j;
}
}
sorted += g_i;
}
return sorted;
}
}
global utils as Utils = Utils();
# ########################
# Get mob soul by its name
# ########################
global Soul as function(string)IItemStack = function (name as string) as IItemStack {
val soul = itemUtils.getItem("draconicevolution:mob_soul");
if (!isNull(soul)) {
return soul.withTag({EntityName: name});
}
return null;
};
# ########################
# Fluid Cell is like bucket, but stackable
# ########################
global FluidCell as function(string)IItemStack = function (name as string) as IItemStack {
return <ic2:fluid_cell>.withTag({Fluid: {FluidName: name, Amount: 1000}});
};