Skip to content

Commit

Permalink
Initial update for 1.21.3
Browse files Browse the repository at this point in the history
also changes the extra tps tracker on fabric/neo from 5s to 15s
  • Loading branch information
jpenilla committed Oct 26, 2024
1 parent 5cb7acd commit 39790a6
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 33 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
Minecraft server mod/plugin to show TPS, MSPT, and other information in the tab menu, boss bar, and action bar.

Current supported platforms:
- [Paper](https://papermc.io)/Spigot API (Minecraft versions 1.8.8-1.21.1+)
- [Paper](https://papermc.io)/Spigot API (Minecraft versions 1.8.8-1.21.3+)
- [Sponge](https://spongepowered.org) 12+
- [Fabric](https://fabricmc.net/) (Minecraft 1.21.1, requires [Fabric API](https://modrinth.com/mod/fabric-api))
- [NeoForge](https://neoforged.net/) (Minecraft 1.21.1)
- [Fabric](https://fabricmc.net/) (Minecraft 1.21.3, requires [Fabric API](https://modrinth.com/mod/fabric-api))
- [NeoForge](https://neoforged.net/) (Minecraft 1.21.3)

## Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void executeTickInfo(final @NonNull CommandContext<Commander> ctx) {
.append(space());
final Iterator<Double> tpsIterator = Arrays.stream(tps).iterator();
final Deque<String> tpsDurations = tps.length == 4
? new ArrayDeque<>(Arrays.asList("5s", "1m", "5m", "15m"))
? new ArrayDeque<>(Arrays.asList("15s", "1m", "5m", "15m"))
: new ArrayDeque<>(Arrays.asList("1m", "5m", "15m"));
while (tpsIterator.hasNext()) {
builder.append(TPSUtil.coloredTps(tpsIterator.next(), Theme.DEFAULT.colorScheme()))
Expand Down
3 changes: 3 additions & 0 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {
include(libs.bundles.configurate)
implementation(libs.adventureSerializerConfigurate4)
include(libs.adventureSerializerConfigurate4)

modImplementation(libs.fabricPermissionsApi)
include(libs.fabricPermissionsApi)
}

indra {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import me.lucko.fabric.api.permissions.v0.Permissions;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.modcommon.MinecraftServerAudiences;
import net.kyori.adventure.text.Component;
import net.minecraft.server.level.ServerPlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -46,7 +47,7 @@ public static FabricUser from(final TabTPSFabric tabTPSFabric, final ServerPlaye

@Override
public Component displayName() {
return this.base().getDisplayName().asComponent();
return MinecraftServerAudiences.of(this.base().getServer()).asAdventure(this.base().getDisplayName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package xyz.jpenilla.tabtps.fabric.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.function.BooleanSupplier;
Expand All @@ -37,7 +38,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import xyz.jpenilla.tabtps.common.service.TickTimeService;
import xyz.jpenilla.tabtps.common.util.RollingAverage;
import xyz.jpenilla.tabtps.common.util.TPSUtil;
Expand All @@ -51,34 +51,60 @@
@Mixin(MinecraftServer.class)
@Implements({@Interface(iface = TickTimeService.class, prefix = "tabtps$")})
abstract class MinecraftServerMixin implements MinecraftServerAccess {
@Unique
private final TickTimes tickTimes5s = new TickTimes(100);
@Unique
private final TickTimes tickTimes10s = new TickTimes(200);
@Unique
private final TickTimes tickTimes60s = new TickTimes(1200);

private final RollingAverage tps5s = new RollingAverage(5);
@Unique
private final RollingAverage tps15s = new RollingAverage(15);
@Unique
private final RollingAverage tps1m = new RollingAverage(60);
@Unique
private final RollingAverage tps5m = new RollingAverage(60 * 5);
@Unique
private final RollingAverage tps15m = new RollingAverage(60 * 15);

@Unique
private long previousTime;
@Unique
private boolean tickingPaused;

@Shadow private int tickCount;
@Shadow @Final private long[] tickTimesNanos;

@Inject(method = "tickServer", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final long tickStartTimeNanos, final long tickDurationNanos) {
@Inject(
method = "tickServer",
at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", ordinal = 0)
)
private void injectPause(final BooleanSupplier keepTicking, final CallbackInfo ci) {
this.tickingPaused = true;
}

@Inject(method = "tickServer", at = @At(value = "RETURN", ordinal = 1))
public void injectTick(
final BooleanSupplier keepTicking,
final CallbackInfo ci,
@Local(ordinal = 0) final long tickStartTimeNanos,
@Local(ordinal = 1) final long tickDurationNanos
) {
this.tickTimes5s.add(this.tickCount, tickDurationNanos);
this.tickTimes10s.add(this.tickCount, tickDurationNanos);
this.tickTimes60s.add(this.tickCount, tickDurationNanos);

if (this.tickCount % RollingAverage.SAMPLE_INTERVAL == 0) {
if (this.previousTime == 0) {
this.previousTime = tickStartTimeNanos - RollingAverage.TICK_TIME;
if (this.previousTime == 0 || this.tickingPaused) {
this.previousTime = tickStartTimeNanos - tickDurationNanos;
if (this.tickingPaused) {
this.tickingPaused = false;
}
}
final long diff = tickStartTimeNanos - this.previousTime;
this.previousTime = tickStartTimeNanos;
final BigDecimal currentTps = RollingAverage.TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP);
this.tps5s.add(currentTps, diff);
this.tps15s.add(currentTps, diff);
this.tps1m.add(currentTps, diff);
this.tps5m.add(currentTps, diff);
this.tps15m.add(currentTps, diff);
Expand All @@ -91,7 +117,7 @@ public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final

public double @NonNull [] tabtps$recentTps() {
final double[] tps = new double[4];
tps[0] = this.tps5s.average();
tps[0] = this.tps15s.average();
tps[1] = this.tps1m.average();
tps[2] = this.tps5m.average();
tps[3] = this.tps15m.average();
Expand Down
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"fabricloader": ">=0.15.11",
"fabric": "*",
"fabric-permissions-api-v0": "*",
"minecraft": ">=1.21 <=1.21.1"
"minecraft": "1.21.3"
}
}
2 changes: 1 addition & 1 deletion gradle/build-logic/src/main/kotlin/ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ val bukkitVersions = listOf(
"1.18.2",
"1.19.4",
"1.20.6",
"1.21.1",
"1.21.3",
)
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ guava = "21.0"
bstats = "3.1.0"
paperApi = "1.16.5-R0.1-SNAPSHOT"
paperLib = "1.0.8"
fabricApi = "0.105.0+1.21.1"
fabricApi = "0.107.0+1.21.3"
fabricLoader = "0.16.7"
minecraft = "1.21.1"
adventurePlatformFabric = "5.14.1"
adventurePlatformNeoforge = "6.0.0"
minecraft = "1.21.3"
adventurePlatformMod = "6.1.0-SNAPSHOT"
mixin = "0.8.7"
neoforge = "21.1.71"
neoforge = "21.3.3-beta"

# buildSrc
indra = "3.1.3"
Expand All @@ -43,8 +42,8 @@ adventureTextSerializerLegacy = { group = "net.kyori", name = "adventure-text-se
adventureSerializerConfigurate4 = { group = "net.kyori", name = "adventure-serializer-configurate4", version.ref = "adventure" }
adventureTextFeaturePagination = { group = "net.kyori", name = "adventure-text-feature-pagination", version.ref = "adventurePagination" }
adventurePlatformBukkit = { group = "net.kyori", name = "adventure-platform-bukkit", version.ref = "adventurePlatform" }
adventurePlatformFabric = { group = "net.kyori", name = "adventure-platform-fabric", version.ref = "adventurePlatformFabric" }
adventurePlatformNeoforge = { group = "net.kyori", name = "adventure-platform-neoforge", version.ref = "adventurePlatformNeoforge" }
adventurePlatformFabric = { group = "net.kyori", name = "adventure-platform-fabric", version.ref = "adventurePlatformMod" }
adventurePlatformNeoforge = { group = "net.kyori", name = "adventure-platform-neoforge", version.ref = "adventurePlatformMod" }
minimessage = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "adventure" }

cloudBom = { group = "org.incendo", name = "cloud-bom", version.ref = "cloud" }
Expand Down Expand Up @@ -80,6 +79,7 @@ paperLib = { group = "io.papermc", name = "paperlib", version.ref = "paperLib" }

fabricApi = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fabricApi" }
fabricLoader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fabricLoader" }
fabricPermissionsApi = "me.lucko:fabric-permissions-api:0.3.2"
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" }

zNeoforge = { module = "net.neoforged:neoforge", version.ref = "neoforge" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package xyz.jpenilla.tabtps.neoforge.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.function.BooleanSupplier;
Expand All @@ -37,7 +38,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import xyz.jpenilla.tabtps.common.service.TickTimeService;
import xyz.jpenilla.tabtps.common.util.RollingAverage;
import xyz.jpenilla.tabtps.common.util.TPSUtil;
Expand All @@ -51,34 +51,60 @@
@Mixin(MinecraftServer.class)
@Implements({@Interface(iface = TickTimeService.class, prefix = "tabtps$")})
abstract class MinecraftServerMixin implements MinecraftServerAccess {
@Unique
private final TickTimes tickTimes5s = new TickTimes(100);
@Unique
private final TickTimes tickTimes10s = new TickTimes(200);
@Unique
private final TickTimes tickTimes60s = new TickTimes(1200);

private final RollingAverage tps5s = new RollingAverage(5);
@Unique
private final RollingAverage tps15s = new RollingAverage(15);
@Unique
private final RollingAverage tps1m = new RollingAverage(60);
@Unique
private final RollingAverage tps5m = new RollingAverage(60 * 5);
@Unique
private final RollingAverage tps15m = new RollingAverage(60 * 15);

@Unique
private long previousTime;
@Unique
private boolean tickingPaused;

@Shadow private int tickCount;
@Shadow @Final private long[] tickTimesNanos;

@Inject(method = "tickServer", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final long tickStartTimeNanos, final long tickDurationNanos) {
@Inject(
method = "tickServer",
at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", ordinal = 0)
)
private void injectPause(final BooleanSupplier keepTicking, final CallbackInfo ci) {
this.tickingPaused = true;
}

@Inject(method = "tickServer", at = @At(value = "RETURN", ordinal = 1))
public void injectTick(
final BooleanSupplier keepTicking,
final CallbackInfo ci,
@Local(ordinal = 0) final long tickStartTimeNanos,
@Local(ordinal = 1) final long tickDurationNanos
) {
this.tickTimes5s.add(this.tickCount, tickDurationNanos);
this.tickTimes10s.add(this.tickCount, tickDurationNanos);
this.tickTimes60s.add(this.tickCount, tickDurationNanos);

if (this.tickCount % RollingAverage.SAMPLE_INTERVAL == 0) {
if (this.previousTime == 0) {
this.previousTime = tickStartTimeNanos - RollingAverage.TICK_TIME;
if (this.previousTime == 0 || this.tickingPaused) {
this.previousTime = tickStartTimeNanos - tickDurationNanos;
if (this.tickingPaused) {
this.tickingPaused = false;
}
}
final long diff = tickStartTimeNanos - this.previousTime;
this.previousTime = tickStartTimeNanos;
final BigDecimal currentTps = RollingAverage.TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP);
this.tps5s.add(currentTps, diff);
this.tps15s.add(currentTps, diff);
this.tps1m.add(currentTps, diff);
this.tps5m.add(currentTps, diff);
this.tps15m.add(currentTps, diff);
Expand All @@ -91,7 +117,7 @@ public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final

public double @NonNull [] tabtps$recentTps() {
final double[] tps = new double[4];
tps[0] = this.tps5s.average();
tps[0] = this.tps15s.average();
tps[1] = this.tps1m.average();
tps[2] = this.tps5m.average();
tps[3] = this.tps15m.average();
Expand Down
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ side = "BOTH"
[[dependencies.tabtps]]
modId = "minecraft"
type = "required"
versionRange = "[1.21,1.21.2)"
versionRange = "[1.21.3]"
ordering = "NONE"
side = "BOTH"

Expand Down
4 changes: 2 additions & 2 deletions sponge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sponge {
}

minecraft {
version("1.21.1")
version("1.21.3")
platform(MinecraftPlatform.JOINED)
}

Expand Down Expand Up @@ -97,7 +97,7 @@ tabTPSPlatform {
publishMods.modrinth {
modLoaders.add("sponge")
minecraftVersions.addAll(
"1.21.1"
"1.21.3"
)
}

Expand Down

0 comments on commit 39790a6

Please sign in to comment.