From 2480fe0d862fa4fced46de71fcf9192b6c9478e9 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 29 Mar 2025 10:40:36 -0500 Subject: [PATCH] Add basic MC 1.21.5 rendering (block colors and world gen broken) --- build.gradle | 2 +- .../common/wrappers/VersionConstants.java | 2 + .../minecraft/MinecraftGLWrapper.java | 9 +- .../minecraft/MinecraftRenderWrapper.java | 89 ++++++++++++++++++- .../common/wrappers/misc/LightMapWrapper.java | 8 ++ .../mimicObject/DhLitWorldGenRegion.java | 8 ++ coreSubProjects | 2 +- .../mixins/client/MixinLightTexture.java | 26 ++++-- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- versionProperties/1.21.5.properties | 55 ++++++++++++ 11 files changed, 191 insertions(+), 14 deletions(-) create mode 100644 versionProperties/1.21.5.properties diff --git a/build.gradle b/build.gradle index acf0d7a01..ccea89f55 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ plugins { id "systems.manifold.manifold-gradle-plugin" version "0.0.2-alpha" // Architectury is used here only as a replacement for forge's own loom - id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.9-SNAPSHOT" apply false } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/VersionConstants.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/VersionConstants.java index 6ab219b34..88f81c665 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/VersionConstants.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/VersionConstants.java @@ -72,6 +72,8 @@ public class VersionConstants implements IVersionConstants return "1.21.3"; #elif MC_VER == MC_1_21_4 return "1.21_4"; + #elif MC_VER == MC_1_21_5 + return "1.21_5"; #else ERROR MC version constant missing #endif diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftGLWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftGLWrapper.java index 3136b3b43..73c109806 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftGLWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftGLWrapper.java @@ -19,7 +19,11 @@ package com.seibel.distanthorizons.common.wrappers.minecraft; +#if MC_VER < MC_1_21_5 import com.mojang.blaze3d.platform.GlStateManager; +#elif MC_VER == MC_1_21_5 +import com.mojang.blaze3d.opengl.GlStateManager; +#endif import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftGLWrapper; @@ -148,7 +152,10 @@ public class MinecraftGLWrapper implements IMinecraftGLWrapper public void glBlendFunc(int sfactor, int dfactor) { GL32.glBlendFunc(sfactor, dfactor); - GlStateManager._blendFunc(sfactor, dfactor); + + #if MC_VER < MC_1_21_5 + GlStateManager._blendFunc(sfactor, dfactor); + #endif } /** @see GL32#glBlendFuncSeparate */ @Override diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java index 160267c8f..2f1a36446 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/minecraft/MinecraftRenderWrapper.java @@ -71,6 +71,10 @@ import net.minecraft.world.phys.Vec3; import org.apache.logging.log4j.Logger; import org.joml.Vector4f; +#if MC_VER >= MC_1_21_5 +import com.mojang.blaze3d.opengl.GlTexture; +import org.lwjgl.opengl.GL32; +#endif /** * A singleton that contains everything @@ -102,8 +106,15 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper */ public int finalLevelFrameBufferId = -1; + public boolean colorTextureCastFailLogged = false; + public boolean depthTextureCastFailLogged = false; + + //=========// + // methods // + //=========// + @Override public Vec3f getLookAtVector() { @@ -250,6 +261,16 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper private RenderTarget getRenderTarget() { return MC.getMainRenderTarget(); } + @Override + public boolean mcRendersToFrameBuffer() + { + #if MC_VER < MC_1_21_5 + return true; + #else + return false; + #endif + } + @Override public int getTargetFrameBuffer() { @@ -259,27 +280,87 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper return this.finalLevelFrameBufferId; } + #if MC_VER < MC_1_21_5 return this.getRenderTarget().frameBufferId; + #else + // MC renders to a texture and then directly to the default FBO now + // we need to draw to their texture instead of the FBO + return 0; // 0 is the ID for the default frame buffer + #endif } @Override public void clearTargetFrameBuffer() { this.finalLevelFrameBufferId = -1; } @Override - public int getDepthTextureId() { return this.getRenderTarget().getDepthTextureId(); } + public int getDepthTextureId() + { + #if MC_VER < MC_1_21_5 + return this.getRenderTarget().getDepthTextureId(); + #else + try + { + GlTexture glTexture = (GlTexture) this.getRenderTarget().getDepthTexture(); + if (glTexture == null) + { + // shouldn't happen, but just in case + return 0; + } + + return glTexture.glId(); + } + catch (ClassCastException e) + { + // only log this error once per session + if (!this.depthTextureCastFailLogged) + { + this.depthTextureCastFailLogged = true; + LOGGER.error("Unable to cast render Target depth texture to GlTexture. MC or a rendering mod may have changed the object type.", e); + } + return 0; + } + #endif + } @Override - public int getColorTextureId() { return this.getRenderTarget().getColorTextureId(); } + public int getColorTextureId() + { + #if MC_VER < MC_1_21_5 + return this.getRenderTarget().getColorTextureId(); + #else + try + { + GlTexture glTexture = (GlTexture) this.getRenderTarget().getColorTexture(); + if (glTexture == null) + { + // shouldn't happen, but just in case + return 0; + } + + return glTexture.glId(); + } + catch (ClassCastException e) + { + // only log this error once per session + if (!this.colorTextureCastFailLogged) + { + this.colorTextureCastFailLogged = true; + LOGGER.error("Unable to cast render Target color texture to GlTexture. MC or a rendering mod may have changed the object type.", e); + } + return 0; + } + #endif + } @Override public int getTargetFrameBufferViewportWidth() { - return getRenderTarget().viewWidth; + return this.getRenderTarget().viewWidth; } @Override public int getTargetFrameBufferViewportHeight() { - return getRenderTarget().viewHeight; + return this.getRenderTarget().viewHeight; } @Override diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/LightMapWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/LightMapWrapper.java index f7e61ea51..c3cf971a6 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/LightMapWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/LightMapWrapper.java @@ -52,6 +52,7 @@ public class LightMapWrapper implements ILightMapWrapper public void uploadLightmap(NativeImage image) { + #if MC_VER < MC_1_21_5 int currentTexture = GLMC.getActiveTexture(); if (this.textureId == 0) { @@ -69,13 +70,20 @@ public class LightMapWrapper implements ILightMapWrapper { GLMC.glBindTexture(currentTexture); } + #else + throw new UnsupportedOperationException("setLightmapId should be used for MC versions after 1.21.5"); // TODO that MC version number is wrong, when did we actually start using setLightmapId()? + #endif } private void createLightmap(NativeImage image) { + #if MC_VER < MC_1_21_5 this.textureId = GLMC.glGenTextures(); GLMC.glBindTexture(this.textureId); GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, image.format().glFormat(), image.getWidth(), image.getHeight(), 0, image.format().glFormat(), GL32.GL_UNSIGNED_BYTE, (ByteBuffer) null); + #else + throw new UnsupportedOperationException("setLightmapId should be used for MC versions after 1.21.5"); // TODO that MC version number is wrong, when did we actually start using setLightmapId()? + #endif } public void setLightmapId(int minecraftLightmapTetxureId) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/mimicObject/DhLitWorldGenRegion.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/mimicObject/DhLitWorldGenRegion.java index fe82337d5..475e97889 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/mimicObject/DhLitWorldGenRegion.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/mimicObject/DhLitWorldGenRegion.java @@ -229,8 +229,16 @@ public class DhLitWorldGenRegion extends WorldGenRegion { ChunkAccess chunkAccess = this.getChunk(blockPos); if (chunkAccess instanceof LevelChunk) + { return true; + } + + #if MC_VER < MC_1_21_5 chunkAccess.setBlockState(blockPos, blockState, /*isBlockMoving*/false); + #else + chunkAccess.setBlockState(blockPos, blockState, /*flags*/0); + #endif + // This is for post ticking for water on gen and stuff like that. Not enabled // for now. // if (blockState.hasPostProcess(this, blockPos)) diff --git a/coreSubProjects b/coreSubProjects index 1234ff4d2..91e17c420 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 1234ff4d286d22a5fd007d8773a305fda33b5ee2 +Subproject commit 91e17c420a567af775833a21d366f895e0cbe954 diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java index ab70f9ae5..a38b73ba8 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinLightTexture.java @@ -34,21 +34,34 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; #if MC_VER < MC_1_21_3 import com.mojang.blaze3d.platform.NativeImage; -#else +#elif MC_VER < MC_1_21_5 import com.mojang.blaze3d.pipeline.TextureTarget; +#else +import com.mojang.blaze3d.opengl.GlTexture; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.textures.GpuTexture; #endif @Mixin(LightTexture.class) public class MixinLightTexture { - @Shadow - @Final + #if MC_VER < MC_1_21_3 + @Shadow + @Final private NativeImage lightPixels; - #else + #elif MC_VER < MC_1_21_5 + @Shadow + @Final private TextureTarget target; + #else + @Shadow + @Final + private GpuTexture texture; #endif + + @Inject(method = "updateLightTexture(F)V", at = @At("RETURN")) public void updateLightTexture(float partialTicks, CallbackInfo ci) { @@ -63,8 +76,11 @@ public class MixinLightTexture #if MC_VER < MC_1_21_3 MinecraftRenderWrapper.INSTANCE.updateLightmap(this.lightPixels, clientLevel); - #else + #elif MC_VER < MC_1_21_5 MinecraftRenderWrapper.INSTANCE.setLightmapId(this.target.getColorTextureId(), clientLevel); + #else + GlTexture glTexture = (GlTexture) this.texture; + MinecraftRenderWrapper.INSTANCE.setLightmapId(glTexture.glId(), clientLevel); #endif } diff --git a/gradle.properties b/gradle.properties index a0a25fa14..ea51c0ddc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -51,7 +51,7 @@ versionStr= # This defines what MC version Intellij will use for the preprocessor # and what version is used automatically by build and run commands -mcVer=1.21.4 +mcVer=1.21.5 # Defines the maximum amount of memory Minecraft is allowed when run in a development environment #minecraftMemoryJavaArg="-Xmx4G" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9355b4155..94113f200 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/versionProperties/1.21.5.properties b/versionProperties/1.21.5.properties new file mode 100644 index 000000000..3d351f2f4 --- /dev/null +++ b/versionProperties/1.21.5.properties @@ -0,0 +1,55 @@ +# 1.21.4 version +java_version=21 +minecraft_version=1.21.5 +parchment_version=1.21:2024.07.28 +compatible_minecraft_versions=["1.21.5"] +accessWidenerVersion=1_21_4 +builds_for=fabric +# forge is broken due to gradle/build script issues + +# Netty +netty_version=4.1.97.Final + +# Fabric loader +fabric_loader_version=0.16.10 +fabric_api_version=0.119.5+1.21.5 + modmenu_version=14.0.0-rc.2 + starlight_version_fabric= + phosphor_version_fabric= + lithium_version= + sodium_version=mc1.21.5-0.6.11-fabric + iris_version=1.8.10+1.21.5-fabric + bclib_version= + immersive_portals_version= + canvas_version= + + fabric_incompatibility_list={ } + fabric_recommend_list={} + + # Fabric mod run + # 0 = Don't enable and don't run + # 1 = Can be referenced in code but doesn't run + # 2 = Can be referenced in code and runs in client + enable_starlight=0 + enable_phosphor=0 + enable_sodium=1 + enable_lithium=0 + enable_iris=1 + enable_bclib=0 + enable_immersive_portals=0 + enable_canvas=0 + +# (Neo)Forge loader +forge_version= +neoforge_version=21.5.0-beta + # (Neo)Forge mod versions + starlight_version_forge= + terraforged_version= + + # (Neo)Forge mod run + # 0 = Don't enable and don't run + # 1 = Can be referenced in code but doesn't run + # 2 = Can be referenced in code and runs in client + enable_starlight_forge=0 + enable_terraforged=0 + enable_terrafirmacraft=0