Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix translations on quilt and some updates #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url "https://jitpack.io" }
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings "com.github.redlime:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://fabricmc.net/versions.html
minecraft_version=1.16.1
minecraft_version_code=1.16.1
yarn_mappings=1.16.1+build.21
loader_version=0.14.17
yarn_mappings=1.16.1.build.19
loader_version=0.14.25

# Mod Properties
mod_version=14.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public abstract class MinecraftClientMixin {
@Shadow @Final private Window window;
private boolean disconnectCheck = false;

@Inject(at = @At("HEAD"), method = "method_29607(Ljava/lang/String;Lnet/minecraft/world/level/LevelInfo;Lnet/minecraft/util/registry/RegistryTracker$Modifiable;Lnet/minecraft/world/gen/GeneratorOptions;)V")
@Inject(at = @At("HEAD"), method = "createWorld")
public void onCreate(String worldName, LevelInfo levelInfo, RegistryTracker.Modifiable registryTracker, GeneratorOptions generatorOptions, CallbackInfo ci) {
RunCategory category = SpeedRunOption.getOption(SpeedRunOptions.TIMER_CATEGORY);
if (category.isAutoStart()) InGameTimer.start(worldName, RunType.fromBoolean(InGameTimerUtils.IS_SET_SEED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@

import com.redlimerl.speedrunigt.option.SpeedRunOption;
import com.redlimerl.speedrunigt.option.SpeedRunOptions;
import com.redlimerl.speedrunigt.utils.TranslateHelper;
import com.redlimerl.speedrunigt.utils.ResourcesHelper;
import net.minecraft.client.resource.language.TranslationStorage;
import net.minecraft.resource.Resource;
import net.minecraft.util.Language;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;
import java.util.Map;
import java.util.Optional;

@Mixin(TranslationStorage.class)
public class TranslationStorageMixin {

@Inject(method = "load(Ljava/util/List;Ljava/util/Map;)V", at = @At("RETURN"))
private static void onLoad(List<Resource> resources, Map<String, String> translationMap, CallbackInfo ci) {
TranslateHelper.setup(resources, translationMap::put, SpeedRunOption.getOption(SpeedRunOptions.ALWAYS_ENGLISH_TRANSLATIONS));
resources.forEach(resource -> {
// minecraft always loads en_us as a backup, if using only english translations just skip loading the other attempts
if (SpeedRunOption.getOption(SpeedRunOptions.ALWAYS_ENGLISH_TRANSLATIONS) && !resource.getId().getPath().equalsIgnoreCase("lang/en_us.json"))
return;
Optional.ofNullable(ResourcesHelper.toStream("/assets/speedrunigt/" + resource.getId().getPath()))
.ifPresent(langStream -> Language.load(langStream, translationMap::put));
});
}
}
31 changes: 0 additions & 31 deletions src/main/java/com/redlimerl/speedrunigt/utils/TranslateHelper.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
package com.redlimerl.speedrunigt.utils;

import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.Resource;
import net.minecraft.util.Language;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.List;
import java.util.function.BiConsumer;

public class TranslateHelper {
public static String[] getLangFileNames() throws IOException, URISyntaxException {
return ResourcesHelper.getResourceChildren("lang");
}

public static void setup(List<Resource> resources, BiConsumer<String, String> biConsumer, boolean englishOnly) {
try {
for (String langFileName : getLangFileNames()) {
if (englishOnly && !langFileName.endsWith("en_us.json")) continue;

for (Resource resource : resources) {
if (!langFileName.endsWith(resource.getId().getPath())) continue;

InputStream inputStream = TranslateHelper.class.getResourceAsStream(langFileName);
if (inputStream != null) {
Language.load(inputStream, biConsumer);
}
}
}
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}

public static void reload() {
MinecraftClient.getInstance().reloadResources();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],

"depends": {
"fabricloader": ">=0.12.2",
"fabricloader": ">=0.14.20",
"minecraft": "{{MC_VERSION}}"
},

Expand Down