@@ -158,8 +158,8 @@ public static void init() {
158158
159159 }
160160
161- public SurroundingTemperatureSimulator (ServerPlayer player ) {
162- int sourceX = Mth .floor (player . getX ()) , sourceY = Mth .floor (player . getEyeY ()) , sourceZ = Mth .floor (player . getZ () );
161+ public SurroundingTemperatureSimulator (ServerLevel world , double sx , double sy , double sz , boolean threadSafe ) {
162+ int sourceX = Mth .floor (sx ) , sourceY = Mth .floor (sy ) , sourceZ = Mth .floor (sz );
163163 // these are block position offset
164164 int offsetN = sourceZ - range ;
165165 int offsetW = sourceX - range ;
@@ -168,12 +168,10 @@ public SurroundingTemperatureSimulator(ServerPlayer player) {
168168 int chunkOffsetW = offsetW >> 4 ;
169169 int chunkOffsetN = offsetN >> 4 ;
170170 int chunkOffsetD = offsetD >> 4 ;
171-
172171 // get origin point(center of 8 sections)
173172 origin = new BlockPos ((chunkOffsetW + 1 ) << 4 , (chunkOffsetD + 1 ) << 4 , (chunkOffsetN + 1 ) << 4 );
174173 // fetch all sections to lower calculation cost
175174 int i = 0 ;
176- ServerLevel world = player .serverLevel ();
177175
178176 for (int x = chunkOffsetW ; x <= chunkOffsetW + 1 ; x ++)
179177 for (int z = chunkOffsetN ; z <= chunkOffsetN + 1 ; z ++) {
@@ -182,16 +180,23 @@ public SurroundingTemperatureSimulator(ServerPlayer player) {
182180 int index0 =cnk .getSectionIndexFromSectionY (chunkOffsetD );
183181 int index1 =index0 +1 ;
184182 maps [i / 2 ] = cnk .getOrCreateHeightmapUnprimed (Types .MOTION_BLOCKING_NO_LEAVES );
185- //copy to avoid threading issue
183+
186184 if (index0 >=0 &&index0 <maxIndex )
187- sections [i ] = cnk .getSection (index0 ).getStates (). copy () ;
185+ sections [i ] = cnk .getSection (index0 ).getStates ();
188186 //System.out.println(sections[i].get(0, 0, 0));
189187 if (index1 >=0 &&index1 <maxIndex )
190- sections [i + 1 ] = cnk .getSection (index1 ).getStates (). copy () ;
188+ sections [i + 1 ] = cnk .getSection (index1 ).getStates ();
191189 //System.out.println(sections[i+1].get(0, 0, 0));
192190 i += 2 ;
193191 }
194- rnd = new Random (player .blockPosition ().asLong () ^ (world .getGameTime () >> 6 ));
192+ //copy to avoid threading issue
193+ if (threadSafe ) {
194+ for (int j =0 ;j <sections .length ;j ++)
195+ if (sections [j ]!=null )
196+ sections [j ]=sections [j ].copy ();
197+
198+ }
199+ rnd = new Random (new BlockPos (sourceX ,sourceY ,sourceZ ).asLong () ^ (world .getGameTime () >> 6 ));
195200 }
196201
197202 /**
0 commit comments