From 0c3ed9bbb2640490ba6c866693e89b9e893b8dc2 Mon Sep 17 00:00:00 2001 From: ev chang Date: Mon, 1 Jul 2024 06:02:04 +0900 Subject: [PATCH] Fix entities disappearing with MonkeyBlur --- build.gradle.kts | 13 ++++-------- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- root.gradle.kts | 4 ++-- settings.gradle.kts | 2 +- .../polyblur/blurs/monkey/MonkeyBlur.java | 14 +++++++++++-- .../polyblur/mixin/RenderGlobalMixin.java | 19 ++++++++++++++++++ .../mixin/SBAEntityOutlineRendererMixin.java | 20 +++++++++++++++++++ .../SkyHanniEntityOutlineRendererMixin.java | 20 +++++++++++++++++++ .../assets/polyblur/shaders/monkeyblur.frag | 6 +++--- src/main/resources/mixins.polyblur.json | 5 ++++- 11 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/polyfrost/polyblur/mixin/RenderGlobalMixin.java create mode 100644 src/main/java/org/polyfrost/polyblur/mixin/SBAEntityOutlineRendererMixin.java create mode 100644 src/main/java/org/polyfrost/polyblur/mixin/SkyHanniEntityOutlineRendererMixin.java diff --git a/build.gradle.kts b/build.gradle.kts index 3ffc0ea..d4c488b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ plugins { id("org.polyfrost.defaults.java") id("org.polyfrost.defaults.loom") id("com.github.johnrengelman.shadow") - id("net.kyori.blossom") version "1.3.1" + id("net.kyori.blossom") version "1.3.2" id("signing") java } @@ -23,11 +23,6 @@ val mod_version: String by project val mod_id: String by project val mod_archives_name: String by project -// Sets up the variables for when we preprocess to other Minecraft versions. -preprocess { - vars.put("MODERN", if (project.platform.mcMinor >= 16) 1 else 0) -} - // Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`. blossom { replaceToken("@VER@", mod_version) @@ -94,14 +89,14 @@ repositories { // Configures the libraries/dependencies for your mod. dependencies { // Adds the OneConfig library, so we can develop with it. - modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.1-alpha+") + modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+") modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.1.2") // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier. if (platform.isLegacyForge) { compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") - shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+") + shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17") } } @@ -168,7 +163,7 @@ tasks { // Configures our shadow/shade configuration, so we can // include some dependencies within our mod jar file. named("shadowJar") { - archiveClassifier.set("dev") // TODO: machete gets confused by the `dev` prefix. + archiveClassifier.set("dev") configurations = listOf(shade) duplicatesStrategy = DuplicatesStrategy.EXCLUDE relocate("ofconfig.", "") diff --git a/gradle.properties b/gradle.properties index 978b341..219483b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ mod_version = 1.0.0 mod_archives_name=PolyBlur # Gradle Configuration -- DO NOT TOUCH THESE VALUES. -polyfrost.defaults.loom=1 +polyfrost.defaults.loom=3 org.gradle.daemon=true org.gradle.parallel=true org.gradle.configureoncommand=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e411586..48c0a02 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/root.gradle.kts b/root.gradle.kts index 6246bdf..3d32bca 100644 --- a/root.gradle.kts +++ b/root.gradle.kts @@ -1,7 +1,7 @@ plugins { - kotlin("jvm") version "1.8.22" apply false + kotlin("jvm") version "1.9.10" apply false id("org.polyfrost.multi-version.root") - id("com.github.johnrengelman.shadow") version "7.1.2" apply false + id("com.github.johnrengelman.shadow") version "8.1.1" apply false } preprocess { diff --git a/settings.gradle.kts b/settings.gradle.kts index 5c72efc..9e4f599 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,7 +7,7 @@ pluginManagement { maven("https://repo.polyfrost.org/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit } plugins { - val pgtVersion = "0.2.9" // Sets the default versions for Polyfrost Gradle Toolkit + val pgtVersion = "0.6.2" // Sets the default versions for Polyfrost Gradle Toolkit id("org.polyfrost.multi-version.root") version pgtVersion } } diff --git a/src/main/java/org/polyfrost/polyblur/blurs/monkey/MonkeyBlur.java b/src/main/java/org/polyfrost/polyblur/blurs/monkey/MonkeyBlur.java index 1f9c36a..22662fc 100644 --- a/src/main/java/org/polyfrost/polyblur/blurs/monkey/MonkeyBlur.java +++ b/src/main/java/org/polyfrost/polyblur/blurs/monkey/MonkeyBlur.java @@ -77,6 +77,7 @@ public void startFrame() { previousCameraPosZ = cameraPosZ; bindFb(); + clearFb(); } public void endFrame() { @@ -107,6 +108,8 @@ public void endFrame() { } if (!isEnabled()) return; + //mc.renderGlobal.renderEntityOutlineFramebuffer(); + unbindFb(); if (monkeyblurShader == null) { @@ -143,7 +146,14 @@ public void bindFb() { frameBuffer = new MonkeyBuffer(mc.displayWidth, mc.displayHeight); } OpenGlHelper.glBindFramebuffer(OpenGlHelper.GL_FRAMEBUFFER, frameBuffer.framebufferObject); - frameBuffer.clear(); + } + + public void clearFb() { + if (!isEnabled()) return; + + if (frameBuffer != null) { + frameBuffer.clear(); + } } public void unbindFb() { @@ -225,7 +235,7 @@ static void invertMat4(FloatBuffer in, FloatBuffer out) { } public boolean isEnabled() { - return OpenGlHelper.framebufferSupported && PolyBlur.instance.config.enabled && PolyBlur.instance.config.blurMode == 0 && !changedPerspective && !OFConfig.isShaders(); + return OpenGlHelper.framebufferSupported && PolyBlur.instance != null && PolyBlur.instance.config.enabled && PolyBlur.instance.config.blurMode == 0 && !changedPerspective && !OFConfig.isShaders(); } public void outputFb(int width, int height, int texture) { diff --git a/src/main/java/org/polyfrost/polyblur/mixin/RenderGlobalMixin.java b/src/main/java/org/polyfrost/polyblur/mixin/RenderGlobalMixin.java new file mode 100644 index 0000000..92d7215 --- /dev/null +++ b/src/main/java/org/polyfrost/polyblur/mixin/RenderGlobalMixin.java @@ -0,0 +1,19 @@ +package org.polyfrost.polyblur.mixin; + +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.culling.ICamera; +import net.minecraft.entity.Entity; +import org.polyfrost.polyblur.blurs.monkey.MonkeyBlur; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(RenderGlobal.class) +public abstract class RenderGlobalMixin { + + @Inject(method = "renderEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/shader/Framebuffer;bindFramebuffer(Z)V", ordinal = 1, shift = At.Shift.AFTER)) + private void onRenderEntitiesPre(Entity renderViewEntity, ICamera camera, float partialTicks, CallbackInfo ci) { + MonkeyBlur.instance.bindFb(); + } +} diff --git a/src/main/java/org/polyfrost/polyblur/mixin/SBAEntityOutlineRendererMixin.java b/src/main/java/org/polyfrost/polyblur/mixin/SBAEntityOutlineRendererMixin.java new file mode 100644 index 0000000..b0d909f --- /dev/null +++ b/src/main/java/org/polyfrost/polyblur/mixin/SBAEntityOutlineRendererMixin.java @@ -0,0 +1,20 @@ +package org.polyfrost.polyblur.mixin; + +import org.polyfrost.polyblur.blurs.monkey.MonkeyBlur; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Pseudo +@Mixin(targets = "codes.biscuit.skyblockaddons.features.EntityOutlines.EntityOutlineRenderer") +public class SBAEntityOutlineRendererMixin { + + @Dynamic("SBA") + @Inject(method = "renderEntityOutlines", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/shader/Framebuffer;bindFramebuffer(Z)V", ordinal = 3, shift = At.Shift.AFTER, remap = true), remap = false) + private void onRenderEntityOutlinesPre(CallbackInfo ci) { + MonkeyBlur.instance.bindFb(); + } +} diff --git a/src/main/java/org/polyfrost/polyblur/mixin/SkyHanniEntityOutlineRendererMixin.java b/src/main/java/org/polyfrost/polyblur/mixin/SkyHanniEntityOutlineRendererMixin.java new file mode 100644 index 0000000..4ec59d1 --- /dev/null +++ b/src/main/java/org/polyfrost/polyblur/mixin/SkyHanniEntityOutlineRendererMixin.java @@ -0,0 +1,20 @@ +package org.polyfrost.polyblur.mixin; + +import org.polyfrost.polyblur.blurs.monkey.MonkeyBlur; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Pseudo +@Mixin(targets = "at.hannibal2.skyhanni.utils.EntityOutlineRenderer") +public class SkyHanniEntityOutlineRendererMixin { + + @Dynamic("SkyHanni") + @Inject(method = "renderEntityOutlines", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/shader/Framebuffer;bindFramebuffer(Z)V", ordinal = 3, shift = At.Shift.AFTER, remap = true), remap = false) + private void onRenderEntityOutlinesPre(CallbackInfo ci) { + MonkeyBlur.instance.bindFb(); + } +} diff --git a/src/main/resources/assets/polyblur/shaders/monkeyblur.frag b/src/main/resources/assets/polyblur/shaders/monkeyblur.frag index 554c1b8..0a79b3a 100644 --- a/src/main/resources/assets/polyblur/shaders/monkeyblur.frag +++ b/src/main/resources/assets/polyblur/shaders/monkeyblur.frag @@ -25,7 +25,7 @@ float maxDepth(vec2 texcoord, sampler2D tex) { for (int x = -2; x < 3; x++) { for (int y = -2; y < 3; y++) { - float d = texture2D(tex, texcoord + t * vec2(x, y)).x; + float d = texture2D(tex, texcoord + t * vec2(float(x), float(y))).x; depth = max(depth, d); } } @@ -58,11 +58,11 @@ void main() { vel = vel / (1.0 + length(vel)) * strength * 0.01; vec2 coord = texcoord.st + vel; - int count = 1; + float count = 1; for (int i = 0; i < 30; ++i, coord += vel) { if (coord.s > 1.0 || coord.t > 1.0 || coord.s < 0.0 || coord.t < 0.0) break; color += texture2D(texture, coord).xyz; - ++count; + count += 1; } color /= count; diff --git a/src/main/resources/mixins.polyblur.json b/src/main/resources/mixins.polyblur.json index e44e7d3..1cb1dc8 100644 --- a/src/main/resources/mixins.polyblur.json +++ b/src/main/resources/mixins.polyblur.json @@ -14,6 +14,9 @@ "EntityRendererMixin_PhosphorBlur", "MinecraftMixin", "OptifineConfigMixin", - "ShaderGroupAccessor" + "RenderGlobalMixin", + "SBAEntityOutlineRendererMixin", + "ShaderGroupAccessor", + "SkyHanniEntityOutlineRendererMixin" ] } \ No newline at end of file