| 1 | package net.minecraft.client.gui.components.debug;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.platform.Window;
|
| 4 | import com.mojang.blaze3d.systems.RenderSystem;
|
| 5 | import com.mojang.renderpearl.api.device.DeviceInfo;
|
| 6 | import com.mojang.renderpearl.api.device.DeviceType;
|
| 7 | import java.util.List;
|
| 8 | import java.util.Locale;
|
| 9 | import net.fabricmc.api.EnvType;
|
| 10 | import net.fabricmc.api.Environment;
|
| 11 | import net.minecraft.client.Minecraft;
|
| 12 | import net.minecraft.resources.Identifier;
|
| 13 | import net.minecraft.world.level.Level;
|
| 14 | import net.minecraft.world.level.chunk.LevelChunk;
|
| 15 | import org.jspecify.annotations.Nullable;
|
| 16 | import oshi.SystemInfo;
|
| 17 | import oshi.hardware.CentralProcessor;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class DebugEntrySystemSpecs implements DebugScreenEntry {
|
| 21 | private static final Identifier GROUP = Identifier.withDefaultNamespace("system");
|
| 22 | private static @Nullable String cpuInfo;
|
| 23 |
|
| 24 | public static String getCpuInfo() {
|
| 25 | if (cpuInfo == null) {
|
| 26 | cpuInfo = "<unknown>";
|
| 27 |
|
| 28 | try {
|
| 29 | CentralProcessor processor = new SystemInfo().getHardware().getProcessor();
|
| 30 | cpuInfo = String.format(Locale.ROOT, "%dx %s", processor.getLogicalProcessorCount(), processor.getProcessorIdentifier().getName()).replaceAll("\\s+", " ");
|
| 31 | } catch (Throwable var1) {
|
| 32 | }
|
| 33 | }
|
| 34 |
|
| 35 | return cpuInfo;
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | public void display(
|
| 40 | final DebugScreenDisplayer displayer,
|
| 41 | final @Nullable Level serverOrClientLevel,
|
| 42 | final @Nullable LevelChunk clientChunk,
|
| 43 | final @Nullable LevelChunk serverChunk
|
| 44 | ) {
|
| 45 | DeviceInfo deviceInfo = RenderSystem.getDevice().getDeviceInfo();
|
| 46 | Window window = Minecraft.getInstance().getWindow();
|
| 47 | displayer.addToGroup(
|
| 48 | GROUP,
|
| 49 | List.of(
|
| 50 | String.format(Locale.ROOT, "Java: %s", System.getProperty("java.version")),
|
| 51 | String.format(Locale.ROOT, "CPU: %s", getCpuInfo()),
|
| 52 | String.format(Locale.ROOT, "Display: %dx%d (%s)", window.getWidth(), window.getHeight(), deviceInfo.vendorName()),
|
| 53 | String.format(Locale.ROOT, "Window: %dx%d (%.2fx pixel density)", window.getScreenWidth(), window.getScreenHeight(), window.getPixelDensity()),
|
| 54 | String.format(Locale.ROOT, "%s%s", deviceInfo.name(), this.typeName(deviceInfo.type())),
|
| 55 | String.format(Locale.ROOT, "%s %s", deviceInfo.backendName(), this.firstLine(deviceInfo.driverInfo()))
|
| 56 | )
|
| 57 | );
|
| 58 | }
|
| 59 |
|
| 60 | private String firstLine(final String value) {
|
| 61 | return value.lines().findFirst().orElse(value);
|
| 62 | }
|
| 63 |
|
| 64 | private String typeName(final DeviceType type) {
|
| 65 | return switch (type) {
|
| 66 | case OTHER -> "";
|
| 67 | case INTEGRATED -> " (iGPU)";
|
| 68 | case DISCRETE -> " (dGPU)";
|
| 69 | case VIRTUAL -> " (vGPU)";
|
| 70 | case CPU -> " (software)";
|
| 71 | };
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | public boolean isAllowed(final boolean reducedDebugInfo) {
|
| 76 | return true;
|
| 77 | }
|
| 78 | }
|
| 79 |
|