diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..8815f9b7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,29 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Build + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.5.0 + - name: Set up JDK 8 for x64 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + architecture: x64 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2.4.0 + with: + gradle-version: 4.10.3 + - name: Build TASmod with Gradle + run: gradle shadowJar + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: TASmod-Dev-Build + path: build/libs \ No newline at end of file diff --git a/.github/workflows/buildandupload.yml b/.github/workflows/buildandupload.yml new file mode 100644 index 00000000..c0ddb487 --- /dev/null +++ b/.github/workflows/buildandupload.yml @@ -0,0 +1,36 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Build and Upload to Discord + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + if: github.repository == 'MinecraftTAS/TASmod' + steps: + - uses: actions/checkout@v3.5.0 + - name: Set up JDK 8 for x64 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + architecture: x64 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2.4.0 + with: + gradle-version: 4.10.3 + - name: Build TASmod with Gradle + run: gradle shadowJar + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: TASmod-Dev-Build + path: build/libs + - name: Send file to discord channel + uses: sinshutu/upload-to-discord@master + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + with: + args: build/libs/TASmod-*.jar \ No newline at end of file diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index 1860807d..00000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,31 +0,0 @@ -# This workflow will build a Java project with Gradle -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: Java CI with Gradle - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 8 for x64 - uses: actions/setup-java@v2 - with: - java-version: '8' - distribution: 'adopt' - architecture: x64 - - name: Prepare folders - run: mkdir -p gradle/wrapper - - name: Download gradle properties - run: wget -P gradle/wrapper https://data.mgnet.work/tasmod/gradle-wrapper.properties - - name: Obtain gradle - run: wget -P gradle/wrapper https://data.mgnet.work/tasmod/gradle-wrapper.jar - - name: Build TASmod with Gradle - run: java -cp gradle/wrapper/gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain shadowJar --no-daemon - - run: find . -type f ! -name "*forge.jar" -delete - - uses: actions/upload-artifact@v2 - with: - name: TASmod-Dev-Build - path: build/libs diff --git a/.gitignore b/.gitignore index 2dffa767..b96c7fb2 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,5 @@ build # other eclipse -run +run/ logs/ \ No newline at end of file diff --git a/README.md b/README.md index 9349594b..2dc3ce39 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,16 @@ # TASmod -Lets you record and play back tickperfect inputs. - +A Tool-Assisted Speedrun-Mod for Minecraft 1.12.2. +Is able to capture inputs and play them back, by pretending to be a keyboard. + +To reduce complexity, all aspects of RNG-Manipulation have been externalized to a repository called [KillTheRNG](https://github.com/MinecraftTAS/KillTheRNG). It is now available as an optional dependency and a [standalone mod](https://maven.mgnet.work/#/main/com/minecrafttas/killtherng-full) + This mod is currently only for Forge 1.12.2 and will update/downgrade once 1.12.2 works properly -## Credits -Author of the original mod: tr7zw -Main Author: Scribble +> **New:** There are plans now to switch to Legacy-fabric, for downgrading, see [#101](https://github.com/MinecraftTAS/TASmod/issues/101). + +# Credits +Author of the original mod: [tr7zw](https://github.com/tr7zw/MC-TASmod) +Main Mod Author: Scribble Contributions by: famous1622, Pancake @@ -14,14 +19,65 @@ Tickrate 0 idea: [Cubitect](https://github.com/Cubitect/Cubitick) Savestate idea: [bspkrs, MightyPork](https://github.com/bspkrs-mods/WorldStateCheckpoints), although implementation is totally different now Special thanks: Darkmoon, The Minecraft TAS Community -## Commands -`/record` Starts to record your input, hit the same command again to stop recording -`/play` Starts to play back a the stored inputs -`/save ` Saves stored inputs to a file -`/load ` Load inputs from file -`/clearinputs` Delete all stored inputs, use this before starting a brand new recording. `/record` will resume the recording and not clear the inputs first. - -## Development -To load mixins in eclipse use `--mixin mixins.tasmod.json --tweakClass org.spongepowered.asm.launch.MixinTweaker` in program arguments - -You will also find a KillTheRNG.jar (not with -deobf at the end!) in the libs folder. Copy that into `run/mods` to trick Minecraft into loading a second mod. \ No newline at end of file +# Features +## Playback +This mod can record and play back +- The entire keyboard, minus TASmod keybinds (see below). +- Gui-Screens like crafting, the pause menu and the main menu! (Except the keybinding screen) +- Any screen size and window size (No warranties here...) + +### Commands +`/record` - Start a recording. This will record inputs to RAM. Closing the game will empty these inputs. +`/play` - Start to play back the stored inputs. +`/save ` - Save stored inputs to a file. +`/load ` - Load inputs from file. +`/clearinputs` - Delete all stored inputs, use this before starting a brand new recording. +`/record` - will resume the recording and not clear the inputs first. +`/playuntil ` - Stops the next playback at the specified tick number, then switches to a recording. Run this command then start a playback via `/play`. + +`/fullrecord, /fullplay` - Same as record/play however it will quit to the main menu first. +`/restartandplay ` - Quits Minecraft completely. When restarting, the specified file will be loaded and played back, when the menu appears. +### Keybinds +F10 - Stops either a playback or a recording. + +## Savestate +### Commands +`/savestate` - Prints a full guide to the savestate command in chat. +### Keybinds +J - Make a new savestate. +K - Load the most recent savestate. + +## Tickratechanger (Slowdown) +### Commands +`/tickrate ` - Changes the game speed. Default is 20, anthing below will slow the game down, anything above will speed it up. +### Keybinds +F8 - Enter "Tickrate 0". The game is paused but you can still look around. +F9 - While in tickrate 0, advance the tick by 1. By holding keyboardkeys, you can make inputs while tickadvancing. + +## Multiplayer support +**Important:** This is **NOT** a clientside mod, a server side installation is required a.k.a This doesn't work on Hypixel, 2b2t etc. These servers will **NEVER** be supported. + +Record TASes with friends! Needs operator permissions to run tasmod related commands. +/savestate can be used to manage savestates. + +> **Note:** /fullrecord, /fullplay and /restartandplay are not guaranteed to work in multiplayer at this time. + +## HUD +When ingame, hitting F6 will show you options for customising your HUD, with monitoring options and more. Even more options are available when KillTheRNG is installed. + +# Development +## Setup +1. Clone this repository and put it in your workspace directory (where you open eclipse or idea) +2. Import gradle project + - Use gradle version 4.10.3 + - Use [JDK 8](https://adoptium.net/en/temurin/releases/?version=8) +3. Run gradle tasks `setupDecompWorkspace` then `eclipse`. +4. *Optional but recommended:* Run gradle task `downloadKTRNG` (in the "tasmod" category) to download KillTheRNG to the run/mods folder. + +## Running +The task `eclipse` should've generated to launch configs: `TASmod_Client.launch` and `TASmod_Server.launch`. Select it, then click the run or debug button in your IDE. + +> **Note:** Additional setup is required for the server to actually start, like changing the eula.txt and setting `online-mode` to false in server.properties. + +## Building +Build the mod using the gradle task `build` (or alternatively `shadowJar`). \ No newline at end of file diff --git a/TASFile_Dark_Npp_language.xml b/TASFile_Dark_Npp_language.xml index ac97a526..9aa12cc2 100644 --- a/TASFile_Dark_Npp_language.xml +++ b/TASFile_Dark_Npp_language.xml @@ -1,11 +1,11 @@ - + - 00# 01 02 03 04 + 00# 00// 00$ 01 02 03 04 @@ -35,30 +35,30 @@ 00[ 01 02] 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.gradle b/build.gradle index 126e7f01..bea800b1 100644 --- a/build.gradle +++ b/build.gradle @@ -16,11 +16,10 @@ plugins { } apply plugin: 'net.minecraftforge.gradle.forge' apply plugin: 'org.spongepowered.mixin' -//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. -version = "Alpha8.1" -group = "de.scribble.lp.tastools" // http://maven.apache.org/guides/mini/guide-naming-conventions.html +version = "Alpha9" +group = "com.minecrafttas" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TASmod-1.12.2" sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. @@ -28,38 +27,34 @@ compileJava { sourceCompatibility = targetCompatibility = '1.8' } -shadowJar { - archiveName = "${archivesBaseName}-${version}-forge.jar" -} - minecraft { version = "1.12.2-14.23.5.2847" runDir = "run" - // the mappings can be changed at any time, and must be in the following format. - // snapshot_YYYYMMDD snapshot are built nightly. - // stable_# stables are built at the discretion of the MCP team. - // Use non-default mappings at your own risk. they may not always work. - // simply re-run your setup task after changing the mappings to update your workspace. mappings = "snapshot_20171003" makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. replace '${version}':project.version,'${mcversion}':project.minecraft.version clientRunArgs += "--mixin mixins.tasmod.json --tweakClass org.spongepowered.asm.launch.MixinTweaker" serverRunArgs += "--mixin mixins.tasmod.json --tweakClass org.spongepowered.asm.launch.MixinTweaker" } + repositories { mavenCentral() - maven { url = "https://maven.mgnet.work" } + maven { url = "https://maven.mgnet.work/main" } + maven { url 'https://jitpack.io' } maven { name = 'sponge' url = 'https://repo.spongepowered.org/maven' } } + +configurations { + downloadMod{ + transitive = false + } +} + dependencies { - // you may put jars on which you depend on in ./libs - // or you may define them like so.. - //compile "some.group:artifact:version:classifier" - //compile "some.group:artifact:version" compile('org.spongepowered:mixin:0.8.2') { exclude module: 'launchwrapper' exclude module: 'guava' @@ -69,26 +64,21 @@ dependencies { } compile 'org.msgpack:msgpack-core:0.8.16' compile 'org.msgpack:jackson-dataformat-msgpack:0.8.16' - compile files('libs/KillTheRNG-1.12.2-1.3-deobf.jar') + //compile files('libs/KillTheRNG-1.12.2-2.0-WIP-deobf.jar') + compile 'com.minecrafttas:killtherng:2.0-SNAPSHOT' //compile files('libs/BigArrayList-1.3.jar') compile 'com.dselent:bigarraylist:1.0' - // real examples - //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env - //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env - - // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. - //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' - - // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, - // except that these dependencies get remapped to your current MCP mappings - //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev' - //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev' - - // for more info... - // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html - // http://www.gradle.org/docs/current/userguide/dependency_management.html + + downloadMod 'com.minecrafttas:killtherng-full:2.0-SNAPSHOT' +} +task downloadKTRNG(type: Copy) { + group 'tasmod' + description 'Downloads KillTheRNG to the run/mods/ folder of the project' + from configurations.downloadMod + into 'run/mods/' } + jar { manifest { attributes 'FMLAT': 'tasmod_at.cfg', @@ -100,38 +90,48 @@ jar { } processResources { - // this will ensure that this task is redone when the versions change. inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version - // replace stuff in mcmod.info, nothing else from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' // replace version and mcversion expand 'version':project.version, 'mcversion':project.minecraft.version } - // copy everything else except the mcmod.info from(sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } } + shadowJar { + archiveName = "${archivesBaseName}-${version}-shadow.jar" mainSpec.sourcePaths.clear() dependsOn reobfJar configurations = [project.configurations.compile] - relocate 'org.msgpack', 'de.scribble.lp.tasmod.repack.org.msgpack' - relocate 'com.fasterxml', 'de.scribble.lp.tasmod.repack.com.fasterxml' + relocate 'org.msgpack', 'com.minecrafttas.tasmod.repack.org.msgpack' + relocate 'com.fasterxml', 'com.minecrafttas.tasmod.repack.com.fasterxml' classifier "shadow" exclude 'dummyThing' - exclude 'de/scribble/lp/killtherng/', 'assets/killtherng/', 'mixins.killtherng.json', 'kaptainwutax/', 'com/seedfinding/' + exclude 'com/minecrafttas/killtherng/', 'assets/killtherng/', 'mixins.killtherng.json', 'mixins.killtherng.refmap.json', 'kaptainwutax/', 'com/seedfinding/' afterEvaluate { from zipTree(reobfJar.jar) } + + //Rename delete the mixinless version and rename the shadow jar + doLast { + delete("${buildDir}/libs/${archivesBaseName}-${version}.jar") + ant.move(file:"build/libs/${archivesBaseName}-${version}-shadow.jar", tofile:"build/libs/${archivesBaseName}-${version}.jar") + } } + +artifacts { + archives shadowJar +} + mixin { // Specify "notch" or "searge" here defaultObfuscationEnv searge diff --git a/libs/KillTheRNG-1.12.2-1.3-deobf.jar b/libs/KillTheRNG-1.12.2-1.3-deobf.jar deleted file mode 100644 index 4a682d94..00000000 Binary files a/libs/KillTheRNG-1.12.2-1.3-deobf.jar and /dev/null differ diff --git a/libs/KillTheRNG-1.12.2-1.3.jar b/libs/KillTheRNG-1.12.2-1.3.jar deleted file mode 100644 index cac0515a..00000000 Binary files a/libs/KillTheRNG-1.12.2-1.3.jar and /dev/null differ diff --git a/src/main/java/de/scribble/lp/tasmod/ClientProxy.java b/src/main/java/com/minecrafttas/tasmod/ClientProxy.java similarity index 52% rename from src/main/java/de/scribble/lp/tasmod/ClientProxy.java rename to src/main/java/com/minecrafttas/tasmod/ClientProxy.java index 4aaf4eb4..e931a458 100644 --- a/src/main/java/de/scribble/lp/tasmod/ClientProxy.java +++ b/src/main/java/com/minecrafttas/tasmod/ClientProxy.java @@ -1,18 +1,22 @@ -package de.scribble.lp.tasmod; +package com.minecrafttas.tasmod; import java.io.File; import org.lwjgl.input.Keyboard; -import de.pfannekuchen.infogui.gui.InfoHud; -import de.pfannekuchen.tasmod.events.AimAssistEvents; -import de.pfannekuchen.tasmod.events.CameraInterpolationEvents; -import de.scribble.lp.tasmod.commands.tutorial.TutorialHandler; -import de.scribble.lp.tasmod.events.PlayerJoinLeaveEvents; -import de.scribble.lp.tasmod.shield.ShieldDownloader; -import de.scribble.lp.tasmod.util.ContainerSerialiser; -import de.scribble.lp.tasmod.virtual.VirtualInput; -import de.scribble.lp.tasmod.virtual.VirtualKeybindings; +import com.minecrafttas.tasmod.commands.tutorial.TutorialHandler; +import com.minecrafttas.tasmod.events.AimAssistEvents; +import com.minecrafttas.tasmod.events.CameraInterpolationEvents; +import com.minecrafttas.tasmod.events.KeybindingEvents; +import com.minecrafttas.tasmod.events.PlayerJoinLeaveEvents; +import com.minecrafttas.tasmod.gui.InfoHud; +import com.minecrafttas.tasmod.networking.TASmodNetworkClient; +import com.minecrafttas.tasmod.playback.PlaybackSerialiser; +import com.minecrafttas.tasmod.util.ShieldDownloader; +import com.minecrafttas.tasmod.util.TickScheduler; +import com.minecrafttas.tasmod.virtual.VirtualInput; +import com.minecrafttas.tasmod.virtual.VirtualKeybindings; + import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import net.minecraft.launchwrapper.Launch; @@ -31,25 +35,9 @@ public class ClientProxy extends CommonProxy { public static boolean isDevEnvironment; - public static KeyBinding tickratezeroKey = new KeyBinding("Tickrate 0 Key", Keyboard.KEY_F8, "TASmod"); - - public static KeyBinding tickAdvance = new KeyBinding("Advance Tick", Keyboard.KEY_F9, "TASmod"); - - public static KeyBinding stopkey = new KeyBinding("Recording/Playback Stop", Keyboard.KEY_F10, "TASmod"); - - public static KeyBinding savestateSaveKey = new KeyBinding("Create Savestate", Keyboard.KEY_J, "TASmod"); - - public static KeyBinding savestateLoadKey = new KeyBinding("Load Latest Savestate", Keyboard.KEY_K, "TASmod"); - - public static KeyBinding testingKey = new KeyBinding("Various Testing", Keyboard.KEY_F12, "TASmod"); - - public static KeyBinding infoGuiKey = new KeyBinding("Open InfoGui Editor", Keyboard.KEY_F6, "TASmod"); - - public static KeyBinding bufferViewKey = new KeyBinding("Buffer View", Keyboard.KEY_NUMPAD0, "TASmod"); - public static VirtualInput virtual; - public static ContainerSerialiser serialiser = new ContainerSerialiser(); + public static PlaybackSerialiser serialiser = new PlaybackSerialiser(); public static final String tasdirectory = Minecraft.getMinecraft().mcDataDir.getAbsolutePath() + File.separator + "saves" + File.separator + "tasfiles"; @@ -59,6 +47,12 @@ public class ClientProxy extends CommonProxy { public static ShieldDownloader shieldDownloader; + public static TASmodNetworkClient packetClient; + + public static TickScheduler gameLoopSchedulerClient = new TickScheduler(); + + public static TickScheduler tickSchedulerClient = new TickScheduler(); + public void preInit(FMLPreInitializationEvent ev) { isDevEnvironment = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); playbackTutorial = new TutorialHandler((short) 1); @@ -92,24 +86,30 @@ public void init(FMLInitializationEvent ev) { //It pains me to do this ._. MinecraftForge.EVENT_BUS.register(new PlayerJoinLeaveEvents()); - ClientRegistry.registerKeyBinding(tickratezeroKey); - ClientRegistry.registerKeyBinding(tickAdvance); - ClientRegistry.registerKeyBinding(stopkey); - ClientRegistry.registerKeyBinding(savestateSaveKey); - ClientRegistry.registerKeyBinding(savestateLoadKey); - ClientRegistry.registerKeyBinding(testingKey); - ClientRegistry.registerKeyBinding(infoGuiKey); - ClientRegistry.registerKeyBinding(bufferViewKey); + ClientRegistry.registerKeyBinding(KeybindingEvents.tickratezeroKey); + ClientRegistry.registerKeyBinding(KeybindingEvents.tickAdvance); + ClientRegistry.registerKeyBinding(KeybindingEvents.stopkey); + ClientRegistry.registerKeyBinding(KeybindingEvents.savestateSaveKey); + ClientRegistry.registerKeyBinding(KeybindingEvents.savestateLoadKey); + ClientRegistry.registerKeyBinding(KeybindingEvents.testingKey); + ClientRegistry.registerKeyBinding(KeybindingEvents.infoGuiKey); + ClientRegistry.registerKeyBinding(KeybindingEvents.bufferViewKey); + + if(TASmod.ktrngHandler.isLoaded()) { + KeybindingEvents.ktrngKey=new KeyBinding("KTRNG SeedChange Pause", Keyboard.KEY_B, "TASmod"); + ClientRegistry.registerKeyBinding(KeybindingEvents.ktrngKey); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.ktrngKey); + } - VirtualKeybindings.registerBlockedKeyBinding(tickratezeroKey); - VirtualKeybindings.registerBlockedKeyBinding(tickAdvance); - VirtualKeybindings.registerBlockedKeyBinding(stopkey); - VirtualKeybindings.registerBlockedKeyBinding(savestateSaveKey); - VirtualKeybindings.registerBlockedKeyBinding(savestateLoadKey); - VirtualKeybindings.registerBlockedKeyBinding(testingKey); - VirtualKeybindings.registerBlockedKeyBinding(infoGuiKey); - VirtualKeybindings.registerBlockedKeyBinding(bufferViewKey); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.tickratezeroKey); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.tickAdvance); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.stopkey); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.savestateSaveKey); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.savestateLoadKey); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.testingKey); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.infoGuiKey); + VirtualKeybindings.registerBlockedKeyBinding(KeybindingEvents.bufferViewKey); createTASDir(); createSavestatesDir(); diff --git a/src/main/java/com/minecrafttas/tasmod/CommonProxy.java b/src/main/java/com/minecrafttas/tasmod/CommonProxy.java new file mode 100644 index 00000000..95ada9bb --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/CommonProxy.java @@ -0,0 +1,104 @@ +package com.minecrafttas.tasmod; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.minecrafttas.tasmod.commands.clearinputs.ClearInputsPacket; +import com.minecrafttas.tasmod.commands.folder.FolderPacket; +import com.minecrafttas.tasmod.commands.fullplay.FullPlayPacket; +import com.minecrafttas.tasmod.commands.fullrecord.FullRecordPacket; +import com.minecrafttas.tasmod.commands.loadtas.LoadTASPacket; +import com.minecrafttas.tasmod.commands.playuntil.PlayUntilPacket; +import com.minecrafttas.tasmod.commands.restartandplay.RestartAndPlayPacket; +import com.minecrafttas.tasmod.commands.savetas.SaveTASPacket; +import com.minecrafttas.tasmod.ktrng.KTRNGSeedPacket; +import com.minecrafttas.tasmod.ktrng.KTRNGStartSeedPacket; +import com.minecrafttas.tasmod.networking.IdentificationPacket; +import com.minecrafttas.tasmod.networking.PacketSerializer; +import com.minecrafttas.tasmod.playback.PlaybackController; +import com.minecrafttas.tasmod.playback.server.InitialSyncStatePacket; +import com.minecrafttas.tasmod.playback.server.SyncStatePacket; +import com.minecrafttas.tasmod.savestates.client.InputSavestatesPacket; +import com.minecrafttas.tasmod.savestates.server.LoadstatePacket; +import com.minecrafttas.tasmod.savestates.server.SavestatePacket; +import com.minecrafttas.tasmod.savestates.server.motion.MotionPacket; +import com.minecrafttas.tasmod.savestates.server.motion.RequestMotionPacket; +import com.minecrafttas.tasmod.savestates.server.playerloading.SavestatePlayerLoadingPacket; +import com.minecrafttas.tasmod.tickratechanger.AdvanceTickratePacket; +import com.minecrafttas.tasmod.tickratechanger.ChangeTickratePacket; +import com.minecrafttas.tasmod.tickratechanger.PauseTickratePacket; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; +import com.minecrafttas.tasmod.ticksync.TickSyncPacket; +import com.minecrafttas.tasmod.util.TickScheduler; + +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.network.simpleimpl.SimpleNetworkWrapper; + +public class CommonProxy { + public static SimpleNetworkWrapper NETWORK; + public static Logger logger = LogManager.getLogger("TASmod"); + + public static TickScheduler tickSchedulerServer = new TickScheduler(); + + public void preInit(FMLPreInitializationEvent ev) { + + TickrateChangerServer.logger = logger; + + + PacketSerializer.registerPacket(IdentificationPacket.class); + // Ticksync + PacketSerializer.registerPacket(TickSyncPacket.class); + + + //Tickratechanger + PacketSerializer.registerPacket(ChangeTickratePacket.class); + PacketSerializer.registerPacket(PauseTickratePacket.class); + PacketSerializer.registerPacket(AdvanceTickratePacket.class); + + + // Savestates + PacketSerializer.registerPacket(SavestatePacket.class); + PacketSerializer.registerPacket(LoadstatePacket.class); + + PacketSerializer.registerPacket(InputSavestatesPacket.class); + PacketSerializer.registerPacket(SavestatePlayerLoadingPacket.class); + + PacketSerializer.registerPacket(RequestMotionPacket.class); + PacketSerializer.registerPacket(MotionPacket.class); + + // KillTheRNG + PacketSerializer.registerPacket(KTRNGSeedPacket.class); + PacketSerializer.registerPacket(KTRNGStartSeedPacket.class); + + // Recording/Playback + PacketSerializer.registerPacket(SyncStatePacket.class); + PacketSerializer.registerPacket(InitialSyncStatePacket.class); + + PacketSerializer.registerPacket(ClearInputsPacket.class); + + PacketSerializer.registerPacket(FullRecordPacket.class); + PacketSerializer.registerPacket(FullPlayPacket.class); + + PacketSerializer.registerPacket(RestartAndPlayPacket.class); + + // Storing + PacketSerializer.registerPacket(SaveTASPacket.class); + PacketSerializer.registerPacket(LoadTASPacket.class); + + // Misc + PacketSerializer.registerPacket(PlaybackController.TeleportPlayerPacket.class); + PacketSerializer.registerPacket(FolderPacket.class); + + PacketSerializer.registerPacket(PlayUntilPacket.class); + + } + + public void init(FMLInitializationEvent ev) { + } + + public void postInit(FMLPostInitializationEvent ev) { + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/Config.java b/src/main/java/com/minecrafttas/tasmod/Config.java similarity index 92% rename from src/main/java/de/scribble/lp/tasmod/Config.java rename to src/main/java/com/minecrafttas/tasmod/Config.java index 971c24d5..1f55832e 100644 --- a/src/main/java/de/scribble/lp/tasmod/Config.java +++ b/src/main/java/com/minecrafttas/tasmod/Config.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod; +package com.minecrafttas.tasmod; import net.minecraftforge.common.config.Configuration; diff --git a/src/main/java/de/scribble/lp/tasmod/InfoGui.java b/src/main/java/com/minecrafttas/tasmod/InfoGui.java similarity index 82% rename from src/main/java/de/scribble/lp/tasmod/InfoGui.java rename to src/main/java/com/minecrafttas/tasmod/InfoGui.java index d59c122c..e66a2c0e 100644 --- a/src/main/java/de/scribble/lp/tasmod/InfoGui.java +++ b/src/main/java/com/minecrafttas/tasmod/InfoGui.java @@ -1,10 +1,10 @@ -package de.scribble.lp.tasmod; +package com.minecrafttas.tasmod; import org.lwjgl.opengl.Display; +import com.minecrafttas.tasmod.playback.controlbytes.ControlByteHandler; import com.mojang.realmsclient.gui.ChatFormatting; -import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; @@ -16,7 +16,7 @@ * The InfoGui returns! * Pancake says: No it doesn't. * - * @author ScribbleLP + * @author Scribble * */ public class InfoGui extends Gui { @@ -51,7 +51,7 @@ public void drawStuff(RenderGameOverlayEvent.Post event) { // new Gui().drawString(mc.fontRenderer, "Client Ticks: " + TickSync.getClienttickcounter(), 16, 110, 0xFFFFFF); // Current Pointer location // // new Gui().drawString(mc.fontRenderer, "EntitySeed: "+ EntityRandom.currentSeed, 16, 130, 0xFFFFFF); // Current Pointer location -// new Gui().drawString(mc.fontRenderer, "ItemSeed: "+ ItemRandom.currentSeed, 16, 140, 0xFFFFFF); // Current Pointer location +// drawString(mc.fontRenderer, "RandomServer: "+ TASmod.ktrngHandler.getGlobalSeedServer(), 2, 130, 0xFFFFFF); // Current Pointer location // // EntityPlayerSP player=Minecraft.getMinecraft().player; @@ -64,7 +64,7 @@ public void drawStuff(RenderGameOverlayEvent.Post event) { for (String mouse : ClientProxy.virtual.getNextMousePresses()) { out1 = out1.concat(mouse + " "); } - new Gui().drawString(mc.fontRenderer, out1, 5, height - 20, 0xFFFFFF); // Current Pointer location + drawString(mc.fontRenderer, out1, 5, height - 20, 0xFFFFFF); // Current Pointer location String out2 = ""; for (String key : ClientProxy.virtual.getCurrentKeyboardPresses()) { @@ -74,12 +74,12 @@ public void drawStuff(RenderGameOverlayEvent.Post event) { for (String key : ClientProxy.virtual.getNextKeyboardPresses()) { out2 = out2.concat(key + " "); } - new Gui().drawString(mc.fontRenderer, out2, 5, height - 10, 0xFFFFFF); // Current Pointer location + drawString(mc.fontRenderer, out2, 5, height - 10, 0xFFFFFF); // Current Pointer location } - new Gui().drawString(mc.fontRenderer, ClientProxy.virtual.getContainer().index() + "", 5, height - 30, 0xFFFFFF); // Current Pointer location - new Gui().drawCenteredString(mc.fontRenderer, "TASmod is still in development! Major issues may arise!", width / 2, height - 50, 0xFF8400); // Current Pointer location + drawString(mc.fontRenderer, ClientProxy.virtual.getContainer().index() + "", 5, height - 30, 0xFFFFFF); // Current Pointer location + drawCenteredString(mc.fontRenderer, "TASmod is still in development! Major issues may arise!", width / 2, height - 50, 0xFF8400); // Current Pointer location // } // if (Strokesenabled) { diff --git a/src/main/java/de/scribble/lp/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java similarity index 70% rename from src/main/java/de/scribble/lp/tasmod/TASmod.java rename to src/main/java/com/minecrafttas/tasmod/TASmod.java index 6651329e..97c916a9 100644 --- a/src/main/java/de/scribble/lp/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod; +package com.minecrafttas.tasmod; import java.io.File; import java.io.IOException; @@ -6,28 +6,31 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import de.scribble.lp.killtherng.KillTheRNG; -import de.scribble.lp.tasmod.commands.clearinputs.CommandClearInputs; -import de.scribble.lp.tasmod.commands.folder.CommandFolder; -import de.scribble.lp.tasmod.commands.fullplay.CommandFullPlay; -import de.scribble.lp.tasmod.commands.fullrecord.CommandFullRecord; -import de.scribble.lp.tasmod.commands.loadtas.CommandLoadTAS; -import de.scribble.lp.tasmod.commands.playback.CommandPlay; -import de.scribble.lp.tasmod.commands.recording.CommandRecord; -import de.scribble.lp.tasmod.commands.restartandplay.CommandRestartAndPlay; -import de.scribble.lp.tasmod.commands.savetas.CommandSaveTAS; -import de.scribble.lp.tasmod.commands.tutorial.CommandPlaybacktutorial; -import de.scribble.lp.tasmod.savestates.server.SavestateCommand; -import de.scribble.lp.tasmod.savestates.server.SavestateHandler; -import de.scribble.lp.tasmod.savestates.server.SavestateTrackerFile; -import de.scribble.lp.tasmod.tickratechanger.CommandTickrate; -import de.scribble.lp.tasmod.util.ModIncompatibleException; -import de.scribble.lp.tasmod.util.changestates.ContainerStateServer; +import com.minecrafttas.tasmod.commands.clearinputs.CommandClearInputs; +import com.minecrafttas.tasmod.commands.folder.CommandFolder; +import com.minecrafttas.tasmod.commands.fullplay.CommandFullPlay; +import com.minecrafttas.tasmod.commands.fullrecord.CommandFullRecord; +import com.minecrafttas.tasmod.commands.loadtas.CommandLoadTAS; +import com.minecrafttas.tasmod.commands.playback.CommandPlay; +import com.minecrafttas.tasmod.commands.playuntil.CommandPlayUntil; +import com.minecrafttas.tasmod.commands.recording.CommandRecord; +import com.minecrafttas.tasmod.commands.restartandplay.CommandRestartAndPlay; +import com.minecrafttas.tasmod.commands.savetas.CommandSaveTAS; +import com.minecrafttas.tasmod.commands.tutorial.CommandPlaybacktutorial; +import com.minecrafttas.tasmod.ktrng.KillTheRNGHandler; +import com.minecrafttas.tasmod.networking.TASmodNetworkServer; +import com.minecrafttas.tasmod.playback.server.TASstateServer; +import com.minecrafttas.tasmod.savestates.server.SavestateCommand; +import com.minecrafttas.tasmod.savestates.server.SavestateHandler; +import com.minecrafttas.tasmod.savestates.server.files.SavestateTrackerFile; +import com.minecrafttas.tasmod.tickratechanger.CommandTickrate; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; +import com.minecrafttas.tasmod.util.ModIncompatibleException; + import net.minecraft.server.MinecraftServer; 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.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; @@ -39,15 +42,13 @@ /** * ModLoader for TASmod * - * @author ScribbleLP + * @author Scribble * */ @Mod(modid = "tasmod", name = "Tool-Assisted Speedrun Mod", version = TASmod.VERSION) public class TASmod { - @Instance - public static TASmod instance = new TASmod(); - @SidedProxy(serverSide = "de.scribble.lp.tasmod.CommonProxy", clientSide = "de.scribble.lp.tasmod.ClientProxy") + @SidedProxy(serverSide = "com.minecrafttas.tasmod.CommonProxy", clientSide = "com.minecrafttas.tasmod.ClientProxy") public static CommonProxy proxy; public static final String VERSION = "${version}"; @@ -55,16 +56,21 @@ public class TASmod { private static MinecraftServer serverInstance; - public static boolean isKTRNGLoaded; - public static final Logger logger = LogManager.getLogger("TASMod"); - public static ContainerStateServer containerStateServer; + public static TASstateServer containerStateServer; public static SavestateHandler savestateHandler; + + public static KillTheRNGHandler ktrngHandler; + + public static TASmodNetworkServer packetServer; @EventHandler public void preInit(FMLPreInitializationEvent ev) throws Exception { + logger.info("Initializing TASmod"); + logger.info("Testing connection with KillTheRNG"); + ktrngHandler=new KillTheRNGHandler(Loader.isModLoaded("killtherng")); proxy.preInit(ev); if (Loader.isModLoaded("tastools")) { throw new ModIncompatibleException("\n========================================================================\n" + "\n" + "Detected TASTools to be loaded. TASMod and TASTools are incompatible!\n" + "\n" + "========================================================================"); @@ -91,14 +97,6 @@ public void preInit(FMLPreInitializationEvent ev) throws Exception { @EventHandler public void init(FMLInitializationEvent ev) { - logger.info("Initializing TASmod"); - logger.info("Testing connection with KillTheRNG"); - isKTRNGLoaded=Loader.isModLoaded("killtherng"); - if (isKTRNGLoaded) { - KillTheRNG.LOGGER.info("Connection established with TASmod"); - }else { - logger.info("KillTheRNG doesn't appear to be loaded"); - } proxy.init(ev); } @@ -110,7 +108,7 @@ public void postInit(FMLPostInitializationEvent ev) { @EventHandler public void serverStart(FMLServerStartingEvent ev) { serverInstance = ev.getServer(); - containerStateServer=new ContainerStateServer(); + containerStateServer=new TASstateServer(); // Command handling ev.registerServerCommand(new CommandTickrate()); ev.registerServerCommand(new CommandRecord()); @@ -124,6 +122,7 @@ public void serverStart(FMLServerStartingEvent ev) { ev.registerServerCommand(new CommandFullRecord()); ev.registerServerCommand(new CommandFullPlay()); ev.registerServerCommand(new CommandRestartAndPlay()); + ev.registerServerCommand(new CommandPlayUntil()); // Save Loadstate Count File savestateDirectory = new File(serverInstance.getDataDirectory() + File.separator + "saves" + File.separator + "savestates" + File.separator); @@ -133,16 +132,24 @@ public void serverStart(FMLServerStartingEvent ev) { e.printStackTrace(); } - savestateHandler=new SavestateHandler(ev.getServer()); + savestateHandler=new SavestateHandler(ev.getServer(), logger); + + try { + packetServer = new TASmodNetworkServer(logger); + } catch (IOException e) { + e.printStackTrace(); + } + + if(!serverInstance.isDedicatedServer()) { + TickrateChangerServer.ticksPerSecond=0F; + TickrateChangerServer.tickrateSaved=20F; + } } @EventHandler public void serverStop(FMLServerStoppingEvent ev) { serverInstance=null; - } - - public static TASmod getInstance() { - return instance; + packetServer.close(); } public static MinecraftServer getServerInstance() { diff --git a/src/main/java/com/minecrafttas/tasmod/commands/clearinputs/ClearInputsPacket.java b/src/main/java/com/minecrafttas/tasmod/commands/clearinputs/ClearInputsPacket.java new file mode 100644 index 00000000..9b6a9f9f --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/clearinputs/ClearInputsPacket.java @@ -0,0 +1,41 @@ +package com.minecrafttas.tasmod.commands.clearinputs; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; + +public class ClearInputsPacket implements Packet{ + + @Override + public void handle(PacketSide side, EntityPlayer playerz) { + if(side.isServer()) { + EntityPlayerMP player = (EntityPlayerMP)playerz; + player.getServerWorld().addScheduledTask(()->{ + if(player.canUseCommand(2, "clearinputs")) { + TASmod.packetServer.sendToAll(this); + } + }); + } else { + Minecraft.getMinecraft().addScheduledTask(()->{ + ClientProxy.virtual.getContainer().clear(); + }); + } + + } + + @Override + public void serialize(PacketBuffer buf) { + + } + + @Override + public void deserialize(PacketBuffer buf) { + + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/clearinputs/CommandClearInputs.java b/src/main/java/com/minecrafttas/tasmod/commands/clearinputs/CommandClearInputs.java similarity index 81% rename from src/main/java/de/scribble/lp/tasmod/commands/clearinputs/CommandClearInputs.java rename to src/main/java/com/minecrafttas/tasmod/commands/clearinputs/CommandClearInputs.java index 35cc0eea..e37f89f8 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/clearinputs/CommandClearInputs.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/clearinputs/CommandClearInputs.java @@ -1,6 +1,7 @@ -package de.scribble.lp.tasmod.commands.clearinputs; +package com.minecrafttas.tasmod.commands.clearinputs; + +import com.minecrafttas.tasmod.TASmod; -import de.scribble.lp.tasmod.CommonProxy; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; @@ -22,7 +23,7 @@ public String getUsage(ICommandSender sender) { @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if(sender instanceof EntityPlayer) { - CommonProxy.NETWORK.sendToAll(new ClearInputsPacket()); + TASmod.packetServer.sendToAll(new ClearInputsPacket()); } } @Override diff --git a/src/main/java/de/scribble/lp/tasmod/commands/folder/CommandFolder.java b/src/main/java/com/minecrafttas/tasmod/commands/folder/CommandFolder.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/commands/folder/CommandFolder.java rename to src/main/java/com/minecrafttas/tasmod/commands/folder/CommandFolder.java index ad8a4d2d..1876c9cd 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/folder/CommandFolder.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/folder/CommandFolder.java @@ -1,9 +1,10 @@ -package de.scribble.lp.tasmod.commands.folder; +package com.minecrafttas.tasmod.commands.folder; import java.util.ArrayList; import java.util.List; -import de.scribble.lp.tasmod.CommonProxy; +import com.minecrafttas.tasmod.TASmod; + import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; @@ -21,7 +22,7 @@ public String getName() { @Override public String getUsage(ICommandSender sender) { return "/folder "; - } + } @Override public int getRequiredPermissionLevel() { @@ -32,9 +33,9 @@ public int getRequiredPermissionLevel() { public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (args.length == 1) { if (args[0].equalsIgnoreCase("savestates")) { - CommonProxy.NETWORK.sendTo(new FolderPacket(0), (EntityPlayerMP) sender); + TASmod.packetServer.sendTo(new FolderPacket(0), (EntityPlayerMP) sender); } else if (args[0].equalsIgnoreCase("tasfiles")) { - CommonProxy.NETWORK.sendTo(new FolderPacket(1), (EntityPlayerMP) sender); + TASmod.packetServer.sendTo(new FolderPacket(1), (EntityPlayerMP) sender); } } } diff --git a/src/main/java/com/minecrafttas/tasmod/commands/folder/FolderPacket.java b/src/main/java/com/minecrafttas/tasmod/commands/folder/FolderPacket.java new file mode 100644 index 00000000..cb805329 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/folder/FolderPacket.java @@ -0,0 +1,49 @@ +package com.minecrafttas.tasmod.commands.folder; + +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +public class FolderPacket implements Packet { + int command; + + public FolderPacket() { + } + + /** + * 0: Open savestates folder + * 1: Open TASdir folder + * @param command The folder to open + */ + public FolderPacket(int command) { + this.command=command; + } + + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isClient()) { + switch(command) { + case 0: + OpenStuff.openSavestates(); + break; + case 1: + OpenStuff.openTASFolder(); + break; + } + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeInt(command); + } + + @Override + public void deserialize(PacketBuffer buf) { + command=buf.readInt(); + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/folder/OpenStuff.java b/src/main/java/com/minecrafttas/tasmod/commands/folder/OpenStuff.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/commands/folder/OpenStuff.java rename to src/main/java/com/minecrafttas/tasmod/commands/folder/OpenStuff.java index 3c359f9e..a12da837 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/folder/OpenStuff.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/folder/OpenStuff.java @@ -1,11 +1,11 @@ -package de.scribble.lp.tasmod.commands.folder; +package com.minecrafttas.tasmod.commands.folder; import java.awt.Desktop; import java.io.File; import java.io.IOException; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.CommonProxy; public class OpenStuff { diff --git a/src/main/java/de/scribble/lp/tasmod/commands/fullplay/CommandFullPlay.java b/src/main/java/com/minecrafttas/tasmod/commands/fullplay/CommandFullPlay.java similarity index 75% rename from src/main/java/de/scribble/lp/tasmod/commands/fullplay/CommandFullPlay.java rename to src/main/java/com/minecrafttas/tasmod/commands/fullplay/CommandFullPlay.java index 149b384f..f9b68d0d 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/fullplay/CommandFullPlay.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/fullplay/CommandFullPlay.java @@ -1,10 +1,10 @@ -package de.scribble.lp.tasmod.commands.fullplay; +package com.minecrafttas.tasmod.commands.fullplay; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.savestates.server.SavestateState; +import com.minecrafttas.tasmod.savestates.server.exceptions.LoadstateException; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.savestates.server.SavestateState; -import de.scribble.lp.tasmod.savestates.server.exceptions.LoadstateException; -import de.scribble.lp.tasmod.util.TASstate; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; @@ -39,7 +39,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args TASmod.savestateHandler.state=SavestateState.NONE; } TASmod.containerStateServer.setServerState(TASstate.PLAYBACK); - CommonProxy.NETWORK.sendToAll(new FullPlayPacket()); + TASmod.packetServer.sendToAll(new FullPlayPacket()); } } diff --git a/src/main/java/com/minecrafttas/tasmod/commands/fullplay/FullPlayPacket.java b/src/main/java/com/minecrafttas/tasmod/commands/fullplay/FullPlayPacket.java new file mode 100644 index 00000000..4d3f326c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/fullplay/FullPlayPacket.java @@ -0,0 +1,38 @@ +package com.minecrafttas.tasmod.commands.fullplay; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.events.OpenGuiEvents; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiMainMenu; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +public class FullPlayPacket implements Packet { + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isClient()) { + OpenGuiEvents.stateWhenOpened = TASstate.PLAYBACK; + Minecraft mc = Minecraft.getMinecraft(); + ClientProxy.tickSchedulerClient.add(()->{ + mc.world.sendQuittingDisconnectingPacket(); + mc.loadWorld((WorldClient) null); + mc.displayGuiScreen(new GuiMainMenu()); + }); + } + } + + @Override + public void serialize(PacketBuffer buf) { + } + + @Override + public void deserialize(PacketBuffer buf) { + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/fullrecord/CommandFullRecord.java b/src/main/java/com/minecrafttas/tasmod/commands/fullrecord/CommandFullRecord.java similarity index 75% rename from src/main/java/de/scribble/lp/tasmod/commands/fullrecord/CommandFullRecord.java rename to src/main/java/com/minecrafttas/tasmod/commands/fullrecord/CommandFullRecord.java index c8df3725..c7145ff4 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/fullrecord/CommandFullRecord.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/fullrecord/CommandFullRecord.java @@ -1,10 +1,10 @@ -package de.scribble.lp.tasmod.commands.fullrecord; +package com.minecrafttas.tasmod.commands.fullrecord; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.savestates.server.SavestateState; +import com.minecrafttas.tasmod.savestates.server.exceptions.SavestateException; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.savestates.server.SavestateState; -import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateException; -import de.scribble.lp.tasmod.util.TASstate; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; @@ -39,7 +39,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args TASmod.savestateHandler.state = SavestateState.NONE; } TASmod.containerStateServer.setServerState(TASstate.RECORDING); - CommonProxy.NETWORK.sendToAll(new FullRecordPacket()); + TASmod.packetServer.sendToAll(new FullRecordPacket()); } } diff --git a/src/main/java/com/minecrafttas/tasmod/commands/fullrecord/FullRecordPacket.java b/src/main/java/com/minecrafttas/tasmod/commands/fullrecord/FullRecordPacket.java new file mode 100644 index 00000000..8be0897e --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/fullrecord/FullRecordPacket.java @@ -0,0 +1,41 @@ +package com.minecrafttas.tasmod.commands.fullrecord; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.events.OpenGuiEvents; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiMainMenu; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +public class FullRecordPacket implements Packet{ + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isClient()) { + OpenGuiEvents.stateWhenOpened = TASstate.RECORDING; + ClientProxy.virtual.getContainer().clear(); + Minecraft mc = Minecraft.getMinecraft(); + ClientProxy.tickSchedulerClient.add(()->{ + mc.world.sendQuittingDisconnectingPacket(); + mc.loadWorld((WorldClient) null); + mc.displayGuiScreen(new GuiMainMenu()); + }); + } + } + + @Override + public void serialize(PacketBuffer buf) { + + } + + @Override + public void deserialize(PacketBuffer buf) { + + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/loadtas/CommandLoadTAS.java b/src/main/java/com/minecrafttas/tasmod/commands/loadtas/CommandLoadTAS.java similarity index 89% rename from src/main/java/de/scribble/lp/tasmod/commands/loadtas/CommandLoadTAS.java rename to src/main/java/com/minecrafttas/tasmod/commands/loadtas/CommandLoadTAS.java index c7871084..e2f18298 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/loadtas/CommandLoadTAS.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/loadtas/CommandLoadTAS.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.commands.loadtas; +package com.minecrafttas.tasmod.commands.loadtas; import java.io.File; import java.io.FileFilter; import java.util.ArrayList; import java.util.List; -import de.scribble.lp.tasmod.CommonProxy; +import com.minecrafttas.tasmod.TASmod; + import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -43,7 +44,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args } name=name.concat(args[i]+spacer); } - CommonProxy.NETWORK.sendToAll(new LoadTASPacket(name)); + TASmod.packetServer.sendToAll(new LoadTASPacket(name)); } } else { sender.sendMessage(new TextComponentString(TextFormatting.RED + "You have no permission to use this command")); @@ -71,11 +72,11 @@ public List getFilenames() { File[] listOfFiles = folder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { - return pathname.getName().endsWith(".tas"); + return pathname.getName().endsWith(".mctas"); } }); for (int i = 0; i < listOfFiles.length; i++) { - tab.add(listOfFiles[i].getName().replaceAll("\\.tas", "")); + tab.add(listOfFiles[i].getName().replaceAll("\\.mctas", "")); } return tab; } diff --git a/src/main/java/com/minecrafttas/tasmod/commands/loadtas/LoadTASPacket.java b/src/main/java/com/minecrafttas/tasmod/commands/loadtas/LoadTASPacket.java new file mode 100644 index 00000000..c2cd528c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/loadtas/LoadTASPacket.java @@ -0,0 +1,63 @@ +package com.minecrafttas.tasmod.commands.loadtas; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; + +public class LoadTASPacket implements Packet{ + private String name; + + public LoadTASPacket() { + } + + public LoadTASPacket(String name) { + this.name=name; + } + + @Override + public void handle(PacketSide side, EntityPlayer playerz) { + if (side.isServer()) { + EntityPlayerMP player = (EntityPlayerMP) playerz; + player.getServerWorld().addScheduledTask(() -> { + if (player.canUseCommand(2, "loadtas")) { + TASmod.packetServer.sendToAll(this); + } + }); + } else { + Minecraft mc = Minecraft.getMinecraft(); + mc.addScheduledTask(() -> { + try { + ClientProxy.virtual.loadInputs(name); + } catch (IOException e) { + mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + e.getMessage())); + return; + } + mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.GREEN + "Loaded inputs from " + name + ".mctas")); + }); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeInt(name.getBytes().length); + buf.writeCharSequence(name, Charset.defaultCharset()); + } + + @Override + public void deserialize(PacketBuffer buf) { + int length = buf.readInt(); + name = (String) buf.readCharSequence(length, StandardCharsets.UTF_8); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/playback/CommandPlay.java b/src/main/java/com/minecrafttas/tasmod/commands/playback/CommandPlay.java similarity index 93% rename from src/main/java/de/scribble/lp/tasmod/commands/playback/CommandPlay.java rename to src/main/java/com/minecrafttas/tasmod/commands/playback/CommandPlay.java index 8993f15d..096ffff6 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/playback/CommandPlay.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/playback/CommandPlay.java @@ -1,10 +1,10 @@ -package de.scribble.lp.tasmod.commands.playback; +package com.minecrafttas.tasmod.commands.playback; import java.util.List; import com.google.common.collect.ImmutableList; +import com.minecrafttas.tasmod.TASmod; -import de.scribble.lp.tasmod.TASmod; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; diff --git a/src/main/java/com/minecrafttas/tasmod/commands/playuntil/CommandPlayUntil.java b/src/main/java/com/minecrafttas/tasmod/commands/playuntil/CommandPlayUntil.java new file mode 100644 index 00000000..9140f222 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/playuntil/CommandPlayUntil.java @@ -0,0 +1,39 @@ +package com.minecrafttas.tasmod.commands.playuntil; + +import com.minecrafttas.tasmod.TASmod; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.text.TextComponentString; + +public class CommandPlayUntil extends CommandBase{ + + @Override + public String getName() { + return "playuntil"; + } + + @Override + public String getUsage(ICommandSender sender) { + return "/playuntil "; + } + + @Override + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + if(args.length==1) { + int i = 0; + try { + i = Integer.parseInt(args[0]); + } catch (NumberFormatException e) { + throw new CommandException("{} is not a number", args[0]); + } + TASmod.packetServer.sendToAll(new PlayUntilPacket(i)); + } + else { + sender.sendMessage(new TextComponentString("Stops the next playback one tick before the specified tick and lets you record from there:\n\n/playuntil 10, runs the playback until tick 9 and will record from there. Useful when you can't savestate")); + } + } + +} diff --git a/src/main/java/com/minecrafttas/tasmod/commands/playuntil/PlayUntilPacket.java b/src/main/java/com/minecrafttas/tasmod/commands/playuntil/PlayUntilPacket.java new file mode 100644 index 00000000..a93adac7 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/playuntil/PlayUntilPacket.java @@ -0,0 +1,38 @@ +package com.minecrafttas.tasmod.commands.playuntil; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +public class PlayUntilPacket implements Packet { + + private int until; + + public PlayUntilPacket() { + } + + public PlayUntilPacket(int until) { + this.until = until; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isClient()) { + ClientProxy.virtual.getContainer().setPlayUntil(until); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeInt(until); + } + + @Override + public void deserialize(PacketBuffer buf) { + until = buf.readInt(); + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/recording/CommandRecord.java b/src/main/java/com/minecrafttas/tasmod/commands/recording/CommandRecord.java similarity index 85% rename from src/main/java/de/scribble/lp/tasmod/commands/recording/CommandRecord.java rename to src/main/java/com/minecrafttas/tasmod/commands/recording/CommandRecord.java index c04268a8..0e267df3 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/recording/CommandRecord.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/recording/CommandRecord.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.commands.recording; +package com.minecrafttas.tasmod.commands.recording; import java.util.List; import com.google.common.collect.ImmutableList; +import com.minecrafttas.tasmod.CommonProxy; +import com.minecrafttas.tasmod.TASmod; -import de.scribble.lp.tasmod.TASmod; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; @@ -43,6 +44,9 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args } if (args.length < 1) { TASmod.containerStateServer.toggleRecording(); + CommonProxy.tickSchedulerServer.add(() ->{ + TASmod.ktrngHandler.broadcastStartSeed(); + }); } else if (args.length > 1) { sender.sendMessage(new TextComponentString(TextFormatting.RED + "Too many arguments. " + getUsage(sender))); } diff --git a/src/main/java/de/scribble/lp/tasmod/commands/restartandplay/CommandRestartAndPlay.java b/src/main/java/com/minecrafttas/tasmod/commands/restartandplay/CommandRestartAndPlay.java similarity index 85% rename from src/main/java/de/scribble/lp/tasmod/commands/restartandplay/CommandRestartAndPlay.java rename to src/main/java/com/minecrafttas/tasmod/commands/restartandplay/CommandRestartAndPlay.java index de541cf7..dcec9534 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/restartandplay/CommandRestartAndPlay.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/restartandplay/CommandRestartAndPlay.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.commands.restartandplay; +package com.minecrafttas.tasmod.commands.restartandplay; import java.io.File; import java.io.FileFilter; @@ -6,10 +6,10 @@ import java.util.ArrayList; import java.util.List; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.savestates.server.exceptions.LoadstateException; -import de.scribble.lp.tasmod.util.TASstate; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.savestates.server.exceptions.LoadstateException; + import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -53,7 +53,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args e.printStackTrace(); } TASmod.containerStateServer.setServerState(TASstate.PLAYBACK); - CommonProxy.NETWORK.sendToAll(new RestartAndPlayPacket(args[0])); + TASmod.packetServer.sendToAll(new RestartAndPlayPacket(args[0])); } } else { sender.sendMessage(new TextComponentString(TextFormatting.RED + "You have no permission to use this command")); @@ -80,11 +80,11 @@ public List getFilenames() { File[] listOfFiles = folder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { - return pathname.getName().endsWith(".tas"); + return pathname.getName().endsWith(".mctas"); } }); for (int i = 0; i < listOfFiles.length; i++) { - tab.add(listOfFiles[i].getName().replaceAll("\\.tas", "")); + tab.add(listOfFiles[i].getName().replaceAll("\\.mctas", "")); } return tab; } diff --git a/src/main/java/com/minecrafttas/tasmod/commands/restartandplay/RestartAndPlayPacket.java b/src/main/java/com/minecrafttas/tasmod/commands/restartandplay/RestartAndPlayPacket.java new file mode 100644 index 00000000..ff7f935f --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/restartandplay/RestartAndPlayPacket.java @@ -0,0 +1,52 @@ +package com.minecrafttas.tasmod.commands.restartandplay; + +import java.nio.charset.Charset; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.fml.common.FMLCommonHandler; + +public class RestartAndPlayPacket implements Packet{ + private String name; + + public RestartAndPlayPacket() { + } + + public RestartAndPlayPacket(String name) { + this.name=name; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isClient()) { + try { + Thread.sleep(100L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + Minecraft.getMinecraft().addScheduledTask(() -> { + ClientProxy.config.get("General", "fileToLoad", "").set(name); + ClientProxy.config.save(); + FMLCommonHandler.instance().exitJava(0, false); + }); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeInt(name.getBytes().length); + buf.writeCharSequence(name, Charset.defaultCharset()); + + } + + @Override + public void deserialize(PacketBuffer buf) { + int length = buf.readInt(); + name = (String) buf.readCharSequence(length, Charset.defaultCharset()); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/savetas/CommandSaveTAS.java b/src/main/java/com/minecrafttas/tasmod/commands/savetas/CommandSaveTAS.java similarity index 91% rename from src/main/java/de/scribble/lp/tasmod/commands/savetas/CommandSaveTAS.java rename to src/main/java/com/minecrafttas/tasmod/commands/savetas/CommandSaveTAS.java index 1f11b858..58922bd5 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/savetas/CommandSaveTAS.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/savetas/CommandSaveTAS.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.commands.savetas; +package com.minecrafttas.tasmod.commands.savetas; import java.io.File; import java.io.FileFilter; @@ -6,8 +6,8 @@ import java.util.List; import com.google.common.collect.ImmutableList; +import com.minecrafttas.tasmod.TASmod; -import de.scribble.lp.tasmod.CommonProxy; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -52,7 +52,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args } name = name.concat(args[i] + spacer); } - CommonProxy.NETWORK.sendToAll(new SaveTASPacket(name)); + TASmod.packetServer.sendToAll(new SaveTASPacket(name)); } } else { sender.sendMessage(new TextComponentString(TextFormatting.RED + "You have no permission to use this command")); @@ -84,11 +84,11 @@ public List getFilenames() { File[] listOfFiles = folder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { - return pathname.getName().endsWith(".tas"); + return pathname.getName().endsWith(".mctas"); } }); for (int i = 0; i < listOfFiles.length; i++) { - tab.add(listOfFiles[i].getName().replaceAll("\\.tas", "")); + tab.add(listOfFiles[i].getName().replaceAll("\\.mctas", "")); } return tab; } diff --git a/src/main/java/com/minecrafttas/tasmod/commands/savetas/SaveTASPacket.java b/src/main/java/com/minecrafttas/tasmod/commands/savetas/SaveTASPacket.java new file mode 100644 index 00000000..31a679f7 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/commands/savetas/SaveTASPacket.java @@ -0,0 +1,62 @@ +package com.minecrafttas.tasmod.commands.savetas; + +import java.io.IOException; +import java.nio.charset.Charset; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; + +public class SaveTASPacket implements Packet { + String name; + + public SaveTASPacket() { + } + + public SaveTASPacket(String recordingName) { + name = recordingName; + } + + @Override + public void handle(PacketSide side, EntityPlayer playerz) { + if (side.isClient()) { + Minecraft mc = Minecraft.getMinecraft(); + mc.addScheduledTask(() -> { + try { + ClientProxy.virtual.saveInputs(name); + } catch (IOException e) { + mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + e.getMessage())); + return; + } + mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.GREEN + "Saved inputs to " + name + ".mctas")); + }); + } else { + EntityPlayerMP player = (EntityPlayerMP) playerz; + player.getServerWorld().addScheduledTask(() -> { + if (player.canUseCommand(2, "savetas")) { + TASmod.packetServer.sendToAll(this); + } + }); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeInt(name.getBytes().length); + buf.writeCharSequence(name, Charset.defaultCharset()); + } + + @Override + public void deserialize(PacketBuffer buf) { + int length = buf.readInt(); + name = (String) buf.readCharSequence(length, Charset.defaultCharset()); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/tutorial/CommandPlaybacktutorial.java b/src/main/java/com/minecrafttas/tasmod/commands/tutorial/CommandPlaybacktutorial.java similarity index 91% rename from src/main/java/de/scribble/lp/tasmod/commands/tutorial/CommandPlaybacktutorial.java rename to src/main/java/com/minecrafttas/tasmod/commands/tutorial/CommandPlaybacktutorial.java index af668265..021604de 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/tutorial/CommandPlaybacktutorial.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/tutorial/CommandPlaybacktutorial.java @@ -1,6 +1,7 @@ -package de.scribble.lp.tasmod.commands.tutorial; +package com.minecrafttas.tasmod.commands.tutorial; + +import com.minecrafttas.tasmod.ClientProxy; -import de.scribble.lp.tasmod.ClientProxy; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; diff --git a/src/main/java/de/scribble/lp/tasmod/commands/tutorial/TutorialHandler.java b/src/main/java/com/minecrafttas/tasmod/commands/tutorial/TutorialHandler.java similarity index 98% rename from src/main/java/de/scribble/lp/tasmod/commands/tutorial/TutorialHandler.java rename to src/main/java/com/minecrafttas/tasmod/commands/tutorial/TutorialHandler.java index 01970b89..363a5c77 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/tutorial/TutorialHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/tutorial/TutorialHandler.java @@ -1,8 +1,9 @@ -package de.scribble.lp.tasmod.commands.tutorial; +package com.minecrafttas.tasmod.commands.tutorial; import org.lwjgl.input.Keyboard; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; diff --git a/src/main/java/de/scribble/lp/tasmod/duck/ChunkProviderDuck.java b/src/main/java/com/minecrafttas/tasmod/duck/ChunkProviderDuck.java similarity index 65% rename from src/main/java/de/scribble/lp/tasmod/duck/ChunkProviderDuck.java rename to src/main/java/com/minecrafttas/tasmod/duck/ChunkProviderDuck.java index da02ccf1..065430b0 100644 --- a/src/main/java/de/scribble/lp/tasmod/duck/ChunkProviderDuck.java +++ b/src/main/java/com/minecrafttas/tasmod/duck/ChunkProviderDuck.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.duck; +package com.minecrafttas.tasmod.duck; public interface ChunkProviderDuck { public void unloadAllChunks(); diff --git a/src/main/java/de/scribble/lp/tasmod/duck/GuiScreenDuck.java b/src/main/java/com/minecrafttas/tasmod/duck/GuiScreenDuck.java similarity index 79% rename from src/main/java/de/scribble/lp/tasmod/duck/GuiScreenDuck.java rename to src/main/java/com/minecrafttas/tasmod/duck/GuiScreenDuck.java index c3d153ba..de47d6ed 100644 --- a/src/main/java/de/scribble/lp/tasmod/duck/GuiScreenDuck.java +++ b/src/main/java/com/minecrafttas/tasmod/duck/GuiScreenDuck.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.duck; +package com.minecrafttas.tasmod.duck; public interface GuiScreenDuck { public int calcX(int X); diff --git a/src/main/java/de/scribble/lp/tasmod/duck/SubtickDuck.java b/src/main/java/com/minecrafttas/tasmod/duck/SubtickDuck.java similarity index 69% rename from src/main/java/de/scribble/lp/tasmod/duck/SubtickDuck.java rename to src/main/java/com/minecrafttas/tasmod/duck/SubtickDuck.java index 39febf21..d7c43852 100644 --- a/src/main/java/de/scribble/lp/tasmod/duck/SubtickDuck.java +++ b/src/main/java/com/minecrafttas/tasmod/duck/SubtickDuck.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.duck; +package com.minecrafttas.tasmod.duck; public interface SubtickDuck { public abstract void runSubtick(float partialTicks); diff --git a/src/main/java/de/pfannekuchen/tasmod/events/AimAssistEvents.java b/src/main/java/com/minecrafttas/tasmod/events/AimAssistEvents.java similarity index 81% rename from src/main/java/de/pfannekuchen/tasmod/events/AimAssistEvents.java rename to src/main/java/com/minecrafttas/tasmod/events/AimAssistEvents.java index a48b022b..5a2a007d 100644 --- a/src/main/java/de/pfannekuchen/tasmod/events/AimAssistEvents.java +++ b/src/main/java/com/minecrafttas/tasmod/events/AimAssistEvents.java @@ -1,8 +1,9 @@ -package de.pfannekuchen.tasmod.events; +package com.minecrafttas.tasmod.events; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.util.PlayerPositionCalculator; -import de.pfannekuchen.tasmod.utils.PlayerPositionCalculator; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerClient; import net.minecraft.client.Minecraft; import net.minecraftforge.client.event.DrawBlockHighlightEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; diff --git a/src/main/java/de/pfannekuchen/tasmod/events/CameraInterpolationEvents.java b/src/main/java/com/minecrafttas/tasmod/events/CameraInterpolationEvents.java similarity index 78% rename from src/main/java/de/pfannekuchen/tasmod/events/CameraInterpolationEvents.java rename to src/main/java/com/minecrafttas/tasmod/events/CameraInterpolationEvents.java index 6defb5b1..7b692d35 100644 --- a/src/main/java/de/pfannekuchen/tasmod/events/CameraInterpolationEvents.java +++ b/src/main/java/com/minecrafttas/tasmod/events/CameraInterpolationEvents.java @@ -1,9 +1,10 @@ -package de.pfannekuchen.tasmod.events; +package com.minecrafttas.tasmod.events; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.mixin.accessors.AccessorRunStuff; +import com.minecrafttas.tasmod.playback.PlaybackController.TickInputContainer; +import com.minecrafttas.tasmod.playback.controlbytes.ControlByteHandler; -import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.inputcontainer.TickInputContainer; -import de.scribble.lp.tasmod.mixin.accessors.AccessorRunStuff; import net.minecraft.client.Minecraft; import net.minecraft.util.math.MathHelper; import net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup; diff --git a/src/main/java/com/minecrafttas/tasmod/events/KeybindingEvents.java b/src/main/java/com/minecrafttas/tasmod/events/KeybindingEvents.java new file mode 100644 index 00000000..deac7418 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/events/KeybindingEvents.java @@ -0,0 +1,88 @@ +package com.minecrafttas.tasmod.events; + +import org.lwjgl.input.Keyboard; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.CommonProxy; +import com.minecrafttas.tasmod.externalGui.InputContainerView; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.playback.server.TASstateClient; +import com.minecrafttas.tasmod.savestates.server.LoadstatePacket; +import com.minecrafttas.tasmod.savestates.server.SavestatePacket; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.virtual.VirtualKeybindings; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.KeyBinding; + +/** + * + * The class where all keybinding functionality is executed + * @author Scribble + * + */ +public class KeybindingEvents { + + public static KeyBinding tickratezeroKey = new KeyBinding("Tickrate 0 Key", Keyboard.KEY_F8, "TASmod"); + + public static KeyBinding tickAdvance = new KeyBinding("Advance Tick", Keyboard.KEY_F9, "TASmod"); + + public static KeyBinding stopkey = new KeyBinding("Recording/Playback Stop", Keyboard.KEY_F10, "TASmod"); + + public static KeyBinding savestateSaveKey = new KeyBinding("Create Savestate", Keyboard.KEY_J, "TASmod"); + + public static KeyBinding savestateLoadKey = new KeyBinding("Load Latest Savestate", Keyboard.KEY_K, "TASmod"); + + public static KeyBinding testingKey = new KeyBinding("Various Testing", Keyboard.KEY_F12, "TASmod"); + + public static KeyBinding infoGuiKey = new KeyBinding("Open InfoGui Editor", Keyboard.KEY_F6, "TASmod"); + + public static KeyBinding bufferViewKey = new KeyBinding("Buffer View", Keyboard.KEY_NUMPAD0, "TASmod"); + + public static KeyBinding ktrngKey = null; + + public static void fireKeybindingsEvent() { + + if (VirtualKeybindings.isKeyDownExceptTextfield(savestateSaveKey)) { + + ClientProxy.packetClient.sendToServer(new SavestatePacket()); + + } else if (VirtualKeybindings.isKeyDownExceptTextfield(savestateLoadKey)) { + + ClientProxy.packetClient.sendToServer(new LoadstatePacket()); + + } else if (VirtualKeybindings.isKeyDownExceptTextfield(bufferViewKey)) { + + InputContainerView.startBufferView(); + + } else if (VirtualKeybindings.isKeyDownExceptTextfield(infoGuiKey)) { + + Minecraft.getMinecraft().displayGuiScreen(ClientProxy.hud); + + } else if (VirtualKeybindings.isKeyDown(stopkey)) { + + TASstateClient.setOrSend(TASstate.NONE); + + } else if (VirtualKeybindings.isKeyDown(tickratezeroKey)) { + + TickrateChangerClient.togglePause(); + + } else if (VirtualKeybindings.isKeyDown(tickAdvance)) { + + TickrateChangerClient.advanceTick(); + + } else if (VirtualKeybindings.isKeyDown(testingKey)) { + + CommonProxy.tickSchedulerServer.add(() -> { + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + } else if (ktrngKey!=null && VirtualKeybindings.isKeyDown(ktrngKey)) { + + } + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/events/LoadWorldEvents.java b/src/main/java/com/minecrafttas/tasmod/events/LoadWorldEvents.java similarity index 69% rename from src/main/java/de/scribble/lp/tasmod/events/LoadWorldEvents.java rename to src/main/java/com/minecrafttas/tasmod/events/LoadWorldEvents.java index 7fbbf820..2f2b6a95 100644 --- a/src/main/java/de/scribble/lp/tasmod/events/LoadWorldEvents.java +++ b/src/main/java/com/minecrafttas/tasmod/events/LoadWorldEvents.java @@ -1,9 +1,10 @@ -package de.scribble.lp.tasmod.events; +package com.minecrafttas.tasmod.events; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerClient; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerServer; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; public class LoadWorldEvents { @@ -18,10 +19,14 @@ public class LoadWorldEvents { /** * Executed when an integrated server is launched * - * @see de.scribble.lp.tasmod.mixin.events.MixinMinecraft#inject_launchIntegratedServer(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) + * @see com.minecrafttas.tasmod.mixin.events.MixinMinecraft#inject_launchIntegratedServer(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) */ public static void startLaunchServer() { TASmod.logger.info("Starting the integrated server"); + PlaybackController container = ClientProxy.virtual.getContainer(); + if(!container.isNothingPlaying() && !container.isPaused()) { + container.pause(true); + } if (TickrateChangerClient.ticksPerSecond == 0 || TickrateChangerClient.advanceTick) { waszero = true; } @@ -32,12 +37,10 @@ public static void startLaunchServer() { * Executed when the server is initialising * Side: Integrated Server * - * @see de.scribble.lp.tasmod.mixin.events.MixinIntegratedServer#inject_init(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) + * @see com.minecrafttas.tasmod.mixin.events.MixinIntegratedServer#inject_init(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) */ public static void initServer() { TASmod.logger.info("Integrated server initialised"); - TickrateChangerClient.pauseClientGame(true); - TickrateChangerServer.pauseServerGame(true); } /* The following code is for integrated and dedicated server! */ @@ -46,7 +49,7 @@ public static void initServer() { * Executed when the server is shutting down. If the tickrate is 0 the server * might freeze and never shutdown * - * @see de.scribble.lp.tasmod.mixin.events.MixinMinecraftServer#inject_initiateShutDown(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) + * @see com.minecrafttas.tasmod.mixin.events.MixinMinecraftServer#inject_initiateShutDown(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) */ public static void startShutdown() { if (TickrateChangerServer.ticksPerSecond == 0 || TickrateChangerServer.advanceTick) { @@ -79,6 +82,7 @@ public static void doneWithLoadingScreen() { if (loadingScreenDelay > -1) { if (loadingScreenDelay == 0) { TASmod.logger.info("Finished loading screen on the client"); + TickrateChangerClient.joinServer(); if (!waszero) { if(TASmod.getServerInstance()!=null) { //Check if a server is running and if it's an integrated server TickrateChangerClient.pauseClientGame(false); @@ -87,7 +91,7 @@ public static void doneWithLoadingScreen() { } else { waszero = false; } - isLoading=false; + isLoading = false; } loadingScreenDelay--; } diff --git a/src/main/java/de/scribble/lp/tasmod/events/OpenGuiEvents.java b/src/main/java/com/minecrafttas/tasmod/events/OpenGuiEvents.java similarity index 67% rename from src/main/java/de/scribble/lp/tasmod/events/OpenGuiEvents.java rename to src/main/java/com/minecrafttas/tasmod/events/OpenGuiEvents.java index 17272d26..89b52b7e 100644 --- a/src/main/java/de/scribble/lp/tasmod/events/OpenGuiEvents.java +++ b/src/main/java/com/minecrafttas/tasmod/events/OpenGuiEvents.java @@ -1,9 +1,12 @@ -package de.scribble.lp.tasmod.events; +package com.minecrafttas.tasmod.events; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.playback.server.TASstateClient; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerClient; -import de.scribble.lp.tasmod.util.TASstate; import net.minecraft.client.gui.GuiControls; import net.minecraft.client.gui.GuiIngameMenu; import net.minecraft.client.gui.GuiMainMenu; @@ -21,7 +24,12 @@ public class OpenGuiEvents { */ public static void openGuiMainMenu(GuiMainMenu guiMainMenu) { if (stateWhenOpened != null) { - ClientProxy.virtual.getContainer().setTASState(stateWhenOpened); + PlaybackController container = ClientProxy.virtual.getContainer(); + if(stateWhenOpened == TASstate.RECORDING) { + long seed = TASmod.ktrngHandler.getGlobalSeedClient(); + container.setStartSeed(seed); + } + container.setTASState(stateWhenOpened); stateWhenOpened = null; } LoadWorldEvents.doneShuttingDown(); @@ -46,7 +54,7 @@ public static void openGuiControls(GuiControls guiControls) { if (TickrateChangerClient.ticksPerSecond == 0 || TickrateChangerClient.advanceTick) { TASmod.logger.info("Pausing game during GuiControls"); TickrateChangerClient.pauseGame(false); - TASstate.setOrSend(TASstate.NONE); + TASstateClient.setOrSend(stateWhenOpened); waszero = true; } } diff --git a/src/main/java/de/scribble/lp/tasmod/events/PlayerJoinLeaveEvents.java b/src/main/java/com/minecrafttas/tasmod/events/PlayerJoinLeaveEvents.java similarity index 68% rename from src/main/java/de/scribble/lp/tasmod/events/PlayerJoinLeaveEvents.java rename to src/main/java/com/minecrafttas/tasmod/events/PlayerJoinLeaveEvents.java index 5d91af4a..012c0091 100644 --- a/src/main/java/de/scribble/lp/tasmod/events/PlayerJoinLeaveEvents.java +++ b/src/main/java/com/minecrafttas/tasmod/events/PlayerJoinLeaveEvents.java @@ -1,13 +1,16 @@ -package de.scribble.lp.tasmod.events; +package com.minecrafttas.tasmod.events; +import java.io.IOException; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.TASmodNetworkClient; +import com.minecrafttas.tasmod.playback.server.InitialSyncStatePacket; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; import com.mojang.authlib.GameProfile; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerClient; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerServer; -import de.scribble.lp.tasmod.ticksync.TickSyncServer; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -23,8 +26,6 @@ public class PlayerJoinLeaveEvents { */ public static void firePlayerJoinedServerSide(EntityPlayerMP player) { TASmod.logger.info("Firing login events for {} on the SERVER", player.getName()); - TickSyncServer.joinServer(player); - TASmod.containerStateServer.joinServer(player); TickrateChangerServer.joinServer(player); } @@ -35,6 +36,7 @@ public static void firePlayerJoinedServerSide(EntityPlayerMP player) { */ public static void firePlayerLeaveServerSide(EntityPlayerMP player) { // TASmod.logger.info("Firing logout events for {} on the SERVER", player.getName()); + TASmod.containerStateServer.leaveServer(player); } /** @@ -44,10 +46,21 @@ public static void firePlayerLeaveServerSide(EntityPlayerMP player) { @SideOnly(Side.CLIENT) public static void firePlayerJoinedClientSide(net.minecraft.client.entity.EntityPlayerSP player) { TASmod.logger.info("Firing login events for {} on the CLIENT", player.getName()); + + Minecraft mc = Minecraft.getMinecraft(); + + if(mc.isIntegratedServerRunning()) + ClientProxy.packetClient = new TASmodNetworkClient(TASmod.logger); + else + ClientProxy.packetClient = new TASmodNetworkClient(TASmod.logger, mc.getCurrentServerData().serverIP, 3111); + + ClientProxy.packetClient.sendToServer(new InitialSyncStatePacket(ClientProxy.virtual.getContainer().getState())); + ClientProxy.virtual.unpressNext(); ClientProxy.shieldDownloader.onPlayerJoin(player.getGameProfile()); - TickrateChangerClient.joinServer(); - ClientProxy.virtual.getContainer().printCredits(); +// TickrateChangerClient.joinServer(); //TODO Only the first player joining the server should be able to change the tickrate + TASmod.ktrngHandler.setInitialSeed(); + } /** @@ -57,6 +70,14 @@ public static void firePlayerJoinedClientSide(net.minecraft.client.entity.Entity @SideOnly(Side.CLIENT) public static void firePlayerLeaveClientSide(net.minecraft.client.entity.EntityPlayerSP player) { TASmod.logger.info("Firing logout events for {} on the CLIENT", player.getName()); + try { + if(ClientProxy.packetClient!=null) { + ClientProxy.packetClient.killClient(); + ClientProxy.packetClient=null; + } + } catch (IOException e) { + e.printStackTrace(); + } } /** diff --git a/src/main/java/com/minecrafttas/tasmod/events/SavestateEvents.java b/src/main/java/com/minecrafttas/tasmod/events/SavestateEvents.java new file mode 100644 index 00000000..2dae89da --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/events/SavestateEvents.java @@ -0,0 +1,27 @@ +package com.minecrafttas.tasmod.events; + +import java.io.File; + +/** + * Events for savestating + * @author Scribble + * + */ +public class SavestateEvents { + + /** + * Executed when creating a savestate + * @param targetfolder Folder where the savestate will be saved to + */ + public static void triggerSavestateEvent(File targetfolder) { + + } + + /** + * Executed when loading a savestate + * @param targetfolder The folder where the savestate will be coming from + */ + public static void triggerLoadstateEvent(File targetfolder) { + + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/events/TickEvents.java b/src/main/java/com/minecrafttas/tasmod/events/TickEvents.java new file mode 100644 index 00000000..c978c2c5 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/events/TickEvents.java @@ -0,0 +1,32 @@ +package com.minecrafttas.tasmod.events; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.ticksync.TickSyncClient; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +/** + * Hooks into client on server tick loops + * @author Scribble + * + */ +public class TickEvents { + + public static void onRender() { + KeybindingEvents.fireKeybindingsEvent(); + + if (ClientProxy.packetClient != null && ClientProxy.packetClient.isClosed()) { // If the server died, but the client has not left the world + TickSyncClient.shouldTick.set(true); + } + } + + @SideOnly(Side.CLIENT) + public static void onClientTick() { + TASmod.ktrngHandler.updateClient(); + } + + public static void onServerTick() { + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/externalGui/InputContainerView.java b/src/main/java/com/minecrafttas/tasmod/externalGui/InputContainerView.java similarity index 93% rename from src/main/java/de/scribble/lp/tasmod/externalGui/InputContainerView.java rename to src/main/java/com/minecrafttas/tasmod/externalGui/InputContainerView.java index f69280fd..17f4b569 100644 --- a/src/main/java/de/scribble/lp/tasmod/externalGui/InputContainerView.java +++ b/src/main/java/com/minecrafttas/tasmod/externalGui/InputContainerView.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.externalGui; +package com.minecrafttas.tasmod.externalGui; import java.awt.BorderLayout; import java.awt.Color; @@ -16,10 +16,11 @@ import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableModel; -import de.scribble.lp.tasmod.inputcontainer.InputContainer; -import de.scribble.lp.tasmod.inputcontainer.TickInputContainer; -import de.scribble.lp.tasmod.virtual.VirtualInput; +import com.minecrafttas.tasmod.playback.PlaybackController; +import com.minecrafttas.tasmod.playback.PlaybackController.TickInputContainer; +import com.minecrafttas.tasmod.virtual.VirtualInput; +@Deprecated public class InputContainerView extends JFrame { private static final long serialVersionUID = -1823965270972132025L; @@ -113,7 +114,7 @@ public static void update(VirtualInput input) { if (model == null) { return; } - InputContainer container = input.getContainer(); + PlaybackController container = input.getContainer(); if (container == null || container.isEmpty()) { return; } diff --git a/src/main/java/de/scribble/lp/tasmod/gui/GuiMultiplayerTimeOut.java b/src/main/java/com/minecrafttas/tasmod/gui/GuiMultiplayerTimeOut.java similarity index 98% rename from src/main/java/de/scribble/lp/tasmod/gui/GuiMultiplayerTimeOut.java rename to src/main/java/com/minecrafttas/tasmod/gui/GuiMultiplayerTimeOut.java index edcb54ad..1d31f354 100644 --- a/src/main/java/de/scribble/lp/tasmod/gui/GuiMultiplayerTimeOut.java +++ b/src/main/java/com/minecrafttas/tasmod/gui/GuiMultiplayerTimeOut.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.gui; +package com.minecrafttas.tasmod.gui; import java.io.IOException; diff --git a/src/main/java/de/scribble/lp/tasmod/gui/GuiMultiplayerWarn.java b/src/main/java/com/minecrafttas/tasmod/gui/GuiMultiplayerWarn.java similarity index 97% rename from src/main/java/de/scribble/lp/tasmod/gui/GuiMultiplayerWarn.java rename to src/main/java/com/minecrafttas/tasmod/gui/GuiMultiplayerWarn.java index 38439544..0197e799 100644 --- a/src/main/java/de/scribble/lp/tasmod/gui/GuiMultiplayerWarn.java +++ b/src/main/java/com/minecrafttas/tasmod/gui/GuiMultiplayerWarn.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.gui; +package com.minecrafttas.tasmod.gui; import java.io.IOException; diff --git a/src/main/java/de/pfannekuchen/infogui/gui/InfoHud.java b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java similarity index 89% rename from src/main/java/de/pfannekuchen/infogui/gui/InfoHud.java rename to src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java index 55c4b1d9..4d7e2547 100644 --- a/src/main/java/de/pfannekuchen/infogui/gui/InfoHud.java +++ b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java @@ -1,4 +1,4 @@ -package de.pfannekuchen.infogui.gui; +package com.minecrafttas.tasmod.gui; import java.io.File; import java.io.FileOutputStream; @@ -11,20 +11,18 @@ import org.lwjgl.opengl.GL11; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.events.CameraInterpolationEvents; +import com.minecrafttas.tasmod.mixin.accessors.AccessorWorld; +import com.minecrafttas.tasmod.monitoring.DesyncMonitoring; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.playback.controlbytes.ControlByteHandler; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.util.PlayerPositionCalculator; +import com.minecrafttas.tasmod.util.TrajectoriesCalculator; import com.mojang.realmsclient.gui.ChatFormatting; -import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler; -import de.pfannekuchen.tasmod.events.CameraInterpolationEvents; -import de.pfannekuchen.tasmod.utils.PlayerPositionCalculator; -import de.pfannekuchen.tasmod.utils.TrajectoriesCalculator; -import de.scribble.lp.killtherng.KillTheRNG; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.mixin.accessors.AccessorWorld; -import de.scribble.lp.tasmod.monitoring.DesyncMonitoring; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerClient; -import de.scribble.lp.tasmod.ticksync.TickSync; -import de.scribble.lp.tasmod.util.TASstate; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.math.Vec3d; @@ -255,12 +253,12 @@ public boolean checkInit() { y += 14; - if(TASmod.isKTRNGLoaded) { + if(TASmod.ktrngHandler.isLoaded()) { title = "ktrng_randomseed"; if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { if (Minecraft.getMinecraft().currentScreen == this) return "KTRNG"; - return "RandomSeed: " + KillTheRNG.randomness.Global.getSeed(); + return "RandomSeed: " + TASmod.ktrngHandler.getGlobalSeedClient(); })); } @@ -274,19 +272,19 @@ public boolean checkInit() { title = "cticks"; y += 14; - if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); - lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { - if (Minecraft.getMinecraft().currentScreen == this) return "Client Ticks"; - return "Client Ticks: " + TickSync.getClienttickcounter(); - })); +// if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); +// lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { +// if (Minecraft.getMinecraft().currentScreen == this) return "Client Ticks"; +// return "Client Ticks: " + ClientProxy.ticksyncClient.getClienttickcounter(); +// })); title = "sticks"; y += 14; - if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); - lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { - if (Minecraft.getMinecraft().currentScreen == this) return "Server Ticks"; - return "Server Ticks: " + TickSync.getServertickcounter(); - })); +// if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); +// lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { +// if (Minecraft.getMinecraft().currentScreen == this) return "Server Ticks"; +// return "Server Ticks: " + ClientProxy.ticksyncClient.getServertickcounter(); +// })); title = "nextxyz"; y += 14; @@ -356,7 +354,8 @@ public boolean checkInit() { if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { if (Minecraft.getMinecraft().currentScreen == this) return "Desync"; - return ClientProxy.virtual.getContainer().dMonitor.getMonitoring(ClientProxy.virtual.getContainer(), Minecraft.getMinecraft().player); + DesyncMonitoring dMonitor=ClientProxy.virtual.getContainer().desyncMonitor; + return dMonitor.getStatus(Minecraft.getMinecraft().player); })); title = "desyncstatusMotion"; @@ -364,8 +363,8 @@ public boolean checkInit() { if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { if (Minecraft.getMinecraft().currentScreen == this) return "Desync Motion"; - DesyncMonitoring dMonitor=ClientProxy.virtual.getContainer().dMonitor; - return dMonitor.getMx()+" "+ dMonitor.getMy()+" "+dMonitor.getMz(); + DesyncMonitoring dMonitor=ClientProxy.virtual.getContainer().desyncMonitor; + return dMonitor.getMotion(); })); title = "desyncstatusPos"; @@ -373,10 +372,20 @@ public boolean checkInit() { if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { if (Minecraft.getMinecraft().currentScreen == this) return "Desync Position"; - DesyncMonitoring dMonitor=ClientProxy.virtual.getContainer().dMonitor; - return dMonitor.getX()+" "+ dMonitor.getY()+" "+dMonitor.getZ(); + DesyncMonitoring dMonitor=ClientProxy.virtual.getContainer().desyncMonitor; + return dMonitor.getPos(); })); + y += 14; + title = "ktrng_desync"; + if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); + lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { + if (Minecraft.getMinecraft().currentScreen == this) return "Desync KTRNG"; + DesyncMonitoring dMonitor=ClientProxy.virtual.getContainer().desyncMonitor; + return dMonitor.getSeed(); + })); + + } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGMonitor.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGMonitor.java new file mode 100644 index 00000000..33778934 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGMonitor.java @@ -0,0 +1,11 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.killtherng.custom.EventAnnotations.CaptureRandomness; + +public class KTRNGMonitor { + + @CaptureRandomness(name = "jukeboxRecordDropPosition") + public static void monitor(long seed, String value) { +// System.out.println(String.format("Seed: %s, Value: %s", seed, value)); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGSeedPacket.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGSeedPacket.java new file mode 100644 index 00000000..c8523c8c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGSeedPacket.java @@ -0,0 +1,40 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +public class KTRNGSeedPacket implements Packet { + + private long seed; + + public KTRNGSeedPacket() { + } + + public KTRNGSeedPacket(long seed) { + this.seed = seed; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if (side.isClient()) { + TASmod.ktrngHandler.setGlobalSeedClient(seed); + } else { + TASmod.ktrngHandler.setGlobalSeedServer(seed); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeLong(seed); + } + + @Override + public void deserialize(PacketBuffer buf) { + seed = buf.readLong(); + } + +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGStartSeedPacket.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGStartSeedPacket.java new file mode 100644 index 00000000..6ec9fc48 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGStartSeedPacket.java @@ -0,0 +1,51 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.CommonProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +public class KTRNGStartSeedPacket implements Packet{ + + private long seed; + + /** + * Do not use! + */ + @Deprecated + public KTRNGStartSeedPacket() { + } + + /** + * Set's the start seed of the client + * @param seed + */ + public KTRNGStartSeedPacket(long seed) { + this.seed = seed; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isClient()) { + ClientProxy.virtual.getContainer().setStartSeed(seed); + } else { + CommonProxy.tickSchedulerServer.add(()->{ + TASmod.ktrngHandler.setGlobalSeedServer(seed); + }); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeLong(seed); + } + + @Override + public void deserialize(PacketBuffer buf) { + seed = buf.readLong(); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java new file mode 100644 index 00000000..f2ac904c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java @@ -0,0 +1,146 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.killtherng.KillTheRNG; +import com.minecrafttas.killtherng.SeedingModes; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +/** + * Easy access to the KillTheRNG library without littering the rest of the code + * + * @author Scribble + * + */ +public class KillTheRNGHandler{ + + private boolean isLoaded; + + /** + * Instantiates a KillTheRNGHandler instance + * @param isLoaded If the KillTheRNG mod is loaded + */ + public KillTheRNGHandler(boolean isLoaded) { + + this.isLoaded=isLoaded; + + if (isLoaded) { + KillTheRNG.LOGGER.info("Connection established with TASmod"); + KillTheRNG.isLibrary=true; + KillTheRNG.mode=SeedingModes.TickChange; + + KillTheRNG.annotations.register(new KTRNGMonitor()); + }else { + TASmod.logger.info("KillTheRNG doesn't appear to be loaded"); + } + } + + public long advanceGlobalSeedServer() { + if(isLoaded()) { + return KillTheRNG.commonRandom.nextSeed(); + } else { + return 0; + } + } + + public long getGlobalSeedServer() { + if(isLoaded()) { + return KillTheRNG.commonRandom.GlobalServer.getSeed(); + } else { + return 0; + } + } + + public boolean isLoaded() { + return isLoaded; + } + + + //=================================================Setting the seed + /** + * @return The global seed of the client + */ + @SideOnly(Side.CLIENT) + public long getGlobalSeedClient() { + if(isLoaded()) + return KillTheRNG.clientRandom.GlobalClient.getSeed(); + else + return 0; + } + + /** + * Set the global seed on the client + * @param seedIn The seed on the client + */ + @SideOnly(Side.CLIENT) + public void setGlobalSeedClient(long seedIn) { + if (isLoaded()) { + KillTheRNG.clientRandom.setSeedAll(seedIn); + } + } + + + public void setGlobalSeedServer(long seedIn) { + if (isLoaded()) { + KillTheRNG.commonRandom.setSeedAll(seedIn); + } + } + /** + * Sends a packet to the server, setting the global seed + * @param seedIn The seed on the server + */ + @SideOnly(Side.CLIENT) + public void sendGlobalSeedToServer(long seedIn) { + if(isLoaded()) { + if(ClientProxy.packetClient!=null) + ClientProxy.packetClient.sendToServer(new KTRNGSeedPacket(seedIn)); + else + setGlobalSeedClient(seedIn); + } + } + //=================================================TASmod integration + + /** + * Executed every tick. + */ + @SideOnly(Side.CLIENT) + public void updateClient() { + } + + /** + * Executed every tick on the server + */ + public void updateServer() { + if(isLoaded()) { + if(TASmod.containerStateServer.getState() != TASstate.PAUSED) + TASmod.packetServer.sendToAll(new KTRNGSeedPacket(advanceGlobalSeedServer())); + } + } + + //================================================= Seedsync + + public void broadcastStartSeed() { + if(isLoaded()) { + long seed = getGlobalSeedServer(); + TASmod.packetServer.sendToAll(new KTRNGStartSeedPacket(seed)); + } + } + + @SideOnly(Side.CLIENT) + public void setInitialSeed() { + setInitialSeed(getGlobalSeedClient()); + } + + @SideOnly(Side.CLIENT) + public void setInitialSeed(long initialSeed) { + if(ClientProxy.packetClient != null) { + TASmod.logger.info("Sending initial client seed: {}", initialSeed); + ClientProxy.packetClient.sendToServer(new KTRNGStartSeedPacket(initialSeed)); // TODO Every new player in multiplayer will currently send the initial seed, which is BAD + } else { + TASmod.ktrngHandler.setGlobalSeedClient(initialSeed); + } + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinEntityPlayer.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinEntityPlayer.java similarity index 94% rename from src/main/java/de/scribble/lp/tasmod/mixin/MixinEntityPlayer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/MixinEntityPlayer.java index 73f37724..adad6650 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinEntityPlayer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinEntityPlayer.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin; +package com.minecrafttas.tasmod.mixin; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinEntityRenderer.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinEntityRenderer.java similarity index 93% rename from src/main/java/de/scribble/lp/tasmod/mixin/MixinEntityRenderer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/MixinEntityRenderer.java index bdc41369..8715a8b2 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinEntityRenderer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinEntityRenderer.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin; +package com.minecrafttas.tasmod.mixin; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; @@ -11,10 +11,11 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.pfannekuchen.tasmod.events.CameraInterpolationEvents; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.duck.SubtickDuck; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.duck.SubtickDuck; +import com.minecrafttas.tasmod.events.CameraInterpolationEvents; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; + import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.util.math.MathHelper; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinFrustum.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinFrustum.java similarity index 94% rename from src/main/java/de/scribble/lp/tasmod/mixin/MixinFrustum.java rename to src/main/java/com/minecrafttas/tasmod/mixin/MixinFrustum.java index 80b3061d..00c393ad 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinFrustum.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinFrustum.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin; +package com.minecrafttas.tasmod.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinGuiScreen.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinGuiScreen.java similarity index 98% rename from src/main/java/de/scribble/lp/tasmod/mixin/MixinGuiScreen.java rename to src/main/java/com/minecrafttas/tasmod/mixin/MixinGuiScreen.java index 6882dbc3..97ab4c94 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinGuiScreen.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinGuiScreen.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin; +package com.minecrafttas.tasmod.mixin; import org.lwjgl.input.Mouse; import org.spongepowered.asm.mixin.Mixin; @@ -9,8 +9,9 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.duck.GuiScreenDuck; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.duck.GuiScreenDuck; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinInGameHud.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinInGameHud.java similarity index 97% rename from src/main/java/de/scribble/lp/tasmod/mixin/MixinInGameHud.java rename to src/main/java/com/minecrafttas/tasmod/mixin/MixinInGameHud.java index e21cde6e..4d562688 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinInGameHud.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinInGameHud.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin; +package com.minecrafttas.tasmod.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraft.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraft.java similarity index 83% rename from src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraft.java rename to src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraft.java index 0b5659af..f3f07779 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraft.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraft.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin; +package com.minecrafttas.tasmod.mixin; import java.io.IOException; @@ -13,16 +13,17 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.duck.GuiScreenDuck; -import de.scribble.lp.tasmod.duck.SubtickDuck; -import de.scribble.lp.tasmod.events.KeybindingEvents; -import de.scribble.lp.tasmod.events.LoadWorldEvents; -import de.scribble.lp.tasmod.externalGui.InputContainerView; -import de.scribble.lp.tasmod.savestates.server.SavestateHandler; -import de.scribble.lp.tasmod.savestates.server.playerloading.SavestatePlayerLoading; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerClient; -import de.scribble.lp.tasmod.ticksync.TickSync; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.duck.GuiScreenDuck; +import com.minecrafttas.tasmod.duck.SubtickDuck; +import com.minecrafttas.tasmod.events.LoadWorldEvents; +import com.minecrafttas.tasmod.events.TickEvents; +import com.minecrafttas.tasmod.externalGui.InputContainerView; +import com.minecrafttas.tasmod.savestates.server.SavestateHandler; +import com.minecrafttas.tasmod.savestates.server.playerloading.SavestatePlayerLoading; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.ticksync.TickSyncClient; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.EntityRenderer; @@ -40,11 +41,13 @@ public abstract class MixinMinecraft { @Inject(method = "runGameLoop", at = @At(value = "HEAD")) public void injectRunGameLoop(CallbackInfo ci) { - KeybindingEvents.fireKeybindingsEvent(); + TickEvents.onRender(); LoadWorldEvents.doneWithLoadingScreen(); - if(((Minecraft) (Object) this).player!=null) { + ClientProxy.gameLoopSchedulerClient.runAllTasks(); + + if(((Minecraft) (Object) this).player != null) { ClientProxy.hud.tick(); } @@ -52,10 +55,10 @@ public void injectRunGameLoop(CallbackInfo ci) { ClientProxy.virtual.updateNextKeyboard(Keyboard.getEventKey(), Keyboard.getEventKeyState(), Keyboard.getEventCharacter()); } while (Mouse.next()) { - if(this.currentScreen==null) { + if(this.currentScreen == null) { ClientProxy.virtual.updateNextMouse(Mouse.getEventButton(), Mouse.getEventButtonState(), Mouse.getEventDWheel(), Mouse.getEventX(), Mouse.getEventY(), TickrateChangerClient.ticksPerSecond==0); } else { - GuiScreenDuck screen=(GuiScreenDuck) currentScreen; + GuiScreenDuck screen = (GuiScreenDuck) currentScreen; ClientProxy.virtual.updateNextMouse(Mouse.getEventButton(), Mouse.getEventButtonState(), Mouse.getEventDWheel(), screen.calcX(Mouse.getEventX()), screen.calcY(Mouse.getEventY()), TickrateChangerClient.ticksPerSecond==0); } } @@ -74,28 +77,40 @@ public void injectRunGameLoop(CallbackInfo ci) { @Redirect(method = "runGameLoop", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;runTick()V")) public void redirectRunTick(Minecraft mc) { - for (int j2 = 0; j2 < TickSync.getTickAmount((Minecraft) (Object) this); j2++) { - ClientProxy.virtual.updateContainer(); - if (TickrateChangerClient.ticksPerSecond != 0) { - ((SubtickDuck) this.entityRenderer).runSubtick(this.isGamePaused ? this.renderPartialTicksPaused : this.timer.renderPartialTicks); - } - this.runTick(); + ClientProxy.virtual.updateContainer(); + if (TickrateChangerClient.ticksPerSecond != 0) { + ((SubtickDuck) this.entityRenderer).runSubtick(this.isGamePaused ? this.renderPartialTicksPaused : this.timer.renderPartialTicks); } + this.runTick(); + ClientProxy.tickSchedulerClient.runAllTasks(); if (TickrateChangerClient.advanceTick) { TickrateChangerClient.advanceTick = false; TickrateChangerClient.changeClientTickrate(0F); } + TickSyncClient.clientPostTick((Minecraft)(Object)this); } @Shadow public abstract void runTick(); + @Inject(method = "shutdownMinecraftApplet", at = @At("HEAD")) + public void inject_shutdownMinecraftApplet(CallbackInfo ci) { + try { + if (ClientProxy.packetClient != null) { + TickrateChangerClient.changeTickrate(20); + ClientProxy.packetClient.killClient(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + // ===================================================================================================================================== @Inject(method = "runTick", at = @At(value = "HEAD")) public void injectRunTick(CallbackInfo ci) throws IOException { + InputContainerView.update(ClientProxy.virtual); - TickSync.incrementClienttickcounter(); if (SavestatePlayerLoading.wasLoading) { SavestatePlayerLoading.wasLoading = false; @@ -165,6 +180,10 @@ public boolean redirectMouseNext() { @Redirect(method = "runTickMouse", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventButton()I", remap = false)) public int redirectMouseGetEventButton() { + +// if(!VirtualKeybindings.isKeyCodeAlwaysBlocked(ClientProxy.virtual.getEventMouseKey()-100)) { +// TASmod.ktrngHandler.nextPlayerInput(); // Advance ktrng seed on player input +// } return ClientProxy.virtual.getEventMouseKey() + 100; } diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java similarity index 51% rename from src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java index 5875cfd1..0ee85557 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin; +package com.minecrafttas.tasmod.mixin; import java.util.Queue; import java.util.concurrent.FutureTask; @@ -10,13 +10,13 @@ import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.savestates.server.SavestateHandler; -import de.scribble.lp.tasmod.savestates.server.SavestateState; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerServer; -import de.scribble.lp.tasmod.ticksync.TickSyncPackage; -import de.scribble.lp.tasmod.ticksync.TickSyncServer; +import com.minecrafttas.tasmod.CommonProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.savestates.server.SavestateHandler; +import com.minecrafttas.tasmod.savestates.server.SavestateState; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; +import com.minecrafttas.tasmod.ticksync.TickSyncServer; + import net.minecraft.network.NetworkSystem; import net.minecraft.server.MinecraftServer; import net.minecraftforge.fml.relauncher.Side; @@ -34,30 +34,9 @@ public long modifyMSPT(long fiftyLong) { // ===================================================================================================================================== - @Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;tick()V", ordinal = 1)) + @Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;tick()V")) public void redirectTick(MinecraftServer server) { - this.tick(); - if (TASmod.savestateHandler.state == SavestateState.WASLOADING) { - TASmod.savestateHandler.state = SavestateState.NONE; - SavestateHandler.playerLoadSavestateEventServer(); - } - - if (TickSyncServer.isEnabled()) { - if (TickSyncServer.getServertickcounter() == Integer.MAX_VALUE - 1) { - TickSyncServer.resetTickCounter(); - CommonProxy.NETWORK.sendToAll(new TickSyncPackage(TickSyncServer.getServertickcounter(), true, true)); - } else { - TickSyncServer.incrementServerTickCounter(); - CommonProxy.NETWORK.sendToAll(new TickSyncPackage(TickSyncServer.getServertickcounter(), false, true)); - } - } else { - TickSyncServer.incrementServerTickCounter(); - CommonProxy.NETWORK.sendToAll(new TickSyncPackage(TickSyncServer.getServertickcounter(), false, false)); - } - if (TickrateChangerServer.advanceTick) { - TickrateChangerServer.changeServerTickrate(0F); - TickrateChangerServer.advanceTick = false; - } + } @Shadow @@ -65,7 +44,7 @@ public void redirectTick(MinecraftServer server) { // ===================================================================================================================================== - @Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(JJ)J")) +// @Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/lang/Math;max(JJ)J")) public long redirectMathMax(long oneLong, long i) { return i; // Getting the original value of i } @@ -83,18 +62,43 @@ public long redirectMathMax(long oneLong, long i) { private int faketick = 0; + @Shadow + private boolean serverIsRunning; + @Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;sleep(J)V")) public void redirectThreadSleep(long msToTick) { + + /* The server should tick if: + * (shouldTick in ticksync is true OR there are no players connected to the custom server) AND the tickrate is not zero. That or advance tick is true*/ + if( (TickSyncServer.shouldTick() && TickrateChangerServer.ticksPerSecond != 0) || TickrateChangerServer.advanceTick) { + long timeBeforeTick = System.currentTimeMillis(); + + if (TASmod.savestateHandler.state == SavestateState.WASLOADING) { + TASmod.savestateHandler.state = SavestateState.NONE; + SavestateHandler.playerLoadSavestateEventServer(); + } - if (msToTick <= 0L) { - if (TickrateChangerServer.ticksPerSecond > 20.0) - msToTick = 0L; - else - msToTick = 1L; - } - for (long o = 0; o < msToTick; o++) { - if (TickrateChangerServer.ticksPerSecond == 0) { - currentTime = System.currentTimeMillis(); + TASmod.ktrngHandler.updateServer(); + this.tick(); + CommonProxy.tickSchedulerServer.runAllTasks(); + + if (TickrateChangerServer.advanceTick) { + TickrateChangerServer.changeServerTickrate(0F); + TickrateChangerServer.advanceTick = false; + } + TickSyncServer.serverPostTick(); + + long tickDuration = System.currentTimeMillis() - timeBeforeTick; + + // ================================================== + + try { + Thread.sleep(Math.max(1L, TickrateChangerServer.millisecondsPerTick - tickDuration)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } else { // This is when the server should not tick... This is to ensure network tick stuff is working + if(TickrateChangerServer.ticksPerSecond == 0) { faketick++; if (faketick >= 50) { faketick = 0; @@ -104,28 +108,23 @@ public void redirectThreadSleep(long msToTick) { } } } - if (TickrateChangerServer.interrupt) { - currentTime = System.currentTimeMillis(); - msToTick = 1L; - TickrateChangerServer.interrupt = false; - } - synchronized (this.futureTaskQueue) { - while (!this.futureTaskQueue.isEmpty()) { - try { - ((FutureTask) this.futureTaskQueue.poll()).run(); - } catch (Throwable var9) { - var9.printStackTrace(); - } - } - } - + try { - Thread.sleep(1L); + Thread.sleep(1); } catch (InterruptedException e) { - TASmod.logger.error("Thread Sleep Interrupted!"); e.printStackTrace(); } } + + synchronized (this.futureTaskQueue) { + while (!this.futureTaskQueue.isEmpty()) { + try { + ((FutureTask) this.futureTaskQueue.poll()).run(); + } catch (Throwable var9) { + var9.printStackTrace(); + } + } + } } @SideOnly(Side.SERVER) @@ -138,24 +137,13 @@ private void runPendingCommands() { // ===================================================================================================================================== -// @Inject(method = "tick", at = @At("HEAD")) -// public void lagServer(CallbackInfo ci) { -// if(SavestateEvents.lagServer) { -// SavestateEvents.lagServer=false; -// try { -// Thread.sleep(5000L); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// } -// } // @ModifyVariable(method = "run", at = @At(value = "STORE"), index = 5, ordinal = 2) -// public long limitLag(long j) { -// if(j>(500L*(20/TickrateChangerServer.TICKS_PER_SECOND))){ -// return 50L; -// } -// return j; -// } - + public long limitLag(long j) { + if(j>=TickrateChangerServer.millisecondsPerTick*5){ + return TickrateChangerServer.millisecondsPerTick; + } + return j; + } + } diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinTextfield.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinTextfield.java similarity index 83% rename from src/main/java/de/scribble/lp/tasmod/mixin/MixinTextfield.java rename to src/main/java/com/minecrafttas/tasmod/mixin/MixinTextfield.java index 404e3d16..85f89676 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinTextfield.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinTextfield.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin; +package com.minecrafttas.tasmod.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.virtual.VirtualKeybindings; +import com.minecrafttas.tasmod.virtual.VirtualKeybindings; + import net.minecraft.client.gui.GuiTextField; @Mixin(GuiTextField.class) diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/MixinTimer.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinTimer.java new file mode 100644 index 00000000..1df3eab9 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinTimer.java @@ -0,0 +1,74 @@ +package com.minecrafttas.tasmod.mixin; + + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.ticksync.TickSyncClient; + +import net.minecraft.client.Minecraft; +import net.minecraft.util.Timer; + +@Mixin(Timer.class) +/** + * Rewrites updateTimer to make it possible to interpolate ticks. + * @author Pancake + * + */ +public class MixinTimer { + + @Shadow + private int elapsedTicks; + @Shadow + private float renderPartialTicks; + @Shadow + private float elapsedPartialTicks; + @Shadow + private long lastSyncSysClock; + @Shadow + private float tickLength; + + @Unique + private long millisLastTick; + @Unique + private long lastGameLoop; + @Unique + private float lastTickDuration; + + @Inject(method = "updateTimer", at = @At("HEAD"), cancellable = true) + public void inject_tick(CallbackInfo ci) { + if (Minecraft.getMinecraft().getConnection() != null) { + lastSyncSysClock = Minecraft.getSystemTime(); // update the tick tracker so that after returning to scheduling the client won't catch up all ticks (max 10) + this.elapsedTicks = 0; // do not do any ticks + long newGameLoop = Minecraft.getSystemTime(); + if (TickSyncClient.shouldTick.compareAndSet(true, false)) { + this.elapsedTicks++; + this.lastTickDuration = newGameLoop - this.millisLastTick; + if(TickrateChangerClient.advanceTick) { + lastTickDuration = TickrateChangerClient.millisecondsPerTick; // Keep the lastTick duration steady during tickadvance, since it grows larger the longer you wait in tickrate 0 + } + this.millisLastTick = newGameLoop; // Update millisLastTick + this.renderPartialTicks = 0; // Reset after the tick + } + // Interpolating + this.elapsedPartialTicks = (newGameLoop - this.lastGameLoop) / this.lastTickDuration; + float newPartialTicks = this.renderPartialTicks; + newPartialTicks += this.elapsedPartialTicks; + newPartialTicks -= (int) this.renderPartialTicks; + if (newPartialTicks > this.renderPartialTicks) { + this.renderPartialTicks = newPartialTicks; + } + this.lastGameLoop = newGameLoop; + ci.cancel(); + } else { + this.millisLastTick = Minecraft.getSystemTime(); + this.lastGameLoop = Minecraft.getSystemTime(); + TickSyncClient.shouldTick.set(true); // The client should always tick if it once thrown out of the vanilla scheduling part, to make the server tick, etc. + } + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorEntity.java b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorEntity.java similarity index 86% rename from src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorEntity.java rename to src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorEntity.java index ea44535f..a805c1c5 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorEntity.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorEntity.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.accessors; +package com.minecrafttas.tasmod.mixin.accessors; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorMinecraftServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorMinecraftServer.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorMinecraftServer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorMinecraftServer.java index d3a79e61..67a388dc 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorMinecraftServer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorMinecraftServer.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.accessors; +package com.minecrafttas.tasmod.mixin.accessors; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorRunStuff.java b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorRunStuff.java similarity index 90% rename from src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorRunStuff.java rename to src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorRunStuff.java index 656bb4f3..c1b7e8bb 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorRunStuff.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorRunStuff.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.accessors; +package com.minecrafttas.tasmod.mixin.accessors; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorSaveHandler.java b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorSaveHandler.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorSaveHandler.java rename to src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorSaveHandler.java index f5633244..fecf5d52 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorSaveHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorSaveHandler.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.accessors; +package com.minecrafttas.tasmod.mixin.accessors; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorTimer.java b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorTimer.java similarity index 83% rename from src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorTimer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorTimer.java index f7c93464..55f8fec8 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorTimer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorTimer.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.accessors; +package com.minecrafttas.tasmod.mixin.accessors; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorWorld.java b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorWorld.java similarity index 90% rename from src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorWorld.java rename to src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorWorld.java index 95bec7a6..6c602a6e 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorWorld.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorWorld.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.accessors; +package com.minecrafttas.tasmod.mixin.accessors; import java.util.List; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorWorldServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorWorldServer.java similarity index 67% rename from src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorWorldServer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorWorldServer.java index 0976d5cc..429a798c 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/accessors/AccessorWorldServer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/accessors/AccessorWorldServer.java @@ -1,6 +1,7 @@ -package de.scribble.lp.tasmod.mixin.accessors; +package com.minecrafttas.tasmod.mixin.accessors; import java.util.Set; +import java.util.TreeSet; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -12,4 +13,7 @@ public interface AccessorWorldServer { @Accessor("pendingTickListEntriesHashSet") public Set getTickListEntries(); + + @Accessor("pendingTickListEntriesTreeSet") + public TreeSet getTreeListEntries(); } diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiControls.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiControls.java similarity index 86% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiControls.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiControls.java index ddef12b5..4f6e496d 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiControls.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiControls.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.events.OpenGuiEvents; +import com.minecrafttas.tasmod.events.OpenGuiEvents; + import net.minecraft.client.gui.GuiControls; import net.minecraft.client.gui.GuiScreen; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiIngameMenu.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiIngameMenu.java similarity index 83% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiIngameMenu.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiIngameMenu.java index 538680fd..8dd638e5 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiIngameMenu.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiIngameMenu.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.events.OpenGuiEvents; +import com.minecrafttas.tasmod.events.OpenGuiEvents; + import net.minecraft.client.gui.GuiIngameMenu; @Mixin(GuiIngameMenu.class) diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiMainMenu.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiMainMenu.java similarity index 86% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiMainMenu.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiMainMenu.java index ba9def54..b2276048 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinGuiMainMenu.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinGuiMainMenu.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -6,8 +6,9 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.events.OpenGuiEvents; -import de.scribble.lp.tasmod.gui.GuiMultiplayerWarn; +import com.minecrafttas.tasmod.events.OpenGuiEvents; +import com.minecrafttas.tasmod.gui.GuiMultiplayerWarn; + import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiScreen; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinIntegratedServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinIntegratedServer.java similarity index 82% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinIntegratedServer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinIntegratedServer.java index 95de4f5a..0005367a 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinIntegratedServer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinIntegratedServer.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; 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; -import de.scribble.lp.tasmod.events.LoadWorldEvents; +import com.minecrafttas.tasmod.events.LoadWorldEvents; + import net.minecraft.server.integrated.IntegratedServer; @Mixin(IntegratedServer.class) diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinMinecraft.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinMinecraft.java similarity index 75% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinMinecraft.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinMinecraft.java index 637bf09b..80db99a4 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinMinecraft.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinMinecraft.java @@ -1,11 +1,13 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.events.LoadWorldEvents; +import com.minecrafttas.tasmod.events.LoadWorldEvents; +import com.minecrafttas.tasmod.events.TickEvents; + import net.minecraft.client.Minecraft; @Mixin(Minecraft.class) @@ -20,4 +22,9 @@ public void inject_launchIntegratedServer(CallbackInfo ci) { public void inject_loadWorld(CallbackInfo ci) { LoadWorldEvents.doneLoadingClientWorld(); } + + @Inject(method = "runTick", at = @At("HEAD")) + public void inject_runTick(CallbackInfo ci) { + TickEvents.onClientTick(); + } } diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinMinecraftServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinMinecraftServer.java similarity index 67% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinMinecraftServer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinMinecraftServer.java index 5a65922d..6049c2ad 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinMinecraftServer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinMinecraftServer.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -6,14 +6,16 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.events.LoadWorldEvents; +import com.minecrafttas.tasmod.events.LoadWorldEvents; +import com.minecrafttas.tasmod.events.TickEvents; + import net.minecraft.server.MinecraftServer; @Mixin(MinecraftServer.class) public class MixinMinecraftServer { @Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z", shift = Shift.AFTER)) - public void inject_run(CallbackInfo ci) { + public void inject_init(CallbackInfo ci) { } @Inject(method = "initiateShutdown", at = @At("HEAD")) @@ -21,4 +23,9 @@ public void inject_initiateShutDown(CallbackInfo ci) { LoadWorldEvents.startShutdown(); } + @Inject(method = "tick", at = @At("HEAD")) + public void inject_tick(CallbackInfo ci) { + TickEvents.onServerTick(); + } + } diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinNetHandlerPlayClient.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinNetHandlerPlayClient.java similarity index 91% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinNetHandlerPlayClient.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinNetHandlerPlayClient.java index 99f2c409..7b731c8b 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinNetHandlerPlayClient.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -6,7 +6,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.events.PlayerJoinLeaveEvents; +import com.minecrafttas.tasmod.events.PlayerJoinLeaveEvents; + import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinPlayerList.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinPlayerList.java similarity index 90% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinPlayerList.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinPlayerList.java index fd981ad6..1a2ab67d 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinPlayerList.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinPlayerList.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.events.PlayerJoinLeaveEvents; +import com.minecrafttas.tasmod.events.PlayerJoinLeaveEvents; + import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.NetworkManager; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinWorldClient.java b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinWorldClient.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/mixin/events/MixinWorldClient.java rename to src/main/java/com/minecrafttas/tasmod/mixin/events/MixinWorldClient.java index 6518bc45..9afbcb66 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/events/MixinWorldClient.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/events/MixinWorldClient.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin.events; +package com.minecrafttas.tasmod.mixin.events; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.events.PlayerJoinLeaveEvents; +import com.minecrafttas.tasmod.events.PlayerJoinLeaveEvents; + import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.WorldClient; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinDragonFightManager.java b/src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinDragonFightManager.java similarity index 94% rename from src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinDragonFightManager.java rename to src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinDragonFightManager.java index cd15a9a3..f92b3d19 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinDragonFightManager.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinDragonFightManager.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.fixes; +package com.minecrafttas.tasmod.mixin.fixes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinMinecraftFullscreen.java b/src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinMinecraftFullscreen.java similarity index 88% rename from src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinMinecraftFullscreen.java rename to src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinMinecraftFullscreen.java index 6f68f9b8..602809bd 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinMinecraftFullscreen.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinMinecraftFullscreen.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.mixin.fixes; +package com.minecrafttas.tasmod.mixin.fixes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -6,7 +6,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.Minecraft; import net.minecraft.client.settings.GameSettings; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinNetworkManager.java b/src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinNetworkManager.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinNetworkManager.java rename to src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinNetworkManager.java index 35b1e741..fd68940a 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/fixes/MixinNetworkManager.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/fixes/MixinNetworkManager.java @@ -1,12 +1,13 @@ -package de.scribble.lp.tasmod.mixin.fixes; +package com.minecrafttas.tasmod.mixin.fixes; 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; -import de.scribble.lp.tasmod.events.LoadWorldEvents; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerServer; +import com.minecrafttas.tasmod.events.LoadWorldEvents; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; + import net.minecraft.network.INetHandler; import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.NetworkManager; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGameSettings.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGameSettings.java similarity index 89% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGameSettings.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGameSettings.java index ed3bbe3d..87f5515e 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGameSettings.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGameSettings.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.KeyBinding; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiChat.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiChat.java similarity index 83% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiChat.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiChat.java index aca04f3d..1aa618cf 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiChat.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiChat.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.gui.GuiChat; @Mixin(GuiChat.class) diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiClickableScrolledSelectionListProxy.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiClickableScrolledSelectionListProxy.java similarity index 85% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiClickableScrolledSelectionListProxy.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiClickableScrolledSelectionListProxy.java index 8e03552a..42de9814 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiClickableScrolledSelectionListProxy.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiClickableScrolledSelectionListProxy.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.gui.GuiClickableScrolledSelectionListProxy; @Mixin(GuiClickableScrolledSelectionListProxy.class) diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiContainer.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiContainer.java similarity index 92% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiContainer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiContainer.java index 39dd30c6..2a01ed15 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiContainer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiContainer.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.settings.KeyBinding; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiContainerCreative.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiContainerCreative.java similarity index 88% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiContainerCreative.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiContainerCreative.java index 9c2d9f32..5f22e419 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiContainerCreative.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiContainerCreative.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.gui.inventory.GuiContainerCreative; @Mixin(GuiContainerCreative.class) diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiScreenAdvancements.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiScreenAdvancements.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiScreenAdvancements.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiScreenAdvancements.java index 398f12f7..978457b4 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiScreenAdvancements.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiScreenAdvancements.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.gui.advancements.GuiScreenAdvancements; @Mixin(GuiScreenAdvancements.class) diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiSlot.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiSlot.java similarity index 92% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiSlot.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiSlot.java index c712c5f3..19682b97 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiSlot.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiSlot.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.gui.GuiSlot; @Mixin(GuiSlot.class) diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiStats.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiStats.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiStats.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiStats.java index ff89e630..479d1654 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinGuiStats.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinGuiStats.java @@ -1,10 +1,10 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; @Mixin(targets = "net.minecraft.client.gui.achievement.GuiStats$Stats") public class MixinGuiStats { diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinKeyBinding.java b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinKeyBinding.java similarity index 83% rename from src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinKeyBinding.java rename to src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinKeyBinding.java index 30e9cca5..9feacb73 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/playbackhooks/MixinKeyBinding.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/playbackhooks/MixinKeyBinding.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin.playbackhooks; +package com.minecrafttas.tasmod.mixin.playbackhooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ClientProxy; + import net.minecraft.client.settings.KeyBinding; @Mixin(KeyBinding.class) diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinChunkProviderClient.java b/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinChunkProviderClient.java similarity index 88% rename from src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinChunkProviderClient.java rename to src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinChunkProviderClient.java index e61b0bbf..c44e8e72 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinChunkProviderClient.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinChunkProviderClient.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.savestates; +package com.minecrafttas.tasmod.mixin.savestates; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import de.scribble.lp.tasmod.duck.ChunkProviderDuck; +import com.minecrafttas.tasmod.duck.ChunkProviderDuck; + import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.objects.ObjectIterator; import net.minecraft.client.multiplayer.ChunkProviderClient; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinChunkProviderServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinChunkProviderServer.java similarity index 90% rename from src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinChunkProviderServer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinChunkProviderServer.java index 3b2a00dd..e3f3f7dd 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinChunkProviderServer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinChunkProviderServer.java @@ -1,10 +1,11 @@ -package de.scribble.lp.tasmod.mixin.savestates; +package com.minecrafttas.tasmod.mixin.savestates; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import de.scribble.lp.tasmod.duck.ChunkProviderDuck; +import com.minecrafttas.tasmod.duck.ChunkProviderDuck; + import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.objects.ObjectIterator; import net.minecraft.world.chunk.Chunk; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinEntityPlayerMP.java b/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinEntityPlayerMP.java similarity index 92% rename from src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinEntityPlayerMP.java rename to src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinEntityPlayerMP.java index db8c8910..9885bd96 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/savestates/MixinEntityPlayerMP.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinEntityPlayerMP.java @@ -1,12 +1,13 @@ -package de.scribble.lp.tasmod.mixin.savestates; +package com.minecrafttas.tasmod.mixin.savestates; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.savestates.server.motion.ClientMotionServer; -import de.scribble.lp.tasmod.savestates.server.motion.ClientMotionServer.Saver; +import com.minecrafttas.tasmod.savestates.server.motion.ClientMotionServer; +import com.minecrafttas.tasmod.savestates.server.motion.ClientMotionServer.Saver; + import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinNetHandlerPlayServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinNetHandlerPlayServer.java new file mode 100644 index 00000000..27020dbd --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinNetHandlerPlayServer.java @@ -0,0 +1,21 @@ +package com.minecrafttas.tasmod.mixin.savestates; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.savestates.server.SavestateState; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.NetHandlerPlayServer; + +@Mixin(NetHandlerPlayServer.class) +public class MixinNetHandlerPlayServer { + + + @Redirect(method = "processPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayerMP;isInvulnerableDimensionChange()Z")) + public boolean redirect_processPlayer(EntityPlayerMP parentIn) { + return !parentIn.isInvulnerableDimensionChange() && (TASmod.savestateHandler.state!=SavestateState.LOADING && TASmod.savestateHandler.state!=SavestateState.WASLOADING); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/shields/MixinRenderItem.java b/src/main/java/com/minecrafttas/tasmod/mixin/shields/MixinRenderItem.java similarity index 90% rename from src/main/java/de/scribble/lp/tasmod/mixin/shields/MixinRenderItem.java rename to src/main/java/com/minecrafttas/tasmod/mixin/shields/MixinRenderItem.java index 4f60013d..e6941427 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/shields/MixinRenderItem.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/shields/MixinRenderItem.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin.shields; +package com.minecrafttas.tasmod.mixin.shields; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import de.scribble.lp.tasmod.shield.ShieldDownloader; +import com.minecrafttas.tasmod.util.ShieldDownloader; + import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.entity.EntityLivingBase; diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/shields/MixinTileEntityItemStackRenderer.java b/src/main/java/com/minecrafttas/tasmod/mixin/shields/MixinTileEntityItemStackRenderer.java similarity index 91% rename from src/main/java/de/scribble/lp/tasmod/mixin/shields/MixinTileEntityItemStackRenderer.java rename to src/main/java/com/minecrafttas/tasmod/mixin/shields/MixinTileEntityItemStackRenderer.java index 27aa59dd..d837e3ab 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/shields/MixinTileEntityItemStackRenderer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/shields/MixinTileEntityItemStackRenderer.java @@ -1,11 +1,12 @@ -package de.scribble.lp.tasmod.mixin.shields; +package com.minecrafttas.tasmod.mixin.shields; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.shield.ShieldDownloader; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.util.ShieldDownloader; + import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.tileentity.TileEntityItemStackRenderer; import net.minecraft.entity.EntityLivingBase; diff --git a/src/main/java/com/minecrafttas/tasmod/monitoring/DesyncMonitoring.java b/src/main/java/com/minecrafttas/tasmod/monitoring/DesyncMonitoring.java new file mode 100644 index 00000000..2533146a --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/monitoring/DesyncMonitoring.java @@ -0,0 +1,336 @@ +package com.minecrafttas.tasmod.monitoring; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.util.List; + +import com.dselent.bigarraylist.BigArrayList; +import com.minecrafttas.killtherng.custom.CustomRandom; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.util.text.TextFormatting; + +/** + * Stores the players position during recording and compares it with the position during playback + * @author Scribble + * + */ +public class DesyncMonitoring { + + private File tempDir = new File(Minecraft.getMinecraft().mcDataDir.getAbsolutePath() + File.separator + "saves" + File.separator + "tasfiles" + File.separator + "temp" + File.separator + "monitoring"); + + private BigArrayList container = new BigArrayList(tempDir.toString()); + + private MonitorContainer currentValues; + + private PlaybackController controller; + + /** + * Creates an empty desync monitor + * @param playbackController + */ + public DesyncMonitoring(PlaybackController playbackController) { + controller = playbackController; + } + + /** + * Parses lines and fills the desync monitor + * @param playbackController + * @param monitorLines + */ + public DesyncMonitoring(PlaybackController playbackController, List monitorLines) throws IOException{ + this(playbackController); + container = loadFromFile(monitorLines); + } + + public void recordNull(int index) { + if(container.size()<=index) { + container.add(new MonitorContainer(index)); + } else { + container.set(index, new MonitorContainer(index)); + } + } + + public void recordMonitor(int index) { + EntityPlayerSP player = Minecraft.getMinecraft().player; + MonitorContainer values = null; + if(player != null) { + values = new MonitorContainer(index, player.posX, player.posY, player.posZ, player.motionX, player.motionY, player.motionZ, TASmod.ktrngHandler.getGlobalSeedClient()); + } else { + values = new MonitorContainer(index, 0D, 0D, 0D, 0D, 0D, 0D, 0L); + } + + if(container.size()<=index) { + container.add(values); + } else { + container.set(index, values); + } + } + + public void playMonitor(int index) { + currentValues = get(index-1); + } + + private BigArrayList loadFromFile(List monitorLines) throws IOException { + BigArrayList out = new BigArrayList(tempDir.toString()); + int linenumber = 0; + for(String line : monitorLines) { + linenumber++; + String[] split = line.split(" "); + double x = 0; + double y = 0; + double z = 0; + double mx = 0; + double my = 0; + double mz = 0; + long seed = 0; + try { + x = Double.parseDouble(split[0]); + y = Double.parseDouble(split[1]); + z = Double.parseDouble(split[2]); + mx = Double.parseDouble(split[3]); + my = Double.parseDouble(split[4]); + mz = Double.parseDouble(split[5]); + seed = Long.parseLong(split[6]); + } catch (Exception e) { + e.printStackTrace(); + throw new IOException("Error in monitoring section in line "+ linenumber + ". Some value is not a number"); + } + out.add(new MonitorContainer(linenumber, x, y, z, mx, my, mz, seed)); + } + return out; + } + + public MonitorContainer get(int index) { + try { + return container.get(index); + } catch (IndexOutOfBoundsException e) { + return null; + } + } + + private String lastStatus = TextFormatting.GRAY + "Empty"; + + public String getStatus(EntityPlayerSP player) { + if (!controller.isNothingPlaying()) { + if (currentValues != null) { + double[] playervalues = new double[6]; + playervalues[0] = player.posX; + playervalues[1] = player.posY; + playervalues[2] = player.posZ; + playervalues[3] = player.motionX; + playervalues[4] = player.motionY; + playervalues[5] = player.motionZ; + DesyncStatus status = currentValues.getSeverity(controller.index(), playervalues, TASmod.ktrngHandler.getGlobalSeedClient()); + lastStatus = status.getFormat() + status.getText(); + } else { + lastStatus = TextFormatting.GRAY + "Empty"; + } + } + return lastStatus; + } + + private String lastPos = ""; + + public String getPos() { + if(currentValues!=null && !controller.isNothingPlaying()) { + EntityPlayerSP player = Minecraft.getMinecraft().player; + String[] values = new String[3]; + values[0]=getFormattedString(player.posX-currentValues.values[0]); + values[1]=getFormattedString(player.posY-currentValues.values[1]); + values[2]=getFormattedString(player.posZ-currentValues.values[2]); + + String out = ""; + for (String val : values) { + if(val !=null) { + out+=val+" "; + } + } + lastPos=out; + } + return lastPos; + } + + private String lastMotion = ""; + + public String getMotion() { + if(currentValues!=null && !controller.isNothingPlaying()) { + EntityPlayerSP player = Minecraft.getMinecraft().player; + String[] values = new String[3]; + values[0] = getFormattedString(player.motionX - currentValues.values[3]); + values[1] = getFormattedString(player.motionY - currentValues.values[4]); + values[2] = getFormattedString(player.motionZ - currentValues.values[5]); + + String out = ""; + for (String val : values) { + if (val != null) { + out+=val+" "; + } + } + lastMotion = out; + } + return lastMotion; + } + + private String lastSeed = ""; + + public String getSeed() { + if(currentValues!=null && !controller.isNothingPlaying()) { + if(currentValues.seed == TASmod.ktrngHandler.getGlobalSeedClient()) { + lastSeed = ""; + } else { + if(TASmod.ktrngHandler.isLoaded()) { + long distance = CustomRandom.distance(currentValues.seed, TASmod.ktrngHandler.getGlobalSeedClient()); + if(distance == 0L) { + lastSeed = ""; + } else { + lastSeed = DesyncStatus.SEED.format+Long.toString(distance); + } + } else { + lastSeed = DesyncStatus.SEED.format+"TAS was recorded with KillTheRNG"; + } + } + } + return lastSeed; + } + + private String getFormattedString(double delta) { + String out = ""; + if(delta != 0D) { + DesyncStatus status = DesyncStatus.fromDelta(delta); + if(status == DesyncStatus.EQUAL) { + return ""; + } + out = status.getFormat() + Double.toString(delta); + } + return out; + } + + public class MonitorContainer implements Serializable{ + private static final long serialVersionUID = -3138791930493647885L; + + int index; + + double[] values = new double[6]; + + long seed; + + + public MonitorContainer(int index, double posx, double posy, double posz, double velx, double vely, double velz, long seed) { + this.index = index; + this.values[0] = posx; + this.values[1] = posy; + this.values[2] = posz; + this.values[3] = velx; + this.values[4] = vely; + this.values[5] = velz; + this.seed = seed; + } + + public MonitorContainer(int index) { + this(index, 0, 0, 0, 0, 0, 0, 0); + } + + @Override + public String toString() { + return String.format("%s %s %s %s %s %s %s", values[0], values[1], values[2], values[3], values[4], values[5], seed); + } + + public DesyncStatus getSeverity(int index, double[] playerValues, long seed) { + + if(this.seed != seed) { + if(TASmod.ktrngHandler.isLoaded()) { + if(CustomRandom.distance(this.seed, seed)!=1) { + return DesyncStatus.SEED; + } + } else { + return DesyncStatus.SEED; + } + } + + DesyncStatus out = null; + + for (int i = 0; i < values.length; i++) { + double delta = 0; + try { + delta = playerValues[i] - values[i]; + } catch (Exception e) { + return DesyncStatus.ERROR; + } + DesyncStatus status = DesyncStatus.fromDelta(delta); + if(out==null || status.getSeverity() > out.getSeverity()) { + out = status; + } + } + + return out; + } + } + + public enum DesyncStatus { + EQUAL(0, TextFormatting.GREEN, "In sync", 0D), + WARNING(1, TextFormatting.YELLOW, "Slight desync", 0.00001D), + MODERATE(2, TextFormatting.RED, "Moderate desync", 0.01D), + TOTAL(3, TextFormatting.DARK_RED, "Total desync"), + SEED(3, TextFormatting.DARK_PURPLE, "RNG Seed desync"), + ERROR(3, TextFormatting.DARK_PURPLE, "ERROR"); + + private Double tolerance; + private int severity; + private String text; + private TextFormatting format; + + private DesyncStatus(int severity, TextFormatting color, String text) { + this.severity = severity; + this.format = color; + this.text = text; + tolerance = null; + } + + private DesyncStatus(int severity, TextFormatting color, String text, double tolerance) { + this(severity, color, text); + this.tolerance=tolerance; + } + + public static DesyncStatus fromDelta(double delta) { + DesyncStatus out = TOTAL; + for(DesyncStatus status : values()) { + if(status.tolerance == null) { + return status; + } + if(Math.abs(delta)=status.tolerance) { + out = status; + } + } + return out; + } + + public TextFormatting getFormat() { + return format; + } + + public int getSeverity() { + return severity; + } + + public String getText() { + return text; + } + } + + public void clear() { + currentValues=null; + container = new BigArrayList(tempDir.toString()); + lastStatus = TextFormatting.GRAY+"Empty"; + lastPos = ""; + lastMotion = ""; + lastSeed = ""; + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/monitoring/Monitor.java b/src/main/java/com/minecrafttas/tasmod/monitoring/Monitor.java similarity index 97% rename from src/main/java/de/scribble/lp/tasmod/monitoring/Monitor.java rename to src/main/java/com/minecrafttas/tasmod/monitoring/Monitor.java index c4e6a6a3..7e342eb4 100644 --- a/src/main/java/de/scribble/lp/tasmod/monitoring/Monitor.java +++ b/src/main/java/com/minecrafttas/tasmod/monitoring/Monitor.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.monitoring; +package com.minecrafttas.tasmod.monitoring; import java.lang.reflect.Field; diff --git a/src/main/java/com/minecrafttas/tasmod/networking/IdentificationPacket.java b/src/main/java/com/minecrafttas/tasmod/networking/IdentificationPacket.java new file mode 100644 index 00000000..2d548f4e --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/networking/IdentificationPacket.java @@ -0,0 +1,53 @@ +package com.minecrafttas.tasmod.networking; + +import java.util.UUID; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.ticksync.TickSyncServer; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +/** + * Used to identify the socket. This enables the server to send packets to a specific player + * @author Scribble + */ +public class IdentificationPacket implements Packet { + + private UUID uuid; + + public IdentificationPacket() { + + } + + public IdentificationPacket(UUID uuid) { + this.uuid = uuid; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if (side.isServer()) { + TickSyncServer.onPacket(this.uuid); + } else { + ClientProxy.packetClient.setReady(); + } + } + + @Override + public void serialize(PacketBuffer buf) { + if (uuid != null) { + buf.writeUniqueId(uuid); + } + } + + @Override + public void deserialize(PacketBuffer buf) { + if (buf.capacity() > 0) { + this.uuid = buf.readUniqueId(); + } + } + + public UUID getUuid() { + return uuid; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/networking/Packet.java b/src/main/java/com/minecrafttas/tasmod/networking/Packet.java new file mode 100644 index 00000000..776774f3 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/networking/Packet.java @@ -0,0 +1,36 @@ +package com.minecrafttas.tasmod.networking; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +/** + * This is a Packet transmittable over the TASmod Custom Server. + * + * IMPLEMENTATION NOTICE: + * There are no clientbound or serverbound packets as they were deemed unnecessary. This means both the server and the client can transmit any packet. + * @author Pancake + */ +public interface Packet { + + /** + * Once a packet is being received it is immediately handled in this method. + * + * IMPLEMENTATION NOTICE: + * This process is non-blocking for the game and executed on the tasmod server thread temporarily blocking it. + */ + void handle(PacketSide side, EntityPlayer player); + + /** + * In order to transfer packets over the network connection they need to be serialized into a stream of bytes. + * @param buf Packet buffer to serialize to + * @return A serializable packet buffer + */ + void serialize(PacketBuffer buf); + + /** + * In order to receive packets over the network connection the other end serializes the packet into a stream of bytes. Therefore this end needs to deserialize the packet + * @param buf A deserializable packet buffer + */ + void deserialize(PacketBuffer buf); + +} diff --git a/src/main/java/com/minecrafttas/tasmod/networking/PacketSerializer.java b/src/main/java/com/minecrafttas/tasmod/networking/PacketSerializer.java new file mode 100644 index 00000000..11d53a3c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/networking/PacketSerializer.java @@ -0,0 +1,83 @@ +package com.minecrafttas.tasmod.networking; + +import java.util.ArrayList; + +import com.minecrafttas.tasmod.TASmod; + +import io.netty.buffer.Unpooled; +import net.minecraft.network.PacketBuffer; + +/** + * This class helps serializing and deserializing packets + * @author Pancake + */ +public class PacketSerializer { + + private static ArrayList> REGISTRY = new ArrayList<>(); + + /** + * Deserialize a TASmod packet from a packet buffer. The packet class is prefixed with an id and read here. + * + * @param buf Serialized byte buffer with id prefix + * @return Deserialized packet + */ + public static Packet deserialize(PacketBuffer buf) { + // Read packet id and deserialize the correct packet + int packetId = buf.readInt(); + + Packet packet=null; + try { + packet = REGISTRY.get(packetId).newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + if(packet == null) { + TASmod.logger.warn("Unregistered packet received! Packet Id: " + packetId); + return null; + } + + packet.deserialize(buf); + return packet; + } + + /** + * Serialize a TASmod packet to a packet buffer. The packet class is read and a id prefixed packet buffer is returned + * + * @param packet Non-serialized packet + * @return Serialized packet buffer with id prefix + */ + public static PacketBuffer serialize(Packet packet) { + // Figure out packet class and prefix the correct id + + PacketBuffer buf = new PacketBuffer(Unpooled.buffer()); + int packetID = REGISTRY.indexOf(packet.getClass()); + + if(packetID == -1) { + TASmod.logger.warn("Unregistered packet was trying to be serialized! Packet Class: " + packet.getClass().getSimpleName()); + return null; + } + + buf.writeInt(packetID); + + packet.serialize(buf); + return buf; + } + + public static void registerPacket(Class packet) { + if(REGISTRY.contains(packet)) { + TASmod.logger.warn("Trying to register packet which already exists: "+packet.getClass().getSimpleName()); + } + REGISTRY.add(packet); + } + + public static void unregisterPacket(Class packet) { + if(REGISTRY.contains(packet)) { + TASmod.logger.warn("Trying to unregister packet which doesn't exist in the registry: "+packet.getClass().getSimpleName()); + } + REGISTRY.remove(packet); + } + +} diff --git a/src/main/java/com/minecrafttas/tasmod/networking/PacketSide.java b/src/main/java/com/minecrafttas/tasmod/networking/PacketSide.java new file mode 100644 index 00000000..7b9c0e48 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/networking/PacketSide.java @@ -0,0 +1,14 @@ +package com.minecrafttas.tasmod.networking; + +public enum PacketSide { + CLIENT, + SERVER; + + public boolean isClient() { + return this == CLIENT; + } + + public boolean isServer() { + return this == SERVER; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/networking/TASmodNetworkClient.java b/src/main/java/com/minecrafttas/tasmod/networking/TASmodNetworkClient.java new file mode 100644 index 00000000..2a429b9e --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/networking/TASmodNetworkClient.java @@ -0,0 +1,145 @@ +package com.minecrafttas.tasmod.networking; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.InterruptedIOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketException; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +import org.apache.logging.log4j.Logger; + +import com.minecrafttas.tasmod.ClientProxy; + +import io.netty.buffer.Unpooled; +import net.minecraft.client.Minecraft; +import net.minecraft.network.PacketBuffer; + +public class TASmodNetworkClient { + + private Logger logger; + + private Thread clientThread; + + private Socket clientSocket; + + private BlockingQueue packetsToSend = new LinkedBlockingQueue<>(); + + private boolean ready = false; + + public TASmodNetworkClient(Logger logger) { + this(logger, "127.0.0.1", 3111); // Set ip for different server + } + + public TASmodNetworkClient(Logger logger, String serverIP, int port) { + this.logger = logger; + this.logger.info("Trying to connect to {}:{}", serverIP, port); + createClient(serverIP, port); + } + + public void sendToServer(Packet packet) { + if(clientThread == null) + return; + if(!clientThread.isAlive()) + return; + packetsToSend.add(packet); + } + + private void createClient(String serverIp, int port) { + + packetsToSend.add(new IdentificationPacket(Minecraft.getMinecraft().player.getUniqueID())); + + clientThread = new Thread(() -> { + try(Socket cSocket = new Socket()){ + cSocket.connect(new InetSocketAddress(serverIp, port)); + this.clientSocket = cSocket; + + clientSocket.setTcpNoDelay(true); + // Prepare the in and out streams. + DataInputStream inputStream = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream())); + + createSendThread(); + + // Use the current thread to indefinitly fetch packets + Packet packet; + while (clientSocket.isConnected()) { + // Handle the next packet. If no packet is avilable, the readInt() call will hang until there is one. + int packetSize = inputStream.readInt(); + byte[] packetData = new byte[packetSize]; + inputStream.read(packetData, 0, packetSize); + PacketBuffer packetBuf = new PacketBuffer(Unpooled.wrappedBuffer(packetData)); + // Deserialize and run the packet + packet = PacketSerializer.deserialize(packetBuf); + packet.handle(PacketSide.CLIENT, Minecraft.getMinecraft().player); + logger.trace("Handled a " + packet.getClass().getSimpleName() + " from the socket."); + } + + } catch (EOFException | SocketException | InterruptedIOException exception) { + // The custom TASmod client was closed and the end of stream was reached. The socket was shut down properly. + logger.info("Custom TASmod client was shutdown"); + } catch (Exception exception) { + logger.error("Custom TASmod client was unexpectedly shutdown {}", exception); + exception.printStackTrace(); + ClientProxy.gameLoopSchedulerClient.add(()->{ + throw new RuntimeException("TASmod networking was shut down. The real errors are above"); + }); + } + }); + clientThread.setName("TASmod Network Client Accept"); + clientThread.setDaemon(true); + clientThread.start(); + } + + private void createSendThread() throws IOException { + DataOutputStream outputStream = new DataOutputStream(new BufferedOutputStream(clientSocket.getOutputStream())); + // Create a new thread that writes packets if available + Thread outputThread = new Thread(() -> { + try { + Packet packet; + while (!clientSocket.isClosed()) { + // Try to poll another packet that wants to be sent + packet = packetsToSend.peek(); + boolean skip = !(packet instanceof IdentificationPacket) && !ready; + if (packet == null || skip) { + Thread.sleep(1); // If nothing has to be done, let the cpu rest by waiting + continue; + } + packetsToSend.poll(); + // A packet was found: Serialize then send it. + byte[] packetData = PacketSerializer.serialize(packet).array(); + outputStream.writeInt(packetData.length); + outputStream.write(packetData); + outputStream.flush(); + logger.trace("Sent a " + packet.getClass().getSimpleName() + " to the socket."); + } + } catch (Exception e) { + e.printStackTrace(); + // This exception is already logged by the thread one layer above + // therefore nothing needs to be done here. + } + }); + outputThread.setDaemon(true); // If daemon is set, the jvm will quit without waiting for this thread to finish + outputThread.setName("TASmod Network Client Send"); + outputThread.start(); + } + + public void killClient() throws IOException { + if(clientThread != null && clientSocket != null) { + clientSocket.close(); + } + } + + public boolean isClosed() { + return clientSocket.isClosed(); + } + + public void setReady() { + ready = true; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/networking/TASmodNetworkServer.java b/src/main/java/com/minecrafttas/tasmod/networking/TASmodNetworkServer.java new file mode 100644 index 00000000..de3daebd --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/networking/TASmodNetworkServer.java @@ -0,0 +1,237 @@ +package com.minecrafttas.tasmod.networking; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.EOFException; +import java.io.IOException; +import java.io.InterruptedIOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +import org.apache.logging.log4j.Logger; + +import com.minecrafttas.tasmod.TASmod; + +import io.netty.buffer.Unpooled; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; + +/** + * A custom packet server extending beyond the standard Minecraft network manager + * @author Pancake, Scribble + * + */ +public class TASmodNetworkServer { + + private Logger logger; + + private Thread serverThread; + + private ServerSocket serverSocket; + + private Map connectedPlayers = Collections.synchronizedMap(new HashMap()); + + private Map> queues = Collections.synchronizedMap(new HashMap<>()); + + private int connections = 0; + + public TASmodNetworkServer(Logger logger) throws IOException { + this(logger, 3111); + } + + public TASmodNetworkServer(Logger logger, int port) throws IOException { + this.logger = logger; + createServer(port); + } + + private void createServer(int port) throws IOException { + serverThread = new Thread(() -> { + + try(ServerSocket serverS = new ServerSocket(port)){ + this.serverSocket = serverS; + + while (!this.serverSocket.isClosed()) { + Socket socket = null; + + socket = serverSocket.accept(); + socket.setTcpNoDelay(true); + + final LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + + connections++; + createSendThread(socket, queue); + createAcceptThread(socket, queue); + } + + } catch (EOFException | SocketException | InterruptedIOException exception) { + logger.debug("Custom TASmod server was shutdown"); + } catch (Exception exception) { + logger.error("Custom TASmod server was unexpectedly shutdown {}", exception); + exception.printStackTrace(); + } + + }); + serverThread.setName("TASmod Network Server Main"); + serverThread.setDaemon(true); + serverThread.start(); + } + + private void createSendThread(Socket socket, LinkedBlockingQueue packetQueue) throws IOException, InterruptedException { + Thread sendThread = new Thread(()->{ + DataOutputStream outputStream; + try { + outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); + } catch (IOException e) { + e.printStackTrace(); + return; + } + Packet packet; + while (!socket.isClosed()) { + try { + // Try to poll another packet that wants to be sent + packet = packetQueue.poll(); + if (packet == null) { + Thread.sleep(1); // If nothing has to be done, let the cpu rest by waiting + continue; + } + // A packet was found: Serialize then send it. + byte[] packetData = PacketSerializer.serialize(packet).array(); + outputStream.writeInt(packetData.length); + outputStream.write(packetData); + outputStream.flush(); + logger.trace("Sent a " + packet.getClass().getSimpleName() + " to the socket."); + } catch(Exception e) { + logger.catching(e); + } + } + }); + sendThread.setDaemon(true); + sendThread.setName("TASmod Network Server Send #"+connections); + sendThread.start(); + } + + private void createAcceptThread(Socket socket, LinkedBlockingQueue packetQueue) throws IOException { + Thread acceptThread = new Thread(()->{ + DataInputStream inputStream; + try { + inputStream = new DataInputStream(new BufferedInputStream(socket.getInputStream())); + } catch (IOException e2) { + e2.printStackTrace(); + return; + } + Packet packet; + while (!socket.isClosed()) { + // Handle the next packet. If no packet is avilable, the readInt() call will + // hang until there is one. + try { + int packetSize = inputStream.readInt(); + byte[] packetData = new byte[packetSize]; + inputStream.read(packetData, 0, packetSize); + + PacketBuffer packetBuf = new PacketBuffer(Unpooled.wrappedBuffer(packetData)); + // Deserialize and run the packet + packet = PacketSerializer.deserialize(packetBuf); + + if(packet instanceof IdentificationPacket) { + handleIdentificationPacket(packet, socket, packetQueue); + } + + if(connectedPlayers.containsKey(socket)) { + UUID id = connectedPlayers.get(socket); + EntityPlayerMP player = TASmod.getServerInstance().getPlayerList().getPlayerByUUID(id); + + packet.handle(PacketSide.SERVER, player); + logger.trace("Handled a " + packet.getClass().getSimpleName() + " from the socket."); + } + }catch (EOFException e){ + logger.info("Client socket was shut down"); + try { + socket.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } catch (Exception e) { + logger.error(e.getMessage()); + e.printStackTrace(); + try { + socket.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } + UUID id = connectedPlayers.get(socket); + connectedPlayers.remove(socket); + queues.remove(id); + connections--; + }); + acceptThread.setDaemon(true); + acceptThread.setName("TASmod Network Server Accept #"+connections); + acceptThread.start(); + } + + private void handleIdentificationPacket(Packet packet, Socket socket, LinkedBlockingQueue packetQueue) { + if(!connectedPlayers.containsKey(socket)) { + IdentificationPacket idPacket = (IdentificationPacket) packet; + logger.info("Identified player with uuid: {}", idPacket.getUuid()); + connectedPlayers.put(socket, idPacket.getUuid()); + queues.put(idPacket.getUuid(), packetQueue); + sendTo(new IdentificationPacket(), idPacket.getUuid()); + } + } + + public void sendToAll(Packet packet) { + if(serverThread.isAlive()) { + queues.forEach((id, queue) -> queue.add(packet)); + } + } + + public void sendTo(Packet packet, EntityPlayerMP... players) { + if(serverThread.isAlive()) { + queues.forEach((id, queue) -> { + for(EntityPlayerMP player : players) { + if(player.getUniqueID().equals(id)) { + queue.add(packet); + } + } + + }); + } + } + + public void sendTo(Packet packet, UUID... uuids) { + if(serverThread.isAlive()) { + queues.forEach((id, queue) -> { + for(UUID idToSend : uuids) { + if(idToSend.equals(id)) { + queue.add(packet); + } + } + }); + } + } + + public int getConnections() { + return connections; + } + + public void close() { + if(serverSocket==null) + return; + try { + serverSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + connections = 0; + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/inputcontainer/InputContainer.java b/src/main/java/com/minecrafttas/tasmod/playback/PlaybackController.java similarity index 70% rename from src/main/java/de/scribble/lp/tasmod/inputcontainer/InputContainer.java rename to src/main/java/com/minecrafttas/tasmod/playback/PlaybackController.java index caf732b8..cbcbded4 100644 --- a/src/main/java/de/scribble/lp/tasmod/inputcontainer/InputContainer.java +++ b/src/main/java/com/minecrafttas/tasmod/playback/PlaybackController.java @@ -1,6 +1,7 @@ -package de.scribble.lp.tasmod.inputcontainer; +package com.minecrafttas.tasmod.playback; import java.io.File; +import java.io.Serializable; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -8,53 +9,57 @@ import org.lwjgl.opengl.Display; import com.dselent.bigarraylist.BigArrayList; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.monitoring.DesyncMonitoring; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.playback.controlbytes.ControlByteHandler; +import com.minecrafttas.tasmod.playback.server.TASstateClient; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.virtual.VirtualInput; +import com.minecrafttas.tasmod.virtual.VirtualKeyboard; +import com.minecrafttas.tasmod.virtual.VirtualMouse; +import com.minecrafttas.tasmod.virtual.VirtualSubticks; import com.mojang.realmsclient.gui.ChatFormatting; import com.mojang.realmsclient.util.Pair; -import de.pfannekuchen.tasmod.controlbytes.ControlByteHandler; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.monitoring.DesyncMonitoring; -import de.scribble.lp.tasmod.util.ContainerSerialiser; -import de.scribble.lp.tasmod.util.TASstate; -import de.scribble.lp.tasmod.virtual.VirtualInput; -import de.scribble.lp.tasmod.virtual.VirtualKeyboard; -import de.scribble.lp.tasmod.virtual.VirtualMouse; -import de.scribble.lp.tasmod.virtual.VirtualSubticks; -import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; /** - * A container where the inputs are stored.
+ * A controller where the inputs are stored.
*
- * Filling this container is accomplished by setting the state to "recording" + * Filling this controller is accomplished by setting the state to "recording" * via {@linkplain #setRecording(boolean)},
* or by loading inputs from file.
*
* These inputs can be played back at any time by setting * {@linkplain #setPlayback(boolean)} to true.
*
- * Information about the author etc. get stored in the input container too and + * Information about the author etc. get stored in the playback controller too and * will be printed out in chat when the player loads into a world
* Inputs are saved and loaded to/from file via the - * {@linkplain ContainerSerialiser} + * {@linkplain PlaybackSerialiser} * - * @author ScribbleLP + * @author Scribble * */ -public class InputContainer { +public class PlaybackController { /** - * The current state of the container. + * The current state of the controller. */ private TASstate state = TASstate.NONE; + /** + * The state of the controller when the state is paused + */ private TASstate tempPause = TASstate.NONE; /** * The current index of the inputs @@ -74,10 +79,22 @@ public class InputContainer { */ private BigArrayList inputs = new BigArrayList(directory + File.separator + "temp"); - // All control characters - private Map>> controls = new HashMap>>(); + /** + * A map of control bytes. Used to change settings during playback via the playback file. + *

+ * A full list of changes can be found in {@link ControlByteHandler} + *

+ * The values are as follows:

+ * Map(int playbackLine, List(Pair(String controlCommand, String[] arguments))" + */ + private Map>> controlBytes = new HashMap>>(); + + /** + * The comments in the file, used to store them again later + */ + private Map> comments = new HashMap<>(); - public DesyncMonitoring dMonitor = new DesyncMonitoring(); + public DesyncMonitoring desyncMonitor = new DesyncMonitoring(this); // ===================================================================================================== @@ -90,10 +107,14 @@ public class InputContainer { private int rerecords = 0; private String startLocation = ""; + + private long startSeed = TASmod.ktrngHandler.getGlobalSeedClient(); // ===================================================================================================== private boolean creditsPrinted=false; + + private Integer playUntil = null; /** * Starts or stops a recording/playback @@ -131,7 +152,7 @@ public String setTASState(TASstate stateIn, boolean verbose) { case PLAYBACK: if (Minecraft.getMinecraft().player != null && !startLocation.isEmpty()) { try { - tpPlayer(startLocation); // TODO #99 Make this a secondary command + tpPlayer(startLocation); } catch (NumberFormatException e) { state = TASstate.NONE; e.printStackTrace(); @@ -142,11 +163,17 @@ public String setTASState(TASstate stateIn, boolean verbose) { index = 0; state = TASstate.PLAYBACK; creditsPrinted=false; + TASmod.ktrngHandler.setInitialSeed(startSeed); return verbose ? TextFormatting.GREEN + "Starting playback" : ""; case RECORDING: - if (Minecraft.getMinecraft().player != null) { + if (Minecraft.getMinecraft().player != null && startLocation.isEmpty()) { startLocation = getStartLocation(Minecraft.getMinecraft().player); } + if(this.inputs.isEmpty()) { + inputs.add(new TickInputContainer(index)); + desyncMonitor.recordNull(index); +// desyncMonitor.recordNull(index+1); + } state = TASstate.RECORDING; return verbose ? TextFormatting.GREEN + "Starting a recording" : ""; case PAUSED: @@ -181,6 +208,7 @@ public String setTASState(TASstate stateIn, boolean verbose) { ClientProxy.virtual.unpressEverything(); return verbose ? TextFormatting.GREEN + "Pausing a playback" : ""; case NONE: + Minecraft.getMinecraft().gameSettings.chatLinks = true; ClientProxy.virtual.unpressEverything(); state = TASstate.NONE; return verbose ? TextFormatting.GREEN + "Stopping the playback" : ""; @@ -330,10 +358,13 @@ public VirtualSubticks addSubticksToContainer(VirtualSubticks subticks) { public void nextTick() { /*Stop the playback while player is still loading*/ EntityPlayerSP player=Minecraft.getMinecraft().player; - if(player!=null&&!player.addedToChunk) { - pause(true); - }else { - pause(false); + + if(player!=null && player.addedToChunk) { + if(isPaused() && tempPause != TASstate.NONE) { + TASstateClient.setOrSend(tempPause); // The recording is paused in LoadWorldEvents#startLaunchServer + pause(false); + printCredits(); + } } /*Tick the next playback or recording*/ @@ -346,8 +377,15 @@ public void nextTick() { private void recordNextTick() { index++; - inputs.add(new TickInputContainer(index, keyboard.clone(), mouse.clone(), subticks.clone())); - dMonitor.capturePosition(); // Capturing the current position of the player + if(inputs.size()<=index) { + if(inputs.size()= index; i--) { + inputs.remove(i); + } + index--; + TASstateClient.setOrSend(TASstate.RECORDING); + return; + } + /*Stop condition*/ - if (index >= inputs.size()) { + if (index == inputs.size()) { unpressContainer(); - TASstate.setOrSend(TASstate.NONE); + TASstateClient.setOrSend(TASstate.NONE); } /*Continue condition*/ else { @@ -370,11 +420,9 @@ private void playbackNextTick() { this.mouse = tickcontainer.getMouse().clone(); this.subticks = tickcontainer.getSubticks().clone(); // check for control bytes - List> controlbyte = controls.get(index); - if (controlbyte != null) - for (Pair pair : controlbyte) - ControlByteHandler.onControlByte(pair.first(), pair.second()); + ControlByteHandler.readCotrolByte(controlBytes.get(index)); } + desyncMonitor.playMonitor(index); } // ===================================================================================================== // Methods to manipulate inputs @@ -396,7 +444,11 @@ public BigArrayList getInputs() { } public Map>> getControlBytes() { - return controls; + return controlBytes; + } + + public Map> getComments() { + return comments; } public void setIndex(int index) throws IndexOutOfBoundsException{ @@ -425,9 +477,11 @@ public TickInputContainer get(int index) { public void clear() { inputs = new BigArrayList(directory + File.separator + "temp"); - controls.clear(); + controlBytes.clear(); + comments.clear(); index = 0; - dMonitor.getPos().clear(); + startLocation=""; + desyncMonitor.clear(); clearCredits(); } @@ -497,6 +551,14 @@ public void fixTicks() { inputs.get(i).setTick(i + 1); } } + + public long getStartSeed() { + return startSeed; + } + + public void setStartSeed(long startSeed) { + this.startSeed = startSeed; + } // ===================================================================================================== // Methods and classes related to the start location of a TAS @@ -546,10 +608,16 @@ private void tpPlayer(String startLocation) throws NumberFormatException { float angleYaw = Float.parseFloat(section[3]); float anglePitch = Float.parseFloat(section[4]); - CommonProxy.NETWORK.sendToServer(new TeleportPlayerPacket(x, y, z, angleYaw, anglePitch)); + ClientProxy.packetClient.sendToServer(new TeleportPlayerPacket(x, y, z, angleYaw, anglePitch)); } - public static class TeleportPlayerPacket implements IMessage { + /** + * Permissionless player teleporting packet + * + * @author Scribble + * + */ + public static class TeleportPlayerPacket implements Packet { double x; double y; @@ -570,16 +638,20 @@ public TeleportPlayerPacket() { } @Override - public void fromBytes(ByteBuf buf) { - this.x = buf.readDouble(); - this.y = buf.readDouble(); - this.z = buf.readDouble(); - this.angleYaw = buf.readFloat(); - this.anglePitch = buf.readFloat(); + public void handle(PacketSide side, EntityPlayer playerz) { + if (side.isServer()) { + EntityPlayerMP player = (EntityPlayerMP) playerz; + player.getServerWorld().addScheduledTask(() -> { + player.rotationPitch = anglePitch; + player.rotationYaw = angleYaw; + + player.setPositionAndUpdate(x, y, z); + }); + } } @Override - public void toBytes(ByteBuf buf) { + public void serialize(PacketBuffer buf) { buf.writeDouble(x); buf.writeDouble(y); buf.writeDouble(z); @@ -588,32 +660,18 @@ public void toBytes(ByteBuf buf) { buf.writeFloat(anglePitch); } - } - - /** - * Permissionless player teleporting packet - * - * @author ScribbleLP - * - */ - public static class TeleportPlayerPacketHandler implements IMessageHandler { - @Override - public IMessage onMessage(TeleportPlayerPacket message, MessageContext ctx) { - if (ctx.side.isServer()) { - net.minecraft.entity.player.EntityPlayerMP player = ctx.getServerHandler().player; - ctx.getServerHandler().player.getServerWorld().addScheduledTask(() -> { - player.rotationPitch = message.anglePitch; - player.rotationYaw = message.angleYaw; - - player.setPositionAndUpdate(message.x, message.y, message.z); - }); - } - return null; + public void deserialize(PacketBuffer buf) { + this.x = buf.readDouble(); + this.y = buf.readDouble(); + this.z = buf.readDouble(); + this.angleYaw = buf.readFloat(); + this.anglePitch = buf.readFloat(); } } + // ============================================================== /** @@ -646,4 +704,126 @@ private void printMessage(String msg, ChatFormatting format) { Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(formatString + msg)); } + + public void setPlayUntil(int until) { + this.playUntil = until; + } + + // ============================================================== + + /** + * Storage class which stores the keyboard, mouse and subticks of a given tick. + * @author Scribble + * + */ + public static class TickInputContainer implements Serializable { + + private static final long serialVersionUID = -3420565284438152474L; + + private int tick; + + private VirtualKeyboard keyboard; + + private VirtualMouse mouse; + + private VirtualSubticks subticks; + + public TickInputContainer(int tick, VirtualKeyboard keyboard, VirtualMouse mouse, VirtualSubticks subticks) { + this.tick = tick; + this.keyboard = keyboard; + this.mouse = mouse; + this.subticks = subticks; + } + + public TickInputContainer(int tick) { + this.tick = tick; + this.keyboard = new VirtualKeyboard(); + this.mouse = new VirtualMouse(); + this.subticks = new VirtualSubticks(0, 0); + } + + @Override + public String toString() { + return tick + "|" + keyboard.toString() + "|" + mouse.toString() + "|" + subticks.toString(); + } + + public VirtualKeyboard getKeyboard() { + return keyboard; + } + + public VirtualMouse getMouse() { + return mouse; + } + + public VirtualSubticks getSubticks() { + return subticks; + } + + public int getTick() { + return tick; + } + + public void setTick(int tick) { + this.tick = tick; + } + + @Override + public TickInputContainer clone() { + return new TickInputContainer(tick, keyboard, mouse, subticks); + } + } + + /** + * State of the input recorder + * @author Scribble + * + */ + public static enum TASstate { + /** + * The game records inputs to the {@link InputContainer}. + */ + RECORDING, + /** + * The game plays back the inputs loaded in {@link InputContainer} and locks user interaction. + */ + PLAYBACK, + /** + * The playback or recording is paused and may be resumed. Note that the game isn't paused, only the playback. Useful for debugging things. + */ + PAUSED, // #124 + /** + * The game is neither recording, playing back or paused, is also set when aborting all mentioned states. + */ + NONE; + + public int getIndex() { + switch(this) { + case NONE: + return 0; + case PLAYBACK: + return 1; + case RECORDING: + return 2; + case PAUSED: + return 3; + default: + return 0; + } + } + + public static TASstate fromIndex(int state) { + switch (state) { + case 0: + return NONE; + case 1: + return PLAYBACK; + case 2: + return RECORDING; + case 3: + return PAUSED; + default: + return NONE; + } + } + } } diff --git a/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java b/src/main/java/com/minecrafttas/tasmod/playback/PlaybackSerialiser.java similarity index 60% rename from src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java rename to src/main/java/com/minecrafttas/tasmod/playback/PlaybackSerialiser.java index 48802a68..18f3d328 100644 --- a/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java +++ b/src/main/java/com/minecrafttas/tasmod/playback/PlaybackSerialiser.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.util; +package com.minecrafttas.tasmod.playback; import java.io.File; import java.io.IOException; @@ -6,23 +6,25 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.apache.commons.io.FileUtils; import com.dselent.bigarraylist.BigArrayList; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.monitoring.DesyncMonitoring; +import com.minecrafttas.tasmod.playback.PlaybackController.TickInputContainer; +import com.minecrafttas.tasmod.playback.controlbytes.ControlByteHandler; +import com.minecrafttas.tasmod.util.FileThread; +import com.minecrafttas.tasmod.virtual.VirtualKey; +import com.minecrafttas.tasmod.virtual.VirtualKeyboard; +import com.minecrafttas.tasmod.virtual.VirtualMouse; +import com.minecrafttas.tasmod.virtual.VirtualMouse.PathNode; +import com.minecrafttas.tasmod.virtual.VirtualSubticks; import com.mojang.realmsclient.util.Pair; -import de.scribble.lp.tasmod.inputcontainer.InputContainer; -import de.scribble.lp.tasmod.inputcontainer.TickInputContainer; -import de.scribble.lp.tasmod.monitoring.DesyncMonitoring; -import de.scribble.lp.tasmod.virtual.VirtualKey; -import de.scribble.lp.tasmod.virtual.VirtualKeyboard; -import de.scribble.lp.tasmod.virtual.VirtualMouse; -import de.scribble.lp.tasmod.virtual.VirtualMouse.PathNode; -import de.scribble.lp.tasmod.virtual.VirtualSubticks; - /** - * Saves a given {@linkplain InputContainer} to a file. Is also able to read an input container from a file.
+ * Saves a given {@linkplain PlaybackController} to a file. Is also able to read an input container from a file.
*
* I plan to be backwards compatible so all the save functions have a V1 in their name by the time of writing this
*
@@ -33,7 +35,49 @@ * @author ScribbleLP * */ -public class ContainerSerialiser { +public class PlaybackSerialiser { + + /** + * A list of sections to check for in the playback file + * @author ScribbleLP + * + */ + public enum SectionsV1{ + TICKS("Ticks", ""), + KEYBOARD("Keyboard", "(\\|Keyboard:)"), + MOUSE("Mouse", "(\\|Mouse:)"), + CAMERA("Camera", "(\\|Camera:)"); + + private String name; + private String regex; + + private SectionsV1(String nameIn, String regexIn) { + name=nameIn; + regex=regexIn; + } + + public String getName() { + return name; + } + + public String getRegex() { + return regex; + } + + public static String getRegexString() { + String out=""; + for(SectionsV1 section : values()) { + if(!section.getRegex().isEmpty()) { + String seperator="|"; + if(values().length-1==section.ordinal()) { + seperator=""; + } + out=out.concat(section.getRegex()+seperator); + } + } + return out; + } + } /** * Saves all inputs of the input container @@ -41,7 +85,7 @@ public class ContainerSerialiser { * @param container The container to save * @throws IOException When the input container is empty */ - public void saveToFileV1(File file, InputContainer container) throws IOException { + public void saveToFileV1(File file, PlaybackController container) throws IOException { saveToFileV1Until(file, container, -1); } @@ -52,15 +96,15 @@ public void saveToFileV1(File file, InputContainer container) throws IOException * @param index index until the inputs get saved * @throws IOException When the input container is empty */ - public void saveToFileV1Until(File file, InputContainer container, int index) throws IOException{ + public void saveToFileV1Until(File file, PlaybackController container, int index) throws IOException{ if (container.size() == 0) { throw new IOException("There are no inputs to save to a file"); } FileThread fileThread = new FileThread(file, false); - FileThread monitorThread= new FileThread(new File(file, "../"+file.getName().replace(".tas", "")+".mon"), false); +// FileThread monitorThread= new FileThread(new File(file, "../"+file.getName().replace(".mctas", "")+".mon"), false); fileThread.start(); - monitorThread.start(); +// monitorThread.start(); fileThread.addLine("################################################# TASFile ###################################################\n" + "# Version:1 #\n" @@ -79,19 +123,42 @@ public void saveToFileV1Until(File file, InputContainer container, int index) th + "# #\n" + "#----------------------------------------------- Settings --------------------------------------------------#\n" + "#StartPosition:"+container.getStartLocation()+"\n" - + "#############################################################################################################\n"); + + "# #\n" + + "#StartSeed:" + container.getStartSeed() + "\n" + + "#############################################################################################################\n" + + "#Comments start with \"//\" at the start of the line, comments with # will not be saved\n"); BigArrayList ticks = container.getInputs(); + Map>> cbytes= container.getControlBytes(); + Map> comments = container.getComments(); + for (int i = 0; i < ticks.size(); i++) { if(i==index) { break; } - TickInputContainer tick = ticks.get(i); - fileThread.addLine(tick.toString() + "\n"); - monitorThread.addLine(container.dMonitor.get(i) + "\n"); + + // Add comments + if(comments.containsKey(i)) { + List multiLine=comments.get(i); + multiLine.forEach(comment -> { + fileThread.addLine("//"+comment+"\n"); + }); + } + + // Add controlbytes + if(cbytes.containsKey(i)) { + List> cbytelist= cbytes.get(i); + String cbyteString= ControlByteHandler.toString(cbytelist); + if(!cbyteString.isEmpty()) { + fileThread.addLine(cbyteString); + } + } + + // Add a data line + TickInputContainer tickInput = ticks.get(i); + fileThread.addLine(tickInput.toString() + "~&\t\t\t\t//Monitoring:"+container.desyncMonitor.get(i)+"\n"); } fileThread.close(); - monitorThread.close(); } public int getFileVersion(File file) throws IOException { @@ -111,21 +178,24 @@ public int getFileVersion(File file) throws IOException { return 0; } - public InputContainer fromEntireFileV1(File file) throws IOException { + public PlaybackController fromEntireFileV1(File file) throws IOException { List lines = FileUtils.readLines(file, StandardCharsets.UTF_8); - File monitorFile=new File(file, "../"+file.getName().replace(".tas", "")+".mon"); + File monitorFile=new File(file, "../"+file.getName().replace(".mctas", "")+".mon"); - List monitorLines=null; + List monitorLines=new ArrayList<>(); + // Read the legacy monitoring file system. Still reads the file but deletes it afterwards if(monitorFile.exists()) { monitorLines = FileUtils.readLines(monitorFile, StandardCharsets.UTF_8); + monitorFile.delete(); } + boolean oldmonfileLoaded=!monitorLines.isEmpty(); - InputContainer container = new InputContainer(); + PlaybackController controller = new PlaybackController(); - String author = "Insert author here"; //TODO Make this print out in chat + String author = "Insert author here"; String title = "Insert TAS category here"; @@ -133,55 +203,99 @@ public InputContainer fromEntireFileV1(File file) throws IOException { int rerecords = 0; + // No default start location String startLocation=""; + + // Default the start seed to the current global ktrng seed. If KTRNG is not loaded, defaults to 0 + long startSeed=TASmod.ktrngHandler.getGlobalSeedClient(); - container.clear(); + // Clear the current container before reading new data + controller.clear(); - int linenumber = 0; + int linenumber = 0; //The current line number + for (String line : lines) { linenumber++; - //Read out the data + int tickcount=(int) controller.getInputs().size(); + // Read out header if (line.startsWith("#")) { + // Read author tag if (line.startsWith("#Author:")) { author = line.split(":")[1]; + // Read title tag } else if (line.startsWith("#Title:")) { title = line.split(":")[1]; + // Read playtime } else if (line.startsWith("#Playing Time:")) { - playtime = line.split(":")[1]; + playtime = line.split("Playing Time:")[1]; + // Read rerecords } else if (line.startsWith("#Rerecords:")) { rerecords = Integer.parseInt(line.split(":")[1]); + // Read start position } else if (line.startsWith("#StartPosition:")) { startLocation = line.replace("#StartPosition:", ""); + // Read start seed + } else if (line.startsWith("#StartSeed:")) { + startSeed = Long.parseLong(line.replace("#StartSeed:", "")); } + // Read control bytes } else if (line.startsWith("$") && line.replace('$', ' ').trim().contains(" ")) { String[] sections = line.replace('$', ' ').trim().split(" ", 2); if (sections.length == 0) continue; String control = sections[0]; String[] params = sections[1].split(" "); - List> cbytes = container.getControlBytes().getOrDefault((int) container.getInputs().size(), new ArrayList<>()); + List> cbytes = controller.getControlBytes().getOrDefault(tickcount, new ArrayList<>()); cbytes.add(Pair.of(control, params)); - container.getControlBytes().put((int) container.getInputs().size(), cbytes); + controller.getControlBytes().put(tickcount, cbytes); + //Read comments + } else if (line.startsWith("//")) { + List commentList = controller.getComments().getOrDefault(tickcount, new ArrayList<>()); + commentList.add(line.replace("//", "")); + controller.getComments().put(tickcount, commentList); + //Read data } else { - String[] sections = line.split("\\|"); + + // Splitting the line into a data- and commentPart, the comment part will most likely contain the Monitoring + String dataPart=line; + String commentPart=""; + if(line.contains("~&")) { + String[] splitComments=line.split("~&"); + dataPart=splitComments[0]; + commentPart=splitComments[1]; + } + String[] sections = dataPart.split(SectionsV1.getRegexString()); - if (sections.length != 4) { + if (sections.length != SectionsV1.values().length) { throw new IOException("Error in line " + linenumber + ". Cannot read the line correctly"); } - - container.getInputs().add(new TickInputContainer(readTicks(sections[0], linenumber), readKeyboard(sections[1], linenumber), readMouse(sections[2], linenumber), readSubtick(sections[3], linenumber))); + + controller.getInputs().add(new TickInputContainer(readTicks(sections[0], linenumber), readKeyboard(sections[1], linenumber), readMouse(sections[2], linenumber), readSubtick(sections[3], linenumber))); + + if(!oldmonfileLoaded) { + String[] commentData = commentPart.split("Monitoring:"); + if(commentData.length==2) { + monitorLines.add(commentData[1]); + } + } } } - container.setAuthors(author); - container.setTitle(title); - container.setPlaytime(playtime); - container.setRerecords(rerecords); - container.setStartLocation(startLocation); - if(monitorLines!=null) { - container.dMonitor.setPos(monitorLines); + controller.setAuthors(author); + controller.setTitle(title); + controller.setPlaytime(playtime); + controller.setRerecords(rerecords); + controller.setStartLocation(startLocation); + controller.setStartSeed(startSeed); + if(!monitorLines.isEmpty()) { + controller.desyncMonitor = new DesyncMonitoring(controller, monitorLines); } - return container; + //If an old monitoring file is loaded, save the file immediately to not loose any data. + if(oldmonfileLoaded) { + saveToFileV1(file, controller); + } + + return controller; } private int readTicks(String section, int linenumber) throws IOException { @@ -330,6 +444,8 @@ private VirtualSubticks readSubtick(String section, int linenumber) throws IOExc return new VirtualSubticks(x, y); } + + // private String getStartLocation() { // Minecraft mc = Minecraft.getMinecraft(); diff --git a/src/main/java/de/pfannekuchen/tasmod/controlbytes/ControlByteHandler.java b/src/main/java/com/minecrafttas/tasmod/playback/controlbytes/ControlByteHandler.java similarity index 66% rename from src/main/java/de/pfannekuchen/tasmod/controlbytes/ControlByteHandler.java rename to src/main/java/com/minecrafttas/tasmod/playback/controlbytes/ControlByteHandler.java index 7713ace3..055caa9b 100644 --- a/src/main/java/de/pfannekuchen/tasmod/controlbytes/ControlByteHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/playback/controlbytes/ControlByteHandler.java @@ -1,4 +1,8 @@ -package de.pfannekuchen.tasmod.controlbytes; +package com.minecrafttas.tasmod.playback.controlbytes; + +import java.util.List; + +import com.mojang.realmsclient.util.Pair; /** * Handles playback control bytes @@ -10,10 +14,40 @@ public class ControlByteHandler { * Resets all control-byte-controlled settings */ public static void reset() { + ControlByteHandler.hideInfoBox = true; + ControlByteHandler.text = ""; ControlByteHandler.shouldInterpolate = false; ControlByteHandler.shouldRenderHud = true; - ControlByteHandler.text = ""; - ControlByteHandler.hideInfoBox = true; + } + + public static void readCotrolByte(List> list) { + if (list != null) + for (Pair pair : list) + ControlByteHandler.onControlByte(pair.first(), pair.second()); + } + + public static String toString(List> cbytes) { + String out=""; + // Iterating over the list of cbytes + for(Pair pair : cbytes) { + + //Add the command byte + out=out.concat("$"+pair.first()+" "); + + //Add the arguments + String[] args=pair.second(); + for (int i = 0; i < args.length; i++) { + String limiter=" "; + if(args.length-1==i) { + limiter=""; + } + out=out.concat(args[i]+limiter); + } + //Add a new line for a new controlbyte + out=out.concat("\n"); + } + + return out; } /** diff --git a/src/main/java/com/minecrafttas/tasmod/playback/server/InitialSyncStatePacket.java b/src/main/java/com/minecrafttas/tasmod/playback/server/InitialSyncStatePacket.java new file mode 100644 index 00000000..7eb69aa1 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/playback/server/InitialSyncStatePacket.java @@ -0,0 +1,32 @@ +package com.minecrafttas.tasmod.playback.server; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; + +/** + * Sends the state of the client to the server on server join. Is only applied if you are the first player on the server and if you are operator + * + * @author Scribble + * + */ +public class InitialSyncStatePacket extends SyncStatePacket { + + public InitialSyncStatePacket() { + super(); + } + + public InitialSyncStatePacket(TASstate state) { + super(state); + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isServer()) + TASmod.containerStateServer.onInitialPacket((EntityPlayerMP)player, this.getState()); + } + +} diff --git a/src/main/java/com/minecrafttas/tasmod/playback/server/SyncStatePacket.java b/src/main/java/com/minecrafttas/tasmod/playback/server/SyncStatePacket.java new file mode 100644 index 00000000..cb62fde9 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/playback/server/SyncStatePacket.java @@ -0,0 +1,93 @@ +package com.minecrafttas.tasmod.playback.server; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.playback.PlaybackController; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient; +import com.minecrafttas.tasmod.util.TickScheduler.TickTask; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.text.TextComponentString; + +/** + * Syncs the current state of the input recorder with the state on the server side and with the state on all other clients + * + * @author Scribble + * + */ +public class SyncStatePacket implements Packet { + + + private short state; + private boolean verbose; + + public SyncStatePacket() { + state = 0; + } + + public SyncStatePacket(TASstate state) { + verbose = true; + this.state = (short) state.getIndex(); + } + + public SyncStatePacket(TASstate state, boolean verbose) { + this.verbose = verbose; + this.state = (short) state.getIndex(); + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeShort(state); + buf.writeBoolean(verbose); + } + + @Override + public void deserialize(PacketBuffer buf) { + state = buf.readShort(); + verbose = buf.readBoolean(); + } + + protected TASstate getState() { + return TASstate.fromIndex(state); + } + + public boolean isVerbose() { + return verbose; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isServer()) { + TASmod.containerStateServer.onPacket((EntityPlayerMP)player, getState()); + } + else { + + TASstate state = getState(); + + TickTask task = ()->{ + + PlaybackController container = ClientProxy.virtual.getContainer(); + if (state != container.getState()) { + String chatMessage = container.setTASState(state, verbose); + if (!chatMessage.isEmpty()) { + Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(chatMessage)); + } + } + + }; + + + if((state == TASstate.RECORDING || state == TASstate.PLAYBACK) && TickrateChangerClient.ticksPerSecond != 0) { + ClientProxy.tickSchedulerClient.add(task); // Starts a recording in the next tick + } else { + ClientProxy.gameLoopSchedulerClient.add(task); // Starts a recording in the next frame + } + } + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/playback/server/TASstateClient.java b/src/main/java/com/minecrafttas/tasmod/playback/server/TASstateClient.java new file mode 100644 index 00000000..293f82c6 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/playback/server/TASstateClient.java @@ -0,0 +1,21 @@ +package com.minecrafttas.tasmod.playback.server; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; + +import net.minecraft.client.Minecraft; + +public class TASstateClient { + + public static void setStateClient(TASstate state) { + ClientProxy.virtual.getContainer().setTASState(state); + } + + public static void setOrSend(TASstate state) { + if(Minecraft.getMinecraft().player!=null) { + ClientProxy.packetClient.sendToServer(new SyncStatePacket(state)); + }else { + ClientProxy.virtual.getContainer().setTASState(state); + } + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/util/changestates/ContainerStateServer.java b/src/main/java/com/minecrafttas/tasmod/playback/server/TASstateServer.java similarity index 67% rename from src/main/java/de/scribble/lp/tasmod/util/changestates/ContainerStateServer.java rename to src/main/java/com/minecrafttas/tasmod/playback/server/TASstateServer.java index 6f299edb..3721a3ae 100644 --- a/src/main/java/de/scribble/lp/tasmod/util/changestates/ContainerStateServer.java +++ b/src/main/java/com/minecrafttas/tasmod/playback/server/TASstateServer.java @@ -1,8 +1,8 @@ -package de.scribble.lp.tasmod.util.changestates; +package com.minecrafttas.tasmod.playback.server; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.util.TASstate; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; @@ -17,25 +17,32 @@ * Additionally the client can start recording before the server is even started * and when multiple clients still have to connect to the server. * - * @author ScribbleLP + * @author Scribble * */ -public class ContainerStateServer { +public class TASstateServer { + private TASstate state; - private boolean shouldChange; + private boolean shouldChange = true; - public ContainerStateServer() { + public TASstateServer() { state = TASstate.NONE; - shouldChange = false; + shouldChange = true; } - public void joinServer(EntityPlayerMP player) { - if (!shouldChange) { - shouldChange = true; - CommonProxy.NETWORK.sendTo(new RequestStatePacket(), player); //TODO Rewrite this s*** - } else { - CommonProxy.NETWORK.sendTo(new SyncStatePacket(state, false), player); + public void onInitialPacket(EntityPlayerMP player, TASstate tasState) { + if(player.canUseCommand(2, "") && shouldChange) { + setState(tasState); + shouldChange = false; + }else { + TASmod.packetServer.sendTo(new SyncStatePacket(tasState), player); + } + } + + public void onPacket(EntityPlayerMP player, TASstate tasState) { + if(player.canUseCommand(2, "")) { + setState(tasState); } } @@ -44,14 +51,14 @@ public void leaveServer(EntityPlayerMP player) { if (server != null) { if (server.getPlayerList().getPlayers().size() == 1) { state = TASstate.NONE; - shouldChange = false; + shouldChange = true; } } } public void setState(TASstate stateIn) { setServerState(stateIn); - CommonProxy.NETWORK.sendToAll(new SyncStatePacket(state)); + TASmod.packetServer.sendToAll(new SyncStatePacket(state, true)); } public void setServerState(TASstate stateIn) { @@ -74,8 +81,6 @@ public void togglePlayback() { setState(state == TASstate.PLAYBACK ? TASstate.NONE : TASstate.PLAYBACK); } - - public TASstate getState() { return state; } diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/client/InputSavestatesHandler.java b/src/main/java/com/minecrafttas/tasmod/savestates/client/InputSavestatesHandler.java similarity index 83% rename from src/main/java/de/scribble/lp/tasmod/savestates/client/InputSavestatesHandler.java rename to src/main/java/com/minecrafttas/tasmod/savestates/client/InputSavestatesHandler.java index 44b3ea23..e5ef33d7 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/client/InputSavestatesHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/client/InputSavestatesHandler.java @@ -1,16 +1,16 @@ -package de.scribble.lp.tasmod.savestates.client; +package com.minecrafttas.tasmod.savestates.client; import java.io.File; import java.io.IOException; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.CommonProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.playback.PlaybackController; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.savestates.server.exceptions.SavestateException; import com.mojang.realmsclient.gui.ChatFormatting; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.inputcontainer.InputContainer; -import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateException; -import de.scribble.lp.tasmod.util.TASstate; import net.minecraft.client.Minecraft; import net.minecraft.util.text.TextComponentString; import net.minecraftforge.fml.relauncher.Side; @@ -45,9 +45,9 @@ public static void savestate(String nameOfSavestate) throws SavestateException, savestateDirectory.mkdir(); - File targetfile = new File(savestateDirectory, nameOfSavestate + ".tas"); + File targetfile = new File(savestateDirectory, nameOfSavestate + ".mctas"); - InputContainer container = ClientProxy.virtual.getContainer(); + PlaybackController container = ClientProxy.virtual.getContainer(); if (container.isRecording()) { ClientProxy.serialiser.saveToFileV1(targetfile, container); //If the container is recording, store it entirely } else if(container.isPlayingback()){ @@ -72,9 +72,9 @@ public static void loadstate(String nameOfSavestate) throws IOException { savestateDirectory.mkdir(); - File targetfile = new File(savestateDirectory, nameOfSavestate + ".tas"); + File targetfile = new File(savestateDirectory, nameOfSavestate + ".mctas"); - InputContainer container = ClientProxy.virtual.getContainer(); + PlaybackController container = ClientProxy.virtual.getContainer(); if (!container.isNothingPlaying()) { // If the file exists and the container is recording or playing, load the clientSavestate if (targetfile.exists()) { ClientProxy.virtual.loadClientSavestate(ClientProxy.serialiser.fromEntireFileV1(targetfile)); diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/client/InputSavestatesPacket.java b/src/main/java/com/minecrafttas/tasmod/savestates/client/InputSavestatesPacket.java new file mode 100644 index 00000000..08587b6b --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/savestates/client/InputSavestatesPacket.java @@ -0,0 +1,63 @@ +package com.minecrafttas.tasmod.savestates.client; + +import java.io.IOException; +import java.nio.charset.Charset; + +import com.minecrafttas.tasmod.CommonProxy; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.savestates.server.exceptions.SavestateException; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +public class InputSavestatesPacket implements Packet{ + private boolean mode; + private String name; + + public InputSavestatesPacket() { + } + /** + * Makes a savestate of the recording on the Client + * @param mode If true: Make a savestate, else load the savestate + * @param name Name of the savestated file + */ + public InputSavestatesPacket(boolean mode,String name) { + this.mode=mode; + this.name=name; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isClient()) { + if (mode == true) { + try { + InputSavestatesHandler.savestate(name); + } catch (SavestateException e) { + CommonProxy.logger.error(e.getMessage()); + } catch (IOException e) { + e.printStackTrace(); + } + } else { + try { + InputSavestatesHandler.loadstate(name); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + } + @Override + public void serialize(PacketBuffer buf) { + buf.writeInt(name.length()); + buf.writeCharSequence(name, Charset.defaultCharset()); + buf.writeBoolean(mode); + } + @Override + public void deserialize(PacketBuffer buf) { + int length=buf.readInt(); + name=(String) buf.readCharSequence(length, Charset.defaultCharset()); + mode=buf.readBoolean(); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/client/gui/GuiSavestateLoadingScreen.java b/src/main/java/com/minecrafttas/tasmod/savestates/client/gui/GuiSavestateLoadingScreen.java similarity index 93% rename from src/main/java/de/scribble/lp/tasmod/savestates/client/gui/GuiSavestateLoadingScreen.java rename to src/main/java/com/minecrafttas/tasmod/savestates/client/gui/GuiSavestateLoadingScreen.java index 437f0432..585fdd13 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/client/gui/GuiSavestateLoadingScreen.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/client/gui/GuiSavestateLoadingScreen.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.client.gui; +package com.minecrafttas.tasmod.savestates.client.gui; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/client/gui/GuiSavestateSavingScreen.java b/src/main/java/com/minecrafttas/tasmod/savestates/client/gui/GuiSavestateSavingScreen.java similarity index 93% rename from src/main/java/de/scribble/lp/tasmod/savestates/client/gui/GuiSavestateSavingScreen.java rename to src/main/java/com/minecrafttas/tasmod/savestates/client/gui/GuiSavestateSavingScreen.java index 2554ac72..db1d5ba1 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/client/gui/GuiSavestateSavingScreen.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/client/gui/GuiSavestateSavingScreen.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.client.gui; +package com.minecrafttas.tasmod.savestates.client.gui; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/server/LoadstatePacket.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/LoadstatePacket.java new file mode 100644 index 00000000..f797fc4c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/LoadstatePacket.java @@ -0,0 +1,73 @@ +package com.minecrafttas.tasmod.savestates.server; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.savestates.server.chunkloading.SavestatesChunkControl; +import com.minecrafttas.tasmod.savestates.server.exceptions.LoadstateException; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; + +public class LoadstatePacket implements Packet { + + public int index; + + /** + * Load a savestate at the current index + */ + public LoadstatePacket() { + index = -1; + } + + /** + * Load the savestate at the specified index + * + * @param index The index to load the savestate + */ + public LoadstatePacket(int index) { + this.index = index; + } + + @Override + public void handle(PacketSide side, EntityPlayer playerz) { + if (side.isServer()) { + EntityPlayerMP player = (EntityPlayerMP) playerz; + player.getServerWorld().addScheduledTask(()->{ + if (!player.canUseCommand(2, "tickrate")) { + player.sendMessage(new TextComponentString(TextFormatting.RED + "You don't have permission to do that")); + return; + } + try { + TASmod.savestateHandler.loadState(index, true); + } catch (LoadstateException e) { + player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to load a savestate: " + e.getMessage())); + } catch (Exception e) { + player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to load a savestate: " + e.getCause().toString())); + e.printStackTrace(); + } finally { + TASmod.savestateHandler.state = SavestateState.NONE; + } + }); + } else { + Minecraft.getMinecraft().addScheduledTask(()->{ + SavestatesChunkControl.unloadAllClientChunks(); + }); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeInt(index); + } + + @Override + public void deserialize(PacketBuffer buf) { + index = buf.readInt(); + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateCommand.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateCommand.java similarity index 95% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateCommand.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateCommand.java index 8cb2e2db..f460cc1e 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateCommand.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateCommand.java @@ -1,12 +1,13 @@ -package de.scribble.lp.tasmod.savestates.server; +package com.minecrafttas.tasmod.savestates.server; import java.io.IOException; import java.util.List; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.savestates.server.exceptions.LoadstateException; -import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateDeleteException; -import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateException; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.savestates.server.exceptions.LoadstateException; +import com.minecrafttas.tasmod.savestates.server.exceptions.SavestateDeleteException; +import com.minecrafttas.tasmod.savestates.server.exceptions.SavestateException; + import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; @@ -60,7 +61,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args } else if (args.length == 3) { int args1 = processIndex(args[1]); int args2 = processIndex(args[2]); - int count = args2 - args1; + int count = (args2+1) - args1; TextComponentString confirm = new TextComponentString(TextFormatting.YELLOW + "Are you sure you want to delete " + count + (count == 1 ? " savestate? " : " savestates? ") + TextFormatting.GREEN + "[YES]"); confirm.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/savestate deletDis %s %s", args[1], args[2]))); sender.sendMessage(confirm); @@ -205,9 +206,6 @@ private void loadLatest(String[] args) throws CommandException { private void delete(String[] args) throws CommandException { int arg1 = processIndex(args[1]); - if (arg1 == 0) { - throw new CommandException("Cannot delete savestate 0", new Object[] {}); - } try { TASmod.savestateHandler.deleteSavestate(arg1); } catch (SavestateDeleteException e) { diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateHandler.java similarity index 77% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateHandler.java index 5e84930c..17c89fa9 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateHandler.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.server; +package com.minecrafttas.tasmod.savestates.server; import java.io.File; import java.io.FileFilter; @@ -11,17 +11,22 @@ import java.util.regex.Pattern; import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.Logger; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.events.SavestateEvents; +import com.minecrafttas.tasmod.savestates.client.InputSavestatesPacket; +import com.minecrafttas.tasmod.savestates.server.chunkloading.SavestatesChunkControl; +import com.minecrafttas.tasmod.savestates.server.exceptions.LoadstateException; +import com.minecrafttas.tasmod.savestates.server.exceptions.SavestateDeleteException; +import com.minecrafttas.tasmod.savestates.server.exceptions.SavestateException; +import com.minecrafttas.tasmod.savestates.server.files.SavestateDataFile; +import com.minecrafttas.tasmod.savestates.server.files.SavestateDataFile.DataValues; +import com.minecrafttas.tasmod.savestates.server.files.SavestateTrackerFile; +import com.minecrafttas.tasmod.savestates.server.motion.ClientMotionServer; +import com.minecrafttas.tasmod.savestates.server.playerloading.SavestatePlayerLoading; +import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.savestates.client.InputSavestatesPacket; -import de.scribble.lp.tasmod.savestates.server.chunkloading.SavestatesChunkControl; -import de.scribble.lp.tasmod.savestates.server.exceptions.LoadstateException; -import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateDeleteException; -import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateException; -import de.scribble.lp.tasmod.savestates.server.motion.ClientMotionServer; -import de.scribble.lp.tasmod.savestates.server.playerloading.SavestatePlayerLoading; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerServer; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; @@ -57,14 +62,18 @@ public class SavestateHandler { private int latestIndex = 0; private int currentIndex; + + private final Logger logger; /** * Creates a savestate handler on the specified server + * @param logger * * @param The server that should store the savestates */ - public SavestateHandler(MinecraftServer server) { + public SavestateHandler(MinecraftServer server, Logger logger) { this.server = server; + this.logger = logger; createSavestateDirectory(); refresh(); loadCurrentIndexFromFile(); @@ -73,8 +82,7 @@ public SavestateHandler(MinecraftServer server) { /** * Creates a copy of the world that is currently being played and saves it in * .minecraft/saves/savestates/worldname-Savestate[{@linkplain #currentIndex}+1] - *
- *
+ *

* Side: Server * * @throws SavestateException @@ -90,8 +98,8 @@ public void saveState(int savestateIndex, boolean tickrate0) throws SavestateExc /** * Creates a copy of the world that is currently being played and saves it in - * .minecraft/saves/savestates/worldname-Savestate[savestateIndex]
- *
+ * .minecraft/saves/savestates/worldname-Savestate[savestateIndex] + *

* Side: Server * * @param savestateIndex The index where the mod will save the savestate. @@ -111,7 +119,7 @@ public void saveState(int savestateIndex, boolean tickrate0, boolean changeIndex } // Lock savestating and loadstating state = SavestateState.SAVING; - + // Create a directory just in case createSavestateDirectory(); @@ -126,7 +134,7 @@ public void saveState(int savestateIndex, boolean tickrate0, boolean changeIndex // Save the world! server.getPlayerList().saveAllPlayerData(); - server.saveAllWorlds(true); + server.saveAllWorlds(false); // Refreshing the index list refresh(); @@ -142,9 +150,11 @@ public void saveState(int savestateIndex, boolean tickrate0, boolean changeIndex String worldname = server.getFolderName(); File currentfolder = new File(savestateDirectory, ".." + File.separator + worldname); File targetfolder = getSavestateFile(indexToSave); + + SavestateEvents.triggerSavestateEvent(targetfolder); if (targetfolder.exists()) { - TASmod.logger.warn("WARNING! Overwriting the savestate with the index {}", indexToSave); + logger.warn("WARNING! Overwriting the savestate with the index {}", indexToSave); FileUtils.deleteDirectory(targetfolder); } @@ -157,7 +167,7 @@ public void saveState(int savestateIndex, boolean tickrate0, boolean changeIndex * Send the name of the world to all players. This will make a savestate of the * recording on the client with that name */ - CommonProxy.NETWORK.sendToAll(new InputSavestatesPacket(true, getSavestateName(indexToSave))); + TASmod.packetServer.sendToAll(new InputSavestatesPacket(true, getSavestateName(indexToSave))); } // Wait for the chunkloader to save the game @@ -167,6 +177,8 @@ public void saveState(int savestateIndex, boolean tickrate0, boolean changeIndex } } + saveSavestateDataFile(false); + // Copy the directory FileUtils.copyDirectory(currentfolder, targetfolder); @@ -175,13 +187,11 @@ public void saveState(int savestateIndex, boolean tickrate0, boolean changeIndex tracker.increaseSavestates(); tracker.saveFile(); - saveCurrentIndexToFile(); - // Send a notification that the savestate has been loaded server.getPlayerList().sendMessage(new TextComponentString(TextFormatting.GREEN + "Savestate " + indexToSave + " saved")); // Close the GuiSavestateScreen on the client - CommonProxy.NETWORK.sendToAll(new SavestatePacket()); + TASmod.packetServer.sendToAll(new SavestatePacket()); if (!tickrate0) { TickrateChangerServer.pauseGame(false); @@ -194,7 +204,7 @@ public void saveState(int savestateIndex, boolean tickrate0, boolean changeIndex /** * Loads the latest savestate at {@linkplain #currentIndex} * .minecraft/saves/savestates/worldname-Savestate[{@linkplain #currentIndex}] - * + *

* Side: Server * * @throws LoadstateException @@ -219,7 +229,7 @@ public void loadState(int savestateIndex, boolean tickrate0) throws LoadstateExc /** * Loads the latest savestate it can find in * .minecraft/saves/savestates/worldname-Savestate - * + *

* Side: Server * * @param savestateIndex The index where the mod will load the savestate. @@ -238,7 +248,7 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex } // Lock savestating and loadstating state = SavestateState.LOADING; - + // Create a directory just in case createSavestateDirectory(); @@ -263,6 +273,8 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex File currentfolder = new File(savestateDirectory, ".." + File.separator + worldname); File targetfolder = getSavestateFile(indexToLoad); + SavestateEvents.triggerLoadstateEvent(targetfolder); + /* * Prevents loading an InputSavestate when loading index 0 (Index 0 is the * savestate when starting a recording. Not doing this will load an empty @@ -270,7 +282,7 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex */ if (savestateIndex != 0) { // Load savestate on the client - CommonProxy.NETWORK.sendToAll(new InputSavestatesPacket(false, getSavestateName(indexToLoad))); + TASmod.packetServer.sendToAll(new InputSavestatesPacket(false, getSavestateName(indexToLoad))); } // Disabeling level saving for all worlds in case the auto save kicks in during @@ -280,7 +292,7 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex } // Unload chunks on the client - CommonProxy.NETWORK.sendToAll(new LoadstatePacket()); + TASmod.packetServer.sendToAll(new LoadstatePacket()); // Unload chunks on the server SavestatesChunkControl.disconnectPlayersFromChunkMap(); @@ -290,6 +302,9 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex // Delete and copy directories FileUtils.deleteDirectory(currentfolder); FileUtils.copyDirectory(targetfolder, currentfolder); + + // Loads savestate data from the file like name and ktrng seed if ktrng is loaded + loadSavestateDataFile(); // Update the player and the client SavestatePlayerLoading.loadAndSendMotionToPlayer(); @@ -308,8 +323,6 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex tracker.increaseRerecords(); tracker.saveFile(); - saveCurrentIndexToFile(); - // Send a notification that the savestate has been loaded server.getPlayerList().sendMessage(new TextComponentString(TextFormatting.GREEN + "Savestate " + indexToLoad + " loaded")); @@ -318,9 +331,6 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex SavestatesChunkControl.addPlayerToServerChunk(player); }); - // Updating redstone component timers to the new world time (#136) - SavestatesChunkControl.updateWorldServerTickListEntries(); - WorldServer[] worlds = DimensionManager.getWorlds(); for (WorldServer world : worlds) { @@ -368,11 +378,11 @@ public boolean accept(File pathname) { if (matcher.find()) { index = Integer.parseInt(matcher.group(0)); } else { - TASmod.logger.warn(String.format("Could not process the savestate %s", file.getName())); + logger.warn(String.format("Could not process the savestate %s", file.getName())); continue; } } catch (NumberFormatException e) { - TASmod.logger.warn(String.format("Could not process the savestate %s", e.getMessage())); + logger.warn(String.format("Could not process the savestate %s", e.getMessage())); continue; } indexList.add(index); @@ -417,6 +427,9 @@ public void deleteSavestate(int index) throws SavestateDeleteException { if (index < 0) { throw new SavestateDeleteException("Cannot delete the negative indexes"); } + if(index == 0) { + throw new SavestateDeleteException("Cannot delete protected savestate 0"); + } File toDelete = getSavestateFile(index); if (toDelete.exists()) { try { @@ -440,7 +453,7 @@ public void deleteSavestate(int index) throws SavestateDeleteException { * Deletes savestates in a range from "from" to "to" * * @param from - * @param to (exclusive) + * @param to (inclusive) * @throws SavestateDeleteException */ public void deleteSavestate(int from, int to) throws SavestateDeleteException { @@ -453,10 +466,8 @@ public void deleteSavestate(int from, int to) throws SavestateDeleteException { if (from >= to) { throw new SavestateDeleteException("Can't delete amounts that are negative or 0"); } - for (int i = from; i < to; i++) { - if (i == 0) { - continue; - } + for (int i = from; i <= to; i++) { +// System.out.println("Would've deleted savestate: "+i); try { deleteSavestate(i); } catch (SavestateDeleteException e) { @@ -466,6 +477,9 @@ public void deleteSavestate(int from, int to) throws SavestateDeleteException { } } + /** + * @return A list of index numbers as string in the form of: "0, 1, 2, 3" + */ public String getIndexesAsString() { refresh(); String out = ""; @@ -478,53 +492,93 @@ public String getIndexesAsString() { /** * Saves the current index to the current world-folder (not the savestate * folder) + * + * @param legacy If the data file should only store the index, since it comes from a legacy file format */ - private void saveCurrentIndexToFile() { + private void saveSavestateDataFile(boolean legacy) { File tasmodDir = new File(savestateDirectory, "../" + server.getFolderName() + "/tasmod/"); if (!tasmodDir.exists()) { tasmodDir.mkdir(); } - File savestateDat = new File(tasmodDir, "savestate.data"); - List lines = new ArrayList(); - lines.add("currentIndex=" + currentIndex); - try { - FileUtils.writeLines(savestateDat, lines); - } catch (IOException e) { - e.printStackTrace(); + File savestateDat = new File(tasmodDir, "savestateData.txt"); + + if(savestateDat.exists()) { + savestateDat.delete(); } + + SavestateDataFile file = new SavestateDataFile(); + + file.set(DataValues.INDEX, Integer.toString(currentIndex)); + + if(!legacy) { + if(TASmod.ktrngHandler.isLoaded()) { + file.set(DataValues.SEED, Long.toString(TASmod.ktrngHandler.getGlobalSeedServer())); + } + } + + file.save(savestateDat); } + /** + * Loads information from savestateData.txt + *

+ * This loads everything except the index, since that is loaded when the world is loaded + */ + private void loadSavestateDataFile() { + File tasmodDir = new File(savestateDirectory, "../" + server.getFolderName() + "/tasmod/"); + File savestateDat = new File(tasmodDir, "savestateData.txt"); + + if(!savestateDat.exists()) { + return; + } + + SavestateDataFile datafile = new SavestateDataFile(); + + datafile.load(savestateDat); + + if(TASmod.ktrngHandler.isLoaded()) { + String seedString = datafile.get(DataValues.SEED); + if(seedString != null) { + TASmod.ktrngHandler.sendGlobalSeedToServer(Long.parseLong(seedString)); + } else { + logger.warn("KTRNG seed not loaded because it was not found in savestateData.txt!"); + } + } + } + /** * Loads the current index to the current world-folder (not the savestate * folder) + *

+ * This ensures that the server knows the current index when loading the world */ public void loadCurrentIndexFromFile() { int index = -1; - List lines = new ArrayList(); File tasmodDir = new File(savestateDirectory, "../" + server.getFolderName() + "/tasmod/"); if (!tasmodDir.exists()) { tasmodDir.mkdir(); } + File savestateDat = new File(tasmodDir, "savestate.data"); - try { - lines = FileUtils.readLines(savestateDat, StandardCharsets.UTF_8); - } catch (IOException e) { - TASmod.logger.warn("No savestate.data file found in current world folder, ignoring it"); + if(savestateDat.exists()) { + index = legacyIndexFile(savestateDat); + setCurrentIndex(index, true); + saveSavestateDataFile(true); + savestateDat.delete(); + return; } - if (!lines.isEmpty()) { - for (String line : lines) { - if (line.startsWith("currentIndex=")) { - try { - index = Integer.parseInt(line.split("=")[1]); - } catch (NumberFormatException e) { - e.printStackTrace(); - } - } - } + + savestateDat = new File(tasmodDir, "savestateData.txt"); + if(savestateDat.exists()) { + SavestateDataFile file = new SavestateDataFile(); + file.load(savestateDat); + + index = Integer.parseInt(file.get(DataValues.INDEX)); + + setCurrentIndex(index, true); } - setCurrentIndex(index, true); } - + private void setCurrentIndex(int index, boolean changeIndex) { if(changeIndex) { if (index < 0) { @@ -532,9 +586,9 @@ private void setCurrentIndex(int index, boolean changeIndex) { } else { currentIndex = index; } - TASmod.logger.info("Setting the savestate index to {}", currentIndex); + logger.info("Setting the savestate index to {}", currentIndex); } else { - TASmod.logger.warn("Keeping the savestate index at {}", currentIndex); + logger.warn("Keeping the savestate index at {}", currentIndex); } } @@ -552,10 +606,34 @@ public static void playerLoadSavestateEventServer() { NBTTagCompound nbttagcompound = playerList.getPlayerNBT(player); SavestatePlayerLoading.reattachEntityToPlayer(nbttagcompound, player.getServerWorld(), player); } + // Updating redstone component timers to the new world time (#136) + SavestatesChunkControl.updateWorldServerTickListEntries(); } @SideOnly(Side.CLIENT) public static void playerLoadSavestateEventClient() { SavestatesChunkControl.addPlayerToClientChunk(Minecraft.getMinecraft().player); } + + private int legacyIndexFile(File savestateDat) { + int index = -1; + List lines = new ArrayList(); + try { + lines = FileUtils.readLines(savestateDat, StandardCharsets.UTF_8); + } catch (IOException e) { + logger.warn("No savestate.data file found in current world folder, ignoring it"); + } + if (!lines.isEmpty()) { + for (String line : lines) { + if (line.startsWith("currentIndex=")) { + try { + index = Integer.parseInt(line.split("=")[1]); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } + } + return index; + } } \ No newline at end of file diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestatePacket.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestatePacket.java new file mode 100644 index 00000000..3273face --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestatePacket.java @@ -0,0 +1,81 @@ +package com.minecrafttas.tasmod.savestates.server; + +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.savestates.client.gui.GuiSavestateSavingScreen; +import com.minecrafttas.tasmod.savestates.server.exceptions.SavestateException; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; + +public class SavestatePacket implements Packet { + + public int index; + + /** + * Make a savestate at the next index + */ + public SavestatePacket() { + index=-1; + } + + /** + * Make a savestate at the specified index + * + * @param index The index where to make a savestate + */ + public SavestatePacket(int index) { + this.index=index; + } + + @Override + public void handle(PacketSide side, EntityPlayer playerz) { + if(side.isServer()) { + EntityPlayerMP player = (EntityPlayerMP) playerz; + player.getServerWorld().addScheduledTask(()->{ + if (!player.canUseCommand(2, "savestate")) { + player.sendMessage(new TextComponentString(TextFormatting.RED+"You don't have permission to do that")); + return; + } + try { + TASmod.savestateHandler.saveState(index, true); + } catch (SavestateException e) { + player.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to create a savestate: "+ e.getMessage())); + + } catch (Exception e) { + e.printStackTrace(); + player.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to create a savestate: "+ e.getCause().toString())); + } finally { + TASmod.savestateHandler.state=SavestateState.NONE; + } + }); + + } + else { + Minecraft.getMinecraft().addScheduledTask(() -> { + Minecraft mc = Minecraft.getMinecraft(); + if (!(mc.currentScreen instanceof GuiSavestateSavingScreen)) { + mc.displayGuiScreen(new GuiSavestateSavingScreen()); + } else { + mc.displayGuiScreen(null); + } + }); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeInt(index); + } + + @Override + public void deserialize(PacketBuffer buf) { + index=buf.readInt(); + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateState.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateState.java similarity index 57% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateState.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateState.java index 15f3f0fe..801166a0 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateState.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/SavestateState.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.server; +package com.minecrafttas.tasmod.savestates.server; public enum SavestateState { SAVING, diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/chunkloading/SavestatesChunkControl.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/chunkloading/SavestatesChunkControl.java similarity index 94% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/chunkloading/SavestatesChunkControl.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/chunkloading/SavestatesChunkControl.java index aea6e9ca..97387c63 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/chunkloading/SavestatesChunkControl.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/chunkloading/SavestatesChunkControl.java @@ -1,14 +1,15 @@ -package de.scribble.lp.tasmod.savestates.server.chunkloading; +package com.minecrafttas.tasmod.savestates.server.chunkloading; import java.util.List; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.duck.ChunkProviderDuck; -import de.scribble.lp.tasmod.mixin.accessors.AccessorSaveHandler; -import de.scribble.lp.tasmod.mixin.accessors.AccessorWorld; -import de.scribble.lp.tasmod.mixin.accessors.AccessorWorldServer; -import de.scribble.lp.tasmod.mixin.savestates.MixinChunkProviderClient; -import de.scribble.lp.tasmod.mixin.savestates.MixinChunkProviderServer; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.duck.ChunkProviderDuck; +import com.minecrafttas.tasmod.mixin.accessors.AccessorSaveHandler; +import com.minecrafttas.tasmod.mixin.accessors.AccessorWorld; +import com.minecrafttas.tasmod.mixin.accessors.AccessorWorldServer; +import com.minecrafttas.tasmod.mixin.savestates.MixinChunkProviderClient; +import com.minecrafttas.tasmod.mixin.savestates.MixinChunkProviderServer; + import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ChunkProviderClient; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/LoadstateException.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/LoadstateException.java similarity index 75% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/LoadstateException.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/LoadstateException.java index 8c69e79c..849e1e80 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/LoadstateException.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/LoadstateException.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.server.exceptions; +package com.minecrafttas.tasmod.savestates.server.exceptions; public class LoadstateException extends Exception{ /** diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/SavestateDeleteException.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/SavestateDeleteException.java similarity index 76% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/SavestateDeleteException.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/SavestateDeleteException.java index c3877f1f..df7d12ac 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/SavestateDeleteException.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/SavestateDeleteException.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.server.exceptions; +package com.minecrafttas.tasmod.savestates.server.exceptions; public class SavestateDeleteException extends Exception { /** diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/SavestateException.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/SavestateException.java similarity index 75% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/SavestateException.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/SavestateException.java index 48331a04..a68c9610 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/exceptions/SavestateException.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/exceptions/SavestateException.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.server.exceptions; +package com.minecrafttas.tasmod.savestates.server.exceptions; public class SavestateException extends Exception{ /** diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/server/files/SavestateDataFile.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/files/SavestateDataFile.java new file mode 100644 index 00000000..90dad8bb --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/files/SavestateDataFile.java @@ -0,0 +1,65 @@ +package com.minecrafttas.tasmod.savestates.server.files; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.InvalidPropertiesFormatException; +import java.util.Properties; + +public class SavestateDataFile { + + public enum DataValues { + INDEX("currentIndex"), + Name("savestateName"), + SEED("ktrngSeed"); + + + private String configname; + + private DataValues(String configname) { + this.configname=configname; + } + + public String getConfigName() { + return configname; + } + } + + Properties properties = new Properties(); + + public void set(DataValues key, String val) { + properties.setProperty(key.getConfigName(), val); + } + + public String get(DataValues key) { + return properties.getProperty(key.getConfigName()); + } + + public void save(File file) { + try { + Writer writer = new FileWriter(file); + properties.store(writer, "Data for this savestate from TASmod"); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void load(File file) { + try { + Reader reader = new FileReader(file); + properties.load(reader); + reader.close(); + } catch (InvalidPropertiesFormatException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateTrackerFile.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/files/SavestateTrackerFile.java similarity index 95% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateTrackerFile.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/files/SavestateTrackerFile.java index 89d43f3b..825ca960 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateTrackerFile.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/files/SavestateTrackerFile.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.server; +package com.minecrafttas.tasmod.savestates.server.files; import java.io.File; import java.io.IOException; @@ -10,7 +10,7 @@ /** * Used to keep track of savestates and rerecordings - * @author ScribbleLP + * @author Scribble * */ public class SavestateTrackerFile { diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/motion/ClientMotionServer.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/motion/ClientMotionServer.java similarity index 87% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/motion/ClientMotionServer.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/motion/ClientMotionServer.java index 9b80b671..345912fc 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/motion/ClientMotionServer.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/motion/ClientMotionServer.java @@ -1,11 +1,11 @@ -package de.scribble.lp.tasmod.savestates.server.motion; +package com.minecrafttas.tasmod.savestates.server.motion; import java.util.Map; import com.google.common.collect.Maps; +import com.minecrafttas.tasmod.CommonProxy; +import com.minecrafttas.tasmod.TASmod; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; import net.minecraft.entity.player.EntityPlayerMP; public class ClientMotionServer { @@ -18,7 +18,7 @@ public static Map getMotion() { public static void requestMotionFromClient() { motion.clear(); - CommonProxy.NETWORK.sendToAll(new RequestMotionPacket()); + TASmod.packetServer.sendToAll(new RequestMotionPacket()); int i = 1; while (motion.size() != TASmod.getServerInstance().getPlayerList().getCurrentPlayerCount()) { @@ -30,7 +30,7 @@ public static void requestMotionFromClient() { } if(i % 30 == 1) { CommonProxy.logger.info("Resending motion packet"); - CommonProxy.NETWORK.sendToAll(new RequestMotionPacket()); + TASmod.packetServer.sendToAll(new RequestMotionPacket()); } if (i == 1000) { CommonProxy.logger.warn("Client motion timed out!"); diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/server/motion/MotionPacket.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/motion/MotionPacket.java new file mode 100644 index 00000000..4968cd2b --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/motion/MotionPacket.java @@ -0,0 +1,82 @@ +package com.minecrafttas.tasmod.savestates.server.motion; + +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.savestates.server.motion.ClientMotionServer.Saver; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; + +/** + * A packet containing the motion data of the player + * @author Scribble + * + */ +public class MotionPacket implements Packet { + private double x = 0; + private double y = 0; + private double z = 0; + private float rx = 0; + private float ry = 0; + private float rz = 0; + private boolean sprinting; + private float jumpMovementVector = 0.2F; + + public MotionPacket() { + } + + /** + * Sends the players motion data to the server + * @param x + * @param y + * @param z + * @param moveForward + * @param moveVertical + * @param moveStrafe + * @param isSprinting + * @param jumpMovementVector + */ + public MotionPacket(double x, double y, double z, float moveForward, float moveVertical, float moveStrafe, boolean isSprinting, float jumpMovementVector) { + this.x = x; + this.y = y; + this.z = z; + this.rx = moveForward; + this.ry = moveVertical; + this.rz = moveStrafe; + sprinting = isSprinting; + this.jumpMovementVector = jumpMovementVector; + } + + @Override + public void handle(PacketSide side, EntityPlayer playercommon) { + if (side.isServer()) { + EntityPlayerMP player = (EntityPlayerMP) playercommon; + ClientMotionServer.getMotion().put(player, new Saver(x, y, z, rx, ry, rz, sprinting, jumpMovementVector)); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeDouble(x); + buf.writeDouble(y); + buf.writeDouble(z); + buf.writeFloat(rx); + buf.writeFloat(ry); + buf.writeFloat(rz); + buf.writeBoolean(sprinting); + buf.writeFloat(jumpMovementVector); + } + + @Override + public void deserialize(PacketBuffer buf) { + x = buf.readDouble(); + y = buf.readDouble(); + z = buf.readDouble(); + rx = buf.readFloat(); + ry = buf.readFloat(); + rz = buf.readFloat(); + sprinting = buf.readBoolean(); + jumpMovementVector = buf.readFloat(); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/server/motion/RequestMotionPacket.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/motion/RequestMotionPacket.java new file mode 100644 index 00000000..e76675aa --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/motion/RequestMotionPacket.java @@ -0,0 +1,50 @@ +package com.minecrafttas.tasmod.savestates.server.motion; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.savestates.client.gui.GuiSavestateSavingScreen; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +/** + * Requests the motion from the client + * @author Scribble + * + */ +public class RequestMotionPacket implements Packet { + + /** + * Requests the motion from the client + */ + public RequestMotionPacket() { + } + + @Override + public void handle(PacketSide side, EntityPlayer playerz) { + if(side.isClient()) { + EntityPlayerSP player = (EntityPlayerSP) playerz; + if (player != null) { + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiSavestateSavingScreen)) { + Minecraft.getMinecraft().displayGuiScreen(new GuiSavestateSavingScreen()); + } + ClientProxy.packetClient.sendToServer(new MotionPacket(player.motionX, player.motionY, player.motionZ, player.moveForward, player.moveVertical, player.moveStrafing, player.isSprinting(), player.jumpMovementFactor)); + } + } + + } + + @Override + public void serialize(PacketBuffer buf) { + + } + + @Override + public void deserialize(PacketBuffer buf) { + + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/NoPortalTeleporter.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/NoPortalTeleporter.java similarity index 84% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/NoPortalTeleporter.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/NoPortalTeleporter.java index f53d2701..d1ac16d3 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/NoPortalTeleporter.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/NoPortalTeleporter.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.savestates.server.playerloading; +package com.minecrafttas.tasmod.savestates.server.playerloading; import net.minecraft.entity.Entity; import net.minecraft.world.World; diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/SavestatePlayerLoading.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/SavestatePlayerLoading.java similarity index 90% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/SavestatePlayerLoading.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/SavestatePlayerLoading.java index 7dd64971..2b6fbd9c 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/SavestatePlayerLoading.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/SavestatePlayerLoading.java @@ -1,12 +1,11 @@ -package de.scribble.lp.tasmod.savestates.server.playerloading; +package com.minecrafttas.tasmod.savestates.server.playerloading; import java.util.List; import java.util.UUID; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.mixin.accessors.AccessorWorld; -import de.scribble.lp.tasmod.savestates.server.playerloading.SavestatePlayerLoadingPacket.SavestatePlayerLoadingPacketHandler; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.mixin.accessors.AccessorWorld; + import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; @@ -58,7 +57,7 @@ public static void loadAndSendMotionToPlayer() { player.readFromNBT(nbttagcompound); - CommonProxy.NETWORK.sendTo(new SavestatePlayerLoadingPacket(nbttagcompound), player); + TASmod.packetServer.sendTo(new SavestatePlayerLoadingPacket(nbttagcompound), player); } } diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/SavestatePlayerLoadingPacket.java b/src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/SavestatePlayerLoadingPacket.java similarity index 54% rename from src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/SavestatePlayerLoadingPacket.java rename to src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/SavestatePlayerLoadingPacket.java index dc1707c9..28d1d159 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/playerloading/SavestatePlayerLoadingPacket.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/server/playerloading/SavestatePlayerLoadingPacket.java @@ -1,19 +1,18 @@ -package de.scribble.lp.tasmod.savestates.server.playerloading; +package com.minecrafttas.tasmod.savestates.server.playerloading; import java.io.IOException; -import de.pfannekuchen.tasmod.events.CameraInterpolationEvents; -import de.scribble.lp.tasmod.savestates.server.chunkloading.SavestatesChunkControl; -import io.netty.buffer.ByteBuf; +import com.minecrafttas.tasmod.events.CameraInterpolationEvents; +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; +import com.minecrafttas.tasmod.savestates.server.chunkloading.SavestatesChunkControl; + import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.PacketBuffer; import net.minecraft.world.GameType; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; /** * Reads the playerdata coming from the server and also applies motion, relative @@ -22,7 +21,7 @@ * @author ScribbleLP * */ -public class SavestatePlayerLoadingPacket implements IMessage { +public class SavestatePlayerLoadingPacket implements Packet { private NBTTagCompound compound; @@ -33,42 +32,11 @@ public SavestatePlayerLoadingPacket(NBTTagCompound nbttagcompound) { compound = nbttagcompound; }; - @Override - public void fromBytes(ByteBuf buf) { - PacketBuffer buffi = new PacketBuffer(buf); - try { - compound = buffi.readCompoundTag(); - } catch (IOException e) { - e.printStackTrace(); - } - } @Override - public void toBytes(ByteBuf buf) { - PacketBuffer buffi = new PacketBuffer(buf); - buffi.writeCompoundTag(compound); - } - - public NBTTagCompound getNbtTagCompound() { - return compound; - } - - public static class SavestatePlayerLoadingPacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(SavestatePlayerLoadingPacket message, MessageContext ctx) { - if (ctx.side.isClient()) { - Minecraft.getMinecraft().addScheduledTask(() -> { - workaround(message); - }); - } - return null; - } - - @SideOnly(Side.CLIENT) - private void workaround(SavestatePlayerLoadingPacket message) { - net.minecraft.client.entity.EntityPlayerSP player = Minecraft.getMinecraft().player; - NBTTagCompound compound = message.getNbtTagCompound(); + public void handle(PacketSide side, EntityPlayer playerz) { + if(side.isClient()) { + EntityPlayerSP player = (EntityPlayerSP)playerz; player.readFromNBT(compound); NBTTagCompound motion = compound.getCompoundTag("clientMotion"); @@ -106,4 +74,18 @@ private void workaround(SavestatePlayerLoadingPacket message) { } } + @Override + public void serialize(PacketBuffer buf) { + buf.writeCompoundTag(compound); + } + + @Override + public void deserialize(PacketBuffer buf) { + try { + compound = buf.readCompoundTag(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } diff --git a/src/main/java/com/minecrafttas/tasmod/tickratechanger/AdvanceTickratePacket.java b/src/main/java/com/minecrafttas/tasmod/tickratechanger/AdvanceTickratePacket.java new file mode 100644 index 00000000..832051c3 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/tickratechanger/AdvanceTickratePacket.java @@ -0,0 +1,46 @@ +package com.minecrafttas.tasmod.tickratechanger; + +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +/** + * Advanced game by 1 tick + * + * @author Scribble + * + */ +public class AdvanceTickratePacket implements Packet { + /** + * Advanced game by 1 tick + */ + public AdvanceTickratePacket() { + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if (side.isServer()) { + if (player.canUseCommand(2, "tickrate")) { + if (TickrateChangerServer.ticksPerSecond == 0) { + TickrateChangerServer.advanceTick(); + } + } + } else { + TickrateChangerClient.advanceClientTick(); // Using advanceTick() would create an endless loop + } + } + + @Override + public void serialize(PacketBuffer buf) { + + } + + @Override + public void deserialize(PacketBuffer buf) { + + } + + +} diff --git a/src/main/java/com/minecrafttas/tasmod/tickratechanger/ChangeTickratePacket.java b/src/main/java/com/minecrafttas/tasmod/tickratechanger/ChangeTickratePacket.java new file mode 100644 index 00000000..03959294 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/tickratechanger/ChangeTickratePacket.java @@ -0,0 +1,52 @@ +package com.minecrafttas.tasmod.tickratechanger; + +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +/** + * Changes the tickrate on the other side + * + * @author Scribble + * + */ +public class ChangeTickratePacket implements Packet { + + float tickrate; + + public ChangeTickratePacket() { + } + + /** + * Changes the tickrate on the other side + * + * @param tickrate The new tickrate + */ + public ChangeTickratePacket(float tickrate) { + this.tickrate = tickrate; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if (side.isServer()) { + if (player.canUseCommand(2, "tickrate")) { + TickrateChangerServer.changeTickrate(tickrate); + } + } else { + TickrateChangerClient.changeClientTickrate(tickrate); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeFloat(tickrate); + } + + @Override + public void deserialize(PacketBuffer buf) { + tickrate = buf.readFloat(); + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/CommandTickrate.java b/src/main/java/com/minecrafttas/tasmod/tickratechanger/CommandTickrate.java similarity index 96% rename from src/main/java/de/scribble/lp/tasmod/tickratechanger/CommandTickrate.java rename to src/main/java/com/minecrafttas/tasmod/tickratechanger/CommandTickrate.java index 73a1bd89..533536bf 100644 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/CommandTickrate.java +++ b/src/main/java/com/minecrafttas/tasmod/tickratechanger/CommandTickrate.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.tickratechanger; +package com.minecrafttas.tasmod.tickratechanger; import java.util.List; diff --git a/src/main/java/com/minecrafttas/tasmod/tickratechanger/PauseTickratePacket.java b/src/main/java/com/minecrafttas/tasmod/tickratechanger/PauseTickratePacket.java new file mode 100644 index 00000000..2d4a5c4d --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/tickratechanger/PauseTickratePacket.java @@ -0,0 +1,114 @@ +package com.minecrafttas.tasmod.tickratechanger; + +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +/** + * Sets the game to tickrate 0 and back + * + * @author Scribble + * + */ +public class PauseTickratePacket implements Packet { + + private short status; + + /** + * Toggles the tickrate between 0 and tickrate > 0 + */ + public PauseTickratePacket() { + status = 0; + } + + /** + * Changes the state to either PAUSE UNPAUSE or TOGGLED + * + * @param state The state + */ + public PauseTickratePacket(State state) { + this.status = state.toShort(); + } + + public State getState() { + return State.fromShort(status); + } + + + /** + * Can be {@link State#PAUSE}, {@link State#UNPAUSE} or {@link State#TOGGLE} + * + * @author ScribbleLP + * + */ + public enum State { + /** + * Set's the game to tickrate 0 + */ + PAUSE((short) 1), + /** + * Set's the game to "tickrate saved" + */ + UNPAUSE((short) 2), + /** + * Toggles between {@link #PAUSE} and {@link #UNPAUSE} + */ + TOGGLE((short) 0); + + private short id; + + State(short i) { + id = i; + } + + public short toShort() { + return id; + } + + public static State fromShort(short i) { + switch (i) { + case 1: + return PAUSE; + case 2: + return UNPAUSE; + default: + return TOGGLE; + } + } + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if (side.isServer()) { + if (player.canUseCommand(2, "tickrate")) { + State state = getState(); + if (state == State.PAUSE) + TickrateChangerServer.pauseGame(true); + else if (state == State.UNPAUSE) + TickrateChangerServer.pauseGame(false); + else if (state == State.TOGGLE) + TickrateChangerServer.togglePause(); + } + } else if (side.isClient()) { + State state = getState(); + if (state == State.PAUSE) + TickrateChangerClient.pauseClientGame(true); + else if (state == State.UNPAUSE) + TickrateChangerClient.pauseClientGame(false); + else if (state == State.TOGGLE) + TickrateChangerClient.togglePauseClient(); + } + } + + @Override + public void serialize(PacketBuffer buf) { + buf.writeShort(status); + } + + @Override + public void deserialize(PacketBuffer buf) { + status = buf.readShort(); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerClient.java b/src/main/java/com/minecrafttas/tasmod/tickratechanger/TickrateChangerClient.java similarity index 81% rename from src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerClient.java rename to src/main/java/com/minecrafttas/tasmod/tickratechanger/TickrateChangerClient.java index cec4fb46..8296732a 100644 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerClient.java +++ b/src/main/java/com/minecrafttas/tasmod/tickratechanger/TickrateChangerClient.java @@ -1,14 +1,15 @@ -package de.scribble.lp.tasmod.tickratechanger; +package com.minecrafttas.tasmod.tickratechanger; + +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.mixin.accessors.AccessorRunStuff; +import com.minecrafttas.tasmod.mixin.accessors.AccessorTimer; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.mixin.accessors.AccessorRunStuff; -import de.scribble.lp.tasmod.mixin.accessors.AccessorTimer; import net.minecraft.client.Minecraft; /** * Changes the {@link Minecraft#timer} variable - * @author ScribbleLP + * @author Scribble * */ public class TickrateChangerClient { @@ -27,6 +28,8 @@ public class TickrateChangerClient { * True if the tickrate is 20 and the client should advance 1 tick */ public static boolean advanceTick = false; + + public static long millisecondsPerTick = 50L; /** * Changes both client and server tickrates @@ -37,6 +40,10 @@ public static void changeTickrate(float tickrate) { changeClientTickrate(tickrate); changeServerTickrate(tickrate); } + + public static void changeClientTickrate(float tickrate) { + changeClientTickrate(tickrate, true); + } /** * Changes the tickrate of the client
@@ -45,13 +52,15 @@ public static void changeTickrate(float tickrate) { * * @param tickrate The new tickrate of the client */ - public static void changeClientTickrate(float tickrate) { + public static void changeClientTickrate(float tickrate, boolean log) { if (tickrate < 0) { return; } Minecraft mc = Minecraft.getMinecraft(); if (tickrate > 0) { - ((AccessorTimer) ((AccessorRunStuff) mc).timer()).tickLength(1000F / tickrate); + millisecondsPerTick = (long) (1000F / tickrate); + ((AccessorTimer) ((AccessorRunStuff) mc).timer()).tickLength(millisecondsPerTick); + } else if (tickrate == 0F) { if (ticksPerSecond != 0) { tickrateSaved = ticksPerSecond; @@ -59,7 +68,8 @@ public static void changeClientTickrate(float tickrate) { ((AccessorTimer) ((AccessorRunStuff) mc).timer()).tickLength(Float.MAX_VALUE); } ticksPerSecond = tickrate; - log("Setting the client tickrate to "+ ticksPerSecond); + if(log) + log("Setting the client tickrate to "+ ticksPerSecond); } /** @@ -72,7 +82,7 @@ public static void changeServerTickrate(float tickrate) { if (tickrate < 0) { return; } - CommonProxy.NETWORK.sendToServer(new ChangeTickratePacket(tickrate)); + ClientProxy.packetClient.sendToServer(new ChangeTickratePacket(tickrate)); } /** @@ -80,7 +90,7 @@ public static void changeServerTickrate(float tickrate) { */ public static void togglePause() { if (Minecraft.getMinecraft().world != null) { - CommonProxy.NETWORK.sendToServer(new PauseTickratePacket()); + ClientProxy.packetClient.sendToServer(new PauseTickratePacket()); } else { togglePauseClient(); } @@ -139,7 +149,7 @@ public static void advanceTick() { * Sends a {@link AdvanceTickratePacket} to the server to advance the server */ public static void advanceServerTick() { - CommonProxy.NETWORK.sendToServer(new AdvanceTickratePacket()); + ClientProxy.packetClient.sendToServer(new AdvanceTickratePacket()); } /** diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerServer.java b/src/main/java/com/minecrafttas/tasmod/tickratechanger/TickrateChangerServer.java similarity index 62% rename from src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerServer.java rename to src/main/java/com/minecrafttas/tasmod/tickratechanger/TickrateChangerServer.java index 1885d5fe..467f6ebe 100644 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerServer.java +++ b/src/main/java/com/minecrafttas/tasmod/tickratechanger/TickrateChangerServer.java @@ -1,10 +1,27 @@ -package de.scribble.lp.tasmod.tickratechanger; +package com.minecrafttas.tasmod.tickratechanger; + +import org.apache.logging.log4j.Logger; + +import com.minecrafttas.tasmod.TASmod; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; import net.minecraft.entity.player.EntityPlayerMP; +/** + * Controls the tickrate on the server side + * + * The tickrate is controlled in MinecraftServer.run() where the server is halted for 50 milliseconds minus the time the tick took to execute. + *

+ * To change the tickrate on server and all clients use {@link #changeTickrate(float)}. + *

+ * You can individually set the tickrate with {@link #changeClientTickrate(float)} and {@link #changeServerTickrate(float)}. + *

+ * + * + * @author Scribble + * + */ public class TickrateChangerServer { + /** * The current tickrate of the client */ @@ -15,23 +32,26 @@ public class TickrateChangerServer { */ public static long millisecondsPerTick=50L; - /** - * If true, interrupts the infinite loop that is used to enable tickratae 0 on the server - */ - public static boolean interrupt=false; - /** * The tickrate before {@link #ticksPerSecond} was changed to 0, used to toggle * pausing */ public static float tickrateSaved=20F; + /** * True if the tickrate is 20 and the server should advance 1 tick */ public static boolean advanceTick=false; /** - * Changes both client and server tickrates + * The logger used for logging. Has to be set seperately + */ + public static Logger logger; + + /** + * Changes both client and server tickrates. + *

+ * Tickrates can be tickrate>=0 with 0 pausing the game. * * @param tickrate The new tickrate of client and server */ @@ -40,13 +60,20 @@ public static void changeTickrate(float tickrate) { changeServerTickrate(tickrate); } + public static void changeClientTickrate(float tickrate) { + changeClientTickrate(tickrate, false); + } + /** * Changes the tickrate of all clients. Sends a {@link ChangeTickratePacket} * * @param tickrate The new tickrate of the client + * @param log If a message should logged */ - public static void changeClientTickrate(float tickrate) { - CommonProxy.NETWORK.sendToAll(new ChangeTickratePacket(tickrate)); + public static void changeClientTickrate(float tickrate, boolean log) { + if(log) + log("Changing the tickrate "+ tickrate + " to all clients"); + TASmod.packetServer.sendToAll(new ChangeTickratePacket(tickrate)); } /** @@ -55,17 +82,27 @@ public static void changeClientTickrate(float tickrate) { * @param tickrate The new tickrate of the server */ public static void changeServerTickrate(float tickrate) { - interrupt=true; + changeServerTickrate(tickrate, true); + } + + /** + * Changes the tickrate of the server + * + * @param tickrate The new tickrate of the server + * @param log If a message should logged + */ + public static void changeServerTickrate(float tickrate, boolean log) { if(tickrate>0) { millisecondsPerTick = (long)(1000L / tickrate); }else if(tickrate==0) { if(ticksPerSecond!=0) { tickrateSaved=ticksPerSecond; } - millisecondsPerTick = Long.MAX_VALUE; } ticksPerSecond = tickrate; - log("Setting the server tickrate to "+ ticksPerSecond); + if(log) { + log("Setting the server tickrate to "+ ticksPerSecond); + } } /** @@ -119,7 +156,7 @@ public static void advanceTick() { * Sends a {@link AdvanceTickratePacket} to all clients */ private static void advanceClientTick() { - CommonProxy.NETWORK.sendToAll(new AdvanceTickratePacket()); + TASmod.packetServer.sendToAll(new AdvanceTickratePacket()); } /** @@ -138,12 +175,16 @@ private static void advanceServerTick() { */ public static void joinServer(EntityPlayerMP player) { if(TASmod.getServerInstance().isDedicatedServer()) { - TASmod.logger.info("Sending the current tickrate ({}) to {}", ticksPerSecond, player.getName()); - CommonProxy.NETWORK.sendTo(new ChangeTickratePacket(ticksPerSecond), player); + log("Sending the current tickrate ("+ticksPerSecond+") to " +player.getName()); + TASmod.packetServer.sendTo(new ChangeTickratePacket(ticksPerSecond), player); } } + /** + * The message to log + * @param msg + */ private static void log(String msg) { - TASmod.logger.info(msg); + logger.info(msg); } } diff --git a/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncClient.java b/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncClient.java new file mode 100644 index 00000000..566c0dd6 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncClient.java @@ -0,0 +1,44 @@ +package com.minecrafttas.tasmod.ticksync; + +import java.util.concurrent.atomic.AtomicBoolean; + +import com.minecrafttas.tasmod.ClientProxy; + +import net.minecraft.client.Minecraft; + +/** + * This class manages tick sync + * German: https://1drv.ms/p/s!Av_ysXerhm5CphLvLvguvL5QYe1A?e=MHPldP + * English: https://1drv.ms/p/s!Av_ysXerhm5Cpha7Qq2tiVebd4DY?e=pzxOva + * + * @author Pancake + */ +public class TickSyncClient { + + public static final AtomicBoolean shouldTick = new AtomicBoolean(true); + + /** + * Handles incoming tick packets from the server to the client + * This will simply tick the client as long as the tick is correct + * + * @param uuid Server UUID, null + * @param tick Current tick of the server + */ + public static void onPacket() { + shouldTick.set(true); + } + + /** + * Called after a client tick. This will send a packet + * to the server making it tick + * + * @param mc Instance of Minecraft + */ + public static void clientPostTick(Minecraft mc) { + if (mc.player == null && ClientProxy.packetClient==null) { + return; + } + ClientProxy.packetClient.sendToServer(new TickSyncPacket(mc.player.getGameProfile().getId())); + } + +} diff --git a/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncPacket.java b/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncPacket.java new file mode 100644 index 00000000..27347e51 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncPacket.java @@ -0,0 +1,48 @@ +package com.minecrafttas.tasmod.ticksync; + +import java.util.UUID; + +import com.minecrafttas.tasmod.networking.Packet; +import com.minecrafttas.tasmod.networking.PacketSide; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.network.PacketBuffer; + +/** + * Packet for {@linkplain TickSyncServer} + * @author Scribble + * + */ +public class TickSyncPacket implements Packet { + + protected UUID uuid; + + public TickSyncPacket() { + + } + + public TickSyncPacket(UUID id) { + this.uuid = id; + } + + @Override + public void handle(PacketSide side, EntityPlayer player) { + if(side.isServer()) { + TickSyncServer.onPacket(this.uuid); + }else { + TickSyncClient.onPacket(); + } + } + + @Override + public void serialize(PacketBuffer buf) { + if(uuid!=null) + buf.writeUniqueId(uuid); + } + + @Override + public void deserialize(PacketBuffer buf) { + uuid = buf.readUniqueId(); + } + +} diff --git a/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncServer.java b/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncServer.java new file mode 100644 index 00000000..fc5337db --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ticksync/TickSyncServer.java @@ -0,0 +1,62 @@ +package com.minecrafttas.tasmod.ticksync; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import com.minecrafttas.tasmod.TASmod; + +/** + * This class manages tick sync + * German: https://1drv.ms/p/s!Av_ysXerhm5CphLvLvguvL5QYe1A?e=MHPldP + * English: https://1drv.ms/p/s!Av_ysXerhm5Cpha7Qq2tiVebd4DY?e=pzxOva + * + * @author Pancake + */ +public class TickSyncServer { + + private static List synchronizedList = Collections.synchronizedList(new ArrayList<>()); + + /** + * Handles incoming tick packets from the client to the server + * This will put the uuid into a list of ticked clients and once every client + * is in that list, tick the server. + * + * @param uuid Player UUID + * @param tick Current tick of the player + */ + public static void onPacket(UUID uuid) { + synchronized (synchronizedList) { + if(!synchronizedList.contains(uuid)) { + synchronizedList.add(uuid); + } + } + } + + public static boolean shouldTick() { + synchronized (synchronizedList) { + int acknowledged = synchronizedList.size(); + int totalConnections = TASmod.packetServer.getConnections(); + if(acknowledged >= totalConnections) { + return true; + }else { + return false; + } + } + } + + /** + * Called after a server tick. This will send a packet + * to all clients making them tick + */ + public static void serverPostTick() { + TASmod.packetServer.sendToAll(new TickSyncPacket()); + if(synchronizedList.size()>0) + synchronizedList.clear(); + } + + public static void clearList() { + synchronizedList.clear(); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/util/FileThread.java b/src/main/java/com/minecrafttas/tasmod/util/FileThread.java similarity index 96% rename from src/main/java/de/scribble/lp/tasmod/util/FileThread.java rename to src/main/java/com/minecrafttas/tasmod/util/FileThread.java index 1f3e80a7..cdf61425 100644 --- a/src/main/java/de/scribble/lp/tasmod/util/FileThread.java +++ b/src/main/java/com/minecrafttas/tasmod/util/FileThread.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.util; +package com.minecrafttas.tasmod.util; import java.io.File; import java.io.FileNotFoundException; diff --git a/src/main/java/de/scribble/lp/tasmod/util/ModIncompatibleException.java b/src/main/java/com/minecrafttas/tasmod/util/ModIncompatibleException.java similarity index 86% rename from src/main/java/de/scribble/lp/tasmod/util/ModIncompatibleException.java rename to src/main/java/com/minecrafttas/tasmod/util/ModIncompatibleException.java index e81206df..f85575f0 100644 --- a/src/main/java/de/scribble/lp/tasmod/util/ModIncompatibleException.java +++ b/src/main/java/com/minecrafttas/tasmod/util/ModIncompatibleException.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.util; +package com.minecrafttas.tasmod.util; public class ModIncompatibleException extends Exception{ /** diff --git a/src/main/java/de/pfannekuchen/tasmod/utils/PlayerPositionCalculator.java b/src/main/java/com/minecrafttas/tasmod/util/PlayerPositionCalculator.java similarity index 96% rename from src/main/java/de/pfannekuchen/tasmod/utils/PlayerPositionCalculator.java rename to src/main/java/com/minecrafttas/tasmod/util/PlayerPositionCalculator.java index d2ceddc3..ad09dc87 100644 --- a/src/main/java/de/pfannekuchen/tasmod/utils/PlayerPositionCalculator.java +++ b/src/main/java/com/minecrafttas/tasmod/util/PlayerPositionCalculator.java @@ -1,11 +1,12 @@ -package de.pfannekuchen.tasmod.utils; +package com.minecrafttas.tasmod.util; import java.util.List; -import de.pfannekuchen.tasmod.events.CameraInterpolationEvents; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.mixin.accessors.AccessorEntity; -import de.scribble.lp.tasmod.mixin.accessors.AccessorRunStuff; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.events.CameraInterpolationEvents; +import com.minecrafttas.tasmod.mixin.accessors.AccessorEntity; +import com.minecrafttas.tasmod.mixin.accessors.AccessorRunStuff; + import net.minecraft.block.Block; import net.minecraft.block.BlockFence; import net.minecraft.block.BlockFenceGate; @@ -352,7 +353,9 @@ else if (!source.isSneaking() && source.height != 1.65F) yNew = posY; zNew = posZ; - Minecraft.getMinecraft().renderGlobal.drawSelectionBox(source, result, 0, Minecraft.getMinecraft().getRenderPartialTicks()); + if(result!=null) { + Minecraft.getMinecraft().renderGlobal.drawSelectionBox(source, result, 0, Minecraft.getMinecraft().getRenderPartialTicks()); + } GlStateManager.enableAlpha(); } diff --git a/src/main/java/de/scribble/lp/tasmod/util/PointerNormalizer.java b/src/main/java/com/minecrafttas/tasmod/util/PointerNormalizer.java similarity index 99% rename from src/main/java/de/scribble/lp/tasmod/util/PointerNormalizer.java rename to src/main/java/com/minecrafttas/tasmod/util/PointerNormalizer.java index eab6281f..ec020ac4 100644 --- a/src/main/java/de/scribble/lp/tasmod/util/PointerNormalizer.java +++ b/src/main/java/com/minecrafttas/tasmod/util/PointerNormalizer.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.util; +package com.minecrafttas.tasmod.util; import org.lwjgl.LWJGLException; import org.lwjgl.opengl.Display; diff --git a/src/main/java/de/scribble/lp/tasmod/shield/ShieldDownloader.java b/src/main/java/com/minecrafttas/tasmod/util/ShieldDownloader.java similarity index 99% rename from src/main/java/de/scribble/lp/tasmod/shield/ShieldDownloader.java rename to src/main/java/com/minecrafttas/tasmod/util/ShieldDownloader.java index 5220f43a..bba8f150 100644 --- a/src/main/java/de/scribble/lp/tasmod/shield/ShieldDownloader.java +++ b/src/main/java/com/minecrafttas/tasmod/util/ShieldDownloader.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.shield; +package com.minecrafttas.tasmod.util; import java.awt.image.BufferedImage; import java.io.BufferedReader; diff --git a/src/main/java/com/minecrafttas/tasmod/util/TickScheduler.java b/src/main/java/com/minecrafttas/tasmod/util/TickScheduler.java new file mode 100644 index 00000000..1df52a54 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/util/TickScheduler.java @@ -0,0 +1,31 @@ +package com.minecrafttas.tasmod.util; + +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * Schedules a lambda to be run in the next tick + * + * @author Scribble + * + */ +public class TickScheduler { + + Queue queue = new ConcurrentLinkedQueue<>(); + + public void runAllTasks() { + TickTask task; + while((task = queue.poll()) != null) { + task.runTask(); + } + } + + public void add(TickTask task) { + queue.add(task); + } + + @FunctionalInterface + public interface TickTask { + public void runTask(); + } +} diff --git a/src/main/java/de/pfannekuchen/tasmod/utils/TrajectoriesCalculator.java b/src/main/java/com/minecrafttas/tasmod/util/TrajectoriesCalculator.java similarity index 96% rename from src/main/java/de/pfannekuchen/tasmod/utils/TrajectoriesCalculator.java rename to src/main/java/com/minecrafttas/tasmod/util/TrajectoriesCalculator.java index ba03f9de..1052668b 100644 --- a/src/main/java/de/pfannekuchen/tasmod/utils/TrajectoriesCalculator.java +++ b/src/main/java/com/minecrafttas/tasmod/util/TrajectoriesCalculator.java @@ -1,6 +1,7 @@ -package de.pfannekuchen.tasmod.utils; +package com.minecrafttas.tasmod.util; + +import com.minecrafttas.tasmod.mixin.accessors.AccessorRunStuff; -import de.scribble.lp.tasmod.mixin.accessors.AccessorRunStuff; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.item.ItemBow; diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualChar.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualChar.java similarity index 92% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualChar.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualChar.java index 37d024b1..3ed211a7 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualChar.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualChar.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; import java.util.Map; diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualInput.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java similarity index 93% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualInput.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java index c1b2fafa..790025b3 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualInput.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualInput.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; import java.io.File; import java.io.IOException; @@ -6,14 +6,15 @@ import java.util.Iterator; import java.util.List; -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.events.OpenGuiEvents; -import de.scribble.lp.tasmod.inputcontainer.InputContainer; -import de.scribble.lp.tasmod.inputcontainer.TickInputContainer; -import de.scribble.lp.tasmod.mixin.accessors.AccessorRunStuff; -import de.scribble.lp.tasmod.util.PointerNormalizer; -import de.scribble.lp.tasmod.util.TASstate; +import com.minecrafttas.tasmod.ClientProxy; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.events.OpenGuiEvents; +import com.minecrafttas.tasmod.mixin.accessors.AccessorRunStuff; +import com.minecrafttas.tasmod.playback.PlaybackController; +import com.minecrafttas.tasmod.playback.PlaybackController.TASstate; +import com.minecrafttas.tasmod.playback.PlaybackController.TickInputContainer; +import com.minecrafttas.tasmod.util.PointerNormalizer; + import net.minecraft.client.Minecraft; /** @@ -79,7 +80,7 @@ *

  • Recording support for the full keyboard/eventual modding support
  • * * - * @author ScribbleLP + * @author Scribble * */ public class VirtualInput { @@ -88,7 +89,7 @@ public class VirtualInput { * The container where all inputs get stored during recording or stored and * ready to be played back */ - private InputContainer container = new InputContainer(); + private PlaybackController container = new PlaybackController(); // ===========================Keyboard================================= @@ -151,6 +152,7 @@ public void updateNextKeyboard(int keycode, boolean keystate, char character) { return; } VirtualKey key = nextKeyboard.get(keycode); + key.setPressed(keystate); } @@ -417,7 +419,7 @@ public float getSubtickYaw() { // =====================================Container=========================================== - public InputContainer getContainer() { + public PlaybackController getContainer() { return container; } @@ -436,7 +438,7 @@ public void updateContainer() { * * @param container to replace the current one */ - public void setContainer(InputContainer container) { + public void setContainer(PlaybackController container) { this.container = container; } @@ -446,11 +448,11 @@ public void setContainer(InputContainer container) { * Loads and preloads the inputs from the new InputContainer to * {@link #container} * - * Saving a savestate is done via {@linkplain de.scribble.lp.tasmod.util.ContainerSerialiser#saveToFileV1(File, InputContainer)} in {@linkplain de.scribble.lp.tasmod.savestates.client.InputSavestatesHandler#savestate(String)} + * Saving a savestate is done via {@linkplain com.minecrafttas.tasmod.playback.PlaybackSerialiser#saveToFileV1(File, PlaybackController)} in {@linkplain com.minecrafttas.tasmod.savestates.client.InputSavestatesHandler#savestate(String)} * * @param savestatecontainer The container that should be loaded. */ - public void loadClientSavestate(InputContainer savestatecontainer) { + public void loadClientSavestate(PlaybackController savestatecontainer) { if (container.isPlayingback()) { preloadInput(container, savestatecontainer.size() - 1); // Preloading from the current container and @@ -517,7 +519,7 @@ public void loadClientSavestate(InputContainer savestatecontainer) { * @param index The index of the container from which the inputs should be * loaded */ - private void preloadInput(InputContainer container, int index) { + private void preloadInput(PlaybackController container, int index) { TickInputContainer tickcontainer = container.get(index); if (tickcontainer != null) { @@ -535,13 +537,13 @@ private void preloadInput(InputContainer container, int index) { // ================================Load/Save Inputs===================================== public void loadInputs(String filename) throws IOException { - setContainer(ClientProxy.serialiser.fromEntireFileV1(new File(ClientProxy.tasdirectory + "/" + filename + ".tas"))); + setContainer(ClientProxy.serialiser.fromEntireFileV1(new File(ClientProxy.tasdirectory + "/" + filename + ".mctas"))); getContainer().fixTicks(); } public void saveInputs(String filename) throws IOException { ClientProxy.createTASDir(); - ClientProxy.serialiser.saveToFileV1(new File(ClientProxy.tasdirectory + "/" + filename + ".tas"), ClientProxy.virtual.getContainer()); + ClientProxy.serialiser.saveToFileV1(new File(ClientProxy.tasdirectory + "/" + filename + ".mctas"), ClientProxy.virtual.getContainer()); } // =====================================Debug=========================================== diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualKey.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKey.java similarity index 94% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualKey.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualKey.java index d776e009..67cd7323 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualKey.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKey.java @@ -1,11 +1,11 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; import java.io.Serializable; /** * Class to store which keys on the keyboard have been pressed, similar to how Keybindings work.
    * - * @author ScribbleLP + * @author Scribble * */ public class VirtualKey implements Serializable { diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeybindings.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeybindings.java similarity index 96% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeybindings.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeybindings.java index 877e4b5d..6ddf98e5 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeybindings.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeybindings.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; import java.util.ArrayList; import java.util.HashMap; @@ -8,8 +8,8 @@ import org.lwjgl.input.Mouse; import com.google.common.collect.Maps; +import com.minecrafttas.tasmod.ClientProxy; -import de.scribble.lp.tasmod.ClientProxy; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiControls; @@ -28,7 +28,7 @@ * Keybindings registered with {@link #registerBlockedKeyBinding(KeyBinding)} * will not be recorded during a recording or pressed in a playback * - * @author ScribbleLP + * @author Scribble * */ public class VirtualKeybindings { diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeyboard.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard.java similarity index 98% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeyboard.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard.java index aa63602e..4bbcbccf 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeyboard.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboard.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; import java.io.Serializable; import java.util.ArrayList; @@ -11,6 +11,7 @@ import org.lwjgl.input.Keyboard; import com.google.common.collect.Maps; +import com.minecrafttas.tasmod.playback.PlaybackSerialiser; public class VirtualKeyboard implements Serializable { @@ -375,6 +376,6 @@ public String toString() { charString = StringUtils.replace(charString, "\n", "\\n"); } - return "Keyboard:"+keyString + ";" + charString; + return PlaybackSerialiser.SectionsV1.KEYBOARD.getName()+":"+keyString + ";" + charString; } } diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeyboardEvent.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboardEvent.java similarity index 92% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeyboardEvent.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboardEvent.java index c1f61313..90d2a9e0 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualKeyboardEvent.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualKeyboardEvent.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; public class VirtualKeyboardEvent { private int keycode; diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualMouse.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouse.java similarity index 97% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualMouse.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouse.java index 8792d539..8d3ea7cb 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualMouse.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouse.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; import java.io.Serializable; import java.util.ArrayList; @@ -8,6 +8,7 @@ import java.util.Map; import com.google.common.collect.Maps; +import com.minecrafttas.tasmod.playback.PlaybackSerialiser; public class VirtualMouse implements Serializable { @@ -332,7 +333,7 @@ public String toString() { pathString = pathString.concat("[" + path.get(i).toString() + "]" + seperator); } } - return "Mouse:"+keyString + ";" + pathString; + return PlaybackSerialiser.SectionsV1.MOUSE.getName()+":"+keyString + ";" + pathString; } public void setPath(List path) { diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualMouseEvent.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouseEvent.java similarity index 95% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualMouseEvent.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouseEvent.java index b6059d68..ba912793 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualMouseEvent.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualMouseEvent.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; /** * Template for recording Mouse.next() events. diff --git a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualSubticks.java b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualSubticks.java similarity index 76% rename from src/main/java/de/scribble/lp/tasmod/virtual/VirtualSubticks.java rename to src/main/java/com/minecrafttas/tasmod/virtual/VirtualSubticks.java index ad9804b5..29efd22a 100644 --- a/src/main/java/de/scribble/lp/tasmod/virtual/VirtualSubticks.java +++ b/src/main/java/com/minecrafttas/tasmod/virtual/VirtualSubticks.java @@ -1,7 +1,9 @@ -package de.scribble.lp.tasmod.virtual; +package com.minecrafttas.tasmod.virtual; import java.io.Serializable; +import com.minecrafttas.tasmod.playback.PlaybackSerialiser; + public class VirtualSubticks implements Serializable{ /** * @@ -35,6 +37,6 @@ public VirtualSubticks clone() { @Override public String toString() { - return "Camera:"+pitch+";"+yaw; + return PlaybackSerialiser.SectionsV1.CAMERA.getName()+":"+pitch+";"+yaw; } } diff --git a/src/main/java/de/scribble/lp/tasmod/CommonProxy.java b/src/main/java/de/scribble/lp/tasmod/CommonProxy.java deleted file mode 100644 index 4c7be428..00000000 --- a/src/main/java/de/scribble/lp/tasmod/CommonProxy.java +++ /dev/null @@ -1,122 +0,0 @@ -package de.scribble.lp.tasmod; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import de.scribble.lp.tasmod.commands.clearinputs.ClearInputsPacket; -import de.scribble.lp.tasmod.commands.clearinputs.ClearInputsPacket.ClearInputsPacketHandler; -import de.scribble.lp.tasmod.commands.folder.FolderPacket; -import de.scribble.lp.tasmod.commands.folder.FolderPacket.FolderPacketHandler; -import de.scribble.lp.tasmod.commands.fullplay.FullPlayPacket; -import de.scribble.lp.tasmod.commands.fullplay.FullPlayPacket.FullPlayPacketHandler; -import de.scribble.lp.tasmod.commands.fullrecord.FullRecordPacket; -import de.scribble.lp.tasmod.commands.fullrecord.FullRecordPacket.FullRecordPacketHandler; -import de.scribble.lp.tasmod.commands.loadtas.LoadTASPacket; -import de.scribble.lp.tasmod.commands.loadtas.LoadTASPacket.LoadTASPacketHandler; -import de.scribble.lp.tasmod.commands.restartandplay.RestartAndPlayPacket; -import de.scribble.lp.tasmod.commands.restartandplay.RestartAndPlayPacket.RestartAndPlayPacketHandler; -import de.scribble.lp.tasmod.commands.savetas.SaveTASPacket; -import de.scribble.lp.tasmod.commands.savetas.SaveTASPacket.SaveTASPacketHandler; -import de.scribble.lp.tasmod.inputcontainer.InputContainer; -import de.scribble.lp.tasmod.savestates.client.InputSavestatesPacket; -import de.scribble.lp.tasmod.savestates.client.InputSavestatesPacket.InputSavestatesPacketHandler; -import de.scribble.lp.tasmod.savestates.server.LoadstatePacket; -import de.scribble.lp.tasmod.savestates.server.LoadstatePacket.LoadstatePacketHandler; -import de.scribble.lp.tasmod.savestates.server.SavestatePacket; -import de.scribble.lp.tasmod.savestates.server.SavestatePacket.SavestatePacketHandler; -import de.scribble.lp.tasmod.savestates.server.motion.MotionPacket; -import de.scribble.lp.tasmod.savestates.server.motion.MotionPacket.MotionPacketHandler; -import de.scribble.lp.tasmod.savestates.server.motion.RequestMotionPacket; -import de.scribble.lp.tasmod.savestates.server.motion.RequestMotionPacket.RequestMotionPacketHandler; -import de.scribble.lp.tasmod.savestates.server.playerloading.SavestatePlayerLoadingPacket; -import de.scribble.lp.tasmod.savestates.server.playerloading.SavestatePlayerLoadingPacket.SavestatePlayerLoadingPacketHandler; -import de.scribble.lp.tasmod.tickratechanger.AdvanceTickratePacket; -import de.scribble.lp.tasmod.tickratechanger.AdvanceTickratePacket.AdvanceTickratePacketHandler; -import de.scribble.lp.tasmod.tickratechanger.ChangeTickratePacket; -import de.scribble.lp.tasmod.tickratechanger.ChangeTickratePacket.ChangeTickratePacketHandler; -import de.scribble.lp.tasmod.tickratechanger.PauseTickratePacket; -import de.scribble.lp.tasmod.tickratechanger.PauseTickratePacket.PauseTickratePacketHandler; -import de.scribble.lp.tasmod.ticksync.TickSyncPackage; -import de.scribble.lp.tasmod.ticksync.TickSyncPackage.TickSyncPacketHandler; -import de.scribble.lp.tasmod.util.changestates.RequestStatePacket; -import de.scribble.lp.tasmod.util.changestates.RequestStatePacket.RequestStatePacketHandler; -import de.scribble.lp.tasmod.util.changestates.SyncStatePacket; -import de.scribble.lp.tasmod.util.changestates.SyncStatePacket.SyncStatePacketHandler; -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.network.NetworkRegistry; -import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; -import net.minecraftforge.fml.relauncher.Side; - -public class CommonProxy { - public static SimpleNetworkWrapper NETWORK; - public static Logger logger = LogManager.getLogger("TASmod"); - - public void preInit(FMLPreInitializationEvent ev) { - NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel("tasmod"); - int i = -1; - - // Tickrate - NETWORK.registerMessage(ChangeTickratePacketHandler.class, ChangeTickratePacket.class, i++, Side.SERVER); - NETWORK.registerMessage(ChangeTickratePacketHandler.class, ChangeTickratePacket.class, i++, Side.CLIENT); - - NETWORK.registerMessage(AdvanceTickratePacketHandler.class, AdvanceTickratePacket.class, i++, Side.SERVER); - NETWORK.registerMessage(AdvanceTickratePacketHandler.class, AdvanceTickratePacket.class, i++, Side.CLIENT); - - NETWORK.registerMessage(PauseTickratePacketHandler.class, PauseTickratePacket.class, i++, Side.SERVER); - NETWORK.registerMessage(PauseTickratePacketHandler.class, PauseTickratePacket.class, i++, Side.CLIENT); - - // Ticksync - NETWORK.registerMessage(TickSyncPacketHandler.class, TickSyncPackage.class, i++, Side.CLIENT); - - // Sync State - NETWORK.registerMessage(RequestStatePacketHandler.class, RequestStatePacket.class, i++, Side.CLIENT); - - NETWORK.registerMessage(SyncStatePacketHandler.class, SyncStatePacket.class, i++, Side.CLIENT); - NETWORK.registerMessage(SyncStatePacketHandler.class, SyncStatePacket.class, i++, Side.SERVER); - - // Trigger savestates/loadstates on the client - NETWORK.registerMessage(SavestatePacketHandler.class, SavestatePacket.class, i++, Side.SERVER); - NETWORK.registerMessage(SavestatePacketHandler.class, SavestatePacket.class, i++, Side.CLIENT); - NETWORK.registerMessage(LoadstatePacketHandler.class, LoadstatePacket.class, i++, Side.SERVER); - NETWORK.registerMessage(LoadstatePacketHandler.class, LoadstatePacket.class, i++, Side.CLIENT); - - // Sync player motion between client and server - NETWORK.registerMessage(RequestMotionPacketHandler.class, RequestMotionPacket.class, i++, Side.CLIENT); - NETWORK.registerMessage(MotionPacketHandler.class, MotionPacket.class, i++, Side.SERVER); - - // Create or load a savestate of the recording or playback on the client - NETWORK.registerMessage(InputSavestatesPacketHandler.class, InputSavestatesPacket.class, i++, Side.CLIENT); - - // When loadstating, send the data of the client from server to client - NETWORK.registerMessage(SavestatePlayerLoadingPacketHandler.class, SavestatePlayerLoadingPacket.class, i++, Side.CLIENT); - - // Trigger saving the inputs to file on the client - NETWORK.registerMessage(SaveTASPacketHandler.class, SaveTASPacket.class, i++, Side.CLIENT); - NETWORK.registerMessage(SaveTASPacketHandler.class, SaveTASPacket.class, i++, Side.SERVER); - NETWORK.registerMessage(LoadTASPacketHandler.class, LoadTASPacket.class, i++, Side.CLIENT); - NETWORK.registerMessage(LoadTASPacketHandler.class, LoadTASPacket.class, i++, Side.SERVER); - NETWORK.registerMessage(ClearInputsPacketHandler.class, ClearInputsPacket.class, i++, Side.CLIENT); - NETWORK.registerMessage(ClearInputsPacketHandler.class, ClearInputsPacket.class, i++, Side.SERVER); - - // Misc - NETWORK.registerMessage(FolderPacketHandler.class, FolderPacket.class, i++, Side.CLIENT); - NETWORK.registerMessage(InputContainer.TeleportPlayerPacketHandler.class, InputContainer.TeleportPlayerPacket.class, i++, Side.SERVER); - - // Fullrecord - NETWORK.registerMessage(FullRecordPacketHandler.class, FullRecordPacket.class, i++, Side.CLIENT); - // Fullplay - NETWORK.registerMessage(FullPlayPacketHandler.class, FullPlayPacket.class, i++, Side.CLIENT); - // RestartAndPlay - NETWORK.registerMessage(RestartAndPlayPacketHandler.class, RestartAndPlayPacket.class, i++, Side.CLIENT); - - } - - public void init(FMLInitializationEvent ev) { - } - - public void postInit(FMLPostInitializationEvent ev) { - } - -} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/clearinputs/ClearInputsPacket.java b/src/main/java/de/scribble/lp/tasmod/commands/clearinputs/ClearInputsPacket.java deleted file mode 100644 index f82bf618..00000000 --- a/src/main/java/de/scribble/lp/tasmod/commands/clearinputs/ClearInputsPacket.java +++ /dev/null @@ -1,40 +0,0 @@ -package de.scribble.lp.tasmod.commands.clearinputs; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class ClearInputsPacket implements IMessage{ - - @Override - public void fromBytes(ByteBuf buf) { - } - - @Override - public void toBytes(ByteBuf buf) { - } - - public static class ClearInputsPacketHandler implements IMessageHandler{ - - @Override - public IMessage onMessage(ClearInputsPacket message, MessageContext ctx) { - if(ctx.side.isServer()) { - ctx.getServerHandler().player.getServerWorld().addScheduledTask(()->{ - if(ctx.getServerHandler().player.canUseCommand(2, "clearinputs")) { - CommonProxy.NETWORK.sendToAll(message); - } - }); - } else { - Minecraft.getMinecraft().addScheduledTask(()->{ - ClientProxy.virtual.getContainer().clear(); - }); - } - return null; - } - - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/folder/FolderPacket.java b/src/main/java/de/scribble/lp/tasmod/commands/folder/FolderPacket.java deleted file mode 100644 index 39da711d..00000000 --- a/src/main/java/de/scribble/lp/tasmod/commands/folder/FolderPacket.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.scribble.lp.tasmod.commands.folder; - -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class FolderPacket implements IMessage{ - int command; - public FolderPacket() { - } - - public FolderPacket(int command) { - this.command=command; - } - - @Override - public void fromBytes(ByteBuf buf) { - command=buf.readInt(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(command); - } - - public int getCommand() { - return command; - } - - public static class FolderPacketHandler implements IMessageHandler{ - - @Override - public IMessage onMessage(FolderPacket message, MessageContext ctx) { - if(ctx.side.isClient()) { - switch(message.command) { - case 0: - OpenStuff.openSavestates(); - break; - case 1: - OpenStuff.openTASFolder(); - break; - } - } - return null; - } - - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/fullplay/FullPlayPacket.java b/src/main/java/de/scribble/lp/tasmod/commands/fullplay/FullPlayPacket.java deleted file mode 100644 index 0a1d99ae..00000000 --- a/src/main/java/de/scribble/lp/tasmod/commands/fullplay/FullPlayPacket.java +++ /dev/null @@ -1,57 +0,0 @@ -package de.scribble.lp.tasmod.commands.fullplay; - -import de.scribble.lp.tasmod.events.OpenGuiEvents; -import de.scribble.lp.tasmod.util.TASstate; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiMainMenu; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class FullPlayPacket implements IMessage { - - public FullPlayPacket() { - } - - @Override - public void fromBytes(ByteBuf buf) { - } - - @Override - public void toBytes(ByteBuf buf) { - } - - public static class FullPlayPacketHandler implements IMessageHandler { - - public FullPlayPacketHandler() { - } - - @Override - public IMessage onMessage(FullPlayPacket message, MessageContext ctx) { - if (ctx.side.isClient()) { - workaround(); - } - return null; - } - - @SideOnly(Side.CLIENT) - private void workaround() { - Minecraft mc = Minecraft.getMinecraft(); - mc.addScheduledTask(() ->{ - try { - Thread.sleep(10L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - OpenGuiEvents.stateWhenOpened=TASstate.PLAYBACK; - mc.world.sendQuittingDisconnectingPacket(); - mc.loadWorld((WorldClient)null); - mc.displayGuiScreen(new GuiMainMenu()); - }); - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/fullrecord/FullRecordPacket.java b/src/main/java/de/scribble/lp/tasmod/commands/fullrecord/FullRecordPacket.java deleted file mode 100644 index 876840eb..00000000 --- a/src/main/java/de/scribble/lp/tasmod/commands/fullrecord/FullRecordPacket.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.scribble.lp.tasmod.commands.fullrecord; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.events.OpenGuiEvents; -import de.scribble.lp.tasmod.util.TASstate; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.WorldClient; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class FullRecordPacket implements IMessage { - - public FullRecordPacket() { - } - - @Override - public void fromBytes(ByteBuf buf) { - } - - @Override - public void toBytes(ByteBuf buf) { - } - - public static class FullRecordPacketHandler implements IMessageHandler { - - public FullRecordPacketHandler() { - } - - @Override - public IMessage onMessage(FullRecordPacket message, MessageContext ctx) { - if (ctx.side == Side.CLIENT) { - Minecraft mc = Minecraft.getMinecraft(); - mc.addScheduledTask(() -> { - workaround(mc); - }); - } - return null; - } - - @SideOnly(Side.CLIENT) - private void workaround(Minecraft mc) { - OpenGuiEvents.stateWhenOpened = TASstate.RECORDING; - ClientProxy.virtual.getContainer().clear(); - mc.world.sendQuittingDisconnectingPacket(); - mc.loadWorld((WorldClient) null); - mc.displayGuiScreen(new net.minecraft.client.gui.GuiMainMenu()); - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/loadtas/LoadTASPacket.java b/src/main/java/de/scribble/lp/tasmod/commands/loadtas/LoadTASPacket.java deleted file mode 100644 index 71f57df4..00000000 --- a/src/main/java/de/scribble/lp/tasmod/commands/loadtas/LoadTASPacket.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.scribble.lp.tasmod.commands.loadtas; - -import java.io.IOException; -import java.nio.charset.Charset; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class LoadTASPacket implements IMessage{ - private String name; - - public LoadTASPacket() { - } - - public LoadTASPacket(String name) { - this.name=name; - } - @Override - public void fromBytes(ByteBuf buf) { - int length = buf.readInt(); - name = (String) buf.readCharSequence(length, Charset.defaultCharset()); - - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(name.getBytes().length); - buf.writeCharSequence(name, Charset.defaultCharset()); - } - - public String getName() { - return name; - } - - public static class LoadTASPacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(LoadTASPacket message, MessageContext ctx) { - if (ctx.side.isServer()) { - ctx.getServerHandler().player.getServerWorld().addScheduledTask(() -> { - if (ctx.getServerHandler().player.canUseCommand(2, "loadtas")) { - CommonProxy.NETWORK.sendToAll(message); - } - }); - } else { - Minecraft.getMinecraft().addScheduledTask(() -> { - try { - ClientProxy.virtual.loadInputs(message.getName()); - } catch (IOException e) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + e.getMessage())); - return; - } - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.GREEN + "Loaded inputs from " + message.getName() + ".tas")); - }); - } - return null; - } - - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/restartandplay/RestartAndPlayPacket.java b/src/main/java/de/scribble/lp/tasmod/commands/restartandplay/RestartAndPlayPacket.java deleted file mode 100644 index 30d2bc69..00000000 --- a/src/main/java/de/scribble/lp/tasmod/commands/restartandplay/RestartAndPlayPacket.java +++ /dev/null @@ -1,55 +0,0 @@ -package de.scribble.lp.tasmod.commands.restartandplay; - -import java.nio.charset.Charset; - -import de.scribble.lp.tasmod.ClientProxy; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class RestartAndPlayPacket implements IMessage{ - private String name; - - public RestartAndPlayPacket() { - } - - public RestartAndPlayPacket(String name) { - this.name=name; - } - @Override - public void fromBytes(ByteBuf buf) { - int length = buf.readInt(); - name = (String) buf.readCharSequence(length, Charset.defaultCharset()); - - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(name.getBytes().length); - buf.writeCharSequence(name, Charset.defaultCharset()); - } - - public static class RestartAndPlayPacketHandler implements IMessageHandler{ - - @Override - public IMessage onMessage(RestartAndPlayPacket message, MessageContext ctx) { - if(ctx.side.isClient()) { - try { - Thread.sleep(100L); - } catch (InterruptedException e) { - e.printStackTrace(); - } - Minecraft.getMinecraft().addScheduledTask(() -> { - ClientProxy.config.get("General", "fileToLoad", "").set(message.name); - ClientProxy.config.save(); - FMLCommonHandler.instance().exitJava(0, false); - }); - } - return null; - } - - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/commands/savetas/SaveTASPacket.java b/src/main/java/de/scribble/lp/tasmod/commands/savetas/SaveTASPacket.java deleted file mode 100644 index 990c6e17..00000000 --- a/src/main/java/de/scribble/lp/tasmod/commands/savetas/SaveTASPacket.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.scribble.lp.tasmod.commands.savetas; - -import java.io.IOException; -import java.nio.charset.Charset; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class SaveTASPacket implements IMessage { - String name; - - public SaveTASPacket() { - } - - public SaveTASPacket(String recordingName) { - name = recordingName; - } - - @Override - public void fromBytes(ByteBuf buf) { - int length = buf.readInt(); - name = (String) buf.readCharSequence(length, Charset.defaultCharset()); - - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(name.getBytes().length); - buf.writeCharSequence(name, Charset.defaultCharset()); - } - - public String getName() { - return name; - } - - public static class SaveTASPacketHandler implements IMessageHandler { - - public SaveTASPacketHandler() { - } - - @Override - public IMessage onMessage(SaveTASPacket message, MessageContext ctx) { - if (ctx.side.isClient()) { - Minecraft.getMinecraft().addScheduledTask(() -> { - try { - ClientProxy.virtual.saveInputs(message.getName()); - } catch (IOException e) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.RED + e.getMessage())); - return; - } - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(TextFormatting.GREEN + "Saved inputs to " + message.getName() + ".tas")); - }); - } else { - ctx.getServerHandler().player.getServerWorld().addScheduledTask(() -> { - if (ctx.getServerHandler().player.canUseCommand(2, "savetas")) { - CommonProxy.NETWORK.sendToAll(message); - } - }); - } - return null; - } - - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/events/KeybindingEvents.java b/src/main/java/de/scribble/lp/tasmod/events/KeybindingEvents.java deleted file mode 100644 index 56f72c22..00000000 --- a/src/main/java/de/scribble/lp/tasmod/events/KeybindingEvents.java +++ /dev/null @@ -1,56 +0,0 @@ -package de.scribble.lp.tasmod.events; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.externalGui.InputContainerView; -import de.scribble.lp.tasmod.savestates.server.LoadstatePacket; -import de.scribble.lp.tasmod.savestates.server.SavestatePacket; -import de.scribble.lp.tasmod.tickratechanger.TickrateChangerClient; -import de.scribble.lp.tasmod.util.TASstate; -import de.scribble.lp.tasmod.virtual.VirtualKeybindings; -import net.minecraft.client.Minecraft; - -/** - * The class where all keybinding functionality is executed - * @author ScribbleLP - * - */ -public class KeybindingEvents { - - public static void fireKeybindingsEvent() { - - if (VirtualKeybindings.isKeyDownExceptTextfield(ClientProxy.savestateSaveKey)) { - - CommonProxy.NETWORK.sendToServer(new SavestatePacket()); - - } else if (VirtualKeybindings.isKeyDownExceptTextfield(ClientProxy.savestateLoadKey)) { - - CommonProxy.NETWORK.sendToServer(new LoadstatePacket()); - - } else if (VirtualKeybindings.isKeyDownExceptTextfield(ClientProxy.bufferViewKey)) { - - InputContainerView.startBufferView(); - - } else if (VirtualKeybindings.isKeyDownExceptTextfield(ClientProxy.infoGuiKey)) { - - Minecraft.getMinecraft().displayGuiScreen(ClientProxy.hud); - - } else if (VirtualKeybindings.isKeyDown(ClientProxy.stopkey)) { - - TASstate.setOrSend(TASstate.NONE); - - } else if (VirtualKeybindings.isKeyDown(ClientProxy.tickratezeroKey)) { - - TickrateChangerClient.togglePause(); - - } else if (VirtualKeybindings.isKeyDown(ClientProxy.tickAdvance)) { - - TickrateChangerClient.advanceTick(); - - } else if (VirtualKeybindings.isKeyDown(ClientProxy.testingKey)) { - - TASstate.setOrSend(ClientProxy.virtual.getContainer().togglePause()); - - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/inputcontainer/TickInputContainer.java b/src/main/java/de/scribble/lp/tasmod/inputcontainer/TickInputContainer.java deleted file mode 100644 index 649a48ca..00000000 --- a/src/main/java/de/scribble/lp/tasmod/inputcontainer/TickInputContainer.java +++ /dev/null @@ -1,64 +0,0 @@ -package de.scribble.lp.tasmod.inputcontainer; - -import java.io.Serializable; - -import de.scribble.lp.tasmod.virtual.VirtualKeyboard; -import de.scribble.lp.tasmod.virtual.VirtualMouse; -import de.scribble.lp.tasmod.virtual.VirtualSubticks; - -public class TickInputContainer implements Serializable { - - private static final long serialVersionUID = -3420565284438152474L; - - private int tick; - - private VirtualKeyboard keyboard; - - private VirtualMouse mouse; - - private VirtualSubticks subticks; - - public TickInputContainer(int tick, VirtualKeyboard keyboard, VirtualMouse mouse, VirtualSubticks subticks) { - this.tick = tick; - this.keyboard = keyboard; - this.mouse = mouse; - this.subticks = subticks; - } - - public TickInputContainer(int tick) { - this.tick = tick; - this.keyboard = new VirtualKeyboard(); - this.mouse = new VirtualMouse(); - this.subticks = new VirtualSubticks(0, 0); - } - - @Override - public String toString() { - return tick + "|" + keyboard.toString() + "|" + mouse.toString() + "|" + subticks.toString(); - } - - public VirtualKeyboard getKeyboard() { - return keyboard; - } - - public VirtualMouse getMouse() { - return mouse; - } - - public VirtualSubticks getSubticks() { - return subticks; - } - - public int getTick() { - return tick; - } - - public void setTick(int tick) { - this.tick = tick; - } - - @Override - public TickInputContainer clone() { - return new TickInputContainer(tick, keyboard, mouse, subticks); - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/monitoring/DesyncMonitoring.java b/src/main/java/de/scribble/lp/tasmod/monitoring/DesyncMonitoring.java deleted file mode 100644 index f1a8655f..00000000 --- a/src/main/java/de/scribble/lp/tasmod/monitoring/DesyncMonitoring.java +++ /dev/null @@ -1,214 +0,0 @@ -package de.scribble.lp.tasmod.monitoring; - -import java.util.ArrayList; -import java.util.List; - -import de.scribble.lp.tasmod.inputcontainer.InputContainer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.util.text.TextFormatting; - -/** - * Stores the players position during recording and compares it with the position during playback - * @author ScribbleLP - * - */ -public class DesyncMonitoring { - private List pos = new ArrayList(); - - private String lastDesync=""; - - private String x; - private String y; - private String z; - - private String Mx; - private String My; - private String Mz; - - - public void capturePosition() { - EntityPlayerSP player = Minecraft.getMinecraft().player; - if (player != null) { - pos.add(player.posX + " " + player.posY + " " + player.posZ + " " + player.motionX + " " + player.motionY + " " + player.motionZ); - }else { - pos.add(0 + " " + 0 + " " + 0 + " " + 0 + " " + 0 + " " + 0); - } - } - - public List getPos() { - return pos; - } - - public void setPos(List pos) { - this.pos = pos; - } - - public String get(int index) { - String out = ""; - - try { - out = pos.get(index); - } catch (IndexOutOfBoundsException e) { - return ""; - } - return out; - } - - public String getMonitoring(InputContainer inputContainer, EntityPlayerSP player) { - int index = inputContainer.index() - 1; - String position = get(index); - - if (position.isEmpty()) { - clearDelta(); - return TextFormatting.GRAY + "Empty"; - } - - if(inputContainer.isNothingPlaying()) { - return lastDesync; - } - String[] split = position.split(" "); - double x = 0; - double y = 0; - double z = 0; - double mx = 0; - double my = 0; - double mz = 0; - try { - x = Double.parseDouble(split[0]); - y = Double.parseDouble(split[1]); - z = Double.parseDouble(split[2]); - mx = Double.parseDouble(split[3]); - my = Double.parseDouble(split[4]); - mz = Double.parseDouble(split[5]); - } catch (Exception e) { - return TextFormatting.DARK_PURPLE + "Error"; - } - - boolean isEqual = player.posX == x && player.posY == y && player.posZ == z && player.motionX == mx && player.motionY == my && player.motionZ == mz; - - if (isEqual) { - this.x=""; - this.y=""; - this.z=""; - Mx=""; - My=""; - Mz=""; - lastDesync=TextFormatting.GREEN + "In sync"; - return lastDesync; - } else { - double dx = 0D; - double dy = 0D; - double dz = 0D; - double dMx = 0D; - double dMy = 0D; - double dMz = 0D; - - dx = player.posX - x; - dy = player.posY - y; - dz = player.posZ - z; - - dMx = player.motionX - mx; - dMy = player.motionY - my; - dMz = player.motionZ - mz; - - boolean isWarning = Math.abs(dx) < 0.00001 && Math.abs(dy) < 0.00001 && Math.abs(dz) < 0.00001 && Math.abs(dMx) < 0.00001 && Math.abs(dMy) < 0.00001 && Math.abs(dMz) < 0.00001; - - if (dx != 0D) { - TextFormatting format=desyncColor(dx); - this.x=format+" X: " + dx; - }else { - this.x=""; - } - if (dy != 0D) { - TextFormatting format=desyncColor(dy); - this.y=format+" Y: " + dy; - }else { - this.y=""; - } - if (dz != 0D) { - TextFormatting format=desyncColor(dz); - this.z=format+" Z: " + dz; - }else { - this.z=""; - } - if (dMx != 0D) { - TextFormatting format=desyncColor(dMx); - this.Mx=format+" MotionX: " + dMx; - }else { - this.Mx=""; - } - if (dMy != 0D) { - TextFormatting format=desyncColor(dMy); - this.My=format+" MotionY: " + dMy; - }else { - this.My=""; - } - if (dMz != 0D) { - TextFormatting format=desyncColor(dMz); - this.Mz=format+" MotionZ: " + dMz; - }else { - this.Mz=""; - } - - if (isWarning) { - lastDesync = TextFormatting.YELLOW + "Slight desync "; - return lastDesync; - } - - boolean isModerate = Math.abs(dx) < 0.01 && Math.abs(dy) < 0.01 && Math.abs(dz) < 0.01 && Math.abs(dMx) < 0.01 && Math.abs(dMy) < 0.01 && Math.abs(dMz) < 0.01; - - if (isModerate) { - lastDesync = TextFormatting.RED + "Moderate desync "; - return lastDesync; - } - - lastDesync = TextFormatting.DARK_RED + "Total desync "; - return lastDesync; - } - } - - private TextFormatting desyncColor(double val) { - val=Math.abs(val); - if(val>0&&val<0.00001) { - return TextFormatting.YELLOW; - }else if(val>0.00001&&val<0.01){ - return TextFormatting.RED; - }else { - return TextFormatting.DARK_RED; - } - } - - public String getX() { - return x; - } - - public String getY() { - return y; - } - - public String getZ() { - return z; - } - - public String getMx() { - return Mx; - } - - public String getMy() { - return My; - } - - public String getMz() { - return Mz; - } - - private void clearDelta(){ - x=""; - y=""; - z=""; - Mx=""; - My=""; - Mz=""; - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/client/InputSavestatesPacket.java b/src/main/java/de/scribble/lp/tasmod/savestates/client/InputSavestatesPacket.java deleted file mode 100644 index 8690216a..00000000 --- a/src/main/java/de/scribble/lp/tasmod/savestates/client/InputSavestatesPacket.java +++ /dev/null @@ -1,75 +0,0 @@ -package de.scribble.lp.tasmod.savestates.client; - -import java.io.IOException; -import java.nio.charset.Charset; - -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateException; -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class InputSavestatesPacket implements IMessage{ - private boolean mode; - private String name; - - public InputSavestatesPacket() { - } - /** - * Makes a savestate of the recording on the Client - * @param mode If true: Make a savestate, else load the savestate - * @param name Name of the savestated file - */ - public InputSavestatesPacket(boolean mode,String name) { - this.mode=mode; - this.name=name; - } - - @Override - public void fromBytes(ByteBuf buf) { - int length=buf.readInt(); - name=(String) buf.readCharSequence(length, Charset.defaultCharset()); - mode=buf.readBoolean(); - - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(name.length()); - buf.writeCharSequence(name, Charset.defaultCharset()); - buf.writeBoolean(mode); - } - public String getName() { - return name; - } - - public boolean getMode() { - return mode; - } - - public static class InputSavestatesPacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(InputSavestatesPacket message, MessageContext ctx) { - if (ctx.side.isClient()) { - if (message.getMode() == true) { - try { - InputSavestatesHandler.savestate(message.getName()); - } catch (SavestateException e) { - CommonProxy.logger.error(e.getMessage()); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - try { - InputSavestatesHandler.loadstate(message.getName()); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - return null; - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/LoadstatePacket.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/LoadstatePacket.java deleted file mode 100644 index 0f0b0305..00000000 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/LoadstatePacket.java +++ /dev/null @@ -1,77 +0,0 @@ -package de.scribble.lp.tasmod.savestates.server; - -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.savestates.server.chunkloading.SavestatesChunkControl; -import de.scribble.lp.tasmod.savestates.server.exceptions.LoadstateException; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class LoadstatePacket implements IMessage { - - public int index; - - /** - * Load a savestate at the current index - */ - public LoadstatePacket() { - index = -1; - } - - /** - * Load the savestate at the specified index - * - * @param index The index to load the savestate - */ - public LoadstatePacket(int index) { - this.index = index; - } - - @Override - public void fromBytes(ByteBuf buf) { - index = buf.readInt(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(index); - } - - public static class LoadstatePacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(LoadstatePacket message, MessageContext ctx) { - if (ctx.side.isServer()) { - ctx.getServerHandler().player.getServerWorld().addScheduledTask(() -> { - EntityPlayerMP player = ctx.getServerHandler().player; - if (!player.canUseCommand(2, "tickrate")) { - player.sendMessage(new TextComponentString(TextFormatting.RED + "You don't have permission to do that")); - return; - } - try { - TASmod.savestateHandler.loadState(message.index, true); - } catch (LoadstateException e) { - player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to load a savestate: " + e.getMessage())); - } catch (Exception e) { - player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to load a savestate: " + e.getCause().toString())); - e.printStackTrace(); - } finally { - TASmod.savestateHandler.state = SavestateState.NONE; - } - }); - } else { - Minecraft.getMinecraft().addScheduledTask(() -> { - SavestatesChunkControl.unloadAllClientChunks(); - }); - } - return null; - } - - } - -} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacket.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacket.java deleted file mode 100644 index ee70d459..00000000 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacket.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.scribble.lp.tasmod.savestates.server; - -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.savestates.client.gui.GuiSavestateSavingScreen; -import de.scribble.lp.tasmod.savestates.server.exceptions.SavestateException; -import io.netty.buffer.ByteBuf; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -/** - * Simple networking packet to initiate things on client and server - * - * OnClient: Displays GuiSavestatingScreen.
    If that is already open, closes gui - * OnServer: Initiates savestating - * @author ScribbleLP - * - * @see SavestatePacketHandler - * - */ -public class SavestatePacket implements IMessage{ - - public int index; - - /** - * Make a savestate at the next index - */ - public SavestatePacket() { - index=-1; - } - - /** - * Make a savestate at the specified index - * - * @param index The index where to make a savestate - */ - public SavestatePacket(int index) { - this.index=index; - } - - @Override - public void fromBytes(ByteBuf buf) { - index=buf.readInt(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(index); - } - - public static class SavestatePacketHandler implements IMessageHandler{ - - public SavestatePacketHandler() { - } - - @Override - public IMessage onMessage(SavestatePacket message, MessageContext ctx) { - if(ctx.side.isServer()) { - ctx.getServerHandler().player.getServerWorld().addScheduledTask(()->{ - EntityPlayerMP player=ctx.getServerHandler().player; - if (!player.canUseCommand(2, "savestate")) { - player.sendMessage(new TextComponentString(TextFormatting.RED+"You don't have permission to do that")); - return; - } - try { - TASmod.savestateHandler.saveState(message.index, true); - } catch (SavestateException e) { - player.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to create a savestate: "+ e.getMessage())); - - } catch (Exception e) { - e.printStackTrace(); - player.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to create a savestate: "+ e.getCause().toString())); - } finally { - TASmod.savestateHandler.state=SavestateState.NONE; - } - }); - }else { - net.minecraft.client.Minecraft mc=net.minecraft.client.Minecraft.getMinecraft(); //Forge will think this is executed on the server for some reason... - workaround(mc); - } - return null; - } - - @SideOnly(Side.CLIENT) - private void workaround(net.minecraft.client.Minecraft mc) { - if(!(mc.currentScreen instanceof GuiSavestateSavingScreen)) { - mc.displayGuiScreen(new GuiSavestateSavingScreen()); - }else { - mc.displayGuiScreen(null); - } - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/motion/MotionPacket.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/motion/MotionPacket.java deleted file mode 100644 index a3476895..00000000 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/motion/MotionPacket.java +++ /dev/null @@ -1,100 +0,0 @@ -package de.scribble.lp.tasmod.savestates.server.motion; - -import de.scribble.lp.tasmod.savestates.server.motion.ClientMotionServer.Saver; -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class MotionPacket implements IMessage { - private double x = 0; - private double y = 0; - private double z = 0; - private float rx = 0; - private float ry = 0; - private float rz = 0; - private boolean sprinting; - private float jumpMovementVector = 0.2F; - - public MotionPacket() { - } - - public MotionPacket(double x, double y, double z, float moveForward, float moveVertical, float moveStrafe, boolean isSprinting, float jumpMovementVector) { - this.x = x; - this.y = y; - this.z = z; - this.rx = moveForward; - this.ry = moveVertical; - this.rz = moveStrafe; - sprinting = isSprinting; - this.jumpMovementVector = jumpMovementVector; - } - - @Override - public void fromBytes(ByteBuf buf) { - x = buf.readDouble(); - y = buf.readDouble(); - z = buf.readDouble(); - rx = buf.readFloat(); - ry = buf.readFloat(); - rz = buf.readFloat(); - sprinting = buf.readBoolean(); - jumpMovementVector = buf.readFloat(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeDouble(x); - buf.writeDouble(y); - buf.writeDouble(z); - buf.writeFloat(rx); - buf.writeFloat(ry); - buf.writeFloat(rz); - buf.writeBoolean(sprinting); - buf.writeFloat(jumpMovementVector); - } - - public double getX() { - return x; - } - - public double getY() { - return y; - } - - public double getZ() { - return z; - } - - public float getRx() { - return rx; - } - - public float getRy() { - return ry; - } - - public float getRz() { - return rz; - } - - public boolean isSprinting() { - return sprinting; - } - - public float getJumpMovementVector() { - return jumpMovementVector; - } - - public static class MotionPacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(MotionPacket message, MessageContext ctx) { - if (ctx.side.isServer()) { - ClientMotionServer.getMotion().put(ctx.getServerHandler().player, new Saver(message.getX(), message.getY(), message.getZ(), message.getRx(), message.getRy(), message.getRz(), message.isSprinting(), message.getJumpMovementVector())); - } - return null; - } - - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/motion/RequestMotionPacket.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/motion/RequestMotionPacket.java deleted file mode 100644 index fea96a53..00000000 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/motion/RequestMotionPacket.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.scribble.lp.tasmod.savestates.server.motion; - -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.savestates.client.gui.GuiSavestateSavingScreen; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class RequestMotionPacket implements IMessage { - - @Override - public void fromBytes(ByteBuf buf) { - - } - - @Override - public void toBytes(ByteBuf buf) { - - } - - public static class RequestMotionPacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(RequestMotionPacket message, MessageContext ctx) { - if (ctx.side.isClient()) { - workaround(); - } - return null; - } - - @SideOnly(Side.CLIENT) - // For some reason the packet still tries to execute this on the server even tho ctx.side = CLIENT - private void workaround() { - EntityPlayerSP player = Minecraft.getMinecraft().player; - if (player != null) { - if (!(Minecraft.getMinecraft().currentScreen instanceof GuiSavestateSavingScreen)) { - Minecraft.getMinecraft().displayGuiScreen(new GuiSavestateSavingScreen()); - } - CommonProxy.NETWORK.sendToServer(new MotionPacket(player.motionX, player.motionY, player.motionZ, player.moveForward, player.moveVertical, player.moveStrafing, player.isSprinting(), player.jumpMovementFactor)); - } - } - } - -} diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/AdvanceTickratePacket.java b/src/main/java/de/scribble/lp/tasmod/tickratechanger/AdvanceTickratePacket.java deleted file mode 100644 index a991c4db..00000000 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/AdvanceTickratePacket.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.scribble.lp.tasmod.tickratechanger; - -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; - -/** - * Advanced game by 1 tick - * - * @author ScribbleLP - * - */ -public class AdvanceTickratePacket implements IMessage { - /** - * Advanced game by 1 tick - */ - public AdvanceTickratePacket() { - } - - @Override - public void fromBytes(ByteBuf buf) { - - } - - @Override - public void toBytes(ByteBuf buf) { - - } - - public static class AdvanceTickratePacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(AdvanceTickratePacket message, MessageContext ctx) { - if (ctx.side == Side.SERVER) { - if (ctx.getServerHandler().player.canUseCommand(2, "tickrate")) { - if (TickrateChangerServer.ticksPerSecond == 0) { - TickrateChangerServer.advanceTick(); - } - } - } else { - TickrateChangerClient.advanceClientTick(); // Using advanceTick() would create an endless loop - } - return null; - } - - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/ChangeTickratePacket.java b/src/main/java/de/scribble/lp/tasmod/tickratechanger/ChangeTickratePacket.java deleted file mode 100644 index 91fdaea5..00000000 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/ChangeTickratePacket.java +++ /dev/null @@ -1,61 +0,0 @@ -package de.scribble.lp.tasmod.tickratechanger; - -import io.netty.buffer.ByteBuf; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; - -/** - * Changes the tickrate on the other side - * - * @author ScribbleLP - * - */ -public class ChangeTickratePacket implements IMessage { - - float tickrate; - - public ChangeTickratePacket() { - } - - /** - * Changes the tickrate on the other side - * - * @param tickrate The new tickrate - */ - public ChangeTickratePacket(float tickrate) { - this.tickrate = tickrate; - } - - @Override - public void fromBytes(ByteBuf buf) { - tickrate = buf.readFloat(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeFloat(tickrate); - } - - public static class ChangeTickratePacketHandler implements IMessageHandler { - - public ChangeTickratePacketHandler() { - } - - @Override - public IMessage onMessage(ChangeTickratePacket message, MessageContext ctx) { - if (ctx.side == Side.SERVER) { - EntityPlayerMP player = ctx.getServerHandler().player; - if (player.canUseCommand(2, "tickrate")) { - TickrateChangerServer.changeTickrate(message.tickrate); - } - } else if (ctx.side == Side.CLIENT) { - TickrateChangerClient.changeClientTickrate(message.tickrate); - } - return null; - } - } - -} diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/PauseTickratePacket.java b/src/main/java/de/scribble/lp/tasmod/tickratechanger/PauseTickratePacket.java deleted file mode 100644 index de510676..00000000 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/PauseTickratePacket.java +++ /dev/null @@ -1,118 +0,0 @@ -package de.scribble.lp.tasmod.tickratechanger; - -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -/** - * Sets the game to tickrate 0 and back - * - * @author ScribbleLP - * - */ -public class PauseTickratePacket implements IMessage { - - private short status; - - /** - * Toggles the tickrate between 0 and tickrate > 0 - */ - public PauseTickratePacket() { - status = 0; - } - - /** - * Changes the state to either PAUSE UNPAUSE or TOGGLED - * - * @param state The state - */ - public PauseTickratePacket(State state) { - this.status = state.toShort(); - } - - @Override - public void fromBytes(ByteBuf buf) { - status = buf.readShort(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeShort(status); - } - - public State getState() { - return State.fromShort(status); - } - - public static class PauseTickratePacketHandler implements IMessageHandler { - - public PauseTickratePacketHandler() { - } - - @Override - public IMessage onMessage(PauseTickratePacket message, MessageContext ctx) { - if (ctx.side.isServer()) { - if (ctx.getServerHandler().player.canUseCommand(2, "tickrate")) { - if (message.getState() == State.PAUSE) - TickrateChangerServer.pauseGame(true); - else if (message.getState() == State.UNPAUSE) - TickrateChangerServer.pauseGame(false); - else if (message.getState() == State.TOGGLE) - TickrateChangerServer.togglePause(); - } - } else if (ctx.side.isClient()) { - if (message.getState() == State.PAUSE) - TickrateChangerClient.pauseClientGame(true); - else if (message.getState() == State.UNPAUSE) - TickrateChangerClient.pauseClientGame(false); - else if (message.getState() == State.TOGGLE) - TickrateChangerClient.togglePauseClient(); - } - return null; - } - - } - - /** - * Can be {@link State#PAUSE}, {@link State#UNPAUSE} or {@link State#TOGGLE} - * - * @author ScribbleLP - * - */ - public enum State { - /** - * Set's the game to tickrate 0 - */ - PAUSE((short) 1), - /** - * Set's the game to "tickrate saved" - */ - UNPAUSE((short) 2), - /** - * Toggles between {@link #PAUSE} and {@link #UNPAUSE} - */ - TOGGLE((short) 0); - - private short id; - - State(short i) { - id = i; - } - - public short toShort() { - return id; - } - - public static State fromShort(short i) { - switch (i) { - case 1: - return PAUSE; - case 2: - return UNPAUSE; - default: - return TOGGLE; - } - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/ticksync/TickSync.java b/src/main/java/de/scribble/lp/tasmod/ticksync/TickSync.java deleted file mode 100644 index b1e200c3..00000000 --- a/src/main/java/de/scribble/lp/tasmod/ticksync/TickSync.java +++ /dev/null @@ -1,105 +0,0 @@ -package de.scribble.lp.tasmod.ticksync; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.gui.GuiMultiplayerTimeOut; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.WorldClient; - -/** - * Makes tickrate only dependent on the server, e.g. when the server lags, the - * client lags too - * - * @author ScribbleLP - * - */ -public class TickSync { - private static int servertickcounter; - private static int clienttickcounter; - private static boolean enabled = true; - private static int softLockTimer; - - public static boolean isLagging; - - /** - * Turns the ticksync on and off - * - * @param enable - */ - public static void sync(boolean enable) { - enabled = enable; - } - - /** - * If ticksync is enabled - * - * @return enabled - */ - public static boolean isEnabled() { - return enabled; - } - - /** - * The tick counter of the server - * - * @return - */ - public static int getServertickcounter() { - return servertickcounter; - } - - /** - * The tick counter of the client - * - * @return - */ - public static int getClienttickcounter() { - return clienttickcounter; - } - - /** - * Increment tickcounter and reset softlock timer, called in runTick - */ - public static void incrementClienttickcounter() { - softLockTimer = 0; - clienttickcounter++; - } - - /** - * Setting the tickcounter of the server coming from the TicksyncPacketHandler - * - * @param counter - */ - public static void setServerTickcounter(int counter) { - servertickcounter = counter; - } - - /** - * Reset the tick counter on server start - */ - public static void resetTickCounter() { - clienttickcounter = 0; - servertickcounter = 0; - } - - public static int getTickAmount(Minecraft mc) { - if (mc.world != null) { - int ticking = servertickcounter - clienttickcounter; - TickSync.isLagging = false; - if (ticking < 0) { - TickSync.isLagging = true; - if (!ClientProxy.isDevEnvironment) { // For the Dev environment to stop a disconnect when debugging on the server side - softLockTimer++; - } - if (softLockTimer == 100) { - mc.world.sendQuittingDisconnectingPacket(); - mc.loadWorld((WorldClient) null); - mc.displayGuiScreen(new GuiMultiplayerTimeOut()); - } - } - return Math.max(ticking + 1, 0); - } else { - return 1; - } - } - -} diff --git a/src/main/java/de/scribble/lp/tasmod/ticksync/TickSyncPackage.java b/src/main/java/de/scribble/lp/tasmod/ticksync/TickSyncPackage.java deleted file mode 100644 index a940af57..00000000 --- a/src/main/java/de/scribble/lp/tasmod/ticksync/TickSyncPackage.java +++ /dev/null @@ -1,73 +0,0 @@ -package de.scribble.lp.tasmod.ticksync; - -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; - -public class TickSyncPackage implements IMessage { - private int ticks; - private boolean shouldreset; - private boolean shouldstop; - - public TickSyncPackage() { - ticks = 0; - shouldreset = false; - shouldstop = false; - } - - public TickSyncPackage(int ticks, boolean reset, boolean stop) { - this.ticks = ticks; - this.shouldreset = reset; - this.shouldstop = stop; - } - - @Override - public void fromBytes(ByteBuf buf) { - this.ticks = buf.readInt(); - this.shouldreset = buf.readBoolean(); - this.shouldstop = buf.readBoolean(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeInt(ticks); - buf.writeBoolean(shouldreset); - buf.writeBoolean(shouldstop); - } - - public int getTicks() { - return ticks; - } - - public boolean isShouldreset() { - return shouldreset; - } - - public boolean isShouldstop() { - return shouldstop; - } - - public static class TickSyncPacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(TickSyncPackage message, MessageContext ctx) { - if (ctx.side == Side.CLIENT) { - Minecraft.getMinecraft().addScheduledTask(() -> { - if (message.isShouldreset()) { - TickSync.resetTickCounter(); - } else { - TickSync.setServerTickcounter(message.getTicks()); - } - - if (TickSync.isEnabled() != message.isShouldstop()) { - TickSync.sync(message.isShouldstop()); - } - }); - } - return null; - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/ticksync/TickSyncServer.java b/src/main/java/de/scribble/lp/tasmod/ticksync/TickSyncServer.java deleted file mode 100644 index f18d163f..00000000 --- a/src/main/java/de/scribble/lp/tasmod/ticksync/TickSyncServer.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.scribble.lp.tasmod.ticksync; - -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.mixin.accessors.AccessorMinecraftServer; -import net.minecraft.entity.player.EntityPlayerMP; - -public class TickSyncServer { - private static int serverticksync = 0; - private static boolean enabled = true; - - public static void sync(boolean enable) { - enabled = enable; - } - - public static void incrementServerTickCounter() { - serverticksync++; - } - - public static void resetTickCounter() { - ((AccessorMinecraftServer) TASmod.getServerInstance().getServer()).tickCounter(0); - serverticksync = 0; - } - - public static int getServertickcounter() { - return serverticksync; - } - - public static boolean isEnabled() { - return enabled; - } - - public static void joinServer(EntityPlayerMP player) { - TickSyncServer.resetTickCounter(); - CommonProxy.NETWORK.sendToAll(new TickSyncPackage(TickSyncServer.getServertickcounter(), true, TickSyncServer.isEnabled())); - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/util/TASstate.java b/src/main/java/de/scribble/lp/tasmod/util/TASstate.java deleted file mode 100644 index c0272abd..00000000 --- a/src/main/java/de/scribble/lp/tasmod/util/TASstate.java +++ /dev/null @@ -1,73 +0,0 @@ -package de.scribble.lp.tasmod.util; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; -import de.scribble.lp.tasmod.inputcontainer.InputContainer; -import de.scribble.lp.tasmod.util.changestates.SyncStatePacket; -import net.minecraft.client.Minecraft; - -/** - * State of the input recorder - * @author ScribbleLP - * - */ -public enum TASstate { - /** - * The game records inputs to the {@link InputContainer}. - */ - RECORDING, - /** - * The game plays back the inputs loaded in {@link InputContainer} and locks user interaction. - */ - PLAYBACK, - /** - * The playback or recording is paused and may be resumed. Note that the game isn't paused, only the playback. Useful for debugging things. - */ - PAUSED, // #124 - /** - * The game is neither recording, playing back or paused, is also set when aborting all mentioned states. - */ - NONE; - - /** - * Requests a state change to the server. If no server is available (e.g. in the main menu), it will set the state directly. - * @param state The new state of the playback. - */ - public static void setOrSend(TASstate state) { - if(Minecraft.getMinecraft().player!=null) { - CommonProxy.NETWORK.sendToServer(new SyncStatePacket(state)); - }else { - ClientProxy.virtual.getContainer().setTASState(state); - } - } - - public int getIndex() { - switch(this) { - case NONE: - return 0; - case PLAYBACK: - return 1; - case RECORDING: - return 2; - case PAUSED: - return 3; - default: - return 0; - } - } - - public static TASstate fromIndex(int state) { - switch (state) { - case 0: - return NONE; - case 1: - return PLAYBACK; - case 2: - return RECORDING; - case 3: - return PAUSED; - default: - return NONE; - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/util/changestates/RequestStatePacket.java b/src/main/java/de/scribble/lp/tasmod/util/changestates/RequestStatePacket.java deleted file mode 100644 index c5a4a4b1..00000000 --- a/src/main/java/de/scribble/lp/tasmod/util/changestates/RequestStatePacket.java +++ /dev/null @@ -1,38 +0,0 @@ -package de.scribble.lp.tasmod.util.changestates; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.CommonProxy; -import io.netty.buffer.ByteBuf; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -public class RequestStatePacket implements IMessage { - - public RequestStatePacket() { - - } - - @Override - public void fromBytes(ByteBuf buf) { - - } - - @Override - public void toBytes(ByteBuf buf) { - - } - - public static class RequestStatePacketHandler implements IMessageHandler{ - - @Override - public IMessage onMessage(RequestStatePacket message, MessageContext ctx) { - if(ctx.side.isClient()) { - CommonProxy.NETWORK.sendToServer(new SyncStatePacket(ClientProxy.virtual.getContainer().getState(), false)); - } - return null; - } - - } - -} diff --git a/src/main/java/de/scribble/lp/tasmod/util/changestates/SyncStatePacket.java b/src/main/java/de/scribble/lp/tasmod/util/changestates/SyncStatePacket.java deleted file mode 100644 index ea72eb2a..00000000 --- a/src/main/java/de/scribble/lp/tasmod/util/changestates/SyncStatePacket.java +++ /dev/null @@ -1,79 +0,0 @@ -package de.scribble.lp.tasmod.util.changestates; - -import de.scribble.lp.tasmod.ClientProxy; -import de.scribble.lp.tasmod.TASmod; -import de.scribble.lp.tasmod.inputcontainer.InputContainer; -import de.scribble.lp.tasmod.util.TASstate; -import io.netty.buffer.ByteBuf; -import net.minecraft.client.Minecraft; -import net.minecraft.util.text.TextComponentString; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; - -/** - * Syncs the current state of the input recorder with the state on the server side and witht the state on all other clients - * - * @author ScribbleLP - * - */ -public class SyncStatePacket implements IMessage { - - private short state; - private boolean verbose; - - public SyncStatePacket() { - state = 0; - } - - public SyncStatePacket(TASstate state) { - verbose = true; - this.state = (short) state.getIndex(); - } - - public SyncStatePacket(TASstate state, boolean verbose) { - this.verbose = verbose; - this.state = (short) state.getIndex(); - } - - @Override - public void fromBytes(ByteBuf buf) { - state = buf.readShort(); - verbose = buf.readBoolean(); - } - - @Override - public void toBytes(ByteBuf buf) { - buf.writeShort(state); - buf.writeBoolean(verbose); - } - - public TASstate getState() { - return TASstate.fromIndex(state); - } - - public boolean isVerbose() { - return verbose; - } - - public static class SyncStatePacketHandler implements IMessageHandler { - - @Override - public IMessage onMessage(SyncStatePacket message, MessageContext ctx) { - if (ctx.side.isServer()) { - TASmod.containerStateServer.setState(message.getState()); - } else { - InputContainer container = ClientProxy.virtual.getContainer(); - if (message.getState() != container.getState()) { - String chatMessage = container.setTASState(message.getState(), message.isVerbose()); - if (!chatMessage.isEmpty()) { - Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(chatMessage)); - } - } - } - return null; - } - - } - -} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 9b24e6ae..ecc50bb3 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -5,7 +5,7 @@ "description": "Saves tickperfect inputs to a file and is able to play it back", "version": "${version}", "mcversion": "${mcversion}", - "url": "https://www.curseforge.com/minecraft/mc-mods/tasmod", + "url": "https://minecrafttas.com", "updateUrl": "", "authorList": ["\u00A7btr7zw, Scribble, famous1622, Pancake\u00A7r"], "credits": "\n\nAuthor of the initial mod: \u00A76tr7zw\u00A7r\nMain mod author: \u00A76Scribble\u00A7r\nContributions by \u00A76famous, Pancake\u00A7r\n\nTickrate Code inspired by \u00A76Guichaguri\u00A7r\nTickrate 0 Code inspired by \u00A76Cubitect\u00A7r\n\nSpecial thanks to \u00A76Darkmoon, The Minecraft TAS Community\u00A7r\n", diff --git a/src/main/resources/mixins.tasmod.json b/src/main/resources/mixins.tasmod.json index d03109f0..d84e75ed 100644 --- a/src/main/resources/mixins.tasmod.json +++ b/src/main/resources/mixins.tasmod.json @@ -1,7 +1,7 @@ { "required": true, "minVersion": "0.7.10", - "package": "de.scribble.lp.tasmod.mixin", + "package": "com.minecrafttas.tasmod.mixin", "refmap": "mixins.tasmod.refmap.json", "compatibilityLevel": "JAVA_8", "mixins": [ @@ -13,6 +13,7 @@ //Savestates "savestates.MixinChunkProviderServer", "savestates.MixinEntityPlayerMP", + "savestates.MixinNetHandlerPlayServer", //Events "events.MixinPlayerList", @@ -33,6 +34,7 @@ "client": [ //General "MixinMinecraft", + "MixinTimer", "MixinEntityRenderer", "MixinGuiScreen", "MixinInGameHud",