Jump to content

[Solved] Options for altering alpha of vanilla / other mods' mobs


Recommended Posts

Posted (edited)

Have a mod which could benefit greatly from fading mobs in and out, alpha-wise, but haven't found a solution I like yet.  If it were just my own mobs it would be easy, ofc, but I'd need it for *all* mobs.

 

The obvious answer (if you're familiar with openGL) is to set the openGL rendering settings correctly, but I tried this in RenderLivingEvent.Pre and did not get any results (enabled alpha and set color to (1f, 1f, 1f, 0.4f)).  If someone has tips on hacking this method to work I'd appreciate that.

 

I know a shader would work, but I'm trying to avoid that so as not to break compatibility with other shader mods.

 

Replacing vertex data in existing models would also work in theory, but would probably be extremely inefficient, since I'd need to generate (currentModelCount * alphaSteps) models, right?

 

In any case, looking for the most "normal" way to accomplish this, if there is such a thing.

 

 

 

Edit: I made a dumb mistake and used enableAlpha/disableAlpha instead of enableBlend/disableBlend.  This code works fine:
 

Spoiler

@SubscribeEvent
public static void preRender(RenderLivingEvent.Pre event)
{
    GlStateManager.enableBlend();
    GlStateManager.color(1, 1, 1, 0.4f);
}

@SubscribeEvent
public static void postRender(RenderLivingEvent.Post event)
{
    GlStateManager.color(1, 1, 1, 1);
    GlStateManager.disableBlend();
}

 

 

Edited by Laike_Endaril
Solved
Posted

Does running your event subscriber with LOWEST priority fix it?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
1 hour ago, Cadiboo said:

Does running your event subscriber with LOWEST priority fix it?

When I tested using the event mentioned, my mod was the only one loaded, so I'm automatically both LOWEST and HIGHEST, since there are no other mods loaded to add event subscribers.  But yeah, I've had to solve some mod compatibility stuff using priorities before, and it is something I will keep in mind for compat if I get this working on vanilla first.

Posted

The event is probably technically working, but I suspect that most rendering code overwrites whatever you do there. The rendering events are good for ADDING something else to be rendered, or fully replacing what is rendered, but not really good for changing what is rendered. 

 

It is actually usually good practice for any rendering code to sort of "reset" some of the GL stuff to a known state, exactly so other code running before it can't mess it up.

 

Now Minecraft code is quite inconsistent so you might get lucky and find some places where a judiciously placed alpha change will affect the next thing rendered but it would be hard to count on it, as you found out.

 

If you're really good at GL, you might be able to push/pop a matrix to apply the alpha but you'd have to take care to handle the events symmetrically so that you don't end up overflowing the matrix stack.

 

If you're ambitious you can replace all the renderers for the vanilla entities with ones how you want, but doing it for other mobs would be tough.

 

Sorry, maybe someone has a clever idea to do what you're looking for. Otherwise, I'd trace through the various rendering code to see if there is a place to surgically insert an alpha change.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Yeah, what I tried before was a temporary test; I'm decent with openGL so I (usually *cough*) make sure to push/pop or reset parameters when I'm done.

 

Dang, was hoping I had missed something handy, but so far it seems about as much trouble as I thought it would be...I may poke around like you said and see if there's anything global-ish that I can intercept (if it doesn't do *all mobs* or at least nearly all mobs then it wouldn't be worth doing).

 

I'll be sure to post if I find anything workable that doesn't involve loads of incompatibility issues :P

Posted

I can think of a dirty hack (asside from a coremod)

use GLStateManager to set the alpha to what it’s going to be set in the render call (so the state manager will ignore the next call) then directly set you values with GL11.

In the post event set it back with GL11/change it to something else with GLStateManager

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
17 hours ago, Cadiboo said:

use GLStateManager to set the alpha to what it’s going to be set in the render call (so the state manager will ignore the next call) then directly set you values with GL11.

 

I actually considered this, but was iffy about it because I have no way of knowing for sure what it will be set to for some random mod's mobs (though surely in most cases it will be 1; fully opaque).  One other issue would be if the alpha settings are set more than once between when I set them and when the entity is rendered, because there's no way for me to prevent GLStateManager from passing it if it changes twice.

 

HOWEVER, by suggesting it you got me to go look at the GLStateManager class again, and made me realize something extremely useful, so thanks, Cadiboo!

 

Specifically this, which I am quite excited about now:
 

Spoiler

    private static final FloatBuffer BUF_FLOAT_16 = BufferUtils.createFloatBuffer(16);
    private static final FloatBuffer BUF_FLOAT_4 = BufferUtils.createFloatBuffer(4);
    private static final GlStateManager.AlphaState alphaState = new GlStateManager.AlphaState();
    private static final GlStateManager.BooleanState lightingState = new GlStateManager.BooleanState(2896);
    private static final GlStateManager.BooleanState[] lightState = new GlStateManager.BooleanState[8];
    private static final GlStateManager.ColorMaterialState colorMaterialState;
    private static final GlStateManager.BlendState blendState;
    private static final GlStateManager.DepthState depthState;
    private static final GlStateManager.FogState fogState;
    private static final GlStateManager.CullState cullState;
    private static final GlStateManager.PolygonOffsetState polygonOffsetState;
    private static final GlStateManager.ColorLogicState colorLogicState;
    private static final GlStateManager.TexGenState texGenState;
    private static final GlStateManager.ClearState clearState;
    private static final GlStateManager.StencilState stencilState;
    private static final GlStateManager.BooleanState normalizeState;
    private static int activeTextureUnit;
    private static final GlStateManager.TextureState[] textureState;
    private static int activeShadeModel;
    private static final GlStateManager.BooleanState rescaleNormalState;
    private static final GlStateManager.ColorMask colorMaskState;
    private static final GlStateManager.Color colorState;

 

 

All the cached openGL states it uses are *OBJECT INSTANCES!*

 

I can most likely extend them and reflect-replace to accomplish my goal.  I also doubt this would have many (if any) compatibility issues with other mods, since I wouldn't expect many people to be messing with these (I can accept the off-chance of 1 or 2 incompatible mods).


I'll tinker with this after I take care of a couple other things, and post back here after I try it!

Posted

But unfortunately I hadn't realized GlStateManager.AlphaState only has a private constructor, and so I cannot extend it.  So that's about as far as I got with my bright idea lol

 

While I was at it, I also tried what you suggested @Cadiboo, but had no luck there either:
 

    @SubscribeEvent
    public static void preRender(RenderLivingEvent.Pre event)
    {
        GlStateManager.disableAlpha();
        GlStateManager.color(1, 1, 1, 1);
        GL11.glEnable(GL11.GL_ALPHA);
        GL11.glColor4f(1, 1, 1, 0.4f);
    }

    @SubscribeEvent
    public static void postRender(RenderLivingEvent.Post event)
    {
        GlStateManager.enableAlpha();
        GlStateManager.color(1, 1, 1, 0.4f);
        GlStateManager.disableAlpha();
        GlStateManager.color(1, 1, 1, 1);
    }

 

This code had no visible effect (and yes, that class was on the event bus; other, unrelated events in the class were firing on the client)

 

I'll probably put this feature on hold for now and maybe come back to it later and try one of the other approaches

Posted

I wouldn't usually recommend this, but as it has a private constructor you probably won't mess with anything. You could use an Access Transformer

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Alright, so I made a dumb mistake and used enableAlpha / disableAlpha instead of enableBlend / disableBlend for one of the first, most simple methods of accomplishing this.

 

The following works just fine... :P
 

Quote

@SubscribeEvent
public static void preRender(RenderLivingEvent.Pre event)
{
    GlStateManager.enableBlend();
    GlStateManager.color(1, 1, 1, 0.4f);
}

@SubscribeEvent
public static void postRender(RenderLivingEvent.Post event)
{
    GlStateManager.color(1, 1, 1, 1);
    GlStateManager.disableBlend();
}

 

 

Yep...on the bright side, now I know how to use ATs due to my dumb mistake.  Thanks to Tama on the MMD discord for smacking me in the face

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

    • that happens every time I enter a new dimension.
    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
  • Topics

×
×
  • Create New...

Important Information

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