@@ -156,176 +156,21 @@ IEnumerator IEnumerable.GetEnumerator()
156156
157157
158158 #region Standard Patterns
159- // lazily initialized to reduce overhead
160-
161- [ NotNull ]
162- public static BlockPalette Light
163- {
164- get
165- {
166- if ( lightPalette == null )
167- {
168- lightPalette = DefineLight ( ) ;
169- }
170- return lightPalette ;
171- }
172- }
173- static BlockPalette lightPalette ;
174-
175- [ NotNull ]
176- public static BlockPalette Light2 {
177- get {
178- if ( lightPalette2 == null ) {
179- lightPalette2 = DefineLight2 ( ) ;
180- }
181- return lightPalette2 ;
182- }
183- }
184- static BlockPalette lightPalette2 ;
185-
186- [ NotNull ]
187- public static BlockPalette Dark
188- {
189- get
190- {
191- if ( darkPalette == null )
192- {
193- darkPalette = DefineDark ( ) ;
194- }
195- return darkPalette ;
196- }
197- }
198- static BlockPalette darkPalette ;
199-
200- [ NotNull ]
201- public static BlockPalette Dark2 {
202- get {
203- if ( darkPalette2 == null ) {
204- darkPalette2 = DefineDark2 ( ) ;
205- }
206- return darkPalette2 ;
207- }
208- }
209- static BlockPalette darkPalette2 ;
210-
211-
212- [ NotNull ]
213- public static BlockPalette Layered
214- {
215- get
216- {
217- if ( layeredPalette == null )
218- {
219- layeredPalette = DefineLayered ( ) ;
220- }
221- return layeredPalette ;
222- }
223- }
224- static BlockPalette layeredPalette ;
225-
226- [ NotNull ]
227- public static BlockPalette Layered2 {
228- get {
229- if ( layeredPalette2 == null ) {
230- layeredPalette2 = DefineLayered2 ( ) ;
231- }
232- return layeredPalette2 ;
233- }
234- }
235- static BlockPalette layeredPalette2 ;
236-
237- [ NotNull ]
238- public static BlockPalette Gray
239- {
240- get
241- {
242- if ( grayPalette == null )
243- {
244- grayPalette = DefineGray ( ) ;
245- }
246- return grayPalette ;
247- }
248- }
249- static BlockPalette grayPalette ;
250-
251-
252- [ NotNull ]
253- public static BlockPalette DarkGray
254- {
255- get
256- {
257- if ( darkGrayPalette == null )
258- {
259- darkGrayPalette = DefineDarkGray ( ) ;
260- }
261- return darkGrayPalette ;
262- }
263- }
264- static BlockPalette darkGrayPalette ;
265-
266-
267- [ NotNull ]
268- public static BlockPalette LayeredGray
269- {
270- get
271- {
272- if ( layeredGrayPalette == null )
273- {
274- layeredGrayPalette = DefineLayeredGray ( ) ;
275- }
276- return layeredGrayPalette ;
277- }
278- }
279- static BlockPalette layeredGrayPalette ;
280-
281-
282- [ NotNull ]
283- public static BlockPalette BW
284- {
285- get
286- {
287- if ( bwPalette == null )
288- {
289- bwPalette = DefineBW ( ) ;
290- }
291- return bwPalette ;
292- }
293- }
294- static BlockPalette bwPalette ;
295-
296-
297- [ NotNull ]
298- public static BlockPalette GetPalette ( StandardBlockPalette palette )
299- {
300- switch ( palette )
301- {
302- case StandardBlockPalette . Light :
303- return Light ;
304- case StandardBlockPalette . Light2 :
305- return Light2 ;
306- case StandardBlockPalette . Dark :
307- return Dark ;
308- case StandardBlockPalette . Dark2 :
309- return Dark2 ;
310- case StandardBlockPalette . Layered :
311- return Layered ;
312- case StandardBlockPalette . Layered2 :
313- return Layered2 ;
314- case StandardBlockPalette . Gray :
315- return Gray ;
316- case StandardBlockPalette . DarkGray :
317- return DarkGray ;
318- case StandardBlockPalette . LayeredGray :
319- return LayeredGray ;
320- case StandardBlockPalette . BW :
321- return BW ;
322- default :
323- throw new ArgumentOutOfRangeException ( "palette" ) ;
159+
160+ public static List < BlockPalette > Palettes = new List < BlockPalette > ( ) {
161+ DefineLight ( ) , DefineLight2 ( ) , DefineDark ( ) , DefineDark2 ( ) ,
162+ DefineBW ( ) , DefineGray ( ) , DefineDarkGray ( ) ,
163+ DefineLayered ( ) , DefineLayered2 ( ) , DefineLayeredGray ( ) ,
164+ } ;
165+
166+ public static BlockPalette FindPalette ( string name ) {
167+ foreach ( BlockPalette palette in Palettes ) {
168+ if ( palette . Name . CaselessEquals ( name ) ) return palette ;
324169 }
170+ return null ;
325171 }
326172
327-
328- [ NotNull ]
173+ // 1-layer standard blocks, lit
329174 static BlockPalette DefineLight ( )
330175 {
331176 return new BlockPalette ( "Light" , 1 ) {
@@ -352,7 +197,7 @@ static BlockPalette DefineLight()
352197 } ;
353198 }
354199
355- [ NotNull ]
200+ // 1-layer standard+CPE blocks, lit
356201 static BlockPalette DefineLight2 ( ) {
357202 return new BlockPalette ( "Light2" , 1 ) {
358203 { RgbColor . FromArgb ( 124 , 124 , 124 ) , Block . Stone } , //
@@ -395,7 +240,7 @@ static BlockPalette DefineLight2() {
395240 }
396241
397242
398- [ NotNull ]
243+ // 1-layer standard blocks, shadowed
399244 static BlockPalette DefineDark ( )
400245 {
401246 return new BlockPalette ( "Dark" , 1 ) {
@@ -422,7 +267,7 @@ static BlockPalette DefineDark()
422267 } ;
423268 }
424269
425- [ NotNull ]
270+ // 1-layer standard+CPE blocks, shadowed
426271 static BlockPalette DefineDark2 ( ) {
427272 return new BlockPalette ( "Dark2" , 1 ) {
428273 { RgbColor . FromArgb ( 74 , 74 , 74 ) , Block . Stone } , //
@@ -465,34 +310,34 @@ static BlockPalette DefineDark2() {
465310 }
466311
467312
468- [ NotNull ]
313+ // 2-layer standard blocks
469314 static BlockPalette DefineLayered ( )
470315 {
471316 BlockPalette palette = new BlockPalette ( "Layered" , 2 ) ;
472- foreach ( var pair in Light . palette )
473- {
317+ foreach ( var pair in DefineLight ( ) . palette ) {
474318 palette . Add ( pair . Key , new [ ] { Block . None , pair . Value [ 0 ] } ) ;
475319 }
476- foreach ( var pair in Dark . palette )
477- {
320+ foreach ( var pair in DefineDark ( ) . palette ) {
478321 palette . Add ( pair . Key , new [ ] { pair . Value [ 0 ] , Block . Air } ) ;
479322 }
323+
480324 palette . Add ( RgbColor . FromArgb ( 61 , 74 , 167 ) , new [ ] { Block . White , Block . StillWater } ) ;
481325 palette . Add ( RgbColor . FromArgb ( 47 , 59 , 152 ) , new [ ] { Block . Gray , Block . StillWater } ) ;
482326 palette . Add ( RgbColor . FromArgb ( 34 , 47 , 140 ) , new [ ] { Block . Black , Block . StillWater } ) ;
483327 palette . Add ( RgbColor . FromArgb ( 22 , 38 , 131 ) , new [ ] { Block . Obsidian , Block . StillWater } ) ;
484328 return palette ;
485329 }
486330
487- [ NotNull ]
331+ // 2-layer standard+CPE blocks
488332 static BlockPalette DefineLayered2 ( ) {
489333 BlockPalette palette = new BlockPalette ( "Layered2" , 2 ) ;
490- foreach ( var pair in Light2 . palette ) {
334+ foreach ( var pair in DefineLight2 ( ) . palette ) {
491335 palette . Add ( pair . Key , new [ ] { Block . None , pair . Value [ 0 ] } ) ;
492336 }
493- foreach ( var pair in Dark2 . palette ) {
337+ foreach ( var pair in DefineDark2 ( ) . palette ) {
494338 palette . Add ( pair . Key , new [ ] { pair . Value [ 0 ] , Block . Air } ) ;
495339 }
340+
496341 palette . Add ( RgbColor . FromArgb ( 61 , 74 , 167 ) , new [ ] { Block . White , Block . StillWater } ) ;
497342 palette . Add ( RgbColor . FromArgb ( 47 , 59 , 152 ) , new [ ] { Block . Gray , Block . StillWater } ) ;
498343 palette . Add ( RgbColor . FromArgb ( 34 , 47 , 140 ) , new [ ] { Block . Black , Block . StillWater } ) ;
@@ -501,52 +346,50 @@ static BlockPalette DefineLayered2() {
501346 }
502347
503348
504- [ NotNull ]
349+ // 1-layer gray blocks, lit
505350 static BlockPalette DefineGray ( )
506351 {
507352 return new BlockPalette ( "Gray" , 1 ) {
508- { RgbColor . FromArgb ( 64 , 64 , 64 ) , new [ ] { Block . Black } } ,
509- { RgbColor . FromArgb ( 118 , 118 , 118 ) , new [ ] { Block . Gray } } ,
510- { RgbColor . FromArgb ( 179 , 179 , 179 ) , new [ ] { Block . White } } ,
511- { RgbColor . FromArgb ( 21 , 19 , 29 ) , new [ ] { Block . Obsidian } }
353+ { RgbColor . FromArgb ( 64 , 64 , 64 ) , Block . Black } ,
354+ { RgbColor . FromArgb ( 118 , 118 , 118 ) , Block . Gray } ,
355+ { RgbColor . FromArgb ( 179 , 179 , 179 ) , Block . White } ,
356+ { RgbColor . FromArgb ( 21 , 19 , 29 ) , Block . Obsidian }
512357 } ;
513358 }
514359
515360
516- [ NotNull ]
361+ // 2-layer gray blocks, shadowed
517362 static BlockPalette DefineDarkGray ( )
518363 {
519364 return new BlockPalette ( "DarkGray" , 1 ) {
520- { RgbColor . FromArgb ( 41 , 41 , 41 ) , new [ ] { Block . Black } } ,
521- { RgbColor . FromArgb ( 72 , 72 , 72 ) , new [ ] { Block . Gray } } ,
522- { RgbColor . FromArgb ( 109 , 109 , 109 ) , new [ ] { Block . White } } ,
523- { RgbColor . FromArgb ( 15 , 14 , 20 ) , new [ ] { Block . Obsidian } }
365+ { RgbColor . FromArgb ( 41 , 41 , 41 ) , Block . Black } ,
366+ { RgbColor . FromArgb ( 72 , 72 , 72 ) , Block . Gray } ,
367+ { RgbColor . FromArgb ( 109 , 109 , 109 ) , Block . White } ,
368+ { RgbColor . FromArgb ( 15 , 14 , 20 ) , Block . Obsidian }
524369 } ;
525370 }
526371
527372
528- [ NotNull ]
373+ // 2-layer gray blocks
529374 static BlockPalette DefineLayeredGray ( )
530375 {
531376 BlockPalette palette = new BlockPalette ( "LayeredGray" , 2 ) ;
532- foreach ( var pair in Gray . palette )
533- {
377+ foreach ( var pair in DefineGray ( ) . palette ) {
534378 palette . Add ( pair . Key , new [ ] { Block . None , pair . Value [ 0 ] } ) ;
535379 }
536- foreach ( var pair in DarkGray . palette )
537- {
380+ foreach ( var pair in DefineDarkGray ( ) . palette ) {
538381 palette . Add ( pair . Key , new [ ] { pair . Value [ 0 ] , Block . Air } ) ;
539382 }
540383 return palette ;
541384 }
542385
543386
544- [ NotNull ]
387+ // "black" (obsidian) and white blocks only
545388 static BlockPalette DefineBW ( )
546389 {
547390 return new BlockPalette ( "BW" , 1 ) {
548- { RgbColor . FromArgb ( 179 , 179 , 179 ) , new [ ] { Block . White } } ,
549- { RgbColor . FromArgb ( 21 , 19 , 29 ) , new [ ] { Block . Obsidian } }
391+ { RgbColor . FromArgb ( 179 , 179 , 179 ) , Block . White } ,
392+ { RgbColor . FromArgb ( 21 , 19 , 29 ) , Block . Obsidian }
550393 } ;
551394 }
552395
@@ -557,19 +400,4 @@ protected struct LabColor
557400 public double L , a , b ;
558401 }
559402 }
560-
561-
562- public enum StandardBlockPalette
563- {
564- Light , // 1-layer standard blocks, lit
565- Light2 , // 1-layer standard+CPE blocks, lit
566- Dark , // 1-layer standard blocks, shadowed
567- Dark2 , // 1-layer standard+CPE blocks, shadowed
568- Layered , // 2-layer standard blocks
569- Layered2 , // 2-layer standard+CPE blocks
570- Gray , // 1-layer gray blocks, lit
571- DarkGray , // 2-layer gray blocks, shadowed
572- LayeredGray , // 2-layer gray blocks
573- BW // "black" (obsidian) and white blocks only
574- }
575403}
0 commit comments