2626 * Connected Texture Mod (CTM) handler
2727 */
2828public class CTMTexturePack {
29- private String [] ctpfiles ;
30- private TexturePackLoader tpl ;
29+ private final String [] ctpfiles ;
30+ private final TexturePackLoader tpl ;
3131 private CTMProps [][] bytilelist ;
3232 private CTMProps [][] bybaseblockstatelist ;
3333 private BitSet mappedtiles ;
3434 private BitSet mappedblocks ;
3535 private String [] biomenames ;
3636
37- private String vanillatextures ;
37+ private final String vanillatextures ;
3838
3939 static final int BOTTOM_FACE = 0 ; // 0, -1, 0
4040 static final int TOP_FACE = 1 ; // 0, 1, 0
@@ -146,7 +146,7 @@ public enum CTMMethod {
146146 public enum CTMConnect {
147147 NONE , BLOCK , TILE , MATERIAL , UNKNOWN
148148 }
149- public static final int FACE_BOTTOM = ( 1 << 0 ) ;
149+ public static final int FACE_BOTTOM = 1 ;
150150 public static final int FACE_TOP = (1 << 1 );
151151 public static final int FACE_NORTH = (1 << 2 );
152152 public static final int FACE_SOUTH = (1 << 3 );
@@ -196,46 +196,49 @@ public static class CTMProps {
196196 private String [] tokenize (String v , String split )
197197 {
198198 StringTokenizer tok = new StringTokenizer (v , split );
199- ArrayList <String > rslt = new ArrayList <String >();
199+ ArrayList <String > rslt = new ArrayList <>();
200200
201201 while (tok .hasMoreTokens ()) {
202202 rslt .add (tok .nextToken ());
203203 }
204- return rslt .toArray (new String [rslt . size () ]);
204+ return rslt .toArray (new String [0 ]);
205205 }
206206
207207 private void getFaces (Properties p ) {
208208 String v = p .getProperty ("faces" , "all" ).trim ().toLowerCase ();
209209 this .faces = 0 ;
210210 String [] tok = v .split ("\\ s+" );
211211 for (String t : tok ) {
212- if (t .equals ("bottom" )) {
213- this .faces |= FACE_BOTTOM ;
214- }
215- else if (t .equals ("top" )) {
216- this .faces |= FACE_TOP ;
217- }
218- else if (t .equals ("north" )) {
219- this .faces |= FACE_NORTH ;
220- }
221- else if (t .equals ("south" )) {
222- this .faces |= FACE_SOUTH ;
223- }
224- else if (t .equals ("east" )) {
225- this .faces |= FACE_EAST ;
226- }
227- else if (t .equals ("west" )) {
228- this .faces |= FACE_WEST ;
229- }
230- else if (t .equals ("sides" ) || t .equals ("side" )) {
231- this .faces |= FACE_SIDES ;
232- }
233- else if (t .equals ("all" )) {
234- this .faces |= FACE_ALL ;
235- }
236- else {
237- Log .info ("Unknown face in CTM file: " + t );
238- this .faces |= FACE_UNKNOWN ;
212+ switch (t ) {
213+ case "bottom" :
214+ this .faces |= FACE_BOTTOM ;
215+ break ;
216+ case "top" :
217+ this .faces |= FACE_TOP ;
218+ break ;
219+ case "north" :
220+ this .faces |= FACE_NORTH ;
221+ break ;
222+ case "south" :
223+ this .faces |= FACE_SOUTH ;
224+ break ;
225+ case "east" :
226+ this .faces |= FACE_EAST ;
227+ break ;
228+ case "west" :
229+ this .faces |= FACE_WEST ;
230+ break ;
231+ case "sides" :
232+ case "side" :
233+ this .faces |= FACE_SIDES ;
234+ break ;
235+ case "all" :
236+ this .faces |= FACE_ALL ;
237+ break ;
238+ default :
239+ Log .info ("Unknown face in CTM file: " + t );
240+ this .faces |= FACE_UNKNOWN ;
241+ break ;
239242 }
240243 }
241244 }
@@ -253,13 +256,13 @@ private int[] parseInts(Properties p, String fld) {
253256 String v = p .getProperty (fld );
254257 if (v == null ) return null ;
255258 String [] tok = tokenize (v , ", " );
256- ArrayList <Integer > rslt = new ArrayList <Integer >();
259+ ArrayList <Integer > rslt = new ArrayList <>();
257260 for (String t : tok ) {
258261 t = t .trim ();
259262 String [] vtok = tokenize (t , "-" );
260263 if (vtok .length == 1 ) { /* One value */
261264 try {
262- rslt .add (Integer .parseInt (vtok [0 ]));
265+ rslt .add (Integer .valueOf (vtok [0 ]));
263266 } catch (NumberFormatException nfx ) {
264267 Log .info ("Bad integer in list: " + vtok [0 ]);
265268 }
@@ -311,7 +314,7 @@ private void addBaseBlockStateToIDSet(Set<Integer> list, DynmapBlockState bs) {
311314 }
312315 }
313316 private int [] getIDList (Properties properties , String key , String type ) {
314- Set <Integer > list = new HashSet <Integer >();
317+ Set <Integer > list = new HashSet <>();
315318 String property = properties .getProperty (key , "" );
316319 for (String token : property .split ("\\ s+" )) {
317320 if (token .equals ("" )) {
@@ -387,65 +390,77 @@ else if (addbase) {
387390
388391 private void getMethod (Properties p ) {
389392 String v = p .getProperty ("method" , "default" ).trim ().toLowerCase ();
390- if (v .equals ("ctm" ) || v .equals ("glass" ) || v .equals ("default" )) {
391- method = CTMMethod .CTM ;
392- }
393- else if (v .equals ("horizontal" ) || v .equals ("bookshelf" )) {
394- method = CTMMethod .HORIZONTAL ;
395- }
396- else if (v .equals ("vertical" )) {
397- method = CTMMethod .VERTICAL ;
398- }
399- else if (v .equals ("vertical+horizontal" ) || v .equals ("v+h" )) {
400- method = CTMMethod .VERTICAL_HORIZONTAL ;
401- }
402- else if (v .equals ("horizontal+vertical" ) || v .equals ("h+v" )) {
403- method = CTMMethod .HORIZONTAL_VERTICAL ;
404- }
405- else if (v .equals ("top" ) || v .equals ("sandstone" )) {
406- method = CTMMethod .TOP ;
407- }
408- else if (v .equals ("random" )) {
409- method = CTMMethod .RANDOM ;
410- }
411- else if (v .equals ("repeat" ) || v .equals ("pattern" )) {
412- method = CTMMethod .REPEAT ;
413- }
414- else if (v .equals ("fixed" ) || v .equals ("static" )) {
415- method = CTMMethod .FIXED ;
416- }
417- else {
418- Log .info ("Invalid CTM Method: " + v );
419- method = CTMMethod .NONE ;
393+ switch (v ) {
394+ case "ctm" :
395+ case "glass" :
396+ case "default" :
397+ method = CTMMethod .CTM ;
398+ break ;
399+ case "horizontal" :
400+ case "bookshelf" :
401+ method = CTMMethod .HORIZONTAL ;
402+ break ;
403+ case "vertical" :
404+ method = CTMMethod .VERTICAL ;
405+ break ;
406+ case "vertical+horizontal" :
407+ case "v+h" :
408+ method = CTMMethod .VERTICAL_HORIZONTAL ;
409+ break ;
410+ case "horizontal+vertical" :
411+ case "h+v" :
412+ method = CTMMethod .HORIZONTAL_VERTICAL ;
413+ break ;
414+ case "top" :
415+ case "sandstone" :
416+ method = CTMMethod .TOP ;
417+ break ;
418+ case "random" :
419+ method = CTMMethod .RANDOM ;
420+ break ;
421+ case "repeat" :
422+ case "pattern" :
423+ method = CTMMethod .REPEAT ;
424+ break ;
425+ case "fixed" :
426+ case "static" :
427+ method = CTMMethod .FIXED ;
428+ break ;
429+ default :
430+ Log .info ("Invalid CTM Method: " + v );
431+ method = CTMMethod .NONE ;
432+ break ;
420433 }
421434 }
422435 private void getConnect (Properties p ) {
423436 String v = p .getProperty ("connect" , "none" ).toLowerCase ();
424- if (v .equals ("none" )) {
425- this .connect = CTMConnect .NONE ;
426- }
427- else if (v .equals ("block" )) {
428- this .connect = CTMConnect .BLOCK ;
429- }
430- else if (v .equals ("tile" )) {
431- this .connect = CTMConnect .TILE ;
432- }
433- else if (v .equals ("material" )) {
434- this .connect = CTMConnect .MATERIAL ;
435- }
436- else {
437- Log .info ("Invalid CTM Connect: " + v );
438- this .connect = CTMConnect .UNKNOWN ;
437+ switch (v ) {
438+ case "none" :
439+ this .connect = CTMConnect .NONE ;
440+ break ;
441+ case "block" :
442+ this .connect = CTMConnect .BLOCK ;
443+ break ;
444+ case "tile" :
445+ this .connect = CTMConnect .TILE ;
446+ break ;
447+ case "material" :
448+ this .connect = CTMConnect .MATERIAL ;
449+ break ;
450+ default :
451+ Log .info ("Invalid CTM Connect: " + v );
452+ this .connect = CTMConnect .UNKNOWN ;
453+ break ;
439454 }
440455 }
441456 private void getBiomes (Properties p , CTMTexturePack tp ) {
442457 String v = p .getProperty ("biomes" , "" ).trim ().toLowerCase ();
443458 if (!v .equals ("" )) {
444- ArrayList <Integer > ids = new ArrayList <Integer >();
459+ ArrayList <Integer > ids = new ArrayList <>();
445460 String [] biomenames = tp .biomenames ;
446461 for (String s : v .split ("\\ s+" )) {
447462 for (int i = 0 ; i < biomenames .length ; i ++) {
448- if (s . equals ( biomenames [i ])) {
463+ if (biomenames [i ]. equals ( s )) {
449464 ids .add (i );
450465 s = null ;
451466 break ;
@@ -466,18 +481,20 @@ private void getBiomes(Properties p, CTMTexturePack tp) {
466481 }
467482 private void getSymmetry (Properties p ) {
468483 String v = p .getProperty ("symmetry" , "none" ).trim ().toLowerCase ();
469- if (v .equals ("none" )) {
470- this .symmetry = CTMSymmetry .NONE ;
471- }
472- else if (v .equals ("opposite" )) {
473- this .symmetry = CTMSymmetry .OPPOSITE ;
474- }
475- else if (v .equals ("all" )) {
476- this .symmetry = CTMSymmetry .ALL ;
477- }
478- else {
479- Log .info ("invalid CTM symmetry: " + v );
480- this .symmetry = CTMSymmetry .NONE ;
484+ switch (v ) {
485+ case "none" :
486+ this .symmetry = CTMSymmetry .NONE ;
487+ break ;
488+ case "opposite" :
489+ this .symmetry = CTMSymmetry .OPPOSITE ;
490+ break ;
491+ case "all" :
492+ this .symmetry = CTMSymmetry .ALL ;
493+ break ;
494+ default :
495+ Log .info ("invalid CTM symmetry: " + v );
496+ this .symmetry = CTMSymmetry .NONE ;
497+ break ;
481498 }
482499 }
483500 private void getMatchTiles (Properties p ) {
@@ -509,7 +526,7 @@ private String[] parseTileNames(String v) {
509526 if (v .length () == 0 ) {
510527 return null ;
511528 }
512- ArrayList <String > lst = new ArrayList <String >();
529+ ArrayList <String > lst = new ArrayList <>();
513530 String [] tok = tokenize (v , " ," );
514531 for (String t : tok ) {
515532 if (t .indexOf ('-' ) >= 0 ) {
@@ -699,7 +716,7 @@ private boolean isValidCtm(String fname) {
699716 }
700717 return true ;
701718 }
702- public final boolean exclude (DynmapBlockState block , int face , Context ctx ) {
719+ private boolean exclude (DynmapBlockState block , int face , Context ctx ) {
703720 if ((faces & (1 << ctx .reorient (face ))) == 0 ) {
704721 return true ;
705722 } else if (this .metadata != -1 && block .stateIndex >= 0 && block .stateIndex < 32 ) {
@@ -901,7 +918,7 @@ final boolean shouldConnect(Context ctx, int[] offset) {
901918 * @param is_rp - if true, resource pack; if false, texture pack
902919 */
903920 public CTMTexturePack (TexturePackLoader tpl , TexturePack tp , DynmapCore core , boolean is_rp ) {
904- ArrayList <String > files = new ArrayList <String >();
921+ ArrayList <String > files = new ArrayList <>();
905922 this .tpl = tpl ;
906923 biomenames = core .getBiomeNames ();
907924 Set <String > ent = tpl .getEntries ();
@@ -921,9 +938,9 @@ public CTMTexturePack(TexturePackLoader tpl, TexturePack tp, DynmapCore core, bo
921938 files .add (name );
922939 }
923940 }
924- ctpfiles = files .toArray (new String [files . size () ]);
941+ ctpfiles = files .toArray (new String [0 ]);
925942 Arrays .sort (ctpfiles );
926- processFiles (core );
943+ processFiles ();
927944 }
928945 /**
929946 * Test if enabled properly
@@ -956,7 +973,7 @@ private CTMProps[][] addToList(CTMProps[][] list, BitSet set, int[] keys, CTMPro
956973 /**
957974 * Process property files
958975 */
959- private void processFiles (DynmapCore core ) {
976+ private void processFiles () {
960977 bytilelist = new CTMProps [256 ][];
961978 bybaseblockstatelist = new CTMProps [256 ][];
962979 mappedtiles = new BitSet ();
@@ -1116,7 +1133,7 @@ public int mapTexture(MapIterator mapiter, DynmapBlockState blk, BlockStep lasts
11161133 idx = (mapiter .getBlockKey () << 8 ) | laststep .ordinal ();
11171134 Integer val = (Integer ) cache .get (idx );
11181135 if (val != null ) {
1119- return val . intValue () ;
1136+ return val ;
11201137 }
11211138 }
11221139
@@ -1248,7 +1265,7 @@ private int mapTextureByProp(CTMProps p, Context ctx) {
12481265 return mapTextureVerticalHorizontal (p , ctx );
12491266
12501267 case FIXED :
1251- return mapTextureFixed (p , ctx );
1268+ return mapTextureFixed (p );
12521269
12531270 default :
12541271 return -1 ;
@@ -1523,7 +1540,7 @@ private int mapTextureVerticalHorizontal(CTMProps p, Context ctx) {
15231540 }
15241541
15251542 // Map texture using fixed method
1526- private int mapTextureFixed (CTMProps p , Context ctx ) {
1543+ private int mapTextureFixed (CTMProps p ) {
15271544 return p .tileIcons [0 ];
15281545 }
15291546
@@ -1534,7 +1551,7 @@ private int mapTextureFixed(CTMProps p, Context ctx) {
15341551 private static final long MULTIPLIER = 0x5deece66dL ;
15351552 private static final long ADDEND = 0xbL ;
15361553
1537- private static final int getRandom (int x , int y , int z , int face , int modulus )
1554+ private static int getRandom (int x , int y , int z , int face , int modulus )
15381555 {
15391556 long n = P1 * x * (x + ADDEND ) + P2 * y * (y + ADDEND ) + P3 * z * (z + ADDEND ) + P4 * face * (face + ADDEND );
15401557 n = MULTIPLIER * (n + x + y + z + face ) + ADDEND ;
0 commit comments