Baritone AI pathfinder

Baritone AI pathfinder

72.7k Downloads

My "draw a coloured box" code ignores the colour if baritone is present, what is baritone doing?

CraftedFury opened this issue · 6 comments

commented

I have the following code (see below) that draws a coloured box around whatever BlockPos specified. It's handy for visually identifying blocks.

If baritone is present in the mods folder, it completely ignores the colour value I provide and is always grey. I can't figure out why... it's clearly overriding something somewhere, but I don't know if it's on purpose or toggle able.

public static void drawBox(BlockPos bp, int color) {
	if (bp == null)
		return;

	Minecraft mc = Minecraft.getMinecraft();
	double x = bp.getX() - mc.getRenderManager().viewerPosX;
	double y = bp.getY() - mc.getRenderManager().viewerPosY;
	double z = bp.getZ() - mc.getRenderManager().viewerPosZ;

	// Set GL Settings
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glEnable(GL11.GL_LINE_SMOOTH);
	GL11.glLineWidth(2.0F);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glDepthMask(false);

	float a = (color >> 24 & 0xFF) / 255.0F;
	float r = (color >> 16 & 0xFF) / 255.0F;
	float g = (color >> 8 & 0xFF) / 255.0F;
	float b = (color & 0xFF) / 255.0F;

	GL11.glPushMatrix();
	GL11.glColor4d(r, g, b, a);
	RenderGlobal.drawSelectionBoundingBox(new AxisAlignedBB(x, y, z, x + 1.0D, y + 1.0D, z + 1.0D), r, g, b, a);
	drawBoundingBox(new AxisAlignedBB(x, y, z, x + 1.0D, y + 1.0D, z + 1.0D), r, g, b); // calls a method that just uses `Tessellator tessellator = Tessellator.getInstance();` and `BufferBuilder builder = tessellator.getBuffer();` to build the coloured box
	GL11.glPopMatrix();

	// Reset GL Settings
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glDepthMask(true);
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glDisable(GL11.GL_LINE_SMOOTH);
}

If you comment out the drawBoundingBox( method call (which isn't really needed as an example), you can test this for yourself to see what I mean. Use a vivid colour like Yellow (new Color(0xFFFF55).getRGB()) as the color parameter, and add baritone-api-forge to see it turn gray.

I'm using baritone 1.2.10.

commented

Your open gl is messing with baritone's, usually it's blend or something. This isn't an issue for the baritone repo, this is GL rendering issue with your code.

commented

I have no clue dude, openGL with Minecraft is messy and Baritone uses different flags that conflict with yours. try checking the rendering code to see what flags it uses

commented

again, it's not a Baritone issue, it's an issue with your code conflicting with it's rendering. sorry, can't really help you there :/

commented

@S-B99 I've removed all GL code and all other Mixins and baritone is still forcing the colour to black/grey. I'm only using the built-in net.minecraft RenderGlobal class.

I'm not even sure what else I can do, if the built-in class doesn't play nice with baritone either.

public static void drawBox(BlockPos bp, int color) {
	if (bp == null) return;
	Minecraft mc = Minecraft.getMinecraft();
	double x = bp.getX() - mc.getRenderManager().viewerPosX;
	double y = bp.getY() - mc.getRenderManager().viewerPosY;
	double z = bp.getZ() - mc.getRenderManager().viewerPosZ;

	AxisAlignedBB box = new AxisAlignedBB(x, y, z, x + 1.0D, y + 1.0D, z + 1.0D);
	RenderGlobal.drawSelectionBoundingBox(box, r, g, b, a);
}
commented

Thanks for the idea to check the rendering code. I checked baritone's source code for all references to GL, and found

GlStateManager.disableLighting();

Line 48's GlStateManager.disableLighting(); has fixed my code.

@S-B99 Thank you.

commented

@S-B99 I have removed all GL code except for the tryBlendFuncSeparate, color and glLineWidth method calls. It's still grey. Not sure what's wrong with my code, it works fine when baritone isn't present.

Please help me figure out where I'm using blend or something incorrectly.

public static void drawBox(BlockPos bp, int color) {
	if (bp == null) return;
	Minecraft mc = Minecraft.getMinecraft();
	double x = bp.getX() - mc.getRenderManager().viewerPosX;
	double y = bp.getY() - mc.getRenderManager().viewerPosY;
	double z = bp.getZ() - mc.getRenderManager().viewerPosZ;

	GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
	GlStateManager.glLineWidth(2.0F);

	float a = (color >> 24 & 0xFF) / 255.0F;
	float r = (color >> 16 & 0xFF) / 255.0F;
	float g = (color >> 8 & 0xFF) / 255.0F;
	float b = (color & 0xFF) / 255.0F;

	GlStateManager.color(r, g, b, a);
	AxisAlignedBB box = new AxisAlignedBB(x, y, z, x + 1.0D, y + 1.0D, z + 1.0D);
	RenderGlobal.drawSelectionBoundingBox(box, r, g, b, a);
}