|
| 1 | +/** |
| 2 | + * Animatium |
| 3 | + * The all-you-could-want legacy animations mod for modern minecraft versions. |
| 4 | + * Brings back animations from the 1.7/1.8 era and more. |
| 5 | + * <p> |
| 6 | + * Copyright (C) 2024-2025 lowercasebtw |
| 7 | + * Copyright (C) 2024-2025 mixces |
| 8 | + * Copyright (C) 2024-2025 Contributors to the project retain their copyright |
| 9 | + * <p> |
| 10 | + * This program is free software: you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU General Public License as published by |
| 12 | + * the Free Software Foundation, either version 3 of the License, or |
| 13 | + * (at your option) any later version. |
| 14 | + * <p> |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU General Public License for more details. |
| 19 | + * <p> |
| 20 | + * You should have received a copy of the GNU General Public License |
| 21 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | + */ |
| 23 | + |
| 24 | +package btw.mixces.animatium; |
| 25 | + |
| 26 | +import btw.mixces.animatium.util.MethUtils; |
| 27 | +import com.mojang.blaze3d.systems.RenderSystem; |
| 28 | +import com.mojang.blaze3d.vertex.DefaultVertexFormat; |
| 29 | +import com.mojang.blaze3d.vertex.VertexFormat; |
| 30 | +import net.minecraft.Util; |
| 31 | +import net.minecraft.client.renderer.RenderStateShard; |
| 32 | +import net.minecraft.client.renderer.RenderType; |
| 33 | +import net.minecraft.client.renderer.entity.ItemRenderer; |
| 34 | +import net.minecraft.util.TriState; |
| 35 | +import org.joml.Matrix4f; |
| 36 | + |
| 37 | +public class LegacyGlintType { |
| 38 | + public static final RenderType ITEM_GLINT_LAYER = makeItemGlintLayer(new RenderStateShard.TexturingStateShard( |
| 39 | + "legacy_glint_texturing", |
| 40 | + () -> setupItemGlintTexturing(-50.0F, false, 3000L), |
| 41 | + RenderSystem::resetTextureMatrix |
| 42 | + ), false); |
| 43 | + |
| 44 | + public static final RenderType ITEM_GLINT_2ND_LAYER = makeItemGlintLayer(new RenderStateShard.TexturingStateShard( |
| 45 | + "legacy_glint_texturing", |
| 46 | + () -> setupItemGlintTexturing(10.0F, true, 4873L), |
| 47 | + RenderSystem::resetTextureMatrix |
| 48 | + ), false); |
| 49 | + |
| 50 | + public static final RenderType ITEM_GLINT_TRANSLUCENT_LAYER = makeItemGlintLayer(new RenderStateShard.TexturingStateShard( |
| 51 | + "legacy_glint_texturing", |
| 52 | + () -> setupItemGlintTexturing(-50.0F, false, 3000L), |
| 53 | + RenderSystem::resetTextureMatrix |
| 54 | + ), true); |
| 55 | + |
| 56 | + public static final RenderType ITEM_GLINT_TRANSLUCENT_2ND_LAYER = makeItemGlintLayer(new RenderStateShard.TexturingStateShard( |
| 57 | + "legacy_glint_texturing", |
| 58 | + () -> setupItemGlintTexturing(10.0F, true, 4873L), |
| 59 | + RenderSystem::resetTextureMatrix |
| 60 | + ), true); |
| 61 | + |
| 62 | + public static final RenderType ENTITY_GLINT_LAYER = makeEntityGlintLayer(new RenderStateShard.TexturingStateShard( |
| 63 | + "legacy_glint_texturing", |
| 64 | + LegacyGlintType::setupEntityGlintTexturing, |
| 65 | + RenderSystem::resetTextureMatrix |
| 66 | + ), false); |
| 67 | + |
| 68 | + public static final RenderType ENTITY_ARMOR_GLINT_LAYER = makeEntityGlintLayer(new RenderStateShard.TexturingStateShard( |
| 69 | + "legacy_glint_texturing", |
| 70 | + LegacyGlintType::setupEntityGlintTexturing, |
| 71 | + RenderSystem::resetTextureMatrix |
| 72 | + ), true); |
| 73 | + |
| 74 | + private static RenderType makeItemGlintLayer(RenderStateShard.TexturingStateShard texturingStateShard, boolean translucent) { |
| 75 | + return RenderType.create( |
| 76 | + "legacy_glint" + (translucent ? "_translucent" : ""), |
| 77 | + DefaultVertexFormat.POSITION_TEX, |
| 78 | + VertexFormat.Mode.QUADS, |
| 79 | + 1536, |
| 80 | + RenderType.CompositeState.builder() |
| 81 | + .setShaderState(new RenderStateShard.ShaderStateShard(AnimatiumClient.renderTypeLegacyGlint)) |
| 82 | + .setTextureState( |
| 83 | + new RenderStateShard.TextureStateShard( |
| 84 | + ItemRenderer.ENCHANTED_GLINT_ITEM, |
| 85 | + TriState.DEFAULT, |
| 86 | + false |
| 87 | + ) |
| 88 | + ) |
| 89 | + .setWriteMaskState(RenderType.COLOR_WRITE) |
| 90 | + .setCullState(RenderType.CULL) |
| 91 | + .setDepthTestState(RenderType.EQUAL_DEPTH_TEST) |
| 92 | + .setTransparencyState(RenderType.GLINT_TRANSPARENCY) |
| 93 | + .setTexturingState(texturingStateShard) |
| 94 | + .setOutputState(translucent ? RenderType.ITEM_ENTITY_TARGET : RenderType.MAIN_TARGET) |
| 95 | + .createCompositeState(false) |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + private static RenderType makeEntityGlintLayer( |
| 100 | + RenderStateShard.TexturingStateShard texturingStateShard, boolean armor) { |
| 101 | + return RenderType.create("legacy_" + (armor ? "armor_" : "") + "entity_glint", |
| 102 | + DefaultVertexFormat.POSITION_TEX, |
| 103 | + VertexFormat.Mode.QUADS, |
| 104 | + 1536, |
| 105 | + RenderType.CompositeState.builder() |
| 106 | + .setShaderState(new RenderStateShard.ShaderStateShard(AnimatiumClient.renderTypeLegacyGlint)) |
| 107 | + .setTextureState( |
| 108 | + new RenderStateShard.TextureStateShard( |
| 109 | + ItemRenderer.ENCHANTED_GLINT_ITEM, // <=1.19.3 uses item glint texture, we will to |
| 110 | + TriState.DEFAULT, |
| 111 | + false |
| 112 | + ) |
| 113 | + ) |
| 114 | + .setWriteMaskState(RenderType.COLOR_WRITE) |
| 115 | + .setCullState(RenderType.CULL) |
| 116 | + .setDepthTestState(RenderType.EQUAL_DEPTH_TEST) |
| 117 | + .setTransparencyState(RenderType.GLINT_TRANSPARENCY) |
| 118 | + .setTexturingState(texturingStateShard) |
| 119 | + .setLayeringState(armor ? RenderType.VIEW_OFFSET_Z_LAYERING : RenderType.NO_LAYERING) |
| 120 | + .createCompositeState(false) |
| 121 | + ); |
| 122 | + } |
| 123 | + |
| 124 | + private static void setupItemGlintTexturing(float angle, boolean negative, long clampedTime) { |
| 125 | + float g = (Util.getMillis() % clampedTime) / (float) clampedTime / 8.0F; |
| 126 | + RenderSystem.setTextureMatrix( |
| 127 | + new Matrix4f() |
| 128 | + .scale(8.0F) |
| 129 | + .translate(negative ? -g : g, 0.0F, 0.0F) |
| 130 | + .rotateZ(MethUtils.toRadians(angle))); |
| 131 | + } |
| 132 | + |
| 133 | + private static void setupEntityGlintTexturing() { |
| 134 | + // TODO: Replace with proper <=1.14 translation/stuff |
| 135 | + // TEMPORARY |
| 136 | + // CODE FROM RenderStateShader#setupGlintTexturing(float) |
| 137 | + long l = (long) ((double) Util.getMillis() * 8.0); |
| 138 | + float g = (float) (l % 110000L) / 110000.0F; |
| 139 | + float h = (float) (l % 30000L) / 30000.0F; |
| 140 | + RenderSystem.setTextureMatrix( |
| 141 | + new Matrix4f() |
| 142 | + .translation(-g, h, 0.0F) |
| 143 | + .rotateZ((float) (Math.PI / 18)) |
| 144 | + .scale(0.16F)); |
| 145 | + } |
| 146 | +} |
0 commit comments