Jump to content

Recommended Posts

Posted

My mod adds a custom lightning bolt called dark lightning, with a custom renderer to make it render darkly. However, I am unable to colour the lightning black, no matter how I set the colour values.

 

RenderDarkLightning:

 

package net.condorcraft110.stygian.render;

import java.util.*;
import org.lwjgl.opengl.*;
import net.minecraft.util.*;
import net.minecraft.entity.*;
import net.minecraft.client.renderer.*;
import net.condorcraft110.stygian.entity.*;
import net.minecraft.client.renderer.entity.*;

public class RenderDarkLightning extends Render
{
public void doRender(EntityDarkLightning entity, double x, double y, double z, float f, float g)
{
	Tessellator tessellator = Tessellator.instance;
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        double[] adouble = new double[8];
        double[] adouble1 = new double[8];
        double d3 = 0.0D;
        double d4 = 0.0D;
        Random random = new Random(entity.boltVertex);
        
        for(int i = 7; i >= 0; --i)
        {
            adouble[i] = d3;
            adouble1[i] = d4;
            d3 += (double)(random.nextInt(11) - 5);
            d4 += (double)(random.nextInt(11) - 5);
        }

        for(int k1 = 0; k1 < 4; ++k1)
        {
            Random random1 = new Random(entity.boltVertex);

            for(int j = 0; j < 3; ++j)
            {
                int k = 7;
                int l = 0;

                if(j > 0)
                {
                    k = 7 - j;
                }

                if(j > 0)
                {
                    l = k - 2;
                }

                double d5 = adouble[k] - d3;
                double d6 = adouble1[k] - d4;

                for(int i1 = k; i1 >= l; --i1)
                {
                    double d7 = d5;
                    double d8 = d6;

                    if(j == 0)
                    {
                        d5 += (double)(random1.nextInt(11) - 5);
                        d6 += (double)(random1.nextInt(11) - 5);
                    }
                    else
                    {
                        d5 += (double)(random1.nextInt(31) - 15);
                        d6 += (double)(random1.nextInt(31) - 15);
                    }
                    
                    tessellator.startDrawing(5);
                    tessellator.setColorRGBA_F(0F, 0F, 0F, 1F); // Sets the colour, but still white 
                    double d9 = 0.1D + (double)k1 * 0.2D;
                    
                    if(j == 0)
                    {
                        d9 *= (double)i1 * 0.1D + 1.0D;
                    }
                    
                    double d10 = 0.1D + (double)k1 * 0.2D;
                    
                    if(j == 0)
                    {
                        d10 *= (double)(i1 - 1) * 0.1D + 1.0D;
                    }
                    
                    for(int j1 = 0; j1 < 5; ++j1)
                    {
                        double d11 = x + 0.5D - d9;
                        double d12 = z + 0.5D - d9;
                        
                        if(j1 == 1 || j1 == 2)
                        {
                            d11 += d9 * 2.0D;
                        }
                        
                        if(j1 == 2 || j1 == 3)
                        {
                            d12 += d9 * 2.0D;
                        }
                        
                        double d13 = x + 0.5D - d10;
                        double d14 = z + 0.5D - d10;
                        
                        if(j1 == 1 || j1 == 2)
                        {
                            d13 += d10 * 2.0D;
                        }
                        
                        if(j1 == 2 || j1 == 3)
                        {
                            d14 += d10 * 2.0D;
                        }
                        
                        tessellator.addVertex(d13 + d5, y + (double)(i1 * 16), d14 + d6);
                        tessellator.addVertex(d11 + d7, y + (double)((i1 + 1) * 16), d12 + d8);
                    }
                    
                    tessellator.draw();
                }
            }
        }
        
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
}

public void doRender(Entity entity, double x, double y, double z, float f, float g)
{
	doRender((EntityDarkLightning)entity, x, y, z, f, g);
}

protected ResourceLocation getEntityTexture(Entity entity)
{
	return null;
}
}

 

 

Update: When I don't enable GL_BLEND, the lightning does indeed render in black - but solidly. I want black-coloured lightning, not a large black line in the world :/

Posted

Hi

 

Try using this blend function instead of GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);

 

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

 

Use an alpha value of (say) 0.25 to start off with.

 

This online tool might be helpful,

http://www.andersriggelsen.dk/glblendfunc.php

also this background info link

http://www.glprogramming.com/red/chapter06.html

 

-TGG

 

IT WORKED! Thank you! I really should get down to learning OpenGL properly...

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

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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