Skip to content

Commit

Permalink
fix: Language loading (#110)
Browse files Browse the repository at this point in the history
[publish beta]
修复中文加载不出来的bug
  • Loading branch information
zly2006 authored Apr 28, 2024
1 parent e80a2b6 commit c8857d2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,7 +47,7 @@ private static void loadCustomText(ResourceManager resourceManager, List<String>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrderedText>()
lines.forEach { (name, lines) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fun registerHud() {
RvcHudRenderer.supplierMap["select_mode_hud"] = {
val list = mutableListOf<Text>()
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"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 20 additions & 15 deletions src/main/java/com/github/zly2006/reden/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c8857d2

Please sign in to comment.