Skip to content

Commit 908c25f

Browse files
committed
Slowly move back to Java
1 parent 7c60ba5 commit 908c25f

File tree

76 files changed

+697
-767
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+697
-767
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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.command.AnimatiumCommand;
27+
import btw.mixces.animatium.config.AnimatiumConfig;
28+
import btw.mixces.animatium.packet.AnimatiumInfoPayloadPacket;
29+
import btw.mixces.animatium.packet.SetFeaturesPayloadPacket;
30+
import btw.mixces.animatium.util.Feature;
31+
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
32+
import net.fabricmc.api.ClientModInitializer;
33+
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
34+
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationConnectionEvents;
35+
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents;
36+
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
37+
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
38+
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
39+
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
40+
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
41+
import net.fabricmc.loader.api.FabricLoader;
42+
import net.fabricmc.loader.api.ModContainer;
43+
import net.minecraft.client.renderer.CoreShaders;
44+
import net.minecraft.client.renderer.ShaderDefines;
45+
import net.minecraft.client.renderer.ShaderProgram;
46+
import net.minecraft.resources.ResourceLocation;
47+
48+
import java.io.File;
49+
import java.io.IOException;
50+
import java.nio.file.Files;
51+
import java.util.ArrayList;
52+
import java.util.List;
53+
import java.util.Optional;
54+
55+
public class AnimatiumClient implements ClientModInitializer {
56+
// Settings
57+
public static boolean ENABLED = true;
58+
public static List<Feature> ENABLED_FEATURES = new ArrayList<>();
59+
public static boolean SHOULD_RELOAD_OVERLAY_TEXTURE = true;
60+
61+
// Info
62+
// TODO/NOTE: Find a better way/cleanup
63+
private static final ModContainer MOD_CONTAINER = FabricLoader.getInstance().getModContainer("animatium").orElseThrow(() -> new RuntimeException("Mod not found"));
64+
private static final String[] VERSION_PARTS = MOD_CONTAINER.getMetadata().getVersion().getFriendlyString().split("-");
65+
public static Double VERSION = Double.parseDouble(VERSION_PARTS[0]);
66+
public static Optional<String> DEVELOPMENT_VERSION = Optional.ofNullable(VERSION_PARTS[1]);
67+
68+
public static AnimatiumInfoPayloadPacket getInfoPayload() {
69+
return new AnimatiumInfoPayloadPacket(VERSION, DEVELOPMENT_VERSION);
70+
}
71+
72+
// Shaders
73+
public static ShaderProgram renderTypeLegacyGlint = new ShaderProgram(
74+
ResourceLocation.fromNamespaceAndPath("animatium", "core/rendertype_legacy_glint"),
75+
DefaultVertexFormat.POSITION_TEX,
76+
ShaderDefines.EMPTY
77+
);
78+
79+
static {
80+
CoreShaders.getProgramsToPreload().add(renderTypeLegacyGlint);
81+
}
82+
83+
// Config State
84+
private static final File STATE_FILE = new File(FabricLoader.getInstance().getGameDir().toFile(), "animatium_state.txt");
85+
86+
public static void loadEnabledState() throws IOException {
87+
if (STATE_FILE.exists()) {
88+
ENABLED = Files.readString(STATE_FILE.toPath()).equals("true");
89+
} else {
90+
if (!saveEnabledState()) {
91+
System.err.println("Failed to save enabled state...");
92+
}
93+
}
94+
}
95+
96+
public static boolean saveEnabledState() {
97+
boolean success = true;
98+
try {
99+
if (!STATE_FILE.exists()) {
100+
success = STATE_FILE.createNewFile();
101+
}
102+
103+
if (success) {
104+
Files.writeString(STATE_FILE.toPath(), String.valueOf(ENABLED));
105+
}
106+
} catch (Exception exception) {
107+
success = false;
108+
}
109+
110+
return success;
111+
}
112+
113+
// Other
114+
public static boolean isEnabled() {
115+
return ENABLED;
116+
}
117+
118+
@Override
119+
public void onInitializeClient() {
120+
AnimatiumConfig.load();
121+
try {
122+
loadEnabledState();
123+
} catch (IOException e) {
124+
ENABLED = true;
125+
System.err.println("Failed to load enabled state, defaulting to true...");
126+
}
127+
128+
// Packs
129+
ResourceManagerHelper.registerBuiltinResourcePack(ResourceLocation.parse("animatium:classic_textures"), MOD_CONTAINER, ResourcePackActivationType.DEFAULT_ENABLED);
130+
131+
// Commands
132+
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> AnimatiumCommand.register(dispatcher));
133+
134+
// Packets
135+
ClientLoginConnectionEvents.DISCONNECT.register((packet, client) -> ENABLED_FEATURES.clear());
136+
ClientConfigurationConnectionEvents.DISCONNECT.register((packet, client) -> ENABLED_FEATURES.clear());
137+
ClientPlayConnectionEvents.DISCONNECT.register((packet, client) -> ENABLED_FEATURES.clear());
138+
139+
PayloadTypeRegistry.playC2S().register(AnimatiumInfoPayloadPacket.Companion.getPAYLOAD_ID(), AnimatiumInfoPayloadPacket.Companion.getCODEC());
140+
PayloadTypeRegistry.playS2C().register(SetFeaturesPayloadPacket.Companion.getPAYLOAD_ID(), SetFeaturesPayloadPacket.Companion.getCODEC());
141+
ClientPlayNetworking.registerGlobalReceiver(SetFeaturesPayloadPacket.Companion.getPAYLOAD_ID(), (payload, context) -> context.client().schedule(() -> {
142+
ENABLED_FEATURES.clear();
143+
ENABLED_FEATURES.addAll(payload.getFeatures());
144+
}));
145+
}
146+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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

Comments
 (0)