33import net .minecraft .core .HolderLookup ;
44import net .minecraft .nbt .CompoundTag ;
55import net .minecraft .server .MinecraftServer ;
6+ import net .minecraft .server .level .ServerChunkCache ;
67import net .minecraft .server .level .ServerLevel ;
78import net .minecraft .server .level .ServerPlayer ;
89import net .minecraft .world .entity .player .Player ;
10+ import net .minecraft .world .level .ChunkPos ;
911import net .minecraft .world .level .saveddata .SavedData ;
1012import net .minecraft .world .level .storage .DimensionDataStorage ;
1113import net .minecraft .world .level .storage .LevelResource ;
1214import noobanidus .mods .lootr .common .api .LootrAPI ;
13- import noobanidus .mods .lootr .common .api .data .AdvancementData ;
14- import noobanidus .mods .lootr .common .api .data .ILootrInfoProvider ;
15- import noobanidus .mods .lootr .common .api .data .LootFiller ;
16- import noobanidus .mods .lootr .common .api .data .TickingData ;
15+ import noobanidus .mods .lootr .common .api .data .*;
1716import noobanidus .mods .lootr .common .api .data .inventory .ILootrInventory ;
17+ import noobanidus .mods .lootr .common .chunk .LoadedChunks ;
1818import noobanidus .mods .lootr .common .mixins .AccessorMixinDimensionDataStorage ;
1919import org .jetbrains .annotations .ApiStatus ;
2020import org .jetbrains .annotations .Nullable ;
@@ -230,7 +230,7 @@ public static boolean clearInventories(UUID id) {
230230 paths .forEach (path -> {
231231 if (Files .isRegularFile (path )) {
232232 String fileName = path .getFileName ().toString ();
233- if (fileName .startsWith ("Lootr -" )) {
233+ if (fileName .startsWith ("lootr -" )) {
234234 return ;
235235 }
236236 files .add ("lootr/" + fileName .charAt (0 ) + "/" + fileName .substring (0 , 2 ) + "/" + fileName .replace (".dat" , "" ));
@@ -240,30 +240,50 @@ public static boolean clearInventories(UUID id) {
240240 return false ;
241241 }
242242
243+ for (String cache : ((AccessorMixinDimensionDataStorage ) data ).getCache ().keySet ()) {
244+ if (cache .startsWith ("lootr" ) && !files .contains (cache )) {
245+ files .add (cache );
246+ }
247+ }
248+
243249 int count = 0 ;
244250
245251 for (String file : files ) {
246252 SavedData datum = data .get (new SavedData .Factory <>(() -> LootrDummyData .INSTANCE , LootrSavedData ::load , null ), file );
247253 if (datum == LootrDummyData .INSTANCE ) {
248254 // Failed to load so clear it from the cache
249- LootrAPI .LOG .error ("Failed to load data for " + file + " , removing from cache." );
255+ LootrAPI .LOG .error ("Failed to load data for {} , removing from cache." , file );
250256 ((AccessorMixinDimensionDataStorage ) data ).getCache ().remove (file );
251257 continue ;
252258 }
253259 if (!(datum instanceof LootrSavedData lootrSavedData )) {
254- LootrAPI .LOG .error ("Data for " + file + " is not a LootrSavedData instance." );
260+ LootrAPI .LOG .error ("Data for {} is not a LootrSavedData instance." , file );
255261 ((AccessorMixinDimensionDataStorage ) data ).getCache ().remove (file );
256262 continue ;
257263 }
264+ if (!lootrSavedData .hasBeenOpened ()) {
265+ continue ;
266+ }
258267
259268 if (lootrSavedData .clearInventories (id )) {
260269 count ++;
270+ if (!lootrSavedData .getInfoBlockType ().equals (LootrBlockType .ENTITY )) {
271+ ServerLevel level = server .getLevel (lootrSavedData .getInfoDimension ());
272+ if (level != null ) {
273+ ServerChunkCache chunkCache = level .getChunkSource ();
274+ ChunkPos chunkPos = new ChunkPos (lootrSavedData .getInfoPos ());
275+ if (chunkCache .hasChunk (chunkPos .x , chunkPos .z ) && LoadedChunks .getLoadedChunks (lootrSavedData .getInfoDimension ())
276+ .contains (chunkPos )) {
277+
278+ }
279+ }
280+ }
261281 }
262282 }
263283
264284 if (count > 0 ) {
265285 data .save ();
266- LootrAPI .LOG .info ("Cleared " + count + " inventories for play UUID " + id .toString ());
286+ LootrAPI .LOG .info ("Cleared {} inventories for play UUID {}" , count , id .toString ());
267287 return true ;
268288 }
269289
0 commit comments