Merge branch 'johni/1.13-pre' into johni/blend
This commit is contained in:
@@ -6,12 +6,19 @@ import com.replaymod.core.versions.MCVer;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
//#if MC>=11300
|
||||
//#else
|
||||
//$$ import org.lwjgl.input.Keyboard;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10800
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
//#else
|
||||
@@ -95,24 +102,25 @@ public class KeyBindingRegistry {
|
||||
} catch (Throwable cause) {
|
||||
CrashReport crashReport = CrashReport.makeCrashReport(cause, "Handling Key Binding");
|
||||
CrashReportCategory category = crashReport.makeCategory("Key Binding");
|
||||
category.addCrashSection("Key Binding", keyBinding);
|
||||
MCVer.addDetail(category, "Key Binding", keyBinding::toString);
|
||||
MCVer.addDetail(category, "Handler", runnable::toString);
|
||||
throw new ReportedException(crashReport);
|
||||
throw newReportedException(crashReport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleRaw() {
|
||||
int keyCode = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
|
||||
//int keyCode = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
|
||||
int keyCode = -1; // FIXME
|
||||
for (final Runnable runnable : rawHandlers.get(keyCode)) {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable cause) {
|
||||
CrashReport crashReport = CrashReport.makeCrashReport(cause, "Handling Raw Key Binding");
|
||||
CrashReportCategory category = crashReport.makeCategory("Key Binding");
|
||||
category.addCrashSection("Key Code", keyCode);
|
||||
MCVer.addDetail(category, "Key Code", () -> "" + keyCode);
|
||||
MCVer.addDetail(category, "Handler", runnable::toString);
|
||||
throw new ReportedException(crashReport);
|
||||
throw newReportedException(crashReport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
|
||||
//#if MC<11300
|
||||
//$$ import org.apache.logging.log4j.LogManager;
|
||||
//$$ import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
//$$ import org.spongepowered.asm.mixin.Mixins;
|
||||
//$$
|
||||
//#if MC>=10800
|
||||
import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||
//$$ import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||
//$$ import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||
//#else
|
||||
//$$ import com.replaymod.core.asm.GLErrorTransformer;
|
||||
//$$ import com.replaymod.core.asm.GLStateTrackerTransformer;
|
||||
@@ -16,57 +17,57 @@ import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||
//$$ import java.util.ArrayList;
|
||||
//$$ import java.util.List;
|
||||
//#endif
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.security.CodeSource;
|
||||
import java.util.Map;
|
||||
|
||||
@IFMLLoadingPlugin.TransformerExclusions("com.replaymod.core.asm.")
|
||||
public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
|
||||
public LoadingPlugin() {
|
||||
MixinBootstrap.init();
|
||||
Mixins.addConfiguration("mixins.recording.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.render.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.render.blend.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.replay.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.compat.mapwriter.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.compat.shaders.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.extras.playeroverview.replaymod.json");
|
||||
|
||||
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
|
||||
if (codeSource != null) {
|
||||
URL location = codeSource.getLocation();
|
||||
try {
|
||||
File file = new File(location.toURI());
|
||||
if (file.isFile()) {
|
||||
// This forces forge to reexamine the jar file for FML mods
|
||||
// Should eventually be handled by Mixin itself, maybe?
|
||||
//$$
|
||||
//$$ import java.io.File;
|
||||
//$$ import java.net.URISyntaxException;
|
||||
//$$ import java.net.URL;
|
||||
//$$ import java.security.CodeSource;
|
||||
//$$ import java.util.Map;
|
||||
//$$
|
||||
//$$ @IFMLLoadingPlugin.TransformerExclusions("com.replaymod.core.asm.")
|
||||
//$$ public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
//$$
|
||||
//$$ public LoadingPlugin() {
|
||||
//$$ MixinBootstrap.init();
|
||||
//$$ Mixins.addConfiguration("mixins.recording.replaymod.json");
|
||||
//$$ Mixins.addConfiguration("mixins.render.replaymod.json");
|
||||
//$$ Mixins.addConfiguration("mixins.render.blend.replaymod.json");
|
||||
//$$ Mixins.addConfiguration("mixins.replay.replaymod.json");
|
||||
//$$ Mixins.addConfiguration("mixins.compat.mapwriter.replaymod.json");
|
||||
//$$ Mixins.addConfiguration("mixins.compat.shaders.replaymod.json");
|
||||
//$$ Mixins.addConfiguration("mixins.extras.playeroverview.replaymod.json");
|
||||
//$$
|
||||
//$$ CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
|
||||
//$$ if (codeSource != null) {
|
||||
//$$ URL location = codeSource.getLocation();
|
||||
//$$ try {
|
||||
//$$ File file = new File(location.toURI());
|
||||
//$$ if (file.isFile()) {
|
||||
//$$ // This forces forge to reexamine the jar file for FML mods
|
||||
//$$ // Should eventually be handled by Mixin itself, maybe?
|
||||
//#if MC>=10809
|
||||
CoreModManager.getIgnoredMods().remove(file.getName());
|
||||
//$$ CoreModManager.getIgnoredMods().remove(file.getName());
|
||||
//#else
|
||||
//$$ CoreModManager.getLoadedCoremods().remove(file.getName());
|
||||
//#if MC<=10710
|
||||
//$$ CoreModManager.getReparseableCoremods().add(file.getName());
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
LogManager.getLogger().warn("No CodeSource, if this is not a development environment we might run into problems!");
|
||||
LogManager.getLogger().warn(getClass().getProtectionDomain());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
//$$ }
|
||||
//$$ } catch (URISyntaxException e) {
|
||||
//$$ e.printStackTrace();
|
||||
//$$ }
|
||||
//$$ } else {
|
||||
//$$ LogManager.getLogger().warn("No CodeSource, if this is not a development environment we might run into problems!");
|
||||
//$$ LogManager.getLogger().warn(getClass().getProtectionDomain());
|
||||
//$$ }
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public String[] getASMTransformerClass() {
|
||||
//#if MC>=10800
|
||||
return new String[]{
|
||||
};
|
||||
//$$ return new String[]{
|
||||
//$$ };
|
||||
//#else
|
||||
//$$ List<String> transformers = new ArrayList<>();
|
||||
//$$ if ("true".equals(System.getProperty("replaymod.glerrors", "false"))) {
|
||||
@@ -75,25 +76,26 @@ public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
//$$ transformers.add(GLStateTrackerTransformer.class.getName());
|
||||
//$$ return transformers.stream().toArray(String[]::new);
|
||||
//#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModContainerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSetupClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTransformerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public String getModContainerClass() {
|
||||
//$$ return null;
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public String getSetupClass() {
|
||||
//$$ return null;
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public void injectData(Map<String, Object> data) {
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ @Override
|
||||
//$$ public String getAccessTransformerClass() {
|
||||
//$$ return null;
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
10
src/main/java/com/replaymod/core/Module.java
Normal file
10
src/main/java/com/replaymod/core/Module.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
public interface Module {
|
||||
// FMLCommonSetupEvent for 1.13+, FMLInitializationEvent below
|
||||
default void initCommon() {}
|
||||
// FMLClientSetupEvent for 1.13+, FMLInitializationEvent (if client) below
|
||||
default void initClient() {}
|
||||
// FMLClientSetupEvent for 1.13+, FMLInitializationEvent below
|
||||
default void registerKeyBindings(KeyBindingRegistry registry) {}
|
||||
}
|
||||
@@ -2,21 +2,42 @@ package com.replaymod.core;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.util.concurrent.ListenableFutureTask;
|
||||
import com.replaymod.core.gui.GuiBackgroundProcesses;
|
||||
import com.replaymod.core.gui.GuiReplaySettings;
|
||||
import com.replaymod.core.gui.RestoreReplayGui;
|
||||
import com.replaymod.core.handler.MainMenuHandler;
|
||||
import com.replaymod.core.utils.OpenGLUtils;
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
import com.replaymod.editor.ReplayModEditor;
|
||||
import com.replaymod.extras.ReplayModExtras;
|
||||
import com.replaymod.online.ReplayModOnline;
|
||||
import com.replaymod.recording.ReplayModRecording;
|
||||
import com.replaymod.render.ReplayModRender;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replaystudio.util.I18n;
|
||||
import com.replaymod.simplepathing.ReplayModSimplePathing;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.FolderResourcePack;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
//#if MC>=11300
|
||||
import com.replaymod.core.versions.LangResourcePack;
|
||||
import net.minecraft.resources.FolderPack;
|
||||
import net.minecraft.resources.IPackFinder;
|
||||
import net.minecraft.resources.ResourcePackInfo;
|
||||
import net.minecraftforge.fml.DeferredWorkQueue;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.versions.mcp.MCPVersion;
|
||||
//#else
|
||||
//$$ import net.minecraft.client.resources.FolderResourcePack;
|
||||
//$$ import net.minecraft.client.resources.IResourcePack;
|
||||
//$$ import net.minecraftforge.common.config.Configuration;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10904
|
||||
import net.minecraft.util.text.*;
|
||||
//#else
|
||||
@@ -28,18 +49,23 @@ import net.minecraft.util.text.*;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10800
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
//#if MC>=11300
|
||||
import net.minecraft.client.GameSettings;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
//#else
|
||||
//$$ import net.minecraft.client.settings.GameSettings;
|
||||
//$$ import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
//$$ import net.minecraftforge.fml.common.Loader;
|
||||
//$$ import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
//$$ import net.minecraftforge.fml.common.Mod.Instance;
|
||||
//$$ import net.minecraftforge.fml.common.ModContainer;
|
||||
//$$ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
//$$ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.Loader;
|
||||
@@ -48,9 +74,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
//$$ import cpw.mods.fml.common.Mod.Instance;
|
||||
//$$ import cpw.mods.fml.common.ModContainer;
|
||||
//$$ import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
//$$ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
//$$ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
//$$ import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
//$$ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
//$$ import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
//$$ import com.replaymod.replay.InputReplayTimer;
|
||||
@@ -62,48 +86,108 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
@Mod(modid = ReplayMod.MOD_ID,
|
||||
useMetadata = true,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
acceptableRemoteVersions = "*",
|
||||
//#if MC>=11300
|
||||
@Mod(ReplayMod.MOD_ID)
|
||||
//#else
|
||||
//$$ @Mod(modid = ReplayMod.MOD_ID,
|
||||
//$$ useMetadata = true,
|
||||
//$$ version = "@MOD_VERSION@",
|
||||
//$$ acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
//$$ acceptableRemoteVersions = "*",
|
||||
//#if MC>=10800
|
||||
clientSideOnly = true,
|
||||
updateJSON = "https://raw.githubusercontent.com/ReplayMod/ReplayMod/master/versions.json",
|
||||
//$$ clientSideOnly = true,
|
||||
//$$ updateJSON = "https://raw.githubusercontent.com/ReplayMod/ReplayMod/master/versions.json",
|
||||
//#endif
|
||||
guiFactory = "com.replaymod.core.gui.GuiFactory")
|
||||
public class ReplayMod {
|
||||
//$$ guiFactory = "com.replaymod.core.gui.GuiFactory")
|
||||
//#endif
|
||||
public class ReplayMod implements Module {
|
||||
|
||||
public static ModContainer getContainer() {
|
||||
return Loader.instance().getIndexedModList().get(MOD_ID);
|
||||
//#if MC>=11300
|
||||
return ModList.get().getModContainerById(MOD_ID).get();
|
||||
//#else
|
||||
//$$ return Loader.instance().getIndexedModList().get(MOD_ID);
|
||||
//#endif
|
||||
}
|
||||
|
||||
@Getter(lazy = true)
|
||||
private static final String minecraftVersion = Loader.MC_VERSION;
|
||||
//#if MC>=11300
|
||||
private static final String minecraftVersion = MCPVersion.getMCVersion();
|
||||
//#else
|
||||
//$$ private static final String minecraftVersion = Loader.MC_VERSION;
|
||||
//#endif
|
||||
|
||||
public static final String MOD_ID = "replaymod";
|
||||
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation("replaymod", "replay_gui.png");
|
||||
public static final int TEXTURE_SIZE = 256;
|
||||
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
private static final Minecraft mc = MCVer.getMinecraft();
|
||||
|
||||
@Deprecated
|
||||
public static Configuration config;
|
||||
//#if MC<11300
|
||||
//$$ @Deprecated
|
||||
//$$ public static Configuration config;
|
||||
//#endif
|
||||
|
||||
private final KeyBindingRegistry keyBindingRegistry = new KeyBindingRegistry();
|
||||
private final SettingsRegistry settingsRegistry = new SettingsRegistry();
|
||||
{
|
||||
settingsRegistry.register(Setting.class);
|
||||
}
|
||||
|
||||
// The instance of your mod that Forge uses.
|
||||
@Instance(MOD_ID)
|
||||
//#if MC>=11300
|
||||
{ instance = this; }
|
||||
//#else
|
||||
//$$ @Instance(MOD_ID)
|
||||
//#endif
|
||||
public static ReplayMod instance;
|
||||
|
||||
private final List<Module> modules = new ArrayList<>();
|
||||
|
||||
private final GuiBackgroundProcesses backgroundProcesses = new GuiBackgroundProcesses();
|
||||
|
||||
public ReplayMod() {
|
||||
I18n.setI18n(net.minecraft.client.resources.I18n::format);
|
||||
|
||||
//#if MC>=11300
|
||||
DeferredWorkQueue.runLater(() -> MCVer.getMinecraft().resourcePackRepository.addPackFinder(new LangResourcePack.Finder()));
|
||||
//#endif
|
||||
|
||||
// Register all RM modules
|
||||
modules.add(this);
|
||||
modules.add(new ReplayModRecording(this));
|
||||
ReplayModReplay replayModule = new ReplayModReplay(this);
|
||||
modules.add(replayModule);
|
||||
modules.add(new ReplayModOnline(this, replayModule));
|
||||
modules.add(new ReplayModRender(this));
|
||||
modules.add(new ReplayModSimplePathing(this));
|
||||
modules.add(new ReplayModEditor(this));
|
||||
modules.add(new ReplayModExtras(this));
|
||||
|
||||
//#if MC>=11300
|
||||
settingsRegistry.register();
|
||||
//#endif
|
||||
}
|
||||
|
||||
//#if MC<=11300
|
||||
//$$ @EventHandler
|
||||
//$$ public void init(FMLPreInitializationEvent event) {
|
||||
//$$ config = new Configuration(event.getSuggestedConfigurationFile());
|
||||
//$$ config.load();
|
||||
//$$ settingsRegistry.setConfiguration(config);
|
||||
//$$ settingsRegistry.save(); // Save default values to disk
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
public KeyBindingRegistry getKeyBindingRegistry() {
|
||||
return keyBindingRegistry;
|
||||
}
|
||||
@@ -114,33 +198,28 @@ public class ReplayMod {
|
||||
|
||||
public File getReplayFolder() throws IOException {
|
||||
String path = getSettingsRegistry().get(Setting.RECORDING_PATH);
|
||||
File folder = new File(path.startsWith("./") ? getMinecraft().mcDataDir : null, path);
|
||||
File folder = new File(path.startsWith("./") ? mcDataDir(getMinecraft()) : null, path);
|
||||
FileUtils.forceMkdir(folder);
|
||||
return folder;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
// Initialize the static OpenGL info field from the minecraft main thread
|
||||
// Unfortunately lwjgl uses static methods so we have to make use of magic init calls as well
|
||||
OpenGLUtils.init();
|
||||
|
||||
I18n.setI18n(net.minecraft.client.resources.I18n::format);
|
||||
|
||||
config = new Configuration(event.getSuggestedConfigurationFile());
|
||||
config.load();
|
||||
settingsRegistry.setConfiguration(config);
|
||||
}
|
||||
|
||||
//#ifdef DEV_ENV
|
||||
static { // Note: even preInit is too late and we'd have to issue another resource reload
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IResourcePack> defaultResourcePacks = mc.defaultResourcePacks;
|
||||
FolderResourcePack jGuiResourcePack = new FolderResourcePack(new File("../jGui/src/main/resources")) {
|
||||
//#if MC>=11300
|
||||
FolderPack jGuiResourcePack = new FolderPack(new File("../jGui/src/main/resources")) {
|
||||
@Override
|
||||
protected InputStream getInputStreamByName(String resourceName) throws IOException {
|
||||
protected InputStream getInputStream(String resourceName) throws IOException {
|
||||
try {
|
||||
return super.getInputStreamByName(resourceName);
|
||||
return super.getInputStream(resourceName);
|
||||
//#else
|
||||
//$$ List<IResourcePack> defaultResourcePacks = mc.defaultResourcePacks;
|
||||
//$$ FolderResourcePack jGuiResourcePack = new FolderResourcePack(new File("../jGui/src/main/resources")) {
|
||||
//$$ @Override
|
||||
//$$ protected InputStream getInputStreamByName(String resourceName) throws IOException {
|
||||
//$$ try {
|
||||
//$$ return super.getInputStreamByName(resourceName);
|
||||
//#endif
|
||||
} catch (IOException e) {
|
||||
if ("pack.mcmeta".equals(resourceName)) {
|
||||
return new ByteArrayInputStream(("{\"pack\": {\"description\": \"dummy pack for jGui resources in dev-env\", \"pack_format\": 1}}").getBytes(Charsets.UTF_8));
|
||||
@@ -149,7 +228,16 @@ public class ReplayMod {
|
||||
}
|
||||
}
|
||||
};
|
||||
defaultResourcePacks.add(jGuiResourcePack);
|
||||
//#if MC>=11300
|
||||
mc.resourcePackRepository.addPackFinder(new IPackFinder() {
|
||||
@Override
|
||||
public <T extends ResourcePackInfo> void addPackInfosToMap(Map<String, T> map, ResourcePackInfo.IFactory<T> factory) {
|
||||
map.put("jgui", ResourcePackInfo.func_195793_a("jgui", true, () -> jGuiResourcePack, factory, ResourcePackInfo.Priority.BOTTOM));
|
||||
}
|
||||
});
|
||||
//#else
|
||||
//$$ defaultResourcePacks.add(jGuiResourcePack);
|
||||
//#endif
|
||||
//#if MC<=10710
|
||||
//$$ FolderResourcePack mainResourcePack = new FolderResourcePack(new File("../src/main/resources")) {
|
||||
//$$ @Override
|
||||
@@ -169,30 +257,43 @@ public class ReplayMod {
|
||||
}
|
||||
//#endif
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
getSettingsRegistry().register(Setting.class);
|
||||
//#if MC>=11300
|
||||
{
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((FMLCommonSetupEvent event) -> modules.forEach(Module::initCommon));
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((FMLClientSetupEvent event) -> modules.forEach(Module::initClient));
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener((FMLClientSetupEvent event) -> modules.forEach(m -> m.registerKeyBindings(keyBindingRegistry)));
|
||||
}
|
||||
//#else
|
||||
//$$ @EventHandler
|
||||
//$$ public void init(FMLInitializationEvent event) {
|
||||
//$$ modules.forEach(Module::initCommon);
|
||||
//$$ modules.forEach(Module::initClient);
|
||||
//$$ modules.forEach(m -> m.registerKeyBindings(keyBindingRegistry));
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
@Override
|
||||
public void registerKeyBindings(KeyBindingRegistry registry) {
|
||||
registry.registerKeyBinding("replaymod.input.settings", 0, () -> {
|
||||
new GuiReplaySettings(null, settingsRegistry).display();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initClient() {
|
||||
new MainMenuHandler().register();
|
||||
|
||||
//#if MC<=10710
|
||||
//$$ FML_BUS.register(this); // For runLater(Runnable)
|
||||
//#endif
|
||||
|
||||
FML_BUS.register(keyBindingRegistry);
|
||||
|
||||
getKeyBindingRegistry().registerKeyBinding("replaymod.input.settings", 0, () -> {
|
||||
new GuiReplaySettings(null, settingsRegistry).display();
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) throws IOException {
|
||||
settingsRegistry.save(); // Save default values to disk
|
||||
FORGE_BUS.register(backgroundProcesses);
|
||||
|
||||
// 1.7.10 crashes when render distance > 16
|
||||
//#if MC>=10800
|
||||
if(!FMLClientHandler.instance().hasOptifine())
|
||||
GameSettings.Options.RENDER_DISTANCE.setValueMax(64f);
|
||||
//if(!FMLClientHandler.instance().hasOptifine()) FIXME 1.13 update
|
||||
GameSettings.Options.RENDER_DISTANCE.setValueMax(64f);
|
||||
//#endif
|
||||
|
||||
testIfMoeshAndExitMinecraft();
|
||||
@@ -240,19 +341,18 @@ public class ReplayMod {
|
||||
|
||||
public void runLater(Runnable runnable) {
|
||||
if (mc.isCallingFromMinecraftThread() && inRunLater) {
|
||||
EventBus bus = FORGE_BUS;
|
||||
//#if MC>=10800
|
||||
bus.register(new Object() {
|
||||
FORGE_BUS.register(new Object() {
|
||||
@SubscribeEvent
|
||||
public void onRenderTick(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase == TickEvent.Phase.START) {
|
||||
runLater(runnable);
|
||||
bus.unregister(this);
|
||||
FORGE_BUS.unregister(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
//#else
|
||||
//$$ bus.register(new RunLaterHelper(runnable));
|
||||
//$$ FORGE_BUS.register(new RunLaterHelper(runnable));
|
||||
//#endif
|
||||
return;
|
||||
}
|
||||
@@ -309,7 +409,11 @@ public class ReplayMod {
|
||||
//#endif
|
||||
|
||||
public String getVersion() {
|
||||
return getContainer().getVersion();
|
||||
//#if MC>=11300
|
||||
return getContainer().getModInfo().getVersion().toString();
|
||||
//#else
|
||||
//$$ return getContainer().getVersion();
|
||||
//#endif
|
||||
}
|
||||
|
||||
private void testIfMoeshAndExitMinecraft() {
|
||||
@@ -355,4 +459,8 @@ public class ReplayMod {
|
||||
mc.ingameGUI.getChatGUI().printChatMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
public GuiBackgroundProcesses getBackgroundProcesses() {
|
||||
return backgroundProcesses;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,67 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.replaymod.core.events.SettingsChangedEvent;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.common.config.Configuration;
|
||||
//#endif
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
public class SettingsRegistry {
|
||||
private static final Object NULL_OBJECT = new Object();
|
||||
private Map<SettingKey<?>, Object> settings = new ConcurrentHashMap<>();
|
||||
private Configuration configuration;
|
||||
//#if MC>=11300
|
||||
private ForgeConfigSpec spec;
|
||||
private ModConfig config;
|
||||
//#else
|
||||
//$$ private Configuration configuration;
|
||||
//#endif
|
||||
|
||||
public void setConfiguration(Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
//#if MC>=11300
|
||||
public void register() {
|
||||
if (spec == null) {
|
||||
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
|
||||
for (SettingKey<?> key : settings.keySet()) {
|
||||
builder
|
||||
.translation(key.getDisplayString())
|
||||
.define(key.getCategory() + "." + key.getKey(), key.getDefault());
|
||||
}
|
||||
spec = builder.build();
|
||||
}
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::load);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, spec);
|
||||
}
|
||||
|
||||
List<SettingKey<?>> keys = new ArrayList<>(settings.keySet());
|
||||
settings.clear();
|
||||
for (SettingKey key : keys) {
|
||||
register(key);
|
||||
private void load(ModConfig.Loading event) {
|
||||
config = event.getConfig();
|
||||
for (Map.Entry<SettingKey<?>, Object> entry : settings.entrySet()) {
|
||||
SettingKey<?> key = entry.getKey();
|
||||
Object value = config.getConfigData().get(key.getCategory() + "." + key.getKey());
|
||||
entry.setValue(value == null ? key.getDefault() : value);
|
||||
}
|
||||
}
|
||||
//#else
|
||||
//$$ public void setConfiguration(Configuration configuration) {
|
||||
//$$ this.configuration = configuration;
|
||||
//$$
|
||||
//$$ List<SettingKey<?>> keys = new ArrayList<>(settings.keySet());
|
||||
//$$ settings.clear();
|
||||
//$$ for (SettingKey key : keys) {
|
||||
//$$ register(key);
|
||||
//$$ }
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
public void register(Class<?> settingsClass) {
|
||||
for (Field field : settingsClass.getDeclaredFields()) {
|
||||
@@ -40,23 +77,30 @@ public class SettingsRegistry {
|
||||
}
|
||||
|
||||
public void register(SettingKey<?> key) {
|
||||
Object value;
|
||||
if (configuration != null) {
|
||||
if (key.getDefault() instanceof Boolean) {
|
||||
value = configuration.get(key.getCategory(), key.getKey(), (Boolean) key.getDefault()).getBoolean();
|
||||
} else if (key.getDefault() instanceof Integer) {
|
||||
value = configuration.get(key.getCategory(), key.getKey(), (Integer) key.getDefault()).getInt();
|
||||
} else if (key.getDefault() instanceof Double) {
|
||||
value = configuration.get(key.getCategory(), key.getKey(), (Double) key.getDefault()).getDouble();
|
||||
} else if (key.getDefault() instanceof String) {
|
||||
value = configuration.get(key.getCategory(), key.getKey(), (String) key.getDefault()).getString();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
}
|
||||
} else {
|
||||
value = NULL_OBJECT;
|
||||
//#if MC>=11300
|
||||
if (spec != null) {
|
||||
throw new IllegalStateException("Cannot register more settings are spec has been built.");
|
||||
}
|
||||
settings.put(key, value);
|
||||
settings.put(key, NULL_OBJECT);
|
||||
//#else
|
||||
//$$ Object value;
|
||||
//$$ if (configuration != null) {
|
||||
//$$ if (key.getDefault() instanceof Boolean) {
|
||||
//$$ value = configuration.get(key.getCategory(), key.getKey(), (Boolean) key.getDefault()).getBoolean();
|
||||
//$$ } else if (key.getDefault() instanceof Integer) {
|
||||
//$$ value = configuration.get(key.getCategory(), key.getKey(), (Integer) key.getDefault()).getInt();
|
||||
//$$ } else if (key.getDefault() instanceof Double) {
|
||||
//$$ value = configuration.get(key.getCategory(), key.getKey(), (Double) key.getDefault()).getDouble();
|
||||
//$$ } else if (key.getDefault() instanceof String) {
|
||||
//$$ value = configuration.get(key.getCategory(), key.getKey(), (String) key.getDefault()).getString();
|
||||
//$$ } else {
|
||||
//$$ throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
//$$ }
|
||||
//$$ } else {
|
||||
//$$ value = NULL_OBJECT;
|
||||
//$$ }
|
||||
//$$ settings.put(key, value);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public Set<SettingKey<?>> getSettings() {
|
||||
@@ -72,23 +116,35 @@ public class SettingsRegistry {
|
||||
}
|
||||
|
||||
public <T> void set(SettingKey<T> key, T value) {
|
||||
if (key.getDefault() instanceof Boolean) {
|
||||
configuration.get(key.getCategory(), key.getKey(), (Boolean) key.getDefault()).set((Boolean) value);
|
||||
} else if (key.getDefault() instanceof Integer) {
|
||||
configuration.get(key.getCategory(), key.getKey(), (Integer) key.getDefault()).set((Integer) value);
|
||||
} else if (key.getDefault() instanceof Double) {
|
||||
configuration.get(key.getCategory(), key.getKey(), (Double) key.getDefault()).set((Double) value);
|
||||
} else if (key.getDefault() instanceof String) {
|
||||
configuration.get(key.getCategory(), key.getKey(), (String) key.getDefault()).set((String) value);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
//#if MC>=11300
|
||||
if (config != null) {
|
||||
config.getConfigData().set(key.getCategory() + "." + key.getKey(), value);
|
||||
}
|
||||
//#else
|
||||
//$$ if (key.getDefault() instanceof Boolean) {
|
||||
//$$ configuration.get(key.getCategory(), key.getKey(), (Boolean) key.getDefault()).set((Boolean) value);
|
||||
//$$ } else if (key.getDefault() instanceof Integer) {
|
||||
//$$ configuration.get(key.getCategory(), key.getKey(), (Integer) key.getDefault()).set((Integer) value);
|
||||
//$$ } else if (key.getDefault() instanceof Double) {
|
||||
//$$ configuration.get(key.getCategory(), key.getKey(), (Double) key.getDefault()).set((Double) value);
|
||||
//$$ } else if (key.getDefault() instanceof String) {
|
||||
//$$ configuration.get(key.getCategory(), key.getKey(), (String) key.getDefault()).set((String) value);
|
||||
//$$ } else {
|
||||
//$$ throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
//$$ }
|
||||
//#endif
|
||||
settings.put(key, value);
|
||||
FML_BUS.post(new SettingsChangedEvent(this, key));
|
||||
}
|
||||
|
||||
public void save() {
|
||||
configuration.save();
|
||||
//#if MC>=11300
|
||||
if (config != null) {
|
||||
config.save();
|
||||
}
|
||||
//#else
|
||||
//$$ configuration.save();
|
||||
//#endif
|
||||
}
|
||||
|
||||
public interface SettingKey<T> {
|
||||
@@ -127,7 +183,7 @@ public class SettingsRegistry {
|
||||
|
||||
@Override
|
||||
public String getDisplayString() {
|
||||
return displayString == null ? null : I18n.format(displayString);
|
||||
return displayString;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,11 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
//#if MC>=10800
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
//#endif
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.eventhandler.Event;
|
||||
//#endif
|
||||
|
||||
135
src/main/java/com/replaymod/core/gui/GuiBackgroundProcesses.java
Normal file
135
src/main/java/com/replaymod/core/gui/GuiBackgroundProcesses.java
Normal file
@@ -0,0 +1,135 @@
|
||||
package com.replaymod.core.gui;
|
||||
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.VanillaGuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
//#if MC>=10800
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.getGui;
|
||||
import static com.replaymod.core.versions.MCVer.getMinecraft;
|
||||
|
||||
public class GuiBackgroundProcesses {
|
||||
private GuiPanel panel = new GuiPanel().setLayout(new VerticalLayout().setSpacing(10));
|
||||
|
||||
public void register() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiInit(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
if (getGui(event) != getMinecraft().currentScreen) return; // people tend to construct GuiScreens without opening them
|
||||
|
||||
VanillaGuiScreen.setup(getGui(event)).setLayout(new CustomLayout<GuiScreen>() {
|
||||
@Override
|
||||
protected void layout(GuiScreen container, int width, int height) {
|
||||
pos(panel, width - 5 - width(panel), 5);
|
||||
}
|
||||
}).addElements(null, panel);
|
||||
}
|
||||
|
||||
public void addProcess(GuiElement<?> element) {
|
||||
panel.addElements(new VerticalLayout.Data(1.0),
|
||||
new Element(element));
|
||||
}
|
||||
|
||||
public void removeProcess(GuiElement<?> element) {
|
||||
for (GuiElement child : panel.getChildren()) {
|
||||
if (((Element) child).inner == element) {
|
||||
panel.removeElement(child);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Element extends AbstractGuiContainer<Element> {
|
||||
private GuiElement inner;
|
||||
|
||||
Element(GuiElement inner) {
|
||||
this.inner = inner;
|
||||
addElements(null, inner);
|
||||
|
||||
setLayout(new CustomLayout<Element>() {
|
||||
@Override
|
||||
protected void layout(Element container, int width, int height) {
|
||||
pos(inner, 10, 10);
|
||||
size(inner, width - 20, height - 20);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadableDimension getMinSize() {
|
||||
ReadableDimension minSize = inner.getMinSize();
|
||||
return new Dimension(minSize.getWidth() + 20, minSize.getHeight() + 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||
final int u0 = 0;
|
||||
final int v0 = 39;
|
||||
renderer.bindTexture(TEXTURE);
|
||||
|
||||
int w = size.getWidth();
|
||||
int h = size.getHeight();
|
||||
|
||||
// Corners
|
||||
renderer.drawTexturedRect(0, 0, u0, v0, 5, 5); // Top left
|
||||
renderer.drawTexturedRect(w - 5, 0, u0 + 12, v0, 5, 5); // Top right
|
||||
renderer.drawTexturedRect(0, h - 5, u0, v0 + 12, 5, 5); // Bottom left
|
||||
renderer.drawTexturedRect(w - 5, h - 5, u0 + 12, v0 + 12, 5, 5); // Bottom right
|
||||
|
||||
// Top and bottom edge
|
||||
for (int x = 5; x < w - 5; x += 5) {
|
||||
int rx = Math.min(5, w - 5 - x);
|
||||
renderer.drawTexturedRect(x, 0, u0 + 6, v0, rx, 5); // Top
|
||||
renderer.drawTexturedRect(x, h - 5, u0 + 6, v0 + 12, rx, 5); // Bottom
|
||||
}
|
||||
|
||||
// Left and right edge
|
||||
for (int y = 5; y < h - 5; y += 5) {
|
||||
int ry = Math.min(5, h - 5 - y);
|
||||
renderer.drawTexturedRect(0, y, u0, v0 + 6, 5, ry); // Left
|
||||
renderer.drawTexturedRect(w - 5, y, u0 + 12, v0 + 6, 5, ry); // Right
|
||||
}
|
||||
|
||||
// Center
|
||||
for (int x = 5; x < w - 5; x += 5) {
|
||||
for (int y = 5; y < h - 5; y += 5) {
|
||||
int rx = Math.min(5, w - 5 - x);
|
||||
int ry = Math.min(5, h - 5 - y);
|
||||
renderer.drawTexturedRect(x, y, u0 + 6, v0 + 6, rx, ry);
|
||||
}
|
||||
}
|
||||
|
||||
super.draw(renderer, size, renderInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Element getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class GuiReplaySettings extends AbstractGuiScreen<GuiReplaySettings> {
|
||||
@SuppressWarnings("unchecked")
|
||||
final SettingsRegistry.SettingKey<Boolean> booleanKey = (SettingsRegistry.SettingKey<Boolean>) key;
|
||||
final GuiToggleButton button = new GuiToggleButton<>().setSize(150, 20)
|
||||
.setLabel(key.getDisplayString()).setSelected(settingsRegistry.get(booleanKey) ? 0 : 1)
|
||||
.setI18nLabel(key.getDisplayString()).setSelected(settingsRegistry.get(booleanKey) ? 0 : 1)
|
||||
.setValues(I18n.format("options.on"), I18n.format("options.off"));
|
||||
element = button.onClick(new Runnable() {
|
||||
@Override
|
||||
@@ -60,7 +60,7 @@ public class GuiReplaySettings extends AbstractGuiScreen<GuiReplaySettings> {
|
||||
for (int j = 0; j < entries.length; j++) {
|
||||
Object value = values.get(j);
|
||||
entries[j] = new MultipleChoiceDropdownEntry(value,
|
||||
multipleChoiceKey.getDisplayString() + ": " + I18n.format(value.toString()));
|
||||
I18n.format(multipleChoiceKey.getDisplayString()) + ": " + I18n.format(value.toString()));
|
||||
if (currentValue.equals(value)) {
|
||||
selected = j;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ public class RestoreReplayGui extends AbstractGuiScreen<RestoreReplayGui> {
|
||||
yesButton.onClick(() -> {
|
||||
try {
|
||||
ReplayFile replayFile = new ZipReplayFile(new ReplayStudio(), null, file);
|
||||
// Commit all not-yet-committed files into the main zip file.
|
||||
// If we don't do this, then re-writing packet data below can actually overwrite uncommitted packet data!
|
||||
replayFile.save();
|
||||
ReplayMetaData metaData = replayFile.getMetaData();
|
||||
if (metaData != null && metaData.getDuration() == 0) {
|
||||
// Try to restore replay duration
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.replaymod.core.handler;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -9,13 +10,15 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
//#if MC>=10800
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
//#endif
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.*;
|
||||
|
||||
/**
|
||||
@@ -37,17 +40,18 @@ public class MainMenuHandler {
|
||||
if (x(button) + button.width < gui.width / 2 - 100
|
||||
|| x(button) > gui.width / 2 + 100
|
||||
|| y(button) > gui.height / 4 + 10 + 4 * 24) continue;
|
||||
// Move button up to make space for two rows of buttons
|
||||
// Move button up to make space for one rows of buttons
|
||||
// and then move back down by 10 to compensate for the space to the exit button that was already there
|
||||
int offset = -2 * 24 + 10;
|
||||
int offset = -1 * 24 + 10;
|
||||
y(button, y(button) + offset);
|
||||
//#if MC>=11202
|
||||
if (button == gui.realmsButton) {
|
||||
|
||||
//#if MC>=11300
|
||||
if (button.id == 14) {
|
||||
realmsOffset = offset;
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
//#if MC>=11202
|
||||
//#if MC>=11300
|
||||
if (realmsOffset != 0 && gui.realmsNotification instanceof GuiScreenRealmsProxy) {
|
||||
gui.realmsNotification = new RealmsNotificationProxy((GuiScreenRealmsProxy) gui.realmsNotification, realmsOffset);
|
||||
}
|
||||
@@ -55,7 +59,7 @@ public class MainMenuHandler {
|
||||
}
|
||||
}
|
||||
|
||||
//#if MC>=11202
|
||||
//#if MC>=11300
|
||||
private static class RealmsNotificationProxy extends GuiScreen {
|
||||
private final GuiScreenRealmsProxy proxy;
|
||||
private final int offset;
|
||||
@@ -66,30 +70,25 @@ public class MainMenuHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiSize(int w, int h) {
|
||||
proxy.setGuiSize(w, h);
|
||||
public void setWorldAndResolution(Minecraft mc, int width, int height) {
|
||||
proxy.setWorldAndResolution(mc, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
proxy.initGui();
|
||||
public void tick() {
|
||||
proxy.tick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
proxy.updateScreen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
GL11.glTranslated(0, offset, 0);
|
||||
proxy.drawScreen(mouseX, mouseY - offset, partialTicks);
|
||||
proxy.render(mouseX, mouseY - offset, partialTicks);
|
||||
GL11.glTranslated(0, -offset, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
proxy.mouseClicked(mouseX, mouseY - offset, mouseButton);
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
|
||||
return proxy.mouseClicked(mouseX, mouseY - offset, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,11 +11,16 @@ import net.minecraftforge.registries.RegistryManager;
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.registry.GameData;
|
||||
//#endif
|
||||
//$$ import java.util.stream.Stream;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10800
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.fml.ModList;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.Loader;
|
||||
//$$ import net.minecraftforge.fml.common.ModContainer;
|
||||
//#endif
|
||||
//#else
|
||||
//$$ import cpw.mods.fml.common.Loader;
|
||||
//$$ import cpw.mods.fml.common.ModContainer;
|
||||
@@ -24,22 +29,32 @@ import net.minecraftforge.fml.common.ModContainer;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ModCompat {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Collection<ModInfo> getInstalledNetworkMods() {
|
||||
Map<String, ModContainer> ignoreCaseMap = Loader.instance().getModList().stream()
|
||||
.collect(Collectors.toMap(m -> m.getModId().toLowerCase(), Function.identity()));
|
||||
//#if MC>=11200
|
||||
//#if MC>=11300
|
||||
Map<String, ModInfo> modInfoMap = ModList.get().getMods().stream()
|
||||
.map(m -> new ModInfo(m.getModId(), m.getDisplayName(), m.getVersion().toString()))
|
||||
.collect(Collectors.toMap(ModInfo::getId, Function.identity()));
|
||||
return RegistryManager.ACTIVE.takeSnapshot(false).keySet().stream()
|
||||
.map(RegistryManager.ACTIVE::getRegistry)
|
||||
.map(ForgeRegistry::getKeys).flatMap(Set::stream)
|
||||
.map(ResourceLocation::getResourceDomain).filter(s -> !s.equals("minecraft")).distinct()
|
||||
.map(String::toLowerCase).map(ignoreCaseMap::get).filter(mod -> mod != null)
|
||||
.map(mod -> new ModInfo(mod.getModId(), mod.getName(), mod.getVersion()))
|
||||
.map(ResourceLocation::getNamespace).filter(s -> !s.equals("minecraft")).distinct()
|
||||
.map(modInfoMap::get).filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
//#else
|
||||
//$$ Map<String, ModContainer> ignoreCaseMap = Loader.instance().getModList().stream()
|
||||
//$$ .collect(Collectors.toMap(m -> m.getModId().toLowerCase(), Function.identity()));
|
||||
//#if MC>=11200
|
||||
//$$ return RegistryManager.ACTIVE.takeSnapshot(false).keySet().stream()
|
||||
//$$ .map(RegistryManager.ACTIVE::getRegistry)
|
||||
//$$ .map(ForgeRegistry::getKeys).flatMap(Set::stream)
|
||||
//$$ .map(ResourceLocation::getResourceDomain).filter(s -> !s.equals("minecraft")).distinct()
|
||||
//$$ .map(String::toLowerCase).map(ignoreCaseMap::get).filter(mod -> mod != null)
|
||||
//$$ .map(mod -> new ModInfo(mod.getModId(), mod.getName(), mod.getVersion()))
|
||||
//$$ .collect(Collectors.toList());
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
//$$ return Stream.concat(
|
||||
//$$ ((Set<ResourceLocation>) GameData.getBlockRegistry().getKeys()).stream(),
|
||||
@@ -61,6 +76,7 @@ public class ModCompat {
|
||||
//$$ .collect(Collectors.toList());
|
||||
//#endif
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static final class ModInfoDifference {
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class OpenGLUtils {
|
||||
public static final int VIEWPORT_MAX_WIDTH;
|
||||
public static final int VIEWPORT_MAX_HEIGHT;
|
||||
|
||||
static {
|
||||
IntBuffer buffer = BufferUtils.createIntBuffer(16);
|
||||
GL11.glGetInteger(GL11.GL_MAX_VIEWPORT_DIMS, buffer);
|
||||
VIEWPORT_MAX_WIDTH = buffer.get();
|
||||
VIEWPORT_MAX_HEIGHT = buffer.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic init method which has to be called from the OpenGL thread so the variables in this class
|
||||
* can be initialized successfully.
|
||||
* Does not perform any work on its own.
|
||||
*/
|
||||
public static void init() {
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.replaymod.core.utils;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
//#if MC>=10904
|
||||
import net.minecraft.network.play.server.SPacketCustomPayload;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
//#else
|
||||
//$$ import net.minecraft.network.play.server.S3FPacketCustomPayload;
|
||||
//#endif
|
||||
@@ -18,7 +19,11 @@ import static com.replaymod.core.versions.MCVer.readString;
|
||||
* @see <a href="https://gist.github.com/Johni0702/2547c463e51f65f312cb">Replay Restrictions Gist</a>
|
||||
*/
|
||||
public class Restrictions {
|
||||
public static final String PLUGIN_CHANNEL = "Replay|Restrict";
|
||||
//#if MC>=11300
|
||||
public static final ResourceLocation PLUGIN_CHANNEL = new ResourceLocation("replaymod", "restrict");
|
||||
//#else
|
||||
//$$ public static final String PLUGIN_CHANNEL = "Replay|Restrict";
|
||||
//#endif
|
||||
private boolean noXray;
|
||||
private boolean noNoclip;
|
||||
private boolean onlyFirstPerson;
|
||||
|
||||
@@ -18,15 +18,20 @@ import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.GuiInfoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import de.johni0702.minecraft.gui.versions.MCVer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
//#if MC>=11300
|
||||
//#else
|
||||
//$$ import org.lwjgl.input.Keyboard;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10800
|
||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||
@@ -64,16 +69,30 @@ import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.minecraft.client.Minecraft.getMinecraft;
|
||||
import static com.replaymod.core.versions.MCVer.Minecraft_mcDataDir;
|
||||
import static com.replaymod.core.versions.MCVer.getMinecraft;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static InputStream getResourceAsStream(String path) {
|
||||
// FIXME this seems broken in 1.13, hence the workaround. probably want to open an issue with modlauncher (or forge?)
|
||||
//#ifdef DEV_ENV
|
||||
try {
|
||||
return new java.io.FileInputStream(new File("../src/main/resources" + path));
|
||||
} catch (java.io.FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//#else
|
||||
//$$ return Utils.class.getResourceAsStream(path);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static final BufferedImage DEFAULT_THUMBNAIL;
|
||||
|
||||
static {
|
||||
BufferedImage thumbnail;
|
||||
try {
|
||||
thumbnail = ImageIO.read(Utils.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
|
||||
thumbnail = ImageIO.read(getResourceAsStream("/default_thumb.jpg"));
|
||||
} catch (Exception e) {
|
||||
thumbnail = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
|
||||
e.printStackTrace();
|
||||
@@ -98,7 +117,7 @@ public class Utils {
|
||||
|
||||
static {
|
||||
// Largely from https://community.letsencrypt.org/t/134/37
|
||||
try (InputStream in = Utils.class.getResourceAsStream("/dst_root_ca_x3.pem")){
|
||||
try (InputStream in = getResourceAsStream("/dst_root_ca_x3.pem")){
|
||||
Certificate certificate = CertificateFactory.getInstance("X.509").generateCertificate(in);
|
||||
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
@@ -189,7 +208,11 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static boolean isCtrlDown() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
|
||||
//#if MC>=11300
|
||||
return GuiScreen.isCtrlKeyDown();
|
||||
//#else
|
||||
//$$ return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static <T> void addCallback(ListenableFuture<T> future, Consumer<T> onSuccess, Consumer<Throwable> onFailure) {
|
||||
@@ -216,7 +239,7 @@ public class Utils {
|
||||
// Try to save the crash report
|
||||
if (crashReport.getFile() == null) {
|
||||
try {
|
||||
File folder = new File(getMinecraft().mcDataDir, "crash-reports");
|
||||
File folder = new File(Minecraft_mcDataDir(getMinecraft()), "crash-reports");
|
||||
File file = new File(folder, "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-client.txt");
|
||||
logger.debug("Saving crash report to file: {}", file);
|
||||
crashReport.saveToFile(file);
|
||||
@@ -263,7 +286,7 @@ public class Utils {
|
||||
|
||||
// Replace close button with panel containing close and copy buttons
|
||||
GuiButton copyToClipboardButton = new GuiButton().setI18nLabel("chat.copy").onClick(() ->
|
||||
GuiScreen.setClipboardString(crashReport)).setSize(150, 20);
|
||||
MCVer.setClipboardString(crashReport)).setSize(150, 20);
|
||||
GuiButton closeButton = getCloseButton();
|
||||
popup.removeElement(closeButton);
|
||||
popup.addElements(new VerticalLayout.Data(1),
|
||||
@@ -281,4 +304,17 @@ public class Utils {
|
||||
super.draw(renderer, size, renderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Throwable> void throwIfInstanceOf(Throwable t, Class<T> cls) throws T {
|
||||
if (cls.isInstance(t)) {
|
||||
throw cls.cast(t);
|
||||
}
|
||||
}
|
||||
public static void throwIfUnchecked(Throwable t) {
|
||||
if (t instanceof RuntimeException) {
|
||||
throw (RuntimeException) t;
|
||||
} else if (t instanceof Error) {
|
||||
throw (Error) t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,27 @@ public class WrappedTimer extends Timer {
|
||||
protected final Timer wrapped;
|
||||
|
||||
public WrappedTimer(Timer wrapped) {
|
||||
super(0);
|
||||
//#if MC>=11300
|
||||
super(0, 0);
|
||||
//#else
|
||||
//$$ super(0);
|
||||
//#endif
|
||||
this.wrapped = wrapped;
|
||||
copy(wrapped, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTimer() {
|
||||
public void updateTimer(
|
||||
//#if MC>=11300
|
||||
long sysClock
|
||||
//#endif
|
||||
) {
|
||||
copy(this, wrapped);
|
||||
wrapped.updateTimer();
|
||||
wrapped.updateTimer(
|
||||
//#if MC>=11300
|
||||
sysClock
|
||||
//#endif
|
||||
);
|
||||
copy(wrapped, this);
|
||||
}
|
||||
|
||||
|
||||
146
src/main/java/com/replaymod/core/versions/LangResourcePack.java
Normal file
146
src/main/java/com/replaymod/core/versions/LangResourcePack.java
Normal file
@@ -0,0 +1,146 @@
|
||||
//#if MC>=11300
|
||||
package com.replaymod.core.versions;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import net.minecraft.resources.AbstractResourcePack;
|
||||
import net.minecraft.resources.IPackFinder;
|
||||
import net.minecraft.resources.IResourcePack;
|
||||
import net.minecraft.resources.ResourcePackFileNotFoundException;
|
||||
import net.minecraft.resources.ResourcePackInfo;
|
||||
import net.minecraft.resources.ResourcePackType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
import net.minecraftforge.fml.packs.ModFileResourcePack;
|
||||
import net.minecraftforge.fml.packs.ResourcePackLoader;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringBufferInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Resource pack which on-the-fly converts pre-1.13 language files into 1.13 json format.
|
||||
*/
|
||||
public class LangResourcePack extends AbstractResourcePack {
|
||||
private static final Gson GSON = new Gson();
|
||||
private static final String NAME = "replaymod_lang";
|
||||
private static final Pattern JSON_FILE_PATTERN = Pattern.compile("^assets/" + ReplayMod.MOD_ID + "/lang/([a-z][a-z])_([a-z][a-z]).json$");
|
||||
private static final Pattern LANG_FILE_NAME_PATTERN = Pattern.compile("^([a-z][a-z])_([a-z][a-z]).lang$");
|
||||
|
||||
LangResourcePack() {
|
||||
super(new File(NAME));
|
||||
}
|
||||
|
||||
private ModFileResourcePack getParent() {
|
||||
return ResourcePackLoader.getResourcePackFor(ReplayMod.MOD_ID).orElseThrow(() -> new RuntimeException("Failed to get ReplayMod resource pack!"));
|
||||
}
|
||||
|
||||
private String langName(String path) {
|
||||
Matcher matcher = JSON_FILE_PATTERN.matcher(path);
|
||||
if (!matcher.matches()) return null;
|
||||
return String.format("%s_%s.lang", matcher.group(1), matcher.group(2).toUpperCase());
|
||||
}
|
||||
|
||||
private Path langPath(String path) {
|
||||
ModFileResourcePack parent = getParent();
|
||||
if (parent == null) return null;
|
||||
ModFile modFile = parent.getModFile();
|
||||
|
||||
String langName = langName(path);
|
||||
if (langName == null) return null;
|
||||
return modFile.getLocator().findPath(modFile, "assets", ReplayMod.MOD_ID, "lang", langName);
|
||||
}
|
||||
|
||||
private String convertValue(String value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream getInputStream(String path) throws IOException {
|
||||
if ("pack.mcmeta".equals(path)) {
|
||||
return new StringBufferInputStream("{\"pack\": {\"description\": \"ReplayMod language files\", \"pack_format\": 4}}");
|
||||
}
|
||||
|
||||
Path langPath = langPath(path);
|
||||
if (langPath == null) throw new ResourcePackFileNotFoundException(file, path);
|
||||
|
||||
String langFile;
|
||||
try (InputStream in = Files.newInputStream(langPath)) {
|
||||
langFile = IOUtils.toString(in);
|
||||
}
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
for (String line : langFile.split("\n")) {
|
||||
if (line.trim().isEmpty() || line.trim().startsWith("#")) continue;
|
||||
int i = line.indexOf('=');
|
||||
String key = line.substring(0, i);
|
||||
String value = line.substring(i + 1);
|
||||
value = convertValue(value);
|
||||
properties.put(key, value);
|
||||
}
|
||||
|
||||
return new ByteArrayInputStream(GSON.toJson(properties).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean resourceExists(String path) {
|
||||
Path langPath = langPath(path);
|
||||
return langPath != null && Files.exists(langPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getAllResourceLocations(ResourcePackType resourcePackType, String path, int maxDepth, Predicate<String> filter) {
|
||||
if (resourcePackType == ResourcePackType.CLIENT_RESOURCES && "lang".equals(path)) {
|
||||
IResourcePack parent = getParent();
|
||||
if (parent == null) return Collections.emptyList();
|
||||
return parent.getAllResourceLocations(resourcePackType, path, maxDepth, name -> {
|
||||
Matcher matcher = LANG_FILE_NAME_PATTERN.matcher(name);
|
||||
if (matcher.matches()) {
|
||||
return filter.test(String.format("%s_%s.json", matcher.group(1), matcher.group(1)));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}).stream().map(resourceLocation -> {
|
||||
String p = resourceLocation.getPath().substring(0, "assets/lang/xx_XX".length()) + ".json";
|
||||
return new ResourceLocation(resourceLocation.getNamespace(), p);
|
||||
}).collect(Collectors.toList());
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getResourceNamespaces(ResourcePackType resourcePackType) {
|
||||
if (resourcePackType == ResourcePackType.CLIENT_RESOURCES) {
|
||||
return Collections.singleton("replaymod");
|
||||
} else {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
public static class Finder implements IPackFinder {
|
||||
@Override
|
||||
public <T extends ResourcePackInfo> void addPackInfosToMap(Map<String, T> packList, ResourcePackInfo.IFactory<T> factory) {
|
||||
packList.put(NAME, ResourcePackInfo.func_195793_a(NAME, true, LangResourcePack::new, factory, ResourcePackInfo.Priority.BOTTOM));
|
||||
}
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
@@ -6,9 +6,6 @@ import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.model.ModelBox;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.ServerList;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
@@ -16,8 +13,8 @@ import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.ResourcePackRepository;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -25,6 +22,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
@@ -32,6 +30,25 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderLivingEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
//#if MC>=11300
|
||||
import net.minecraft.client.MainWindow;
|
||||
import net.minecraft.client.renderer.entity.model.ModelBox;
|
||||
import net.minecraft.client.renderer.entity.model.ModelRenderer;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.crash.ReportedException;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
//#else
|
||||
//$$ import net.minecraft.client.gui.ScaledResolution;
|
||||
//$$ import net.minecraft.client.model.ModelBox;
|
||||
//$$ import net.minecraft.client.model.ModelRenderer;
|
||||
//$$ import net.minecraft.client.resources.ResourcePackRepository;
|
||||
//$$ import net.minecraft.util.ReportedException;
|
||||
//$$ import org.apache.logging.log4j.LogManager;
|
||||
//$$ import org.lwjgl.Sys;
|
||||
//$$ import java.awt.Desktop;
|
||||
//#endif
|
||||
|
||||
|
||||
//#if MC>=10904
|
||||
//#if MC>=11200
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
@@ -63,7 +80,11 @@ import net.minecraft.client.renderer.GlStateManager.BooleanState;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||
//#if MC>=11300
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
//#else
|
||||
//$$ import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||
//#endif
|
||||
//#else
|
||||
//$$ import com.google.common.util.concurrent.Futures;
|
||||
//$$ import com.replaymod.render.hooks.GLStateTracker;
|
||||
@@ -85,12 +106,17 @@ import java.util.concurrent.Callable;
|
||||
* Abstraction over things that have changed between different MC versions.
|
||||
*/
|
||||
public class MCVer {
|
||||
public static EventBus FORGE_BUS = MinecraftForge.EVENT_BUS;
|
||||
//#if MC>=11300
|
||||
public static IEventBus FORGE_BUS = MinecraftForge.EVENT_BUS;
|
||||
public static IEventBus FML_BUS = FORGE_BUS;
|
||||
//#else
|
||||
//$$ public static EventBus FORGE_BUS = MinecraftForge.EVENT_BUS;
|
||||
//#if MC>=10809
|
||||
public static EventBus FML_BUS = FORGE_BUS;
|
||||
//$$ public static EventBus FML_BUS = FORGE_BUS;
|
||||
//#else
|
||||
//$$ public static EventBus FML_BUS = FMLCommonHandler.instance().bus();
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
public static void addDetail(CrashReportCategory category, String name, Callable<String> callable) {
|
||||
//#if MC>=10904
|
||||
@@ -104,6 +130,22 @@ public class MCVer {
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static void addButton(GuiScreenEvent.InitGuiEvent event, GuiButton button) {
|
||||
//#if MC>=11300
|
||||
event.addButton(button);
|
||||
//#else
|
||||
//$$ getButtonList(event).add(button);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static void removeButton(GuiScreenEvent.InitGuiEvent event, GuiButton button) {
|
||||
//#if MC>=11300
|
||||
event.removeButton(button);
|
||||
//#else
|
||||
//$$ getButtonList(event).remove(button);
|
||||
//#endif
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<GuiButton> getButtonList(GuiScreenEvent.InitGuiEvent event) {
|
||||
//#if MC>=10904
|
||||
@@ -226,6 +268,14 @@ public class MCVer {
|
||||
//#endif
|
||||
//#endif
|
||||
|
||||
public static File mcDataDir(Minecraft mc) {
|
||||
//#if MC>=11300
|
||||
return mc.gameDir;
|
||||
//#else
|
||||
//$$ return mc.mcDataDir;
|
||||
//#endif
|
||||
}
|
||||
|
||||
//#if MC>=10800
|
||||
public static Entity getRenderViewEntity(Minecraft mc) {
|
||||
return mc.getRenderViewEntity();
|
||||
@@ -318,8 +368,11 @@ public class MCVer {
|
||||
}
|
||||
|
||||
public static BooleanState fog() {
|
||||
//#if MC>=11300
|
||||
return GlStateManager.FOG.fog;
|
||||
//#else
|
||||
//#if MC>=10809
|
||||
return GlStateManager.fogState.fog;
|
||||
//$$ return GlStateManager.fogState.fog;
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
//$$ return GlStateManager.fogState.field_179049_a;
|
||||
@@ -327,11 +380,15 @@ public class MCVer {
|
||||
//$$ return GLStateTracker.getInstance().fog;
|
||||
//#endif
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static void fog(BooleanState fog) {
|
||||
//#if MC>=11300
|
||||
GlStateManager.FOG.fog = fog;
|
||||
//#else
|
||||
//#if MC>=10809
|
||||
GlStateManager.fogState.fog = fog;
|
||||
//$$ GlStateManager.fogState.fog = fog;
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
//$$ GlStateManager.fogState.field_179049_a = fog;
|
||||
@@ -339,22 +396,31 @@ public class MCVer {
|
||||
//$$ GLStateTracker.getInstance().fog = fog;
|
||||
//#endif
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static BooleanState texture2DState(int index) {
|
||||
//#if MC>=11300
|
||||
return GlStateManager.TEXTURES[index].texture2DState;
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
return GlStateManager.textureState[index].texture2DState;
|
||||
//$$ return GlStateManager.textureState[index].texture2DState;
|
||||
//#else
|
||||
//$$ return GLStateTracker.getInstance().texture[index];
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static void texture2DState(int index, BooleanState texture2DState) {
|
||||
//#if MC>=11300
|
||||
GlStateManager.TEXTURES[index].texture2DState = texture2DState;
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
GlStateManager.textureState[index].texture2DState = texture2DState;
|
||||
//$$ GlStateManager.textureState[index].texture2DState = texture2DState;
|
||||
//#else
|
||||
//$$ GLStateTracker.getInstance().texture[index] = texture2DState;
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static void ServerList_saveSingleServer(ServerData serverData) {
|
||||
@@ -373,18 +439,29 @@ public class MCVer {
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static ScaledResolution newScaledResolution(Minecraft mc) {
|
||||
//#if MC>=10809
|
||||
return new ScaledResolution(mc);
|
||||
//#else
|
||||
//$$ return new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static ListenableFuture setServerResourcePack(ResourcePackRepository repo, File file) {
|
||||
//#if MC>=11300
|
||||
public static MainWindow newScaledResolution(Minecraft mc) {
|
||||
return mc.mainWindow;
|
||||
}
|
||||
//#else
|
||||
//$$ public static ScaledResolution newScaledResolution(Minecraft mc) {
|
||||
//#if MC>=10809
|
||||
//$$ return new ScaledResolution(mc);
|
||||
//#else
|
||||
//$$ return new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
//#endif
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
public static ListenableFuture setServerResourcePack(File file) {
|
||||
//#if MC>=11300
|
||||
return getMinecraft().getPackFinder().func_195741_a(file);
|
||||
//#else
|
||||
//$$ ResourcePackRepository repo = getMinecraft().getResourcePackRepository();
|
||||
//#if MC>=10809
|
||||
//#if MC>=11200
|
||||
return repo.setServerResourcePack(file);
|
||||
//$$ return repo.setServerResourcePack(file);
|
||||
//#else
|
||||
//$$ return repo.setResourcePackInstance(file);
|
||||
//#endif
|
||||
@@ -398,6 +475,7 @@ public class MCVer {
|
||||
//$$ return Futures.immediateFuture(null);
|
||||
//#endif
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static boolean isKeyDown(KeyBinding keyBinding) {
|
||||
@@ -566,12 +644,36 @@ public class MCVer {
|
||||
|
||||
public static RenderManager getRenderManager() {
|
||||
//#if MC>=10800
|
||||
return Minecraft.getMinecraft().getRenderManager();
|
||||
return getMinecraft().getRenderManager();
|
||||
//#else
|
||||
//$$ return RenderManager.instance;
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static Minecraft getMinecraft() {
|
||||
//#if MC>=11300
|
||||
return Minecraft.getInstance();
|
||||
//#else
|
||||
//$$ return Minecraft.getMinecraft();
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static long milliTime() {
|
||||
//#if MC>=11300
|
||||
return Util.milliTime();
|
||||
//#else
|
||||
//$$ return Minecraft.getSystemTime();
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static File Minecraft_mcDataDir(Minecraft mc) {
|
||||
//#if MC>=11300
|
||||
return mc.gameDir;
|
||||
//#else
|
||||
//$$ return mc.mcDataDir;
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static int floor(double val) {
|
||||
//#if MC>=11102
|
||||
return MathHelper.floor(val);
|
||||
@@ -580,6 +682,14 @@ public class MCVer {
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static void bindTexture(ResourceLocation texture) {
|
||||
//#if MC>=11300
|
||||
getMinecraft().getTextureManager().bindTexture(texture);
|
||||
//#else
|
||||
//$$ getMinecraft().renderEngine.bindTexture(texture);
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static float cos(float val) {
|
||||
return MathHelper.cos(val);
|
||||
}
|
||||
@@ -612,6 +722,40 @@ public class MCVer {
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static ReportedException newReportedException(CrashReport crashReport) {
|
||||
return new ReportedException(crashReport);
|
||||
}
|
||||
|
||||
public static void openFile(File file) {
|
||||
//#if MC>=11300
|
||||
Util.getOSType().openFile(file);
|
||||
//#else
|
||||
//$$ String path = file.getAbsolutePath();
|
||||
//$$
|
||||
//$$ // First try OS specific methods
|
||||
//$$ try {
|
||||
//$$ switch (Util.getOSType()) {
|
||||
//$$ case WINDOWS:
|
||||
//$$ Runtime.getRuntime().exec(String.format("cmd.exe /C start \"Open file\" \"%s\"", path));
|
||||
//$$ return;
|
||||
//$$ case OSX:
|
||||
//$$ Runtime.getRuntime().exec(new String[]{"/usr/bin/open", path});
|
||||
//$$ return;
|
||||
//$$ }
|
||||
//$$ } catch (IOException e) {
|
||||
//$$ LogManager.getLogger().error("Cannot open file", e);
|
||||
//$$ }
|
||||
//$$
|
||||
//$$ // Otherwise try to java way
|
||||
//$$ try {
|
||||
//$$ Desktop.getDesktop().browse(file.toURI());
|
||||
//$$ } catch (Throwable throwable) {
|
||||
//$$ // And if all fails, lwjgl
|
||||
//$$ Sys.openURL("file://" + path);
|
||||
//$$ }
|
||||
//#endif
|
||||
}
|
||||
|
||||
//#if MC<=10710
|
||||
//$$ public static class GlStateManager {
|
||||
//$$ public static void resetColor() { /* nop */ }
|
||||
@@ -628,4 +772,59 @@ public class MCVer {
|
||||
//$$ public static void rotate(float angle, float x, float y, float z) { glRotatef(angle, x, y, z); }
|
||||
//$$ }
|
||||
//#endif
|
||||
|
||||
//#if MC>=11300
|
||||
public static void color(float r, float g, float b, float a) { GlStateManager.color4f(r, g, b, a); }
|
||||
public static void enableAlpha() { GlStateManager.enableAlphaTest(); }
|
||||
public static void disableAlpha() { GlStateManager.disableAlphaTest(); }
|
||||
public static void tryBlendFuncSeparate(int l, int r, int vl, int vr) { GlStateManager.blendFuncSeparate(l, r, vl, vr); }
|
||||
public static void colorLogicOp(int op) { GlStateManager.logicOp(op); }
|
||||
|
||||
public static abstract class Keyboard {
|
||||
public static final int KEY_LCONTROL = GLFW.GLFW_KEY_LEFT_CONTROL;
|
||||
public static final int KEY_LSHIFT = GLFW.GLFW_KEY_LEFT_SHIFT;
|
||||
public static final int KEY_ESCAPE = GLFW.GLFW_KEY_ESCAPE;
|
||||
public static final int KEY_HOME = GLFW.GLFW_KEY_HOME;
|
||||
public static final int KEY_END = GLFW.GLFW_KEY_END;
|
||||
public static final int KEY_UP = GLFW.GLFW_KEY_UP;
|
||||
public static final int KEY_DOWN = GLFW.GLFW_KEY_DOWN;
|
||||
public static final int KEY_LEFT = GLFW.GLFW_KEY_LEFT;
|
||||
public static final int KEY_RIGHT = GLFW.GLFW_KEY_RIGHT;
|
||||
public static final int KEY_BACK = GLFW.GLFW_KEY_BACKSPACE;
|
||||
public static final int KEY_DELETE = GLFW.GLFW_KEY_DELETE;
|
||||
public static final int KEY_RETURN = GLFW.GLFW_KEY_ENTER;
|
||||
public static final int KEY_TAB = GLFW.GLFW_KEY_TAB;
|
||||
public static final int KEY_F1 = GLFW.GLFW_KEY_F1;
|
||||
public static final int KEY_A = GLFW.GLFW_KEY_A;
|
||||
public static final int KEY_B = GLFW.GLFW_KEY_B;
|
||||
public static final int KEY_C = GLFW.GLFW_KEY_C;
|
||||
public static final int KEY_D = GLFW.GLFW_KEY_D;
|
||||
public static final int KEY_E = GLFW.GLFW_KEY_E;
|
||||
public static final int KEY_F = GLFW.GLFW_KEY_F;
|
||||
public static final int KEY_G = GLFW.GLFW_KEY_G;
|
||||
public static final int KEY_H = GLFW.GLFW_KEY_H;
|
||||
public static final int KEY_I = GLFW.GLFW_KEY_I;
|
||||
public static final int KEY_J = GLFW.GLFW_KEY_J;
|
||||
public static final int KEY_K = GLFW.GLFW_KEY_K;
|
||||
public static final int KEY_L = GLFW.GLFW_KEY_L;
|
||||
public static final int KEY_M = GLFW.GLFW_KEY_M;
|
||||
public static final int KEY_N = GLFW.GLFW_KEY_N;
|
||||
public static final int KEY_O = GLFW.GLFW_KEY_O;
|
||||
public static final int KEY_P = GLFW.GLFW_KEY_P;
|
||||
public static final int KEY_Q = GLFW.GLFW_KEY_Q;
|
||||
public static final int KEY_R = GLFW.GLFW_KEY_R;
|
||||
public static final int KEY_S = GLFW.GLFW_KEY_S;
|
||||
public static final int KEY_T = GLFW.GLFW_KEY_T;
|
||||
public static final int KEY_U = GLFW.GLFW_KEY_U;
|
||||
public static final int KEY_V = GLFW.GLFW_KEY_V;
|
||||
public static final int KEY_W = GLFW.GLFW_KEY_W;
|
||||
public static final int KEY_X = GLFW.GLFW_KEY_X;
|
||||
public static final int KEY_Y = GLFW.GLFW_KEY_Y;
|
||||
public static final int KEY_Z = GLFW.GLFW_KEY_Z;
|
||||
|
||||
public static boolean isKeyDown(int keyCode) {
|
||||
return InputMappings.isKeyDown(keyCode);
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user