Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minecraft 1.21.4 #183

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4+)
- [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.4, requires [Fabric API](https://modrinth.com/mod/fabric-api))
- [NeoForge](https://neoforged.net/) (Minecraft 1.21.4)

## 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.4"
}
}
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.4",
)
20 changes: 10 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ adventure = "4.17.0"
adventurePagination = "4.0.0-SNAPSHOT"
adventurePlatform = "4.3.4"
cloud = "2.0.0"
cloudMinecraft = "2.0.0-beta.9"
cloudModded = "2.0.0-beta.9"
cloudMinecraft = "2.0.0-beta.10"
cloudModded = "2.0.0-beta.10"
cloudSponge = "2.0.0-SNAPSHOT"
configurate = "4.1.2"
typesafeConfig = "1.4.3"
Expand All @@ -22,14 +22,13 @@ guava = "21.0"
bstats = "3.1.0"
paperApi = "1.16.5-R0.1-SNAPSHOT"
paperLib = "1.0.8"
fabricApi = "0.110.0+1.21.1"
fabricApi = "0.112.2+1.21.4"
fabricLoader = "0.16.9"
minecraft = "1.21.1"
adventurePlatformFabric = "5.14.2"
adventurePlatformNeoforge = "6.0.0"
minecraft = "1.21.4"
adventurePlatformMod = "6.1.0"
mixin = "0.8.7"
neoforge = "21.1.82"
neoForm = "1.21.1-20240808.144430"
neoforge = "21.4.33-beta"
neoForm = "1.21.4-20241203.161809"

# buildSrc
indra = "3.1.3"
Expand All @@ -44,8 +43,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 @@ -81,6 +80,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.3"
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.4]"
ordering = "NONE"
side = "BOTH"

Expand Down
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pluginManagement {
}

plugins {
id("quiet-fabric-loom") version "1.8-SNAPSHOT"
id("quiet-fabric-loom") version "1.9-SNAPSHOT"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
id("net.neoforged.moddev.repositories") version "2.0.49-beta"
id("net.neoforged.moddev.repositories") version "2.0.61-beta"
}

rootProject.name = "TabTPS"
Expand Down
8 changes: 3 additions & 5 deletions sponge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ java {

sponge {
injectRepositories(false)
apiVersion("12.0.0-SNAPSHOT")
apiVersion("13.0.0-SNAPSHOT")
plugin(rootProject.name.lowercase()) {
loader {
name(PluginLoaders.JAVA_PLAIN)
Expand Down Expand Up @@ -95,18 +95,16 @@ tabTPSPlatform {
publishMods.modrinth {
modLoaders.add("sponge")
minecraftVersions.addAll(
"1.21.1"
"1.21.4"
)
}

/*
configurations.spongeRuntime {
resolutionStrategy {
eachDependency {
if (target.name == "spongevanilla") {
useVersion("1.20.+")
useVersion("1.21.+")
}
}
}
}
*/
Loading
Loading