11package  com.lambda.client.manager.managers 
22
3- import  com.lambda.client.LambdaMod 
43import  com.lambda.client.event.SafeClientEvent 
54import  com.lambda.client.gui.hudgui.elements.world.ChestCounter 
65import  com.lambda.client.manager.Manager 
@@ -16,7 +15,7 @@ import net.minecraft.tileentity.TileEntityShulkerBox
1615import  net.minecraftforge.fml.common.gameevent.TickEvent 
1716
1817object  ChestCountManager : Manager {
19-     private  const  val  searchDelayTicks  =  5L 
18+     private  const  val  SEARCH_DELAY_TICKS  =  5L 
2019    private  val  delayTimer:  TickTimer  =  TickTimer (TimeUnit .TICKS )
2120    var  chestCount =  0 
2221        private  set
@@ -31,31 +30,20 @@ object ChestCountManager : Manager {
3130            if  (it.phase !=  TickEvent .Phase .END ) return @safeListener
3231            if  (! ChestCounter .visible &&  ! StorageESP .chestCountSetting) return @safeListener
3332            if  (chestCountSearchJob?.isActive ==  true ) return @safeListener
34-             if  (delayTimer.tick(searchDelayTicks )) { 
35-                 chestCountSearchJob  =  defaultScope.launch { 
36-                     searchLoadedTileEntities() 
37-                     delayTimer.reset ()
38-                 } 
33+             if  (! delayTimer.tick(SEARCH_DELAY_TICKS )) return @safeListener 
34+ 
35+             chestCountSearchJob  =  defaultScope.launch { 
36+                 searchLoadedTileEntities ()
37+                 delayTimer.reset() 
3938            }
4039        }
4140    }
4241
4342    private  fun  SafeClientEvent.searchLoadedTileEntities () {
44-         try  {
45-             var  dubsC =  0 
46-             var  chestC =  0 
47-             var  shulkC =  0 
48-             for  (tileEntity in  world.loadedTileEntityList) {
49-                 if  (tileEntity is  TileEntityChest ) {
50-                     chestC++ 
51-                     if  (tileEntity.adjacentChestXPos !=  null  ||  tileEntity.adjacentChestZPos !=  null ) dubsC++ 
52-                 } else  if  (tileEntity is  TileEntityShulkerBox ) shulkC++ 
53-             }
54-             dubsCount =  dubsC
55-             chestCount =  chestC
56-             shulkerCount =  shulkC
57-         } catch  (e:  Exception ) {
58-             LambdaMod .LOG .error(" ChestCounter: Error searching loaded tile entities"  , e)
59-         }
43+         val  chests =  world.loadedTileEntityList.filterIsInstance<TileEntityChest >()
44+ 
45+         dubsCount =  chests.count { it.adjacentChestXPos !=  null  ||  it.adjacentChestZPos !=  null  }
46+         chestCount =  chests.size
47+         shulkerCount =  world.loadedTileEntityList.filterIsInstance<TileEntityShulkerBox >().size
6048    }
6149}
0 commit comments