-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fabric-apiが入っていない場合に文章が壊れる問題の修正 (#3)
- Loading branch information
1 parent
8bbbd80
commit a9bd8d0
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/net/toshimichi/kzeplus/mixins/MixinLanguage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package net.toshimichi.kzeplus.mixins; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.util.JsonHelper; | ||
import net.minecraft.util.Language; | ||
import net.toshimichi.kzeplus.KzePlus; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
import java.util.regex.Pattern; | ||
|
||
@Mixin(Language.class) | ||
public class MixinLanguage { | ||
|
||
@Final @Shadow | ||
private static Pattern TOKEN_PATTERN; | ||
@Final @Shadow | ||
private static Gson GSON; | ||
|
||
@Inject(method = "load", at = @At("HEAD")) | ||
private static void addCustomKeys(InputStream inputStream, BiConsumer<String, String> entryConsumer, CallbackInfo ci) { | ||
Path path = KzePlus.getInstance() | ||
.getModContainer() | ||
.findPath("assets/kze_plus/lang/en_us.json") | ||
.orElseThrow(); | ||
|
||
try (InputStream in = path.toUri().toURL().openStream()) { | ||
JsonObject jsonObject = GSON.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), JsonObject.class); | ||
for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { | ||
String string = TOKEN_PATTERN.matcher(JsonHelper.asString(entry.getValue(), entry.getKey())).replaceAll("%$1s"); | ||
entryConsumer.accept(entry.getKey(), string); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters