From 8a549559e3c213437d112a77bc3330359ccd60c9 Mon Sep 17 00:00:00 2001 From: Bruno Ploumhans <13494793+Technici4n@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:29:07 +0100 Subject: [PATCH] Implement toString() for materials to help with debugging (#4347) --- .../renderer/material/MaterialFinderImpl.java | 5 +++++ .../renderer/material/MaterialViewImpl.java | 16 ++++++++++++++++ .../renderer/material/RenderMaterialImpl.java | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/MaterialFinderImpl.java b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/MaterialFinderImpl.java index a696f88808..0fcc15cae6 100644 --- a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/MaterialFinderImpl.java +++ b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/MaterialFinderImpl.java @@ -109,4 +109,9 @@ public MaterialFinder clear() { public RenderMaterial find() { return RenderMaterialImpl.byIndex(bits); } + + @Override + public String toString() { + return "MaterialFinderImpl{" + contentsToString() + "}"; + } } diff --git a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/MaterialViewImpl.java b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/MaterialViewImpl.java index 255fe22f29..2f1b13ba30 100644 --- a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/MaterialViewImpl.java +++ b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/MaterialViewImpl.java @@ -18,6 +18,8 @@ import static net.fabricmc.fabric.impl.client.indigo.renderer.mesh.EncodingFormat.bitMask; +import java.util.Locale; + import net.minecraft.util.math.MathHelper; import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; @@ -111,4 +113,18 @@ public GlintMode glintMode() { public ShadeMode shadeMode() { return SHADE_MODES[(bits & SHADE_MODE_MASK) >>> SHADE_MODE_BIT_OFFSET]; } + + /** + * Returns a string representation of the material properties. + * To be used in {@link #toString} overrides so they show in the debugger. + */ + String contentsToString() { + return String.format("blend=%s, emissive=%b, disable diffuse=%b, ao=%s, glint=%s, shade=%s", + blendMode().toString().toLowerCase(Locale.ROOT), + emissive(), + disableDiffuse(), + ambientOcclusion().toString().toLowerCase(Locale.ROOT), + glintMode().toString().toLowerCase(Locale.ROOT), + shadeMode().toString().toLowerCase(Locale.ROOT)); + } } diff --git a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/RenderMaterialImpl.java b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/RenderMaterialImpl.java index ce313c08f0..efc3cf6c19 100644 --- a/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/RenderMaterialImpl.java +++ b/fabric-renderer-indigo/src/client/java/net/fabricmc/fabric/impl/client/indigo/renderer/material/RenderMaterialImpl.java @@ -38,6 +38,11 @@ public int index() { return bits; } + @Override + public String toString() { + return "RenderMaterialImpl{" + contentsToString() + "}"; + } + public static RenderMaterialImpl byIndex(int index) { return BY_INDEX[index]; }