<commit_before>package de.longor.talecraft.client.render.renderables;

import org.lwjgl.opengl.GL11;

import de.longor.talecraft.TaleCraft;
import de.longor.talecraft.client.ClientResources;
import de.longor.talecraft.client.render.IRenderable;
import de.longor.talecraft.client.render.renderers.BoxRenderer;
import de.longor.talecraft.proxy.ClientProxy;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;

public class SelectionBoxRenderer implements IRenderable {

	@Override
	public void render(Minecraft mc, ClientProxy clientProxy,
			Tessellator tessellator, VertexBuffer vertexbuffer,
			double partialTicks) {

		// Don't show the selection if we are not in BuildMode!
		if(!ClientProxy.isInBuildMode()) return;

		GlStateManager.enableBlend();
		GlStateManager.blendFunc(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ZERO);

		// Wand Selection Rendering
		NBTTagCompound playerData = mc.thePlayer.getEntityData();
		if(playerData.hasKey("tcWand")) {
			NBTTagCompound tcWand = playerData.getCompoundTag("tcWand");

			if(tcWand.hasKey("cursor")) {
				final float E = -1f / 64f;
				int[] cursor = tcWand.getIntArray("cursor");

				GlStateManager.glPolygonMode(GL11.GL_FRONT, GL11.GL_POINT);
				GlStateManager.glPolygonMode(GL11.GL_BACK, GL11.GL_FILL);
				GlStateManager.enableTexture2D();
				mc.getTextureManager().bindTexture(ClientResources.texColorWhite);
				BoxRenderer.renderBox(tessellator, vertexbuffer, cursor[0]-E, cursor[1]-E, cursor[2]-E, cursor[0]+1+E, cursor[1]+1+E, cursor[2]+1+E, 1f,1f,1f,1f);
				GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
			}

			// If not null, render the cursor selections boundaries.
			if(tcWand.hasKey("boundsA") && tcWand.hasKey("boundsB") && tcWand.getBoolean("enabled")) {
				// get bounds
				int[] a = tcWand.getIntArray("boundsA");
				int[] b = tcWand.getIntArray("boundsB");

				// make sure its correctly sorted
				int ix = Math.min(a[0], b[0]);
				int iy = Math.min(a[1], b[1]);
				int iz = Math.min(a[2], b[2]);
				int ax = Math.max(a[0], b[0]);
				int ay = Math.max(a[1], b[1]);
				int az = Math.max(a[2], b[2]);

				// 'error' offset
				final float E = 1f / 32f;

				// Prepare state
				GlStateManager.enableNormalize();
				GlStateManager.enableTexture2D();
				RenderHelper.disableStandardItemLighting();
				GlStateManager.glLineWidth(2.5f);

				ResourceLocation texture = null;

				TaleCraft.proxy.asClient();
				if(!ClientProxy.settings.getBoolean("client.render.useAlternateSelectionTexture")) {
					texture = ClientResources.textureSelectionBoxWS;
				} else {
					texture = ClientResources.textureSelectionBoxFF;
				}

				GlStateManager.enableTexture2D();
				
				// Render primary (with-depth) box
				{
					mc.getTextureManager().bindTexture(texture);
					GlStateManager.enableDepth();
					BoxRenderer.renderSelectionBox(tessellator, vertexbuffer, ix-E, iy-E, iz-E, ax+1+E, ay+1+E, az+1+E, 1);
				}<commit_msg>Structure-Voids in selection are now highlighted.<commit_after>package de.longor.talecraft.client.render.renderables;

import org.lwjgl.opengl.GL11;

import de.longor.talecraft.TaleCraft;
import de.longor.talecraft.TaleCraftItems;
import de.longor.talecraft.client.ClientResources;
import de.longor.talecraft.client.render.IRenderable;
import de.longor.talecraft.client.render.renderers.BoxRenderer;
import de.longor.talecraft.proxy.ClientProxy;
import de.longor.talecraft.util.WorldHelper;
import de.longor.talecraft.util.WorldHelper.BlockRegionIterator;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntityStructureRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityStructure;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.structure.StructureBoundingBox;
import net.minecraft.world.gen.structure.StructureStart;

public class SelectionBoxRenderer implements IRenderable {

	@Override
	public void render(Minecraft mc, ClientProxy clientProxy,
			Tessellator tessellator, VertexBuffer vertexbuffer,
			double partialTicks) {

		// Don't show the selection if we are not in BuildMode!
		if(!ClientProxy.isInBuildMode()) return;

		GlStateManager.enableBlend();
		GlStateManager.blendFunc(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ZERO);

		// Wand Selection Rendering
		NBTTagCompound playerData = mc.thePlayer.getEntityData();
		if(playerData.hasKey("tcWand")) {
			NBTTagCompound tcWand = playerData.getCompoundTag("tcWand");

			if(tcWand.hasKey("cursor")) {
				final float E = -1f / 64f;
				int[] cursor = tcWand.getIntArray("cursor");

				GlStateManager.glPolygonMode(GL11.GL_FRONT, GL11.GL_POINT);
				GlStateManager.glPolygonMode(GL11.GL_BACK, GL11.GL_FILL);
				GlStateManager.enableTexture2D();
				mc.getTextureManager().bindTexture(ClientResources.texColorWhite);
				BoxRenderer.renderBox(tessellator, vertexbuffer, cursor[0]-E, cursor[1]-E, cursor[2]-E, cursor[0]+1+E, cursor[1]+1+E, cursor[2]+1+E, 1f,1f,1f,1f);
				GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
			}

			// If not null, render the cursor selections boundaries.
			if(tcWand.hasKey("boundsA") && tcWand.hasKey("boundsB") && tcWand.getBoolean("enabled")) {
				// get bounds
				int[] ba = tcWand.getIntArray("boundsA");
				int[] bb = tcWand.getIntArray("boundsB");
				
				// make sure its correctly sorted
				int ix = Math.min(ba[0], bb[0]);
				int iy = Math.min(ba[1], bb[1]);
				int iz = Math.min(ba[2], bb[2]);
				int ax = Math.max(ba[0], bb[0]);
				int ay = Math.max(ba[1], bb[1]);
				int az = Math.max(ba[2], bb[2]);
				
				// Calculate Size & Volume
				int sx = ax-ix+1;
				int sy = ay-iy+1;
				int sz = az-iz+1;
				int sv = sx*sy*sz;
				
				if(sv < 1024 && sv > 0) {
					boolean showVoid = false;
					
					ItemStack IS = mc.thePlayer.getHeldItemMainhand();
					Item I = IS!=null?IS.getItem():null;
					
					if(I!=null) {
						/* TODO: Replace the getBlockFromName with the actual Block instance if possible. */
						showVoid |= I.equals(Item.getItemFromBlock(Block.getBlockFromName("minecraft:structure_void")));
						showVoid |= I.equals(Item.getItemFromBlock(Blocks.STRUCTURE_BLOCK));
						showVoid |= I.equals(TaleCraftItems.paste);
						showVoid |= I.equals(TaleCraftItems.copy);
						showVoid |= I.equals(TaleCraftItems.cut);
					}
					
					if(showVoid) {
						IBlockState stvoid = Block.getBlockFromName("minecraft:structure_void").getDefaultState();
						
						GlStateManager.disableBlend();
						GlStateManager.disableTexture2D();
						GlStateManager.glLineWidth(3f);
						vertexbuffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
						final float m = 0.45f;
						final float M = 1-m;
						
						final int r = 0;
						final int g = 255;
						final int b = 255;
						final int a = 255;
						
						WorldHelper.foreach(mc.theWorld, ix, iy, iz, ax, ay, az, new BlockRegionIterator() {
							@Override public void $(World world, IBlockState state, BlockPos pos) {
								if(!state.equals(stvoid))
									return;
								
								float x = pos.getX();
								float y = pos.getY();
								float z = pos.getZ();
								
								vertexbuffer.pos(x+m, y+m, z+m).color(r, g, b, a).endVertex();
								vertexbuffer.pos(x+M, y+M, z+M).color(r, g, b, a).endVertex();
								vertexbuffer.pos(x+M, y+m, z+m).color(r, g, b, a).endVertex();
								vertexbuffer.pos(x+m, y+M, z+M).color(r, g, b, a).endVertex();
								
								vertexbuffer.pos(x+m, y+m, z+M).color(r, g, b, a).endVertex();
								vertexbuffer.pos(x+M, y+M, z+m).color(r, g, b, a).endVertex();
								vertexbuffer.pos(x+M, y+m, z+M).color(r, g, b, a).endVertex();
								vertexbuffer.pos(x+m, y+M, z+m).color(r, g, b, a).endVertex();
							}
						});
						tessellator.draw();
						GlStateManager.glLineWidth(1f);
						GlStateManager.enableTexture2D();
						GlStateManager.enableBlend();
					}
				}

				// 'error' offset
				final float E = 1f / 32f;

				// Prepare state
				GlStateManager.enableNormalize();
				GlStateManager.enableTexture2D();
				RenderHelper.disableStandardItemLighting();
				GlStateManager.glLineWidth(2.5f);

				ResourceLocation texture = null;

				TaleCraft.proxy.asClient();
				if(!ClientProxy.settings.getBoolean("client.render.useAlternateSelectionTexture")) {
					texture = ClientResources.textureSelectionBoxWS;
				} else {
					texture = ClientResources.textureSelectionBoxFF;
				}

				GlStateManager.enableTexture2D();
				
				// Render primary (with-depth) box
				{
					mc.getTextureManager().bindTexture(texture);
					GlStateManager.enableDepth();
					BoxRenderer.renderSelectionBox(tessellator, vertexbuffer, ix-E, iy-E, iz-E, ax+1+E, ay+1+E, az+1+E, 1);
				}
{'fraction_non_alphanumeric': 0.13317540426408486, 'fraction_numerical': 0.014831599546812235, 'mean_word_length': 3.997426659804426, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '20459', 'n_tokens_mistral': 3994, 'n_tokens_neox': 3334, 'n_words': 573}