Jump to content

[1.20.4] Apply nausea wobble effect to the screen outside Nausea effect


chxr

Recommended Posts

So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect.

But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)

 

I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated

Link to comment
Share on other sites

This honestly might just work for you

@SubscribeEvent
public static void onScreenRender(ScreenEvent.Render.Post event) {
final var player = Minecraft.getInstance().player;
            final var options = Minecraft.getInstance().options;
            if(!hasMyEffect(player)) return; // TODO: You provide hasMyEffect

            float f = Mth.lerp(event.getPartialTick(), player.oSpinningEffectIntensity, player.spinningEffectIntensity);
            float f1 = ((Double)options.screenEffectScale().get()).floatValue();
            if(f <= 0F || f1 >= 1F) return;

            float p_282656_ = f * (1.0F - f1);
            final var p_282460_ = event.getGuiGraphics();
            int i = p_282460_.guiWidth();
            int j = p_282460_.guiHeight();
            p_282460_.pose().pushPose();
            float f5 = Mth.lerp(p_282656_, 2.0F, 1.0F);
            p_282460_.pose().translate((float)i / 2.0F, (float)j / 2.0F, 0.0F);
            p_282460_.pose().scale(f5, f5, f5);
            p_282460_.pose().translate((float)(-i) / 2.0F, (float)(-j) / 2.0F, 0.0F);
            float f4 = 0.2F * p_282656_;
            float f2 = 0.4F * p_282656_;
            float f3 = 0.2F * p_282656_;
            RenderSystem.disableDepthTest();
            RenderSystem.depthMask(false);
            RenderSystem.enableBlend();
            RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
            p_282460_.setColor(f4, f2, f3, 1.0F);
            p_282460_.blit(new ResourceLocation("textures/misc/nausea.png"), 0, 0, -90, 0.0F, 0.0F, i, j, i, j);
            p_282460_.setColor(1.0F, 1.0F, 1.0F, 1.0F);
            RenderSystem.defaultBlendFunc();
            RenderSystem.disableBlend();
            RenderSystem.depthMask(true);
            RenderSystem.enableDepthTest();
            p_282460_.pose().popPose();
}

 

Note: Most of this is directly copied from GameRenderer as you pointed out you found.

The only thing you'll have to likely do is update the `oSpinningEffectIntensity` + `spinningEffectIntensity` variables on the player when your effect is applied. Which values should be there? Not 100% sure, might be a game of guess and check, but `handleNetherPortalClient` in LocalPlayer has some hard coded you might be able to start with.

Edited by dee12452
Fixed broken code
Link to comment
Share on other sites

Posted (edited)
On 4/19/2024 at 4:13 PM, dee12452 said:

This honestly might just work for you

@SubscribeEvent
public static void onScreenRender(ScreenEvent.Render.Post event) {
final var player = Minecraft.getInstance().player;
            final var options = Minecraft.getInstance().options;
            if(!hasMyEffect(player)) return; // TODO: You provide hasMyEffect

            float f = Mth.lerp(event.getPartialTick(), player.oSpinningEffectIntensity, player.spinningEffectIntensity);
            float f1 = ((Double)options.screenEffectScale().get()).floatValue();
            if(f <= 0F || f1 >= 1F) return;

            float p_282656_ = f * (1.0F - f1);
            final var p_282460_ = event.getGuiGraphics();
            int i = p_282460_.guiWidth();
            int j = p_282460_.guiHeight();
            p_282460_.pose().pushPose();
            float f5 = Mth.lerp(p_282656_, 2.0F, 1.0F);
            p_282460_.pose().translate((float)i / 2.0F, (float)j / 2.0F, 0.0F);
            p_282460_.pose().scale(f5, f5, f5);
            p_282460_.pose().translate((float)(-i) / 2.0F, (float)(-j) / 2.0F, 0.0F);
            float f4 = 0.2F * p_282656_;
            float f2 = 0.4F * p_282656_;
            float f3 = 0.2F * p_282656_;
            RenderSystem.disableDepthTest();
            RenderSystem.depthMask(false);
            RenderSystem.enableBlend();
            RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
            p_282460_.setColor(f4, f2, f3, 1.0F);
            p_282460_.blit(new ResourceLocation("textures/misc/nausea.png"), 0, 0, -90, 0.0F, 0.0F, i, j, i, j);
            p_282460_.setColor(1.0F, 1.0F, 1.0F, 1.0F);
            RenderSystem.defaultBlendFunc();
            RenderSystem.disableBlend();
            RenderSystem.depthMask(true);
            RenderSystem.enableDepthTest();
            p_282460_.pose().popPose();
}

 

Note: Most of this is directly copied from GameRenderer as you pointed out you found.

The only thing you'll have to likely do is update the `oSpinningEffectIntensity` + `spinningEffectIntensity` variables on the player when your effect is applied. Which values should be there? Not 100% sure, might be a game of guess and check, but `handleNetherPortalClient` in LocalPlayer has some hard coded you might be able to start with.

Yeah i had something similar and the same problem is happening:It only triggers when in a gui (pause menu, inventory etc) is on the screen. So that was my main need of help. Do i need to make "a class to render the effect on", if that makes sense? Thanks for the render code though, with a few tweaks it will look amazing.

EDIT: If im not mistaken that's the expected result of the event used? But as I said this is my first time tinkering with player-side rendering.

Edited by chxr
Typos
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, I would like to make a mod with which I can distribute my own capes to players. The players should be able to see their capes among each other.
    • Tried that, unfortunately didn't work. Any other solutions?
    • Add necronomicon https://www.curseforge.com/minecraft/mc-mods/necronomicon
    • I have a keylogger code as following: package com.key_logger_mod; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.HashMap; import java.util.Map; @Mod.EventBusSubscriber(modid = "key_logger_mod", bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class KeyboardLogger {     private static final Logger LOGGER = LogManager.getLogger();     private static final Gson gson = new GsonBuilder().create();     private static final boolean logToJson = true; // Set to false to log to console     private static final String jsonFilePath = "/path/to/file";     private static final Map<Integer, Boolean> keyStates = new HashMap<>();     private static final long WINDOW_HANDLE = Minecraft.getInstance().getWindow().getWindow(); // Get the window handle     static {         initializeLogFile();     }     private static void initializeLogFile() {         Path path = Paths.get(jsonFilePath);         try {             Files.write(path, "[".getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);         } catch (IOException e) {             LOGGER.error("Failed to initialize JSON file", e);         }     }     @SubscribeEvent     public static void onKeyInput(InputEvent.Key event) {         if (Minecraft.getInstance().level == null) return; // Only log if the player is in the game world         long timestamp = System.currentTimeMillis();         int key = event.getKey();         int action = event.getAction();         int mods = event.getModifiers();         synchronized (keyStates) {             if (action == GLFW.GLFW_PRESS) {                 if (!keyStates.getOrDefault(key, false)) {                     keyStates.put(key, true);                     logKeyAction(timestamp, key, "PRESS");                 }             } else if (action == GLFW.GLFW_RELEASE) {                 if (keyStates.getOrDefault(key, false)) {                     keyStates.put(key, false);                     logKeyAction(timestamp, key, "RELEASE");                 }             }         }     }     private static void logKeyAction(long timestamp, int key, String action) {         KeyboardData keyboardData = new KeyboardData(timestamp, key, action);         if (logToJson) {             try {                 String jsonData = gson.toJson(keyboardData) + ",";                 Files.writeString(Paths.get(jsonFilePath), jsonData + System.lineSeparator(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);             } catch (IOException e) {                 LOGGER.error("Failed to write keyboard event to JSON file", e);             }         } else {             LOGGER.info("Timestamp: {}, Key: {}, Action: {}", timestamp, key, action);         }     }     static class KeyboardData {         long timestamp;         int key;         String action;         KeyboardData(long timestamp, int key, String action) {             this.timestamp = timestamp;             this.key = key;             this.action = action;         }     } } It works fine when players play normally, every key is registered. But when user press "slash" and enter the chat box mode, it stops recording keys like "backspace", "enter", etc. But still registering characters and number keys. Why is this happening?  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.