11package alexiil .mc .mod .load ;
22
3+ import java .io .BufferedOutputStream ;
4+ import java .io .BufferedWriter ;
35import java .io .File ;
6+ import java .io .FileOutputStream ;
7+ import java .io .IOException ;
8+ import java .io .OutputStream ;
9+ import java .io .OutputStreamWriter ;
410import java .util .Random ;
511
612import net .minecraftforge .common .MinecraftForge ;
@@ -56,6 +62,7 @@ public class CustomLoadingScreen {
5662 "Sets the config to use for the custom loading screen. Use 'builtin/random' for a random loading screen on each load."
5763 + "\n Alternatively you can prefix this with 'config/' to load from the 'config/customloadingscreen/' directory."
5864 + "\n Or you can use 'sample/slideshow' to display images from config/customloadingscreen/slideshow_#.png."
65+ + "\n Or you can set this to 'config/example' to use the default example config."
5966 );
6067
6168 String [] defaultRandoms = { "sample/default" , "sample/white" , "sample/scrolling" , "sample_panorama_lower" };
@@ -106,6 +113,29 @@ public class CustomLoadingScreen {
106113 if (CONFIG .hasChanged ()) {
107114 CONFIG .save ();
108115 }
116+
117+ File clsRoot = new File ("./config/customloadingscreen/" );
118+
119+ if (!clsRoot .exists ()) {
120+ clsRoot .mkdir ();
121+ }
122+
123+ File clsExample = new File (clsRoot , "example.json" );
124+
125+ if (!clsExample .exists ()) {
126+
127+ try (OutputStream out = new FileOutputStream (clsExample )) {
128+ BufferedOutputStream bos = new BufferedOutputStream (out );
129+ BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (bos ));
130+
131+ writeExampleCfg (bw );
132+
133+ bw .flush ();
134+
135+ } catch (IOException e ) {
136+ CLSLog .warn ("Failed to write the example config file!" , e );
137+ }
138+ }
109139 }
110140
111141 public static void finish () {
@@ -131,4 +161,139 @@ public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event
131161 CONFIG .save ();
132162 }
133163 }
164+
165+ private static void ln (BufferedWriter bw , String str ) throws IOException {
166+ bw .write (str .replace ('#' , '"' ));
167+ bw .newLine ();
168+ }
169+
170+ private static void writeExampleCfg (BufferedWriter bw ) throws IOException {
171+ // Exploded copy of "sample/config/default.json"
172+ ln (bw , "{" );
173+ ln (bw , " #renders#: [" );
174+ ln (bw , " {" );
175+ ln (bw , " #image#: {" );
176+ ln (bw , " #parent#: #builtin/panorama#," );
177+ ln (bw , " #image#: #textures/gui/title/background/panorama_x.png#" );
178+ ln (bw , " }" );
179+ ln (bw , " }," );
180+ ln (bw , " {" );
181+ ln (bw , " #image#: {" );
182+ ln (bw , " #parent#: #builtin/image#," );
183+ ln (bw , " #image#: #customloadingscreen:textures/generic/darkened_blur_horizontal_strip.png#," );
184+ ln (bw , " #position_type#: #CENTER#," );
185+ ln (bw , " #offset_pos#: #CENTER#," );
186+ ln (bw , " #position#: {" );
187+ ln (bw , " #x#: #0#," );
188+ ln (bw , " #y#: #0#," );
189+ ln (bw , " #width#: #screen_width#," );
190+ ln (bw , " #height#: #100#" );
191+ ln (bw , " }," );
192+ ln (bw , " #texture#: {" );
193+ ln (bw , " #x#: #0#," );
194+ ln (bw , " #y#: #0#," );
195+ ln (bw , " #width#: #1#," );
196+ ln (bw , " #height#: #1#" );
197+ ln (bw , " }" );
198+ ln (bw , " }" );
199+ ln (bw , " }," );
200+ ln (bw , " {" );
201+ ln (bw , " #image#: {" );
202+ ln (bw , " #parent#:#builtin/image#," );
203+ ln (bw , " #image#: #customloadingscreen:textures/progress_bars.png#," );
204+ ln (bw , " #position_type#: #CENTER#," );
205+ ln (bw , " #offset_pos#: #CENTER#," );
206+ ln (bw , " #position#:{" );
207+ ln (bw , " #x#: #0#," );
208+ ln (bw , " #y#:#20#," );
209+ ln (bw , " #width#:#182 * 2#," );
210+ ln (bw , " #height#:#20#" );
211+ ln (bw , " }," );
212+ ln (bw , " #texture#:{" );
213+ ln (bw , " #x#: #0#," );
214+ ln (bw , " #y#: #70 / 256.0#," );
215+ ln (bw , " #width#: #182 / 256.0#," );
216+ ln (bw , " #height#: #10 / 256.0#" );
217+ ln (bw , " }" );
218+ ln (bw , " }" );
219+ ln (bw , " }," );
220+ ln (bw , " {" );
221+ ln (bw , " #image#: {" );
222+ ln (bw , " #parent#: #builtin/image#," );
223+ ln (bw , " #image#: #customloadingscreen:textures/progress_bars.png#," );
224+ ln (bw , " #position_type#: #CENTER#," );
225+ ln (bw , " #offset_pos#: #CENTER#," );
226+ ln (bw , " #position#:{" );
227+ ln (bw , " #x#:#percentage * 182 - 182#," );
228+ ln (bw , " #y#:#20#," );
229+ ln (bw , " #width#:#percentage * 182 * 2#," );
230+ ln (bw , " #height#:#20#" );
231+ ln (bw , " }," );
232+ ln (bw , " #texture#:{" );
233+ ln (bw , " #x#:#0#," );
234+ ln (bw , " #y#:#80 / 256.0#," );
235+ ln (bw , " #width#: #percentage * 182 / 256.0#," );
236+ ln (bw , " #height#:#10 / 256.0#" );
237+ ln (bw , " }" );
238+ ln (bw , " }" );
239+ ln (bw , " }," );
240+ ln (bw , " {" );
241+ ln (bw , " #image#: {" );
242+ ln (bw , " #parent#: #builtin/text#," );
243+ ln (bw , " #image#: #textures/font/ascii.png#," );
244+ ln (bw , " #position_type#: #CENTER#," );
245+ ln (bw , " #offset_pos#: #CENTER#," );
246+ ln (bw , " #text#: #is_reloading ? status : (status + ': ' + sub_status)#," );
247+ ln (bw , " #position#: {" );
248+ ln (bw , " #x#: #0#," );
249+ ln (bw , " #y#: #-20#," );
250+ ln (bw , " #width#: #0#," );
251+ ln (bw , " #height#: #0#" );
252+ ln (bw , " }," );
253+ ln (bw , " #colour#:#0xFF_FF_FF_FF#" );
254+ ln (bw , " }" );
255+ ln (bw , " }," );
256+ ln (bw , " {" );
257+ ln (bw , " #image#: {" );
258+ ln (bw , " #parent#: #builtin/text#," );
259+ ln (bw , " #image#: #textures/font/ascii.png#," );
260+ ln (bw , " #position_type#: #CENTER#," );
261+ ln (bw , " #offset_pos#: #CENTER#," );
262+ ln (bw , " #text#: #is_reloading ? sub_status : ''#," );
263+ ln (bw , " #position#: {" );
264+ ln (bw , " #x#: #0#," );
265+ ln (bw , " #y#: #0#," );
266+ ln (bw , " #width#: #0#," );
267+ ln (bw , " #height#: #0#" );
268+ ln (bw , " }," );
269+ ln (bw , " #colour#:#0xFF_FF_FF_FF#" );
270+ ln (bw , " }" );
271+ ln (bw , " }," );
272+ ln (bw , " {" );
273+ ln (bw , " #image#: {" );
274+ ln (bw , " #parent#: #builtin/text#," );
275+ ln (bw , " #image#: #textures/font/ascii.png#," );
276+ ln (bw , " #position_type#: #CENTER#," );
277+ ln (bw , " #offset_pos#: #CENTER#," );
278+ ln (bw , " #text#: #(floor(percentage * 100)) + '%'#," );
279+ ln (bw , " #position#: {" );
280+ ln (bw , " #x#: #0#," );
281+ ln (bw , " #y#: #-10#," );
282+ ln (bw , " #width#: #0#," );
283+ ln (bw , " #height#: #0#" );
284+ ln (bw , " }," );
285+ ln (bw , " #colour#:#0xFF_FF_FF_FF#" );
286+ ln (bw , " }" );
287+ ln (bw , " }" );
288+ ln (bw , " ]," );
289+ ln (bw , " #functions#:[" );
290+ ln (bw , " ]," );
291+ ln (bw , " #factories#:[" );
292+ ln (bw , " ]," );
293+ ln (bw , " #actions#:[" );
294+ ln (bw , " ]," );
295+ ln (bw , " #variables#:{" );
296+ ln (bw , " }" );
297+ ln (bw , "}" );
298+ }
134299}
0 commit comments