diff --git a/src/main/java/com/github/zly2006/reden/mixin/richTranslation/MixinTranslationStorage.java b/src/main/java/com/github/zly2006/reden/mixin/richTranslation/MixinTranslationStorage.java index 13a2eaa9..83c65640 100644 --- a/src/main/java/com/github/zly2006/reden/mixin/richTranslation/MixinTranslationStorage.java +++ b/src/main/java/com/github/zly2006/reden/mixin/richTranslation/MixinTranslationStorage.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -46,7 +47,7 @@ private static void loadCustomText(ResourceManager resourceManager, List Gson gson = new Gson(); resourceManager.getAllResources(identifier).forEach(resource -> { try { - var jo = gson.fromJson(new InputStreamReader(resource.getInputStream()), JsonObject.class); + var jo = gson.fromJson(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8), JsonObject.class); jo.entrySet().stream().filter(it -> it.getValue() instanceof JsonArray).forEach(it -> { MutableText text = Text.Serialization.fromJsonTree(it.getValue()); tempTextMap.put(it.getKey(), text); diff --git a/src/main/java/com/github/zly2006/reden/rvc/gui/RvcHudRenderer.kt b/src/main/java/com/github/zly2006/reden/rvc/gui/RvcHudRenderer.kt index bb310b53..7e84503c 100644 --- a/src/main/java/com/github/zly2006/reden/rvc/gui/RvcHudRenderer.kt +++ b/src/main/java/com/github/zly2006/reden/rvc/gui/RvcHudRenderer.kt @@ -25,7 +25,7 @@ object RvcHudRenderer: IRenderer { override fun onRenderGameOverlayPost(drawContext: DrawContext) { val mc = MinecraftClient.getInstance() - if ((mc.player)?.holdingToolItem != true) return + if (!mc.player.holdingToolItem) return updateLines() val allLines = mutableListOf() lines.forEach { (name, lines) -> diff --git a/src/main/java/com/github/zly2006/reden/rvc/gui/hud/gameplay/SelectModeHud.kt b/src/main/java/com/github/zly2006/reden/rvc/gui/hud/gameplay/SelectModeHud.kt index a2e15af0..38c18e6c 100644 --- a/src/main/java/com/github/zly2006/reden/rvc/gui/hud/gameplay/SelectModeHud.kt +++ b/src/main/java/com/github/zly2006/reden/rvc/gui/hud/gameplay/SelectModeHud.kt @@ -13,7 +13,7 @@ fun registerHud() { RvcHudRenderer.supplierMap["select_mode_hud"] = { val list = mutableListOf() val mc = MinecraftClient.getInstance() - if (mc.player?.holdingToolItem == true) { + if (mc.player.holdingToolItem) { if (selectedStructure == null) { list.add(Text.translatable("reden.widget.rvc.hud.selected_nothing")) } diff --git a/src/main/java/com/github/zly2006/reden/rvc/tracking/client/ClientTracking.kt b/src/main/java/com/github/zly2006/reden/rvc/tracking/client/ClientTracking.kt index ca146385..ff8a3427 100644 --- a/src/main/java/com/github/zly2006/reden/rvc/tracking/client/ClientTracking.kt +++ b/src/main/java/com/github/zly2006/reden/rvc/tracking/client/ClientTracking.kt @@ -21,7 +21,7 @@ fun registerSelectionTool() { if (!eventButtonState) return false // ensure mouse down val mc = MinecraftClient.getInstance() if (mc.currentScreen != null) return false // ensure no gui - if (mc.player?.holdingToolItem != true) return false // ensure hand tool item + if (!mc.player.holdingToolItem) return false // ensure hand tool item // get clicked block val raycast = mc.cameraEntity!!.raycast(256.0, 0f, false) diff --git a/src/main/java/com/github/zly2006/reden/utils/Utils.kt b/src/main/java/com/github/zly2006/reden/utils/Utils.kt index 9ce61a52..b696748c 100644 --- a/src/main/java/com/github/zly2006/reden/utils/Utils.kt +++ b/src/main/java/com/github/zly2006/reden/utils/Utils.kt @@ -49,10 +49,11 @@ fun PlayerEntity.sendMessage(s: String) { sendMessage(Text.literal(s)) } -val ClientPlayerEntity.holdingToolItem: Boolean get() { - val stack = getStackInHand(Hand.MAIN_HAND) ?: return false - return Registries.ITEM.getId(stack.item) == Identifier.tryParse(SELECTION_TOOL.stringValue) -} +val ClientPlayerEntity?.holdingToolItem: Boolean + get() { + val stack = this?.getStackInHand(Hand.MAIN_HAND) ?: return false + return Registries.ITEM.getId(stack.item) == Identifier.tryParse(SELECTION_TOOL.stringValue) + } fun World.setBlockNoPP(pos: BlockPos, state: BlockState, flags: Int = Block.NOTIFY_LISTENERS) { setBlockState(pos, state, flags and Block.NOTIFY_NEIGHBORS.inv() or Block.FORCE_STATE or Block.SKIP_DROPS) @@ -89,12 +90,13 @@ object ResourceLoader { fun buttonWidget(x: Int, y: Int, width: Int, height: Int, message: Text, onPress: ButtonWidget.PressAction) = ButtonWidget(x, y, width, height, message, onPress) { it.get() } -val isSinglePlayerAndCheating: Boolean get() { - infix fun Boolean?.and(other: Boolean?) = this ?: false && other ?: false - return MinecraftClient.getInstance()?.let { - (it.server?.isSingleplayer and it.player?.hasPermissionLevel(2)) - } == true -} +val isSinglePlayerAndCheating: Boolean + get() { + infix fun Boolean?.and(other: Boolean?) = this ?: false && other ?: false + return MinecraftClient.getInstance()?.let { + (it.server?.isSingleplayer and it.player?.hasPermissionLevel(2)) + } == true + } fun memorySizeToString(size: Int) { val unit = arrayOf("B", "KB", "MB", "GB", "TB") @@ -154,25 +156,28 @@ fun checkMalilib() { if (isClient) Class.forName("fi.dy.masa.malilib.util.FileUtils") } catch (_: ClassNotFoundException) { - throw ModResolutionException(""" + throw ModResolutionException( + """ Dependency not found! Reden requires Malilib to run on the clients. Please install Malilib from https://www.curseforge.com/minecraft/mc-mods/malilib - """.trimIndent()) + """.trimIndent() + ) } } /** * @author Zai_yu_you */ +@Deprecated("", level = DeprecationLevel.HIDDEN) fun generateRandomColor(alpha: Int, baseGray: Int, offsetWeight: Float): Int { require(offsetWeight > 0 && offsetWeight <= 1) { "The input offsetWeight must be between 0(inclusive) and 1 " } require(baseGray in 1..256) { "The input baseGray must be between 0(inclusive) and 256 " } val random = Random() - var r = (baseGray * (1 - offsetWeight) + random.nextInt((baseGray * offsetWeight).toInt())) as Int - var g = (baseGray * (1 - offsetWeight) + random.nextInt((baseGray * offsetWeight).toInt())) as Int - var b = (baseGray * (1 - offsetWeight) + random.nextInt((baseGray * offsetWeight).toInt())) as Int + var r = (baseGray * (1 - offsetWeight) + random.nextInt((baseGray * offsetWeight).toInt())).toInt() + var g = (baseGray * (1 - offsetWeight) + random.nextInt((baseGray * offsetWeight).toInt())).toInt() + var b = (baseGray * (1 - offsetWeight) + random.nextInt((baseGray * offsetWeight).toInt())).toInt() //归一化 var scaleFactor = 256f / (r + g + b)