4141 */
4242public class HDBlockModels {
4343 private static int max_patches ;
44- static HashMap < Integer , HDBlockModel > models_by_id_data = new HashMap < Integer , HDBlockModel >() ;
44+ static HDBlockModel [] models_by_id_data = new HDBlockModel [ 0 ] ;
4545 static PatchDefinitionFactory pdf = new PatchDefinitionFactory ();
4646 static BitSet customModelsRequestingTileData = new BitSet (); // Index by globalStateIndex
4747 static BitSet changeIgnoredBlocks = new BitSet (); // Index by globalStateIndex
@@ -53,17 +53,19 @@ public class HDBlockModels {
5353
5454 /* Reset model if defined by different block set */
5555 public static boolean resetIfNotBlockSet (DynmapBlockState blk , String blockset ) {
56- HDBlockModel bm = models_by_id_data .get (blk .globalStateIndex );
56+ int idx = blk .globalStateIndex ;
57+ HDBlockModel bm = (idx < models_by_id_data .length ) ? models_by_id_data [idx ] : null ;
5758 if ((bm != null ) && (bm .getBlockSet ().equals (blockset ) == false )) {
5859 Debug .debug ("Reset block model for " + blk + " from " + bm .getBlockSet () + " due to new def from " + blockset );
59- models_by_id_data . remove ( blk . globalStateIndex ) ;
60+ models_by_id_data [ idx ] = null ;
6061 return true ;
6162 }
6263 return false ;
6364 }
6465 /* Get texture count needed for model */
6566 public static int getNeededTextureCount (DynmapBlockState blk ) {
66- HDBlockModel bm = models_by_id_data .get (blk .globalStateIndex );
67+ int idx = blk .globalStateIndex ;
68+ HDBlockModel bm = (idx < models_by_id_data .length ) ? models_by_id_data [idx ] : null ;
6769 if (bm != null ) {
6870 return bm .getTextureCount ();
6971 }
@@ -88,18 +90,12 @@ public static void handleBlockAlias() {
8890
8991 private static void remapModel (String bn , String newbn ) {
9092 DynmapBlockState frombs = DynmapBlockState .getBaseStateByName (bn );
91- DynmapBlockState tobs = DynmapBlockState .getBaseStateByName (bn );
93+ DynmapBlockState tobs = DynmapBlockState .getBaseStateByName (newbn );
9294 int fcnt = frombs .getStateCount ();
9395 for (int bs = 0 ; bs < tobs .getStateCount (); bs ++) {
9496 DynmapBlockState tb = tobs .getState (bs );
95- DynmapBlockState fs = tobs .getState (bs % fcnt );
96- HDBlockModel m = models_by_id_data .get (fs .globalStateIndex );
97- if (m != null ) {
98- models_by_id_data .put (tb .globalStateIndex , m );
99- }
100- else {
101- models_by_id_data .remove (tb .globalStateIndex );
102- }
97+ DynmapBlockState fs = frombs .getState (bs % fcnt );
98+ models_by_id_data [tb .globalStateIndex ] = models_by_id_data [fs .globalStateIndex ];
10399 customModelsRequestingTileData .set (tb .globalStateIndex , customModelsRequestingTileData .get (fs .globalStateIndex ));
104100 changeIgnoredBlocks .set (tb .globalStateIndex , changeIgnoredBlocks .get (fs .globalStateIndex ));
105101 }
@@ -113,7 +109,7 @@ private static void remapModel(String bn, String newbn) {
113109 public static final String [] getTileEntityFieldsNeeded (DynmapBlockState blk ) {
114110 int idx = blk .globalStateIndex ;
115111 if (customModelsRequestingTileData .get (idx )) {
116- HDBlockModel mod = models_by_id_data . get (idx ) ;
112+ HDBlockModel mod = (idx < models_by_id_data . length ) ? models_by_id_data [ idx ] : null ;
117113 if (mod instanceof CustomBlockModel ) {
118114 return ((CustomBlockModel )mod ).render .getTileEntityFieldsNeeded ();
119115 }
@@ -166,7 +162,7 @@ public static void loadModels(DynmapCore core, ConfigurationNode config) {
166162 File datadir = core .getDataFolder ();
167163 max_patches = 6 ; /* Reset to default */
168164 /* Reset models-by-ID-Data cache */
169- models_by_id_data . clear () ;
165+ models_by_id_data = new HDBlockModel [ DynmapBlockState . getGlobalIndexMax ()] ;
170166 /* Reset scaled models by scale cache */
171167 scaled_models_by_scale .clear ();
172168 /* Reset change-ignored flags */
@@ -455,7 +451,7 @@ else if (typeid.equals("rotate")) {
455451 Log .severe ("Invalid rotate ID: " + bs + " on line " + lineNum + " of file: " + fname );
456452 continue ;
457453 }
458- HDBlockModel mod = models_by_id_data . get ( bs .globalStateIndex ) ;
454+ HDBlockModel mod = models_by_id_data [ bs .globalStateIndex ] ;
459455 if (modlist .isEmpty ()) {
460456 }
461457 else if ((mod != null ) && ((rot %90 ) == 0 ) && (mod instanceof HDBlockVolumetricModel )) {
@@ -524,7 +520,7 @@ else if (typeid.equals("patchrotate")) {
524520 Log .severe ("Invalid patchrotate ID: " + bs + " on line " + lineNum + "of file: " + fname );
525521 continue ;
526522 }
527- HDBlockModel mod = models_by_id_data . get ( bs .globalStateIndex ) ;
523+ HDBlockModel mod = models_by_id_data [ bs .globalStateIndex ] ;
528524 if (pmodlist .isEmpty ()) {
529525 }
530526 else if ((mod != null ) && (mod instanceof HDBlockPatchModel )) {
0 commit comments