Colorful Hearts

Colorful Hearts

12M Downloads

HeartRenderer does not provide DrawContext

Noaaan opened this issue ยท 3 comments

commented

As specified in the commit bae76d4, HeartRenderer does not use DrawContext. This is a problem, as adding compatibility for it forces the construction of our own DrawContext.

An example of this is the following Mixin snippet when porting Spectrum to 1.20:

	private void renderPlayerHeartsAzureDikeInjector(MatrixStack poseStack, PlayerEntity player, int x, int y, int maxHealth, int currentHealth, int displayHealth, int absorption, boolean renderHighlight, CallbackInfo ci) {
		InGameHud hud = MinecraftClient.getInstance().inGameHud;
		int scaledWidth = ((InGameHudAccessor) hud).getWidth();
		int scaledHeight = ((InGameHudAccessor) hud).getHeight();

                // Construct own DrawContext, as its not being passed. Loses data, and could produce undefined behavior or bugs
		DrawContext context = new DrawContext(MinecraftClient.getInstance(), MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers());
		context.getMatrices().multiplyPositionMatrix(poseStack.peek().getPositionMatrix());

                // Pass to our own API
		HudRenderers.renderAzureDike(context, scaledWidth, scaledHeight, player);
	}
commented

Ah, I missed switching to this. I'll get to it as soon as I am back from vacation (sometime next week).

commented

I assume that DrawContext referred to GuiGraphics from official mappings

EDIT: Also sorry for this taking so long.

commented

I just realised that there is no need for a mixin here. The way I do my injection is by just making it so that the vanilla render loop never starts, I do not overwrite the whole vanilla method. You can see that here

/**
* Disables the default heart renderer by setting for-loop index to -1 resulting in it never executing
* Also injects own heart render
*/
@ModifyVariable(method = "renderHearts", at = @At("STORE"), ordinal = 11)

The already present solution where your render is injected at TAIL of vanilla's renderHealthBar method should work without any issues