Jump to content

Finally solved: (1.7.2) Custom Particles just rendered black


Bedrock_Miner

Recommended Posts

Heyho Guys!

I created some custom particles but sometimes (I don't exactly know why) they're just rendered in black. What can I do to avoid this annoying problem?

 

I have to admit that I have no Idea why this problem appears. The particles are actually flying in a straight line and if I look to much downwards they appear colorless. But I can't exactly say when.

 

Paticles code:

package com.bedrockminer.mod.client.particle;

import ...;

public abstract class EntityModParticleFX extends EntityFX {

public EntityMpdParticleFX(World world, double x, double y, double z, double vX, double vY, double vZ) {
	super(world, x, y, z);
	this.setRBGColorF(1.0F, 1.0F, 1.0F);
	this.motionX = vX;
	this.motionY = vY;
	this.motionZ = vZ;
	this.particleGravity = 0.0F;
}

public EntityModParticleFX(World world, double x, double y, double z) {
	super(world, x, y, z);
	this.setRBGColorF(1.0F, 1.0F, 1.0F);
}

@Override
public void renderParticle(Tessellator t, float par2, float par3, float par4, float par5, float par6, float par7) {
	t.draw();//Restart so that the texture can be changed
	Minecraft.getMinecraft().getTextureManager().bindTexture(this.getResourceLocation());
	t.startDrawingQuads();
	float f6 = this.particleTextureIndexX / 4.0F;
        float f7 = f6 + 0.25F;
        float f8 = this.particleTextureIndexY / 4.0F;
        float f9 = f8 + 0.25F;
        float f10 = 0.1F * this.particleScale;

        GL11.glDisable(GL11.GL_LIGHTING);
        t.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        float f11 = (float)(this.prevPosX + (this.posX - this.prevPosX) * par2 - interpPosX);
        float f12 = (float)(this.prevPosY + (this.posY - this.prevPosY) * par2 - interpPosY);
        float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ);
        t.addVertexWithUV(f11 - par3 * f10 - par6 * f10, f12 - par4 * f10, f13 - par5 * f10 - par7 * f10, f7, f9);
        t.addVertexWithUV(f11 - par3 * f10 + par6 * f10, f12 + par4 * f10, f13 - par5 * f10 + par7 * f10, f7, f8);
        t.addVertexWithUV(f11 + par3 * f10 + par6 * f10, f12 + par4 * f10, f13 + par5 * f10 + par7 * f10, f6, f8);
        t.addVertexWithUV(f11 + par3 * f10 - par6 * f10, f12 - par4 * f10, f13 + par5 * f10 - par7 * f10, f6, f9);
        t.draw();//Restart so that the texture can be changed
        Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/particle/particles.png"));
        t.startDrawingQuads();
}

@Override
public int getBrightnessForRender(float par1) //Copied from other particles in Vanilla
    {
        float agePercentage = (this.particleAge + par1) / this.particleMaxAge;

        if (agePercentage < 0.0F)
        {
            agePercentage = 0.0F;
        }

        if (agePercentage > 1.0F)
        {
            agePercentage = 1.0F;
        }

        int i = super.getBrightnessForRender(par1);
        int j = i & 255;
        int k = i >> 16 & 255;
        j += (int)(agePercentage * 15.0F * 16.0F);

        if (j > 240)
        {
            j = 240;
        }

        return j | k << 16;
    }

    /**
     * Gets how bright this entity is.
     */
    @Override
public float getBrightness(float par1) //Copied from other particles in Vanilla
    {
        float agePercentage = (this.particleAge + par1) / this.particleMaxAge;

        if (agePercentage < 0.0F)
        {
            agePercentage = 0.0F;
        }

        if (agePercentage > 1.0F)
        {
            agePercentage = 1.0F;
        }

        float f2 = super.getBrightness(par1);
        return f2 * agePercentage + (1.0F - agePercentage);
    }

// Now only unnecessary stuff follows.

@Override
public void setParticleTextureIndex(int index) {
	index %= 16;
	this.particleTextureIndexX = index % 4;
	this.particleTextureIndexY = index / 4;
}

@Override
public void nextTextureIndexX() {
	this.setParticleTextureIndex(this.particleTextureIndexX + this.particleTextureIndexY * 4 + 1);
}

@Override
public void onUpdate() {
	super.onUpdate();
	this.nextTextureIndexX();
}

protected abstract ResourceLocation getResourceLocation();

public void addRandomToVelocity() {
	this.motionX = this.motionX + (float)(Math.random() * 2.0D - 1.0D) * 0.4F;
        this.motionY = this.motionY + (float)(Math.random() * 2.0D - 1.0D) * 0.4F;
        this.motionZ = this.motionZ + (float)(Math.random() * 2.0D - 1.0D) * 0.4F;
        float f = (float)(Math.random() + Math.random() + 1.0D) * 0.15F;
        float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
        this.motionX = this.motionX / f1 * f * 0.4000000059604645D;
        this.motionY = this.motionY / f1 * f * 0.4000000059604645D + 0.10000000149011612D;
        this.motionZ = this.motionZ / f1 * f * 0.4000000059604645D;
}

public void enableGravity() {
	this.particleGravity = 1F;
}
}

Link to comment
Share on other sites

Hi

 

This class might be of interest to you

https://github.com/TheGreyGhost/SpeedyTools/blob/Working/src/speedytools/common/Utilities/OpenGLdebugging.java

 

I've used it in the past to check what the OpenGL settings are; it's not complete, but dumpAllIsEnabled() works and has showed up problems for me before- dump for a good render, dump for a bad render, and spot the difference.

 

-TGG

Link to comment
Share on other sites

  • 2 weeks later...

I compared the state when the particles are black with the state when they are coloured, but I can see no difference!

Here is the data your GLDebugger put out:

GL_VERTEX_ARRAY:false (Vertex array enable)
GL_NORMAL_ARRAY:false (Normal array enable)
GL_COLOR_ARRAY:false (RGBA color array enable)
GL_INDEX_ARRAY:false (Color-index array enable)
GL_TEXTURE_COORD_ARRAY:false (Texture coordinate array enable)
GL_EDGE_FLAG_ARRAY:false (Edge flag array enable)
GL_NORMALIZE:true (Current normal normalization on/off)
GL_FOG:true (True if fog enabled)
GL_LIGHTING:false (True if lighting is enabled)
GL_COLOR_MATERIAL:true (True if color tracking is enabled)
GL_LIGHT0:false (True if light 0 enabled)
GL_LIGHT1:false (True if light 1 enabled)
GL_LIGHT2:false (True if light 2 enabled)
GL_LIGHT3:false (True if light 3 enabled)
GL_LIGHT4:false (True if light 4 enabled)
GL_LIGHT5:false (True if light 5 enabled)
GL_LIGHT6:false (True if light 6 enabled)
GL_LIGHT7:false (True if light 7 enabled)
GL_POINT_SMOOTH:false (Point antialiasing on)
GL_LINE_SMOOTH:false (Line antialiasing on)
GL_LINE_STIPPLE:false (Line stipple enable)
GL_CULL_FACE:true (Polygon culling enabled)
GL_POLYGON_SMOOTH:false (Polygon antialiasing on)
GL_POLYGON_OFFSET_POINT:false (Polygon offset enable for GL_POINT mode rasterization)
GL_POLYGON_OFFSET_LINE:false (Polygon offset enable for GL_LINE mode rasterization)
GL_POLYGON_OFFSET_FILL:false (Polygon offset enable for GL_FILL mode rasterization)
GL_POLYGON_STIPPLE:false (Polygon stipple enable)
GL_TEXTURE_1D:false (True if 1-D texturing enabled )
GL_TEXTURE_2D:true (True if 2-D texturing enabled )
GL_TEXTURE_GEN_S:false (Texgen enabled (x is S, T, R, or Q))
GL_TEXTURE_GEN_T:false (Texgen enabled (x is S, T, R, or Q))
GL_TEXTURE_GEN_R:false (Texgen enabled (x is S, T, R, or Q))
GL_TEXTURE_GEN_Q:false (Texgen enabled (x is S, T, R, or Q))
GL_SCISSOR_TEST:false (Scissoring enabled)
GL_ALPHA_TEST:true (Alpha test enabled)
GL_STENCIL_TEST:false (Stenciling enabled)
GL_DEPTH_TEST:true (Depth buffer enabled)
GL_BLEND:true (Blending enabled)
GL_DITHER:true (Dithering enabled)
GL_INDEX_LOGIC_OP:false (Color index logical operation enabled)
GL_COLOR_LOGIC_OP:false (RGBA color logical operation enabled)
GL_AUTO_NORMAL:false (True if automatic normal generation enabled)

 

Any Ideas which setting can cause the problem?

 

Additional question: Is it possible to render the particles in front of water? Normally they are always rendered behind water, even if they are in front of it. (Also with vanilla particles, try it out!)

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

    • this is my first time using this website. Im having an issue where if I have EC Apotheosis enabled the game launches but crashes on the loading screen. If I disable the mod the game runs fine. Dont know if it will help but this is the exported curseforge proflie file. https://drive.google.com/file/d/1iDoqIGmiJsTKW5ocru7FBxIdBiKgUr0i/view?usp=sharing
    • How to fix file server-1.20.1-20230612.114412-srg.jar  
    • Just a few months ago I was creating my own plugin for Minecraft 1.20.2 spigot that did the same thing, but the skins were not saved, if you can understand this code that I made a long time ago it may help you.   //This is a class method private static String APIRequest(String value, String url, String toSearch) { try { URL api = new URL(url + value); HttpURLConnection connection = (HttpURLConnection) api.openConnection(); connection.setRequestMethod("GET"); int responseCode = connection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); for (String responseChar; (responseChar = reader.readLine()) != null; ) response.append(responseChar); reader.close(); JSONObject responseObject = new JSONObject(response.toString()); if (!toSearch.equals("id")) return responseObject .getJSONArray("properties") .getJSONObject(0) .getString("value"); else return responseObject.getString("id"); } else { AntiGianka.ConsoleMessage(ChatColor.RED, String.format( "Could not get %s. Response code: %s", ((toSearch.equals("id")) ? "UUID" : "texture"), responseCode )); } } catch (MalformedURLException error) { AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error); } catch (IOException error) { AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while attempting to connect to the URL. Error: " + error); } return ""; } //other class method private void SkinGetter() { String uuid; String textureCoded; if ((uuid = APIRequest(args[0], "https://api.mojang.com/users/profiles/minecraft/", "id")).isEmpty() || (textureCoded = APIRequest(uuid, "https://sessionserver.mojang.com/session/minecraft/profile/", "value")).isEmpty() ) sender.sendMessage(ChatColor.RED + String.format( "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.", args[0], args[0] ) ); else SkinSetter(textureCoded); } //other more private void SkinSetter(String textureCoded) { JSONObject profile = new JSONObject(new String(Base64.getDecoder().decode(textureCoded))); try { URL textureUrl = new URL(profile.getJSONObject("textures"). getJSONObject("SKIN"). getString("url")); if (sender instanceof Player && args.length == 1) { PlayerTextures playerTextures = ((Player) sender).getPlayerProfile().getTextures(); playerTextures.setSkin(textureUrl); ((Player) sender).getPlayerProfile().setTextures(playerTextures); if (((Player) sender).getPlayerProfile().getTextures().getSkin() != null) sender.sendMessage(((Player) sender).getPlayerProfile().getTextures().getSkin().toString()); else sender.sendMessage("Null"); sender.sendMessage("Skin changed successfully.a"); } else { } AntiGianka.ConsoleMessage(ChatColor.GREEN, "Skin command executed successfully."); } catch (MalformedURLException error) { sender.sendMessage(ChatColor.RED + String.format( "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.", args[0], args[0] ) ); AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error); } }  
    • Use /locate structure The chat should show all available structures as suggestion For the Ancient City it is /locate structure ancient_city
  • Topics

×
×
  • Create New...

Important Information

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