Jump to content

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


Laike_Endaril

Recommended Posts

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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

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

    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
  • Topics

×
×
  • Create New...

Important Information

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