Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.15.2] [Solved] How can I render an Bounding Box?

Featured Replies

Posted

Hello! I recently tried to render an AxisAlignedBoundingBox, did a bit of research on rendering, and coded a bit, only to find out

that the code I ended up with doesn't work. I get less FPS, but not a single AABB is rendered.

@EventBusSubscriber(bus = Bus.FORGE, modid = References.MODID, value = Dist.CLIENT)
public class AABBDebug
{
	@SubscribeEvent
	public static void onRender(RenderWorldLastEvent event)
	{
		if(Minecraft.getInstance().world != null)
		{
			ArrayList<StructureData> structures = StructureDataHandler.getStructures(Minecraft.getInstance().world);
			if(structures == null)
				return;
			for(StructureData data : structures)
			{
		        IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
		        IVertexBuilder builder = buffer.getBuffer(RenderType.LINES);
		        MatrixStack matrixStack = event.getMatrixStack();

		        PlayerEntity player = Minecraft.getInstance().player;
		        double x = player.lastTickPosX + (player.getPosX() - player.lastTickPosX) * event.getPartialTicks();
		        double y = player.lastTickPosY + (player.getPosY() - player.lastTickPosY) * event.getPartialTicks();
		        double z = player.lastTickPosZ + (player.getPosZ() - player.lastTickPosZ) * event.getPartialTicks();

		        matrixStack.push();
		        matrixStack.translate(-x, -y, -z);
		        WorldRenderer.drawBoundingBox(matrixStack, builder, data.aabb.minX, data.aabb.minY, data.aabb.minZ, data.aabb.maxX, data.aabb.maxY, data.aabb.maxZ, 1.0f, 1.0f, 1, 1);
		        matrixStack.pop();
		        RenderSystem.disableDepthTest();
		        buffer.finish(RenderType.LINES);
			}
		}
	}
}

Thanks for any help

  • Budschie changed the title to [1.15.2] How can I render an Bounding Box?
  • Author

Ah, I see where my problem was. I used the wrong AxisAlignedBoundingBox. I should have offset it by it's position.

@EventBusSubscriber(bus = Bus.FORGE, modid = References.MODID, value = Dist.CLIENT)
public class AABBDebug
{
	@SubscribeEvent
	public static void onRender(RenderWorldLastEvent event)
	{
		if(Minecraft.getInstance().world != null)
		{
			System.out.println("Rendering...");
			ArrayList<StructureData> structures = StructureDataHandler.getStructures(Minecraft.getInstance().world);
			if(structures == null)
				return;
			for(StructureData data : structures)
			{
				AxisAlignedBB aabb = data.getTranslatedAABB();
				RenderSystem.lineWidth(10.0f);
		        IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
		        if(buffer == null)
		        	return;
		        IVertexBuilder builder = buffer.getBuffer(RenderType.LINES);
		        MatrixStack matrixStack = event.getMatrixStack();
		        PlayerEntity player = Minecraft.getInstance().player;
		        double x = player.lastTickPosX + (player.getPosX() - player.lastTickPosX) * event.getPartialTicks();
		        double y = player.lastTickPosY + (player.getPosY() - player.lastTickPosY) * event.getPartialTicks();
		        double z = player.lastTickPosZ + (player.getPosZ() - player.lastTickPosZ) * event.getPartialTicks();

		        matrixStack.push();
		        matrixStack.translate(-x, -y, -z);
		        WorldRenderer.drawBoundingBox(matrixStack, builder, aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ, 1.0f, 1.0f, 1.0f, 1.0f);
		        matrixStack.pop();
		        RenderSystem.disableDepthTest();
		        buffer.finish(RenderType.LINES);
			}
		}
	}
}

 

  • Budschie changed the title to [1.15.2] [Solved] How can I render an Bounding Box?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.