protected virtual void RenderItem(Item item, float x, float y, float scale) { var model = JsonModelLoader.GetModelForItem(item.UnlocalizedName); if (model?.SlotTexture == null) { return; } Vector2 unit = new Vector2(1f / SharpCraft.Instance.ClientSize.Width, 1f / SharpCraft.Instance.ClientSize.Height); float width = 16; float height = 16; float scaledWidth = 16 * scale; float scaledHeight = 16 * scale; float posX = x + scaledWidth / 2; float posY = -y - scaledHeight / 2; Vector2 pos = new Vector2(posX, posY).Ceiling() * unit; Matrix4 mat = MatrixHelper.CreateTransformationMatrix(pos * 2 - Vector2.UnitX + Vector2.UnitY, scale * new Vector2(width, height) * unit); _item.Bind(); Shader.Bind(); Shader.SetMatrix4("transformationMatrix", mat); Shader.SetVector2("UVmin", model.SlotTexture.UVMin); Shader.SetVector2("UVmax", model.SlotTexture.UVMax); GL.BindTexture(TextureTarget.Texture2D, JsonModelLoader.TextureItems); _item.RawModel.Render(); _item.Unbind(); }
public override void Render(float partialTicks) { Vector3 partialPos = LastPos + (Pos - LastPos) * partialTicks; float partialTime = _ticksLast + (_ticks - _ticksLast) * partialTicks; if (_stack == null || _stack.IsEmpty) { return; } float offY = (float)((Math.Sin(partialTime / 90f * MathHelper.TwoPi) + 1) / 16); Vector3 vec = Vector3.One * 0.5f; Vector3 pos = partialPos - (Vector3.UnitX * 0.125f + Vector3.UnitZ * 0.125f) + Vector3.UnitY * offY; Matrix4 rot = Matrix4.CreateRotationY(partialTime / 90f * MathHelper.TwoPi); Matrix4 t2 = Matrix4.CreateTranslation(-vec); if (_stack.Item is ItemBlock itemBlock) { ModelBlock model = itemBlock.Block.GetState(_stack.Meta).Model; if (model?.RawModel == null) { return; } Shader.Bind(); Shader.SetFloat("fogDistance", SharpCraft.Instance.WorldRenderer.RenderDistance); GL.BindVertexArray(model.RawModel.VaoID); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.EnableVertexAttribArray(2); GL.BindTexture(TextureTarget.Texture2D, JsonModelLoader.TextureBlocks); int itemsToRender = 1; if (_stack.Count > 1) { itemsToRender = 2; } if (_stack.Count >= 32 * 4) { itemsToRender = 3; } if (_stack.Count == 64 * 4) { itemsToRender = 4; } for (int i = 0; i < itemsToRender; i++) { Vector3 posO = Vector3.One * (i / 8f); Matrix4 s = Matrix4.CreateScale(0.25f); Matrix4 t = Matrix4.CreateTranslation(pos + vec * 0.25f); Matrix4 t3 = Matrix4.CreateTranslation(posO); Matrix4 mat = t3 * t2 * (rot * s) * t; Shader.SetMatrix4("transformationMatrix", mat); model.RawModel.Render(); } GL.BindVertexArray(0); GL.DisableVertexAttribArray(0); GL.DisableVertexAttribArray(1); GL.DisableVertexAttribArray(2); Shader.Unbind(); } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); GL.Disable(EnableCap.CullFace); ModelItem model = JsonModelLoader.GetModelForItem(_stack.Item); if (model?.RawModel == null) { return; } Shader.Bind(); GL.BindVertexArray(model.RawModel.VaoID); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.EnableVertexAttribArray(2); GL.BindTexture(TextureTarget.Texture2D, JsonModelLoader.TextureItems); int itemsToRender = 1; if (_stack.Count > 1) { itemsToRender = 2; } if (_stack.Count >= 32 * 4) { itemsToRender = 3; } if (_stack.Count == 64 * 4) { itemsToRender = 4; } for (int i = 0; i < itemsToRender; i++) { Vector3 posO = Vector3.One * (i / 8f); Matrix4 s = Matrix4.CreateScale(0.35f); Matrix4 t = Matrix4.CreateTranslation(pos + vec * 0.35f); Matrix4 t3 = Matrix4.CreateTranslation(posO); Matrix4 mat = t3 * t2 * (rot * s) * t; Shader.SetMatrix4("transformationMatrix", mat); model.RawModel.Render(); } GL.BindVertexArray(0); GL.DisableVertexAttribArray(0); GL.DisableVertexAttribArray(1); GL.DisableVertexAttribArray(2); Shader.Unbind(); GL.Enable(EnableCap.CullFace); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } }
public override void Render(float partialTicks) { float partialTime = _ticksLast + (_ticks - _ticksLast) * partialTicks; var grid = 1 / 4f; var gap = 1 / 16f; for (int y = 0; y < _grid.GetLength(1); y++) { for (int x = 0; x < _grid.GetLength(0); x++) { var stack = _grid[x, y]; var offX = grid * x; var offZ = grid * y; var offsetX = (x + 1) * gap; var offsetY = (y + 1) * gap; if (stack != null && !stack.IsEmpty) { if (stack.Item is ItemBlock ib) { var model = ib.Block.GetState(stack.Meta).Model;//JsonModelLoader.GetModelForBlock(ib.Block)); var mat = Matrix4.CreateTranslation(_pos.X + offX + offsetX, _pos.Y + 1, _pos.Z + offZ + offsetY); var scale = Matrix4.CreateScale(grid); GL.BindTexture(TextureTarget.Texture2D, JsonModelLoader.TextureBlocks); model.Bind(); model.Shader.SetMatrix4("transformationMatrix", scale * mat); model.RawModel.Render(); model.Unbind(); } else { var model = JsonModelLoader.GetModelForItem(stack.Item); var rot = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(90)); var mat = rot * Matrix4.CreateTranslation(_pos.X + offX + offsetX + grid, _pos.Y + 1, _pos.Z + offZ + offsetY); var scale = Matrix4.CreateScale(grid); GL.BindTexture(TextureTarget.Texture2D, JsonModelLoader.TextureItems); model.Bind(); model.Shader.SetMatrix4("transformationMatrix", scale * mat); model.RawModel.Render(); model.Unbind(); } } } } if (_product != null && !_product.IsEmpty) { float offY = (float)((Math.Sin(partialTime / 90f * MathHelper.TwoPi) + 1) / 16); var rot = Matrix4.CreateRotationY(partialTime / 90f * MathHelper.TwoPi); if (_product.Item is ItemBlock ib) { var mat = Matrix4.CreateTranslation(_pos.X + 0.5f, _pos.Y + 1.5f + offY, _pos.Z + 0.5f); var scale = Matrix4.CreateTranslation(Vector3.One * -0.5f) * Matrix4.CreateScale(0.35f); var model = ib.Block.GetState(_product.Meta).Model; GL.BindTexture(TextureTarget.Texture2D, JsonModelLoader.TextureBlocks); model.Bind(); model.Shader.SetMatrix4("transformationMatrix", scale * rot * mat); model.RawModel.Render(); model.Unbind(); } else { var mat = Matrix4.CreateTranslation(_pos.X + 0.5f, _pos.Y + 1.55f + offY, _pos.Z + 0.5f); var scale = Matrix4.CreateTranslation(Vector3.One * -0.5f) * Matrix4.CreateScale(0.475f); var model = JsonModelLoader.GetModelForItem(_product.Item); GL.BindTexture(TextureTarget.Texture2D, JsonModelLoader.TextureItems); model.Bind(); model.Shader.SetMatrix4("transformationMatrix", scale * rot * mat); model.RawModel.Render(); model.Unbind(); } } }