Jump to content

[1.7.10] How does one activate Minecraft shaders? (vanilla ones)


Comrade Bearabyte

Recommended Posts

Hello everyone,

 

I'd like to activate a certain Minecraft shader from "super secret settings" when an item is used, specifically the one named "wobble". Now, I have an item set up and everything, and I overrid the "onItemUse" method (is this the way to do it, BTW?) but I have no idea how to start the shader. I've been looking around the minecraft Shader classes (ShaderManager, ShaderLoader, ...) for a long time but can't seem to figure out how to do this.

 

Thanks!

 

PS: I don't expect a full code or anything similar, just general pointers on how to work with Minecraft shaders, because I'm not at all new to programming, however I am new to modding Minecraft

Link to comment
Share on other sites

Thanks shieldbug, that is indeed changing the shaders. Sorry for the late reply. I now have this code in the item use method:

 

Minecraft.getMinecraft().entityRenderer.activateNextShader();

 

However I am getting an exception, "No OpenGL context found in the current thread.". Which is kind of expected because OpenGL contexts are thread-specific and when one thread uses the context another one cannot. I am assuming for that reason that the GUI thread owns the OpenGL context and that item use method is in a different thread which does not have it. Is there a way to activate the shader from this thread, or is there some other way around this?

Link to comment
Share on other sites

Where did you call that method?

 

In my item class which is the subclass of Item, I overrid the "onItemRightClick" method:

 

@Override

public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)

{

Minecraft.getMinecraft().entityRenderer.activateNextShader();

 

return p_77659_1_;

}

Link to comment
Share on other sites

onItemRightClick is called on both server & client, you cannot interact with client-code directly in there. Check that the world is a client world (world.isRemote is true) and then call a method in your proxy (@SidedProxy) that then activates the shader.

 

Thanks, that fixed it! It's working now, and this is how I currently get wobble:

 

while(Minecraft.getMinecraft().entityRenderer.isShaderActive() ? !(Minecraft.getMinecraft().entityRenderer.getShaderGroup().getShaderGroupName().equals("minecraft:shaders/post/wobble.json")) : true)

                Minecraft.getMinecraft().entityRenderer.activateNextShader();

 

Basicly it cycles through all the shaders until it finds "wobble", is there maybe a certain method for getting a specific one or is this the way to go?

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.



×
×
  • Create New...

Important Information

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