content: package me.earth.earthhack.impl.util.minecraft;
  
  import me.earth.earthhack.api.util.interfaces.Globals;
  import net.minecraft.block.entity.BlockEntity;
  import net.minecraft.world.chunk.WorldChunk;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Convenience class for getting BlockEntities, as
   * the method for getting them in 1.12.2 don't exist
   * anymore.
   *
   * @author cattyn
   */
  public class WorldUtil implements Globals
  {
      public static List<WorldChunk> getLoadedChunks() {
          List<WorldChunk> chunks = new ArrayList<>();
  
          int viewDist = mc.options.getViewDistance().getValue();
  
          for (int x = -viewDist; x <= viewDist; x++) {
              for (int z = -viewDist; z <= viewDist; z++) {
                  WorldChunk chunk = mc.world.getChunkManager().getWorldChunk((int) mc.player.getX() / 16 + x, (int) mc.player.getZ() / 16 + z);
  
                  if (chunk != null) {
                      chunks.add(chunk);
                  }
              }
          }
  
          return chunks;
      }
  
      public static List<BlockEntity> getBlockEntities() {
          List<BlockEntity> list = new ArrayList<>();
          for (WorldChunk chunk : getLoadedChunks())
              list.addAll(chunk.getBlockEntities().values());
  
          return list;
      }
  }
  