<commit_before>/*
 * Copyright (c) 2012-2014, <NAME> and other contributors.  All rights reserved.
 *
 * This file is part of Tectonicus. It is subject to the license terms in the LICENSE file found in
 * the top-level directory of this distribution.  The full list of project contributors is contained
 * in the AUTHORS file found in the same location.
 *
 */

package tectonicus.blockTypes;

import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;

import tectonicus.BlockContext;
import tectonicus.BlockType;
import tectonicus.BlockTypeRegistry;
import tectonicus.rasteriser.SubMesh;
import tectonicus.rasteriser.SubMesh.Rotation;
import tectonicus.raw.RawChunk;
import tectonicus.renderer.Geometry;
import tectonicus.texture.SubTexture;

public class Button implements BlockType
{
	private static final int WIDTH = 6;
	private static final int HEIGHT = 4;
	private static final int DEPTH = 2;
	
	private final String name;
	private final SubTexture frontTexture;
	private final SubTexture sideTexture;
	private final SubTexture edgeTexture;
	
	public Button(String name, SubTexture texture)
	{
		this.name = name;
		
		final float texel;
		if (texture.texturePackVersion == "1.4")
			texel = 1.0f / 16.0f / 16.0f;
		else
			texel = 1.0f / 16.0f;
		
		this.frontTexture = new SubTexture(texture.texture, texture.u0+texel*HEIGHT, texture.v0+texel*WIDTH, texture.u1-texel*HEIGHT, texture.v1-texel*WIDTH);
		this.sideTexture = new SubTexture(texture.texture, texture.u0, texture.v0, texture.u0+texel*WIDTH, texture.v0+texel*DEPTH);
		this.edgeTexture = new SubTexture(texture.texture, texture.u0, texture.v0, texture.u0+texel*DEPTH, texture.v0+texel*HEIGHT);
	}
	
	@Override
	public String getName()
	{
		return name;
	}
	
	@Override
	public boolean isSolid()
	{
		return false;
	}
	
	@Override
	public boolean isWater()
	{
		return false;
	}
	
	@Override
	public void addInteriorGeometry(int x, int y, int z, BlockContext world, BlockTypeRegistry registry, RawChunk rawChunk, Geometry geometry)
	{
		addEdgeGeometry(x, y, z, world, registry, rawChunk, geometry);
	}
	
	@Override
	public void addEdgeGeometry(int x, int y, int z, BlockContext world, BlockTypeRegistry registry, RawChunk rawChunk, Geometry geometry)
	{
		final int data = rawChunk.getBlockData(x, y, z);
		
		final float texel = 1.0f / 16.0f;
		
		final float width = texel * WIDTH;
		final float height = texel * HEIGHT;
		final float depth = texel * DEPTH;
		
		final float xMin = texel * 5.0f; // correct?
		final float xMax = xMin + width;
		
		final float yMin = texel * 6.0f; // correct?
		final float yMax = yMin + height;
		
		final float zMin = 0;
		final float zMax = zMin + depth;
		
		Vector4f white = new Vector4f(1, 1, 1, 1);
		
		SubMesh subMesh = new SubMesh();
		
		// Front quad
		subMesh.addQuad(new Vector3f(xMin, yMax, zMax), new Vector3f(xMax, yMax, zMax), new Vector3f(xMax, yMin, zMax), new Vector3f(xMin, yMin, zMax), white, frontTexture);
		
		// South quad
		subMesh.addQuad(new Vector3f(xMax, yMax, zMax), new Vector3f(xMax, yMax, zMin), new Vector3f(xMax, yMin, zMin), new Vector3f(xMax, yMin, zMax), white, edgeTexture);
		
		// North quad
		subMesh.addQuad(new Vector3f(xMin, yMax, zMin), new Vector3f(xMin, yMax, zMax), new Vector3f(xMin, yMin, zMax), new Vector3f(xMin, yMin, zMin), white, edgeTexture);
		
		// Top quad
		subMesh.addQuad(new Vector3f(xMin, yMax, zMin), new Vector3f(xMax, yMax, zMin), new Vector3f(xMax, yMax, zMax), new Vector3f(xMin, yMax, zMax), white, sideTexture);
		
		// TODO: May need a bottom quad when we get streetview views and can see the button from underneath
		
		float xOffset = x;
		float yOffset = y;
		float zOffset = z;
		
		Rotation rotation = Rotation.None;
		float angle = 0;
		
		final int direction = data & 0x3;
		
		if (direction == 0)
		{
			// Facing east
			rotation = Rotation.Clockwise;
			angle = 180;
		}
		else if (direction == 1)
		{
			// Facing south
			rotation = Rotation.Clockwise;
			angle = 90;
		}
		else if (direction == 2)
		{
			// Facing north
			rotation = Rotation.Clockwise;
			angle = -90;
		}
		else if (direction == 3)
		{
			// Facing west
			// ...build in this direction
		}
		
		subMesh.pushTo(geometry.getMesh(frontTexture.texture, Geometry.MeshType.Solid), xOffset, yOffset, zOffset, rotation, angle);
	}
	
}<commit_msg>Buttons can now render on top or bottom of blocks<commit_after>/*
 * Copyright (c) 2012-2015, <NAME> and other contributors.  All rights reserved.
 *
 * This file is part of Tectonicus. It is subject to the license terms in the LICENSE file found in
 * the top-level directory of this distribution.  The full list of project contributors is contained
 * in the AUTHORS file found in the same location.
 *
 */

package tectonicus.blockTypes;

import org.lwjgl.util.vector.Vector4f;

import tectonicus.BlockContext;
import tectonicus.BlockType;
import tectonicus.BlockTypeRegistry;
import tectonicus.Chunk;
import tectonicus.configuration.LightFace;
import tectonicus.rasteriser.SubMesh;
import tectonicus.rasteriser.SubMesh.Rotation;
import tectonicus.raw.RawChunk;
import tectonicus.renderer.Geometry;
import tectonicus.texture.SubTexture;

public class Button implements BlockType
{
	private static final int WIDTH = 6;
	private static final int HEIGHT = 2;
	private static final int DEPTH = 4;
	
	private final String name;
	private final SubTexture texture;
	
	public Button(String name, SubTexture texture)
	{
		this.name = name;
		this.texture = texture;
	}
	
	@Override
	public String getName()
	{
		return name;
	}
	
	@Override
	public boolean isSolid()
	{
		return false;
	}
	
	@Override
	public boolean isWater()
	{
		return false;
	}
	
	@Override
	public void addInteriorGeometry(int x, int y, int z, BlockContext world, BlockTypeRegistry registry, RawChunk rawChunk, Geometry geometry)
	{
		addEdgeGeometry(x, y, z, world, registry, rawChunk, geometry);
	}
	
	@Override
	public void addEdgeGeometry(int x, int y, int z, BlockContext world, BlockTypeRegistry registry, RawChunk rawChunk, Geometry geometry)
	{
		final int data = rawChunk.getBlockData(x, y, z);
		
		final float texel = 1.0f / texture.texture.getWidth();
		
		final float lightness = Chunk.getLight(world.getLightStyle(), LightFace.Top, rawChunk, x, y, z);
		Vector4f white = new Vector4f(lightness, lightness, lightness, 1);
		
		SubMesh subMesh = new SubMesh();

		float angle = 0;
		float vertAngle = 0;
		
		final int direction = data;
		
		if (direction == 0 || direction == 5)
		{
			SubMesh.addBlock(subMesh, texel*5, 0, texel*6, texel * WIDTH, texel * HEIGHT, texel * DEPTH, white, texture, texture, texture);
			
			if (direction == 0)
				vertAngle = 180;
		}
		else
		{
			SubMesh.addBlock(subMesh, texel*5, texel*6, 0, texel * WIDTH, texel * DEPTH, texel * HEIGHT, white, texture, texture, texture);
		}
		
		
		if (direction == 1)
		{
			// Facing east
			angle = 90;
		}
		else if (direction == 2)
		{
			// Facing west
			angle = -90;
		}
		else if (direction == 3)
		{ 
			//Facing south
		}
		else if (direction == 4)
		{
			// Facing north
			angle = 180;
		}
		
		subMesh.pushTo(geometry.getMesh(texture.texture, Geometry.MeshType.Solid), x, y, z, Rotation.Clockwise, angle, Rotation.Clockwise, vertAngle);
	}
	
}
{'fraction_non_alphanumeric': 0.10348644161593802, 'fraction_numerical': 0.01770890979524073, 'mean_word_length': 3.740327868852459, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7235711', 'n_tokens_mistral': 2752, 'n_tokens_neox': 2417, 'n_words': 750}