forked from MightyPirates/TIS-3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManualAPI.java
200 lines (183 loc) · 6.7 KB
/
ManualAPI.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
package li.cil.tis3d.api;
import li.cil.tis3d.api.manual.ContentProvider;
import li.cil.tis3d.api.manual.ImageProvider;
import li.cil.tis3d.api.manual.ImageRenderer;
import li.cil.tis3d.api.manual.PathProvider;
import li.cil.tis3d.api.manual.TabIconRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nullable;
/**
* This API allows interfacing with the in-game manual of OpenComputers.
* <p>
* It allows opening the manual at a desired specific page, as well as
* registering custom tabs and content callback handlers.
* <p>
* Note: this is a <em>client side only</em> API. It will do nothing on
* dedicated servers (i.e. <tt>API.manual</tt> will be <tt>null</tt>).
*/
public final class ManualAPI {
/**
* Register a tab to be displayed next to the manual.
* <p>
* These are intended to link to index pages, and for the time being there
* a relatively low number of tabs that can be displayed, so I'd ask you to
* only register as many tabs as actually, technically *needed*. Which will
* usually be one, for your main index page.
*
* @param renderer the renderer used to render the icon on your tab.
* @param tooltip the unlocalized tooltip of the tab, or <tt>null</tt>.
* @param path the path to the page to open when the tab is clicked.
*/
public static void addTab(final TabIconRenderer renderer, final String tooltip, final String path) {
if (API.manualAPI != null) {
API.manualAPI.addTab(renderer, tooltip, path);
}
}
/**
* Register a path provider.
* <p>
* Path providers are used to find documentation entries for item stacks
* and blocks in the world.
*
* @param provider the provider to register.
*/
public static void addProvider(final PathProvider provider) {
if (API.manualAPI != null) {
API.manualAPI.addProvider(provider);
}
}
/**
* Register a content provider.
* <p>
* Content providers are used to resolve paths to page content, if the
* standard system (using Minecraft's resource loading facilities) fails.
* <p>
* This can be useful for providing dynamic content, for example.
*
* @param provider the provider to register.
*/
public static void addProvider(final ContentProvider provider) {
if (API.manualAPI != null) {
API.manualAPI.addProvider(provider);
}
}
/**
* Register an image provider.
* <p>
* Image providers are used to render custom content in a page. These are
* selected via the standard image tag of Markdown, based on the prefix of
* the image URL, i.e. <tt>![tooltip](prefix:data)</tt> will select the
* image provider registered for the prefix <tt>prefix</tt>, and pass to
* it the argument <tt>data</tt>, then use the returned renderer to draw
* an element in the place of the tag. The provided prefix is expected to
* be <em>without</em> the colon (<tt>:</tt>).
* <p>
* Custom providers are only selected if a prefix is matched, otherwise
* it'll treat it as a relative path to an image to load via Minecraft's
* resource providing facilities, and display that.
*
* @param prefix the prefix on which to use the provider.
* @param provider the provider to register.
*/
public static void addProvider(final String prefix, final ImageProvider provider) {
if (API.manualAPI != null) {
API.manualAPI.addProvider(prefix, provider);
}
}
/**
* Get the image renderer for the specified image path.
* <p>
* This will look for {@link ImageProvider}s registered for a prefix in the
* specified path. If there is no match, or the matched content provider
* does not provide a renderer, this will return <tt>null</tt>.
*
* @param path the path to the image to get the renderer for.
* @return the custom renderer for that path.
*/
@Nullable
public static ImageRenderer imageFor(final String path) {
if (API.manualAPI != null) {
return API.manualAPI.imageFor(path);
}
return null;
}
// ----------------------------------------------------------------------- //
/**
* Look up the documentation path for the specified item stack.
*
* @param stack the stack to find the documentation path for.
* @return the path to the page, <tt>null</tt> if none is known.
*/
@Nullable
public static String pathFor(final ItemStack stack) {
if (API.manualAPI != null) {
return API.manualAPI.pathFor(stack);
}
return null;
}
/**
* Look up the documentation for the specified block in the world.
*
* @param world the world containing the block.
* @param pos the position of the block.
* @return the path to the page, <tt>null</tt> if none is known.
*/
@Nullable
public static String pathFor(final World world, final BlockPos pos) {
if (API.manualAPI != null) {
return API.manualAPI.pathFor(world, pos);
}
return null;
}
/**
* Get the content of the documentation page at the specified location.
*
* @param path the path of the page to get the content of.
* @return the content of the page, or <tt>null</tt> if none exists.
*/
@Nullable
public static Iterable<String> contentFor(final String path) {
if (API.manualAPI != null) {
return API.manualAPI.contentFor(path);
}
return null;
}
// ----------------------------------------------------------------------- //
/**
* Open the manual for the specified player.
* <p>
* If you wish to display a specific page, call {@link #navigate(String)}
* after this function returns, with the path to the page to show.
*
* @param player the player to open the manual for.
*/
public static void openFor(final EntityPlayer player) {
if (API.manualAPI != null) {
API.manualAPI.openFor(player);
}
}
/**
* Reset the history of the manual.
*/
public static void reset() {
if (API.manualAPI != null) {
API.manualAPI.reset();
}
}
/**
* Navigate to a page in the manual.
*
* @param path the path to navigate to.
*/
public static void navigate(final String path) {
if (API.manualAPI != null) {
API.manualAPI.navigate(path);
}
}
// ----------------------------------------------------------------------- //
private ManualAPI() {
}
}