Merge 1.16 into 1.18
This commit is contained in:
commit
6b1f5232fa
|
|
@ -0,0 +1,67 @@
|
||||||
|
package org.embeddedt.modernfix.util;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.*;
|
||||||
|
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All code here is derived from Guava's Stopwatch and Platform classes.
|
||||||
|
* Too bad it's not a public method call indeed...
|
||||||
|
*/
|
||||||
|
public class TimeFormatter {
|
||||||
|
static String formatCompact4Digits(double value) {
|
||||||
|
return String.format(Locale.ROOT, "%.4g", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatNanos(long nanos) {
|
||||||
|
TimeUnit unit = chooseUnit(nanos);
|
||||||
|
double value = (double) nanos / NANOSECONDS.convert(1, unit);
|
||||||
|
|
||||||
|
return formatCompact4Digits(value) + " " + abbreviate(unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TimeUnit chooseUnit(long nanos) {
|
||||||
|
if (DAYS.convert(nanos, NANOSECONDS) > 0) {
|
||||||
|
return DAYS;
|
||||||
|
}
|
||||||
|
if (HOURS.convert(nanos, NANOSECONDS) > 0) {
|
||||||
|
return HOURS;
|
||||||
|
}
|
||||||
|
if (MINUTES.convert(nanos, NANOSECONDS) > 0) {
|
||||||
|
return MINUTES;
|
||||||
|
}
|
||||||
|
if (SECONDS.convert(nanos, NANOSECONDS) > 0) {
|
||||||
|
return SECONDS;
|
||||||
|
}
|
||||||
|
if (MILLISECONDS.convert(nanos, NANOSECONDS) > 0) {
|
||||||
|
return MILLISECONDS;
|
||||||
|
}
|
||||||
|
if (MICROSECONDS.convert(nanos, NANOSECONDS) > 0) {
|
||||||
|
return MICROSECONDS;
|
||||||
|
}
|
||||||
|
return NANOSECONDS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String abbreviate(TimeUnit unit) {
|
||||||
|
switch (unit) {
|
||||||
|
case NANOSECONDS:
|
||||||
|
return "ns";
|
||||||
|
case MICROSECONDS:
|
||||||
|
return "\u03bcs"; // μs
|
||||||
|
case MILLISECONDS:
|
||||||
|
return "ms";
|
||||||
|
case SECONDS:
|
||||||
|
return "s";
|
||||||
|
case MINUTES:
|
||||||
|
return "min";
|
||||||
|
case HOURS:
|
||||||
|
return "h";
|
||||||
|
case DAYS:
|
||||||
|
return "d";
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import net.minecraft.server.Bootstrap;
|
||||||
import net.minecraftforge.network.NetworkConstants;
|
import net.minecraftforge.network.NetworkConstants;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.embeddedt.modernfix.forge.load.ModWorkManagerQueue;
|
import org.embeddedt.modernfix.forge.load.ModWorkManagerQueue;
|
||||||
|
import org.embeddedt.modernfix.util.TimeFormatter;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
@ -11,6 +12,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
|
||||||
@Mixin(Bootstrap.class)
|
@Mixin(Bootstrap.class)
|
||||||
public class BootstrapMixin {
|
public class BootstrapMixin {
|
||||||
@Shadow private static boolean isBootstrapped;
|
@Shadow private static boolean isBootstrapped;
|
||||||
|
|
@ -20,7 +23,7 @@ public class BootstrapMixin {
|
||||||
@Inject(method = "bootStrap", at = @At("HEAD"))
|
@Inject(method = "bootStrap", at = @At("HEAD"))
|
||||||
private static void doModernFixBootstrap(CallbackInfo ci) {
|
private static void doModernFixBootstrap(CallbackInfo ci) {
|
||||||
if(!isBootstrapped) {
|
if(!isBootstrapped) {
|
||||||
LOGGER.info("ModernFix bootstrap");
|
LOGGER.info("ModernFix reached bootstrap stage ({} after launch)", TimeFormatter.formatNanos(ManagementFactory.getRuntimeMXBean().getUptime() * 1000L));
|
||||||
ModWorkManagerQueue.replace();
|
ModWorkManagerQueue.replace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user