5454import net .minecraft .world .level .LevelAccessor ;
5555import net .minecraft .world .level .biome .Biome ;
5656import net .minecraft .world .level .block .Block ;
57- import net .minecraft .world .level .block .LeavesBlock ;
5857import net .minecraft .world .level .block .LiquidBlock ;
59- import net .minecraft .world .level .block .SoundType ;
6058import net .minecraft .world .level .block .state .BlockState ;
6159import net .minecraft .world .level .chunk .ChunkAccess ;
6260import net .minecraft .world .level .chunk .LevelChunk ;
125123import it .unimi .dsi .fastutil .longs .LongOpenHashSet ;
126124import net .minecraftforge .eventbus .api .EventPriority ;
127125import net .minecraftforge .eventbus .api .SubscribeEvent ;
128-
129126import net .minecraft .world .level .EmptyBlockGetter ;
130127
131128public class DynmapPlugin
@@ -1730,7 +1727,35 @@ public void run() {
17301727 }
17311728 }
17321729
1733- @ SubscribeEvent (priority =EventPriority .LOWEST )
1730+ private void touchChunk (ForgeWorld fw , ChunkAccess c , String cause ) {
1731+ int ymax = Integer .MIN_VALUE ;
1732+ int ymin = Integer .MAX_VALUE ;
1733+ LevelChunkSection [] sections = c .getSections ();
1734+ // If no sections, assume all
1735+ if (sections .length == 0 ) {
1736+ ymax = (c .getMaxSection ()+1 ) << 4 ;
1737+ ymin = c .getMinSection () << 4 ;
1738+ }
1739+ else {
1740+ for (int i = 0 ; i < sections .length ; i ++) {
1741+ if ((sections [i ] != null ) && (sections [i ].hasOnlyAir () == false )) {
1742+ int sy = c .getSectionYFromSectionIndex (i ) << 4 ;
1743+ if (sy < ymin ) ymin = sy ;
1744+ if ((sy +16 ) > ymax ) ymax = sy + 16 ;
1745+ }
1746+ }
1747+ }
1748+ ChunkPos cp = c .getPos ();
1749+ int x = cp .x << 4 ;
1750+ int z = cp .z << 4 ;
1751+ Log .info (String .format ("ymin=%d, ymax=%d" , ymin , ymax ));
1752+ // If not empty AND not initial scan
1753+ if (ymax != Integer .MIN_VALUE ) {
1754+ mapManager .touchVolume (fw .getName (), x , ymin , z , x +15 , ymax , z +15 , "chunkgenerate" );
1755+ }
1756+ }
1757+
1758+ @ SubscribeEvent (priority =EventPriority .MONITOR )
17341759 public void handleChunkLoad (ChunkEvent .Load event ) {
17351760 if (!onchunkgenerate ) return ;
17361761
@@ -1744,7 +1769,7 @@ public void handleChunkLoad(ChunkEvent.Load event) {
17441769 }
17451770 }
17461771 }
1747- @ SubscribeEvent (priority =EventPriority .LOWEST )
1772+ @ SubscribeEvent (priority =EventPriority .MONITOR )
17481773 public void handleChunkUnload (ChunkEvent .Unload event ) {
17491774 if (!onchunkgenerate ) return ;
17501775
@@ -1756,29 +1781,13 @@ public void handleChunkUnload(ChunkEvent.Unload event) {
17561781 ChunkPos cp = c .getPos ();
17571782 if (fw != null ) {
17581783 if (!checkIfKnownChunk (fw , cp )) {
1759- int ymax = Integer .MIN_VALUE ;
1760- int ymin = Integer .MAX_VALUE ;
1761- LevelChunkSection [] sections = c .getSections ();
1762- for (int i = 0 ; i < sections .length ; i ++) {
1763- if ((sections [i ] != null ) && (sections [i ].hasOnlyAir () == false )) {
1764- int sy = c .getSectionYFromSectionIndex (i );
1765- if (sy < ymin ) ymin = sy ;
1766- if ((sy +16 ) > ymax ) ymax = sy + 16 ;
1767- }
1768- }
1769- int x = cp .x << 4 ;
1770- int z = cp .z << 4 ;
1771- // If not empty AND not initial scan
1772- if (ymax != Integer .MIN_VALUE ) {
1773- //Log.info(String.format("chunkkeyerate(unload)(%s,%d,%d,%d,%d,%d,%s)", fw.getName(), x, ymin, z, x+15, ymax, z+15));
1774- mapManager .touchVolume (fw .getName (), x , ymin , z , x +15 , ymax , z +15 , "chunkgenerate" );
1775- }
1784+ touchChunk (fw , c , "unload" );
17761785 }
17771786 removeKnownChunk (fw , cp );
17781787 }
17791788 }
17801789 }
1781- @ SubscribeEvent (priority =EventPriority .LOWEST )
1790+ @ SubscribeEvent (priority =EventPriority .MONITOR )
17821791 public void handleChunkDataSave (ChunkDataEvent .Save event ) {
17831792 if (!onchunkgenerate ) return ;
17841793
@@ -1789,33 +1798,16 @@ public void handleChunkDataSave(ChunkDataEvent.Save event) {
17891798 ForgeWorld fw = getWorld ((ServerLevel )w , false );
17901799 ChunkPos cp = c .getPos ();
17911800 if (fw != null ) {
1792- if (!checkIfKnownChunk (fw , cp )) {
1793- int ymax = Integer .MIN_VALUE ;
1794- int ymin = Integer .MAX_VALUE ;
1795- LevelChunkSection [] sections = c .getSections ();
1796- for (int i = 0 ; i < sections .length ; i ++) {
1797- if ((sections [i ] != null ) && (sections [i ].hasOnlyAir () == false )) {
1798- int sy = c .getSectionYFromSectionIndex (i );
1799- if (sy < ymin ) ymin = sy ;
1800- if ((sy +16 ) > ymax ) ymax = sy + 16 ;
1801- }
1802- }
1803- int x = cp .x << 4 ;
1804- int z = cp .z << 4 ;
1805- // If not empty AND not initial scan
1806- if (ymax != Integer .MIN_VALUE ) {
1807- //Log.info(String.format("chunkkeyerate(save)(%s,%d,%d,%d,%d,%d,%s)", fw.getName(), x, ymin, z, x+15, ymax, z+15));
1808- mapManager .touchVolume (fw .getName (), x , ymin , z , x +15 , ymax , z +15 , "chunkgenerate" );
1809- }
1810- // If cooked, add to known
1811- if ((c .getStatus () == ChunkStatus .FULL ) && (c instanceof LevelChunk )) {
1812- addKnownChunk (fw , cp );
1813- }
1801+ touchChunk (fw , c , "datasave" );
1802+ // If cooked, add to known
1803+ if (c .getStatus () == ChunkStatus .FULL ) {
1804+ addKnownChunk (fw , cp );
18141805 }
18151806 }
18161807 }
18171808 }
1818- @ SubscribeEvent (priority =EventPriority .LOWEST )
1809+
1810+ @ SubscribeEvent (priority =EventPriority .MONITOR , receiveCanceled =false )
18191811 public void handleBlockEvent (BlockEvent event ) {
18201812 if (!core_enabled ) return ;
18211813 if (!onblockchange ) return ;
0 commit comments