Jump to content

[1.10.2] [Solved] Lines render black in the world


Earthcomputer

Recommended Posts

This code is supposed to render lines above a redstone component when it is hovered over showing the inputs and outputs of the component (it should be rendered on top of all the blocks, even if it is behind them). It works sort of, but inconsistently - all the lines turn black or are darker than they should be, and sometimes the lines disappear completely.

 

Picture of the black lines: https://goo.gl/uh7ert

 

Relevant code:

 

 

Post-world-render event listener:

package net.earthcomputer.redbuilder.logic;

import org.lwjgl.opengl.GL11;

import net.earthcomputer.redbuilder.RedBuilderSettings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class RedstoneLogicDisplayListener {

@SubscribeEvent
public void onRenderBlockOverlay(RenderWorldLastEvent e) {
	if (!RedBuilderSettings.enableRedstonePowerInfo) {
		return;
	}

	Minecraft mc = Minecraft.getMinecraft();
	World world = mc.theWorld;
	EntityPlayer player = mc.thePlayer;
	RayTraceResult target = mc.objectMouseOver;
	if (world == null || player == null || target == null) {
		return;
	}

	if (target.typeOfHit != RayTraceResult.Type.BLOCK) {
		return;
	}
	BlockPos pos = target.getBlockPos();
	RedstonePowerInfo powerInfo = RedstoneComponentRegistry.getPowerInfo(world, pos);

	GlStateManager.pushMatrix();
	GlStateManager.translate(0.5 - player.posX, -player.posY, 0.5 - player.posZ);

	GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
	for (PowerPath path : powerInfo.genPowerPaths(world, pos, world.getBlockState(pos))) {
		path.draw();
	}

	GlStateManager.popMatrix();
}

}

 

And here is the PowerPath class where the lines are actually rendered:

package net.earthcomputer.redbuilder.logic;

import java.util.Iterator;
import java.util.List;

import org.lwjgl.opengl.GL11;

import com.google.common.collect.Lists;

import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.BlockPos;

public class PowerPath {

protected List<BlockPos> points = Lists.newArrayList();
protected List<Integer> colors = Lists.newArrayList();

protected PowerPath(BlockPos startingPoint) {
	points.add(startingPoint);
}

public static PowerPath startPoint(BlockPos startingPoint) {
	return new PowerPath(startingPoint);
}

public PowerPath add(BlockPos point, int color) {
	points.add(point);
	colors.add(color);
	return this;
}

public void draw() {
	if (colors.isEmpty()) {
		return;
	}
	if (points.size() != colors.size() + 1) {
		throw new IllegalStateException("points.size() != colors.size() + 1");
	}

	Tessellator tessellator = Tessellator.getInstance();
	VertexBuffer vertexBuffer = tessellator.getBuffer();

	vertexBuffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);

	Iterator<BlockPos> pointIterator = points.iterator();
	Iterator<Integer> colorIterator = colors.iterator();
	BlockPos point = pointIterator.next();
	int color;

	while (pointIterator.hasNext()) {
		color = colorIterator.next();
		drawPoint(vertexBuffer, point, color);
		point = pointIterator.next();
		drawPoint(vertexBuffer, point, color);
	}

	tessellator.draw();
}

private void drawPoint(VertexBuffer buffer, BlockPos point, int color) {
	buffer.pos(point.getX(), point.getY() + 0.5, point.getZ());
	buffer.color((color & 0x00ff0000) >> 16, (color & 0x0000ff00) >> 8, color & 0x000000ff,
			(color & 0xff000000) >>> 24);
	buffer.endVertex();
}

@Override
public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((colors == null) ? 0 : colors.hashCode());
	result = prime * result + ((points == null) ? 0 : points.hashCode());
	return result;
}

@Override
public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (obj == null)
		return false;
	if (!(obj instanceof PowerPath))
		return false;
	PowerPath other = (PowerPath) obj;
	if (colors == null) {
		if (other.colors != null)
			return false;
	} else if (!colors.equals(other.colors))
		return false;
	if (points == null) {
		if (other.points != null)
			return false;
	} else if (!points.equals(other.points))
		return false;
	return true;
}

}

 

 

 

An interesting effect is that if you open the chat GUI while looking at a redstone component, the lines blink on and off (very strange). It's almost as if OpenGL is being distracted by the chat cursor so doesn't draw the lines.

 

If you want to reproduce this yourself, all the code is also on github:

https://github.com/Earthcomputer/RedBuilder

If you want to reproduce the behaviour, remember to turn the mod setting called 'Enable Redstone Power Info' to true, or the lines won't ever appear. The lines still may not appear (this is the bug), though it helps to reload the chunks if you want to see them.

 

Thanks in advance for help, if any can be given!

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Link to comment
Share on other sites

Switching to DrawBlockHighlightEvent fixed the lines randomly disappearing (out of interest, why?).

- I have also changed GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT) to GlStateManager.disableDepth(), because it was causing other issues.

 

However there is still the problem that the lines are appearing black.

- I have tried GlStateManager.color(1f, 1f, 1f), that didn't fix it.

- I also discovered that when looking at a redstone torch with the debug screen open, the lines turn blue and partially transparent (doesn't work with redstone dust or when the debug screen is closed).

I can't figure out what's causing this problem, more help would be appreciated :)

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Link to comment
Share on other sites

After more code digging, I noticed that when the debug screen is opened, GlStateManager.enableTexture2D() is called, and GlStateManager.disableTexture2D() is not called, leading to the inconsistent behaviour with my lines.

 

So, I fixed all my problems with GlStateManager.disableTexture2D() and GlStateManager.disableDepth().

And we all lived happily ever after.

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

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

    • So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect. But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)   I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

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