Jump to content

Recommended Posts

Posted (edited)

I'm a little lost to be honest, my code isn't throwing any errors and after doing some debugging in console the values of all variables seem fine, yet I end up with no lines in my world space whatsoever.

I know that the actual rendering part of my code (should) work (because I used it in a hacked client before I wanted to recreate it as a forge mod), so I assume that I did something wrong when registering the listener or subscribing to the proper event.

 

Here is the code for registering the listener in my Main:

@EventHandler
public static void postInit(FMLPostInitializationEvent event) {
	MinecraftForge.EVENT_BUS.register(new EntityListener());
}

And here is the corresponding section in EntityListener

@SubscribeEvent
public void renderWorld(RenderWorldLastEvent event) {
	EntityTracker.onWorldRender();
}

Lastly here is the onWorldRender function in EntityTracker (I know this is a conflicting classname, didn't bother changing it yet as it shouldn't cause any issues (?), not like I plan to ever publish this anyway)

public static void onWorldRender() {	
	if(tracingHistory != null && tracingHistory.size() > 0) {
		if(Minecraft.getMinecraft().player == null) {
			return;
		}
		Vec3d player_pos = Minecraft.getMinecraft().player.getPositionVector();
		GlStateManager.pushMatrix();
		GlStateManager.disableTexture2D();
		GlStateManager.enableBlend();
		GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		GlStateManager.translate(-player_pos.x, -player_pos.y, -player_pos.z);
		final Tessellator tessellator = Tessellator.getInstance();
		final BufferBuilder bufferBuilder = tessellator.getBuffer();
		GL11.glEnable(GL11.GL_LINE_SMOOTH);
		bufferBuilder.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR);

		TracingData trace_data;
		TrackingData track_data;
		for(Iterator<TracingData> it=tracingHistory.iterator(); it.hasNext();) {
			trace_data = it.next();
			track_data=observedEntityID.get(trace_data.ID);
			trace_data.setupDrawingBuffer(bufferBuilder, track_data);
			if(System.currentTimeMillis() - trace_data.timeOfCreation >= (track_data.getTime()*1000) && ModuleManager.mode == 0) {
				//rendered time >= max time
				it.remove();
			}
		}

		tessellator.draw();
		GL11.glLineWidth(1.0f);
		GlStateManager.disableBlend();
		GlStateManager.enableTexture2D();
		GlStateManager.popMatrix();
	}
}

I should probably show what TracingData::setupDrawingBuffer does aswell

public void setupDrawingBuffer(BufferBuilder bufferBuilder ,TrackingData td) {
	GL11.glLineWidth(td.getThickness());
	//y1->y2 | x1->x2 | z1->z2
	bufferBuilder.pos(x1, y1, z1).color(0,0,0,0).endVertex();
	bufferBuilder.pos(x1, y2, z1).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos(x2, y2, z1).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos(x2, y2, z2).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
}

 

Sooo... any ideas? Would really appreciate help here.

Edited by BlazingTwist
Added version information in the title
Posted

Okay... NOW I am confused...

I changed a few things, I'm registering the listener in my client proxy now

public class ClientProxy extends CommonProxy{
	EntityTracker entityTracker;

  	@Override
	public void postInit(FMLPostInitializationEvent event) {
		super.postInit(event);
		entityTracker = new EntityTracker(this);
		MinecraftForge.EVENT_BUS.register(entityTracker);
	}
}

And I changed my onWorldRender function to not be static (as that messed with my eventlistener before, so I though 1+1=2, and it probably is, I just suck at math and got 3 instead)

I also minimized the use of GL11 and accessed GlStateManager instead.

public class EntityTracker {
	ClientProxy proxy;
	public static HashMap<String, TrackingData> observedEntityID = new HashMap<String, TrackingData>();
	public static ArrayList<TracingData> tracingHistory = new ArrayList<TracingData>();

	public EntityTracker(ClientProxy proxy){
		this.proxy = proxy;
	}

	@SubscribeEvent
	public void onWorldRender(RenderWorldLastEvent event) {
		if(tracingHistory == null || tracingHistory.size() <= 0) {
			return;
		}
		if(Minecraft.getMinecraft().player == null) {
			return;
		}
		Vec3d player_pos = Minecraft.getMinecraft().player.getPositionVector();
		GlStateManager.pushMatrix();
		GlStateManager.disableTexture2D();
		GlStateManager.enableBlend();
		GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		GlStateManager.translate(-player_pos.x, -player_pos.y, -player_pos.z);
		final Tessellator tessellator = Tessellator.getInstance();
		final BufferBuilder bufferBuilder = tessellator.getBuffer();
		bufferBuilder.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR);

		TracingData trace_data;
		TrackingData track_data;
		for(Iterator<TracingData> it=tracingHistory.iterator(); it.hasNext();) {
			trace_data = it.next();
			track_data=observedEntityID.get(trace_data.ID);
			trace_data.setupDrawingBuffer(bufferBuilder, track_data);
			if(System.currentTimeMillis()-trace_data.timeOfCreation>=(track_data.getTime()*1000) && ModuleManager.mode==0) {
				//rendered time >= max time
				it.remove();
			}
		}

		tessellator.draw();
		GlStateManager.glLineWidth(1.0f);
		GlStateManager.disableBlend();
		GlStateManager.enableTexture2D();
		GlStateManager.popMatrix();
	}
}

Also TracingData::setupDrawingBuffer() is doing a little bit more stuff now:

public void setupDrawingBuffer(BufferBuilder bufferBuilder ,TrackingData td) {
	GlStateManager.glLineWidth(td.getThickness());
	//y1->y2 | x1->x2 | z1->z2
	bufferBuilder.pos(x1, y1, z1).color(0,0,0,0).endVertex();
	bufferBuilder.pos(x1, y2, z1).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos(x2, y2, z1).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos(x2, y2, z2).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();

	//render bounding box lines
	bufferBuilder.pos((x2-0.49), (y2-0.49), (z2-0.49)).color(0,0,0,0).endVertex();
	bufferBuilder.pos((x2+0.49), (y2-0.49), (z2-0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2+0.49), (y2-0.49), (z2+0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2-0.49), (y2-0.49), (z2+0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2-0.49), (y2-0.49), (z2-0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2-0.49), (y2+0.49), (z2-0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2+0.49), (y2+0.49), (z2-0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2+0.49), (y2+0.49), (z2+0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2-0.49), (y2+0.49), (z2+0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2-0.49), (y2-0.49), (z2+0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
		
	//fill missing 3 lines
	bufferBuilder.pos((x2-0.49), (y2+0.49), (z2+0.49)).color(0,0,0,0).endVertex();
	bufferBuilder.pos((x2-0.49), (y2+0.49), (z2-0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2+0.49), (y2-0.49), (z2-0.49)).color(0,0,0,0).endVertex();
	bufferBuilder.pos((x2+0.49), (y2+0.49), (z2-0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
	bufferBuilder.pos((x2+0.49), (y2-0.49), (z2+0.49)).color(0,0,0,0).endVertex();
	bufferBuilder.pos((x2+0.49), (y2+0.49), (z2+0.49)).color(td.getRed(), td.getGreen(), td.getBlue(), td.getAlpha()).endVertex();
}

 

So, what's the problem now, you ask?

For some reason it DOES render the complete lower half of TracingData::setupDrawingBuffer, I get a flawless boundingbox, but it does NOT render the first 3 lines (y1->y2 | x1->x2 | z1->z2)

Posted (edited)

Case closed, I'm an idiot!

I just took a real close look at the debug and it turns out

x1=-981.5 | x2=-981.5 | y1=4.70253470330818 | y2=4.70253470330818 | z1=279.5 | z2=279.5

ALL variables are the same! I just missed it the first time I checked because the numbers were flying past so quickly.

It seems that Entity::posY and Entity::lastTickPosY are the same value.

 

Fixed by using Entity::prevPosY instead.

Edited by BlazingTwist

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



×
×
  • Create New...

Important Information

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