Search in sources :

Example 1 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method drawBlockDamageTexture.

//	public static void handleStaticTileRenderer(TileEntity tile)
//	{
//		handleStaticTileRenderer(tile,true);
//	}
//	public static void handleStaticTileRenderer(TileEntity tile, boolean translate)
//	{
//		TileEntitySpecialRenderer tesr = TileEntityRendererDispatcher.instance.getSpecialRenderer(tile);
//		if(tesr instanceof TileRenderIE)
//		{
//			Matrix4 matrixT = new Matrix4();
//			if(translate)
//				matrixT.translate(tile.xCoord, tile.yCoord, tile.zCoord);
//			((TileRenderIE)tesr).renderStatic(tile, Tessellator.instance, matrixT, new Matrix4());
//		}
//	}
//
//	public static void renderStaticWavefrontModel(TileEntity tile, WavefrontObject model, Tessellator tes, Matrix4 translationMatrix, Matrix4 rotationMatrix, int offsetLighting, boolean invertFaces, String... renderedParts) {
//		renderStaticWavefrontModel(tile, model, tes, translationMatrix, rotationMatrix, offsetLighting, invertFaces, 1, 1, 1, renderedParts);
//	}
//
//	/**
//	 * A big "Thank you!" to AtomicBlom and Rorax for helping me figure this one out =P
//	 */
//	public static void renderStaticWavefrontModel(TileEntity tile, WavefrontObject model, Tessellator tes, Matrix4 translationMatrix, Matrix4 rotationMatrix, int offsetLighting, boolean invertFaces, float colR, float colG, float colB, String... renderedParts)
//	{
//		renderStaticWavefrontModel(tile.getWorldObj(),tile.xCoord,tile.yCoord,tile.zCoord, model, tes, translationMatrix, rotationMatrix, offsetLighting, invertFaces, colR,colG,colB, renderedParts);
//	}
//	public static void renderStaticWavefrontModel(IBlockAccess world, int x, int y, int z, WavefrontObject model, Tessellator tes, Matrix4 translationMatrix, Matrix4 rotationMatrix, int offsetLighting, boolean invertFaces, float colR, float colG, float colB, String... renderedParts)
//	{
//		if(world!=null)
//		{
//			int lb = world.getLightBrightnessForSkyBlocks(x, y, z, 0);
//			int lb_j = lb % 65536;
//			int lb_k = lb / 65536;
//			OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)lb_j / 1.0F, (float)lb_k / 1.0F);
//		}
//		Vertex vertexCopy = new Vertex(0,0,0);
//		Vertex normalCopy = new Vertex(0,0,0);
//
//		for(GroupObject groupObject : model.groupObjects)
//		{
//			boolean render = false;
//			if(renderedParts==null || renderedParts.length<1)
//				render = true;
//			else
//				for(String s : renderedParts)
//					if(groupObject.name.equalsIgnoreCase(s))
//						render = true;
//			if(render)
//				for(Face face : groupObject.faces)
//				{
//					if(face.faceNormal == null)
//						face.faceNormal = face.calculateFaceNormal();
//
//					normalCopy.x = face.faceNormal.x;
//					normalCopy.y = face.faceNormal.y;
//					normalCopy.z = face.faceNormal.z;
//					rotationMatrix.apply(normalCopy);
//					float biggestNormal = Math.max(Math.abs(normalCopy.y), Math.max(Math.abs(normalCopy.x),Math.abs(normalCopy.z)));
//					int side = biggestNormal==Math.abs(normalCopy.y)?(normalCopy.y<0?0:1): biggestNormal==Math.abs(normalCopy.z)?(normalCopy.z<0?2:3): (normalCopy.x<0?4:5);
//
//					BlockLightingInfo faceLight = null;
//					if(offsetLighting==0 && world!=null)
//						faceLight = calculateBlockLighting(side, world, world.getBlock(x,y,z), x,y,z, colR,colG,colB, standardBlockAABB);
//					else if(offsetLighting==1 && world!=null)
//					{
//						double faceMinX = face.vertices[0].x;
//						double faceMinY = face.vertices[0].y;
//						double faceMinZ = face.vertices[0].z;
//						double faceMaxX = face.vertices[0].x;
//						double faceMaxY = face.vertices[0].y;
//						double faceMaxZ = face.vertices[0].z;
//						for(int i=1; i<face.vertices.length; ++i)
//						{
//							faceMinX = Math.min(faceMinX, face.vertices[i].x);
//							faceMinY = Math.min(faceMinY, face.vertices[i].y);
//							faceMinZ = Math.min(faceMinZ, face.vertices[i].z);
//							faceMaxX = Math.max(faceMaxX, face.vertices[i].x);
//							faceMaxY = Math.max(faceMaxY, face.vertices[i].y);
//							faceMaxZ = Math.max(faceMaxZ, face.vertices[i].z);
//						}
//						faceLight = calculateBlockLighting(side, world, world.getBlock(x, y, z), x,y,z, colR,colG,colB, AxisAlignedBB.getBoundingBox(faceMinX,faceMinY,faceMinZ, faceMaxX,faceMaxY,faceMaxZ));
//					}
//
//					tes.setNormal(face.faceNormal.x, face.faceNormal.y, face.faceNormal.z);
//
//					for(int i=0; i<face.vertices.length; ++i)
//					{
//						int target = !invertFaces?i:(face.vertices.length-1-i);
//						int corner = (int)(target/(float)face.vertices.length*4);
//						Vertex vertex = face.vertices[target];
//						vertexCopy.x = vertex.x;
//						vertexCopy.y = vertex.y;
//						vertexCopy.z = vertex.z;
//						rotationMatrix.apply(vertexCopy);
//						translationMatrix.apply(vertexCopy);
//						if(faceLight!=null)
//						{
//							tes.setBrightness(corner==0?faceLight.brightnessTopLeft: corner==1?faceLight.brightnessBottomLeft: corner==2?faceLight.brightnessBottomRight: faceLight.brightnessTopRight);
//							float r = corner==0?faceLight.colorRedTopLeft: corner==1?faceLight.colorRedBottomLeft: corner==2?faceLight.colorRedBottomRight: faceLight.colorRedTopRight;
//							float g = corner==0?faceLight.colorGreenTopLeft: corner==1?faceLight.colorGreenBottomLeft: corner==2?faceLight.colorGreenBottomRight: faceLight.colorGreenTopRight;
//							float b = corner==0?faceLight.colorBlueTopLeft: corner==1?faceLight.colorBlueBottomLeft: corner==2?faceLight.colorBlueBottomRight: faceLight.colorBlueTopRight;
//							tes.setColorOpaque_F(r, g, b);
//						}
//						else if(world!=null)
//						{
//							tes.setBrightness(0xb000b0);
//							tes.setColorOpaque_F(colR,colG,colB);
//						}
//
//						if(face.textureCoordinates!=null && face.textureCoordinates.length>0)
//						{
//							TextureCoordinate textureCoordinate = face.textureCoordinates[target];
//							tes.addVertexWithUV(vertexCopy.x, vertexCopy.y, vertexCopy.z, textureCoordinate.u, textureCoordinate.v);
//						}
//						else
//						{
//							tes.addVertex(vertexCopy.x, vertexCopy.y, vertexCopy.z);
//						}
//					}
//				}
//		}
//	}
//	public static void renderStaticWavefrontModelWithIcon(TileEntity tile, WavefrontObject model, IIcon icon, Tessellator tes, Matrix4 translationMatrix, Matrix4 rotationMatrix, int offsetLighting, boolean invertFaces, float colR, float colG, float colB, String... renderedParts)
//	{
//		renderStaticWavefrontModelWithIcon(tile.getWorldObj(),tile.xCoord,tile.yCoord,tile.zCoord, model, icon, tes, translationMatrix, rotationMatrix, offsetLighting, invertFaces, colR,colG,colB, renderedParts);
//	}
//	public static void renderStaticWavefrontModelWithIcon(IBlockAccess world, int x, int y, int z, WavefrontObject model, IIcon icon, Tessellator tes, Matrix4 translationMatrix, Matrix4 rotationMatrix, int offsetLighting, boolean invertFaces, float colR, float colG, float colB, String... renderedParts)
//	{
//		if(icon==null)
//			return;
//		if(world!=null)
//		{
//			int lb = world.getLightBrightnessForSkyBlocks(x, y, z, 0);
//			int lb_j = lb % 65536;
//			int lb_k = lb / 65536;
//			OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)lb_j / 1.0F, (float)lb_k / 1.0F);
//		}
//		Vertex normalCopy = new Vertex(0,0,0);
//
//		float minU = icon.getInterpolatedU(0);
//		float sizeU = icon.getInterpolatedU(16) - minU;
//		float minV = icon.getInterpolatedV(0);
//		float sizeV = icon.getInterpolatedV(16) - minV;
//		float baseOffsetU = (16f/icon.getIconWidth())*.0005F;
//		float baseOffsetV = (16f/icon.getIconHeight())*.0005F;
//
//		for(GroupObject groupObject : model.groupObjects)
//		{
//			boolean render = false;
//			if(renderedParts==null || renderedParts.length<1)
//				render = true;
//			else
//				for(String s : renderedParts)
//					if(groupObject.name.equalsIgnoreCase(s))
//						render = true;
//			if(render)
//				for(Face face : groupObject.faces)
//				{
//					if(face.faceNormal == null)
//						face.faceNormal = face.calculateFaceNormal();
//
//					normalCopy.x = face.faceNormal.x;
//					normalCopy.y = face.faceNormal.y;
//					normalCopy.z = face.faceNormal.z;
//					rotationMatrix.apply(normalCopy);
//					float biggestNormal = Math.max(Math.abs(normalCopy.y), Math.max(Math.abs(normalCopy.x),Math.abs(normalCopy.z)));
//					int side = biggestNormal==Math.abs(normalCopy.y)?(normalCopy.y<0?0:1): biggestNormal==Math.abs(normalCopy.z)?(normalCopy.z<0?2:3): (normalCopy.x<0?4:5);
//
//					BlockLightingInfo faceLight = null;
//					if(offsetLighting==0 && world!=null)
//						faceLight = calculateBlockLighting(side, world, world.getBlock(x,y,z), x,y,z, colR,colG,colB, standardBlockAABB);
//					else if(offsetLighting==1 && world!=null)
//					{
//						double faceMinX = face.vertices[0].x;
//						double faceMinY = face.vertices[0].y;
//						double faceMinZ = face.vertices[0].z;
//						double faceMaxX = face.vertices[0].x;
//						double faceMaxY = face.vertices[0].y;
//						double faceMaxZ = face.vertices[0].z;
//						for(int i=1; i<face.vertices.length; ++i)
//						{
//							faceMinX = Math.min(faceMinX, face.vertices[i].x);
//							faceMinY = Math.min(faceMinY, face.vertices[i].y);
//							faceMinZ = Math.min(faceMinZ, face.vertices[i].z);
//							faceMaxX = Math.max(faceMaxX, face.vertices[i].x);
//							faceMaxY = Math.max(faceMaxY, face.vertices[i].y);
//							faceMaxZ = Math.max(faceMaxZ, face.vertices[i].z);
//						}
//						faceLight = calculateBlockLighting(side, world, world.getBlock(x, y, z), x,y,z, colR,colG,colB, AxisAlignedBB.getBoundingBox(faceMinX,faceMinY,faceMinZ, faceMaxX,faceMaxY,faceMaxZ));
//					}
//
//					tes.setNormal(face.faceNormal.x, face.faceNormal.y, face.faceNormal.z);
//
//					float averageU = 0F;
//					float averageV = 0F;
//					if(face.textureCoordinates!=null && face.textureCoordinates.length>0)
//					{
//						for(int i=0; i<face.textureCoordinates.length; ++i)
//						{
//							averageU += face.textureCoordinates[i].u;
//							averageV += face.textureCoordinates[i].v;
//						}
//						averageU = averageU / face.textureCoordinates.length;
//						averageV = averageV / face.textureCoordinates.length;
//					}
//
//					TextureCoordinate[] oldUVs = new TextureCoordinate[face.textureCoordinates.length];
//					for(int v=0; v<face.vertices.length; ++v)
//					{
//						float offsetU, offsetV;
//						offsetU = baseOffsetU;
//						offsetV = baseOffsetV;
//						if (face.textureCoordinates[v].u > averageU)
//							offsetU = -offsetU;
//						if (face.textureCoordinates[v].v > averageV)
//							offsetV = -offsetV;
//
//						oldUVs[v] = face.textureCoordinates[v];
//						TextureCoordinate textureCoordinate = face.textureCoordinates[v];
//						face.textureCoordinates[v] = new TextureCoordinate(
//								minU + sizeU * (textureCoordinate.u+offsetU),
//								minV + sizeV * (textureCoordinate.v+offsetV)
//								);
//					}
//					addFaceToWorldRender(face, tes, faceLight, translationMatrix, rotationMatrix, invertFaces, colR, colG, colB);
//					for(int v=0; v<face.vertices.length; ++v)
//						face.textureCoordinates[v] = new TextureCoordinate(oldUVs[v].u,oldUVs[v].v);
//				}
//		}
//	}
//	public static void renderWavefrontModelWithModifications(WavefrontObject model, Tessellator tes, Matrix4 translationMatrix, Matrix4 rotationMatrix, boolean flipTextureU, String... renderedParts)
//	{
//		Vertex vertexCopy = new Vertex(0,0,0);
//		Vertex normalCopy = new Vertex(0,0,0);
//
//		for(GroupObject groupObject : model.groupObjects)
//		{
//			boolean render = false;
//			if(renderedParts==null || renderedParts.length<1)
//				render = true;
//			else
//				for(String s : renderedParts)
//					if(groupObject.name.equalsIgnoreCase(s))
//						render = true;
//			if(render)
//				for(Face face : groupObject.faces)
//				{
//					if(face.faceNormal == null)
//						face.faceNormal = face.calculateFaceNormal();
//
//					normalCopy.x = face.faceNormal.x;
//					normalCopy.y = face.faceNormal.y;
//					normalCopy.z = face.faceNormal.z;
//					rotationMatrix.apply(normalCopy);
//
//
//					tes.setNormal(face.faceNormal.x, face.faceNormal.y, face.faceNormal.z);
//					for(int i=0; i<face.vertices.length; ++i)
//					{
//						Vertex vertex = face.vertices[i];
//						vertexCopy.x = vertex.x;
//						vertexCopy.y = vertex.y;
//						vertexCopy.z = vertex.z;
//						rotationMatrix.apply(vertexCopy);
//						translationMatrix.apply(vertexCopy);
//
//						if((face.textureCoordinates != null) && (face.textureCoordinates.length > 0))
//						{
//							TextureCoordinate textureCoordinate = face.textureCoordinates[flipTextureU?(face.textureCoordinates.length-1)-i: i];
//							tes.addVertexWithUV(vertexCopy.x, vertexCopy.y, vertexCopy.z, textureCoordinate.u, textureCoordinate.v);
//						}
//						else
//							tes.addVertex(vertexCopy.x, vertexCopy.y, vertexCopy.z);
//					}
//				}
//		}
//	}
//
//	public static void renderWavefrontWithIconUVs(WavefrontObject model, IIcon icon, String... parts)
//	{
//		renderWavefrontWithIconUVs(model, GL11.GL_QUADS, icon, parts);
//		renderWavefrontWithIconUVs(model, GL11.GL_TRIANGLES, icon, parts);
//	}
//
//	public static void renderWavefrontWithIconUVs(WavefrontObject model, int glDrawingMode, IIcon icon, String... parts)
//	{
//		if(icon==null)
//			return;
//		List<String> renderParts = Arrays.asList(parts);
//		tes().startDrawing(glDrawingMode);
//		for(GroupObject go : model.groupObjects)
//			if(go.glDrawingMode==glDrawingMode)
//				if(renderParts.contains(go.name))
//					tessellateWavefrontGroupObjectWithIconUVs(go, icon);
//		tes().draw();
//	}
//	public static void tessellateWavefrontGroupObjectWithIconUVs(GroupObject object, IIcon icon)
//	{
//		if(icon==null)
//			return;
//
//		float minU = icon.getInterpolatedU(0);
//		float sizeU = icon.getInterpolatedU(16) - minU;
//		float minV = icon.getInterpolatedV(0);
//		float sizeV = icon.getInterpolatedV(16) - minV;
//		float baseOffsetU = (16f/icon.getIconWidth())*.0005F;
//		float baseOffsetV = (16f/icon.getIconHeight())*.0005F;
//		for(Face face : object.faces)
//		{
//			float averageU = 0F;
//			float averageV = 0F;
//			if(face.textureCoordinates!=null && face.textureCoordinates.length>0)
//			{
//				for(int i=0; i<face.textureCoordinates.length; ++i)
//				{
//					averageU += face.textureCoordinates[i].u;
//					averageV += face.textureCoordinates[i].v;
//				}
//				averageU = averageU / face.textureCoordinates.length;
//				averageV = averageV / face.textureCoordinates.length;
//			}
//
//			TextureCoordinate[] oldUVs = new TextureCoordinate[face.textureCoordinates.length];
//			for(int v=0; v<face.vertices.length; ++v)
//			{
//				float offsetU, offsetV;
//				offsetU = baseOffsetU;
//				offsetV = baseOffsetV;
//				if (face.textureCoordinates[v].u > averageU)
//					offsetU = -offsetU;
//				if (face.textureCoordinates[v].v > averageV)
//					offsetV = -offsetV;
//
//				oldUVs[v] = face.textureCoordinates[v];
//				TextureCoordinate textureCoordinate = face.textureCoordinates[v];
//				face.textureCoordinates[v] = new TextureCoordinate(
//						minU + sizeU * (textureCoordinate.u+offsetU),
//						minV + sizeV * (textureCoordinate.v+offsetV)
//						);
//			}
//			face.addFaceForRender(ClientUtils.tes(),0);
//			for(int v=0; v<face.vertices.length; ++v)
//				face.textureCoordinates[v] = new TextureCoordinate(oldUVs[v].u,oldUVs[v].v);
//		}
//	}
//
//	public static void addFaceToWorldRender(Face face, Tessellator tes, BlockLightingInfo light, Matrix4 translationMatrix, Matrix4 rotationMatrix, boolean invert, float colR, float colG, float colB)
//	{
//		Vertex vertexCopy = new Vertex(0,0,0);
//		for(int i=0; i<face.vertices.length; ++i)
//		{
//			int target = !invert?i:(face.vertices.length-1-i);
//			int corner = (int)(target/(float)face.vertices.length*4);
//			Vertex vertex = face.vertices[target];
//			vertexCopy.x = vertex.x;
//			vertexCopy.y = vertex.y;
//			vertexCopy.z = vertex.z;
//			rotationMatrix.apply(vertexCopy);
//			translationMatrix.apply(vertexCopy);
//			if(light!=null)
//			{
//				tes.setBrightness(corner==0?light.brightnessTopLeft: corner==1?light.brightnessBottomLeft: corner==2?light.brightnessBottomRight: light.brightnessTopRight);
//				float r = corner==0?light.colorRedTopLeft: corner==1?light.colorRedBottomLeft: corner==2?light.colorRedBottomRight: light.colorRedTopRight;
//				float g = corner==0?light.colorGreenTopLeft: corner==1?light.colorGreenBottomLeft: corner==2?light.colorGreenBottomRight: light.colorGreenTopRight;
//				float b = corner==0?light.colorBlueTopLeft: corner==1?light.colorBlueBottomLeft: corner==2?light.colorBlueBottomRight: light.colorBlueTopRight;
//				tes.setColorOpaque_F(r, g, b);
//			}
//			else
//			{
//				tes.setBrightness(0xb000b0);
//				tes.setColorOpaque_F(colR,colG,colB);
//			}
//
//			if(face.textureCoordinates!=null && face.textureCoordinates.length>0)
//			{
//				TextureCoordinate textureCoordinate = face.textureCoordinates[target];
//				tes.addVertexWithUV(vertexCopy.x, vertexCopy.y, vertexCopy.z, textureCoordinate.u, textureCoordinate.v);
//			}
//			else
//			{
//				tes.addVertex(vertexCopy.x, vertexCopy.y, vertexCopy.z);
//			}
//		}
//	}
//
//
//	public static void renderItemIn2D(IIcon icon, double[] uv, int width, int height, float depth)
//	{
//		double uMin = icon.getInterpolatedU(uv[0]*16);
//		double uMax = icon.getInterpolatedU(uv[1]*16);
//		double vMin = icon.getInterpolatedV(uv[2]*16);
//		double vMax = icon.getInterpolatedV(uv[3]*16);
//
//		double w = width/16d/2;
//		double h = height/16d;
//		tes().startDrawingQuads();
//		tes().setNormal(0.0F, 0.0F, 1.0F);
//		tes().addVertexWithUV(-w, 0, 0.0D, uMin, vMax);
//		tes().addVertexWithUV( w, 0, 0.0D, uMax, vMax);
//		tes().addVertexWithUV( w, h, 0.0D, uMax, vMin);
//		tes().addVertexWithUV(-w, h, 0.0D, uMin, vMin);
//		tes().draw();
//		tes().startDrawingQuads();
//		tes().setNormal(0.0F, 0.0F, -1.0F);
//		tes().addVertexWithUV(-w, h, (0.0F - depth), uMin, vMin);
//		tes().addVertexWithUV( w, h, (0.0F - depth), uMax, vMin);
//		tes().addVertexWithUV( w, 0, (0.0F - depth), uMax, vMax);
//		tes().addVertexWithUV(-w, 0, (0.0F - depth), uMin, vMax);
//		tes().draw();
//		double f5 = 0.5F * (uMin - uMax) / (float)width;
//		double f6 = 0.5F * (vMax - vMin) / (float)height;
//		int k;
//		double f7;
//		double f8;
//		double f9;
//
//		tes().startDrawingQuads();
//		tes().setNormal(0.0F, 1.0F, 0.0F);
//		for(k=0; k<width; k++)
//		{
//			f7 = k/(double)width;
//			f8 = uMin + (uMax - uMin) * f7 - f5;
//			f9 = k/(double)icon.getIconWidth();
//			tes().addVertexWithUV(-w+f9, 0, -depth, f8, vMax);
//			tes().addVertexWithUV(-w+f9, 0, 0, f8, vMax);
//			tes().addVertexWithUV(-w+f9, h, 0, f8, vMin);
//			tes().addVertexWithUV(-w+f9, h, -depth, f8, vMin);
//		}
//		tes().draw();
//
//		tes().startDrawingQuads();
//		tes().setNormal(1.0F, 0.0F, 0.0F);
//		for(k=0; k<width; k++)
//		{
//			f7 = k/(double)width;
//			f8 = uMin + (uMax - uMin) * f7 - f5;
//			f9 = (k+1)/(double)icon.getIconWidth();
//			tes().addVertexWithUV(-w+f9, h, -depth, f8, vMin);
//			tes().addVertexWithUV(-w+f9, h, 0, f8, vMin);
//			tes().addVertexWithUV(-w+f9, 0, 0, f8, vMax);
//			tes().addVertexWithUV(-w+f9, 0, -depth, f8, vMax);
//		}
//		tes().draw();
//
//		tes().startDrawingQuads();
//		tes().setNormal(0.0F, 1.0F, 0.0F);
//		for (k = 0; k < height; ++k)
//		{
//			f7 = k / (double)height;
//			f8 = vMax + (vMin - vMax) * f7 - f6;
//			f9 = (k+1)/(double)icon.getIconHeight();
//			tes().addVertexWithUV(-w, f9, 0, uMin, f8);
//			tes().addVertexWithUV( w, f9, 0, uMax, f8);
//			tes().addVertexWithUV( w, f9, -depth, uMax, f8);
//			tes().addVertexWithUV(-w, f9,- depth, uMin, f8);
//		}
//		tes().draw();
//
//		tes().startDrawingQuads();
//		tes().setNormal(0.0F, -1.0F, 0.0F);
//		for (k = 0; k < height; ++k)
//		{
//			f7 = k / (double)height;
//			f8 = vMax + (vMin - vMax) * f7 - f6;
//			f9 = k/(double)icon.getIconHeight();
//			tes().addVertexWithUV( w, f9, 0, uMax, f8);
//			tes().addVertexWithUV(-w, f9, 0, uMin, f8);
//			tes().addVertexWithUV(-w, f9, -depth, uMin, f8);
//			tes().addVertexWithUV( w, f9, -depth, uMax, f8);
//		}
//		tes().draw();
//	}
//
//	public static void drawInventoryBlock(Block block, int metadata, RenderBlocks renderer)
//	{
//		Tessellator tes = tes();
//		GL11.glPushMatrix();
//		GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
//		GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
//		tes.startDrawingQuads();
//		tes.setNormal(0.0F, -1.0F, 0.0F);
//		renderer.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, renderer.overrideBlockTexture!=null?renderer.overrideBlockTexture: renderer.getBlockIconFromSideAndMetadata(block, 0, metadata));
//		tes.draw();
//		tes.startDrawingQuads();
//		tes.setNormal(0.0F, 1.0F, 0.0F);
//		renderer.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, renderer.overrideBlockTexture!=null?renderer.overrideBlockTexture: renderer.getBlockIconFromSideAndMetadata(block, 1, metadata));
//		tes.draw();
//		tes.startDrawingQuads();
//		tes.setNormal(0.0F, 0.0F, -1.0F);
//		renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.overrideBlockTexture!=null?renderer.overrideBlockTexture: renderer.getBlockIconFromSideAndMetadata(block, 2, metadata));
//		tes.draw();
//		tes.startDrawingQuads();
//		tes.setNormal(0.0F, 0.0F, 1.0F);
//		renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.overrideBlockTexture!=null?renderer.overrideBlockTexture: renderer.getBlockIconFromSideAndMetadata(block, 3, metadata));
//		tes.draw();
//		tes.startDrawingQuads();
//		tes.setNormal(-1.0F, 0.0F, 0.0F);
//		renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.overrideBlockTexture!=null?renderer.overrideBlockTexture: renderer.getBlockIconFromSideAndMetadata(block, 4, metadata));
//		tes.draw();
//		tes.startDrawingQuads();
//		tes.setNormal(1.0F, 0.0F, 0.0F);
//		renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.overrideBlockTexture!=null?renderer.overrideBlockTexture: renderer.getBlockIconFromSideAndMetadata(block, 5, metadata));
//		tes.draw();
//		GL11.glPopMatrix();
//	}
//Cheers boni =P
public static void drawBlockDamageTexture(Tessellator tessellatorIn, VertexBuffer worldRendererIn, Entity entityIn, float partialTicks, World world, Collection<BlockPos> blocks) {
    double d0 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double) partialTicks;
    double d1 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double) partialTicks;
    double d2 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double) partialTicks;
    TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
    // 0-10
    int progress = (int) (Minecraft.getMinecraft().playerController.curBlockDamageMP * 10f) - 1;
    if (progress < 0)
        return;
    renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    //preRenderDamagedBlocks BEGIN
    GlStateManager.tryBlendFuncSeparate(774, 768, 1, 0);
    GlStateManager.enableBlend();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 0.5F);
    GlStateManager.doPolygonOffset(-3.0F, -3.0F);
    GlStateManager.enablePolygonOffset();
    GlStateManager.alphaFunc(516, 0.1F);
    GlStateManager.enableAlpha();
    GlStateManager.pushMatrix();
    //preRenderDamagedBlocks END
    worldRendererIn.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRendererIn.setTranslation(-d0, -d1, -d2);
    //		worldRendererIn.markDirty();
    for (BlockPos blockpos : blocks) {
        double d3 = (double) blockpos.getX() - d0;
        double d4 = (double) blockpos.getY() - d1;
        double d5 = (double) blockpos.getZ() - d2;
        Block block = world.getBlockState(blockpos).getBlock();
        TileEntity te = world.getTileEntity(blockpos);
        boolean hasBreak = block instanceof BlockChest || block instanceof BlockEnderChest || block instanceof BlockSign || block instanceof BlockSkull;
        if (!hasBreak)
            hasBreak = te != null && te.canRenderBreaking();
        if (!hasBreak) {
            IBlockState iblockstate = world.getBlockState(blockpos);
            if (iblockstate.getMaterial() != Material.AIR) {
                TextureAtlasSprite textureatlassprite = destroyBlockIcons[progress];
                BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
                blockrendererdispatcher.renderBlockDamage(iblockstate, blockpos, textureatlassprite, world);
            }
        }
    }
    tessellatorIn.draw();
    worldRendererIn.setTranslation(0.0D, 0.0D, 0.0D);
    // postRenderDamagedBlocks BEGIN
    GlStateManager.disableAlpha();
    GlStateManager.doPolygonOffset(0.0F, 0.0F);
    GlStateManager.disablePolygonOffset();
    GlStateManager.enableAlpha();
    GlStateManager.depthMask(true);
    GlStateManager.popMatrix();
// postRenderDamagedBlocks END
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) TileEntity(net.minecraft.tileentity.TileEntity) TextureManager(net.minecraft.client.renderer.texture.TextureManager) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method createBakedBox.

public static Set<BakedQuad> createBakedBox(Vector3f from, Vector3f to, Matrix4 matrix, EnumFacing facing, Function<Vector3f[], Vector3f[]> vertexTransformer, Function<EnumFacing, TextureAtlasSprite> textureGetter, float[] colour) {
    HashSet quads = new HashSet();
    if (vertexTransformer == null)
        vertexTransformer = v -> v;
    Vector3f[] vertices = { new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, from.y, to.z), new Vector3f(to.x, from.y, to.z), new Vector3f(to.x, from.y, from.z) };
    TextureAtlasSprite sprite = textureGetter.apply(EnumFacing.DOWN);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.DOWN, facing), sprite, new double[] { from.x * 16, 16 - from.z * 16, to.x * 16, 16 - to.z * 16 }, colour, true));
    for (Vector3f v : vertices) v.setY(to.y);
    sprite = textureGetter.apply(EnumFacing.UP);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.UP, facing), sprite, new double[] { from.x * 16, from.z * 16, to.x * 16, to.z * 16 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(to.x, to.y, from.z), new Vector3f(to.x, from.y, from.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
    sprite = textureGetter.apply(EnumFacing.NORTH);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.NORTH, facing), sprite, new double[] { from.x * 16, 16 - to.y * 16, to.x * 16, 16 - from.y * 16 }, colour, false));
    for (Vector3f v : vertices) v.setZ(to.z);
    sprite = textureGetter.apply(EnumFacing.SOUTH);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.SOUTH, facing), sprite, new double[] { to.x * 16, 16 - to.y * 16, from.x * 16, 16 - from.y * 16 }, colour, true));
    vertices = new Vector3f[] { new Vector3f(from.x, to.y, to.z), new Vector3f(from.x, from.y, to.z), new Vector3f(from.x, from.y, from.z), new Vector3f(from.x, to.y, from.z) };
    sprite = textureGetter.apply(EnumFacing.WEST);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.WEST, facing), sprite, new double[] { to.z * 16, 16 - to.y * 16, from.z * 16, 16 - from.y * 16 }, colour, true));
    for (Vector3f v : vertices) v.setX(to.x);
    sprite = textureGetter.apply(EnumFacing.EAST);
    if (sprite != null)
        quads.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertexTransformer.apply(vertices)), Utils.rotateFacingTowardsDir(EnumFacing.EAST, facing), sprite, new double[] { from.z * 16, 16 - to.y * 16, to.z * 16, 16 - from.y * 16 }, colour, false));
    return quads;
}
Also used : net.minecraft.util(net.minecraft.util) Normal(net.minecraftforge.client.model.obj.OBJModel.Normal) ModelBox(net.minecraft.client.model.ModelBox) AttenuationType(net.minecraft.client.audio.ISound.AttenuationType) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) ModelRenderer(net.minecraft.client.model.ModelRenderer) I18n(net.minecraft.client.resources.I18n) Vec3i(net.minecraft.util.math.Vec3i) Vec3d(net.minecraft.util.math.Vec3d) Lib(blusunrize.immersiveengineering.api.Lib) GL11(org.lwjgl.opengl.GL11) IEProperties(blusunrize.immersiveengineering.api.IEProperties) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Quat4d(javax.vecmath.Quat4d) Vector3f(org.lwjgl.util.vector.Vector3f) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) net.minecraft.client.renderer(net.minecraft.client.renderer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) java.util(java.util) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SmartLightingQuad(blusunrize.immersiveengineering.client.models.SmartLightingQuad) Function(java.util.function.Function) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) IEFluid(blusunrize.immersiveengineering.common.util.IEFluid) net.minecraft.block(net.minecraft.block) Minecraft(net.minecraft.client.Minecraft) Nonnull(javax.annotation.Nonnull) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Entity(net.minecraft.entity.Entity) Utils(blusunrize.immersiveengineering.common.util.Utils) World(net.minecraft.world.World) TextFormatting(net.minecraft.util.text.TextFormatting) TextureMap(net.minecraft.client.renderer.texture.TextureMap) Timer(net.minecraft.util.Timer) BlockPos(net.minecraft.util.math.BlockPos) TextureManager(net.minecraft.client.renderer.texture.TextureManager) ModelBase(net.minecraft.client.model.ModelBase) IETileSound(blusunrize.immersiveengineering.common.util.sound.IETileSound) IBlockState(net.minecraft.block.state.IBlockState) GuiScreen(net.minecraft.client.gui.GuiScreen) FontRenderer(net.minecraft.client.gui.FontRenderer) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Material(net.minecraft.block.material.Material) TileEntity(net.minecraft.tileentity.TileEntity) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 3 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project ImmersiveEngineering by BluSunrize.

the class ConveyorVertical method modifyQuads.

@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
    if (tile != null && this.renderBottomBelt(tile, facing)) {
        TextureAtlasSprite sprite = ClientUtils.getSprite(isActive(tile) ? ConveyorBasic.texture_on : ConveyorBasic.texture_off);
        TextureAtlasSprite spriteColour = ClientUtils.getSprite(getColouredStripesTexture());
        boolean[] walls = { super.renderWall(tile, facing, 0), super.renderWall(tile, facing, 1) };
        baseModel.addAll(ModelConveyor.getBaseConveyor(facing, .875f, new Matrix4(facing), ConveyorDirection.HORIZONTAL, sprite, walls, new boolean[] { true, false }, spriteColour, getDyeColour()));
    }
    return baseModel;
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project ImmersiveEngineering by BluSunrize.

the class ConveyorSplit method modifyQuads.

@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
    TextureAtlasSprite tex_casing0 = ClientUtils.getSprite(texture_casing);
    Matrix4 matrix = new Matrix4(facing);
    float[] colour = { 1, 1, 1, 1 };
    Vector3f[] vertices = { new Vector3f(.0625f, .1875f, 0), new Vector3f(.0625f, .1875f, 1), new Vector3f(.9375f, .1875f, 1), new Vector3f(.9375f, .1875f, 0) };
    baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), EnumFacing.UP, tex_casing0, new double[] { 1, 16, 15, 0 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(.0625f, 0, 0), new Vector3f(.0625f, .1875f, 0), new Vector3f(.9375f, .1875f, 0), new Vector3f(.9375f, 0, 0) };
    baseModel.set(15, ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, ClientUtils.getSprite(ModelConveyor.rl_casing[1]), new double[] { 1, 16, 15, 13 }, colour, false));
    vertices = new Vector3f[] { new Vector3f(.0625f, .125f, 0), new Vector3f(.0625f, .1875f, 0), new Vector3f(.9375f, .1875f, 0), new Vector3f(.9375f, .125f, 0) };
    Vector3f[] vertices2 = new Vector3f[] { new Vector3f(.5f, .125f, 0), new Vector3f(.5f, .125f, .5f), new Vector3f(.5f, .1875f, .5f), new Vector3f(.5f, .1875f, 0) };
    Vector3f[] vertices3 = new Vector3f[] { new Vector3f(.5f, .125f, 0), new Vector3f(.5f, .125f, .5f), new Vector3f(.5f, .1875f, .5f), new Vector3f(.5f, .1875f, 0) };
    for (int i = 0; i < 8; i++) {
        for (int iv = 0; iv < vertices.length; iv++) {
            vertices[iv].setZ((i + 1) * .0625f);
            vertices2[iv].setX(vertices2[iv].getX() + .0625f);
            vertices3[iv].setX(vertices3[iv].getX() - .0625f);
        }
        double v = 16 - i;
        baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices), facing, tex_casing0, new double[] { 1, v - 1, 15, v }, colour, true));
        if (i < 7) {
            double u = 8 - i;
            baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices2), facing, tex_casing0, new double[] { u - 1, 16, u, 8 }, colour, true));
            baseModel.add(ClientUtils.createBakedQuad(DefaultVertexFormats.ITEM, ClientUtils.applyMatrixToVertices(matrix, vertices3), facing, tex_casing0, new double[] { u - 1, 16, u, 8 }, colour, false));
        }
    }
    return baseModel;
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with TextureAtlasSprite

use of net.minecraft.client.renderer.texture.TextureAtlasSprite in project ImmersiveEngineering by BluSunrize.

the class ModelConveyor method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState blockState, @Nullable EnumFacing side, long rand) {
    TileEntity tile = null;
    String key = "default";
    EnumFacing facing = EnumFacing.NORTH;
    if (blockState == null)
        key = conveyor != null ? ConveyorHandler.reverseClassRegistry.get(conveyor.getClass()).toString() : "immersiveengineering:conveyor";
    else {
        facing = blockState.getValue(IEProperties.FACING_ALL);
        if (blockState instanceof IExtendedBlockState) {
            IExtendedBlockState exState = (IExtendedBlockState) blockState;
            if (exState.getUnlistedNames().contains(BlockConveyor.ICONEYOR_PASSTHROUGH))
                conveyor = ((IExtendedBlockState) blockState).getValue(BlockConveyor.ICONEYOR_PASSTHROUGH);
            if (exState.getUnlistedNames().contains(IEProperties.TILEENTITY_PASSTHROUGH))
                tile = ((IExtendedBlockState) blockState).getValue(IEProperties.TILEENTITY_PASSTHROUGH);
            if (conveyor != null && tile != null)
                key = conveyor.getModelCacheKey(tile, facing);
        }
    }
    List<BakedQuad> cachedQuads = modelCache.get(key);
    if (cachedQuads != null)
        return Collections.synchronizedList(Lists.newArrayList(cachedQuads));
    else {
        cachedQuads = Collections.synchronizedList(Lists.newArrayList());
        Matrix4f facingMatrix = TRSRTransformation.getMatrix(facing);
        if (conveyor != null)
            facingMatrix = conveyor.modifyBaseRotationMatrix(facingMatrix, tile, facing);
        Matrix4 matrix = new Matrix4(facingMatrix);
        ConveyorDirection conDir = conveyor != null ? conveyor.getConveyorDirection() : ConveyorDirection.HORIZONTAL;
        boolean[] walls = conveyor != null && tile != null ? new boolean[] { conveyor.renderWall(tile, facing, 0), conveyor.renderWall(tile, facing, 1) } : new boolean[] { true, true };
        TextureAtlasSprite tex_conveyor = ClientUtils.mc().getTextureMapBlocks().getMissingSprite();
        TextureAtlasSprite tex_conveyor_colour = null;
        int colourStripes = -1;
        if (conveyor != null) {
            tex_conveyor = ClientUtils.getSprite(tile != null ? (conveyor.isActive(tile) ? conveyor.getActiveTexture() : conveyor.getInactiveTexture()) : conveyor.getActiveTexture());
            if ((colourStripes = conveyor.getDyeColour()) >= 0)
                tex_conveyor_colour = ClientUtils.getSprite(conveyor.getColouredStripesTexture());
        }
        cachedQuads.addAll(getBaseConveyor(facing, 1, matrix, conDir, tex_conveyor, walls, new boolean[] { true, true }, tex_conveyor_colour, colourStripes));
        if (conveyor != null)
            cachedQuads = conveyor.modifyQuads(cachedQuads, tile, facing);
        modelCache.put(key, cachedQuads);
        return Collections.synchronizedList(Lists.newArrayList(cachedQuads));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Matrix4f(javax.vecmath.Matrix4f) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Aggregations

TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)44 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)7 EnumFacing (net.minecraft.util.EnumFacing)7 ResourceLocation (net.minecraft.util.ResourceLocation)6 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)5 IBlockState (net.minecraft.block.state.IBlockState)5 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)5 TileEntity (net.minecraft.tileentity.TileEntity)5 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 Tessellator (net.minecraft.client.renderer.Tessellator)4 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 Vector3f (org.lwjgl.util.vector.Vector3f)4 HashMap (java.util.HashMap)3 Block (net.minecraft.block.Block)3 TextureManager (net.minecraft.client.renderer.texture.TextureManager)3 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)2 Utils (blusunrize.immersiveengineering.common.util.Utils)2 ImmutableList (com.google.common.collect.ImmutableList)2 Map (java.util.Map)2