|
6 | 6 | import net.minecraft.server.level.ServerChunkCache; |
7 | 7 | import net.minecraft.server.level.ServerLevel; |
8 | 8 | import net.minecraft.server.level.ServerPlayer; |
| 9 | +import net.minecraft.world.entity.Entity; |
9 | 10 | import net.minecraft.world.entity.player.Player; |
10 | 11 | import net.minecraft.world.level.ChunkPos; |
| 12 | +import net.minecraft.world.level.block.entity.BlockEntity; |
11 | 13 | import net.minecraft.world.level.saveddata.SavedData; |
12 | 14 | import net.minecraft.world.level.storage.DimensionDataStorage; |
13 | 15 | import net.minecraft.world.level.storage.LevelResource; |
14 | 16 | import noobanidus.mods.lootr.common.api.LootrAPI; |
| 17 | +import noobanidus.mods.lootr.common.api.PlatformAPI; |
15 | 18 | import noobanidus.mods.lootr.common.api.data.*; |
| 19 | +import noobanidus.mods.lootr.common.api.data.blockentity.ILootrBlockEntity; |
| 20 | +import noobanidus.mods.lootr.common.api.data.entity.ILootrCart; |
16 | 21 | import noobanidus.mods.lootr.common.api.data.inventory.ILootrInventory; |
17 | 22 | import noobanidus.mods.lootr.common.chunk.LoadedChunks; |
18 | 23 | import noobanidus.mods.lootr.common.mixins.AccessorMixinDimensionDataStorage; |
@@ -267,14 +272,27 @@ public static boolean clearInventories(UUID id) { |
267 | 272 |
|
268 | 273 | if (lootrSavedData.clearInventories(id)) { |
269 | 274 | 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 | | - |
| 275 | + ServerLevel level = server.getLevel(lootrSavedData.getInfoDimension()); |
| 276 | + if (level != null) { |
| 277 | + ServerChunkCache chunkCache = level.getChunkSource(); |
| 278 | + ChunkPos chunkPos = new ChunkPos(lootrSavedData.getInfoPos()); |
| 279 | + if (chunkCache.hasChunk(chunkPos.x, chunkPos.z) && LoadedChunks.getLoadedChunks(lootrSavedData.getInfoDimension()) |
| 280 | + .contains(chunkPos)) { |
| 281 | + if (lootrSavedData.getInfoBlockType() == LootrBlockType.ENTITY) { |
| 282 | + Entity entity = level.getEntity(lootrSavedData.getInfoUUID()); |
| 283 | + if (entity instanceof ILootrCart cart) { |
| 284 | + cart.removeVisualOpener(id); |
| 285 | + cart.markChanged(); |
| 286 | + PlatformAPI.performCartClose(cart); |
| 287 | + } |
| 288 | + } else { |
| 289 | + BlockEntity entity = level.getBlockEntity(lootrSavedData.getInfoPos()); |
| 290 | + if (LootrAPI.resolveBlockEntity(entity) instanceof ILootrBlockEntity blockEntity) { |
| 291 | + blockEntity.removeVisualOpener(id); |
| 292 | + blockEntity.markChanged(); |
| 293 | + PlatformAPI.performBlockClose(blockEntity); |
| 294 | + blockEntity.performUpdate(); |
| 295 | + } |
278 | 296 | } |
279 | 297 | } |
280 | 298 | } |
|
0 commit comments