24c58cbMerge branch '1.8' into 1.8.91ffeb01Update jGuic122d30Merge branch '1.8-path-segments' into 1.827fd25aFix crash when server responds with garbage to language query (fixes #51)db6b0ffFix / by 0 when two spectator keyframes are closer than 50ms (fixes #60)d61d0acFix hand of invisible spectated player being visible (fixes #59)f7460f9Re-enable time path after path playback (fixes #55)bdbffd5Add Catmull-Rom spline interpolator to simplepathing5cbfd28Generate interpolator settings from InterpolatorType enum6095aefFix loading and storing of default interpolator with settings3f52336Revert "Fix AbstractMethodError caused by FG2.0 not supporting lambdas (fixes #58)"c6293bcUpdate to FG2.2c8126edMerge '1.8' into 1.8.964898ceFix NPE when saving recorded resource pack70e3e54Fix AbstractMethodError caused by FG2.0 not supporting lambdas (fixes #58)3f2b3d6Fix replacing source file in Replay Editor (fixes #57)d2def94Fix duration of replays corrupted because of JVM/OS crash2c64030Refactor simple pathing timeline logic into dedicated class with unit tests Fix logic for user-set interpolators4deb374Enable validation on focus change for all number input fields5302bcaFix id and text of Replay Editor button in docs057edccManually inject root cert for cross-signed LetsEncrypt cert in requestscd16211Register new Property to imply that the path segment following a keyframe has a user-set interpolator instead of the default Modified Keyframe GUI to allow for custom Path interpolator
118 lines
4.4 KiB
Java
118 lines
4.4 KiB
Java
package com.replaymod.extras;
|
|
|
|
import com.google.common.base.Charsets;
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.replaymod.core.ReplayMod;
|
|
import com.replaymod.online.ReplayModOnline;
|
|
import com.replaymod.online.api.ApiClient;
|
|
import com.replaymod.online.api.ApiException;
|
|
import lombok.RequiredArgsConstructor;
|
|
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.lang3.StringEscapeUtils;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.ConnectException;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
public class LocalizationExtra implements Extra {
|
|
private ReplayModOnline module;
|
|
|
|
@Override
|
|
public void register(ReplayMod mod) throws Exception {
|
|
this.module = ReplayModOnline.instance;
|
|
|
|
final Minecraft mc = mod.getMinecraft();
|
|
Thread localizedResourcePackLoader = new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
try {
|
|
@SuppressWarnings("unchecked")
|
|
List<IResourcePack> defaultResourcePacks = mc.defaultResourcePacks;
|
|
defaultResourcePacks.add(new LocalizedResourcePack(module.getApiClient()));
|
|
mc.addScheduledTask(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
mc.refreshResources();
|
|
}
|
|
});
|
|
} catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}, "localizedResourcePackLoader");
|
|
localizedResourcePackLoader.start();
|
|
}
|
|
|
|
@RequiredArgsConstructor
|
|
public static class LocalizedResourcePack implements IResourcePack {
|
|
private final ApiClient apiClient;
|
|
private Map<String, String> availableLanguages = new HashMap<>();
|
|
private boolean websiteAvailable = true;
|
|
|
|
@Override
|
|
public InputStream getInputStream(ResourceLocation loc) {
|
|
if(!loc.getResourcePath().endsWith(".lang")) return null;
|
|
String langcode = loc.getResourcePath().split("/")[1].split("\\.")[0];
|
|
if(availableLanguages.containsKey(langcode)) return new ByteArrayInputStream(availableLanguages.get(langcode).getBytes(Charsets.UTF_8));
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public boolean resourceExists(ResourceLocation loc) {
|
|
if(!(loc.getResourcePath().endsWith(".lang"))) return false;
|
|
String langcode = loc.getResourcePath().split("/")[1].split("\\.")[0];
|
|
if(availableLanguages.containsKey(langcode)) return true;
|
|
if(!websiteAvailable) return false;
|
|
try {
|
|
if (Boolean.parseBoolean(System.getProperty("replaymod.offline", "false"))) {
|
|
return false;
|
|
}
|
|
String lang = apiClient.getTranslation(langcode);
|
|
String prop = StringEscapeUtils.unescapeHtml4(lang);
|
|
availableLanguages.put(langcode, prop);
|
|
return true;
|
|
} catch (ApiException e) {
|
|
if (e.getError() == null || e.getError().getId() != 16) { // This language has not been translated
|
|
e.printStackTrace();
|
|
}
|
|
} catch(ConnectException ce) {
|
|
websiteAvailable = false;
|
|
ce.printStackTrace();
|
|
} catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Set<String> getResourceDomains() {
|
|
return ImmutableSet.of("minecraft", "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";
|
|
}
|
|
}
|
|
}
|