<commit_before>package ethanjones.cubes.graphics.hud.inv;

import ethanjones.cubes.block.Block;
import ethanjones.cubes.block.BlockRenderType;
import ethanjones.cubes.core.id.IDManager;
import ethanjones.cubes.core.util.BlockFace;
import ethanjones.cubes.graphics.Graphics;
import ethanjones.cubes.graphics.world.AreaMesh;
import ethanjones.cubes.graphics.world.BlockTextureHandler;
import ethanjones.cubes.graphics.world.FaceVertices;
import ethanjones.cubes.world.light.BlockLight;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.RenderableProvider;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import com.badlogic.gdx.utils.ScreenUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class BlockIcons {
  
  private static HashMap<BlockID, TextureRegion> textureRegions = new HashMap<BlockID, TextureRegion>();
  
  public static TextureRegion getIcon(String id, int meta) {
    BlockID blockID = new BlockID();
    blockID.id = id;
    blockID.meta = meta;
    return textureRegions.get(blockID);
  }
  
  public static void renderIcons() {
    int size = 128;
    
    FrameBuffer frameBuffer = new FrameBuffer(Format.RGBA8888, size, size, false);
    frameBuffer.begin();
  
    PerspectiveCamera camera = new PerspectiveCamera(30f, size, size);
    camera.position.set(2.4f, 2f, 2.4f);
    camera.lookAt(0f, 0f, 0f);
    camera.near = 0.1f;
    camera.update(true);
    
  
    final AreaMesh mesh = new AreaMesh();
    List<Block> blocks = IDManager.getBlocks();
    
    int numberBlock = (int) Math.ceil(Math.sqrt(blocks.size()));
    Pixmap pixmap = new Pixmap(size * numberBlock, size * numberBlock, Format.RGBA8888);
    int number = 0;
    HashMap<BlockID, Location> map = new HashMap<BlockID, Location>();
            
    for (Block block : blocks) {
      for (int meta : block.displayMetaValues()) {
        BlockRenderType type = block.renderType(meta);
        if (type != BlockRenderType.DEFAULT) continue;
        BlockTextureHandler textureHandler = block.getTextureHandler(meta);
        int vertexOffset = 0;
        vertexOffset = FaceVertices.createMaxX(Vector3.Zero, textureHandler.getSide(BlockFace.posX), 0, 0, 0, BlockLight.FULL_LIGHT, AreaMesh.vertices, vertexOffset);
        vertexOffset = FaceVertices.createMaxY(Vector3.Zero, textureHandler.getSide(BlockFace.posY), 0, 0, 0, BlockLight.FULL_LIGHT, AreaMesh.vertices, vertexOffset);
        vertexOffset = FaceVertices.createMaxZ(Vector3.Zero, textureHandler.getSide(BlockFace.posZ), 0, 0, 0, BlockLight.FULL_LIGHT, AreaMesh.vertices, vertexOffset);
        mesh.saveVertices(vertexOffset);
        Graphics.modelBatch.begin(camera);
        Graphics.modelBatch.render(new RenderableProvider() {
          @Override
          public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
            renderables.add(mesh.renderable(pool));
          }
        });
        Graphics.modelBatch.end();
        Pixmap bufferPixmap = ScreenUtils.getFrameBufferPixmap(0, 0, size, size);
//        FileHandle fileHandle = Assets.assetsFolder.child(block.id.replace(':', '-') + "-" + meta + ".png");
//        try {
//          PixmapIO.writePNG(fileHandle, bufferPixmap);
//        } catch (GdxRuntimeException e) {
//          Log.error("Failed to write packed image", e);
//        }
        int x = (number % numberBlock) * size;
        int y = (number / numberBlock) * size;
        pixmap.drawPixmap(bufferPixmap, x, y);
        bufferPixmap.dispose();
        BlockID blockID = new BlockID();<commit_msg>Fix crash on startup caused by having fog enabled when drawing block icons.<commit_after>package ethanjones.cubes.graphics.hud.inv;

import ethanjones.cubes.block.Block;
import ethanjones.cubes.block.BlockRenderType;
import ethanjones.cubes.core.id.IDManager;
import ethanjones.cubes.core.util.BlockFace;
import ethanjones.cubes.graphics.Graphics;
import ethanjones.cubes.graphics.world.AreaMesh;
import ethanjones.cubes.graphics.world.BlockTextureHandler;
import ethanjones.cubes.graphics.world.FaceVertices;
import ethanjones.cubes.graphics.world.RenderingSettings;
import ethanjones.cubes.world.light.BlockLight;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g3d.Renderable;
import com.badlogic.gdx.graphics.g3d.RenderableProvider;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import com.badlogic.gdx.utils.ScreenUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class BlockIcons {
  
  private static HashMap<BlockID, TextureRegion> textureRegions = new HashMap<BlockID, TextureRegion>();
  
  public static TextureRegion getIcon(String id, int meta) {
    BlockID blockID = new BlockID();
    blockID.id = id;
    blockID.meta = meta;
    return textureRegions.get(blockID);
  }
  
  public static void renderIcons() {
    int size = 128;
    
    FrameBuffer frameBuffer = new FrameBuffer(Format.RGBA8888, size, size, false);
    frameBuffer.begin();
  
    PerspectiveCamera camera = new PerspectiveCamera(30f, size, size);
    camera.position.set(2.4f, 2f, 2.4f);
    camera.lookAt(0f, 0f, 0f);
    camera.near = 0.1f;
    camera.update(true);
    
  
    final AreaMesh mesh = new AreaMesh();
    List<Block> blocks = IDManager.getBlocks();
    
    int numberBlock = (int) Math.ceil(Math.sqrt(blocks.size()));
    Pixmap pixmap = new Pixmap(size * numberBlock, size * numberBlock, Format.RGBA8888);
    int number = 0;
    HashMap<BlockID, Location> map = new HashMap<BlockID, Location>();
  
    final RenderingSettings renderingSettings = new RenderingSettings();
    renderingSettings.setLightOverride(BlockLight.FULL_LIGHT);
    renderingSettings.setFogEnabled(false);
            
    for (Block block : blocks) {
      for (int meta : block.displayMetaValues()) {
        BlockRenderType type = block.renderType(meta);
        if (type != BlockRenderType.DEFAULT) continue;
        BlockTextureHandler textureHandler = block.getTextureHandler(meta);
        int vertexOffset = 0;
        vertexOffset = FaceVertices.createMaxX(Vector3.Zero, textureHandler.getSide(BlockFace.posX), 0, 0, 0, BlockLight.FULL_LIGHT, AreaMesh.vertices, vertexOffset);
        vertexOffset = FaceVertices.createMaxY(Vector3.Zero, textureHandler.getSide(BlockFace.posY), 0, 0, 0, BlockLight.FULL_LIGHT, AreaMesh.vertices, vertexOffset);
        vertexOffset = FaceVertices.createMaxZ(Vector3.Zero, textureHandler.getSide(BlockFace.posZ), 0, 0, 0, BlockLight.FULL_LIGHT, AreaMesh.vertices, vertexOffset);
        mesh.saveVertices(vertexOffset);
        Graphics.modelBatch.begin(camera);
        Graphics.modelBatch.render(new RenderableProvider() {
          @Override
          public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
            Renderable renderable = mesh.renderable(pool);
            renderable.userData = renderingSettings;
            renderables.add(renderable);
          }
        });
        Graphics.modelBatch.end();
        Pixmap bufferPixmap = ScreenUtils.getFrameBufferPixmap(0, 0, size, size);
//        FileHandle fileHandle = Assets.assetsFolder.child(block.id.replace(':', '-') + "-" + meta + ".png");
//        try {
//          PixmapIO.writePNG(fileHandle, bufferPixmap);
//        } catch (GdxRuntimeException e) {
//          Log.error("Failed to write packed image", e);
//        }
        int x = (number % numberBlock) * size;
        int y = (number / numberBlock) * size;
        pixmap.drawPixmap(bufferPixmap, x, y);
        bufferPixmap.dispose();
        BlockID blockID = new BlockID();
{'fraction_non_alphanumeric': 0.11454673225579762, 'fraction_numerical': 0.010541110330288124, 'mean_word_length': 3.7757270693512304, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '414365', 'n_tokens_mistral': 2793, 'n_tokens_neox': 2680, 'n_words': 515}