-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path08-datatype-maps.zs
66 lines (57 loc) · 2.37 KB
/
08-datatype-maps.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
import crafttweaker.oredict.IOreDictEntry;
/*
Crafttweaker Maps/Associative Arrays
Immersive Engineering Required for script to work (Thermal Foundation is optional)
https://www.youtube.com/watch?v=3hX4XH1VYvw
A map (or an Associative Array, which is the proper term) is a data-type that's similiar to arrays.
The big difference being that a map can have non-numeric indexes.
A map is declared with the {} brackets and entries are specified as key: value
Text before the key separator ":" will be interpreted as strings even if they don't have
the quotation marks, so both iron and "iron" would later be accessed through map["iron"]
You could fetch the IOreDictEntry for oreIron from the metalObjects map
with -> metalObjects["iron"].ore
When wondering what key represents what nesting level just read
"as IOreDictEntry[string][string]" LEFT to right
So for example:
First [string] bracket represents the level where the iron, gold and copper keys are
Second [string] bracket represents the level where the ore and dust keys are
Thidrly IOreDictEntry, The value.
*/
var metalObjects as IOreDictEntry[string][string] = {
iron: {
ore: <ore:oreIron>,
dust: <ore:dustIron>
},
gold: {
ore: <ore:oreGold>,
dust: <ore:dustGold>
},
copper: {
ore: <ore:oreCopper>,
dust: <ore:dustCopper>
},
silver: {
ore: <ore:oreSilver>,
dust: <ore:dustSilver>
}
};
# They can both be accessed with [key][key] or [key].memberGetter
print(metalObjects["iron"]["dust"].firstItem.displayName); # -> Pulverized Iron
print(metalObjects["copper"]["ore"].firstItem.displayName); # -> Copper Ore
print(metalObjects["iron"].dust.firstItem.displayName); # -> Pulverized Iron
print(metalObjects["copper"].ore.firstItem.displayName); # -> Copper Ore
/*
You can loop nested maps like these with
either the key, value iterator and grab the nested map from -> value
*/
for key, value in metalObjects {
recipes.addShapeless(value.dust.firstItem * 4,
[<immersiveengineering:tool>, value.ore]
);
}
# or the key iterator and get the nested map from -> metalObjects[key]
for key in metalObjects {
recipes.addShapeless(metalObjects[key].dust.firstItem * 4,
[<immersiveengineering:tool>, metalObjects[key].ore]
);
}