|
| 1 | +/* |
| 2 | + * This program is free software; you can redistribute it and/or |
| 3 | + * modify it under the terms of the GNU Lesser General Public |
| 4 | + * License as published by the Free Software Foundation; either |
| 5 | + * version 3 of the License, or (at your option) any later version. |
| 6 | + * |
| 7 | + * This program is distributed in the hope that it will be useful, |
| 8 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 10 | + * Lesser General Public License for more details. |
| 11 | + * |
| 12 | + * You should have received a copy of the GNU Lesser General Public License |
| 13 | + * along with this program; if not, write to the Free Software Foundation, |
| 14 | + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 15 | + * |
| 16 | + * For more information, see the LICENSE file. |
| 17 | + */ |
| 18 | + |
| 19 | +package io.github.axolotlclient.oldanimations.util; |
| 20 | + |
| 21 | +import net.minecraft.client.render.platform.GlStateManager; |
| 22 | +import net.minecraft.client.render.texture.TextureAtlas; |
| 23 | +import net.minecraft.client.render.texture.TextureManager; |
| 24 | +import net.minecraft.client.render.vertex.BufferBuilder; |
| 25 | +import net.minecraft.client.render.vertex.DefaultVertexFormat; |
| 26 | +import net.minecraft.client.render.vertex.Tesselator; |
| 27 | +import net.minecraft.resource.Identifier; |
| 28 | + |
| 29 | +/** The previous 1.7 GUI overlay, with both quads submitted in one draw. */ |
| 30 | +public final class GuiGlintRenderer { |
| 31 | + private GuiGlintRenderer() { |
| 32 | + } |
| 33 | + |
| 34 | + public static void render(TextureManager textures, Identifier glint, long time) { |
| 35 | + GlStateManager.depthMask(false); |
| 36 | + GlStateManager.depthFunc(518); |
| 37 | + GlStateManager.disableLighting(); |
| 38 | + GlStateManager.blendFuncSeparate(772, 1, 0, 0); |
| 39 | + textures.bind(glint); |
| 40 | + GlStateManager.pushMatrix(); |
| 41 | + try { |
| 42 | + GlStateManager.scalef(0.5F, 0.5F, 0.5F); |
| 43 | + GlStateManager.translatef(0.0F, -0.25F, 0.0F); |
| 44 | + Tesselator tesselator = Tesselator.getInstance(); |
| 45 | + BufferBuilder buffer = tesselator.getBuffer(); |
| 46 | + buffer.begin(7, DefaultVertexFormat.POSITION_TEX_COLOR); |
| 47 | + appendQuad(buffer, (float) (time % 3000L) / 3000.0F, 4.0F); |
| 48 | + appendQuad(buffer, (float) (time % 4873L) / 4873.0F, -1.0F); |
| 49 | + tesselator.end(); |
| 50 | + } finally { |
| 51 | + GlStateManager.popMatrix(); |
| 52 | + GlStateManager.blendFuncSeparate(770, 771, 1, 0); |
| 53 | + GlStateManager.enableLighting(); |
| 54 | + GlStateManager.depthFunc(515); |
| 55 | + GlStateManager.depthMask(true); |
| 56 | + textures.bind(TextureAtlas.BLOCKS_LOCATION); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + private static void appendQuad(BufferBuilder buffer, float speed, float skew) { |
| 61 | + // Same positions, UVs and color as the removed GlintQuadModel, without |
| 62 | + // allocating a model, vertex arrays or lists for each overlay pass. |
| 63 | + float dimension = 20.0F / 256.0F; |
| 64 | + vertex(buffer, -0.5F, -0.25F, speed + dimension * skew, dimension); |
| 65 | + vertex(buffer, 0.5F, -0.25F, speed + dimension + dimension * skew, dimension); |
| 66 | + vertex(buffer, 0.5F, 0.75F, speed + dimension, 0.0F); |
| 67 | + vertex(buffer, -0.5F, 0.75F, speed, 0.0F); |
| 68 | + } |
| 69 | + |
| 70 | + private static void vertex(BufferBuilder buffer, float x, float y, float u, float v) { |
| 71 | + buffer.vertex(x, y, 0.0F).texture(u, v).color(128, 64, 204, 255).nextVertex(); |
| 72 | + } |
| 73 | +} |
0 commit comments