Skip to content

Commit

Permalink
Implement toString() for materials to help with debugging (#4347)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Jan 7, 2025
1 parent 339ab8c commit 8a54955
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ public MaterialFinder clear() {
public RenderMaterial find() {
return RenderMaterialImpl.byIndex(bits);
}

@Override
public String toString() {
return "MaterialFinderImpl{" + contentsToString() + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit 8a54955

Please sign in to comment.