Fix a few old MC versions compiling

This commit is contained in:
James Seibel
2025-10-11 12:04:41 -05:00
parent 4187eaf112
commit cb1a617b92
4 changed files with 60 additions and 9 deletions
+43 -6
View File
@@ -72,19 +72,22 @@ dependencies {
// runtimeOnly "javax.annotation:javax.annotation-api:1.3.2" // runtimeOnly "javax.annotation:javax.annotation-api:1.3.2"
// compileOnly "javax.annotation:javax.annotation-api:1.3.2" // compileOnly "javax.annotation:javax.annotation-api:1.3.2"
// modImplementation "javax.annotation:javax.annotation-api:1.3.2" // modImplementation "javax.annotation:javax.annotation-api:1.3.2"
// Fabric API // Fabric API
addModJar(fabricApi.module("fabric-api-base", rootProject.fabric_api_version)) addModJar(fabricApi.module("fabric-api-base", rootProject.fabric_api_version))
addModJar(fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version)) addModJar(fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version))
addModJar(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) if (buildVersionBefore(minecraft_version, "1.21.10"))
addModJar(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version))
else // > 1.21.10
addModJar(fabricApi.module("fabric-resource-loader-v1", rootProject.fabric_api_version))
addModJar(fabricApi.module("fabric-events-interaction-v0", rootProject.fabric_api_version)) addModJar(fabricApi.module("fabric-events-interaction-v0", rootProject.fabric_api_version))
addModJar(fabricApi.module("fabric-rendering-v1", rootProject.fabric_api_version)) // TODO: Remove this as it is only needed in 1 line (FabricClientProxy) addModJar(fabricApi.module("fabric-rendering-v1", rootProject.fabric_api_version))
addModJar(fabricApi.module("fabric-networking-api-v1", rootProject.fabric_api_version)) addModJar(fabricApi.module("fabric-networking-api-v1", rootProject.fabric_api_version))
addModJar(fabricApi.module("fabric-entity-events-v1", rootProject.fabric_api_version)) addModJar(fabricApi.module("fabric-entity-events-v1", rootProject.fabric_api_version))
if (minecraft_version >= "1.19.2") if (buildVersionBefore(minecraft_version, "1.19.2"))
addModJar(fabricApi.module("fabric-command-api-v2", rootProject.fabric_api_version))
else // < 1.19.2
addModJar(fabricApi.module("fabric-command-api-v1", rootProject.fabric_api_version)) addModJar(fabricApi.module("fabric-command-api-v1", rootProject.fabric_api_version))
else
addModJar(fabricApi.module("fabric-command-api-v2", rootProject.fabric_api_version))
// used by mod menu in MC 1.20.6+ // used by mod menu in MC 1.20.6+
addModJar(fabricApi.module("fabric-screen-api-v1", rootProject.fabric_api_version)) addModJar(fabricApi.module("fabric-screen-api-v1", rootProject.fabric_api_version))
@@ -143,6 +146,40 @@ dependencies {
} }
} }
private static boolean buildVersionBefore(String minecraft_version, String compareVersion)
{
int sortValue = sortSemanticVersionOldestToNewest(minecraft_version, compareVersion);
return sortValue == -1;
}
/**
* input format: "major.minor.patch"
* needed so we can sort versions with different length strings
* IE: 1.21.1 should come before 1.21.10
*/
private static int sortSemanticVersionOldestToNewest(String version1, String version2)
{
String[] parts1 = version1.split("\\.");
String[] parts2 = version2.split("\\.");
int major1 = Integer.parseInt(parts1[0]);
int major2 = Integer.parseInt(parts2[0]);
if (major1 != major2)
{
return Integer.compare(major1, major2);
}
int minor1 = Integer.parseInt(parts1[1]);
int minor2 = Integer.parseInt(parts2[1]);
if (minor1 != minor2)
{
return Integer.compare(minor1, minor2);
}
int patch1 = Integer.parseInt(parts1[2]);
int patch2 = Integer.parseInt(parts2[2]);
return Integer.compare(patch1, patch2);
}
task deleteResources(type: Delete) { task deleteResources(type: Delete) {
delete file("build/resources/main") delete file("build/resources/main")
@@ -290,7 +290,7 @@ public class FabricClientProxy implements AbstractModInitializer.IEventProxy
#if MC_VER < MC_1_21_6 #if MC_VER < MC_1_21_6
// rendered in MixinLevelRenderer // rendered in MixinLevelRenderer
#else #else
ClientApi.INSTANCE.renderDeferredLodsForShaders(ClientLevelWrapper.getWrapper(); ClientApi.INSTANCE.renderDeferredLodsForShaders();
#endif #endif
this.clientApi.renderFadeTransparent(); this.clientApi.renderFadeTransparent();
@@ -30,6 +30,20 @@ import net.minecraft.client.renderer.RenderType;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
#elif MC_VER < MC_1_21_10
import com.mojang.blaze3d.buffers.GpuBufferSlice;
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
import com.mojang.blaze3d.resource.GraphicsResourceAllocator;
import net.minecraft.client.Camera;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.renderer.chunk.ChunkSectionsToRender;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.util.profiling.ProfilerFiller;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import org.joml.Vector4f;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
#else #else
import com.mojang.blaze3d.buffers.GpuBufferSlice; import com.mojang.blaze3d.buffers.GpuBufferSlice;
import com.mojang.blaze3d.framegraph.FrameGraphBuilder; import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
@@ -164,7 +178,7 @@ public class MixinLevelRenderer
#if MC_VER < MC_1_21_6 #if MC_VER < MC_1_21_10
// rendering handled via Fabric Api render event // rendering handled via Fabric Api render event
#else #else
@Inject(at = @At("HEAD"), method = "prepareChunkRenders") @Inject(at = @At("HEAD"), method = "prepareChunkRenders")
+1 -1
View File
@@ -11,7 +11,7 @@ builds_for=fabric,neoforge
netty_version=4.1.97.Final netty_version=4.1.97.Final
# Fabric loader # Fabric loader
fabric_loader_version=0.17.2 fabric_loader_version=0.17.3
fabric_api_version=0.135.0+1.21.10 fabric_api_version=0.135.0+1.21.10
modmenu_version=16.0.0-rc.1 modmenu_version=16.0.0-rc.1
starlight_version_fabric= starlight_version_fabric=