Jump to content

Recommended Posts

Posted

This is my first Forge mod for 1.15.2.

I'm trying to render 3d lines into the world.

Previously I used the RenderWorldLastEvent, but after I disabled Clouds in the Video settings I noticed, that the event wasn't being called anymore.

This led me to believe, that I may have used the wrong event for this kind of stuff.

 

This is the code I use to draw an outline around an area:

//The method that should be called by the event
public void render() {
	if(pos1 != null && pos2 != null) {
      	//The next few lines calculate, where to render the area
		int[] xList = new int[4];
		int[] yList = new int[4];
		int[] zList = new int[4];
		
		xList[0] = pos1.getX();
		xList[1] = pos1.getX()+1;
		yList[0] = pos1.getY();
		yList[1] = pos1.getY()+1;
		zList[0] = pos1.getZ();
		zList[1] = pos1.getZ()+1;
		
		xList[2] = pos2.getX();
		xList[3] = pos2.getX()+1;
		yList[2] = pos2.getY();
		yList[3] = pos2.getY()+1;
		zList[2] = pos2.getZ();
		zList[3] = pos2.getZ()+1;
		
		int minX = Integer.MAX_VALUE;
		int minY = Integer.MAX_VALUE;
		int minZ = Integer.MAX_VALUE;
		int maxX = Integer.MIN_VALUE;
		int maxY = Integer.MIN_VALUE;
		int maxZ = Integer.MIN_VALUE;
		
		for(int x : xList) {
			if(x < minX) minX = x;
			if(x > maxX) maxX = x;
		}
		
		for(int y : yList) {
			if(y < minY) minY = y;
			if(y > maxY) maxY = y;
		}
		
		for(int z : zList) {
			if(z < minZ) minZ = z;
			if(z > maxZ) maxZ = z;
		}
		
      	//Render the first area
		AxisAlignedBB aabb = new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
		renderArea(aabb, 1.0f, 1.0f, 1.0f);
      	//If position 3 is set, render the second area in another color
		if(pos3 != null) {
			AxisAlignedBB aabb2 = new AxisAlignedBB(pos3.getX(), pos3.getY(), pos3.getZ(), pos3.getX() + (maxX - minX), pos3.getY() + (maxY - minY), pos3.getZ() + (maxZ - minZ));
			renderArea(aabb2, 1.0f, 0.33f, 0.33f);
		}
	}
}

//Contains the code to do the actual rendering
public void renderArea(AxisAlignedBB aabb, float r, float g, float b) {
	Minecraft mc = Minecraft.getInstance();
	Vec3d pos = mc.getRenderManager().info.getProjectedView();
	float yaw = mc.getRenderManager().info.getYaw();
	float pitch = mc.getRenderManager().info.getPitch();
	
	GL11.glPushMatrix();
  	//Rotate after the camera
	GL11.glRotated(yaw-180, 0, 1, 0);
	GL11.glRotated(pitch, -Math.sin((yaw + 90) / 360 * Math.PI * 2), 0, Math.cos((yaw + 90) / 360 * Math.PI * 2));
  	//Translation
	GL11.glTranslated(-pos.x, -pos.y, -pos.z);
  	//Expand the area for better visibility
	aabb = aabb.expand(0.01, 0.01, 0.01);
	aabb = aabb.offset(-0.005, -0.005, -0.005);
  	//Color
	RenderSystem.color4f(r, g, b, 1.0f);
	GL11.glLineWidth(4);
  	//Vertices
	GL11.glBegin(GL11.GL_LINES);
	GL11.glVertex3d(aabb.minX, aabb.minY, aabb.minZ);
	GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.minZ);
	
	GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.minZ);
	GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.minZ);
	
	GL11.glVertex3d(aabb.minX, aabb.minY, aabb.minZ);
	GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.minZ);
	
	GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.minZ);
	GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.minZ);
	
	GL11.glVertex3d(aabb.minX, aabb.minY, aabb.maxZ);
	GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.maxZ);
	
	GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.maxZ);
	GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.maxZ);
	GL11.glVertex3d(aabb.minX, aabb.minY, aabb.maxZ);
	GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.maxZ);
	
	GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.maxZ);
	GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.maxZ);
	
	GL11.glVertex3d(aabb.minX, aabb.minY, aabb.minZ);
	GL11.glVertex3d(aabb.minX, aabb.minY, aabb.maxZ);
	
	GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.minZ);
	GL11.glVertex3d(aabb.minX, aabb.maxY, aabb.maxZ);
	
	GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.minZ);
	GL11.glVertex3d(aabb.maxX, aabb.minY, aabb.maxZ);
	
	GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.minZ);
	GL11.glVertex3d(aabb.maxX, aabb.maxY, aabb.maxZ);
	GL11.glEnd();
	GL11.glPopMatrix();
}

 

Posted (edited)

Hi

 

I've got an example mod that has two examples of rendering 3D lines

https://github.com/TheGreyGhost/MinecraftByExample

see

mbe21-RenderLines

and 

DebugBlockVoxelShapeHighlighter

 

There is some further advice in this link about rendering and using RenderWorldLastEvent:

https://gist.github.com/williewillus/353c872bcf1a6ace9921189f6100d09a

 

The appropriate event for rendering depends on when you want to render them; is it related to a block or item, or related to the player, or does it occur all the time?  Perhaps describe for us in more detail what the gameplay effect you're trying to achieve is?

 

-TGG

Edited by TheGreyGhost
Posted
13 hours ago, TheGreyGhost said:

Perhaps describe for us in more detail what the gameplay effect you're trying to achieve is?

The idea is a mod, with wich you can highlight a specific block area.

You can just press a key while looking at a block and the mod saves the position.

After selecting two positions the mod will highlight the area between them.

When pressing another keybind the mod will open a GUI.

In this GUI you can select what operation should be executed. ("fill" or "clone")

The mod will automatically generate the correct fill or clone command and execute it on behalf of the player.

This is intended to make executing commands quicker.

 

I have uploaded a video on youtube (unlisted) that shows how the mod is used and what problems it has.

 

 

Posted

Hi

 

In that case the DrawHighlightEvent is definitely the one you want.

 

Funnily enough one of my first mods was the same thing, great minds think alike obviously :P  Abandoned it in 1.8 because it was too much work to keep up to date...

 

 

-TGG

 

Posted

Nice mod!

The only problem now is that the DrawHighlightEvent is only called when the player highlights a block.

But the player should also see the structure when it is not targeted.

It should look similar to a structure block for example.

Thanks for the help though!

You should really continue that mod!

Posted

Ah, ok.

 

In that case RenderWorldLastEvent probably is the best one - I've never seen that disabling clouds problem with it.  Might be worth tracing into updateCameraAndRender() to see why.  It might be a forge bug perhaps...

 

Or perhaps your drawing code is wrong (relying on the renderer to be in a particular state, and this state changes if you turn the clouds off).  I think in any case you should convert your direct calls into the proper RenderType and IVertexBuffer calls.

 

-TGG

 

PS That mod is dead and buried a long time ago now :)  Too many projects, too little time...

 

 

Posted
public void renderArea(AxisAlignedBB aabb, float r, float g, float b) {
		RenderSystem.pushMatrix();
		ActiveRenderInfo info = Minecraft.getInstance().getRenderManager().info;
		RenderSystem.rotatef(info.getYaw()-180, 0, 1, 0);
		RenderSystem.rotatef(info.getPitch(), (float) (-Math.sin((info.getYaw() + 90) / 360 * Math.PI * 2)), 0.0f, (float) (Math.cos((info.getYaw() + 90) / 360 * Math.PI * 2)));
		RenderSystem.translated(-info.getProjectedView().x, -info.getProjectedView().y, -info.getProjectedView().z);
		RenderSystem.lineWidth(4);
		RenderSystem.color4f(r, g, b, 1.0f);
		
		aabb = aabb.expand(0.001, 0.001, 0.001);
		aabb = aabb.offset(-0.0005, -0.0005, -0.0005);
		
		Tessellator tessellator = Tessellator.getInstance();
		BufferBuilder builder = tessellator.getBuffer();
		builder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION);
		builder.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
		builder.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
		
		builder.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
		builder.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
		
		builder.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
		builder.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
		
		builder.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
		builder.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
		
		builder.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
		builder.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
		
		builder.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
		builder.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();
		
		builder.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
		builder.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
		
		builder.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
		builder.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();
		
		builder.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex();
		builder.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex();
		
		builder.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex();
		builder.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex();
		
		builder.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex();
		builder.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex();
		
		builder.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex();
		builder.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex();
		tessellator.draw();
		RenderSystem.popMatrix();
	}

 

I have changed the renderArea method to this and it still has the same problems.

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.