Compare commits
51 Commits
1.9.4-2.0.
...
1.7.10-2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1283a39ffa | ||
|
|
adfe6a2bfc | ||
|
|
b27af2781b | ||
|
|
41d2547f3c | ||
|
|
00e999ffd2 | ||
|
|
767ea292a7 | ||
|
|
5b04edbbd3 | ||
|
|
6aff99d3ac | ||
|
|
703805f269 | ||
|
|
7a4440c4a8 | ||
|
|
0b9c56cdfd | ||
|
|
933ee5f866 | ||
|
|
83b1090e42 | ||
|
|
5c73117e9f | ||
|
|
4704b2984e | ||
|
|
0c226b0236 | ||
|
|
1b9b13ee7f | ||
|
|
c2000b3edc | ||
|
|
aafeecc670 | ||
|
|
9292add867 | ||
|
|
8499c0f154 | ||
|
|
b9ea572e19 | ||
|
|
a2f8c88a3d | ||
|
|
19629c32f0 | ||
|
|
fe1d9b828d | ||
|
|
1a1e96c375 | ||
|
|
35eb9cad33 | ||
|
|
91573d9487 | ||
|
|
d71358bcba | ||
|
|
1a55983986 | ||
|
|
18c5bcd469 | ||
|
|
c054fe83f6 | ||
|
|
f13297c5a5 | ||
|
|
391f304c5f | ||
|
|
0e0eaaa9a7 | ||
|
|
a34bbbcd68 | ||
|
|
60879fbbed | ||
|
|
dfafbecf35 | ||
|
|
8a6ec5191b | ||
|
|
5677fc54cb | ||
|
|
748a91e7b2 | ||
|
|
ee24866f29 | ||
|
|
dba085c700 | ||
|
|
3f0e3e725e | ||
|
|
40e1d850da | ||
|
|
03aada1f5f | ||
|
|
0c1dc658ad | ||
|
|
fcbbbc9ea1 | ||
|
|
fe6ded0143 | ||
|
|
f58fa8f9c2 | ||
|
|
4fc3a3166c |
@@ -7,7 +7,7 @@ pipeline:
|
||||
commands:
|
||||
- curl --fail --create-dirs -o $HOME/.gradle/init.d/mirror.gradle https://maven.johni0702.de/config/gradle
|
||||
- curl --fail --create-dirs -o $HOME/.m2/settings.xml https://maven.johni0702.de/config/maven
|
||||
- JAVA_OPTS=-Xmx1516M ./gradlew setupDecompWorkspace
|
||||
- ./gradlew setupCIWorkspace
|
||||
- ./gradlew :build
|
||||
archive:
|
||||
image: plugins/s3
|
||||
|
||||
@@ -1 +1 @@
|
||||
eyJhbGciOiJIUzI1NiJ9.cGlwZWxpbmU6CiAgY2xvbmU6CiAgICBpbWFnZTogcGx1Z2lucy9naXQKICAgIHRhZ3M6IHRydWUKICBidWlsZDoKICAgIGltYWdlOiBtYXZlbjozLjMuOS1qZGstOAogICAgY29tbWFuZHM6CiAgICAgIC0gY3VybCAtLWZhaWwgLS1jcmVhdGUtZGlycyAtbyAkSE9NRS8uZ3JhZGxlL2luaXQuZC9taXJyb3IuZ3JhZGxlIGh0dHBzOi8vbWF2ZW4uam9obmkwNzAyLmRlL2NvbmZpZy9ncmFkbGUKICAgICAgLSBjdXJsIC0tZmFpbCAtLWNyZWF0ZS1kaXJzIC1vICRIT01FLy5tMi9zZXR0aW5ncy54bWwgaHR0cHM6Ly9tYXZlbi5qb2huaTA3MDIuZGUvY29uZmlnL21hdmVuCiAgICAgIC0gSkFWQV9PUFRTPS1YbXgxNTE2TSAuL2dyYWRsZXcgc2V0dXBEZWNvbXBXb3Jrc3BhY2UKICAgICAgLSAuL2dyYWRsZXcgOmJ1aWxkCiAgYXJjaGl2ZToKICAgIGltYWdlOiBwbHVnaW5zL3MzCiAgICBhY2w6IHB1YmxpYy1yZWFkCiAgICByZWdpb246ICJ1cy1lYXN0LTEiCiAgICBidWNrZXQ6ICJyZXBsYXltb2QiCiAgICBwYXRoX3N0eWxlOiB0cnVlCiAgICBzb3VyY2U6IGJ1aWxkL2xpYnMvKgogICAgc3RyaXBfcHJlZml4OiBidWlsZC9saWJzLwogICAgdGFyZ2V0OiAvCg.nzPW0_TpMIjnFZZ5Ci439QDKlaDo1a3DCH-VCYUgpx8
|
||||
eyJhbGciOiJIUzI1NiJ9.cGlwZWxpbmU6CiAgY2xvbmU6CiAgICBpbWFnZTogcGx1Z2lucy9naXQKICAgIHRhZ3M6IHRydWUKICBidWlsZDoKICAgIGltYWdlOiBtYXZlbjozLjMuOS1qZGstOAogICAgY29tbWFuZHM6CiAgICAgIC0gY3VybCAtLWZhaWwgLS1jcmVhdGUtZGlycyAtbyAkSE9NRS8uZ3JhZGxlL2luaXQuZC9taXJyb3IuZ3JhZGxlIGh0dHBzOi8vbWF2ZW4uam9obmkwNzAyLmRlL2NvbmZpZy9ncmFkbGUKICAgICAgLSBjdXJsIC0tZmFpbCAtLWNyZWF0ZS1kaXJzIC1vICRIT01FLy5tMi9zZXR0aW5ncy54bWwgaHR0cHM6Ly9tYXZlbi5qb2huaTA3MDIuZGUvY29uZmlnL21hdmVuCiAgICAgIC0gLi9ncmFkbGV3IHNldHVwQ0lXb3Jrc3BhY2UKICAgICAgLSAuL2dyYWRsZXcgOmJ1aWxkCiAgYXJjaGl2ZToKICAgIGltYWdlOiBwbHVnaW5zL3MzCiAgICBhY2w6IHB1YmxpYy1yZWFkCiAgICByZWdpb246ICJ1cy1lYXN0LTEiCiAgICBidWNrZXQ6ICJyZXBsYXltb2QiCiAgICBwYXRoX3N0eWxlOiB0cnVlCiAgICBzb3VyY2U6IGJ1aWxkL2xpYnMvKgogICAgc3RyaXBfcHJlZml4OiBidWlsZC9saWJzLwogICAgdGFyZ2V0OiAvCg.riE6lhwfdNUhI7LO2SxEKFOjzjaX40ne7Ae9gyP75KE
|
||||
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -2,6 +2,6 @@
|
||||
path = jGui
|
||||
url = https://github.com/ReplayMod/jGui
|
||||
|
||||
[submodule "ReplayStudio"]
|
||||
path = ReplayStudio
|
||||
url = https://github.com/ReplayMod/ReplayStudio
|
||||
[submodule "src/main/resources/assets/replaymod/lang"]
|
||||
path = src/main/resources/assets/replaymod/lang
|
||||
url = https://github.com/ReplayMod/Translations
|
||||
|
||||
Submodule ReplayStudio deleted from 44f7345b6b
114
build.gradle
114
build.gradle
@@ -1,7 +1,5 @@
|
||||
import groovy.json.JsonOutput
|
||||
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -9,23 +7,17 @@ buildscript {
|
||||
name = "forge"
|
||||
url = "http://files.minecraftforge.net/maven"
|
||||
}
|
||||
maven {
|
||||
name = "sponge"
|
||||
url = "https://repo.spongepowered.org/maven"
|
||||
}
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
|
||||
classpath 'org.spongepowered:mixingradle:0.4-SNAPSHOT'
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
apply plugin: 'org.spongepowered.mixin'
|
||||
apply plugin: 'forge'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
@@ -34,13 +26,22 @@ version = gitDescribe()
|
||||
group= "com.replaymod"
|
||||
archivesBaseName = "replaymod"
|
||||
|
||||
ext {
|
||||
mixinConfigs = [
|
||||
'compat.shaders', 'extras.playeroverview', 'recording', 'render', 'replay'
|
||||
].collect {"mixins.${it}.replaymod.json"}
|
||||
mixinSrg = new File(project.buildDir, 'tmp/mixins/mixins.srg')
|
||||
mixinRefMap = new File(project.buildDir, 'tmp/mixins/mixins.replaymod.refmap.json')
|
||||
}
|
||||
|
||||
minecraft {
|
||||
coreMod = 'com.replaymod.core.LoadingPlugin'
|
||||
version = '1.9.4-12.17.0.1976'
|
||||
version = '1.7.10-10.13.4.1558-1.7.10'
|
||||
runDir = "eclipse"
|
||||
mappings = "snapshot_20160518"
|
||||
mappings = "stable_12"
|
||||
replace '@MOD_VERSION@', project.version
|
||||
replace '@MC_VERSION@', project.minecraft.version
|
||||
// Includes intentional whitespace to stop Forge from declaring the mod to be compatible with
|
||||
// a newer srg-compatible MC version (that may be using a different protocol version)
|
||||
replace '@MC_VERSION@', "[ ${project.minecraft.version} ]"
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -49,7 +50,7 @@ repositories {
|
||||
url = "http://repo.spongepowered.org/maven/"
|
||||
}
|
||||
maven {
|
||||
url 'https://repo.spacehq.org/content/repositories/snapshots/'
|
||||
url 'https://jitpack.io'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ configurations {
|
||||
dependencies {
|
||||
compile 'org.projectlombok:lombok:1.16.4'
|
||||
|
||||
compile 'org.spongepowered:mixin:0.6.4-SNAPSHOT'
|
||||
compile 'org.spongepowered:mixin:0.6.8-SNAPSHOT'
|
||||
shade 'com.googlecode.mp4parser:isoparser:1.1.7'
|
||||
shade 'org.apache.commons:commons-exec:1.3'
|
||||
shade 'com.google.apis:google-api-services-youtube:v3-rev178-1.22.0'
|
||||
@@ -71,24 +72,22 @@ dependencies {
|
||||
|
||||
shade 'org.aspectj:aspectjrt:1.8.2'
|
||||
|
||||
compile project(':ReplayStudio')
|
||||
shade 'com.github.replaymod:ReplayStudio:181140c'
|
||||
|
||||
testCompile 'junit:junit:4.11'
|
||||
}
|
||||
|
||||
tasks['idea'].dependsOn ':ReplayStudio:preshadowJar'
|
||||
|
||||
jar {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
|
||||
dependsOn configurations.compile
|
||||
dependsOn configurations.shade
|
||||
dependsOn ':ReplayStudio:shadowJar'
|
||||
|
||||
from project.mixinRefMap
|
||||
|
||||
def shade = {files(
|
||||
configurations.compile.findAll {it.name.startsWith 'mixin-'}
|
||||
+ configurations.shade
|
||||
+ getTasks().getByPath(':ReplayStudio:shadowJar').outputs.files
|
||||
)}
|
||||
|
||||
def noticeDir = file("$buildDir/NOTICE")
|
||||
@@ -103,27 +102,6 @@ jar {
|
||||
}
|
||||
from noticeDir
|
||||
|
||||
def langDir = file("$buildDir/languages")
|
||||
doFirst {
|
||||
try {
|
||||
langDir.deleteDir()
|
||||
langDir.mkdirs()
|
||||
def dir = new File(langDir, 'assets/replaymod/lang/')
|
||||
dir.mkdirs()
|
||||
def zip = new ZipInputStream(new URL('http://replaymod.com/api/grab_languages').openStream())
|
||||
def e;
|
||||
while ((e = zip.nextEntry) != null) {
|
||||
new File(dir, e.getName()) << zip
|
||||
zip.closeEntry()
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
from (langDir) {
|
||||
exclude '**/en_US.lang'
|
||||
}
|
||||
|
||||
from ({shade().collect { it.isDirectory() ? it : zipTree(it) }}) {
|
||||
exclude '**/NOTICE*'
|
||||
// exclude everything taken in from jGui for running the mod in a dev environment
|
||||
@@ -138,7 +116,8 @@ jar {
|
||||
manifest {
|
||||
attributes 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker',
|
||||
'TweakOrder': '0',
|
||||
'FMLCorePluginContainsFMLMod': 'true',
|
||||
'MixinConfigs': project.mixinConfigs.join(','),
|
||||
'FMLCorePlugin': 'com.replaymod.core.LoadingPlugin',
|
||||
'FMLAT': 'replaymod_at.cfg'
|
||||
}
|
||||
}
|
||||
@@ -178,6 +157,8 @@ processResources
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
// Required so resources are loaded correctly in dev env
|
||||
output.resourcesDir = output.classesDir
|
||||
// Directly include jGui into main build
|
||||
// This could also be done by including it as a gradle subproject, however
|
||||
// doing so caused classpath issues on some IntelliJ versions.
|
||||
@@ -187,7 +168,13 @@ sourceSets {
|
||||
resources {
|
||||
srcDir 'jGui/src/main/resources'
|
||||
}
|
||||
refMap = "mixins.replaymod.refmap.json"
|
||||
}
|
||||
integrationTest {
|
||||
compileClasspath += main.runtimeClasspath + main.output
|
||||
java {
|
||||
srcDir file('src/integration-test/java')
|
||||
}
|
||||
resources.srcDir file('src/integration-test/resources')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,10 +183,49 @@ task copySrg(type: Copy, dependsOn: 'genSrgs') {
|
||||
into 'build'
|
||||
}
|
||||
|
||||
reobf.doFirst {
|
||||
if (project.mixinSrg.exists()) {
|
||||
addExtraSrgFile project.mixinSrg
|
||||
}
|
||||
}
|
||||
|
||||
compileJava.dependsOn copySrg
|
||||
compileJava {
|
||||
options.compilerArgs += [
|
||||
"-AoutSrgFile=${project.mixinSrg.canonicalPath}",
|
||||
"-AoutRefMapFile=${project.mixinRefMap.canonicalPath}",
|
||||
"-AreobfSrgFile=${project.file('build/mcp-srg.srg').canonicalPath}"
|
||||
]
|
||||
}
|
||||
|
||||
setupDecompWorkspace.dependsOn copySrg
|
||||
setupDevWorkspace.dependsOn copySrg
|
||||
project.tasks.idea.dependsOn copySrg
|
||||
|
||||
task runIntegrationTest(type: JavaExec, dependsOn: ["makeStart", "jar"]) {
|
||||
main = 'GradleStart'
|
||||
standardOutput = System.out
|
||||
errorOutput = System.err
|
||||
workingDir file(minecraft.runDir)
|
||||
|
||||
def testDir = new File(minecraft.runDir, "integration-test")
|
||||
doFirst {
|
||||
testDir.deleteDir()
|
||||
testDir.mkdirs()
|
||||
}
|
||||
|
||||
doLast {
|
||||
testDir.deleteDir()
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
def runClient = tasks.getByName("runClient")
|
||||
runIntegrationTest.jvmArgs = runClient.jvmArgs + "-Dfml.noGrab=true"
|
||||
runIntegrationTest.args = runClient.args + "--gameDir" + testDir.canonicalPath
|
||||
runIntegrationTest.classpath runClient.classpath + sourceSets.integrationTest.output
|
||||
}
|
||||
}
|
||||
|
||||
def generateVersionsJson() {
|
||||
// List all tags
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
|
||||
2
jGui
2
jGui
Submodule jGui updated: 26af916257...042e1c6e50
@@ -1 +0,0 @@
|
||||
include 'ReplayStudio'
|
||||
30
src/integration-test/java/IntegrationTest.java
Normal file
30
src/integration-test/java/IntegrationTest.java
Normal file
@@ -0,0 +1,30 @@
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Entry point for running integration tests from within the IDE.
|
||||
* This is <b>not</b> called when running integration tests directly from gradle.
|
||||
*/
|
||||
public class IntegrationTest {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
// Prevent MC from grabbing our mouse during the test (it's not needed)
|
||||
System.setProperty("fml.noGrab", "true");
|
||||
|
||||
// Make sure the test folder exists and is fresh
|
||||
File gameDir = new File(System.getProperty("user.dir"), "integration-test");
|
||||
if (gameDir.exists()) {
|
||||
FileUtils.forceDelete(gameDir);
|
||||
}
|
||||
FileUtils.forceMkdir(gameDir);
|
||||
|
||||
// Set game dir to test folder and call regular entry point
|
||||
List<String> argsList = new ArrayList<>(Arrays.asList(args));
|
||||
argsList.add("--gameDir");
|
||||
argsList.add(gameDir.getCanonicalPath());
|
||||
GradleStart.main(argsList.toArray(new String[argsList.size()]));
|
||||
}
|
||||
}
|
||||
371
src/integration-test/java/com/replaymod/core/AbstractTask.java
Normal file
371
src/integration-test/java/com/replaymod/core/AbstractTask.java
Normal file
@@ -0,0 +1,371 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiOverlay;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiOverlay;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiTexturedButton;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static com.replaymod.core.ReplayModIntegrationTest.LOGGER;
|
||||
import static com.replaymod.core.utils.Utils.addCallback;
|
||||
|
||||
public abstract class AbstractTask implements Task {
|
||||
public static Task create(Consumer<AbstractTask> init) {
|
||||
return new AbstractTask() {
|
||||
@Override
|
||||
protected void init() {
|
||||
init.consume(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static final Minecraft mc = Minecraft.getMinecraft();
|
||||
public final ReplayMod core = ReplayMod.instance;
|
||||
public SettableFuture<Void> future;
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Void> execute() {
|
||||
future = SettableFuture.create();
|
||||
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
addCallback(future, success -> {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}, error -> {});
|
||||
|
||||
init();
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
protected void init() {}
|
||||
|
||||
protected void runLater(Runnable runnable) {
|
||||
core.runLater(() -> {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable t) {
|
||||
future.setException(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void expectGuiClosed(Runnable onClosed) {
|
||||
expectGuiClosed0(10, onClosed);
|
||||
}
|
||||
|
||||
public void expectGuiClosed(int timeout, Runnable onClosed) {
|
||||
expectGuiClosed0(timeout, onClosed);
|
||||
}
|
||||
|
||||
private void expectGuiClosed0(int timeout, Runnable onClosed) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
FMLCommonHandler.instance().bus().register(new GuiEventHandler(timeout, stackTrace, onClosed));
|
||||
}
|
||||
public class GuiEventHandler {
|
||||
final net.minecraft.client.gui.GuiScreen currentScreen = mc.currentScreen;
|
||||
private final int timeout;
|
||||
private final StackTraceElement[] stackTrace;
|
||||
private final Runnable onClosed;
|
||||
int framesPassed;
|
||||
|
||||
public GuiEventHandler(int timeout, StackTraceElement[] stackTrace, Runnable onClosed) {
|
||||
this.timeout = timeout;
|
||||
this.stackTrace = stackTrace;
|
||||
this.onClosed = onClosed;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (currentScreen != mc.currentScreen) {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
onClosed.run();
|
||||
} else {
|
||||
if (framesPassed < timeout) {
|
||||
framesPassed++;
|
||||
} else {
|
||||
Object gui = (gui = GuiScreen.from(currentScreen)) == null ? currentScreen : gui;
|
||||
Exception e = new TimeoutException("Timeout while waiting for " + gui + " to be closed.");
|
||||
e.setStackTrace(Arrays.copyOfRange(stackTrace, 3, stackTrace.length));
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void expectPopupClosed(Runnable onClosed) {
|
||||
expectPopupClosed0(10, onClosed);
|
||||
}
|
||||
|
||||
public void expectPopupClosed(int timeout, Runnable onClosed) {
|
||||
expectPopupClosed0(timeout, onClosed);
|
||||
}
|
||||
|
||||
private void expectPopupClosed0(int timeout, Runnable onClosed) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
FMLCommonHandler.instance().bus().register(new PopupEventHandler(timeout, stackTrace, onClosed));
|
||||
}
|
||||
public class PopupEventHandler {
|
||||
private final int timeout;
|
||||
private final StackTraceElement[] stackTrace;
|
||||
private final Runnable onClosed;
|
||||
private final AbstractGuiPopup popup;
|
||||
int framesPassed;
|
||||
|
||||
public PopupEventHandler(int timeout, StackTraceElement[] stackTrace, Runnable onClosed) {
|
||||
this.timeout = timeout;
|
||||
this.stackTrace = stackTrace;
|
||||
this.onClosed = onClosed;
|
||||
this.popup = getPopup(mc.currentScreen);
|
||||
if (this.popup == null) {
|
||||
throw new IllegalStateException("No popup found.");
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (getPopup(mc.currentScreen) != popup) {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
onClosed.run();
|
||||
} else {
|
||||
if (framesPassed < timeout) {
|
||||
framesPassed++;
|
||||
} else {
|
||||
Exception e = new TimeoutException("Timeout while waiting for " + popup + " to be closed.");
|
||||
e.setStackTrace(Arrays.copyOfRange(stackTrace, 3, stackTrace.length));
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractGuiPopup getPopup(net.minecraft.client.gui.GuiScreen minecraft) {
|
||||
GuiContainer<?> container = GuiOverlay.from(minecraft);
|
||||
if (container == null) {
|
||||
container = GuiScreen.from(minecraft);
|
||||
}
|
||||
if (container != null) {
|
||||
while (container.getContainer() != null) {
|
||||
container = container.getContainer();
|
||||
}
|
||||
GuiElement popup = Iterables.getLast(container.getChildren());
|
||||
if (popup instanceof AbstractGuiPopup) {
|
||||
return (AbstractGuiPopup) popup;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> void expectGui(Class<T> guiClass, Consumer<T> onOpen) {
|
||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
FMLCommonHandler.instance().bus().register(new ExpectGuiEventHandler<T>(guiClass, stackTrace, onOpen));
|
||||
}
|
||||
public class ExpectGuiEventHandler<T> {
|
||||
private final Class<T> guiClass;
|
||||
private final StackTraceElement[] stackTrace;
|
||||
private final Consumer<T> onOpen;
|
||||
net.minecraft.client.gui.GuiScreen currentScreen;
|
||||
int framesPassed;
|
||||
|
||||
public ExpectGuiEventHandler(Class<T> guiClass, StackTraceElement[] stackTrace, Consumer<T> onOpen) {
|
||||
this.guiClass = guiClass;
|
||||
this.stackTrace = stackTrace;
|
||||
this.onOpen = onOpen;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (currentScreen != mc.currentScreen) {
|
||||
currentScreen = mc.currentScreen;
|
||||
framesPassed = 0;
|
||||
}
|
||||
if (framesPassed < 10) {
|
||||
framesPassed++;
|
||||
return;
|
||||
}
|
||||
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
|
||||
Object foundGui = null;
|
||||
if (AbstractGuiScreen.class.isAssignableFrom(guiClass)) {
|
||||
AbstractGuiScreen guiScreen = GuiScreen.from(currentScreen);
|
||||
if (guiClass.isInstance(guiScreen)) {
|
||||
onOpen.consume(guiClass.cast(guiScreen));
|
||||
return;
|
||||
}
|
||||
foundGui = guiScreen;
|
||||
} else if (AbstractGuiOverlay.class.isAssignableFrom(guiClass)) {
|
||||
AbstractGuiOverlay guiScreen = GuiOverlay.from(currentScreen);
|
||||
if (guiClass.isInstance(guiScreen)) {
|
||||
onOpen.consume(guiClass.cast(guiScreen));
|
||||
return;
|
||||
}
|
||||
foundGui = guiScreen;
|
||||
} else if (AbstractGuiPopup.class.isAssignableFrom(guiClass)) {
|
||||
AbstractGuiPopup popup = getPopup(currentScreen);
|
||||
if (guiClass.isInstance(popup)) {
|
||||
onOpen.consume(guiClass.cast(popup));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (guiClass.isInstance(currentScreen)) {
|
||||
onOpen.consume(guiClass.cast(currentScreen));
|
||||
return;
|
||||
}
|
||||
}
|
||||
future.setException(new UnexpectedGuiException(guiClass, stackTrace,
|
||||
foundGui == null ? currentScreen : foundGui));
|
||||
}
|
||||
}
|
||||
class UnexpectedGuiException extends Exception {
|
||||
UnexpectedGuiException(Class<?> guiClass, StackTraceElement[] stackTrace, Object foundGui) {
|
||||
super("Expected instance of " + guiClass + " but found " + foundGui);
|
||||
setStackTrace(Arrays.copyOfRange(stackTrace, 2, stackTrace.length));
|
||||
}
|
||||
}
|
||||
|
||||
private void clickNow(int x, int y) {
|
||||
try {
|
||||
Method method = net.minecraft.client.gui.GuiScreen.class
|
||||
.getDeclaredMethod("mouseClicked", int.class, int.class, int.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(mc.currentScreen, x, y, 0);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void click(int x, int y) {
|
||||
runLater(() -> {
|
||||
LOGGER.info("Clicking at {}/{}", x, y);
|
||||
clickNow(x, y);
|
||||
});
|
||||
}
|
||||
|
||||
private void dragNow(int x, int y) {
|
||||
try {
|
||||
Method method = net.minecraft.client.gui.GuiScreen.class
|
||||
.getDeclaredMethod("mouseClickMove", int.class, int.class, int.class, long.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(mc.currentScreen, x, y, 0, 0);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
runLater(() -> {
|
||||
LOGGER.info("Dragging to {}/{}", x, y);
|
||||
dragNow(x, y);
|
||||
});
|
||||
}
|
||||
|
||||
public void click(GuiButton button) {
|
||||
runLater(() -> {
|
||||
if (!button.isEnabled()) {
|
||||
future.setException(new IllegalStateException("Button is disabled: " + button.getLabel()));
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Clicking button {}", button.getLabel());
|
||||
button.onClick();
|
||||
});
|
||||
}
|
||||
|
||||
public void click(GuiTexturedButton button) {
|
||||
runLater(() -> {
|
||||
if (!button.isEnabled()) {
|
||||
future.setException(new IllegalStateException("Button is disabled: " + button.getTexture()));
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Clicking textured button {}", button.getTexture());
|
||||
button.onClick();
|
||||
});
|
||||
}
|
||||
|
||||
public void click(String buttonText) {
|
||||
runLater(() -> {
|
||||
LOGGER.info("Clicking button {}", buttonText);
|
||||
try {
|
||||
Field field = net.minecraft.client.gui.GuiScreen.class.getDeclaredField("buttonList");
|
||||
field.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<net.minecraft.client.gui.GuiButton> buttonList = (List)
|
||||
field.get(mc.currentScreen);
|
||||
|
||||
net.minecraft.client.gui.GuiButton button = null;
|
||||
for (net.minecraft.client.gui.GuiButton guiButton : buttonList) {
|
||||
if (guiButton.displayString.equals(buttonText)) {
|
||||
button = guiButton;
|
||||
}
|
||||
}
|
||||
if (button == null) {
|
||||
future.setException(new NoSuchElementException("No button with label: " + buttonText));
|
||||
return;
|
||||
}
|
||||
|
||||
clickNow(button.xPosition + 5, button.yPosition + 5);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void type(String string) {
|
||||
for (char c : string.toCharArray()) {
|
||||
press(c, Keyboard.getKeyIndex(String.valueOf(c).toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
public void press(int keyCode) {
|
||||
String keyName = Keyboard.getKeyName(keyCode);
|
||||
char character = keyName.length() == 1 ? keyName.charAt(0) : '\0';
|
||||
press(character, keyCode);
|
||||
}
|
||||
|
||||
public void press(char character, int keyCode) {
|
||||
runLater(() -> {
|
||||
LOGGER.info("Pressing key {}", Keyboard.getKeyName(keyCode));
|
||||
if (mc.currentScreen == null || mc.currentScreen.allowUserInput) {
|
||||
KeyBinding.onTick(keyCode);
|
||||
FMLCommonHandler.instance().fireKeyInput();
|
||||
}
|
||||
if (mc.currentScreen != null) {
|
||||
try {
|
||||
Method method = net.minecraft.client.gui.GuiScreen.class
|
||||
.getDeclaredMethod("keyTyped", char.class, int.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(mc.currentScreen, character, keyCode);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
|
||||
import static com.replaymod.core.ReplayModIntegrationTest.LOGGER;
|
||||
import static com.replaymod.core.utils.Utils.addCallback;
|
||||
|
||||
public class CompositeTask implements Task {
|
||||
private SettableFuture<Void> future;
|
||||
protected final Task[] children;
|
||||
|
||||
public CompositeTask(Task[] children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Void> execute() {
|
||||
future = SettableFuture.create();
|
||||
executeChild(0);
|
||||
return future;
|
||||
}
|
||||
|
||||
private void executeChild(int childIndex) {
|
||||
if (future.isDone()) return;
|
||||
if (childIndex < children.length) {
|
||||
ReplayMod.instance.runLater(() -> {
|
||||
try {
|
||||
Task task = children[childIndex];
|
||||
LOGGER.info("Running task {}", task);
|
||||
ListenableFuture<Void> childFuture = task.execute();
|
||||
addCallback(childFuture, done -> executeChild(childIndex + 1), err -> future.setException(err));
|
||||
} catch (Throwable t) {
|
||||
future.setException(t);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
future.set(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.replaymod.core.regression.RegressionTest60;
|
||||
import com.replaymod.core.regression.RegressionTest61;
|
||||
import com.replaymod.core.regression.RegressionTest62;
|
||||
import com.replaymod.extra.DownloadOpenEye;
|
||||
import com.replaymod.online.SkipLogin;
|
||||
import com.replaymod.recording.CreateSPWorld;
|
||||
import com.replaymod.recording.ExitSPWorld;
|
||||
import com.replaymod.replay.ExitReplay;
|
||||
import com.replaymod.replay.LoadReplay;
|
||||
import com.replaymod.replay.OpenReplayViewer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import static com.replaymod.core.AbstractTask.mc;
|
||||
import static com.replaymod.core.ReplayModIntegrationTest.MOD_ID;
|
||||
import static com.replaymod.core.utils.Utils.addCallback;
|
||||
|
||||
/**
|
||||
* Helper mod that initiates the integration tests.
|
||||
*/
|
||||
@Mod(modid = MOD_ID)
|
||||
public class ReplayModIntegrationTest {
|
||||
public static final String MOD_ID = "replaymod-integration-test";
|
||||
|
||||
public static Logger LOGGER;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLPreInitializationEvent event) {
|
||||
LOGGER = event.getModLog();
|
||||
|
||||
// Make sure the game window doesn't have to remain in focus during the test
|
||||
mc.gameSettings.pauseOnLostFocus = false;
|
||||
|
||||
runTasks(
|
||||
new SkipLogin(),
|
||||
new DownloadOpenEye(),
|
||||
new CreateSPWorld(),
|
||||
new Wait(5000),
|
||||
new ExitSPWorld(),
|
||||
new OpenReplayViewer(),
|
||||
new LoadReplay(),
|
||||
|
||||
new RegressionTest60(),
|
||||
new RegressionTest61(),
|
||||
new RegressionTest62(),
|
||||
|
||||
// new AbstractTask() {}, // Uncomment to not exit on success (useful for writing more tests)
|
||||
new ExitReplay()
|
||||
);
|
||||
}
|
||||
|
||||
private void runTasks(Task... tests) {
|
||||
addCallback(new CompositeTask(tests).execute(), success -> {
|
||||
if (!Minecraft.getMinecraft().hasCrashed) {
|
||||
LOGGER.info("===================================================");
|
||||
LOGGER.info("= ALL TESTS PASSED =");
|
||||
LOGGER.info("===================================================");
|
||||
FMLCommonHandler.instance().exitJava(0, false);
|
||||
}
|
||||
}, error -> {
|
||||
LOGGER.error("Failed task:", error);
|
||||
LOGGER.error("===================================================");
|
||||
LOGGER.error("= TEST FAILED =");
|
||||
LOGGER.error("===================================================");
|
||||
FMLCommonHandler.instance().exitJava(1, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
35
src/integration-test/java/com/replaymod/core/Task.java
Normal file
35
src/integration-test/java/com/replaymod/core/Task.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
public interface Task {
|
||||
ListenableFuture<Void> execute();
|
||||
|
||||
static Task click(int x, int y) {
|
||||
return AbstractTask.create(task -> {
|
||||
task.click(x, y);
|
||||
task.runLater(() -> task.future.set(null));
|
||||
});
|
||||
}
|
||||
|
||||
static Task drag(int x, int y) {
|
||||
return AbstractTask.create(task -> {
|
||||
task.drag(x, y);
|
||||
task.runLater(() -> task.future.set(null));
|
||||
});
|
||||
}
|
||||
|
||||
static Task pressKey(int keyCode) {
|
||||
return AbstractTask.create(task -> {
|
||||
task.press(keyCode);
|
||||
task.runLater(() -> task.future.set(null));
|
||||
});
|
||||
}
|
||||
|
||||
static Task pressKey(char character, int keyCode) {
|
||||
return AbstractTask.create(task -> {
|
||||
task.press(character, keyCode);
|
||||
task.runLater(() -> task.future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
9
src/integration-test/java/com/replaymod/core/Utils.java
Normal file
9
src/integration-test/java/com/replaymod/core/Utils.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
public class Utils {
|
||||
public static void times(int x, Runnable runnable) {
|
||||
for (int i = 0; i < x; i++) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/integration-test/java/com/replaymod/core/Wait.java
Normal file
21
src/integration-test/java/com/replaymod/core/Wait.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
public class Wait extends AbstractTask {
|
||||
private final int duration;
|
||||
|
||||
public Wait(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(duration);
|
||||
runLater(() -> future.set(null));
|
||||
} catch (InterruptedException e) {
|
||||
runLater(() -> future.setException(e));
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.replaymod.core.regression;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.core.CompositeTask;
|
||||
import com.replaymod.core.Task;
|
||||
import com.replaymod.replay.SpectatePlayer;
|
||||
import com.replaymod.replay.overlay.OverlayGui;
|
||||
import com.replaymod.simplepathing.GuiPathingTasks;
|
||||
import com.replaymod.simplepathing.gui.GuiEditKeyframe;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import static com.replaymod.core.AbstractTask.mc;
|
||||
import static com.replaymod.core.Utils.times;
|
||||
|
||||
/**
|
||||
* Regression test: #60 Crash in path preview when two spectator keyframes are closer than 50ms
|
||||
*/
|
||||
public class RegressionTest60 extends CompositeTask {
|
||||
public RegressionTest60() {
|
||||
super(new Task[]{
|
||||
new SpectatePlayer(),
|
||||
OverlayGui.whileOpened(
|
||||
// Place first spectator keyframe
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
// Place second spectator keyframe
|
||||
Task.click(130, 50),
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
// Move second keyframe to 20ms on the keyframe timeline
|
||||
AbstractTask.create(task -> {
|
||||
// Double click keyframe
|
||||
task.click(130, 50);
|
||||
task.click(130, 50);
|
||||
task.expectGui(GuiEditKeyframe.Spectator.class, gui -> {
|
||||
// Set ms field to 20
|
||||
task.click(mc.currentScreen.width / 2 + 80, mc.currentScreen.height / 2);
|
||||
times(4, () -> task.press(Keyboard.KEY_BACK));
|
||||
task.type("20");
|
||||
// Set other fields to 0
|
||||
times(2, () -> {
|
||||
task.press(Keyboard.KEY_TAB);
|
||||
times(4, () -> task.press(Keyboard.KEY_BACK));
|
||||
task.press(Keyboard.KEY_0);
|
||||
});
|
||||
task.click(gui.saveButton);
|
||||
task.expectPopupClosed(() -> task.future.set(null));
|
||||
});
|
||||
}),
|
||||
// Place second spectator keyframe
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton()
|
||||
),
|
||||
// Stop spectating player
|
||||
new SpectatePlayer.End(),
|
||||
// Enable path preview
|
||||
Task.pressKey(Keyboard.KEY_H),
|
||||
new GuiPathingTasks.ClearKeyframeTimeline(),
|
||||
Task.pressKey(Keyboard.KEY_H),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.replaymod.core.regression;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.core.CompositeTask;
|
||||
import com.replaymod.core.Task;
|
||||
import com.replaymod.replay.overlay.OverlayGui;
|
||||
import com.replaymod.simplepathing.GuiPathingTasks;
|
||||
import com.replaymod.simplepathing.gui.GuiEditKeyframe;
|
||||
|
||||
/**
|
||||
* Regression test: #61 NPE when saving in edit keyframe gui of last keyframe
|
||||
*/
|
||||
public class RegressionTest61 extends CompositeTask {
|
||||
public RegressionTest61() {
|
||||
super(new Task[]{
|
||||
OverlayGui.whileOpened(
|
||||
// Place keyframe
|
||||
Task.click(130, 50),
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
AbstractTask.create(task -> {
|
||||
// Double click keyframe
|
||||
task.click(130, 50);
|
||||
task.click(130, 50);
|
||||
task.expectGui(GuiEditKeyframe.Position.class, gui -> {
|
||||
task.click(gui.saveButton);
|
||||
task.expectPopupClosed(() -> task.future.set(null));
|
||||
});
|
||||
}),
|
||||
// Place second spectator keyframe
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton()
|
||||
),
|
||||
new GuiPathingTasks.ClearKeyframeTimeline(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.replaymod.core.regression;
|
||||
|
||||
import com.replaymod.core.CompositeTask;
|
||||
import com.replaymod.core.Task;
|
||||
import com.replaymod.replay.overlay.OverlayGui;
|
||||
import com.replaymod.simplepathing.GuiPathingTasks;
|
||||
|
||||
/**
|
||||
* Regression test: #62 Swapping the only two existing keyframes causes NPE
|
||||
*/
|
||||
public class RegressionTest62 extends CompositeTask {
|
||||
public RegressionTest62() {
|
||||
super(new Task[]{
|
||||
OverlayGui.whileOpened(
|
||||
// Place first keyframe
|
||||
Task.click(130, 50),
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
// Place second keyframe
|
||||
Task.click(150, 50),
|
||||
new GuiPathingTasks.ClickPositionKeyframeButton(),
|
||||
// Move first keyframe past second keyframe
|
||||
Task.click(130,50),
|
||||
Task.drag(170,50)
|
||||
),
|
||||
new GuiPathingTasks.ClearKeyframeTimeline()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.replaymod.extra;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.extras.OpenEyeExtra;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
|
||||
public class DownloadOpenEye extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(OpenEyeExtra.OfferGui.class, offerGui -> {
|
||||
click(offerGui.yesButton);
|
||||
expectGuiClosed(20 * 1000, () -> {
|
||||
File targetFile = new File(mc.mcDataDir, "mods/" + Loader.MC_VERSION + "/OpenEye.jar");
|
||||
if (!targetFile.exists()) {
|
||||
future.setException(new NoSuchFileException(targetFile.getAbsolutePath()));
|
||||
} else {
|
||||
future.set(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.replaymod.online;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.online.gui.GuiLoginPrompt;
|
||||
|
||||
public class SkipLogin extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiLoginPrompt.class, gui -> {
|
||||
click(gui.cancelButton);
|
||||
expectGuiClosed(() -> future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.replaymod.recording;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.gui.GuiCreateWorld;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiSelectWorld;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class CreateSPWorld extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiMainMenu.class, mainMenu -> {
|
||||
click("Singleplayer");
|
||||
expectGui(GuiSelectWorld.class, selectWorld -> {
|
||||
click("Create New World");
|
||||
expectGui(GuiCreateWorld.class, createWorld -> {
|
||||
click("Create New World");
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public class EventHandler {
|
||||
@SubscribeEvent
|
||||
public void onRenderIngame(RenderGameOverlayEvent.Pre event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.replaymod.recording;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import net.minecraft.client.gui.GuiIngameMenu;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ExitSPWorld extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
mc.displayInGameMenu();
|
||||
expectGui(GuiIngameMenu.class, ingameMenu -> {
|
||||
click("Save and Quit to Title");
|
||||
expectGui(GuiMainMenu.class, mainMenu -> new Thread(() -> {
|
||||
try {
|
||||
while (true) {
|
||||
String[] dirs = core.getReplayFolder().list(DirectoryFileFilter.DIRECTORY);
|
||||
if (dirs == null) {
|
||||
future.setException(new NullPointerException("dirs is null"));
|
||||
return;
|
||||
}
|
||||
if (dirs.length == 0) {
|
||||
runLater(() -> future.set(null));
|
||||
return;
|
||||
}
|
||||
Thread.sleep(10);
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
future.setException(e);
|
||||
}
|
||||
}).start());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import net.minecraft.client.gui.GuiIngameMenu;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
|
||||
public class ExitReplay extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
mc.displayInGameMenu();
|
||||
expectGui(GuiIngameMenu.class, ingameMenu -> {
|
||||
click("Exit Replay");
|
||||
expectGui(GuiMainMenu.class, mainMenu -> future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import de.johni0702.minecraft.gui.function.Clickable;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.lwjgl.util.Point;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
public class LoadReplay extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiReplayViewer.class, replayViewer -> runLater(() -> {
|
||||
ReadableDimension size = replayViewer.getMaxSize();
|
||||
// Select first entry
|
||||
replayViewer.forEach(Clickable.class).mouseClick(new Point(size.getWidth() / 2, 40), 0);
|
||||
// Load first replay
|
||||
click(replayViewer.loadButton);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||
}));
|
||||
}
|
||||
|
||||
public class EventHandler {
|
||||
@SubscribeEvent
|
||||
public void onRenderIngame(RenderGameOverlayEvent.Pre event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
|
||||
public class OpenReplayViewer extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiMainMenu.class, mainMenu -> {
|
||||
click("Replay Viewer");
|
||||
expectGui(GuiReplayViewer.class, replayViewer -> future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.replaymod.replay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.extras.playeroverview.PlayerOverviewGui;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class SpectatePlayer extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
press(Keyboard.KEY_B);
|
||||
expectGui(PlayerOverviewGui.class, overview -> {
|
||||
click(overview.getMaxSize().getWidth() / 2 - 60, 60);
|
||||
press(Keyboard.KEY_ESCAPE);
|
||||
expectGuiClosed(() -> future.set(null));
|
||||
});
|
||||
}
|
||||
|
||||
public static class End extends AbstractTask {
|
||||
private int timeout;
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
runLater(() -> press(Keyboard.KEY_LSHIFT));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (timeout++ > 20) {
|
||||
future.setException(new TimeoutException("Camera hasn't stopped spectating."));
|
||||
return;
|
||||
}
|
||||
if (mc.renderViewEntity == mc.thePlayer) {
|
||||
future.set(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.replaymod.replay.overlay;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.core.CompositeTask;
|
||||
import com.replaymod.core.Task;
|
||||
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class OverlayGui {
|
||||
public static Task whileOpened(Task...tasks) {
|
||||
Task[] nTasks = new Task[tasks.length + 2];
|
||||
System.arraycopy(tasks, 0, nTasks, 1, tasks.length);
|
||||
nTasks[0] = new Open();
|
||||
nTasks[tasks.length + 1] = new Close();
|
||||
return new CompositeTask(nTasks);
|
||||
}
|
||||
|
||||
public static class Open extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
press(Keyboard.KEY_T);
|
||||
expectGui(GuiReplayOverlay.class, done -> future.set(null));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Close extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
press(Keyboard.KEY_ESCAPE);
|
||||
expectGuiClosed(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.replaymod.simplepathing;
|
||||
|
||||
import com.replaymod.core.AbstractTask;
|
||||
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
|
||||
import com.replaymod.simplepathing.gui.GuiPathing;
|
||||
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public abstract class GuiPathingTasks extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
expectGui(GuiReplayOverlay.class, ign -> init0(ReplayModSimplePathing.instance.getGuiPathing()));
|
||||
}
|
||||
|
||||
protected abstract void init0(GuiPathing guiPathing);
|
||||
|
||||
public static class ClickPositionKeyframeButton extends GuiPathingTasks {
|
||||
@Override
|
||||
protected void init0(GuiPathing guiPathing) {
|
||||
click(guiPathing.positionKeyframeButton);
|
||||
runLater(() -> future.set(null));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClearKeyframeTimeline extends AbstractTask {
|
||||
@Override
|
||||
protected void init() {
|
||||
press(Keyboard.KEY_C);
|
||||
expectGui(GuiYesNoPopup.class, popup -> {
|
||||
click(popup.getYesButton());
|
||||
expectGuiClosed(() -> future.set(null));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,27 @@
|
||||
package com.replaymod.compat;
|
||||
|
||||
import com.replaymod.compat.bettersprinting.DisableBetterSprinting;
|
||||
import com.replaymod.compat.optifine.DisableFastRender;
|
||||
import com.replaymod.compat.shaders.ShaderBeginRender;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||
import com.replaymod.compat.oranges17animations.HideInvisibleEntities;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
|
||||
@Mod(modid = ReplayModCompat.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
acceptableRemoteVersions = "*",
|
||||
useMetadata = true)
|
||||
public class ReplayModCompat {
|
||||
public static final String MOD_ID = "replaymod-compat";
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
EventBus bus = MinecraftForge.EVENT_BUS;
|
||||
bus.register(new ShaderBeginRender());
|
||||
EventBus bus = FMLCommonHandler.instance().bus();
|
||||
bus.register(new DisableFastRender());
|
||||
bus.register(new HideInvisibleEntities());
|
||||
DisableBetterSprinting.register();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.replaymod.compat.bettersprinting;
|
||||
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replay.events.ReplayChatMessageEvent;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
import cpw.mods.fml.common.versioning.Restriction;
|
||||
import cpw.mods.fml.common.versioning.VersionRange;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.IWorldAccess;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Old Better Sprinting versions replace the vanilla player with their own, overridden instance (replacing the camera entity).
|
||||
*
|
||||
* See: https://github.com/chylex/Better-Sprinting/blob/1.8/src/main/java/chylex/bettersprinting/client/player/impl/LogicImplOverride.java
|
||||
*/
|
||||
public class DisableBetterSprinting {
|
||||
private static final VersionRange OLD_VERSION = VersionRange.newRange(null,
|
||||
Collections.singletonList(new Restriction(null, false, new DefaultArtifactVersion("2.0.0"), false)));
|
||||
private static final String LOGIC_CLASS_NAME = "chylex.bettersprinting.client.player.impl.LogicImplOverride";
|
||||
private static final String CONTROLLER_OVERRIDE_CLASS_NAME = LOGIC_CLASS_NAME + ".PlayerControllerMPOverride";
|
||||
|
||||
public static void register() {
|
||||
Loader.instance().getModList().stream()
|
||||
.filter(mod -> mod.getModId().equalsIgnoreCase("bettersprinting"))
|
||||
.findFirst()
|
||||
.map(ModContainer::getProcessedVersion).filter(OLD_VERSION::containsVersion)
|
||||
.ifPresent($_ -> MinecraftForge.EVENT_BUS.register(new DisableBetterSprinting()));
|
||||
}
|
||||
|
||||
private DisableBetterSprinting() {}
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
private PlayerControllerMP originalController;
|
||||
private BetterSprintingWorldAccess worldAccessHook = new BetterSprintingWorldAccess();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void beforeGuiOpenEvent(GuiOpenEvent event) {
|
||||
if (ReplayModReplay.instance.getReplayHandler() != null && mc.theWorld != null) {
|
||||
// During replay, get ready to revert BetterSprinting's overwritten playerController
|
||||
originalController = mc.playerController;
|
||||
mc.theWorld.addWorldAccess(worldAccessHook);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
public void afterGuiOpenEvent(GuiOpenEvent event) {
|
||||
if (ReplayModReplay.instance.getReplayHandler() != null && mc.theWorld != null) {
|
||||
mc.theWorld.removeWorldAccess(worldAccessHook);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onReplayChatMessage(ReplayChatMessageEvent event) {
|
||||
// Suppress this message if it's the Better Sprinting warning message
|
||||
for (StackTraceElement elem : Thread.currentThread().getStackTrace()) {
|
||||
if (LOGIC_CLASS_NAME.equals(elem.getClassName())) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class BetterSprintingWorldAccess implements IWorldAccess {
|
||||
@Override
|
||||
public void onEntityDestroy(Entity entityIn) {
|
||||
if (mc.playerController != null && mc.playerController.getClass().getName().equals(CONTROLLER_OVERRIDE_CLASS_NAME)) {
|
||||
// Someone has secretly swapped out the player controller and is about to substitute their own player entity.
|
||||
// This is the right time to destroy their plan.
|
||||
mc.playerController = originalController;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void markBlockForUpdate(int x, int y, int z) {}
|
||||
@Override public void markBlockForRenderUpdate(int p_147588_1_, int p_147588_2_, int p_147588_3_) {}
|
||||
@Override public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) {}
|
||||
@Override public void playSound(String soundName, double x, double y, double z, float volume, float pitch) {}
|
||||
@Override public void playSoundToNearExcept(EntityPlayer except, String soundName, double x, double y, double z, float volume, float pitch) {}
|
||||
@Override public void spawnParticle(String p_180442_1_, double p_180442_2_, double p_180442_3_, double p_180442_5_, double p_180442_7_, double p_180442_9_, double p_180442_11_) {}
|
||||
@Override public void onEntityCreate(Entity p_72703_1_) {}
|
||||
@Override public void playRecord(String recordName, int x, int y, int z) {}
|
||||
@Override public void broadcastSound(int p_180440_1_, int x, int y, int z, int p_180440_3_) {}
|
||||
@Override public void playAuxSFX(EntityPlayer p_72706_1_, int p_72706_2_, int p_72706_3_, int p_72706_4_, int p_72706_5_, int p_72706_6_) {}
|
||||
@Override public void destroyBlockPartially(int p_147587_1_, int p_147587_2_, int p_147587_3_, int p_147587_4_, int p_147587_5_) {}
|
||||
@Override public void onStaticEntitiesChanged() {}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.replaymod.compat.optifine;
|
||||
|
||||
import com.replaymod.render.events.ReplayRenderEvent;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
// TODO 1.7.10: Is this still necessary (probably, but needs checking)?
|
||||
public class DisableFastRender {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.replaymod.compat.oranges17animations;
|
||||
|
||||
import com.replaymod.replay.camera.CameraEntity;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.client.event.RenderLivingEvent;
|
||||
|
||||
/**
|
||||
* Orange seems to have copied vast parts of the RendererLivingEntity into their ArmorAnimation class which cancels the RenderLivingEvent.Pre and calls its own code instead.
|
||||
* This breaks our mixin which assures that, even though the camera is in spectator mode, it cannot see invisible entities.
|
||||
*
|
||||
* To fix this issue, we simply cancel the RenderLivingEvent.Pre before it gets to ArmorAnimation if the entity is invisible.
|
||||
*/
|
||||
public class HideInvisibleEntities {
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
private final boolean modLoaded = Loader.isModLoaded("animations");
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void preRenderLiving(RenderLivingEvent.Pre event) {
|
||||
if (modLoaded) {
|
||||
if (mc.thePlayer instanceof CameraEntity && event.entity.isInvisible()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.replaymod.compat.shaders;
|
||||
|
||||
import com.replaymod.render.hooks.EntityRendererHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class ShaderBeginRender {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
/**
|
||||
* Invokes Shaders#beginRender when rendering a video,
|
||||
* as this would usually get called by EntityRenderer#renderWorld,
|
||||
* which we're not calling during rendering.
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public void onRenderTickStart(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != TickEvent.Phase.START) return;
|
||||
if (ShaderReflection.shaders_beginRender == null) return;
|
||||
if (ShaderReflection.config_isShaders == null) return;
|
||||
|
||||
try {
|
||||
// check if video is being rendered
|
||||
if (((EntityRendererHandler.IEntityRenderer) mc.entityRenderer).replayModRender_getHandler() == null)
|
||||
return;
|
||||
|
||||
// check if Shaders are enabled
|
||||
if (!(boolean) (ShaderReflection.config_isShaders.invoke(null))) return;
|
||||
|
||||
ShaderReflection.shaders_beginRender.invoke(null, mc, mc.timer.elapsedPartialTicks, 0);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.replaymod.compat.shaders;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ShaderReflection {
|
||||
|
||||
// Shaders.frameTimeCounter
|
||||
public static Field shaders_frameTimeCounter;
|
||||
|
||||
// Shaders.isShadowPass
|
||||
public static Field shaders_isShadowPass;
|
||||
|
||||
// Shaders.beginRender()
|
||||
public static Method shaders_beginRender;
|
||||
|
||||
// RenderGlobal.chunksToUpdateForced (Optifine only)
|
||||
public static Field renderGlobal_chunksToUpdateForced;
|
||||
|
||||
// Config.isShaders() (Optifine only)
|
||||
public static Method config_isShaders;
|
||||
|
||||
static {
|
||||
try {
|
||||
shaders_frameTimeCounter = Class.forName("shadersmod.client.Shaders")
|
||||
.getDeclaredField("frameTimeCounter");
|
||||
shaders_frameTimeCounter.setAccessible(true);
|
||||
|
||||
shaders_isShadowPass = Class.forName("shadersmod.client.Shaders")
|
||||
.getDeclaredField("isShadowPass");
|
||||
shaders_isShadowPass.setAccessible(true);
|
||||
|
||||
shaders_beginRender = Class.forName("shadersmod.client.Shaders")
|
||||
.getDeclaredMethod("beginRender", Minecraft.class, float.class, long.class);
|
||||
shaders_beginRender.setAccessible(true);
|
||||
|
||||
renderGlobal_chunksToUpdateForced = Class.forName("net.minecraft.client.renderer.RenderGlobal")
|
||||
.getDeclaredField("chunksToUpdateForced");
|
||||
renderGlobal_chunksToUpdateForced.setAccessible(true);
|
||||
|
||||
config_isShaders = Class.forName("Config")
|
||||
.getDeclaredMethod("isShaders");
|
||||
config_isShaders.setAccessible(true);
|
||||
} catch (ClassNotFoundException ignore) {
|
||||
// no shaders mod installed
|
||||
} catch (NoSuchMethodException | NoSuchFieldException e) {
|
||||
// the method wasn't found. Has it been renamed?
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.replaymod.compat.shaders.mixin;
|
||||
|
||||
import com.replaymod.compat.shaders.ShaderReflection;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
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;
|
||||
|
||||
@Mixin(EntityRenderer.class)
|
||||
public abstract class MixinShaderEntityRenderer {
|
||||
|
||||
@Inject(method = "renderWorldPass", at = @At("HEAD"))
|
||||
private void replayModCompat_updateShaderFrameTimeCounter(CallbackInfo ignore) {
|
||||
if (ReplayModReplay.instance.getReplayHandler() == null) return;
|
||||
if (ShaderReflection.shaders_frameTimeCounter == null) return;
|
||||
|
||||
ReplayHandler replayHandler = ReplayModReplay.instance.getReplayHandler();
|
||||
float timestamp = replayHandler.getReplaySender().currentTimeStamp() / 1000f % 3600f;
|
||||
try {
|
||||
ShaderReflection.shaders_frameTimeCounter.set(null, timestamp);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.replaymod.compat.shaders.mixin;
|
||||
|
||||
import com.replaymod.render.hooks.EntityRendererHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.chunk.RenderChunk;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(RenderChunk.class)
|
||||
public abstract class MixinShaderRenderChunk {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
/**
|
||||
* Changes the RenderChunk#isPlayerUpdate method that Optifine adds
|
||||
* to always return true while rendering so no chunks are being added
|
||||
* to a separate rendering queue
|
||||
*/
|
||||
@Inject(method = "isPlayerUpdate", at = @At("HEAD"), cancellable = true)
|
||||
private void replayModCompat_disableIsPlayerUpdate(CallbackInfoReturnable<Boolean> ci) {
|
||||
if (((EntityRendererHandler.IEntityRenderer) mc.entityRenderer).replayModRender_getHandler() == null) return;
|
||||
ci.setReturnValue(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.replaymod.compat.shaders.mixin;
|
||||
|
||||
import com.replaymod.compat.shaders.ShaderReflection;
|
||||
import com.replaymod.render.hooks.EntityRendererHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.culling.ICamera;
|
||||
import net.minecraft.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(RenderGlobal.class)
|
||||
public abstract class MixinShaderRenderGlobal {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
@Shadow
|
||||
public boolean displayListEntitiesDirty;
|
||||
|
||||
@Inject(method = "setupTerrain", at = @At("HEAD"), cancellable = true)
|
||||
public void replayModCompat_setupTerrain(Entity viewEntity, double partialTicks, ICamera camera,
|
||||
int frameCount, boolean playerSpectator, CallbackInfo ci) {
|
||||
if (((EntityRendererHandler.IEntityRenderer) mc.entityRenderer).replayModRender_getHandler() == null) return;
|
||||
if (ShaderReflection.shaders_isShadowPass == null) return;
|
||||
|
||||
// when called by the shadow pass, displayListEntitiesDirty can't be set to false, as no chunk updates
|
||||
// are being processed. As it's being set to true by ChunkLoadingRenderGlobal#updateChunks, we have to
|
||||
// set it to false manually to exit the loop imposed by MixinRenderGlobal#replayModRender_setupTerrain.
|
||||
try {
|
||||
if ((boolean) ShaderReflection.shaders_isShadowPass.get(null) == true) {
|
||||
displayListEntitiesDirty = false;
|
||||
}
|
||||
} catch (IllegalAccessException ignore) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.replaymod.compat.shaders.mixin;
|
||||
|
||||
import com.replaymod.render.hooks.EntityRendererHandler;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Pseudo;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Pseudo
|
||||
@Mixin(targets = "shadersmod/client/Shaders", remap = false)
|
||||
public abstract class MixinShaders {
|
||||
|
||||
@Shadow static Minecraft mc;
|
||||
@Shadow static long systemTime;
|
||||
@Shadow static long lastSystemTime;
|
||||
@Shadow static long diffSystemTime;
|
||||
@Shadow static int frameCounter;
|
||||
@Shadow static float frameTime;
|
||||
@Shadow static float frameTimeCounter;
|
||||
|
||||
@Redirect(method = "beginRender", at = @At(value = "INVOKE", target = "Ljava/lang/System;currentTimeMillis()J"))
|
||||
private static long replayModCompat_currentTimeMillis() {
|
||||
ReplayHandler replayHandler = ReplayModReplay.instance.getReplayHandler();
|
||||
if (replayHandler != null) {
|
||||
systemTime = replayHandler.getReplaySender().currentTimeStamp();
|
||||
|
||||
// We need to manipulate all the other previous-frame-time-based variables too
|
||||
|
||||
lastSystemTime = 0; // Draw all frames as if they were the first ones
|
||||
// diffSystemTime will be set to 0 by Shaders
|
||||
// frameTime will be set to 0 by Shaders
|
||||
frameTimeCounter = systemTime / 1000f; // will be %= 3600f by Shaders
|
||||
|
||||
// Set frameCounter only if rendering is in progress
|
||||
EntityRendererHandler entityRendererHandler =
|
||||
((EntityRendererHandler.IEntityRenderer) mc.entityRenderer).replayModRender_getHandler();
|
||||
if (entityRendererHandler != null) {
|
||||
frameCounter = entityRendererHandler.getRenderInfo().getFramesDone();
|
||||
}
|
||||
|
||||
return systemTime;
|
||||
}
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
94
src/main/java/com/replaymod/core/GLErrorTransformer.java
Normal file
94
src/main/java/com/replaymod/core/GLErrorTransformer.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
/**
|
||||
* Insert glGetError checks after all calls to any method in any GL*, ARB* and EXT* classes
|
||||
*/
|
||||
public class GLErrorTransformer implements IClassTransformer {
|
||||
private static final String GL_CLASS = "org.lwjgl.opengl.GL";
|
||||
private static final String GL = GL_CLASS.replace('.', '/');
|
||||
private static final String ARB_CLASS = "org.lwjgl.opengl.ARB";
|
||||
private static final String ARB = ARB_CLASS.replace('.', '/');
|
||||
private static final String EXT_CLASS = "org.lwjgl.opengl.EXT";
|
||||
private static final String EXT = EXT_CLASS.replace('.', '/');
|
||||
private static final String GLErrorTransformer_CLASS = GLErrorTransformer.class.getName();
|
||||
private static final String GLErrorTransformer = GLErrorTransformer_CLASS.replace('.', '/');
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] basicClass) {
|
||||
// Ignore (anonymous) inner classes of this transformer
|
||||
if (name.startsWith(GLErrorTransformer_CLASS)) return basicClass;
|
||||
|
||||
ClassReader reader = new ClassReader(basicClass);
|
||||
ClassWriter writer = new ClassWriter(reader, 0);
|
||||
reader.accept(new ClassVisitor(Opcodes.ASM5, writer) {
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
|
||||
return new MethodVisitor(Opcodes.ASM5, mv) {
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
||||
super.visitMethodInsn(opcode, owner, name, desc, itf);
|
||||
if (owner.startsWith(GL) || owner.startsWith(ARB) || owner.startsWith(EXT)) {
|
||||
visitLdcInsn(owner.replace('/', '.'));
|
||||
visitLdcInsn(name);
|
||||
super.visitMethodInsn(Opcodes.INVOKESTATIC, GLErrorTransformer, "glErrorCheck", "(Ljava/lang/String;Ljava/lang/String;)V", false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMaxs(int maxStack, int maxLocals) {
|
||||
super.visitMaxs(maxStack + 2, maxLocals);
|
||||
}
|
||||
};
|
||||
}
|
||||
}, 0);
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
private static boolean inGlBegin;
|
||||
|
||||
@SuppressWarnings("unused") // Called via ASM
|
||||
public static void glErrorCheck(String cls, String method) {
|
||||
if (method.equals("glBegin") && cls.equals(GL_CLASS + "11")) {
|
||||
if (inGlBegin) {
|
||||
// glBegin within glBegin
|
||||
throw new GLError(GL11.GL_INVALID_OPERATION, cls, method);
|
||||
}
|
||||
inGlBegin = true;
|
||||
return;
|
||||
}
|
||||
if (inGlBegin && method.equals("glEnd") && cls.equals(GL_CLASS + "11")) {
|
||||
inGlBegin = false;
|
||||
}
|
||||
if (inGlBegin) {
|
||||
return; // Cannot call glGetError in between of glBegin and glEnd
|
||||
}
|
||||
int err = GL11.glGetError();
|
||||
if (err != 0) {
|
||||
GLError e = new GLError(err, cls, method);
|
||||
if ("true".equals(System.getProperty("replaymod.glerrors.throw", "true"))) {
|
||||
throw e;
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class GLError extends RuntimeException {
|
||||
private GLError(int err, String cls, String method) {
|
||||
super(GLU.gluErrorString(err) + " (" + err + ")");
|
||||
StackTraceElement[] stack = getStackTrace();
|
||||
stack[0] = new StackTraceElement(cls, method, stack[0].getFileName(), stack[0].getLineNumber());
|
||||
setStackTrace(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
105
src/main/java/com/replaymod/core/GLStateTrackerTransformer.java
Normal file
105
src/main/java/com/replaymod/core/GLStateTrackerTransformer.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Redirect all calls to GL11.glEnable and GL11.glDisable to the GLStateTracker (excluding that class itself).
|
||||
*/
|
||||
public class GLStateTrackerTransformer implements IClassTransformer {
|
||||
private static final String GL11_CLASS = "org.lwjgl.opengl.GL11";
|
||||
private static final String GL11 = GL11_CLASS.replace('.', '/');
|
||||
private static final String glEnable = "glEnable";
|
||||
private static final String glDisable = "glDisable";
|
||||
private static final String GLStateTracker_CLASS = "com.replaymod.render.hooks.GLStateTracker";
|
||||
private static final String GLStateTracker = GLStateTracker_CLASS.replace('.', '/');
|
||||
private static final String hook_glEnable = "hook_glEnable";
|
||||
private static final String hook_glDisable = "hook_glDisable";
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] basicClass) {
|
||||
// Ignore (anonymous) inner classes of this transformer
|
||||
if (name.startsWith(GLStateTrackerTransformer.class.getName())) return basicClass;
|
||||
// Ignore the state tracker itself
|
||||
if (name.equals(GLStateTracker_CLASS)) return basicClass;
|
||||
|
||||
ClassReader reader = new ClassReader(basicClass);
|
||||
Set<Method> eligibleMethods = findEligibleMethods(reader);
|
||||
if (eligibleMethods.isEmpty()) {
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
ClassWriter writer = new ClassWriter(reader, 0);
|
||||
reader.accept(new ClassVisitor(Opcodes.ASM5, writer) {
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
|
||||
if (!eligibleMethods.contains(new Method(name, desc))) {
|
||||
return mv;
|
||||
}
|
||||
return new MethodVisitor(Opcodes.ASM5, mv) {
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
||||
if (owner.equals(GL11)) {
|
||||
if (name.equals(glEnable)) {
|
||||
owner = GLStateTracker;
|
||||
name = hook_glEnable;
|
||||
} else if (name.equals(glDisable)) {
|
||||
owner = GLStateTracker;
|
||||
name = hook_glDisable;
|
||||
}
|
||||
}
|
||||
super.visitMethodInsn(opcode, owner, name, desc, itf);
|
||||
}
|
||||
};
|
||||
}
|
||||
}, 0);
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
private Set<Method> findEligibleMethods(ClassReader reader) {
|
||||
Set<Method> eligibleMethods = new HashSet<>();
|
||||
reader.accept(new ClassVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String methodName, String methodDesc, String signature, String[] exceptions) {
|
||||
return new MethodVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
||||
if (owner.equals(GL11) && (name.equals(glEnable) || name.equals(glDisable))) {
|
||||
eligibleMethods.add(new Method(methodName, methodDesc));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
||||
return eligibleMethods;
|
||||
}
|
||||
|
||||
private static class Method {
|
||||
private final String name, desc;
|
||||
|
||||
private Method(String name, String desc) {
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Method method = (Method) o;
|
||||
return name.equals(method.name) && desc.equals(method.desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode() ^ desc.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,21 @@ package com.replaymod.core;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.ReportedException;
|
||||
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;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class KeyBindingRegistry {
|
||||
private Map<String, KeyBinding> keyBindings = new HashMap<String, KeyBinding>();
|
||||
@@ -63,7 +64,7 @@ public class KeyBindingRegistry {
|
||||
|
||||
public void handleRepeatedKeyBindings() {
|
||||
for (Map.Entry<KeyBinding, Collection<Runnable>> entry : repeatedKeyBindingHandlers.asMap().entrySet()) {
|
||||
if (entry.getKey().isKeyDown()) {
|
||||
if (entry.getKey().getIsKeyPressed()) {
|
||||
invokeKeyBindingHandlers(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
@@ -85,7 +86,7 @@ public class KeyBindingRegistry {
|
||||
CrashReport crashReport = CrashReport.makeCrashReport(cause, "Handling Key Binding");
|
||||
CrashReportCategory category = crashReport.makeCategory("Key Binding");
|
||||
category.addCrashSection("Key Binding", keyBinding);
|
||||
category.setDetail("Handler", runnable::toString);
|
||||
category.addCrashSectionCallable("Handler", runnable::toString);
|
||||
throw new ReportedException(crashReport);
|
||||
}
|
||||
}
|
||||
@@ -100,7 +101,12 @@ public class KeyBindingRegistry {
|
||||
CrashReport crashReport = CrashReport.makeCrashReport(cause, "Handling Raw Key Binding");
|
||||
CrashReportCategory category = crashReport.makeCategory("Key Binding");
|
||||
category.addCrashSection("Key Code", keyCode);
|
||||
category.setDetail("Handler", runnable::toString);
|
||||
category.addCrashSectionCallable("Handler", new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return runnable;
|
||||
}
|
||||
});
|
||||
throw new ReportedException(crashReport);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
|
||||
import cpw.mods.fml.relauncher.CoreModManager;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
@@ -10,6 +10,8 @@ import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.security.CodeSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
@@ -20,6 +22,7 @@ public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
Mixins.addConfiguration("mixins.render.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.replay.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.compat.shaders.replaymod.json");
|
||||
Mixins.addConfiguration("mixins.extras.playeroverview.replaymod.json");
|
||||
|
||||
CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
|
||||
if (codeSource != null) {
|
||||
@@ -29,7 +32,8 @@ public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
if (file.isFile()) {
|
||||
// This forces forge to reexamine the jar file for FML mods
|
||||
// Should eventually be handled by Mixin itself, maybe?
|
||||
CoreModManager.getIgnoredMods().remove(file.getName());
|
||||
CoreModManager.getLoadedCoremods().remove(file.getName());
|
||||
CoreModManager.getReparseableCoremods().add(file.getName());
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
@@ -42,8 +46,12 @@ public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
return new String[]{
|
||||
};
|
||||
List<String> transformers = new ArrayList<>();
|
||||
if ("true".equals(System.getProperty("replaymod.glerrors", "false"))) {
|
||||
transformers.add(GLErrorTransformer.class.getName());
|
||||
}
|
||||
transformers.add(GLStateTrackerTransformer.class.getName());
|
||||
return transformers.stream().toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,37 +6,47 @@ 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.render.utils.SoundHandler;
|
||||
import com.replaymod.replay.InputReplayTimer;
|
||||
import com.replaymod.replaystudio.util.I18n;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
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 de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.*;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
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 org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
@Mod(modid = ReplayMod.MOD_ID,
|
||||
useMetadata = true,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
updateJSON = "https://raw.githubusercontent.com/ReplayMod/ReplayMod/master/versions.json",
|
||||
acceptableRemoteVersions = "*",
|
||||
guiFactory = "com.replaymod.core.gui.GuiFactory")
|
||||
public class ReplayMod {
|
||||
|
||||
@@ -49,10 +59,10 @@ public class ReplayMod {
|
||||
private static String parseMinecraftVersion() {
|
||||
CrashReport crashReport = new CrashReport("", new Throwable());
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CrashReportCategory.Entry> list = crashReport.getCategory().children;
|
||||
List<CrashReportCategory.Entry> list = crashReport.getCategory().field_85077_c;
|
||||
for (CrashReportCategory.Entry entry : list) {
|
||||
if ("Minecraft Version".equals(entry.getKey())) {
|
||||
return entry.getValue();
|
||||
if ("Minecraft Version".equals(entry.func_85089_a())) {
|
||||
return entry.func_85090_b();
|
||||
}
|
||||
}
|
||||
return "Unknown";
|
||||
@@ -67,6 +77,8 @@ public class ReplayMod {
|
||||
|
||||
@Deprecated
|
||||
public static Configuration config;
|
||||
@Deprecated
|
||||
public static SoundHandler soundHandler = new SoundHandler();
|
||||
|
||||
private final KeyBindingRegistry keyBindingRegistry = new KeyBindingRegistry();
|
||||
private final SettingsRegistry settingsRegistry = new SettingsRegistry();
|
||||
@@ -109,7 +121,8 @@ public class ReplayMod {
|
||||
|
||||
new MainMenuHandler().register();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(keyBindingRegistry);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
FMLCommonHandler.instance().bus().register(keyBindingRegistry);
|
||||
|
||||
getKeyBindingRegistry().registerKeyBinding("replaymod.input.settings", 0, () -> {
|
||||
new GuiReplaySettings(null, settingsRegistry).display();
|
||||
@@ -120,10 +133,155 @@ public class ReplayMod {
|
||||
public void postInit(FMLPostInitializationEvent event) throws IOException {
|
||||
settingsRegistry.save(); // Save default values to disk
|
||||
|
||||
/* TODO 1.7.10: MC crashes when setting render distance to > 16
|
||||
if(!FMLClientHandler.instance().hasOptifine())
|
||||
GameSettings.Options.RENDER_DISTANCE.setValueMax(64f);
|
||||
*/
|
||||
|
||||
testIfMoeshAndExitMinecraft();
|
||||
if (System.getProperty("replaymod.render.file") != null) {
|
||||
final File file = new File(System.getProperty("replaymod.render.file"));
|
||||
if (!file.exists()) {
|
||||
throw new IOException("File \"" + file.getPath() + "\" not found.");
|
||||
}
|
||||
|
||||
final String path = System.getProperty("replaymod.render.path");
|
||||
String type = System.getProperty("replaymod.render.type");
|
||||
String bitrate = System.getProperty("replaymod.render.bitrate");
|
||||
String fps = System.getProperty("replaymod.render.fps");
|
||||
String waitForChunks = System.getProperty("replaymod.render.waitforchunks");
|
||||
String linearMovement = System.getProperty("replaymod.render.linearmovement");
|
||||
String skyColor = System.getProperty("replaymod.render.skycolor");
|
||||
String width = System.getProperty("replaymod.render.width");
|
||||
String height = System.getProperty("replaymod.render.height");
|
||||
String exportCommand = System.getProperty("replaymod.render.exportcommand");
|
||||
String exportCommandArgs = System.getProperty("replaymod.render.exportcommandargs");
|
||||
/*
|
||||
final RenderOptions options = new RenderOptions();
|
||||
if (bitrate != null) {
|
||||
options.setBitrate(bitrate);
|
||||
}
|
||||
if (fps != null) {
|
||||
options.setFps(Integer.parseInt(fps));
|
||||
}
|
||||
if (waitForChunks != null) {
|
||||
options.setWaitForChunks(Boolean.parseBoolean(waitForChunks));
|
||||
}
|
||||
if (linearMovement != null) {
|
||||
options.setLinearMovement(Boolean.parseBoolean(linearMovement));
|
||||
}
|
||||
if (skyColor != null) {
|
||||
if (skyColor.startsWith("0x")) {
|
||||
options.setSkyColor(Integer.parseInt(skyColor.substring(2), 16));
|
||||
} else {
|
||||
options.setSkyColor(Integer.parseInt(skyColor));
|
||||
}
|
||||
}
|
||||
if (width != null) {
|
||||
options.setWidth(Integer.parseInt(width));
|
||||
}
|
||||
if (height != null) {
|
||||
options.setHeight(Integer.parseInt(height));
|
||||
}
|
||||
|
||||
if (exportCommand != null) {
|
||||
options.setExportCommand(exportCommand);
|
||||
}
|
||||
if (exportCommandArgs != null) {
|
||||
options.setExportCommandArgs(exportCommandArgs);
|
||||
} else {
|
||||
options.setExportCommandArgs(EncodingPreset.MP4DEFAULT.getCommandLineArgs());
|
||||
}
|
||||
|
||||
options.setOutputFile(new File(String.valueOf(System.currentTimeMillis())));
|
||||
|
||||
Pipelines.Preset pipelinePreset = Pipelines.Preset.DEFAULT;
|
||||
if (type != null) {
|
||||
String[] parts = type.split(":");
|
||||
type = parts[0].toUpperCase();
|
||||
if ("NORMAL".equals(type) || "DEFAULT".equals(type)) {
|
||||
pipelinePreset = Pipelines.Preset.DEFAULT;
|
||||
} else if ("STEREO".equals(type) || "STEREOSCOPIC".equals(type)) {
|
||||
pipelinePreset = Pipelines.Preset.STEREOSCOPIC;
|
||||
} else if ("CUBIC".equals(type)) {
|
||||
if (parts.length < 2) {
|
||||
throw new IllegalArgumentException("Cubic renderer requires boolean for whether it's stable.");
|
||||
}
|
||||
pipelinePreset = Pipelines.Preset.CUBIC;
|
||||
} else if ("EQUIRECTANGULAR".equals(type)) {
|
||||
if (parts.length < 2) {
|
||||
throw new IllegalArgumentException("Equirectangular renderer requires boolean for whether it's stable.");
|
||||
}
|
||||
pipelinePreset = Pipelines.Preset.EQUIRECTANGULAR;
|
||||
} else if ("ODS".equals(type)) {
|
||||
if (parts.length < 2) {
|
||||
throw new IllegalArgumentException("ODS renderer requires boolean for whether it's stable.");
|
||||
}
|
||||
pipelinePreset = Pipelines.Preset.ODS;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown type: " + parts[0]);
|
||||
}
|
||||
}
|
||||
options.setMode(pipelinePreset);
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Queue<ListenableFutureTask> tasks = mc.scheduledTasks;
|
||||
synchronized (mc.scheduledTasks) {
|
||||
tasks.add(ListenableFutureTask.create(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String renderDistance = System.getProperty("replaymod.render.mc.renderdistance");
|
||||
String clouds = System.getProperty("replaymod.render.mc.clouds");
|
||||
if (renderDistance != null) {
|
||||
mc.gameSettings.renderDistanceChunks = Integer.parseInt(renderDistance);
|
||||
}
|
||||
if (clouds != null) {
|
||||
mc.gameSettings.clouds = Boolean.parseBoolean(clouds);
|
||||
}
|
||||
|
||||
System.out.println("Loading replay...");
|
||||
// TODO
|
||||
// try {
|
||||
// ReplayHandler.startReplay(file, false);
|
||||
// } catch (Throwable t) {
|
||||
// t.printStackTrace();
|
||||
// FMLCommonHandler.instance().exitJava(1, false);
|
||||
// }
|
||||
//
|
||||
// int index = 0;
|
||||
// if (path != null) {
|
||||
// for (KeyframeSet set : ReplayHandler.getKeyframeRepository()) {
|
||||
// if (set.getName().equals(path)) {
|
||||
// break;
|
||||
// }
|
||||
// index++;
|
||||
// }
|
||||
// if (index >= ReplayHandler.getKeyframeRepository().length) {
|
||||
// throw new IllegalArgumentException("No path named \"" + path + "\".");
|
||||
// }
|
||||
// } else if (ReplayHandler.getKeyframeRepository().length == 0) {
|
||||
// throw new IllegalArgumentException("Replay file has no paths defined.");
|
||||
// }
|
||||
// ReplayHandler.useKeyframePresetFromRepository(index);
|
||||
//
|
||||
// System.out.println("Rendering started...");
|
||||
// try {
|
||||
// ReplayProcess.startReplayProcess(options, true);
|
||||
// } catch (Throwable t) {
|
||||
// t.printStackTrace();
|
||||
// FMLCommonHandler.instance().exitJava(1, false);
|
||||
// }
|
||||
// if (mc.hasCrashed) {
|
||||
// System.out.println(mc.crashReporter.getCompleteReport());
|
||||
// }
|
||||
// System.out.println("Rendering done. Shutting down...");
|
||||
// mc.shutdown();
|
||||
}
|
||||
}, null));
|
||||
}
|
||||
|
||||
testIfMoeshAndExitMinecraft();
|
||||
}
|
||||
|
||||
runLater(() -> {
|
||||
// Cleanup deleted corrupted replays
|
||||
@@ -159,9 +317,53 @@ public class ReplayMod {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set when the currently running code has been scheduled by runLater.
|
||||
* If this is the case, subsequent calls to runLater have to be delayed until all scheduled tasks have been
|
||||
* processed, otherwise a livelock may occur.
|
||||
*/
|
||||
private boolean inRunLater = false;
|
||||
|
||||
// 1.7.10: Cannot use MC's because it is processed only during ticks (so not at all when replay is paused)
|
||||
private final Queue<ListenableFutureTask<?>> scheduledTasks = new ArrayDeque<>();
|
||||
|
||||
public void runLater(Runnable runnable) {
|
||||
synchronized (mc.scheduledTasks) {
|
||||
mc.scheduledTasks.add(ListenableFutureTask.create(runnable, null));
|
||||
if (mc.isCallingFromMinecraftThread() && inRunLater) {
|
||||
EventBus bus = FMLCommonHandler.instance().bus();
|
||||
bus.register(new RunLaterHelper(runnable));
|
||||
return;
|
||||
}
|
||||
synchronized (scheduledTasks) {
|
||||
scheduledTasks.add(ListenableFutureTask.create(() -> {
|
||||
inRunLater = true;
|
||||
try {
|
||||
runnable.run();
|
||||
} finally {
|
||||
inRunLater = false;
|
||||
}
|
||||
}, null));
|
||||
}
|
||||
}
|
||||
|
||||
// in 1.7.10 apparently events can't be delivered to anonymous classes
|
||||
@RequiredArgsConstructor
|
||||
public class RunLaterHelper {
|
||||
private final Runnable runnable;
|
||||
@SubscribeEvent
|
||||
public void onRenderTick(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase == TickEvent.Phase.START) {
|
||||
runLater(runnable);
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void runScheduledTasks(InputReplayTimer.RunScheduledTasks event) {
|
||||
synchronized (scheduledTasks) {
|
||||
while (!scheduledTasks.isEmpty()) {
|
||||
scheduledTasks.poll().run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,13 +392,13 @@ public class ReplayMod {
|
||||
private void printToChat(boolean warning, String message, Object... args) {
|
||||
if (getSettingsRegistry().get(Setting.NOTIFICATIONS)) {
|
||||
// Some nostalgia: "§8[§6Replay Mod§8]§r Your message goes here"
|
||||
Style coloredDarkGray = new Style().setColor(TextFormatting.DARK_GRAY);
|
||||
Style coloredGold = new Style().setColor(TextFormatting.GOLD);
|
||||
ITextComponent text = new TextComponentString("[").setStyle(coloredDarkGray)
|
||||
.appendSibling(new TextComponentTranslation("replaymod.title").setStyle(coloredGold))
|
||||
.appendSibling(new TextComponentString("] "))
|
||||
.appendSibling(new TextComponentTranslation(message, args).setStyle(new Style()
|
||||
.setColor(warning ? TextFormatting.RED : TextFormatting.DARK_GREEN)));
|
||||
ChatStyle coloredDarkGray = new ChatStyle().setColor(EnumChatFormatting.DARK_GRAY);
|
||||
ChatStyle coloredGold = new ChatStyle().setColor(EnumChatFormatting.GOLD);
|
||||
IChatComponent text = new ChatComponentText("[").setChatStyle(coloredDarkGray)
|
||||
.appendSibling(new ChatComponentTranslation("replaymod.title").setChatStyle(coloredGold))
|
||||
.appendSibling(new ChatComponentText("] "))
|
||||
.appendSibling(new ChatComponentTranslation(message, args).setChatStyle(new ChatStyle()
|
||||
.setColor(warning ? EnumChatFormatting.RED : EnumChatFormatting.DARK_GREEN)));
|
||||
// Send message to chat GUI
|
||||
// The ingame GUI is initialized at startup, therefore this is possible before the client is connected
|
||||
mc.ingameGUI.getChatGUI().printChatMessage(text);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.replaymod.core;
|
||||
|
||||
import com.replaymod.core.events.SettingsChangedEvent;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -83,7 +83,7 @@ public class SettingsRegistry {
|
||||
throw new IllegalArgumentException("Default type " + key.getDefault().getClass() + " not supported.");
|
||||
}
|
||||
settings.put(key, value);
|
||||
MinecraftForge.EVENT_BUS.post(new SettingsChangedEvent(this, key));
|
||||
FMLCommonHandler.instance().bus().post(new SettingsChangedEvent(this, key));
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.replaymod.core.events;
|
||||
|
||||
import com.replaymod.core.SettingsRegistry;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SettingsChangedEvent extends Event {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.replaymod.core.gui;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import cpw.mods.fml.client.IModGuiFactory;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraftforge.fml.client.IModGuiFactory;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.replaymod.core.handler;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Moves certain buttons on the main menu upwards so we can inject our own.
|
||||
@@ -16,12 +18,14 @@ public class MainMenuHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onInit(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
if (event.getGui() instanceof GuiMainMenu) {
|
||||
for (GuiButton button : event.getButtonList()) {
|
||||
if (event.gui instanceof GuiMainMenu) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GuiButton> buttonList = event.buttonList;
|
||||
for (GuiButton button : buttonList) {
|
||||
// Buttons that aren't in a rectangle directly above our space don't need moving
|
||||
if (button.xPosition + button.width < event.getGui().width / 2 - 100
|
||||
|| button.xPosition > event.getGui().width / 2 + 100
|
||||
|| button.yPosition > event.getGui().height / 4 + 10 + 4 * 24) continue;
|
||||
if (button.xPosition + button.width < event.gui.width / 2 - 100
|
||||
|| button.xPosition > event.gui.width / 2 + 100
|
||||
|| button.yPosition > event.gui.height / 4 + 10 + 4 * 24) continue;
|
||||
// Move button up to make space for two rows of buttons
|
||||
// and then move back down by 10 to compensate for the space to the exit button that was already there
|
||||
button.yPosition -= 2 * 24 - 10;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import com.replaymod.replaystudio.data.ModInfo;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
@@ -17,14 +16,19 @@ public class ModCompat {
|
||||
Map<String, ModContainer> ignoreCaseMap = Loader.instance().getModList().stream()
|
||||
.collect(Collectors.toMap(m -> m.getModId().toLowerCase(), Function.identity()));
|
||||
return Stream.concat(
|
||||
((Set<ResourceLocation>) GameData.getBlockRegistry().getKeys()).stream(),
|
||||
((Set<ResourceLocation>) GameData.getItemRegistry().getKeys()).stream()
|
||||
).map(ResourceLocation::getResourceDomain).filter(s -> !s.equals("minecraft")).distinct()
|
||||
((Set<String>) GameData.getBlockRegistry().getKeys()).stream(),
|
||||
((Set<String>) GameData.getItemRegistry().getKeys()).stream()
|
||||
).map(ModCompat::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());
|
||||
}
|
||||
|
||||
private static String getResourceDomain(String name) {
|
||||
if (!name.contains(":")) return null; // Still using old names without namespace, can't do anything, ignore
|
||||
return name.split(":", 2)[0];
|
||||
}
|
||||
|
||||
public static final class ModInfoDifference {
|
||||
private final Set<ModInfo> missing = new HashSet<>();
|
||||
private final Map<ModInfo, String> differing = new HashMap<>();
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -29,22 +26,21 @@ public class OpenGLUtils {
|
||||
}
|
||||
|
||||
public static void drawRotatedRectWithCustomSizedTexture(int x, int y, float rotation, float u, float v, int width, int height, float textureWidth, float textureHeight) {
|
||||
GlStateManager.pushMatrix();
|
||||
GL11.glPushMatrix();
|
||||
|
||||
float f4 = 1.0F / textureWidth;
|
||||
float f5 = 1.0F / textureHeight;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
VertexBuffer vertexBuffer = tessellator.getBuffer();
|
||||
GlStateManager.translate(x+(width/2), y+(width/2), 0);
|
||||
GlStateManager.rotate(rotation, 0, 0, 1);
|
||||
vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
|
||||
vertexBuffer.pos(-width / 2, height / 2, 0.0D).tex((double) (u * f4), (double) ((v + (float) height) * f5)).endVertex();
|
||||
vertexBuffer.pos(width/2, height/2, 0.0D).tex((double)((u + (float)width) * f4), (double)((v + (float)height) * f5)).endVertex();
|
||||
vertexBuffer.pos(width/2, -height/2, 0.0D).tex((double)((u + (float)width) * f4), (double)(v * f5)).endVertex();
|
||||
vertexBuffer.pos(-width/2, -height/2, 0.0D).tex((double)(u * f4), (double)(v * f5)).endVertex();
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
GL11.glTranslatef(x+(width/2), y+(width/2), 0);
|
||||
GL11.glRotatef(rotation, 0, 0, 1);
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV(-width / 2, height / 2, 0.0D, (double) (u * f4), (double) ((v + (float) height) * f5));
|
||||
tessellator.addVertexWithUV(width/2, height/2, 0.0D, (double)((u + (float)width) * f4), (double)((v + (float)height) * f5));
|
||||
tessellator.addVertexWithUV(width/2, -height/2, 0.0D, (double)((u + (float)width) * f4), (double)(v * f5));
|
||||
tessellator.addVertexWithUV(-width/2, -height/2, 0.0D, (double)(u * f4), (double)(v * f5));
|
||||
tessellator.draw();
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.server.SPacketCustomPayload;
|
||||
import net.minecraft.network.play.server.S3FPacketCustomPayload;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Restrictions set by the server,
|
||||
@@ -14,8 +17,8 @@ public class Restrictions {
|
||||
private boolean onlyFirstPerson;
|
||||
private boolean onlyRecordingPlayer;
|
||||
|
||||
public String handle(SPacketCustomPayload packet) {
|
||||
PacketBuffer buffer = packet.getBufferData();
|
||||
public String handle(S3FPacketCustomPayload packet) throws IOException {
|
||||
PacketBuffer buffer = new PacketBuffer(Unpooled.wrappedBuffer(packet.func_149168_d()));
|
||||
while (buffer.isReadable()) {
|
||||
String name = buffer.readStringFromBuffer(64);
|
||||
boolean active = buffer.readBoolean();
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import com.google.common.net.PercentEscaper;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScrollable;
|
||||
@@ -15,16 +17,21 @@ 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 lombok.SneakyThrows;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
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;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.net.ssl.SSLContext;
|
||||
@@ -34,6 +41,8 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
@@ -45,6 +54,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.minecraft.client.Minecraft.getMinecraft;
|
||||
|
||||
@@ -134,21 +144,48 @@ public class Utils {
|
||||
return mail.matches("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$");
|
||||
}
|
||||
|
||||
public static ResourceLocation getResourceLocationForPlayerUUID(UUID uuid) {
|
||||
NetworkPlayerInfo info = getMinecraft().getConnection().getPlayerInfo(uuid);
|
||||
ResourceLocation skinLocation;
|
||||
if (info != null && info.hasLocationSkin()) {
|
||||
skinLocation = info.getLocationSkin();
|
||||
} else {
|
||||
skinLocation = DefaultPlayerSkin.getDefaultSkin(uuid);
|
||||
private static final PercentEscaper REPLAY_NAME_ENCODER = new PercentEscaper(".-_ ", false);
|
||||
|
||||
public static String replayNameToFileName(String replayName) {
|
||||
return REPLAY_NAME_ENCODER.escape(replayName) + ".mcpr";
|
||||
}
|
||||
|
||||
@SneakyThrows(UnsupportedEncodingException.class)
|
||||
public static String fileNameToReplayName(String fileName) {
|
||||
String baseName = FilenameUtils.getBaseName(fileName);
|
||||
try {
|
||||
return URLDecoder.decode(baseName, Charsets.UTF_8.name());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return baseName;
|
||||
}
|
||||
return skinLocation;
|
||||
}
|
||||
|
||||
public static ResourceLocation getResourceLocationForPlayerUUID(UUID uuid) {
|
||||
EntityPlayer player = Minecraft.getMinecraft().theWorld.getPlayerEntityByUUID(uuid);
|
||||
if (player == null || !(player instanceof AbstractClientPlayer)) {
|
||||
return AbstractClientPlayer.locationStevePng;
|
||||
}
|
||||
return ((AbstractClientPlayer) player).getLocationSkin();
|
||||
}
|
||||
|
||||
public static boolean isCtrlDown() {
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
|
||||
}
|
||||
|
||||
public static <T> void addCallback(ListenableFuture<T> future, Consumer<T> onSuccess, Consumer<Throwable> onFailure) {
|
||||
Futures.addCallback(future, new FutureCallback<T>() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable T result) {
|
||||
onSuccess.accept(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nonnull Throwable t) {
|
||||
onFailure.accept(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GuiInfoPopup error(Logger logger, GuiContainer container, CrashReport crashReport, Runnable onClose) {
|
||||
// Convert crash report to string
|
||||
String crashReportStr = crashReport.getCompleteReport();
|
||||
|
||||
@@ -27,7 +27,7 @@ public class WrappedTimer extends Timer {
|
||||
to.elapsedPartialTicks = from.elapsedPartialTicks;
|
||||
to.lastSyncSysClock = from.lastSyncSysClock;
|
||||
to.lastSyncHRClock = from.lastSyncHRClock;
|
||||
to.counter = from.counter;
|
||||
to.field_74285_i = from.field_74285_i;
|
||||
to.timeSyncAdjustment = from.timeSyncAdjustment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@ package com.replaymod.editor;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.editor.handler.GuiHandler;
|
||||
import com.replaymod.online.Setting;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = ReplayModEditor.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
acceptableRemoteVersions = "*",
|
||||
useMetadata = true)
|
||||
public class ReplayModEditor {
|
||||
public static final String MOD_ID = "replaymod-editor";
|
||||
|
||||
@@ -36,7 +36,6 @@ import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -59,6 +58,9 @@ public class GuiReplayEditor extends GuiScreen {
|
||||
public GuiButton currentTabButton;
|
||||
public GuiPanel currentTabPanel;
|
||||
|
||||
public final GuiLabel warningLabel = new GuiLabel(this).setColor(Colors.RED)
|
||||
.setI18nText("replaymod.gui.editor.disclaimer");
|
||||
|
||||
public final GuiPanel tabButtons = new GuiPanel(this).setLayout(new GridLayout().setSpacingX(5));
|
||||
public final List<GuiPanel> tabPanels = new ArrayList<>();
|
||||
|
||||
@@ -84,15 +86,18 @@ public class GuiReplayEditor extends GuiScreen {
|
||||
// Move all inactive panels aside
|
||||
tabPanels.forEach(e -> pos(e, Integer.MIN_VALUE, Integer.MIN_VALUE));
|
||||
|
||||
pos(warningLabel, 10, 22);
|
||||
size(warningLabel, width - 20, 10);
|
||||
|
||||
pos(tabButtons, 10, y(warningLabel) + height(warningLabel) + 2);
|
||||
size(tabButtons, width - 20, 20);
|
||||
|
||||
pos(buttonPanel, width - 10 - width(buttonPanel), height - 10 - height(buttonPanel));
|
||||
|
||||
if (currentTabPanel != null) {
|
||||
pos(currentTabPanel, 10, 50);
|
||||
pos(currentTabPanel, 10, y(tabButtons) + height(tabButtons) + 10);
|
||||
size(currentTabPanel, width - 20, y(buttonPanel) - 10 - y(currentTabPanel));
|
||||
}
|
||||
|
||||
pos(tabButtons, 10, 20);
|
||||
size(tabButtons, width - 20, 20);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -119,7 +124,7 @@ public class GuiReplayEditor extends GuiScreen {
|
||||
}
|
||||
|
||||
public void save(File inputFile, PacketStream.FilterInfo...filters) {
|
||||
save(FilenameUtils.getBaseName(inputFile.getName()), (outputFile) -> {
|
||||
save(Utils.fileNameToReplayName(inputFile.getName()), (outputFile) -> {
|
||||
Studio studio = new ReplayStudio();
|
||||
File tmpDir = null;
|
||||
try {
|
||||
@@ -214,7 +219,7 @@ public class GuiReplayEditor extends GuiScreen {
|
||||
Utils.error(LOGGER, GuiReplayEditor.this, CrashReport.makeCrashReport(e, "Getting replay folder"), null);
|
||||
return;
|
||||
}
|
||||
File targetFile = new File(replayFolder, name + ".mcpr");
|
||||
File targetFile = new File(replayFolder, Utils.replayNameToFileName(name));
|
||||
if (targetFile.exists()) {
|
||||
LOGGER.trace("Selected file already exists, asking for confirmation");
|
||||
Futures.addCallback(GuiYesNoPopup.open(GuiReplayEditor.this,
|
||||
|
||||
@@ -20,7 +20,6 @@ import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOCase;
|
||||
import org.apache.commons.io.filefilter.SuffixFileFilter;
|
||||
import org.lwjgl.util.Dimension;
|
||||
@@ -52,7 +51,7 @@ public class GuiTrimPanel extends GuiPanel {
|
||||
|
||||
public final GuiDropdownMenu<File> inputReplays = new GuiDropdownMenu<File>(this)
|
||||
.setMinSize(new Dimension(200, 20)).onSelection(i -> updateSelectedReplay())
|
||||
.setToString(f -> f == NO_REPLAY ? "" : FilenameUtils.getBaseName(f.getName()));
|
||||
.setToString(f -> f == NO_REPLAY ? "" : Utils.fileNameToReplayName(f.getName()));
|
||||
|
||||
public final GuiNumberField startHour = newGuiNumberField();
|
||||
public final GuiNumberField startMin = newGuiNumberField();
|
||||
|
||||
@@ -2,13 +2,16 @@ package com.replaymod.editor.handler;
|
||||
|
||||
import com.replaymod.editor.ReplayModEditor;
|
||||
import com.replaymod.editor.gui.GuiReplayEditor;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GuiHandler {
|
||||
private static final int BUTTON_REPLAY_EDITOR = 17890237;
|
||||
@@ -20,28 +23,31 @@ public class GuiHandler {
|
||||
}
|
||||
|
||||
public void register() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void injectIntoMainMenu(GuiScreenEvent.InitGuiEvent event) {
|
||||
if (!(event.getGui() instanceof GuiMainMenu)) {
|
||||
if (!(event.gui instanceof GuiMainMenu)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GuiButton button = new GuiButton(BUTTON_REPLAY_EDITOR, event.getGui().width / 2 + 2,
|
||||
event.getGui().height / 4 + 10 + 3 * 24, I18n.format("replaymod.gui.replayeditor"));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GuiButton> buttonList = event.buttonList;
|
||||
GuiButton button = new GuiButton(BUTTON_REPLAY_EDITOR, event.gui.width / 2 + 2,
|
||||
event.gui.height / 4 + 10 + 3 * 24, I18n.format("replaymod.gui.replayeditor"));
|
||||
button.width = button.width / 2 - 2;
|
||||
event.getButtonList().add(button);
|
||||
buttonList.add(button);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onButton(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
if(!event.getButton().enabled) return;
|
||||
if(!event.button.enabled) return;
|
||||
|
||||
if (event.getGui() instanceof GuiMainMenu) {
|
||||
if (event.getButton().id == BUTTON_REPLAY_EDITOR) {
|
||||
new GuiReplayEditor(GuiScreen.wrap(event.getGui()), mod.getCore()).display();
|
||||
if (event.gui instanceof GuiMainMenu) {
|
||||
if (event.button.id == BUTTON_REPLAY_EDITOR) {
|
||||
new GuiReplayEditor(GuiScreen.wrap(event.gui), mod.getCore()).display();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replay.events.ReplayOpenEvent;
|
||||
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.IGuiImage;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class FullBrightness implements Extra {
|
||||
@@ -40,7 +40,7 @@ public class FullBrightness implements Extra {
|
||||
}
|
||||
});
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.replaymod.core.KeyBindingRegistry;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.replay.events.ReplayOpenEvent;
|
||||
import com.replaymod.replay.gui.overlay.GuiReplayOverlay;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
@@ -17,8 +19,6 @@ import de.johni0702.minecraft.gui.layout.GridLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.LayoutData;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
@@ -35,7 +35,7 @@ public class HotkeyButtons implements Extra {
|
||||
public void register(ReplayMod mod) throws Exception {
|
||||
this.mod = mod;
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,106 +1,110 @@
|
||||
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.client.resources.data.IMetadataSerializer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
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.ConnectException;
|
||||
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 ReplayModOnline module;
|
||||
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 {
|
||||
this.module = ReplayModOnline.instance;
|
||||
|
||||
final Minecraft mc = mod.getMinecraft();
|
||||
Thread localizedResourcePackLoader = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
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(module.getApiClient()));
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mc.refreshResources();
|
||||
}
|
||||
});
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public static class LocalizedResourcePack implements IResourcePack {
|
||||
private final ApiClient apiClient;
|
||||
private Map<String, String> availableLanguages = new HashMap<>();
|
||||
private boolean websiteAvailable = true;
|
||||
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(!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));
|
||||
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) {
|
||||
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;
|
||||
// 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("minecraft", "replaymod");
|
||||
public Set getResourceDomains() {
|
||||
return ImmutableSet.of("replaymod");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IMetadataSection> T getPackMetadata(MetadataSerializer metadataSerializer, String metadataSectionName) throws IOException {
|
||||
public IMetadataSection getPackMetadata(IMetadataSerializer p_135058_1_, String p_135058_2_) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.replaymod.extras;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.Setting;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
@@ -14,7 +15,6 @@ import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
@@ -43,7 +43,7 @@ public class OpenEyeExtra implements Extra {
|
||||
}
|
||||
}
|
||||
|
||||
private class OfferGui extends AbstractGuiScreen<OfferGui> {
|
||||
public class OfferGui extends AbstractGuiScreen<OfferGui> {
|
||||
public final GuiScreen parent;
|
||||
public final GuiPanel textPanel = new GuiPanel().setLayout(new VerticalLayout().setSpacing(3))
|
||||
.addElements(new VerticalLayout.Data(0.5),
|
||||
@@ -69,7 +69,7 @@ public class OpenEyeExtra implements Extra {
|
||||
GuiPopup popup = new GuiPopup(OfferGui.this);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
File targetFile = new File("mods/" + Loader.MC_VERSION, "OpenEye.jar");
|
||||
File targetFile = new File(mod.getMinecraft().mcDataDir, "mods/" + Loader.MC_VERSION + "/OpenEye.jar");
|
||||
FileUtils.forceMkdir(targetFile.getParentFile());
|
||||
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(DOWNLOAD_URL).openConnection();
|
||||
@@ -107,7 +107,7 @@ public class OpenEyeExtra implements Extra {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GuiPopup extends AbstractGuiPopup<GuiPopup> {
|
||||
public static final class GuiPopup extends AbstractGuiPopup<GuiPopup> {
|
||||
GuiPopup(GuiContainer container) {
|
||||
super(container);
|
||||
popup.addElements(null, new GuiIndicator().setColor(Colors.BLACK));
|
||||
|
||||
@@ -4,17 +4,21 @@ import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.extras.playeroverview.PlayerOverview;
|
||||
import com.replaymod.extras.urischeme.UriSchemeExtra;
|
||||
import com.replaymod.extras.youtube.YoutubeUpload;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mod(modid = ReplayModExtras.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
acceptableRemoteVersions = "*",
|
||||
useMetadata = true)
|
||||
public class ReplayModExtras {
|
||||
public static final String MOD_ID = "replaymod-extras";
|
||||
@@ -32,11 +36,13 @@ public class ReplayModExtras {
|
||||
OpenEyeExtra.class
|
||||
);
|
||||
|
||||
private Logger logger;
|
||||
private final Map<Class<? extends Extra>, Extra> instances = new HashMap<>();
|
||||
|
||||
public static Logger LOGGER;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
LOGGER = event.getModLog();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@@ -45,9 +51,14 @@ public class ReplayModExtras {
|
||||
try {
|
||||
Extra extra = cls.newInstance();
|
||||
extra.register(ReplayMod.instance);
|
||||
instances.put(cls, extra);
|
||||
} catch (Throwable t) {
|
||||
logger.warn("Failed to load extra " + cls.getName() + ": ", t);
|
||||
LOGGER.warn("Failed to load extra " + cls.getName() + ": ", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Extra> Optional<T> get(Class<T> cls) {
|
||||
return Optional.ofNullable(instances.get(cls)).map(cls::cast);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.replaymod.extras.playeroverview;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.extras.Extra;
|
||||
@@ -9,17 +8,23 @@ import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replay.camera.CameraEntity;
|
||||
import com.replaymod.replay.events.ReplayCloseEvent;
|
||||
import com.replaymod.replay.events.ReplayOpenEvent;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlayerOverview implements Extra {
|
||||
private ReplayModReplay module;
|
||||
@@ -36,12 +41,10 @@ public class PlayerOverview implements Extra {
|
||||
public void run() {
|
||||
if (module.getReplayHandler() != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityPlayer> players = mod.getMinecraft().theWorld.getPlayers(EntityPlayer.class, new Predicate() {
|
||||
@Override
|
||||
public boolean apply(Object input) {
|
||||
return !(input instanceof CameraEntity); // Exclude the camera entity
|
||||
}
|
||||
});
|
||||
List<EntityPlayer> players = mod.getMinecraft().theWorld.playerEntities;
|
||||
players = players.stream()
|
||||
.filter(it -> !(it instanceof CameraEntity)) // Exclude the camera entity
|
||||
.collect(Collectors.toList());
|
||||
if (!Utils.isCtrlDown()) {
|
||||
// Hide all players that have an UUID v2 (commonly used for NPCs)
|
||||
Iterator<EntityPlayer> iter = players.iterator();
|
||||
@@ -57,13 +60,8 @@ public class PlayerOverview implements Extra {
|
||||
}
|
||||
});
|
||||
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
RenderManager renderManager = mod.getMinecraft().getRenderManager();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, RenderPlayer> skinMap = renderManager.skinMap;
|
||||
skinMap.put("default", new PlayerRenderHook(this, renderManager, false));
|
||||
skinMap.put("slim", new PlayerRenderHook(this, renderManager, true));
|
||||
}
|
||||
|
||||
public boolean isHidden(UUID uuid) {
|
||||
@@ -96,12 +94,19 @@ public class PlayerOverview implements Extra {
|
||||
|
||||
@SubscribeEvent
|
||||
public void oRenderHand(RenderHandEvent event) {
|
||||
Entity view = module.getCore().getMinecraft().getRenderViewEntity();
|
||||
Entity view = module.getCore().getMinecraft().renderViewEntity;
|
||||
if (view != null && isHidden(view.getUniqueID())) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void preRenderPlayer(RenderPlayerEvent.Pre event) {
|
||||
if (isHidden(event.entityPlayer.getUniqueID())) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSavingEnabled() {
|
||||
return savingEnabled;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,15 @@ import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.*;
|
||||
import de.johni0702.minecraft.gui.container.GuiClickable;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiVerticalList;
|
||||
import de.johni0702.minecraft.gui.element.GuiCheckbox;
|
||||
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.IGuiCheckbox;
|
||||
import de.johni0702.minecraft.gui.function.Closeable;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
@@ -15,9 +20,7 @@ import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EnumPlayerModelParts;
|
||||
import net.minecraft.init.MobEffects;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
@@ -37,21 +40,22 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||
public final GuiVerticalList playersScrollable = new GuiVerticalList(contentPanel)
|
||||
.setDrawSlider(true).setDrawShadow(true);
|
||||
public final GuiCheckbox saveCheckbox = new GuiCheckbox(contentPanel)
|
||||
.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.remembersettings.description"))
|
||||
.setI18nLabel("replaymod.gui.playeroverview.remembersettings");
|
||||
public final GuiCheckbox checkAll = new GuiCheckbox(contentPanel){
|
||||
@Override
|
||||
public void onClick() {
|
||||
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
||||
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.createPositionedSoundRecord(BUTTON_SOUND, 1.0F));
|
||||
playersScrollable.forEach(IGuiCheckbox.class).setChecked(true);
|
||||
}
|
||||
}.setLabel("").setChecked(true);
|
||||
}.setLabel("").setChecked(true).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.showall"));
|
||||
public final GuiCheckbox uncheckAll = new GuiCheckbox(contentPanel){
|
||||
@Override
|
||||
public void onClick() {
|
||||
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
|
||||
getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.createPositionedSoundRecord(BUTTON_SOUND, 1.0F));
|
||||
playersScrollable.forEach(IGuiCheckbox.class).setChecked(false);
|
||||
}
|
||||
}.setLabel("").setChecked(false);
|
||||
}.setLabel("").setChecked(false).setTooltip(new GuiTooltip().setI18nText("replaymod.gui.playeroverview.hideall"));
|
||||
|
||||
{
|
||||
setBackground(Background.NONE);
|
||||
@@ -91,12 +95,10 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
|
||||
renderer.bindTexture(texture);
|
||||
renderer.drawTexturedRect(0, 0, 8, 8, 16, 16, 8, 8, 64, 64);
|
||||
if (p.isWearing(EnumPlayerModelParts.HAT)) {
|
||||
renderer.drawTexturedRect(0, 0, 40, 8, size.getWidth(), size.getHeight(), 8, 8, 64, 64);
|
||||
}
|
||||
renderer.drawTexturedRect(0, 0, 40, 8, size.getWidth(), size.getHeight(), 8, 8, 64, 64);
|
||||
}
|
||||
}.setSize(16, 16),
|
||||
new GuiLabel().setText(p.getName()).setColor(isSpectator(p) ? Colors.DKGREY : Colors.WHITE)
|
||||
new GuiLabel().setText(p.getDisplayName()).setColor(isSpectator(p) ? Colors.DKGREY : Colors.WHITE)
|
||||
).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -140,7 +142,7 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||
}
|
||||
|
||||
private static boolean isSpectator(EntityPlayer e) {
|
||||
return e.isInvisible() && e.getActivePotionEffect(MobEffects.INVISIBILITY) == null;
|
||||
return e.isInvisible() && e.getActivePotionEffect(Potion.invisibility) == null;
|
||||
}
|
||||
|
||||
private static final class PlayerComparator implements Comparator<EntityPlayer> {
|
||||
@@ -148,7 +150,7 @@ public class PlayerOverviewGui extends GuiScreen implements Closeable {
|
||||
public int compare(EntityPlayer o1, EntityPlayer o2) {
|
||||
if (isSpectator(o1) && !isSpectator(o2)) return 1;
|
||||
if (isSpectator(o2) && !isSpectator(o1)) return -1;
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.replaymod.extras.playeroverview;
|
||||
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.culling.ICamera;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
|
||||
public class PlayerRenderHook extends RenderPlayer {
|
||||
private final PlayerOverview extra;
|
||||
|
||||
public PlayerRenderHook(PlayerOverview extra, RenderManager renderManager, boolean useSmallArms) {
|
||||
super(renderManager, useSmallArms);
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(AbstractClientPlayer entity, ICamera camera, double camX, double camY, double camZ) {
|
||||
return !extra.isHidden(entity.getUniqueID()) && super.shouldRender(entity, camera, camX, camY, camZ);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.replaymod.extras.playeroverview.mixin;
|
||||
|
||||
import com.replaymod.extras.ReplayModExtras;
|
||||
import com.replaymod.extras.playeroverview.PlayerOverview;
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.renderer.entity.RenderPlayer;
|
||||
import net.minecraft.client.renderer.entity.RendererLivingEntity;
|
||||
import net.minecraft.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This mixin prevents players that are hidden in the PlayerOverview from being rendered.
|
||||
*
|
||||
* Cancelling the RenderPlayerEvent.Pre is insufficient because it affects neither the shadows nor the fire texture.
|
||||
* See: https://github.com/MinecraftForge/MinecraftForge/issues/2987
|
||||
*
|
||||
* The previous solution was to overwrite the RenderPlayer instances which has been dropped in favor of this one
|
||||
* because it is less compatible with other mods whereas this one should be fine as long as no other mod completely
|
||||
* overwrites the methods we modify in this mixin.
|
||||
* One example of the previous solution breaking is when used with VanillaEnhancements because it replaces the
|
||||
* RenderManager with a new custom one which in turn will reset our registered RenderPlayer instances because
|
||||
* it does so after we have already registered with the old RenderManager.
|
||||
*/
|
||||
@Mixin(value = RenderPlayer.class, priority = 1200)
|
||||
public abstract class MixinRenderPlayer extends RendererLivingEntity {
|
||||
public MixinRenderPlayer(ModelBase p_i1261_1_, float p_i1261_2_) {
|
||||
super(p_i1261_1_, p_i1261_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRenderShadowAndFire(Entity entity, double d1, double d2, double d3, float f1, float f2) {
|
||||
UUID uuid = entity.getUniqueID();
|
||||
if (!ReplayModExtras.instance.get(PlayerOverview.class).map(po -> po.isHidden(uuid)).orElse(false)) {
|
||||
super.doRenderShadowAndFire(entity, d1, d2, d3, f1, f2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public class LinuxUriScheme extends UriScheme {
|
||||
"Icon=" + iconFile.getAbsolutePath().replace("\\", "\\\\").replace("\"", "\\\"") + "\n" +
|
||||
"Type=Application\n" +
|
||||
"Terminal=false\n" +
|
||||
"NoDisplay=true\n" +
|
||||
"MimeType=x-scheme-handler/replaymod;";
|
||||
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
|
||||
@@ -3,11 +3,11 @@ package com.replaymod.extras.youtube;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.extras.Extra;
|
||||
import com.replaymod.render.gui.GuiRenderingDone;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class YoutubeUpload implements Extra {
|
||||
@Override
|
||||
@@ -17,8 +17,8 @@ public class YoutubeUpload implements Extra {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGuiOpen(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
if (GuiScreen.from(event.getGui()) instanceof GuiRenderingDone) {
|
||||
GuiRenderingDone gui = (GuiRenderingDone) GuiScreen.from(event.getGui());
|
||||
if (GuiScreen.from(event.gui) instanceof GuiRenderingDone) {
|
||||
GuiRenderingDone gui = (GuiRenderingDone) GuiScreen.from(event.gui);
|
||||
// Check if there already is a youtube button
|
||||
if (gui.actionsPanel.getChildren().stream().anyMatch(it -> it instanceof YoutubeButton)) {
|
||||
return; // Button already added
|
||||
|
||||
@@ -36,6 +36,8 @@ import java.security.GeneralSecurityException;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static com.replaymod.extras.ReplayModExtras.LOGGER;
|
||||
|
||||
public class YoutubeUploader {
|
||||
private static final String CLIENT_ID = "743126594724-mfe7pj1k7e47uu5pk4503c8st9vj9ibu.apps.googleusercontent.com";
|
||||
private static final String CLIENT_SECRET = "gMwcy3mRYCRamCIjJIYP7rqc";
|
||||
@@ -137,7 +139,7 @@ public class YoutubeUploader {
|
||||
|
||||
CommandLine commandLine = new CommandLine(settings.getExportCommand());
|
||||
commandLine.addArguments(args);
|
||||
System.out.println("Re-encoding for ODS with " + settings.getExportCommand() + args);
|
||||
LOGGER.info("Re-encoding for ODS with {} {}", settings.getExportCommand(), args);
|
||||
Process process = new ProcessBuilder(commandLine.toStrings()).directory(videoFile.getParentFile()).start();
|
||||
|
||||
final AtomicBoolean active = new AtomicBoolean(true);
|
||||
@@ -149,7 +151,7 @@ public class YoutubeUploader {
|
||||
char c = (char) in.read();
|
||||
if (c == '\r') {
|
||||
String str = sb.toString();
|
||||
System.out.println(str);
|
||||
LOGGER.debug("[FFmpeg] {}", str);
|
||||
if (str.startsWith("frame=")) {
|
||||
str = str.substring(6).trim();
|
||||
str = str.substring(0, str.indexOf(' '));
|
||||
|
||||
@@ -11,14 +11,14 @@ import com.replaymod.replay.events.ReplayCloseEvent;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.replaystudio.replay.ZipReplayFile;
|
||||
import com.replaymod.replaystudio.studio.ReplayStudio;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
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.SubscribeEvent;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
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.SubscribeEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
@@ -29,6 +29,7 @@ import static net.minecraft.client.Minecraft.getMinecraft;
|
||||
@Mod(modid = ReplayModOnline.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
acceptableRemoteVersions = "*",
|
||||
useMetadata = true)
|
||||
public class ReplayModOnline {
|
||||
public static final String MOD_ID = "replaymod-online";
|
||||
@@ -40,7 +41,7 @@ public class ReplayModOnline {
|
||||
|
||||
private ReplayModReplay replayModule;
|
||||
|
||||
private Logger logger;
|
||||
public static Logger LOGGER;
|
||||
|
||||
private ApiClient apiClient;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class ReplayModOnline {
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
logger = event.getModLog();
|
||||
LOGGER = event.getModLog();
|
||||
core = ReplayMod.instance;
|
||||
replayModule = ReplayModReplay.instance;
|
||||
|
||||
@@ -69,12 +70,12 @@ public class ReplayModOnline {
|
||||
public void init(FMLInitializationEvent event) {
|
||||
if (!getDownloadsFolder().exists()){
|
||||
if (!getDownloadsFolder().mkdirs()) {
|
||||
logger.warn("Failed to create downloads folder: " + getDownloadsFolder());
|
||||
LOGGER.warn("Failed to create downloads folder: " + getDownloadsFolder());
|
||||
}
|
||||
}
|
||||
|
||||
new GuiHandler(this).register();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@@ -82,7 +83,10 @@ public class ReplayModOnline {
|
||||
// Initial login prompt
|
||||
if (!core.getSettingsRegistry().get(Setting.SKIP_LOGIN_PROMPT)) {
|
||||
if (!isLoggedIn()) {
|
||||
new GuiLoginPrompt(apiClient, null, null, false).display();
|
||||
core.runLater(() -> {
|
||||
GuiScreen parent = GuiScreen.wrap(getMinecraft().currentScreen);
|
||||
new GuiLoginPrompt(apiClient, parent, parent, false).display();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +100,7 @@ public class ReplayModOnline {
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
return LOGGER;
|
||||
}
|
||||
|
||||
public ApiClient getApiClient() {
|
||||
|
||||
@@ -2,8 +2,7 @@ package com.replaymod.online.api.replay.holders;
|
||||
|
||||
public enum MinecraftVersion {
|
||||
|
||||
MC_1_8("Minecraft 1.8", "1.8"),
|
||||
MC_1_9_4("Minecraft 1.9.4", "1.9.4");
|
||||
MC_1_8("Minecraft 1.8", "1.8");
|
||||
|
||||
private String niceName, apiName;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class GuiLoginPrompt extends AbstractGuiScreen<GuiLoginPrompt> {
|
||||
private GuiLabel noAccountLabel = new GuiLabel(this).setI18nText("replaymod.gui.login.noacc");
|
||||
private GuiLabel statusLabel = new GuiLabel(this);
|
||||
private GuiButton loginButton = new GuiButton(this).setI18nLabel("replaymod.gui.login").setSize(150, 20).setEnabled(false);
|
||||
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setSize(150, 20);
|
||||
public GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setSize(150, 20);
|
||||
private GuiButton registerButton = new GuiButton(this).setI18nLabel("replaymod.gui.register").setSize(150, 20);
|
||||
private GuiTextField username = new GuiTextField(this).setSize(145, 20).setMaxLength(16).setFocused(true);
|
||||
private GuiPasswordField password = new GuiPasswordField(this).setSize(145, 20)
|
||||
|
||||
@@ -28,6 +28,7 @@ import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.IGuiButton;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiResourceLoadingList;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
@@ -36,8 +37,6 @@ import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import de.johni0702.minecraft.gui.utils.Consumer;
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.logging.log4j.core.helpers.Strings;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
@@ -50,6 +49,8 @@ import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.replaymod.online.ReplayModOnline.LOGGER;
|
||||
|
||||
public class GuiReplayCenter extends GuiScreen {
|
||||
private final ReplayModOnline mod;
|
||||
private final ApiClient apiClient;
|
||||
@@ -109,6 +110,7 @@ public class GuiReplayCenter extends GuiScreen {
|
||||
public void run() {
|
||||
GuiReplayEntry selected = list.getSelected();
|
||||
replayButtonPanel.forEach(IGuiButton.class).setEnabled(selected != null);
|
||||
replayButtonPanel.forEach(IGuiButton.class).setTooltip(null);
|
||||
if (selected != null) {
|
||||
int replayId = selected.fileInfo.getId();
|
||||
boolean favorited = favoritedReplays.contains(replayId);
|
||||
@@ -123,10 +125,22 @@ public class GuiReplayCenter extends GuiScreen {
|
||||
favoriteButton.setI18nLabel("replaymod.gui.center." + (favorited ? "unfavorite" : "favorite"));
|
||||
// Only allow button usage for either unfavorite or favorite after they've actually downloaded it
|
||||
favoriteButton.setEnabled(favorited || selected.downloaded);
|
||||
if (favoriteButton.isEnabled()) {
|
||||
favoriteButton.setTooltip(null);
|
||||
} else {
|
||||
favoriteButton.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.center.downloadrequired"));
|
||||
}
|
||||
|
||||
// Similar for like/dislike buttons
|
||||
likeButton.setEnabled(selected.downloaded);
|
||||
dislikeButton.setEnabled(selected.downloaded);
|
||||
if (likeButton.isEnabled()) {
|
||||
likeButton.setTooltip(null);
|
||||
dislikeButton.setTooltip(null);
|
||||
} else {
|
||||
likeButton.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.center.downloadrequired"));
|
||||
dislikeButton.setTooltip(new GuiTooltip().setI18nText("replaymod.gui.center.downloadrequired"));
|
||||
}
|
||||
likeButton.setI18nLabel("replaymod.gui." + (liked ? "removelike" : "like"));
|
||||
dislikeButton.setI18nLabel("replaymod.gui." + (disliked ? "removedislike" : "dislike"));
|
||||
}
|
||||
@@ -322,7 +336,7 @@ public class GuiReplayCenter extends GuiScreen {
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
FMLLog.getLogger().error("Could not load Replay File " + fileInfo.getId(), e);
|
||||
LOGGER.error("Could not load Replay File {}", fileInfo.getId(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -403,7 +417,7 @@ public class GuiReplayCenter extends GuiScreen {
|
||||
this.downloaded = downloaded;
|
||||
ReplayMetaData metaData = fileInfo.getMetadata();
|
||||
|
||||
name.setText(ChatFormatting.UNDERLINE + FilenameUtils.getBaseName(fileInfo.getName()));
|
||||
name.setText(ChatFormatting.UNDERLINE + Utils.fileNameToReplayName(fileInfo.getName()));
|
||||
author.setI18nText("replaymod.gui.center.author",
|
||||
"" + ChatFormatting.GRAY + ChatFormatting.ITALIC, fileInfo.getOwner());
|
||||
if (Strings.isEmpty(metaData.getServerName())) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.replaymod.online.gui;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
@@ -27,7 +28,7 @@ public class GuiSaveModifiedReplay extends GuiScreen {
|
||||
@Override
|
||||
public void run() {
|
||||
String resultName = name.getText().trim().replace("[^a-zA-Z0-9\\.\\- ]", "_");
|
||||
final File resultFile = new File(file.getParentFile(), resultName + ".mcpr");
|
||||
final File resultFile = new File(file.getParentFile(), Utils.replayNameToFileName(resultName));
|
||||
if (resultFile.exists()) {
|
||||
Futures.addCallback(GuiYesNoPopup.open(GuiSaveModifiedReplay.this,
|
||||
new GuiLabel().setI18nText("replaymod.gui.replaymodified.warning1", resultName).setColor(Colors.BLACK),
|
||||
|
||||
@@ -17,7 +17,12 @@ import com.replaymod.replaystudio.studio.ReplayStudio;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.*;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiCheckbox;
|
||||
import de.johni0702.minecraft.gui.element.GuiImage;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
import de.johni0702.minecraft.gui.element.GuiTooltip;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiDropdownMenu;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiTextArea;
|
||||
@@ -33,7 +38,6 @@ import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -130,7 +134,7 @@ public class GuiUploadReplay extends GuiScreen {
|
||||
}
|
||||
|
||||
// Apply to gui
|
||||
name.setText(FilenameUtils.getBaseName(file.getName()));
|
||||
name.setText(Utils.fileNameToReplayName(file.getName()));
|
||||
int secs = metaData.getDuration() / 1000;
|
||||
durationLabel.setI18nText("replaymod.gui.upload.duration", secs / 60, secs % 60);
|
||||
hideServerIP.setEnabled(!metaData.isSingleplayer());
|
||||
@@ -234,6 +238,8 @@ public class GuiUploadReplay extends GuiScreen {
|
||||
});
|
||||
|
||||
validateInputs();
|
||||
name.onTextChanged(s -> validateInputs());
|
||||
tags.onTextChanged(s -> validateInputs());
|
||||
}
|
||||
|
||||
public void validateInputs() {
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.replaymod.online.gui.GuiLoginPrompt;
|
||||
import com.replaymod.online.gui.GuiReplayCenter;
|
||||
import com.replaymod.online.gui.GuiUploadReplay;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
@@ -14,9 +16,9 @@ import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiHandler {
|
||||
private static final int BUTTON_REPLAY_CENTER = 17890236;
|
||||
@@ -28,23 +30,26 @@ public class GuiHandler {
|
||||
}
|
||||
|
||||
public void register() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void injectIntoMainMenu(GuiScreenEvent.InitGuiEvent event) {
|
||||
if (!(event.getGui() instanceof GuiMainMenu)) {
|
||||
if (!(event.gui instanceof GuiMainMenu)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GuiButton button = new GuiButton(BUTTON_REPLAY_CENTER, event.getGui().width / 2 - 100,
|
||||
event.getGui().height / 4 + 10 + 4 * 24, I18n.format("replaymod.gui.replaycenter"));
|
||||
event.getButtonList().add(button);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GuiButton> buttonList = event.buttonList;
|
||||
GuiButton button = new GuiButton(BUTTON_REPLAY_CENTER, event.gui.width / 2 - 100,
|
||||
event.gui.height / 4 + 10 + 4 * 24, I18n.format("replaymod.gui.replaycenter"));
|
||||
buttonList.add(button);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void injectIntoReplayViewer(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
AbstractGuiScreen guiScreen = GuiScreen.from(event.getGui());
|
||||
AbstractGuiScreen guiScreen = GuiScreen.from(event.gui);
|
||||
if (!(guiScreen instanceof GuiReplayViewer)) {
|
||||
return;
|
||||
}
|
||||
@@ -70,15 +75,15 @@ public class GuiHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onButton(GuiScreenEvent.ActionPerformedEvent.Pre event) {
|
||||
if(!event.getButton().enabled) return;
|
||||
if(!event.button.enabled) return;
|
||||
|
||||
if (event.getGui() instanceof GuiMainMenu) {
|
||||
if (event.getButton().id == BUTTON_REPLAY_CENTER) {
|
||||
if (event.gui instanceof GuiMainMenu) {
|
||||
if (event.button.id == BUTTON_REPLAY_CENTER) {
|
||||
GuiReplayCenter replayCenter = new GuiReplayCenter(mod);
|
||||
if (mod.isLoggedIn()) {
|
||||
replayCenter.display();
|
||||
} else {
|
||||
new GuiLoginPrompt(mod.getApiClient(), GuiScreen.wrap(event.getGui()), replayCenter, true).display();
|
||||
new GuiLoginPrompt(mod.getApiClient(), GuiScreen.wrap(event.gui), replayCenter, true).display();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replaystudio.pathing.PathingRegistry;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
@@ -11,7 +12,11 @@ import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.*;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiClickableContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiVerticalList;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
@@ -41,9 +46,16 @@ public class GuiKeyframeRepository extends GuiScreen implements Closeable {
|
||||
public final GuiButton overwriteButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
timelines.put(selectedEntry.name, currentTimeline);
|
||||
overwriteButton.setDisabled();
|
||||
save();
|
||||
GuiYesNoPopup popup = GuiYesNoPopup.open(GuiKeyframeRepository.this,
|
||||
new GuiLabel().setI18nText("replaymod.gui.keyframerepo.overwrite").setColor(Colors.BLACK)
|
||||
).setYesI18nLabel("gui.yes").setNoI18nLabel("gui.no");
|
||||
Utils.addCallback(popup.getFuture(), doIt -> {
|
||||
if (doIt) {
|
||||
timelines.put(selectedEntry.name, currentTimeline);
|
||||
overwriteButton.setDisabled();
|
||||
save();
|
||||
}
|
||||
}, Throwable::printStackTrace);
|
||||
}
|
||||
}).setSize(75, 20).setI18nLabel("replaymod.gui.overwrite").setDisabled();
|
||||
public final GuiButton saveAsButton = new GuiButton(buttonPanel).onClick(new Runnable() {
|
||||
|
||||
@@ -10,9 +10,9 @@ import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replaystudio.pathing.path.Keyframe;
|
||||
import com.replaymod.replaystudio.pathing.path.Path;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
@@ -65,7 +65,7 @@ public abstract class AbstractTimelinePlayer {
|
||||
}
|
||||
|
||||
replayHandler.getReplaySender().setSyncModeAndWait();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
lastTime = 0;
|
||||
mc.timer = new ReplayTimer(mc.timer);
|
||||
mc.timer.timerSpeed = 1;
|
||||
@@ -87,7 +87,7 @@ public abstract class AbstractTimelinePlayer {
|
||||
mc.timer = ((ReplayTimer) mc.timer).getWrapped();
|
||||
replayHandler.getReplaySender().setReplaySpeed(0);
|
||||
replayHandler.getReplaySender().setAsyncMode(true);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
return;
|
||||
}
|
||||
long time = getTimePassed();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.replaymod.pathing.player;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
import com.replaymod.replaystudio.pathing.path.Timeline;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
/**
|
||||
* Timeline player using the system time.
|
||||
@@ -32,6 +33,7 @@ public class RealtimeTimelinePlayer extends AbstractTimelinePlayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SubscribeEvent // 1.7.10 doesn't yet deal properly with inherited, overridden event handlers
|
||||
public void onTick(ReplayTimer.UpdatedEvent event) {
|
||||
if (secondFrame) {
|
||||
secondFrame = false;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.replaymod.pathing.player;
|
||||
|
||||
import com.replaymod.core.utils.WrappedTimer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.util.Timer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
/**
|
||||
* Wrapper around the current timer that prevents the timer from advancing by itself.
|
||||
@@ -20,7 +20,7 @@ public class ReplayTimer extends WrappedTimer {
|
||||
copy(this, state); // Save our current state
|
||||
super.updateTimer(); // Update current state
|
||||
copy(state, this); // Restore our old state
|
||||
MinecraftForge.EVENT_BUS.post(new UpdatedEvent());
|
||||
FMLCommonHandler.instance().bus().post(new UpdatedEvent());
|
||||
}
|
||||
|
||||
public Timer getWrapped() {
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.replaymod.replaystudio.pathing.property.PropertyPart;
|
||||
import com.replaymod.replaystudio.pathing.property.PropertyParts;
|
||||
import lombok.NonNull;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -36,7 +37,9 @@ public class SpectatorProperty extends AbstractProperty<Integer> {
|
||||
// Lookup entity by id, returns null if an entity with the id does not exists
|
||||
Entity target = world.getEntityByID(value);
|
||||
// Spectate entity, when called with null, returns to camera
|
||||
handler.spectateEntity(target);
|
||||
if (target instanceof EntityLivingBase) {
|
||||
handler.spectateEntity((EntityLivingBase) target);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,19 +4,22 @@ import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.Restrictions;
|
||||
import com.replaymod.recording.handler.ConnectionEventHandler;
|
||||
import com.replaymod.recording.packet.PacketListener;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventBus;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@Mod(modid = ReplayModRecording.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
acceptableRemoteVersions = "*",
|
||||
useMetadata = true)
|
||||
public class ReplayModRecording {
|
||||
public static final String MOD_ID = "replaymod-recording";
|
||||
@@ -51,12 +54,15 @@ public class ReplayModRecording {
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
EventBus bus = MinecraftForge.EVENT_BUS;
|
||||
EventBus bus = FMLCommonHandler.instance().bus();
|
||||
bus.register(connectionEventHandler = new ConnectionEventHandler(logger, core));
|
||||
|
||||
NetworkRegistry.INSTANCE.newSimpleChannel(Restrictions.PLUGIN_CHANNEL);
|
||||
NetworkRegistry.INSTANCE.newChannel(Restrictions.PLUGIN_CHANNEL, new RestrictionsChannelHandler());
|
||||
}
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
private static class RestrictionsChannelHandler extends ChannelDuplexHandler {}
|
||||
|
||||
public void initiateRecording(NetworkManager networkManager) {
|
||||
connectionEventHandler.onConnectedToServerEvent(networkManager);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package com.replaymod.recording.gui;
|
||||
|
||||
import com.replaymod.core.SettingsRegistry;
|
||||
import com.replaymod.recording.Setting;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static com.replaymod.core.ReplayMod.TEXTURE;
|
||||
import static com.replaymod.core.ReplayMod.TEXTURE_SIZE;
|
||||
@@ -40,13 +40,12 @@ public class GuiRecordingOverlay {
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public void renderRecordingIndicator(RenderGameOverlayEvent.Post event) {
|
||||
if (event.getType() != RenderGameOverlayEvent.ElementType.ALL) return;
|
||||
if (event.type != RenderGameOverlayEvent.ElementType.ALL) return;
|
||||
if (settingsRegistry.get(Setting.INDICATOR)) {
|
||||
FontRenderer fontRenderer = mc.fontRendererObj;
|
||||
fontRenderer.drawString(I18n.format("replaymod.gui.recording").toUpperCase(), 30, 18 - (fontRenderer.FONT_HEIGHT / 2), 0xffffffff);
|
||||
mc.renderEngine.bindTexture(TEXTURE);
|
||||
GlStateManager.resetColor();
|
||||
GlStateManager.enableAlpha();
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
Gui.drawModalRectWithCustomSizedTexture(10, 10, 58, 20, 16, 16, TEXTURE_SIZE, TEXTURE_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.replaymod.recording.handler;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.utils.ModCompat;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.recording.Setting;
|
||||
import com.replaymod.recording.gui.GuiRecordingOverlay;
|
||||
import com.replaymod.recording.packet.PacketListener;
|
||||
@@ -9,11 +10,10 @@ import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.replaystudio.replay.ReplayMetaData;
|
||||
import com.replaymod.replaystudio.replay.ZipReplayFile;
|
||||
import com.replaymod.replaystudio.studio.ReplayStudio;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientDisconnectionFromServerEvent;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
@@ -46,10 +46,6 @@ public class ConnectionEventHandler {
|
||||
try {
|
||||
boolean local = networkManager.isLocalChannel();
|
||||
if (local) {
|
||||
if (mc.getIntegratedServer().getEntityWorld().getWorldType() == WorldType.DEBUG_WORLD) {
|
||||
logger.info("Debug World recording is not supported.");
|
||||
return;
|
||||
}
|
||||
if(!core.getSettingsRegistry().get(Setting.RECORD_SINGLEPLAYER)) {
|
||||
logger.info("Singleplayer Recording is disabled");
|
||||
return;
|
||||
@@ -74,7 +70,7 @@ public class ConnectionEventHandler {
|
||||
File folder = core.getReplayFolder();
|
||||
|
||||
String name = sdf.format(Calendar.getInstance().getTime());
|
||||
File currentFile = new File(folder, name + ".mcpr");
|
||||
File currentFile = new File(folder, Utils.replayNameToFileName(name));
|
||||
ReplayFile replayFile = new ZipReplayFile(new ReplayStudio(), currentFile);
|
||||
|
||||
replayFile.writeModInfo(ModCompat.getInstalledNetworkMods());
|
||||
@@ -95,14 +91,14 @@ public class ConnectionEventHandler {
|
||||
guiOverlay.register();
|
||||
|
||||
core.printInfoToChat("replaymod.chat.recordingstarted");
|
||||
} catch(Exception e) {
|
||||
} catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
core.printWarningToChat("replaymod.chat.recordingfailed");
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDisconnectedFromServerEvent(ClientDisconnectionFromServerEvent event) {
|
||||
public void onDisconnectedFromServerEvent(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) {
|
||||
if (packetListener != null) {
|
||||
guiOverlay.unregister();
|
||||
guiOverlay = null;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.replaymod.recording.handler;
|
||||
|
||||
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import net.minecraftforge.fml.common.network.handshake.FMLHandshakeMessage;
|
||||
|
||||
/**
|
||||
* Filters out all handshake packets that were sent for recording but must
|
||||
@@ -17,7 +17,7 @@ import net.minecraftforge.fml.common.network.handshake.FMLHandshakeMessage;
|
||||
public class FMLHandshakeFilter extends SimpleChannelInboundHandler<FMLHandshakeMessage> {
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, FMLHandshakeMessage msg) throws Exception {
|
||||
if (!(msg instanceof FMLHandshakeMessage.RegistryData)) {
|
||||
if (!(msg instanceof FMLHandshakeMessage.ModIdData)) {
|
||||
// Pass on everything but RegistryData messages
|
||||
ctx.fireChannelRead(msg);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
package com.replaymod.recording.handler;
|
||||
|
||||
import com.replaymod.recording.packet.PacketListener;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.datasync.EntityDataManager;
|
||||
import net.minecraft.network.play.server.*;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.server.S04PacketEntityEquipment;
|
||||
import net.minecraft.network.play.server.S0APacketUseBed;
|
||||
import net.minecraft.network.play.server.S0BPacketAnimation;
|
||||
import net.minecraft.network.play.server.S0CPacketSpawnPlayer;
|
||||
import net.minecraft.network.play.server.S0DPacketCollectItem;
|
||||
import net.minecraft.network.play.server.S12PacketEntityVelocity;
|
||||
import net.minecraft.network.play.server.S14PacketEntity.S17PacketEntityLookMove;
|
||||
import net.minecraft.network.play.server.S18PacketEntityTeleport;
|
||||
import net.minecraft.network.play.server.S19PacketEntityHeadLook;
|
||||
import net.minecraft.network.play.server.S1BPacketEntityAttach;
|
||||
import net.minecraft.network.play.server.S25PacketBlockBreakAnim;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.ItemPickupEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -30,24 +38,24 @@ public class RecordingEventHandler {
|
||||
private final PacketListener packetListener;
|
||||
|
||||
private Double lastX, lastY, lastZ;
|
||||
private ItemStack[] playerItems = new ItemStack[6];
|
||||
private ItemStack[] playerItems = new ItemStack[5];
|
||||
private int ticksSinceLastCorrection;
|
||||
private boolean wasSleeping;
|
||||
private int lastRiding = -1;
|
||||
private Integer rotationYawHeadBefore;
|
||||
private boolean wasHandActive;
|
||||
private EnumHand lastActiveHand;
|
||||
|
||||
public RecordingEventHandler(PacketListener packetListener) {
|
||||
this.packetListener = packetListener;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
((RecordingEventSender) mc.renderGlobal).setRecordingEventHandler(this);
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
RecordingEventSender recordingEventSender = ((RecordingEventSender) mc.renderGlobal);
|
||||
if (recordingEventSender.getRecordingEventHandler() == this) {
|
||||
@@ -57,7 +65,7 @@ public class RecordingEventHandler {
|
||||
|
||||
public void onPlayerJoin() {
|
||||
try {
|
||||
packetListener.save(new SPacketSpawnPlayer(mc.thePlayer));
|
||||
packetListener.save(spawnPlayer(mc.thePlayer));
|
||||
} catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
@@ -65,33 +73,18 @@ public class RecordingEventHandler {
|
||||
|
||||
public void onPlayerRespawn() {
|
||||
try {
|
||||
packetListener.save(new SPacketSpawnPlayer(mc.thePlayer));
|
||||
packetListener.save(spawnPlayer(mc.thePlayer));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void onClientSound(SoundEvent sound, SoundCategory category,
|
||||
double x, double y, double z, float volume, float pitch) {
|
||||
try {
|
||||
// Send to all other players in ServerWorldEventHandler#playSoundToAllNearExcept
|
||||
packetListener.save(new SPacketSoundEffect(sound, category, x, y, z, volume, pitch));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void onClientEffect(int type, BlockPos pos, int data) {
|
||||
try {
|
||||
// Send to all other players in ServerWorldEventHandler#playEvent
|
||||
packetListener.save(new SPacketEffect(type, pos, data, false));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
private S0CPacketSpawnPlayer spawnPlayer(EntityPlayer player) {
|
||||
return new S0CPacketSpawnPlayer(player);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(PlayerTickEvent e) {
|
||||
public void onPlayerTick(TickEvent.PlayerTickEvent e) {
|
||||
try {
|
||||
if(e.player != mc.thePlayer) return;
|
||||
|
||||
@@ -99,7 +92,7 @@ public class RecordingEventHandler {
|
||||
if(lastX == null || lastY == null || lastZ == null) {
|
||||
force = true;
|
||||
lastX = e.player.posX;
|
||||
lastY = e.player.posY;
|
||||
lastY = e.player.boundingBox.minY;
|
||||
lastZ = e.player.posZ;
|
||||
}
|
||||
|
||||
@@ -110,23 +103,28 @@ public class RecordingEventHandler {
|
||||
}
|
||||
|
||||
double dx = e.player.posX - lastX;
|
||||
double dy = e.player.posY - lastY;
|
||||
double dy = e.player.boundingBox.minY - lastY;
|
||||
double dz = e.player.posZ - lastZ;
|
||||
|
||||
lastX = e.player.posX;
|
||||
lastY = e.player.posY;
|
||||
lastY = e.player.boundingBox.minY;
|
||||
lastZ = e.player.posZ;
|
||||
|
||||
Packet packet;
|
||||
if (force || Math.abs(dx) > 8.0 || Math.abs(dy) > 8.0 || Math.abs(dz) > 8.0) {
|
||||
packet = new SPacketEntityTeleport(e.player);
|
||||
if(force || Math.abs(dx) > 4.0 || Math.abs(dy) > 4.0 || Math.abs(dz) > 4.0) {
|
||||
int x = MathHelper.floor_double(e.player.posX * 32.0D);
|
||||
int y = MathHelper.floor_double(e.player.boundingBox.minY * 32.0D);
|
||||
int z = MathHelper.floor_double(e.player.posZ * 32.0D);
|
||||
byte yaw = (byte) ((int) (e.player.rotationYaw * 256.0F / 360.0F));
|
||||
byte pitch = (byte) ((int) (e.player.rotationPitch * 256.0F / 360.0F));
|
||||
packet = new S18PacketEntityTeleport(e.player.getEntityId(), x, y, z, yaw, pitch);
|
||||
} else {
|
||||
byte newYaw = (byte) ((int) (e.player.rotationYaw * 256.0F / 360.0F));
|
||||
byte newPitch = (byte) ((int) (e.player.rotationPitch * 256.0F / 360.0F));
|
||||
|
||||
packet = new SPacketEntity.S17PacketEntityLookMove(e.player.getEntityId(),
|
||||
(short) Math.round(dx * 4096), (short) Math.round(dy * 4096), (short) Math.round(dz * 4096),
|
||||
newYaw, newPitch, e.player.onGround);
|
||||
packet = new S17PacketEntityLookMove(e.player.getEntityId(),
|
||||
(byte) Math.round(dx * 32), (byte) Math.round(dy * 32), (byte) Math.round(dz * 32),
|
||||
newYaw, newPitch);
|
||||
}
|
||||
|
||||
packetListener.save(packet);
|
||||
@@ -135,16 +133,18 @@ public class RecordingEventHandler {
|
||||
int rotationYawHead = ((int)(e.player.rotationYawHead * 256.0F / 360.0F));
|
||||
|
||||
if(!Objects.equals(rotationYawHead, rotationYawHeadBefore)) {
|
||||
packetListener.save(new SPacketEntityHeadLook(e.player, (byte) rotationYawHead));
|
||||
packetListener.save(new S19PacketEntityHeadLook(e.player, (byte) rotationYawHead));
|
||||
|
||||
rotationYawHeadBefore = rotationYawHead;
|
||||
}
|
||||
|
||||
packetListener.save(new SPacketEntityVelocity(e.player.getEntityId(), e.player.motionX, e.player.motionY, e.player.motionZ));
|
||||
S12PacketEntityVelocity vel = new S12PacketEntityVelocity(e.player.getEntityId(), e.player.motionX, e.player.motionY, e.player.motionZ);
|
||||
packetListener.save(vel);
|
||||
|
||||
//Animation Packets
|
||||
//Swing Animation
|
||||
if (e.player.isSwingInProgress && e.player.swingProgressInt == -1) {
|
||||
packetListener.save(new SPacketAnimation(e.player, e.player.swingingHand == EnumHand.MAIN_HAND ? 0 : 3));
|
||||
if(e.player.swingProgressInt == 1) {
|
||||
packetListener.save(new S0BPacketAnimation(e.player, 0));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -168,62 +168,65 @@ public class RecordingEventHandler {
|
||||
*/
|
||||
|
||||
//Inventory Handling
|
||||
if (playerItems[0] != mc.thePlayer.getHeldItem(EnumHand.MAIN_HAND)) {
|
||||
playerItems[0] = mc.thePlayer.getHeldItem(EnumHand.MAIN_HAND);
|
||||
packetListener.save(new SPacketEntityEquipment(e.player.getEntityId(), EntityEquipmentSlot.MAINHAND, playerItems[0]));
|
||||
if(playerItems[0] != mc.thePlayer.getHeldItem()) {
|
||||
playerItems[0] = mc.thePlayer.getHeldItem();
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(e.player.getEntityId(), 0, playerItems[0]);
|
||||
packetListener.save(pee);
|
||||
}
|
||||
|
||||
if (playerItems[1] != mc.thePlayer.getHeldItem(EnumHand.OFF_HAND)) {
|
||||
playerItems[1] = mc.thePlayer.getHeldItem(EnumHand.OFF_HAND);
|
||||
packetListener.save(new SPacketEntityEquipment(e.player.getEntityId(), EntityEquipmentSlot.OFFHAND, playerItems[1]));
|
||||
if(playerItems[1] != mc.thePlayer.inventory.armorInventory[0]) {
|
||||
playerItems[1] = mc.thePlayer.inventory.armorInventory[0];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(e.player.getEntityId(), 1, playerItems[1]);
|
||||
packetListener.save(pee);
|
||||
}
|
||||
|
||||
if (playerItems[2] != mc.thePlayer.inventory.armorInventory[0]) {
|
||||
playerItems[2] = mc.thePlayer.inventory.armorInventory[0];
|
||||
packetListener.save(new SPacketEntityEquipment(e.player.getEntityId(), EntityEquipmentSlot.FEET, playerItems[2]));
|
||||
if(playerItems[2] != mc.thePlayer.inventory.armorInventory[1]) {
|
||||
playerItems[2] = mc.thePlayer.inventory.armorInventory[1];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(e.player.getEntityId(), 2, playerItems[2]);
|
||||
packetListener.save(pee);
|
||||
}
|
||||
|
||||
if (playerItems[3] != mc.thePlayer.inventory.armorInventory[1]) {
|
||||
playerItems[3] = mc.thePlayer.inventory.armorInventory[1];
|
||||
packetListener.save(new SPacketEntityEquipment(e.player.getEntityId(), EntityEquipmentSlot.LEGS, playerItems[3]));
|
||||
if(playerItems[3] != mc.thePlayer.inventory.armorInventory[2]) {
|
||||
playerItems[3] = mc.thePlayer.inventory.armorInventory[2];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(e.player.getEntityId(), 3, playerItems[3]);
|
||||
packetListener.save(pee);
|
||||
}
|
||||
|
||||
if (playerItems[4] != mc.thePlayer.inventory.armorInventory[2]) {
|
||||
playerItems[4] = mc.thePlayer.inventory.armorInventory[2];
|
||||
packetListener.save(new SPacketEntityEquipment(e.player.getEntityId(), EntityEquipmentSlot.CHEST, playerItems[4]));
|
||||
}
|
||||
|
||||
if (playerItems[5] != mc.thePlayer.inventory.armorInventory[3]) {
|
||||
playerItems[5] = mc.thePlayer.inventory.armorInventory[3];
|
||||
packetListener.save(new SPacketEntityEquipment(e.player.getEntityId(), EntityEquipmentSlot.HEAD, playerItems[5]));
|
||||
if(playerItems[4] != mc.thePlayer.inventory.armorInventory[3]) {
|
||||
playerItems[4] = mc.thePlayer.inventory.armorInventory[3];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(e.player.getEntityId(), 4, playerItems[4]);
|
||||
packetListener.save(pee);
|
||||
}
|
||||
|
||||
//Leaving Ride
|
||||
|
||||
if((!mc.thePlayer.isRiding() && lastRiding != -1) ||
|
||||
(mc.thePlayer.isRiding() && lastRiding != mc.thePlayer.getRidingEntity().getEntityId())) {
|
||||
(mc.thePlayer.isRiding() && lastRiding != mc.thePlayer.ridingEntity.getEntityId())) {
|
||||
if(!mc.thePlayer.isRiding()) {
|
||||
lastRiding = -1;
|
||||
} else {
|
||||
lastRiding = mc.thePlayer.getRidingEntity().getEntityId();
|
||||
lastRiding = mc.thePlayer.ridingEntity.getEntityId();
|
||||
}
|
||||
packetListener.save(new SPacketEntityAttach(e.player, e.player.getRidingEntity()));
|
||||
|
||||
S1BPacketEntityAttach pea = new S1BPacketEntityAttach();
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeInt(e.player.getEntityId());
|
||||
pbuf.writeInt(lastRiding);
|
||||
pbuf.writeBoolean(false);
|
||||
|
||||
pea.readPacketData(pbuf);
|
||||
|
||||
packetListener.save(pea);
|
||||
}
|
||||
|
||||
//Sleeping
|
||||
if(!mc.thePlayer.isPlayerSleeping() && wasSleeping) {
|
||||
packetListener.save(new SPacketAnimation(e.player, 2));
|
||||
wasSleeping = false;
|
||||
}
|
||||
packetListener.save(new S0BPacketAnimation(e.player, 2));
|
||||
|
||||
// Active hand (e.g. eating, drinking, blocking)
|
||||
if (mc.thePlayer.isHandActive() ^ wasHandActive || mc.thePlayer.getActiveHand() != lastActiveHand) {
|
||||
wasHandActive = mc.thePlayer.isHandActive();
|
||||
lastActiveHand = mc.thePlayer.getActiveHand();
|
||||
EntityDataManager dataManager = new EntityDataManager(null);
|
||||
int state = (wasHandActive ? 1 : 0) | (lastActiveHand == EnumHand.OFF_HAND ? 2 : 0);
|
||||
dataManager.register(EntityLiving.HAND_STATES, (byte) state);
|
||||
packetListener.save(new SPacketEntityMetadata(mc.thePlayer.getEntityId(), dataManager, true));
|
||||
wasSleeping = false;
|
||||
}
|
||||
|
||||
} catch(Exception e1) {
|
||||
@@ -232,49 +235,43 @@ public class RecordingEventHandler {
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPickupItem(ItemPickupEvent event) {
|
||||
public void onPickupItem(PlayerEvent.ItemPickupEvent event) {
|
||||
try {
|
||||
packetListener.save(new SPacketCollectItem(event.pickedUp.getEntityId(), event.player.getEntityId()));
|
||||
packetListener.save(new S0DPacketCollectItem(event.pickedUp.getEntityId(), event.player.getEntityId()));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onStartEating(PlayerUseItemEvent.Start event) {
|
||||
if(!event.entityPlayer.isEating()) return;
|
||||
packetListener.save(new S0BPacketAnimation(event.entityPlayer, 3));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSleep(PlayerSleepInBedEvent event) {
|
||||
try {
|
||||
if (event.getEntityPlayer() != mc.thePlayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
packetListener.save(new SPacketUseBed(event.getEntityPlayer(), event.getPos()));
|
||||
|
||||
wasSleeping = true;
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
if(event.entityPlayer != mc.thePlayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
packetListener.save(new S0APacketUseBed(event.entityPlayer, event.x, event.y, event.z));
|
||||
wasSleeping = true;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void enterMinecart(MinecartInteractEvent event) {
|
||||
try {
|
||||
if(event.getEntity() != mc.thePlayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
packetListener.save(new SPacketEntityAttach(event.getPlayer(), event.getMinecart()));
|
||||
|
||||
lastRiding = event.getMinecart().getEntityId();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
if(event.player != mc.thePlayer) {
|
||||
return;
|
||||
}
|
||||
packetListener.save(new S1BPacketEntityAttach(0, event.player, event.minecart));
|
||||
lastRiding = event.minecart.getEntityId();
|
||||
}
|
||||
|
||||
public void onBlockBreakAnim(int breakerId, BlockPos pos, int progress) {
|
||||
public void onBlockBreakAnim(int breakerId, int x, int y, int z, int progress) {
|
||||
EntityPlayer thePlayer = mc.thePlayer;
|
||||
if (thePlayer != null && breakerId == thePlayer.getEntityId()) {
|
||||
packetListener.save(new SPacketBlockBreakAnim(breakerId, pos, progress));
|
||||
packetListener.save(new S25PacketBlockBreakAnim(breakerId, x, y, z, progress));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.replaymod.recording.mixin;
|
||||
|
||||
import com.replaymod.recording.ReplayModRecording;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import net.minecraft.client.network.NetHandlerLoginClient;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -13,15 +15,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public abstract class MixinNetHandlerLoginClient {
|
||||
|
||||
@Shadow
|
||||
private NetworkManager networkManager;
|
||||
private @Final NetworkManager field_147393_d;
|
||||
|
||||
/**
|
||||
* Starts the recording right before switching into PLAY state.
|
||||
* We cannot use the {@link net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent}
|
||||
* We cannot use the {@link FMLNetworkEvent.ClientConnectedToServerEvent}
|
||||
* as it only fires after the forge handshake.
|
||||
*/
|
||||
@Inject(method = "handleLoginSuccess", at=@At("HEAD"))
|
||||
public void replayModRecording_initiateRecording(CallbackInfo cb) {
|
||||
ReplayModRecording.instance.initiateRecording(networkManager);
|
||||
ReplayModRecording.instance.initiateRecording(field_147393_d);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,20 @@ package com.replaymod.recording.mixin;
|
||||
import com.replaymod.recording.handler.RecordingEventHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.client.network.NetworkPlayerInfo;
|
||||
import net.minecraft.network.play.server.SPacketPlayerListItem;
|
||||
import net.minecraft.network.play.server.SPacketRespawn;
|
||||
import net.minecraft.network.play.server.S01PacketJoinGame;
|
||||
import net.minecraft.network.play.server.S07PacketRespawn;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mixin(NetHandlerPlayClient.class)
|
||||
public abstract class MixinNetHandlerPlayClient {
|
||||
|
||||
@Shadow
|
||||
private Minecraft gameController;
|
||||
|
||||
@Shadow
|
||||
private Map<UUID, NetworkPlayerInfo> playerInfoMap;
|
||||
|
||||
public RecordingEventHandler getRecordingEventHandler() {
|
||||
return ((RecordingEventHandler.RecordingEventSender) gameController.renderGlobal).getRecordingEventHandler();
|
||||
}
|
||||
@@ -31,36 +24,27 @@ public abstract class MixinNetHandlerPlayClient {
|
||||
/**
|
||||
* Record the own player entity joining the world.
|
||||
* We cannot use the {@link net.minecraftforge.event.entity.EntityJoinWorldEvent} because the entity id
|
||||
* of the player is set afterwards and the tablist entry might not yet be sent.
|
||||
* of the player is set afterwards
|
||||
* @param packet The packet
|
||||
* @param ci Callback info
|
||||
*/
|
||||
@Inject(method = "handlePlayerListItem", at=@At("HEAD"))
|
||||
public void recordOwnJoin(SPacketPlayerListItem packet, CallbackInfo ci) {
|
||||
if (gameController.thePlayer == null) return;
|
||||
|
||||
@Inject(method = "handleJoinGame", at=@At("RETURN"))
|
||||
public void recordOwnJoin(S01PacketJoinGame packet, CallbackInfo ci) {
|
||||
RecordingEventHandler handler = getRecordingEventHandler();
|
||||
if (handler != null && packet.getAction() == SPacketPlayerListItem.Action.ADD_PLAYER) {
|
||||
for (SPacketPlayerListItem.AddPlayerData data : packet.getEntries()) {
|
||||
if (data.getProfile() == null || data.getProfile().getId() == null) continue;
|
||||
// Only add spawn packet for our own player and only if he isn't known yet
|
||||
if (data.getProfile().getId().equals(Minecraft.getMinecraft().thePlayer.getGameProfile().getId())
|
||||
&& !playerInfoMap.containsKey(data.getProfile().getId())) {
|
||||
handler.onPlayerJoin();
|
||||
}
|
||||
}
|
||||
if (handler != null) {
|
||||
handler.onPlayerJoin();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record the own player entity respawning.
|
||||
* We cannot use the {@link net.minecraftforge.event.entity.EntityJoinWorldEvent} because that would also include
|
||||
* the first spawn which is already handled by {@link #recordOwnJoin(SPacketPlayerListItem, CallbackInfo)}.
|
||||
* the first spawn which is already handled by {@link #recordOwnJoin(S01PacketJoinGame, CallbackInfo)}.
|
||||
* @param packet The packet
|
||||
* @param ci Callback info
|
||||
*/
|
||||
@Inject(method = "handleRespawn", at=@At("RETURN"))
|
||||
public void recordOwnRespawn(SPacketRespawn packet, CallbackInfo ci) {
|
||||
public void recordOwnRespawn(S07PacketRespawn packet, CallbackInfo ci) {
|
||||
RecordingEventHandler handler = getRecordingEventHandler();
|
||||
if (handler != null) {
|
||||
handler.onPlayerRespawn();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.replaymod.recording.mixin;
|
||||
|
||||
import com.replaymod.recording.handler.FMLHandshakeFilter;
|
||||
import cpw.mods.fml.common.network.handshake.FMLHandshakeCodec;
|
||||
import cpw.mods.fml.common.network.handshake.NetworkDispatcher;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraftforge.fml.common.network.handshake.FMLHandshakeCodec;
|
||||
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.replaymod.recording.mixin;
|
||||
|
||||
import com.replaymod.recording.handler.RecordingEventHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(PlayerControllerMP.class)
|
||||
public abstract class MixinPlayerControllerMP implements RecordingEventHandler.RecordingEventSender {
|
||||
|
||||
@Shadow
|
||||
private Minecraft mc;
|
||||
|
||||
// Redirects the call to playEvent without the initial player argument to the method with that argument
|
||||
// The new method will then play it and (if applicable) record it. (See MixinWorldClient)
|
||||
// This is necessary for the block break event (particles and sound) to be recorded. Otherwise it looks like the
|
||||
// event was emitted because of a packet (player will be null) and not as it actually was (by the player).
|
||||
@Redirect(method = "onPlayerDestroyBlock", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/World;playEvent(ILnet/minecraft/util/math/BlockPos;I)V"))
|
||||
public void replayModRecording_playEvent_fixed(World world, int type, BlockPos pos, int data) {
|
||||
world.playEvent(mc.thePlayer, type, pos, data);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.replaymod.recording.mixin;
|
||||
|
||||
import com.replaymod.recording.handler.RecordingEventHandler;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -23,10 +22,10 @@ public abstract class MixinRenderGlobal implements RecordingEventHandler.Recordi
|
||||
return recordingEventHandler;
|
||||
}
|
||||
|
||||
@Inject(method = "sendBlockBreakProgress", at = @At("HEAD"))
|
||||
public void saveBlockBreakProgressPacket(int breakerId, BlockPos pos, int progress, CallbackInfo info) {
|
||||
@Inject(method = "destroyBlockPartially", at = @At("HEAD"))
|
||||
public void saveBlockBreakProgressPacket(int breakerId, int x, int y, int z, int progress, CallbackInfo info) {
|
||||
if (recordingEventHandler != null) {
|
||||
recordingEventHandler.onBlockBreakAnim(breakerId, pos, progress);
|
||||
recordingEventHandler.onBlockBreakAnim(breakerId, x, y, z, progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
package com.replaymod.recording.mixin;
|
||||
|
||||
import com.replaymod.recording.handler.RecordingEventHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.profiler.Profiler;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraft.world.storage.ISaveHandler;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(WorldClient.class)
|
||||
public abstract class MixinWorldClient extends World implements RecordingEventHandler.RecordingEventSender {
|
||||
@Shadow
|
||||
private Minecraft mc;
|
||||
|
||||
protected MixinWorldClient(ISaveHandler saveHandlerIn, WorldInfo info, WorldProvider providerIn, Profiler profilerIn, boolean client) {
|
||||
super(saveHandlerIn, info, providerIn, profilerIn, client);
|
||||
}
|
||||
|
||||
private RecordingEventHandler replayModRecording_getRecordingEventHandler() {
|
||||
return ((RecordingEventHandler.RecordingEventSender) mc.renderGlobal).getRecordingEventHandler();
|
||||
}
|
||||
|
||||
// Sounds that are emitted by thePlayer no longer take the long way over the server
|
||||
// but are instead played directly by the client. The server only sends these sounds to
|
||||
// other clients so we have to record them manually.
|
||||
// E.g. Block place sounds
|
||||
@Inject(method = "playSound", at = @At("HEAD"))
|
||||
public void replayModRecording_recordClientSound(EntityPlayer player, double x, double y, double z, SoundEvent sound, SoundCategory category,
|
||||
float volume, float pitch, CallbackInfo ci) {
|
||||
if (player == mc.thePlayer) {
|
||||
RecordingEventHandler handler = replayModRecording_getRecordingEventHandler();
|
||||
if (handler != null) {
|
||||
handler.onClientSound(sound, category, x, y, z, volume, pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Same goes for level events (also called effects). E.g. door open, block break, etc.
|
||||
// These are handled in the World class, so we override the method in WorldClient and add our special handling.
|
||||
@Override
|
||||
public void playEvent(EntityPlayer player, int type, BlockPos pos, int data) {
|
||||
if (player == mc.thePlayer) {
|
||||
// We caused this event, the server won't send it to us
|
||||
RecordingEventHandler handler = replayModRecording_getRecordingEventHandler();
|
||||
if (handler != null) {
|
||||
handler.onClientEffect(type, pos, data);
|
||||
}
|
||||
}
|
||||
super.playEvent(player, type, pos, data);
|
||||
}
|
||||
}
|
||||
@@ -4,29 +4,25 @@ import com.replaymod.core.utils.Restrictions;
|
||||
import com.replaymod.replaystudio.data.Marker;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import com.replaymod.replaystudio.replay.ReplayMetaData;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.DataWatcher;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.EnumConnectionState;
|
||||
import net.minecraft.network.EnumPacketDirection;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.datasync.EntityDataManager;
|
||||
import net.minecraft.network.play.server.*;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -87,8 +83,8 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
|
||||
public void save(Packet packet) {
|
||||
try {
|
||||
if(packet instanceof SPacketSpawnPlayer) {
|
||||
UUID uuid = ((SPacketSpawnPlayer) packet).getUniqueId();
|
||||
if(packet instanceof S0CPacketSpawnPlayer) {
|
||||
UUID uuid = ((S0CPacketSpawnPlayer) packet).field_148955_b.getId();
|
||||
Set<String> uuids = new HashSet<>(Arrays.asList(metaData.getPlayers()));
|
||||
uuids.add(uuid.toString());
|
||||
metaData.setPlayers(uuids.toArray(new String[uuids.size()]));
|
||||
@@ -154,32 +150,35 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
try {
|
||||
Packet packet = (Packet) msg;
|
||||
|
||||
if(packet instanceof SPacketCollectItem) {
|
||||
if(packet instanceof S0DPacketCollectItem) {
|
||||
if(mc.thePlayer != null ||
|
||||
((SPacketCollectItem) packet).getEntityID() == mc.thePlayer.getEntityId()) {
|
||||
((S0DPacketCollectItem) packet).func_149353_d() == mc.thePlayer.getEntityId()) {
|
||||
super.channelRead(ctx, msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (packet instanceof SPacketResourcePackSend) {
|
||||
save(resourcePackRecorder.handleResourcePack((SPacketResourcePackSend) packet));
|
||||
return;
|
||||
if (packet instanceof S3FPacketCustomPayload) {
|
||||
S3FPacketCustomPayload p = (S3FPacketCustomPayload) packet;
|
||||
if ("MC|RPack".equals(p.func_149169_c())) {
|
||||
save(resourcePackRecorder.handleResourcePack(p));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (packet instanceof FMLProxyPacket) {
|
||||
// This packet requires special handling
|
||||
((FMLProxyPacket) packet).toS3FPackets().forEach(this::save);
|
||||
save(((FMLProxyPacket) packet).toS3FPacket());
|
||||
super.channelRead(ctx, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
save(packet);
|
||||
|
||||
if (packet instanceof SPacketCustomPayload) {
|
||||
SPacketCustomPayload p = (SPacketCustomPayload) packet;
|
||||
if (Restrictions.PLUGIN_CHANNEL.equals(p.getChannelName())) {
|
||||
packet = new SPacketDisconnect(new TextComponentString("Please update to view this replay."));
|
||||
if (packet instanceof S3FPacketCustomPayload) {
|
||||
S3FPacketCustomPayload p = (S3FPacketCustomPayload) packet;
|
||||
if (Restrictions.PLUGIN_CHANNEL.equals(p.func_149169_c())) {
|
||||
packet = new S40PacketDisconnect(new ChatComponentText("Please update to view this replay."));
|
||||
save(packet);
|
||||
}
|
||||
}
|
||||
@@ -192,37 +191,33 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
super.channelRead(ctx, msg);
|
||||
}
|
||||
|
||||
private <T> void DataManager_set(EntityDataManager dataManager, EntityDataManager.DataEntry<T> entry) {
|
||||
dataManager.register(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private byte[] getPacketData(Packet packet) throws IOException {
|
||||
if (packet instanceof SPacketSpawnMob) {
|
||||
SPacketSpawnMob p = (SPacketSpawnMob) packet;
|
||||
if (p.dataManager == null) {
|
||||
p.dataManager = new EntityDataManager(null);
|
||||
if (p.getDataManagerEntries() != null) {
|
||||
for (EntityDataManager.DataEntry<?> entry : p.getDataManagerEntries()) {
|
||||
DataManager_set(p.dataManager, entry);
|
||||
if(packet instanceof S0FPacketSpawnMob) {
|
||||
S0FPacketSpawnMob p = (S0FPacketSpawnMob) packet;
|
||||
if (p.field_149043_l == null) {
|
||||
p.field_149043_l = new DataWatcher(null);
|
||||
if(p.func_149027_c() != null) {
|
||||
for(DataWatcher.WatchableObject wo : (List<DataWatcher.WatchableObject>) p.func_149027_c()) {
|
||||
p.field_149043_l.addObject(wo.getDataValueId(), wo.getObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (packet instanceof SPacketSpawnPlayer) {
|
||||
SPacketSpawnPlayer p = (SPacketSpawnPlayer) packet;
|
||||
if (p.watcher == null) {
|
||||
p.watcher = new EntityDataManager(null);
|
||||
if (p.getDataManagerEntries() != null) {
|
||||
for (EntityDataManager.DataEntry<?> entry : p.getDataManagerEntries()) {
|
||||
DataManager_set(p.watcher, entry);
|
||||
if(packet instanceof S0CPacketSpawnPlayer) {
|
||||
S0CPacketSpawnPlayer p = (S0CPacketSpawnPlayer) packet;
|
||||
if (p.field_148960_i == null) {
|
||||
p.field_148960_i = new DataWatcher(null);
|
||||
if(p.func_148944_c() != null) {
|
||||
for(DataWatcher.WatchableObject wo : (List<DataWatcher.WatchableObject>) p.func_148944_c()) {
|
||||
p.field_148960_i.addObject(wo.getDataValueId(), wo.getObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Integer packetId = EnumConnectionState.PLAY.getPacketId(EnumPacketDirection.CLIENTBOUND, packet);
|
||||
Integer packetId = (Integer) EnumConnectionState.PLAY.func_150755_b().inverse().get(packet.getClass());
|
||||
if (packetId == null) {
|
||||
throw new IOException("Unknown packet type:" + packet.getClass());
|
||||
}
|
||||
@@ -240,7 +235,7 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
|
||||
public void addMarker() {
|
||||
Entity view = Minecraft.getMinecraft().getRenderViewEntity();
|
||||
Entity view = Minecraft.getMinecraft().renderViewEntity;
|
||||
int timestamp = (int) (System.currentTimeMillis() - startTime);
|
||||
|
||||
Marker marker = new Marker();
|
||||
|
||||
@@ -2,27 +2,23 @@ package com.replaymod.recording.packet;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreenWorking;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.multiplayer.ServerData.ServerResourceMode;
|
||||
import net.minecraft.client.multiplayer.ServerList;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.client.resources.FileResourcePack;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.resources.ResourcePackRepository;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.client.CPacketResourcePackStatus;
|
||||
import net.minecraft.network.play.server.SPacketResourcePackSend;
|
||||
import net.minecraft.network.play.server.S3FPacketCustomPayload;
|
||||
import net.minecraft.util.HttpUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -74,140 +70,75 @@ public class ResourcePackRecorder {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized SPacketResourcePackSend handleResourcePack(SPacketResourcePackSend packet) {
|
||||
public synchronized S3FPacketCustomPayload handleResourcePack(S3FPacketCustomPayload packet) {
|
||||
final int requestId = nextRequestId++;
|
||||
final NetHandlerPlayClient netHandler = mc.getConnection();
|
||||
final NetworkManager netManager = netHandler.getNetworkManager();
|
||||
final String url = packet.getURL();
|
||||
final String hash = packet.getHash();
|
||||
final String url = new String(packet.func_149168_d(), Charsets.UTF_8);
|
||||
|
||||
if (url.startsWith("level://")) {
|
||||
String levelName = url.substring("level://".length());
|
||||
File savesDir = new File(mc.mcDataDir, "saves");
|
||||
final File levelDir = new File(savesDir, levelName);
|
||||
|
||||
if (levelDir.isFile()) {
|
||||
netManager.sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.ACCEPTED));
|
||||
Futures.addCallback(mc.getResourcePackRepository().setResourcePackInstance(levelDir), new FutureCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
recordResourcePack(levelDir, requestId);
|
||||
netManager.sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.SUCCESSFULLY_LOADED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nonnull Throwable throwable) {
|
||||
netManager.sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.FAILED_DOWNLOAD));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
netManager.sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.FAILED_DOWNLOAD));
|
||||
}
|
||||
} else {
|
||||
final ServerData serverData = mc.getCurrentServerData();
|
||||
if (serverData != null && serverData.getResourceMode() == ServerData.ServerResourceMode.ENABLED) {
|
||||
netManager.sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.ACCEPTED));
|
||||
downloadResourcePackFuture(requestId, url, hash);
|
||||
} else if (serverData != null && serverData.getResourceMode() != ServerData.ServerResourceMode.PROMPT) {
|
||||
netManager.sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.DECLINED));
|
||||
} else {
|
||||
mc.addScheduledTask(() -> mc.displayGuiScreen(new GuiYesNo((result, id) -> {
|
||||
ServerData serverData = mc.getCurrentServerData();
|
||||
ServerResourceMode resourceMode = serverData == null ? ServerResourceMode.PROMPT : serverData.getResourceMode();
|
||||
if (resourceMode == ServerResourceMode.ENABLED) {
|
||||
downloadResourcePack(requestId, url);
|
||||
mc.getResourcePackRepository().obtainResourcePack(url);
|
||||
} else if (resourceMode == ServerResourceMode.PROMPT) {
|
||||
// Lambdas MUST NOT be used with methods that need re-obfuscation in FG prior to 2.2 (will result in AbstractMethodError)
|
||||
//noinspection Convert2Lambda
|
||||
mc.displayGuiScreen(new GuiYesNo(new GuiYesNoCallback() {
|
||||
@Override
|
||||
public void confirmClicked(boolean result, int id) {
|
||||
if (serverData != null) {
|
||||
serverData.setResourceMode(result ? ServerData.ServerResourceMode.ENABLED : ServerData.ServerResourceMode.DISABLED);
|
||||
}
|
||||
if (result) {
|
||||
netManager.sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.ACCEPTED));
|
||||
downloadResourcePackFuture(requestId, url, hash);
|
||||
} else {
|
||||
netManager.sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.DECLINED));
|
||||
serverData.setResourceMode(ServerResourceMode.ENABLED);
|
||||
ServerList.func_147414_b(serverData);
|
||||
}
|
||||
|
||||
ServerList.saveSingleServer(serverData);
|
||||
mc.displayGuiScreen(null);
|
||||
}, I18n.format("multiplayer.texturePrompt.line1"), I18n.format("multiplayer.texturePrompt.line2"), 0)));
|
||||
}
|
||||
}
|
||||
|
||||
return new SPacketResourcePackSend("replay://" + requestId, "");
|
||||
}
|
||||
|
||||
private void downloadResourcePackFuture(int requestId, String url, final String hash) {
|
||||
Futures.addCallback(downloadResourcePack(requestId, url, hash), new FutureCallback() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
mc.getConnection().sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.SUCCESSFULLY_LOADED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nonnull Throwable throwable) {
|
||||
mc.getConnection().sendPacket(new CPacketResourcePackStatus(hash, CPacketResourcePackStatus.Action.FAILED_DOWNLOAD));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ListenableFuture downloadResourcePack(final int requestId, String url, String hash) {
|
||||
final ResourcePackRepository repo = mc.mcResourcePackRepository;
|
||||
String fileName;
|
||||
if (hash.matches("^[a-f0-9]{40}$")) {
|
||||
fileName = hash;
|
||||
} else {
|
||||
fileName = url.substring(url.lastIndexOf("/") + 1);
|
||||
|
||||
if (fileName.contains("?")) {
|
||||
fileName = fileName.substring(0, fileName.indexOf("?"));
|
||||
}
|
||||
|
||||
if (!fileName.endsWith(".zip")) {
|
||||
return Futures.immediateFailedFuture(new IllegalArgumentException("Invalid filename; must end in .zip"));
|
||||
}
|
||||
|
||||
fileName = "legacy_" + fileName.replaceAll("\\W", "");
|
||||
}
|
||||
|
||||
final File file = new File(repo.dirServerResourcepacks, fileName);
|
||||
repo.lock.lock();
|
||||
try {
|
||||
repo.clearResourcePack();
|
||||
|
||||
if (file.exists() && hash.length() == 40) {
|
||||
try {
|
||||
String fileHash = Hashing.sha1().hashBytes(Files.toByteArray(file)).toString();
|
||||
if (fileHash.equals(hash)) {
|
||||
recordResourcePack(file, requestId);
|
||||
return repo.setResourcePackInstance(file);
|
||||
if (result) {
|
||||
downloadResourcePack(requestId, url);
|
||||
}
|
||||
|
||||
logger.warn("File " + file + " had wrong hash (expected " + hash + ", found " + fileHash + "). Deleting it.");
|
||||
FileUtils.deleteQuietly(file);
|
||||
} catch (IOException ioexception) {
|
||||
logger.warn("File " + file + " couldn\'t be hashed. Deleting it.", ioexception);
|
||||
FileUtils.deleteQuietly(file);
|
||||
}
|
||||
}
|
||||
|
||||
final GuiScreenWorking guiScreen = new GuiScreenWorking();
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
Futures.getUnchecked(mc.addScheduledTask(() -> mc.displayGuiScreen(guiScreen)));
|
||||
|
||||
Map<String, String> sessionInfo = Minecraft.getSessionInfo();
|
||||
repo.downloadingPacks = HttpUtil.downloadResourcePack(file, url, sessionInfo, 50 * 1024 * 1024, guiScreen, mc.getProxy());
|
||||
Futures.addCallback(repo.downloadingPacks, new FutureCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object value) {
|
||||
recordResourcePack(file, requestId);
|
||||
repo.setResourcePackInstance(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@Nonnull Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
return repo.downloadingPacks;
|
||||
} finally {
|
||||
repo.lock.unlock();
|
||||
}, I18n.format("multiplayer.texturePrompt.line1"), I18n.format("multiplayer.texturePrompt.line2"), 0));
|
||||
}
|
||||
|
||||
return new S3FPacketCustomPayload(packet.func_149169_c(), ("replay://" + requestId).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
private void downloadResourcePack(final int requestId, String url) {
|
||||
final ResourcePackRepository repo = mc.mcResourcePackRepository;
|
||||
|
||||
String fileName = url.substring(url.lastIndexOf("/") + 1);
|
||||
|
||||
if (fileName.contains("?")) {
|
||||
fileName = fileName.substring(0, fileName.indexOf("?"));
|
||||
}
|
||||
|
||||
if (!fileName.endsWith(".zip")) {
|
||||
return;
|
||||
}
|
||||
|
||||
fileName = fileName.replaceAll("\\W", "");
|
||||
|
||||
File file = new File(repo.field_148534_e, fileName);
|
||||
|
||||
HashMap<String, String> hashmap = new HashMap<>();
|
||||
hashmap.put("X-Minecraft-Username", mc.getSession().getUsername());
|
||||
hashmap.put("X-Minecraft-UUID", mc.getSession().getPlayerID());
|
||||
hashmap.put("X-Minecraft-Version", "1.7.10");
|
||||
|
||||
GuiScreenWorking guiScreen = new GuiScreenWorking();
|
||||
Minecraft.getMinecraft().displayGuiScreen(guiScreen);
|
||||
repo.func_148529_f();
|
||||
repo.field_148533_g = true;
|
||||
// Lambdas MUST NOT be used with methods that need re-obfuscation in FG prior to 2.2 (will result in AbstractMethodError)
|
||||
//noinspection Convert2Lambda
|
||||
HttpUtil.downloadResourcePack(file, url, new HttpUtil.DownloadListener() {
|
||||
public void onDownloadComplete(File file) {
|
||||
if (repo.field_148533_g) {
|
||||
repo.field_148533_g = false;
|
||||
repo.field_148532_f = new FileResourcePack(file);
|
||||
Minecraft.getMinecraft().scheduleResourcesRefresh();
|
||||
recordResourcePack(file, requestId);
|
||||
}
|
||||
}
|
||||
}, hashmap, 50*1024*1024, guiScreen, Minecraft.getMinecraft().getProxy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ package com.replaymod.render;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.render.utils.RenderJob;
|
||||
import com.replaymod.replay.events.ReplayCloseEvent;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
@Mod(modid = ReplayModRender.MOD_ID,
|
||||
version = "@MOD_VERSION@",
|
||||
acceptedMinecraftVersions = "@MC_VERSION@",
|
||||
acceptableRemoteVersions = "*",
|
||||
useMetadata = true)
|
||||
public class ReplayModRender {
|
||||
public static final String MOD_ID = "replaymod-render";
|
||||
@@ -45,7 +46,7 @@ public class ReplayModRender {
|
||||
core = ReplayMod.instance;
|
||||
configuration = new Configuration(event.getSuggestedConfigurationFile());
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
|
||||
core.getSettingsRegistry().register(Setting.class);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ package com.replaymod.render;
|
||||
|
||||
import com.replaymod.render.frame.RGBFrame;
|
||||
import com.replaymod.render.rendering.FrameConsumer;
|
||||
import com.replaymod.render.rendering.VideoRenderer;
|
||||
import com.replaymod.render.utils.ByteBufferPool;
|
||||
import com.replaymod.render.utils.StreamPipe;
|
||||
import cpw.mods.fml.common.versioning.ComparableVersion;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.fml.common.versioning.ComparableVersion;
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -32,6 +33,7 @@ import static org.apache.commons.lang3.Validate.isTrue;
|
||||
|
||||
public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
|
||||
private final VideoRenderer renderer;
|
||||
private final RenderSettings settings;
|
||||
private final Process process;
|
||||
private final OutputStream outputStream;
|
||||
@@ -41,8 +43,9 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
|
||||
private ByteArrayOutputStream ffmpegLog = new ByteArrayOutputStream(4096);
|
||||
|
||||
public VideoWriter(final RenderSettings settings) throws IOException {
|
||||
this.settings = settings;
|
||||
public VideoWriter(final VideoRenderer renderer) throws IOException {
|
||||
this.renderer = renderer;
|
||||
this.settings = renderer.getRenderSettings();
|
||||
|
||||
File outputFolder = settings.getOutputFile().getParentFile();
|
||||
FileUtils.forceMkdir(outputFolder);
|
||||
@@ -57,9 +60,13 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
.replace("%FILTERS%", settings.getVideoFilters());
|
||||
|
||||
String executable = settings.getExportCommand().isEmpty() ? findFFmpeg() : settings.getExportCommand();
|
||||
System.out.println("Starting " + executable + " with args: " + commandArgs);
|
||||
LOGGER.info("Starting {} with args: {}", executable, commandArgs);
|
||||
String[] cmdline = new CommandLine(executable).addArguments(commandArgs).toStrings();
|
||||
process = new ProcessBuilder(cmdline).directory(outputFolder).start();
|
||||
try {
|
||||
process = new ProcessBuilder(cmdline).directory(outputFolder).start();
|
||||
} catch (IOException e) {
|
||||
throw new NoFFmpegException(e);
|
||||
}
|
||||
File exportLogFile = new File(Minecraft.getMinecraft().mcDataDir, "export.log");
|
||||
OutputStream exportLogOut = new TeeOutputStream(new FileOutputStream(exportLogFile), ffmpegLog);
|
||||
new StreamPipe(process.getInputStream(), exportLogOut).start();
|
||||
@@ -152,6 +159,16 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
if (aborted) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Check whether this is a failure right at the beginning of the rendering process
|
||||
// or at some later point (ffmpeg won't print the output file until the first frame
|
||||
// has been written to stdin, so we can't already check for invalid args in <init>).
|
||||
getVideoFile();
|
||||
} catch (FFmpegStartupException e) {
|
||||
// Possibly invalid ffmpeg arguments
|
||||
renderer.setFailure(e);
|
||||
return;
|
||||
}
|
||||
CrashReport report = CrashReport.makeCrashReport(t, "Exporting frame");
|
||||
CrashReportCategory exportDetails = report.makeCategory("Export details");
|
||||
exportDetails.addCrashSection("Export command", settings.getExportCommand());
|
||||
@@ -173,7 +190,7 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
aborted = true;
|
||||
}
|
||||
|
||||
public File getVideoFile() {
|
||||
public File getVideoFile() throws FFmpegStartupException {
|
||||
String log = ffmpegLog.toString();
|
||||
for (String line : log.split("\n")) {
|
||||
if (line.startsWith("Output #0")) {
|
||||
@@ -181,6 +198,30 @@ public class VideoWriter implements FrameConsumer<RGBFrame> {
|
||||
return new File(settings.getOutputFile().getParentFile(), fileName);
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("No output file found.");
|
||||
throw new FFmpegStartupException(settings, log);
|
||||
}
|
||||
|
||||
public static class NoFFmpegException extends IOException {
|
||||
public NoFFmpegException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
public static class FFmpegStartupException extends IOException {
|
||||
private final RenderSettings settings;
|
||||
private final String log;
|
||||
|
||||
public FFmpegStartupException(RenderSettings settings, String log) {
|
||||
this.settings = settings;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public RenderSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public String getLog() {
|
||||
return log;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.replaymod.render.RenderSettings;
|
||||
import com.replaymod.render.frame.CubicOpenGlFrame;
|
||||
import com.replaymod.render.frame.ODSOpenGlFrame;
|
||||
import com.replaymod.render.frame.OpenGlFrame;
|
||||
import com.replaymod.render.hooks.GLStateTracker;
|
||||
import com.replaymod.render.rendering.FrameCapturer;
|
||||
import com.replaymod.render.shader.Program;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -15,9 +15,13 @@ import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static net.minecraft.client.renderer.GlStateManager.*;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
||||
import static org.lwjgl.opengl.GL11.glClear;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
||||
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
||||
|
||||
public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
private static final ResourceLocation vertexResource = new ResourceLocation("replaymod", "shader/ods.vert");
|
||||
@@ -28,8 +32,8 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
private final Program.Uniform directionVariable;
|
||||
private final Program.Uniform leftEyeVariable;
|
||||
|
||||
private final BooleanState[] previousStates = new BooleanState[3];
|
||||
private final BooleanState previousFogState;
|
||||
private final GLStateTracker.EnabledState[] previousStates = new GLStateTracker.EnabledState[2];
|
||||
private final GLStateTracker.EnabledState previousFogState;
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
@@ -42,6 +46,11 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
return renderInfo.getFrameSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramesDone() {
|
||||
return renderInfo.getFramesDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalFrames() {
|
||||
return renderInfo.getTotalFrames();
|
||||
@@ -73,15 +82,14 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
setTexture("lightMap", 1);
|
||||
linkState(0, "textureEnabled");
|
||||
linkState(1, "lightMapEnabled");
|
||||
linkState(2, "hurtTextureEnabled");
|
||||
final Program.Uniform uniform = shaderProgram.getUniformVariable("fogEnabled");
|
||||
previousFogState = GlStateManager.fogState.fog;
|
||||
uniform.set(previousFogState.currentState);
|
||||
GlStateManager.fogState.fog = new BooleanState(previousFogState.capability) {
|
||||
previousFogState = GLStateTracker.getInstance().fog;
|
||||
uniform.set(previousFogState.isEnabled());
|
||||
GLStateTracker.getInstance().fog = new GLStateTracker.EnabledState() {
|
||||
@Override
|
||||
public void setState(boolean state) {
|
||||
super.setState(state);
|
||||
uniform.set(state);
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
uniform.set(enabled);
|
||||
}
|
||||
};
|
||||
shaderProgram.stopUsing();
|
||||
@@ -96,13 +104,13 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
|
||||
private void linkState(int id, String var) {
|
||||
final Program.Uniform uniform = shaderProgram.getUniformVariable(var);
|
||||
previousStates[id] = GlStateManager.textureState[id].texture2DState;
|
||||
uniform.set(previousStates[id].currentState);
|
||||
GlStateManager.textureState[id].texture2DState = new BooleanState(previousStates[id].capability) {
|
||||
previousStates[id] = GLStateTracker.getInstance().texture[id];
|
||||
uniform.set(previousStates[id].isEnabled());
|
||||
GLStateTracker.getInstance().texture[id] = new GLStateTracker.EnabledState() {
|
||||
@Override
|
||||
public void setState(boolean state) {
|
||||
super.setState(state);
|
||||
uniform.set(state);
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
uniform.set(enabled);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -132,10 +140,10 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
left.close();
|
||||
right.close();
|
||||
shaderProgram.delete();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
GlStateManager.textureState[i].texture2DState = previousStates[i];
|
||||
for (int i = 0; i < previousStates.length; i++) {
|
||||
GLStateTracker.getInstance().texture[i] = previousStates[i];
|
||||
}
|
||||
GlStateManager.fogState.fog = previousFogState;
|
||||
GLStateTracker.getInstance().fog = previousFogState;
|
||||
}
|
||||
|
||||
private class CubicStereoFrameCapturer extends CubicPboOpenGlFrameCapturer {
|
||||
@@ -147,17 +155,17 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
protected OpenGlFrame renderFrame(int frameId, float partialTicks, CubicOpenGlFrameCapturer.Data captureData) {
|
||||
resize(getFrameWidth(), getFrameHeight());
|
||||
|
||||
pushMatrix();
|
||||
glPushMatrix();
|
||||
frameBuffer().bindFramebuffer(true);
|
||||
|
||||
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
enableTexture2D();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
directionVariable.set(captureData.ordinal());
|
||||
worldRenderer.renderWorld(partialTicks, null);
|
||||
|
||||
frameBuffer().unbindFramebuffer();
|
||||
popMatrix();
|
||||
glPopMatrix();
|
||||
|
||||
return captureFrame(frameId, captureData);
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ import org.lwjgl.util.WritableDimension;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static net.minecraft.client.renderer.GlStateManager.*;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
||||
|
||||
public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData> implements FrameCapturer<F> {
|
||||
protected final WorldRenderer worldRenderer;
|
||||
@@ -76,16 +76,16 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
||||
protected OpenGlFrame renderFrame(int frameId, float partialTicks, D captureData) {
|
||||
resize(getFrameWidth(), getFrameHeight());
|
||||
|
||||
pushMatrix();
|
||||
GL11.glPushMatrix();
|
||||
frameBuffer().bindFramebuffer(true);
|
||||
|
||||
clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
enableTexture2D();
|
||||
GL11.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
GL11.glEnable(GL_TEXTURE_2D);
|
||||
|
||||
worldRenderer.renderWorld(partialTicks, captureData);
|
||||
|
||||
frameBuffer().unbindFramebuffer();
|
||||
popMatrix();
|
||||
GL11.glPopMatrix();
|
||||
|
||||
return captureFrame(frameId, captureData);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import org.lwjgl.util.ReadableDimension;
|
||||
public interface RenderInfo {
|
||||
ReadableDimension getFrameSize();
|
||||
|
||||
int getFramesDone();
|
||||
|
||||
int getTotalFrames();
|
||||
|
||||
float updateForNextFrame();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.replaymod.render.events;
|
||||
|
||||
import com.replaymod.render.rendering.VideoRenderer;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class ReplayRenderEvent extends Event {
|
||||
|
||||
109
src/main/java/com/replaymod/render/gui/GuiExportFailed.java
Normal file
109
src/main/java/com/replaymod/render/gui/GuiExportFailed.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package com.replaymod.render.gui;
|
||||
|
||||
import com.replaymod.render.RenderSettings;
|
||||
import com.replaymod.render.VideoWriter;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiVerticalList;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiElement;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.ReportedException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.replaymod.render.ReplayModRender.LOGGER;
|
||||
|
||||
public class GuiExportFailed extends GuiScreen {
|
||||
public static GuiExportFailed tryToRecover(VideoWriter.FFmpegStartupException e, Consumer<RenderSettings> doRestart) {
|
||||
// Always log the error first
|
||||
LOGGER.error("Rendering video:", e);
|
||||
|
||||
RenderSettings settings = e.getSettings();
|
||||
// Check whether the user has configured some custom ffmpeg arguments
|
||||
if (settings.getEncodingPreset().getValue().equals(settings.getExportArguments())) {
|
||||
// If they haven't, then this is probably a faulty ffmpeg installation and there's nothing we can do
|
||||
CrashReport crashReport = CrashReport.makeCrashReport(e, "Exporting video");
|
||||
CrashReportCategory details = crashReport.makeCategory("Export details");
|
||||
details.addCrashSection("Settings", settings);
|
||||
details.addCrashSection("FFmpeg log", e.getLog());
|
||||
throw new ReportedException(crashReport);
|
||||
} else {
|
||||
// If they have, ask them whether it was intentional
|
||||
GuiExportFailed gui = new GuiExportFailed(e, doRestart);
|
||||
gui.display();
|
||||
return gui;
|
||||
}
|
||||
}
|
||||
|
||||
private final GuiLabel logLabel = new GuiLabel(this)
|
||||
.setI18nText("replaymod.gui.rendering.error.ffmpeglog");
|
||||
private final GuiVerticalList logList = new GuiVerticalList(this).setDrawShadow(true);
|
||||
private final GuiButton resetButton = new GuiButton().setI18nLabel("gui.yes").setSize(100, 20);
|
||||
private final GuiButton abortButton = new GuiButton().setI18nLabel("gui.no").setSize(100, 20);
|
||||
private final GuiPanel info = new GuiPanel(this)
|
||||
.setLayout(new VerticalLayout().setSpacing(4))
|
||||
.addElements(new VerticalLayout.Data(0.5),
|
||||
new GuiLabel().setI18nText("replaymod.gui.rendering.error.ffmpegargs.1"),
|
||||
new GuiLabel().setI18nText("replaymod.gui.rendering.error.ffmpegargs.2"),
|
||||
new GuiLabel(),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.CENTER).setSpacing(5))
|
||||
.addElements(null, resetButton, abortButton)
|
||||
);
|
||||
|
||||
{
|
||||
setLayout(new CustomLayout<GuiScreen>() {
|
||||
@Override
|
||||
protected void layout(GuiScreen container, int width, int height) {
|
||||
pos(info, width/2 - width(info)/2, (height/2 - height(info) - 30) / 2 + 30);
|
||||
pos(logLabel, width/2 - width(logLabel)/2, height/2 + 4);
|
||||
pos(logList, 10, y(logLabel) + height(logLabel) + 4);
|
||||
size(logList, width - 10 - x(logList), height - 10 - y(logList));
|
||||
}
|
||||
});
|
||||
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.rendering.error.title"));
|
||||
setBackground(Background.DIRT);
|
||||
}
|
||||
|
||||
public GuiExportFailed(VideoWriter.FFmpegStartupException e, Consumer<RenderSettings> doRestart) {
|
||||
logList.getListPanel().addElements(null,
|
||||
Arrays.stream(e.getLog().replace("\t", " ").split("\n"))
|
||||
.map(l -> new GuiLabel().setText(l))
|
||||
.toArray(GuiElement[]::new));
|
||||
|
||||
resetButton.onClick(() -> {
|
||||
RenderSettings oldSettings = e.getSettings();
|
||||
doRestart.accept(new RenderSettings(
|
||||
oldSettings.getRenderMethod(),
|
||||
oldSettings.getEncodingPreset(),
|
||||
oldSettings.getVideoWidth(),
|
||||
oldSettings.getVideoHeight(),
|
||||
oldSettings.getFramesPerSecond(),
|
||||
oldSettings.getBitRate(),
|
||||
oldSettings.getOutputFile(),
|
||||
oldSettings.isRenderNameTags(),
|
||||
oldSettings.isStabilizeYaw(),
|
||||
oldSettings.isStabilizePitch(),
|
||||
oldSettings.isStabilizeRoll(),
|
||||
oldSettings.getChromaKeyingColor(),
|
||||
oldSettings.isInject360Metadata(),
|
||||
oldSettings.getAntiAliasing(),
|
||||
oldSettings.getExportCommand(),
|
||||
oldSettings.getEncodingPreset().getValue(),
|
||||
oldSettings.isHighPerformance()
|
||||
));
|
||||
});
|
||||
|
||||
abortButton.onClick(() -> {
|
||||
// Assume they know what they're doing
|
||||
getMinecraft().displayGuiScreen(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.replaymod.render.gui;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.replaymod.core.utils.Utils;
|
||||
import com.replaymod.render.ReplayModRender;
|
||||
import com.replaymod.render.VideoWriter;
|
||||
import com.replaymod.render.rendering.VideoRenderer;
|
||||
import com.replaymod.render.utils.RenderJob;
|
||||
import com.replaymod.replay.ReplayHandler;
|
||||
@@ -11,6 +14,7 @@ import com.replaymod.replaystudio.util.I18n;
|
||||
import de.johni0702.minecraft.gui.GuiRenderer;
|
||||
import de.johni0702.minecraft.gui.RenderInfo;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiClickableContainer;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.container.GuiVerticalList;
|
||||
@@ -25,12 +29,10 @@ import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||
import de.johni0702.minecraft.gui.utils.Colors;
|
||||
import net.minecraft.client.gui.GuiErrorScreen;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableDimension;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static com.replaymod.render.ReplayModRender.LOGGER;
|
||||
@@ -62,7 +64,8 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> {
|
||||
renameButton, removeButton),
|
||||
closeButton);
|
||||
|
||||
private final GuiContainer container;
|
||||
private final AbstractGuiScreen container;
|
||||
private final ReplayHandler replayHandler;
|
||||
private Entry selectedEntry;
|
||||
|
||||
{
|
||||
@@ -84,9 +87,10 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> {
|
||||
}).addElements(null, title, list, buttonPanel);
|
||||
}
|
||||
|
||||
public GuiRenderQueue(GuiContainer container, GuiRenderSettings guiRenderSettings, ReplayHandler replayHandler, Timeline timeline) {
|
||||
public GuiRenderQueue(AbstractGuiScreen container, GuiRenderSettings guiRenderSettings, ReplayHandler replayHandler, Timeline timeline) {
|
||||
super(container);
|
||||
this.container = container;
|
||||
this.replayHandler = replayHandler;
|
||||
LOGGER.trace("Opening render queue popup");
|
||||
|
||||
setBackgroundColor(Colors.DARK_TRANSPARENT);
|
||||
@@ -188,30 +192,46 @@ public class GuiRenderQueue extends AbstractGuiPopup<GuiRenderQueue> {
|
||||
|
||||
renderButton.onClick(() -> {
|
||||
LOGGER.trace("Render button clicked");
|
||||
// Close all GUIs (so settings in GuiRenderSettings are saved)
|
||||
getMinecraft().displayGuiScreen(null);
|
||||
// Start rendering
|
||||
for (RenderJob renderJob : queue) {
|
||||
LOGGER.info("Starting render job {}", renderJob);
|
||||
try {
|
||||
VideoRenderer videoRenderer = new VideoRenderer(renderJob.getSettings(), replayHandler, renderJob.getTimeline());
|
||||
videoRenderer.renderVideo();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Rendering video:", e);
|
||||
GuiErrorScreen errorScreen = new GuiErrorScreen(I18n.format("replaymod.gui.rendering.error.title"),
|
||||
I18n.format("replaymod.gui.rendering.error.message"));
|
||||
getMinecraft().displayGuiScreen(errorScreen);
|
||||
return;
|
||||
} catch (Throwable t) {
|
||||
CrashReport crashReport = CrashReport.makeCrashReport(t, "Rendering video");
|
||||
throw new ReportedException(crashReport);
|
||||
}
|
||||
}
|
||||
processQueue(queue);
|
||||
});
|
||||
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
private void processQueue(Iterable<RenderJob> queue) {
|
||||
// Close all GUIs (so settings in GuiRenderSettings are saved)
|
||||
getMinecraft().displayGuiScreen(null);
|
||||
// Start rendering
|
||||
int jobsDone = 0;
|
||||
for (RenderJob renderJob : queue) {
|
||||
LOGGER.info("Starting render job {}", renderJob);
|
||||
try {
|
||||
VideoRenderer videoRenderer = new VideoRenderer(renderJob.getSettings(), replayHandler, renderJob.getTimeline());
|
||||
videoRenderer.renderVideo();
|
||||
} catch (VideoWriter.NoFFmpegException e) {
|
||||
LOGGER.error("Rendering video:", e);
|
||||
GuiErrorScreen errorScreen = new GuiErrorScreen(I18n.format("replaymod.gui.rendering.error.title"),
|
||||
I18n.format("replaymod.gui.rendering.error.message"));
|
||||
getMinecraft().displayGuiScreen(errorScreen);
|
||||
return;
|
||||
} catch (VideoWriter.FFmpegStartupException e) {
|
||||
int jobsToSkip = jobsDone;
|
||||
GuiExportFailed.tryToRecover(e, newSettings -> {
|
||||
// Update current job with fixed ffmpeg arguments
|
||||
renderJob.setSettings(newSettings);
|
||||
// Restart queue, skipping the already completed jobs
|
||||
processQueue(Iterables.skip(queue, jobsToSkip));
|
||||
});
|
||||
return;
|
||||
} catch (Throwable t) {
|
||||
Utils.error(LOGGER, this, CrashReport.makeCrashReport(t, "Rendering video"), () -> {});
|
||||
container.display(); // Re-show the queue popup and the new error popup
|
||||
return;
|
||||
}
|
||||
jobsDone++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
super.open();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user