RealmsUtil.java

com.mojang.realmsclient.util.RealmsUtil

信息

  • 全限定名:com.mojang.realmsclient.util.RealmsUtil
  • 类型:public class
  • 包:com.mojang.realmsclient.util
  • 源码路径:src/main/java/com/mojang/realmsclient/util/RealmsUtil.java
  • 起始行号:L25
  • 职责:

    TODO

字段/常量

  • LOGGER

    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L26
    • 说明:

      TODO

  • RIGHT_NOW

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L27
    • 说明:

      TODO

  • MINUTES

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L28
    • 说明:

      TODO

  • HOURS

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L29
    • 说明:

      TODO

  • DAYS

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L30
    • 说明:

      TODO

内部类/嵌套类型

  • com.mojang.realmsclient.util.RealmsUtil.RealmsIoConsumer

    • 类型: interface
    • 修饰符: public
    • 源码定位: L98
    • 说明:

      TODO

  • com.mojang.realmsclient.util.RealmsUtil.RealmsIoFunction

    • 类型: interface
    • 修饰符: public
    • 源码定位: L109
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

public static Component convertToAgePresentation(long timeDiff) @ L32

  • 方法名:convertToAgePresentation
  • 源码定位:L32
  • 返回类型:Component
  • 修饰符:public static

参数:

  • timeDiff: long

说明:

TODO

public static Component convertToAgePresentationFromInstant(Instant date) @ L52

  • 方法名:convertToAgePresentationFromInstant
  • 源码定位:L52
  • 返回类型:Component
  • 修饰符:public static

参数:

  • date: Instant

说明:

TODO

public static void extractPlayerFace(GuiGraphicsExtractor graphics, int x, int y, int size, UUID playerId) @ L56

  • 方法名:extractPlayerFace
  • 源码定位:L56
  • 返回类型:void
  • 修饰符:public static

参数:

  • graphics: GuiGraphicsExtractor
  • x: int
  • y: int
  • size: int
  • playerId: UUID

说明:

TODO

public static <T> CompletableFuture<T> supplyAsync(RealmsUtil.RealmsIoFunction<T> function, Consumer<RealmsServiceException> onFailure) @ L63

  • 方法名:supplyAsync
  • 源码定位:L63
  • 返回类型: CompletableFuture
  • 修饰符:public static

参数:

  • function: RealmsUtil.RealmsIoFunction
  • onFailure: Consumer

说明:

TODO

public static CompletableFuture<Void> runAsync(RealmsUtil.RealmsIoConsumer function, Consumer<RealmsServiceException> onFailure) @ L83

  • 方法名:runAsync
  • 源码定位:L83
  • 返回类型:CompletableFuture
  • 修饰符:public static

参数:

  • function: RealmsUtil.RealmsIoConsumer
  • onFailure: Consumer

说明:

TODO

public static Consumer<RealmsServiceException> openScreenOnFailure(Function<RealmsServiceException,Screen> errorScreen) @ L87

  • 方法名:openScreenOnFailure
  • 源码定位:L87
  • 返回类型:Consumer
  • 修饰符:public static

参数:

  • errorScreen: Function<RealmsServiceException,Screen>

说明:

TODO

public static Consumer<RealmsServiceException> openScreenAndLogOnFailure(Function<RealmsServiceException,Screen> errorScreen, String errorMessage) @ L92

  • 方法名:openScreenAndLogOnFailure
  • 源码定位:L92
  • 返回类型:Consumer
  • 修饰符:public static

参数:

  • errorScreen: Function<RealmsServiceException,Screen>
  • errorMessage: String

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class RealmsUtil {
    private static final Logger LOGGER = LogUtils.getLogger();
    private static final Component RIGHT_NOW = Component.translatable("mco.util.time.now");
    private static final int MINUTES = 60;
    private static final int HOURS = 3600;
    private static final int DAYS = 86400;
 
    public static Component convertToAgePresentation(long timeDiff) {
        if (timeDiff < 0L) {
            return RIGHT_NOW;
        } else {
            long timeDiffInSeconds = timeDiff / 1000L;
            if (timeDiffInSeconds < 60L) {
                return Component.translatable("mco.time.secondsAgo", timeDiffInSeconds);
            } else if (timeDiffInSeconds < 3600L) {
                long minutes = timeDiffInSeconds / 60L;
                return Component.translatable("mco.time.minutesAgo", minutes);
            } else if (timeDiffInSeconds < 86400L) {
                long hours = timeDiffInSeconds / 3600L;
                return Component.translatable("mco.time.hoursAgo", hours);
            } else {
                long days = timeDiffInSeconds / 86400L;
                return Component.translatable("mco.time.daysAgo", days);
            }
        }
    }
 
    public static Component convertToAgePresentationFromInstant(Instant date) {
        return convertToAgePresentation(System.currentTimeMillis() - date.toEpochMilli());
    }
 
    public static void extractPlayerFace(GuiGraphicsExtractor graphics, int x, int y, int size, UUID playerId) {
        PlayerSkinRenderCache.RenderInfo renderInfo = Minecraft.getInstance()
            .playerSkinRenderCache()
            .getOrDefault(ResolvableProfile.createUnresolved(playerId));
        PlayerFaceExtractor.extractRenderState(graphics, renderInfo.playerSkin(), x, y, size);
    }
 
    public static <T> CompletableFuture<T> supplyAsync(RealmsUtil.RealmsIoFunction<T> function, @Nullable Consumer<RealmsServiceException> onFailure) {
        return CompletableFuture.supplyAsync(() -> {
            RealmsClient client = RealmsClient.getOrCreate();
 
            try {
                return function.apply(client);
            } catch (Throwable var5) {
                if (var5 instanceof RealmsServiceException e) {
                    if (onFailure != null) {
                        onFailure.accept(e);
                    }
                } else {
                    LOGGER.error("Unhandled exception", var5);
                }
 
                throw new RuntimeException(var5);
            }
        }, Util.nonCriticalIoPool());
    }
 
    public static CompletableFuture<Void> runAsync(RealmsUtil.RealmsIoConsumer function, @Nullable Consumer<RealmsServiceException> onFailure) {
        return supplyAsync(function, onFailure);
    }
 
    public static Consumer<RealmsServiceException> openScreenOnFailure(Function<RealmsServiceException, Screen> errorScreen) {
        Minecraft minecraft = Minecraft.getInstance();
        return e -> minecraft.execute(() -> minecraft.setScreen(errorScreen.apply(e)));
    }
 
    public static Consumer<RealmsServiceException> openScreenAndLogOnFailure(Function<RealmsServiceException, Screen> errorScreen, String errorMessage) {
        return openScreenOnFailure(errorScreen).andThen(e -> LOGGER.error(errorMessage, (Throwable)e));
    }
 
    @FunctionalInterface
    @OnlyIn(Dist.CLIENT)
    public interface RealmsIoConsumer extends RealmsUtil.RealmsIoFunction<Void> {
        void accept(final RealmsClient client) throws RealmsServiceException;
 
        default Void apply(RealmsClient client) throws RealmsServiceException {
            this.accept(client);
            return null;
        }
    }
 
    @FunctionalInterface
    @OnlyIn(Dist.CLIENT)
    public interface RealmsIoFunction<T> {
        T apply(final RealmsClient client) throws RealmsServiceException;
    }
}

引用的其他类

  • RealmsClient

    • 引用位置: 方法调用
    • 关联成员: RealmsClient.getOrCreate()
  • RealmsServiceException

    • 引用位置: 参数/返回值
  • Minecraft

    • 引用位置: 方法调用
    • 关联成员: Minecraft.getInstance()
  • GuiGraphicsExtractor

    • 引用位置: 参数
  • PlayerFaceExtractor

    • 引用位置: 方法调用
    • 关联成员: PlayerFaceExtractor.extractRenderState()
  • Screen

    • 引用位置: 参数
  • LoggedChatMessage

    • 引用位置: 方法调用
    • 关联成员: System.currentTimeMillis()
  • Component

    • 引用位置: 字段/方法调用/返回值
    • 关联成员: Component.translatable()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.nonCriticalIoPool()
  • ResolvableProfile

    • 引用位置: 方法调用
    • 关联成员: ResolvableProfile.createUnresolved()