Spaces:
Build error
Build error
File size: 29,820 Bytes
d46f4a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
package net.minecraft.client.gui.components;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.GlUtil;
import com.mojang.datafixers.DataFixUtils;
import it.unimi.dsi.fastutil.longs.LongSet;
import it.unimi.dsi.fastutil.longs.LongSets;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.EnumMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import net.minecraft.ChatFormatting;
import net.minecraft.SharedConstants;
import net.minecraft.Util;
import net.minecraft.client.ClientBrandRetriever;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.debugchart.BandwidthDebugChart;
import net.minecraft.client.gui.components.debugchart.FpsDebugChart;
import net.minecraft.client.gui.components.debugchart.PingDebugChart;
import net.minecraft.client.gui.components.debugchart.ProfilerPieChart;
import net.minecraft.client.gui.components.debugchart.TpsDebugChart;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.Connection;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.ServerTickRateManager;
import net.minecraft.server.level.ChunkResult;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth;
import net.minecraft.util.debugchart.LocalSampleLogger;
import net.minecraft.util.debugchart.RemoteDebugSampleType;
import net.minecraft.util.debugchart.TpsDebugDimensions;
import net.minecraft.util.profiling.Profiler;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.util.profiling.Zone;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.TickRateManager;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.NaturalSpawner;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class DebugScreenOverlay {
private static final int COLOR_GREY = 14737632;
private static final int MARGIN_RIGHT = 2;
private static final int MARGIN_LEFT = 2;
private static final int MARGIN_TOP = 2;
private static final Map<Heightmap.Types, String> HEIGHTMAP_NAMES = Util.make(new EnumMap<>(Heightmap.Types.class), p_94070_ -> {
p_94070_.put(Heightmap.Types.WORLD_SURFACE_WG, "SW");
p_94070_.put(Heightmap.Types.WORLD_SURFACE, "S");
p_94070_.put(Heightmap.Types.OCEAN_FLOOR_WG, "OW");
p_94070_.put(Heightmap.Types.OCEAN_FLOOR, "O");
p_94070_.put(Heightmap.Types.MOTION_BLOCKING, "M");
p_94070_.put(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, "ML");
});
private final Minecraft minecraft;
private final DebugScreenOverlay.AllocationRateCalculator allocationRateCalculator;
private final Font font;
private HitResult block;
private HitResult liquid;
@Nullable
private ChunkPos lastPos;
@Nullable
private LevelChunk clientChunk;
@Nullable
private CompletableFuture<LevelChunk> serverChunk;
private boolean renderDebug;
private boolean renderProfilerChart;
private boolean renderFpsCharts;
private boolean renderNetworkCharts;
private final LocalSampleLogger frameTimeLogger = new LocalSampleLogger(1);
private final LocalSampleLogger tickTimeLogger = new LocalSampleLogger(TpsDebugDimensions.values().length);
private final LocalSampleLogger pingLogger = new LocalSampleLogger(1);
private final LocalSampleLogger bandwidthLogger = new LocalSampleLogger(1);
private final Map<RemoteDebugSampleType, LocalSampleLogger> remoteSupportingLoggers = Map.of(RemoteDebugSampleType.TICK_TIME, this.tickTimeLogger);
private final FpsDebugChart fpsChart;
private final TpsDebugChart tpsChart;
private final PingDebugChart pingChart;
private final BandwidthDebugChart bandwidthChart;
private final ProfilerPieChart profilerPieChart;
public DebugScreenOverlay(Minecraft p_94039_) {
this.minecraft = p_94039_;
this.allocationRateCalculator = new DebugScreenOverlay.AllocationRateCalculator();
this.font = p_94039_.font;
this.fpsChart = new FpsDebugChart(this.font, this.frameTimeLogger);
this.tpsChart = new TpsDebugChart(this.font, this.tickTimeLogger, () -> p_94039_.level.tickRateManager().millisecondsPerTick());
this.pingChart = new PingDebugChart(this.font, this.pingLogger);
this.bandwidthChart = new BandwidthDebugChart(this.font, this.bandwidthLogger);
this.profilerPieChart = new ProfilerPieChart(this.font);
}
public void clearChunkCache() {
this.serverChunk = null;
this.clientChunk = null;
}
public void render(GuiGraphics p_281427_) {
ProfilerFiller profilerfiller = Profiler.get();
profilerfiller.push("debug");
Entity entity = this.minecraft.getCameraEntity();
this.block = entity.pick(20.0, 0.0F, false);
this.liquid = entity.pick(20.0, 0.0F, true);
this.drawGameInformation(p_281427_);
this.drawSystemInformation(p_281427_);
this.profilerPieChart.setBottomOffset(10);
if (this.renderFpsCharts) {
int i = p_281427_.guiWidth();
int j = i / 2;
this.fpsChart.drawChart(p_281427_, 0, this.fpsChart.getWidth(j));
if (this.tickTimeLogger.size() > 0) {
int k = this.tpsChart.getWidth(j);
this.tpsChart.drawChart(p_281427_, i - k, k);
}
this.profilerPieChart.setBottomOffset(this.tpsChart.getFullHeight());
}
if (this.renderNetworkCharts) {
int l = p_281427_.guiWidth();
int i1 = l / 2;
if (!this.minecraft.isLocalServer()) {
this.bandwidthChart.drawChart(p_281427_, 0, this.bandwidthChart.getWidth(i1));
}
int j1 = this.pingChart.getWidth(i1);
this.pingChart.drawChart(p_281427_, l - j1, j1);
this.profilerPieChart.setBottomOffset(this.pingChart.getFullHeight());
}
try (Zone zone = profilerfiller.zone("profilerPie")) {
this.profilerPieChart.render(p_281427_);
}
profilerfiller.pop();
}
protected void drawGameInformation(GuiGraphics p_281525_) {
List<String> list = this.getGameInformation();
list.add("");
boolean flag = this.minecraft.getSingleplayerServer() != null;
list.add(
"Debug charts: [F3+1] Profiler "
+ (this.renderProfilerChart ? "visible" : "hidden")
+ "; [F3+2] "
+ (flag ? "FPS + TPS " : "FPS ")
+ (this.renderFpsCharts ? "visible" : "hidden")
+ "; [F3+3] "
+ (!this.minecraft.isLocalServer() ? "Bandwidth + Ping" : "Ping")
+ (this.renderNetworkCharts ? " visible" : " hidden")
);
list.add("For help: press F3 + Q");
this.renderLines(p_281525_, list, true);
}
protected void drawSystemInformation(GuiGraphics p_281261_) {
List<String> list = this.getSystemInformation();
this.renderLines(p_281261_, list, false);
}
private void renderLines(GuiGraphics p_286519_, List<String> p_286665_, boolean p_286644_) {
int i = 9;
for (int j = 0; j < p_286665_.size(); j++) {
String s = p_286665_.get(j);
if (!Strings.isNullOrEmpty(s)) {
int k = this.font.width(s);
int l = p_286644_ ? 2 : p_286519_.guiWidth() - 2 - k;
int i1 = 2 + i * j;
p_286519_.fill(l - 1, i1 - 1, l + k + 1, i1 + i - 1, -1873784752);
}
}
for (int j1 = 0; j1 < p_286665_.size(); j1++) {
String s1 = p_286665_.get(j1);
if (!Strings.isNullOrEmpty(s1)) {
int k1 = this.font.width(s1);
int l1 = p_286644_ ? 2 : p_286519_.guiWidth() - 2 - k1;
int i2 = 2 + i * j1;
p_286519_.drawString(this.font, s1, l1, i2, 14737632, false);
}
}
}
protected List<String> getGameInformation() {
IntegratedServer integratedserver = this.minecraft.getSingleplayerServer();
ClientPacketListener clientpacketlistener = this.minecraft.getConnection();
Connection connection = clientpacketlistener.getConnection();
float f = connection.getAverageSentPackets();
float f1 = connection.getAverageReceivedPackets();
TickRateManager tickratemanager = this.getLevel().tickRateManager();
String s1;
if (tickratemanager.isSteppingForward()) {
s1 = " (frozen - stepping)";
} else if (tickratemanager.isFrozen()) {
s1 = " (frozen)";
} else {
s1 = "";
}
String s;
if (integratedserver != null) {
ServerTickRateManager servertickratemanager = integratedserver.tickRateManager();
boolean flag = servertickratemanager.isSprinting();
if (flag) {
s1 = " (sprinting)";
}
String s2 = flag ? "-" : String.format(Locale.ROOT, "%.1f", tickratemanager.millisecondsPerTick());
s = String.format(Locale.ROOT, "Integrated server @ %.1f/%s ms%s, %.0f tx, %.0f rx", integratedserver.getCurrentSmoothedTickTime(), s2, s1, f, f1);
} else {
s = String.format(Locale.ROOT, "\"%s\" server%s, %.0f tx, %.0f rx", clientpacketlistener.serverBrand(), s1, f, f1);
}
BlockPos blockpos = this.minecraft.getCameraEntity().blockPosition();
if (this.minecraft.showOnlyReducedInfo()) {
return Lists.newArrayList(
"Minecraft " + SharedConstants.getCurrentVersion().getName() + " (" + this.minecraft.getLaunchedVersion() + "/" + ClientBrandRetriever.getClientModName() + ")",
this.minecraft.fpsString,
s,
this.minecraft.levelRenderer.getSectionStatistics(),
this.minecraft.levelRenderer.getEntityStatistics(),
"P: " + this.minecraft.particleEngine.countParticles() + ". T: " + this.minecraft.level.getEntityCount(),
this.minecraft.level.gatherChunkSourceStats(),
"",
String.format(Locale.ROOT, "Chunk-relative: %d %d %d", blockpos.getX() & 15, blockpos.getY() & 15, blockpos.getZ() & 15)
);
} else {
Entity entity = this.minecraft.getCameraEntity();
Direction direction = entity.getDirection();
String $$21 = switch (direction) {
case NORTH -> "Towards negative Z";
case SOUTH -> "Towards positive Z";
case WEST -> "Towards negative X";
case EAST -> "Towards positive X";
default -> "Invalid";
};
ChunkPos chunkpos = new ChunkPos(blockpos);
if (!Objects.equals(this.lastPos, chunkpos)) {
this.lastPos = chunkpos;
this.clearChunkCache();
}
Level level = this.getLevel();
LongSet longset = (LongSet)(level instanceof ServerLevel ? ((ServerLevel)level).getForcedChunks() : LongSets.EMPTY_SET);
List<String> list = Lists.newArrayList(
"Minecraft "
+ SharedConstants.getCurrentVersion().getName()
+ " ("
+ this.minecraft.getLaunchedVersion()
+ "/"
+ ClientBrandRetriever.getClientModName()
+ ("release".equalsIgnoreCase(this.minecraft.getVersionType()) ? "" : "/" + this.minecraft.getVersionType())
+ ")",
this.minecraft.fpsString,
s,
this.minecraft.levelRenderer.getSectionStatistics(),
this.minecraft.levelRenderer.getEntityStatistics(),
"P: " + this.minecraft.particleEngine.countParticles() + ". T: " + this.minecraft.level.getEntityCount(),
this.minecraft.level.gatherChunkSourceStats()
);
String s4 = this.getServerChunkStats();
if (s4 != null) {
list.add(s4);
}
list.add(this.minecraft.level.dimension().location() + " FC: " + longset.size());
list.add("");
list.add(
String.format(
Locale.ROOT,
"XYZ: %.3f / %.5f / %.3f",
this.minecraft.getCameraEntity().getX(),
this.minecraft.getCameraEntity().getY(),
this.minecraft.getCameraEntity().getZ()
)
);
list.add(
String.format(
Locale.ROOT,
"Block: %d %d %d [%d %d %d]",
blockpos.getX(),
blockpos.getY(),
blockpos.getZ(),
blockpos.getX() & 15,
blockpos.getY() & 15,
blockpos.getZ() & 15
)
);
list.add(
String.format(
Locale.ROOT,
"Chunk: %d %d %d [%d %d in r.%d.%d.mca]",
chunkpos.x,
SectionPos.blockToSectionCoord(blockpos.getY()),
chunkpos.z,
chunkpos.getRegionLocalX(),
chunkpos.getRegionLocalZ(),
chunkpos.getRegionX(),
chunkpos.getRegionZ()
)
);
list.add(
String.format(Locale.ROOT, "Facing: %s (%s) (%.1f / %.1f)", direction, $$21, Mth.wrapDegrees(entity.getYRot()), Mth.wrapDegrees(entity.getXRot()))
);
LevelChunk levelchunk = this.getClientChunk();
if (levelchunk.isEmpty()) {
list.add("Waiting for chunk...");
} else {
int i = this.minecraft.level.getChunkSource().getLightEngine().getRawBrightness(blockpos, 0);
int j = this.minecraft.level.getBrightness(LightLayer.SKY, blockpos);
int k = this.minecraft.level.getBrightness(LightLayer.BLOCK, blockpos);
list.add("Client Light: " + i + " (" + j + " sky, " + k + " block)");
LevelChunk levelchunk1 = this.getServerChunk();
StringBuilder stringbuilder = new StringBuilder("CH");
for (Heightmap.Types heightmap$types : Heightmap.Types.values()) {
if (heightmap$types.sendToClient()) {
stringbuilder.append(" ")
.append(HEIGHTMAP_NAMES.get(heightmap$types))
.append(": ")
.append(levelchunk.getHeight(heightmap$types, blockpos.getX(), blockpos.getZ()));
}
}
list.add(stringbuilder.toString());
stringbuilder.setLength(0);
stringbuilder.append("SH");
for (Heightmap.Types heightmap$types1 : Heightmap.Types.values()) {
if (heightmap$types1.keepAfterWorldgen()) {
stringbuilder.append(" ").append(HEIGHTMAP_NAMES.get(heightmap$types1)).append(": ");
if (levelchunk1 != null) {
stringbuilder.append(levelchunk1.getHeight(heightmap$types1, blockpos.getX(), blockpos.getZ()));
} else {
stringbuilder.append("??");
}
}
}
list.add(stringbuilder.toString());
if (this.minecraft.level.isInsideBuildHeight(blockpos.getY())) {
list.add("Biome: " + printBiome(this.minecraft.level.getBiome(blockpos)));
if (levelchunk1 != null) {
float f2 = level.getMoonBrightness();
long l = levelchunk1.getInhabitedTime();
DifficultyInstance difficultyinstance = new DifficultyInstance(level.getDifficulty(), level.getDayTime(), l, f2);
list.add(
String.format(
Locale.ROOT,
"Local Difficulty: %.2f // %.2f (Day %d)",
difficultyinstance.getEffectiveDifficulty(),
difficultyinstance.getSpecialMultiplier(),
this.minecraft.level.getDayTime() / 24000L
)
);
} else {
list.add("Local Difficulty: ??");
}
}
if (levelchunk1 != null && levelchunk1.isOldNoiseGeneration()) {
list.add("Blending: Old");
}
}
ServerLevel serverlevel = this.getServerLevel();
if (serverlevel != null) {
ServerChunkCache serverchunkcache = serverlevel.getChunkSource();
ChunkGenerator chunkgenerator = serverchunkcache.getGenerator();
RandomState randomstate = serverchunkcache.randomState();
chunkgenerator.addDebugScreenInfo(list, randomstate, blockpos);
Climate.Sampler climate$sampler = randomstate.sampler();
BiomeSource biomesource = chunkgenerator.getBiomeSource();
biomesource.addDebugInfo(list, blockpos, climate$sampler);
NaturalSpawner.SpawnState naturalspawner$spawnstate = serverchunkcache.getLastSpawnState();
if (naturalspawner$spawnstate != null) {
Object2IntMap<MobCategory> object2intmap = naturalspawner$spawnstate.getMobCategoryCounts();
int i1 = naturalspawner$spawnstate.getSpawnableChunkCount();
list.add(
"SC: "
+ i1
+ ", "
+ Stream.of(MobCategory.values())
.map(p_94068_ -> Character.toUpperCase(p_94068_.getName().charAt(0)) + ": " + object2intmap.getInt(p_94068_))
.collect(Collectors.joining(", "))
);
} else {
list.add("SC: N/A");
}
}
ResourceLocation resourcelocation = this.minecraft.gameRenderer.currentPostEffect();
if (resourcelocation != null) {
list.add("Post: " + resourcelocation);
}
list.add(this.minecraft.getSoundManager().getDebugString() + String.format(Locale.ROOT, " (Mood %d%%)", Math.round(this.minecraft.player.getCurrentMood() * 100.0F)));
return list;
}
}
private static String printBiome(Holder<Biome> p_205375_) {
return p_205375_.unwrap().map(p_205377_ -> p_205377_.location().toString(), p_325324_ -> "[unregistered " + p_325324_ + "]");
}
@Nullable
private ServerLevel getServerLevel() {
IntegratedServer integratedserver = this.minecraft.getSingleplayerServer();
return integratedserver != null ? integratedserver.getLevel(this.minecraft.level.dimension()) : null;
}
@Nullable
private String getServerChunkStats() {
ServerLevel serverlevel = this.getServerLevel();
return serverlevel != null ? serverlevel.gatherChunkSourceStats() : null;
}
private Level getLevel() {
return DataFixUtils.orElse(
Optional.ofNullable(this.minecraft.getSingleplayerServer()).flatMap(p_374571_ -> Optional.ofNullable(p_374571_.getLevel(this.minecraft.level.dimension()))),
this.minecraft.level
);
}
@Nullable
private LevelChunk getServerChunk() {
if (this.serverChunk == null) {
ServerLevel serverlevel = this.getServerLevel();
if (serverlevel == null) {
return null;
}
this.serverChunk = serverlevel.getChunkSource()
.getChunkFuture(this.lastPos.x, this.lastPos.z, ChunkStatus.FULL, false)
.thenApply(p_325326_ -> (LevelChunk)p_325326_.orElse(null));
}
return this.serverChunk.getNow(null);
}
private LevelChunk getClientChunk() {
if (this.clientChunk == null) {
this.clientChunk = this.minecraft.level.getChunk(this.lastPos.x, this.lastPos.z);
}
return this.clientChunk;
}
protected List<String> getSystemInformation() {
long i = Runtime.getRuntime().maxMemory();
long j = Runtime.getRuntime().totalMemory();
long k = Runtime.getRuntime().freeMemory();
long l = j - k;
List<String> list = Lists.newArrayList(
String.format(Locale.ROOT, "Java: %s", System.getProperty("java.version")),
String.format(Locale.ROOT, "Mem: %2d%% %03d/%03dMB", l * 100L / i, bytesToMegabytes(l), bytesToMegabytes(i)),
String.format(Locale.ROOT, "Allocation rate: %03dMB/s", bytesToMegabytes(this.allocationRateCalculator.bytesAllocatedPerSecond(l))),
String.format(Locale.ROOT, "Allocated: %2d%% %03dMB", j * 100L / i, bytesToMegabytes(j)),
"",
String.format(Locale.ROOT, "CPU: %s", GlUtil.getCpuInfo()),
"",
String.format(
Locale.ROOT, "Display: %dx%d (%s)", Minecraft.getInstance().getWindow().getWidth(), Minecraft.getInstance().getWindow().getHeight(), GlUtil.getVendor()
),
GlUtil.getRenderer(),
GlUtil.getOpenGLVersion()
);
if (this.minecraft.showOnlyReducedInfo()) {
return list;
} else {
if (this.block.getType() == HitResult.Type.BLOCK) {
BlockPos blockpos = ((BlockHitResult)this.block).getBlockPos();
BlockState blockstate = this.minecraft.level.getBlockState(blockpos);
list.add("");
list.add(ChatFormatting.UNDERLINE + "Targeted Block: " + blockpos.getX() + ", " + blockpos.getY() + ", " + blockpos.getZ());
list.add(String.valueOf(BuiltInRegistries.BLOCK.getKey(blockstate.getBlock())));
for (Entry<Property<?>, Comparable<?>> entry : blockstate.getValues().entrySet()) {
list.add(this.getPropertyValueString(entry));
}
blockstate.getTags().map(p_325325_ -> "#" + p_325325_.location()).forEach(list::add);
}
if (this.liquid.getType() == HitResult.Type.BLOCK) {
BlockPos blockpos1 = ((BlockHitResult)this.liquid).getBlockPos();
FluidState fluidstate = this.minecraft.level.getFluidState(blockpos1);
list.add("");
list.add(ChatFormatting.UNDERLINE + "Targeted Fluid: " + blockpos1.getX() + ", " + blockpos1.getY() + ", " + blockpos1.getZ());
list.add(String.valueOf(BuiltInRegistries.FLUID.getKey(fluidstate.getType())));
for (Entry<Property<?>, Comparable<?>> entry1 : fluidstate.getValues().entrySet()) {
list.add(this.getPropertyValueString(entry1));
}
fluidstate.getTags().map(p_325328_ -> "#" + p_325328_.location()).forEach(list::add);
}
Entity entity = this.minecraft.crosshairPickEntity;
if (entity != null) {
list.add("");
list.add(ChatFormatting.UNDERLINE + "Targeted Entity");
list.add(String.valueOf(BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType())));
}
return list;
}
}
private String getPropertyValueString(Entry<Property<?>, Comparable<?>> p_94072_) {
Property<?> property = p_94072_.getKey();
Comparable<?> comparable = p_94072_.getValue();
String s = Util.getPropertyName(property, comparable);
if (Boolean.TRUE.equals(comparable)) {
s = ChatFormatting.GREEN + s;
} else if (Boolean.FALSE.equals(comparable)) {
s = ChatFormatting.RED + s;
}
return property.getName() + ": " + s;
}
private static long bytesToMegabytes(long p_94051_) {
return p_94051_ / 1024L / 1024L;
}
public boolean showDebugScreen() {
return this.renderDebug && !this.minecraft.options.hideGui;
}
public boolean showProfilerChart() {
return this.showDebugScreen() && this.renderProfilerChart;
}
public boolean showNetworkCharts() {
return this.showDebugScreen() && this.renderNetworkCharts;
}
public boolean showFpsCharts() {
return this.showDebugScreen() && this.renderFpsCharts;
}
public void toggleOverlay() {
this.renderDebug = !this.renderDebug;
}
public void toggleNetworkCharts() {
this.renderNetworkCharts = !this.renderDebug || !this.renderNetworkCharts;
if (this.renderNetworkCharts) {
this.renderDebug = true;
this.renderFpsCharts = false;
}
}
public void toggleFpsCharts() {
this.renderFpsCharts = !this.renderDebug || !this.renderFpsCharts;
if (this.renderFpsCharts) {
this.renderDebug = true;
this.renderNetworkCharts = false;
}
}
public void toggleProfilerChart() {
this.renderProfilerChart = !this.renderDebug || !this.renderProfilerChart;
if (this.renderProfilerChart) {
this.renderDebug = true;
}
}
public void logFrameDuration(long p_300948_) {
this.frameTimeLogger.logSample(p_300948_);
}
public LocalSampleLogger getTickTimeLogger() {
return this.tickTimeLogger;
}
public LocalSampleLogger getPingLogger() {
return this.pingLogger;
}
public LocalSampleLogger getBandwidthLogger() {
return this.bandwidthLogger;
}
public ProfilerPieChart getProfilerPieChart() {
return this.profilerPieChart;
}
public void logRemoteSample(long[] p_333428_, RemoteDebugSampleType p_333591_) {
LocalSampleLogger localsamplelogger = this.remoteSupportingLoggers.get(p_333591_);
if (localsamplelogger != null) {
localsamplelogger.logFullSample(p_333428_);
}
}
public void reset() {
this.renderDebug = false;
this.tickTimeLogger.reset();
this.pingLogger.reset();
this.bandwidthLogger.reset();
}
@OnlyIn(Dist.CLIENT)
static class AllocationRateCalculator {
private static final int UPDATE_INTERVAL_MS = 500;
private static final List<GarbageCollectorMXBean> GC_MBEANS = ManagementFactory.getGarbageCollectorMXBeans();
private long lastTime = 0L;
private long lastHeapUsage = -1L;
private long lastGcCounts = -1L;
private long lastRate = 0L;
long bytesAllocatedPerSecond(long p_232517_) {
long i = System.currentTimeMillis();
if (i - this.lastTime < 500L) {
return this.lastRate;
} else {
long j = gcCounts();
if (this.lastTime != 0L && j == this.lastGcCounts) {
double d0 = (double)TimeUnit.SECONDS.toMillis(1L) / (double)(i - this.lastTime);
long k = p_232517_ - this.lastHeapUsage;
this.lastRate = Math.round((double)k * d0);
}
this.lastTime = i;
this.lastHeapUsage = p_232517_;
this.lastGcCounts = j;
return this.lastRate;
}
}
private static long gcCounts() {
long i = 0L;
for (GarbageCollectorMXBean garbagecollectormxbean : GC_MBEANS) {
i += garbagecollectormxbean.getCollectionCount();
}
return i;
}
}
} |