Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement toString() for materials to help with debugging #4347

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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