@@ -78,7 +78,7 @@ public Set<ChunkPos> getLoadedChunks() {
7878
7979 public void purge () {
8080 chunkCache .clear ();
81- for (ChunkPos chunk : loadedChunks )
81+ for (ChunkPos chunk : loadedChunks )
8282 sendEmptyChunk (chunk .chunkXPos , chunk .chunkZPos );
8383 loadedChunks .clear ();
8484 }
@@ -135,41 +135,53 @@ public void sendEmptyChunks(int radius) {
135135 public void update (Position position , BlockState block ) {
136136 ChunkPos columnPos = new ChunkPos (position .getX () >> 4 , position .getZ () >> 4 );
137137// System.out.println("translateBlock Position " + position.toString());
138- if (chunkCache .containsKey (columnPos )) {
139- Column column = chunkCache .get (columnPos );
140- BlockPosition blockPos = columnPos .getBlockInChunk (position .getX (), position .getY (), position .getZ ());
141- Chunk chunk = column .getChunks ()[position .getY () >> 4 ];
142- if (chunk != null )
143- chunk .getBlocks ().set (blockPos .x , blockPos .y , blockPos .z , block );
144- }
138+ if (chunkCache .containsKey (columnPos ))
139+ try {
140+ Column column = chunkCache .get (columnPos );
141+ BlockPosition blockPos = columnPos .getBlockInChunk (position .getX (), position .getY (), position .getZ ());
142+ Chunk chunk = column .getChunks ()[position .getY () >> 4 ];
143+ if (chunk != null )
144+ chunk .getBlocks ().set (blockPos .x , blockPos .y , blockPos .z , block );
145+ } catch (java .lang .ArrayIndexOutOfBoundsException ex ) {
146+ this .session .getProxy ().getLogger ().severe ("update(" + position .toString () + ", " + block .toString () + ")) fail to get chunk " + (position .getX () >> 4 ) + "/" + (position .getY () >> 4 ) + "/" + (position .getZ () >> 4 ));
147+ ex .printStackTrace ();
148+ }
145149 //enqueue block update
146150 }
147151
148152 public final ItemEntry translateBlock (Position position ) {
149153 ChunkPos columnPos = new ChunkPos (position .getX () >> 4 , position .getZ () >> 4 );
150- if (chunkCache .containsKey (columnPos )) {
151- Column column = chunkCache .get (columnPos );
152- BlockPosition blockPos = columnPos .getBlockInChunk (position .getX (), position .getY (), position .getZ ());
153- Chunk chunk = column .getChunks ()[position .getY () >> 4 ];
154- if (chunk != null ) {
155- BlockState block = chunk .getBlocks ().get (blockPos .x , blockPos .y , blockPos .z );
156- return ItemBlockTranslator .translateToPE (block .getId (), block .getData ());
154+ if (chunkCache .containsKey (columnPos ))
155+ try {
156+ Column column = chunkCache .get (columnPos );
157+ BlockPosition blockPos = columnPos .getBlockInChunk (position .getX (), position .getY (), position .getZ ());
158+ Chunk chunk = column .getChunks ()[position .getY () >> 4 ];
159+ if (chunk != null ) {
160+ BlockState block = chunk .getBlocks ().get (blockPos .x , blockPos .y , blockPos .z );
161+ return ItemBlockTranslator .translateToPE (block .getId (), block .getData ());
162+ }
163+ } catch (java .lang .ArrayIndexOutOfBoundsException ex ) {
164+ this .session .getProxy ().getLogger ().severe ("getBlock(" + position .toString () + ")) fail to get chunk " + (position .getX () >> 4 ) + "/" + (position .getY () >> 4 ) + "/" + (position .getZ () >> 4 ));
165+ ex .printStackTrace ();
157166 }
158- }
159167 return null ;
160168 }
161169
162170 public final ItemStack getBlock (Position position ) {
163171 ChunkPos columnPos = new ChunkPos (position .getX () >> 4 , position .getZ () >> 4 );
164- if (chunkCache .containsKey (columnPos )) {
165- Column column = chunkCache .get (columnPos );
166- BlockPosition blockPos = columnPos .getBlockInChunk (position .getX (), position .getY (), position .getZ ());
167- Chunk chunk = column .getChunks ()[position .getY () >> 4 ];
168- if (chunk != null ) {
169- BlockState block = chunk .getBlocks ().get (blockPos .x , blockPos .y , blockPos .z );
170- return new ItemStack (block .getId (), 1 , block .getData ());
172+ if (chunkCache .containsKey (columnPos ))
173+ try {
174+ Column column = chunkCache .get (columnPos );
175+ BlockPosition blockPos = columnPos .getBlockInChunk (position .getX (), position .getY (), position .getZ ());
176+ Chunk chunk = column .getChunks ()[position .getY () >> 4 ];
177+ if (chunk != null ) {
178+ BlockState block = chunk .getBlocks ().get (blockPos .x , blockPos .y , blockPos .z );
179+ return new ItemStack (block .getId (), 1 , block .getData ());
180+ }
181+ } catch (java .lang .ArrayIndexOutOfBoundsException ex ) {
182+ this .session .getProxy ().getLogger ().severe ("(getBlock(" + position .toString () + ")) fail to get chunk " + (position .getX () >> 4 ) + "/" + (position .getY () >> 4 ) + "/" + (position .getZ () >> 4 ));
183+ ex .printStackTrace ();
171184 }
172- }
173185 return null ;
174186 }
175187
@@ -323,7 +335,7 @@ public void getDebugGrid() {
323335 System .out .println ("Player Chunk : " + playerChunkPos .toString ());
324336 System .out .println ("Chunk in cache : " + chunkCache .size ());
325337 System .out .println ("Chunk loaded : " + loadedChunks .size ());
326- System .out .println ("Chunk grid : " + width + " * " + height + " = " + (width * height ));
338+ System .out .println ("Chunk grid : " + width + " * " + height + " = " + (width * height ));
327339 System .out .println ("Chunk X : " + minX + " to " + maxX );
328340 System .out .println ("Chunk Z : " + minZ + " to " + maxZ );
329341
0 commit comments