ed56673Merge branch '1.8' into 1.8.991573d9Update jGui, ReplayStudio and Translationsd71358bAdd confirmation dialog before overwriting path presets (fixes #65)1a55983Move addCallback method from integration test Utils to main Utils18c5bcdBe more cooperative with other mods on the ingame menu (fixes #42)c054fe8Register keys for simplepathing only once (fixes #63)f13297cFix default interpolator handling in keyframe gui and after loading (fixes #64)391f304Show error popup if entity tracker fails to load0e0eaaaFix entity tracker being set even if it failed loading (fixes #50)a34bbbcFix NPE when spectating a player without a camera entity60879fbChange local class to be an inner class because Srg2Source breaks with itdfafbecLoad translations from github repo, only reload language not all resource packs8a6ec51Add missing tooltips to player overview and various missing chat messages5677fc5Re-add warning to replay editor748a91eFix missing tooltips on fav/like/dislike buttons in replay centeree24866Fix upload replay button not being updated when name/tags changedba085cMove translations into separate repo3f0e3e7Fix NPE when receiving Replay|Restrict messages (fixes #16 GH)40e1d85Fix crash when saving the last keyframe in the edit gui (fixes #61)03aada1Update Mixin to 0.6.8 (fixes #9 GH)0c1dc65Fix interpolator being lost when moving keyframe to the end (fixes #62)fcbbbc9Add integration test. Run with ./gradlew runIntegrationTestfe6ded0Fix movement of keyframe via GuiEditKeyframe not updating selected keyframef58fa8fFix Login GUI not respecting other GUIs opened on startup4fc3a31Fix OpenEye being installed into working dir instead of mcDataDir
122 lines
4.7 KiB
Java
122 lines
4.7 KiB
Java
package com.replaymod.extras;
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.replaymod.core.ReplayMod;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.resources.IResourcePack;
|
|
import net.minecraft.client.resources.data.IMetadataSection;
|
|
import net.minecraft.client.resources.data.MetadataSerializer;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.URL;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipInputStream;
|
|
|
|
import static com.replaymod.extras.ReplayModExtras.LOGGER;
|
|
|
|
public class LocalizationExtra implements Extra {
|
|
private static final String ZIP_FILE_URL = "https://github.com/ReplayMod/Translations/archive/master.zip";
|
|
private static final String LANG_PREFIX = "Translations-master/";
|
|
|
|
@Override
|
|
public void register(ReplayMod mod) throws Exception {
|
|
final Minecraft mc = mod.getMinecraft();
|
|
if (Boolean.parseBoolean(System.getProperty("replaymod.offline", "false"))) {
|
|
return;
|
|
}
|
|
Thread localizedResourcePackLoader = new Thread(() -> {
|
|
try {
|
|
// Download zip of lang files
|
|
LOGGER.debug("Downloading languages from {}", ZIP_FILE_URL);
|
|
Map<String, byte[]> languages = new HashMap<>();
|
|
try (InputStream urlIn = new URL(ZIP_FILE_URL).openStream();
|
|
ZipInputStream in = new ZipInputStream(urlIn)) {
|
|
ZipEntry entry;
|
|
while ((entry = in.getNextEntry()) != null) {
|
|
String name = entry.getName();
|
|
if (!name.startsWith(LANG_PREFIX) || !name.endsWith(".lang")) {
|
|
continue;
|
|
}
|
|
name = name.substring(LANG_PREFIX.length());
|
|
languages.put(name, IOUtils.toByteArray(in));
|
|
LOGGER.debug("Added language file {}", name);
|
|
}
|
|
}
|
|
LOGGER.debug("Downloaded {} languages", languages.size());
|
|
|
|
// Add lang files as resource pack
|
|
mc.addScheduledTask(() -> {
|
|
@SuppressWarnings("unchecked")
|
|
List<IResourcePack> defaultResourcePacks = mc.defaultResourcePacks;
|
|
defaultResourcePacks.add(new LocalizedResourcePack(languages));
|
|
mc.getLanguageManager().onResourceManagerReload(mc.getResourceManager());
|
|
LOGGER.debug("Added language files to resource packs and reloaded LanguageManager");
|
|
});
|
|
} catch (Throwable t) {
|
|
LOGGER.error("Loading localized resource pack:", t);
|
|
}
|
|
}, "localizedResourcePackLoader");
|
|
localizedResourcePackLoader.setDaemon(true);
|
|
localizedResourcePackLoader.start();
|
|
}
|
|
|
|
public static class LocalizedResourcePack implements IResourcePack {
|
|
private final Pattern LANG_PATTERN = Pattern.compile("^lang/([.+].lang)$");
|
|
private final Map<String, byte[]> languages;
|
|
|
|
public LocalizedResourcePack(Map<String, byte[]> languages) {
|
|
this.languages = languages;
|
|
}
|
|
|
|
@Override
|
|
public InputStream getInputStream(ResourceLocation loc) {
|
|
if (!"replaymod".equals(loc.getResourceDomain())) return null;
|
|
Matcher matcher = LANG_PATTERN.matcher(loc.getResourcePath());
|
|
if (matcher.matches()) {
|
|
byte[] bytes = languages.get(matcher.group());
|
|
if (bytes != null) {
|
|
return new ByteArrayInputStream(bytes);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public boolean resourceExists(ResourceLocation loc) {
|
|
// Assumes that getInputStream returns a ByteArrayInputStream that doesn't need to be closed
|
|
return getInputStream(loc) != null;
|
|
}
|
|
|
|
@Override
|
|
public Set<String> getResourceDomains() {
|
|
return ImmutableSet.of("replaymod");
|
|
}
|
|
|
|
@Override
|
|
public <T extends IMetadataSection> T getPackMetadata(MetadataSerializer metadataSerializer, String metadataSectionName) throws IOException {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public BufferedImage getPackImage() throws IOException {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public String getPackName() {
|
|
return "ReplayModLocalizationResourcePack";
|
|
}
|
|
}
|
|
}
|