From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Mykyta Komarnytskyy Date: Sat, 24 Oct 2020 21:03:53 -0500 Subject: [PATCH] Smarter statistics ticking In vanilla, statistics that count time spent for an action (i.e. time played or sneak time) are incremented every tick. This is retarded. With this patch and a configured interval of 20, the statistics are only ticked every 20th tick and are incremented by 20 ticks at a time. This means a lot less ticking with the same accurate counting. With an interval of 20, this patch saves roughly 3ms per tick on a server w/ 80 players online. Original code by YatopiaMC, licensed under MIT You can find the original code on https://github.com/YatopiaMC/Yatopia diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java index 5a482f4c2a86d3f93fbbe8fc8fd29b07ebd50dc8..0b50301046234551c51b5ea9add450b6310ca73a 100644 --- a/src/main/java/net/minecraft/world/entity/player/Player.java +++ b/src/main/java/net/minecraft/world/entity/player/Player.java @@ -308,19 +308,21 @@ public abstract class Player extends LivingEntity { this.moveCloak(); if (!this.level.isClientSide) { this.foodData.tick(this); - this.awardStat(Stats.PLAY_TIME); - this.awardStat(Stats.TOTAL_WORLD_TIME); - if (this.isAlive()) { - this.awardStat(Stats.TIME_SINCE_DEATH); - } - - if (this.isDiscrete()) { - this.awardStat(Stats.CROUCH_TIME); - } - - if (!this.isSleeping()) { - this.awardStat(Stats.TIME_SINCE_REST); + // Mirai start + if (tickCount % 20 == 0) { + this.awardStat(Stats.PLAY_TIME, 20); + this.awardStat(Stats.TOTAL_WORLD_TIME, 20); + if (this.isAlive()) { + this.awardStat(Stats.TIME_SINCE_DEATH, 20); + } + if (this.isDiscrete()) { + this.awardStat(Stats.CROUCH_TIME, 20); + } + if (!this.isSleeping()) { + this.awardStat(Stats.TIME_SINCE_REST, 20); + } } + // Mirai end } int i = 29999999;