Jump to content

[SOLVED BUT PARSING PROBLEM] [1.19.2] force client to toggle custom "post" shader when something happens on server


cocicocyn

Recommended Posts

disclaimer: i am new to java. however i will not ask for implementation nuances (at least not much. any help is appreciated).

suppose we have a custom block. when we rightclick on it we send a custom package (i assume that because we want specific things to happen on a server). server handles the package (applies effects or whatever) and sends back the answer. client part handles the answer. how do i toggle/load a custom shader when handling the answer from the server? can't seem to find suitable method. do i need to write a mixin? and if so what should i "mixin into"?

i believe it's possible because there is an in-game nausea effect and "wobble" shader (which btw has uniform float Time in it in .fsh file so it's animated)

thanks for help in advance 

Edited by cocicocyn
PostChain#parseUniformNode is sus + problem is finally solved
Link to comment
Share on other sites

  • cocicocyn changed the title to [1.19.2] force client to toggle custom "post" shader when something happens on server
10 hours ago, cocicocyn said:

how do i toggle/load a custom shader when handling the answer from the server?

So, if you want to use the postchain method, you can load a given effect via GameRenderer#loadEffect, the rest would be creating the json, vsh, and fsh as necessary.

10 hours ago, cocicocyn said:

i believe it's possible because there is an in-game nausea effect and "wobble" shader (which btw has uniform float Time in it in .fsh file so it's animated)

Nausea is rendered is highly hardcoded by manipulating the base posestack before everything else is rendered and the overlay is just a simple blit. As for the wobble shader, it's not really used anywhere afaik since it was probably part of the secret settings.

4 hours ago, cocicocyn said:

note for myself: research PostPass and PostChain classes in net.minecraft.client.renderer package (i guess the wiki provider is some third party warn me if this isn't supported) https://nekoyue.github.io/ForgeJavaDocs-NG/javadoc/1.19.3/net/minecraft/client/renderer/package-summary.html

It's illegal for this to be hosted.

  • Thanks 1
Link to comment
Share on other sites

am i the problem here? im not even reading anything from an array. 

net.minecraft.server.ChainedJsonException: Invalid shaders/post/tripeffect.json (Mod Resources) passes[0]->uniforms[0]->values[4]: Index 4 out of bounds for length 4
	at net.minecraft.server.ChainedJsonException.forException(ChainedJsonException.java:47) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading}
	at net.minecraft.client.renderer.PostChain.parseUniformNode(PostChain.java:245) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.PostChain.parsePassNode(PostChain.java:217) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.PostChain.load(PostChain.java:88) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.PostChain.<init>(PostChain.java:54) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.renderer.GameRenderer.loadEffect(GameRenderer.java:321) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.guryavkin.drugsmodguryavkin.event.ClientEvents$ClientKeyEvents.onKeyInput(ClientEvents.java:38) ~[%23188!/:?] {re:classloading}
	at net.guryavkin.drugsmodguryavkin.event.__ClientKeyEvents_onKeyInput_Key.invoke(.dynamic) ~[%23188!/:?] {re:classloading,pl:eventbus:B}
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.3.jar%23107!/:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.3.jar%23107!/:?] {}
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.3.jar%23107!/:?] {}
	at net.minecraftforge.client.ForgeHooksClient.onKeyInput(ForgeHooksClient.java:753) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23182%23189!/:?] {re:classloading}
	at net.minecraft.client.KeyboardHandler.keyPress(KeyboardHandler.java:407) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.KeyboardHandler.lambda$setup$7(KeyboardHandler.java:442) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.util.thread.BlockableEventLoop.execute(BlockableEventLoop.java:90) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.KeyboardHandler.lambda$setup$8(KeyboardHandler.java:441) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at org.lwjgl.glfw.GLFWKeyCallbackI.callback(GLFWKeyCallbackI.java:44) ~[lwjgl-glfw-3.3.1.jar%23162!/:build 7] {}
	at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.3.1.jar%23168!/:build 7] {}
	at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:3403) ~[lwjgl-glfw-3.3.1.jar%23162!/:build 7] {}
	at com.mojang.blaze3d.systems.RenderSystem.flipFrame(RenderSystem.java:164) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at com.mojang.blaze3d.platform.Window.updateDisplay(Window.java:337) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1143) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:700) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.run(Main.java:212) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:51) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:25) ~[fmlloader-1.19.2-43.2.3.jar%2395!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%23108!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%23108!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%23108!/:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%23108!/:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%23108!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%23108!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%23108!/:?] {}
	at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {}
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
	at net.minecraft.client.renderer.PostChain.parseUniformNode(PostChain.java:243) ~[forge-1.19.2-43.2.3_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
	... 36 more
fuckety resource location bad, drugsmodguryavkin shaders/post/tripeffect.json
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4

i can't make further progress anymore. managed to load a shader without shader compilation issues. this is what i get.
my "post" json:

Spoiler
{
    "targets": [
        "swap"
    ],
    "passes": [
        {
            "name": "tripeffect",
            "intarget": "minecraft:main",
            "outtarget": "swap",
            "uniforms": [
                { "name": "ProjMat", "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
                { "name": "OutSize", "values": [ 1.0, 1.0 ] },
                { "name": "Time",  "values": [ 0.0 ] }
            ]
        },
        {
            "name": "blit",
            "intarget": "swap",
            "outtarget": "minecraft:main"
        }
    ]
}

 

 my "program" json:

Spoiler
{
    "blend": {
        "func": "add",
        "srcrgb": "one",
        "dstrgb": "zero"
    },
    "vertex": "tripeffect",
    "fragment": "tripeffect",
    "attributes": [ "Position" ],
    "samplers": [
        { "name": "DiffuseSampler" }
    ],
    "uniforms": [
        { "name": "ProjMat",      "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] },
        { "name": "OutSize",      "type": "float",     "count": 2,  "values": [ 1.0, 1.0 ] },
        { "name": "Time",         "type": "float",     "count": 1,  "values": [ 0.0 ] }
    ]
}

 

my event handler where shader is loaded:

Spoiler
        @SubscribeEvent
        public static void onKeyInput(InputEvent.Key event)
        {
            try
            {
                if(KeyBinding.FUCK_KEY.consumeClick())
                {
                    GameRenderer renderer = Minecraft.getInstance().gameRenderer;
                    ResourceLocation loc = new ResourceLocation(DrugsModGuryavkin.MOD_ID, "shaders/post/tripeffect.json");
                    if (ResourceLocation.isValidResourceLocation(loc.getPath()))
                    {
                        renderer.loadEffect(loc);
                        ModMessages.sendToServer(new HighC2SPacket());
                    }
                    System.out.println(String.format("fuckety resource location bad, %1$s %2$s", loc.getNamespace(), loc.getPath()));
                }
            }
            catch (Exception e)
            {
                System.out.println(e.getMessage());
            }

all sorts of output because im losing my mind rn trying to make it work

my .fsh (if im using built-in uniforms wrong i will fix them later myself dont mind me):

Spoiler
#version 150

#ifdef GL_ES
precision mediump float;
#endif

uniform float Time;
uniform sampler2D DiffuseSampler;

in vec2 texCoord;
in vec2 oneTexel;

out vec4 fragColor;

vec3 pal( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d )
{
    return a + b*cos( 6.28318*(c*t+d) );
}

void main() {
    vec4 origColor = texture(DiffuseSampler, texCoord);

    float catx = texCoord.x;

    float caty = texCoord.y;

    float hyp = sqrt(pow(catx, 2.0) + pow(caty, 2.0));

    float rotAmp = degrees(Time/hyp);

    mat2 rotate = mat2(sin(rotAmp), cos(rotAmp), -cos(rotAmp), sin(rotAmp));

    vec2 p = texCoord.xy / oneTexel.xy * rotate;

    p.x *= oneTexel.x/oneTexel.y;

    vec3 col = pal( p.x+p.y, vec3(abs(0.5*sin(Time)),0.3,0.3),vec3(0.4,abs(0.5*sin(Time-0.7587)),0.2),vec3(abs(0.5*sin(2.0*Time-0.7587)),0.3,abs(0.8*sin(0.1*Time-0.7587))),vec3(0.0,abs(0.5*cos(1.5*Time-0.7587)),0.1) );

    col *= 0.2*abs(sin(degrees(Time/(360.0*4.0))));

    fragColor.r = mix(col.r, origColor.r, 0.1);
    fragColor.g = mix(col.g, origColor.g, 0.1);
    fragColor.b = mix(col.b, origColor.b, 0.1);
    fragColor.a = 1.0;
  
  	//all credit to gleurop on shaderstoy.com btw
}

 

my .vsh (copied blit.vsh)

Spoiler
#version 150

in vec4 Position;

uniform mat4 ProjMat;
uniform vec2 OutSize;
uniform float Time;

out vec2 texCoord;
out vec2 oneTexel;

void main(){
    vec4 outPos = ProjMat * vec4(Position.xy, 0.0, 1.0);
    gl_Position = vec4(outPos.xy, 0.2, 1.0);

    texCoord = Position.xy / OutSize;
    oneTexel = 1.0 / OutSize;
}

 

what am i doing wrong

progress#1 branch in github https://github.com/lveeeeeeeeeee/guryavkin_drugs_mod_for_minecraft

Edited by cocicocyn
added github
Link to comment
Share on other sites

  • cocicocyn changed the title to [SOLVED BUT PARSING PROBLEM] [1.19.2] force client to toggle custom "post" shader when something happens on server

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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