Nessiesson

Untitled

Jan 28th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. From 8db26f74b12cd7c115e3b49c40a953f15001cde5 Mon Sep 17 00:00:00 2001
  2. From: REDACTED
  3. Date: Fri, 1 Dec 2017 02:41:40 +0100
  4. Subject: [PATCH] Added tick/timetime display in the player list.
  5.  
  6. ---
  7. .../net/minecraft/server/MinecraftServer.java | 34 ++++++++++++++++++++++
  8. 1 file changed, 34 insertions(+)
  9.  
  10. diff --git a/src/minecraft_server/net/minecraft/server/MinecraftServer.java b/src/minecraft_server/net/minecraft/server/MinecraftServer.java
  11. index 8fefd31..023d2d5 100644
  12. --- a/src/minecraft_server/net/minecraft/server/MinecraftServer.java
  13. +++ b/src/minecraft_server/net/minecraft/server/MinecraftServer.java
  14. @@ -18,6 +18,7 @@ import java.awt.image.BufferedImage;
  15. import java.io.File;
  16. import java.io.IOException;
  17. import java.io.UnsupportedEncodingException;
  18. +import java.lang.reflect.Field;
  19. import java.net.Proxy;
  20. import java.net.URLEncoder;
  21. import java.nio.charset.StandardCharsets;
  22. @@ -49,6 +50,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
  23. import net.minecraft.init.Bootstrap;
  24. import net.minecraft.network.NetworkSystem;
  25. import net.minecraft.network.ServerStatusResponse;
  26. +import net.minecraft.network.play.server.SPacketPlayerListHeaderFooter;
  27. import net.minecraft.network.play.server.SPacketTimeUpdate;
  28. import net.minecraft.profiler.ISnooperInfo;
  29. import net.minecraft.profiler.Profiler;
  30. @@ -67,6 +69,7 @@ import net.minecraft.util.math.BlockPos;
  31. import net.minecraft.util.math.MathHelper;
  32. import net.minecraft.util.text.ITextComponent;
  33. import net.minecraft.util.text.TextComponentString;
  34. +import net.minecraft.util.text.TextFormatting;
  35. import net.minecraft.world.EnumDifficulty;
  36. import net.minecraft.world.GameType;
  37. import net.minecraft.world.MinecraftException;
  38. @@ -626,6 +629,37 @@ public abstract class MinecraftServer implements ICommandSender, Runnable, IThre
  39. this.saveAllWorlds(true);
  40. this.profiler.endSection();
  41. }
  42. +
  43. + //QC - fancy TPS display
  44. + if(this.tickCounter % 20 == 0)
  45. + {
  46. + this.profiler.startSection("qc_tps_display");
  47. + double MSPT = MathHelper.average(this.tickTimeArray) * 1.0E-6D;
  48. + double TPS = 1000.0D / Math.max(50.0D, MSPT);
  49. +
  50. + String tps_display = TextFormatting.GRAY + "TPS: " +
  51. + (TPS > 16.0D ? TextFormatting.YELLOW : TextFormatting.RED) +
  52. + String.format("%.1f", TPS) +
  53. + TextFormatting.GRAY + " MSPT: " +
  54. + (TPS > 16.0D ? TextFormatting.YELLOW : TextFormatting.RED) +
  55. + String.format("%.1f", MSPT);
  56. +
  57. + SPacketPlayerListHeaderFooter packet = new SPacketPlayerListHeaderFooter();
  58. + Field header = packet.getClass().getDeclaredFields()[0];
  59. + Field footer = packet.getClass().getDeclaredFields()[1];
  60. + header.setAccessible(true);
  61. + footer.setAccessible(true);
  62. + try {
  63. + header.set(packet, new TextComponentString(""));
  64. + footer.set(packet, new TextComponentString(tps_display));
  65. + } catch (IllegalArgumentException e) {
  66. + e.printStackTrace();
  67. + } catch (IllegalAccessException e) {
  68. + e.printStackTrace();
  69. + }
  70. + this.getPlayerList().sendPacketToAllPlayers(packet);
  71. + this.profiler.endSection();
  72. + }
  73.  
  74. this.profiler.startSection("tallying");
  75. this.tickTimeArray[this.tickCounter % 100] = System.nanoTime() - i;
  76. --
  77. 2.7.4.1.g5468f9e
Advertisement
Add Comment
Please, Sign In to add comment