diff --git a/build.gradle b/build.gradle index 320b0770..c145ea28 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ 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 = "Alpha1" +version = "Alpha2" group = "de.scribble.lp.tastools" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TASmod-1.12.2" diff --git a/src/main/java/de/scribble/lp/tasmod/ClientProxy.java b/src/main/java/de/scribble/lp/tasmod/ClientProxy.java index 91e60314..5cede501 100644 --- a/src/main/java/de/scribble/lp/tasmod/ClientProxy.java +++ b/src/main/java/de/scribble/lp/tasmod/ClientProxy.java @@ -1,20 +1,34 @@ package de.scribble.lp.tasmod; +import de.scribble.lp.tasmod.tutorial.TutorialHandler; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.Configuration; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; public class ClientProxy extends CommonProxy{ + public static Configuration config; + + static TutorialHandler playbackTutorial; + public void preInit(FMLPreInitializationEvent ev) { + config = new Configuration(ev.getSuggestedConfigurationFile()); + Config.reloadClientConfig(config); super.preInit(ev); } public void init(FMLInitializationEvent ev) { + playbackTutorial=new TutorialHandler((short)1); MinecraftForge.EVENT_BUS.register(new InfoGui()); + MinecraftForge.EVENT_BUS.register(playbackTutorial); + super.init(ev); } public void postInit(FMLPostInitializationEvent ev) { super.postInit(ev); } + public static TutorialHandler getPlaybackTutorial() { + return playbackTutorial; + } } diff --git a/src/main/java/de/scribble/lp/tasmod/Config.java b/src/main/java/de/scribble/lp/tasmod/Config.java new file mode 100644 index 00000000..b8b48d64 --- /dev/null +++ b/src/main/java/de/scribble/lp/tasmod/Config.java @@ -0,0 +1,15 @@ +package de.scribble.lp.tasmod; + +import de.scribble.lp.tasmod.tutorial.TutorialHandler; +import net.minecraftforge.common.config.Configuration; + +public class Config { + public static void reloadServerConfig(Configuration serverconfig) { + + } + public static void reloadClientConfig(Configuration clientconfig) { + clientconfig.load(); + TutorialHandler.istutorial=clientconfig.get("Tutorial","Enabled",true,"If the tutorial is enabled").getBoolean(); + clientconfig.save(); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/ModLoader.java b/src/main/java/de/scribble/lp/tasmod/ModLoader.java index 48fb62ef..ee6c6750 100644 --- a/src/main/java/de/scribble/lp/tasmod/ModLoader.java +++ b/src/main/java/de/scribble/lp/tasmod/ModLoader.java @@ -7,6 +7,7 @@ import de.scribble.lp.tasmod.recording.CommandRecord; import de.scribble.lp.tasmod.tickratechanger.CommandTickrate; import de.scribble.lp.tasmod.ticksync.CommandTickSync; +import de.scribble.lp.tasmod.tutorial.CommandPlaybacktutorial; import net.minecraft.server.MinecraftServer; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; @@ -60,6 +61,7 @@ public void serverStart(FMLServerStartingEvent ev) { ev.registerServerCommand(new CommandTickSync()); ev.registerServerCommand(new CommandRecord()); ev.registerServerCommand(new CommandPlay()); + ev.registerServerCommand(new CommandPlaybacktutorial()); } public static ModLoader getInstance() { return instance; diff --git a/src/main/java/de/scribble/lp/tasmod/playback/InputPlayback.java b/src/main/java/de/scribble/lp/tasmod/playback/InputPlayback.java index 0c3fe14c..7ee66099 100644 --- a/src/main/java/de/scribble/lp/tasmod/playback/InputPlayback.java +++ b/src/main/java/de/scribble/lp/tasmod/playback/InputPlayback.java @@ -10,6 +10,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import de.scribble.lp.tasmod.ClientProxy; +import de.scribble.lp.tasmod.tutorial.TutorialHandler; import de.scribble.lp.tasmod.virtual.VirtualKeyboardEvent; import de.scribble.lp.tasmod.virtual.VirtualMouseAndKeyboard; import de.scribble.lp.tasmod.virtual.VirtualMouseEvent; @@ -48,6 +50,10 @@ public static void startPlayback(File file, String filename) { playingback=true; playbackIndex=-1; subtickPlaybackindex=-1; + TutorialHandler tutorial= ClientProxy.getPlaybackTutorial(); + if(tutorial.istutorial&&tutorial.getState()==6) { + tutorial.advanceState(); + } // Minecraft.getMinecraft().randommanager.setEntityRandomnessAll(0); // RandomLogger.startRandomLogging(); }else { @@ -56,6 +62,10 @@ public static void startPlayback(File file, String filename) { } public static void stopPlayback() { if(isPlayingback()) { + TutorialHandler tutorial= ClientProxy.getPlaybackTutorial(); + if(tutorial.istutorial&&tutorial.getState()==7) { + tutorial.advanceState(); + } playingback=false; inputList=new ArrayList(); subtickList=new ArrayList(); diff --git a/src/main/java/de/scribble/lp/tasmod/recording/InputRecorder.java b/src/main/java/de/scribble/lp/tasmod/recording/InputRecorder.java index 5e691913..757dbba3 100644 --- a/src/main/java/de/scribble/lp/tasmod/recording/InputRecorder.java +++ b/src/main/java/de/scribble/lp/tasmod/recording/InputRecorder.java @@ -8,6 +8,8 @@ import org.apache.logging.log4j.Logger; import org.lwjgl.input.Keyboard; +import de.scribble.lp.tasmod.ClientProxy; +import de.scribble.lp.tasmod.tutorial.TutorialHandler; import de.scribble.lp.tasmod.virtual.VirtualKeyboardEvent; import de.scribble.lp.tasmod.virtual.VirtualMouseAndKeyboard; import de.scribble.lp.tasmod.virtual.VirtualMouseEvent; @@ -59,6 +61,10 @@ public static void startRecording(String filename) { // Minecraft.getMinecraft().randommanager.setEntityRandomnessAll(0); // RandomLogger.startRandomLogging(); // new SavestateHandlerClient().saveState(); + TutorialHandler tutorial= ClientProxy.getPlaybackTutorial(); + if(tutorial.istutorial&&tutorial.getState()==3) { + tutorial.advanceState(); + } }else { logger.error("There is already a recording running!"); } @@ -195,6 +201,10 @@ public static void stopRecording() { recording=false; Thread t = new Thread(new FileWriterThread(output, fileLocation, logger), "FileWriterThreadTicks"); t.start(); + TutorialHandler tutorial= ClientProxy.getPlaybackTutorial(); + if(tutorial.istutorial&&tutorial.getState()==4) { + tutorial.advanceState(); + } // Thread t2 = new Thread(new FileWriterThread(outputSubtick, fileLocationSubTick, logger), "FileWriterThreadSubtick"); // t2.start(); // RandomLogger.stopRandomLogging(); diff --git a/src/main/java/de/scribble/lp/tasmod/tutorial/CommandPlaybacktutorial.java b/src/main/java/de/scribble/lp/tasmod/tutorial/CommandPlaybacktutorial.java new file mode 100644 index 00000000..d9d02ab5 --- /dev/null +++ b/src/main/java/de/scribble/lp/tasmod/tutorial/CommandPlaybacktutorial.java @@ -0,0 +1,38 @@ +package de.scribble.lp.tasmod.tutorial; + +import de.scribble.lp.tasmod.ClientProxy; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.server.MinecraftServer; + +public class CommandPlaybacktutorial extends CommandBase{ + + @Override + public String getName() { + return "playbacktutorial"; + } + + @Override + public String getUsage(ICommandSender sender) { + return "/playbacktutorial"; + } + + @Override + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + if(sender instanceof EntityPlayer) { + if(!server.isDedicatedServer()) { + TutorialHandler handler=ClientProxy.getPlaybackTutorial(); + if(handler.istutorial) { + handler.istutorial=false; + ClientProxy.config.get("Tutorial","Enabled",true,"If the tutorial is enabled").set(false); + ClientProxy.config.save(); + }else { + handler.setState((short)1); + handler.istutorial=true; + } + } + } + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/tutorial/TutorialHandler.java b/src/main/java/de/scribble/lp/tasmod/tutorial/TutorialHandler.java new file mode 100644 index 00000000..63dda10d --- /dev/null +++ b/src/main/java/de/scribble/lp/tasmod/tutorial/TutorialHandler.java @@ -0,0 +1,239 @@ +package de.scribble.lp.tasmod.tutorial; + +import org.lwjgl.input.Keyboard; + +import de.scribble.lp.tasmod.ClientProxy; +import de.scribble.lp.tasmod.Config; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class TutorialHandler { + + public static boolean istutorial; + + private int state; + + private int cooldowntime=60; + + private int cooldown=cooldowntime; + + + public TutorialHandler() { + } + public TutorialHandler(int state) { + this.state=state; + } + public void setState(int state) { + cooldown=cooldowntime; + this.state = state; + } + public int getState() { + return state; + } + public String[] getTutorialText() { + String[] textout; + switch (state) { + case 1: + textout=text1; + break; + case 2: + textout=text2; + break; + case 3: + textout=text3; + break; + case 4: + textout=text4; + break; + case 5: + textout=text5; + break; + case 6: + textout=text6; + break; + case 7: + textout=text7; + break; + case 8: + textout=text8; + break; + case 9: + textout=text9; + break; + case 10: + textout=text10; + break; + case 11: + textout=text11; + break; + case 12: + textout=text12; + break; + default: + textout=new String[]{""}; + break; + } + return textout; + } + private void checkForKeys() { + switch (state) { + case 0: + break; + case 1: + case 2: + case 5: + case 8: + case 11: + + if(Keyboard.isKeyDown(Keyboard.KEY_RETURN)&&cooldown==0) { + advanceState(); + } + break; + case 9: + if(Keyboard.isKeyDown(Keyboard.KEY_F8)&&cooldown==0) { + advanceState(); + } + break; + case 10: + if(Keyboard.isKeyDown(Keyboard.KEY_F9)&&cooldown==0) { + advanceState(); + } + break; + case 12: + if(Keyboard.isKeyDown(Keyboard.KEY_RETURN)&&cooldown==0) { + istutorial=false; + ClientProxy.config.get("Tutorial","Enabled",true,"If the tutorial is enabled").set(false); + ClientProxy.config.save(); + } + break; + } + } + public void advanceState() { + cooldown=cooldowntime; + state++; + } + Minecraft mc= Minecraft.getMinecraft(); + @SubscribeEvent + public void drawStuff(RenderGameOverlayEvent.Post event) { + if (istutorial) { + if (event.isCancelable() || event.getType() != ElementType.HOTBAR) { + return; + } + checkForKeys(); + ScaledResolution scaled = new ScaledResolution(mc); + int width = scaled.getScaledWidth(); + int height = scaled.getScaledHeight(); + String[] text = getTutorialText(); + for (int i = 0; i < text.length; i++) { + String tex = text[i]; + new Gui().drawString(mc.fontRenderer, tex, width - mc.fontRenderer.getStringWidth(tex) - 10, + 10 + 10 * i, 0xFFFFFF); + } + + if (cooldown != 0) { + cooldown--; + } + } + } + private final String[] text1={"1. Hi, welcome to this InTeRaCtIvE tutorial on how to use this mod.", + "", + "If you have already enough of this text,", + "then type in '/playbacktutorial' to turn this off.", + "", + "If you change your mind after that", + "then you can also enable it with '/playbacktutorial' again", + "", + "If you wish to know more,", + "then continue by pressing RETURN on your keyboard"}; + + private final String[] text2={"2. If you move your mouse you may realise that it feels very laggy.", + "", + "This is intentional so don't tell me the mod is bugged.", + "The mod forces the camera to stay at 20fps/20ticks to ensure playback.", + "", + "Also when loading new chunks you may experience 'lagspikes of death'... Thats intentional too...", + "I've made it so if the server lags, the client lags too...", + "", + "Press RETURN to continue"}; + + private final String[] text3= {"3. This mod can record your inputs and save them to a file.", + "To start a recording type in '/record' and then followed by a filename", + "", + "Objective: Open the chat and type '/record tas'"}; + + private final String[] text4={"4. Now move around open your inventory etc...", + "", + "To stop this, type in the same command again.", + "So open chat, press the up arrow and hit RETURN", + "", + "Objective: Type in '/record' again to stop the recording"}; + + private final String[] text5={"5. Nice! Well, I can't really see what you have done but ok...", + "", + "You can also record stuff using the alias '/r' and if you don't enter a filename,", + "a random filename will be generated.", + "", + "If you are not happy with your recording, then record with the same filename", + "and it will overwrite the previous file", + "", + "Press RETURN to continue"}; + + private final String[] text6={"6. You might have guessed it already,", + " but now you can play back that recording.", + "", + "Use either '/play' or '/p' plus the filename you entered in /record", + "to start playing back the file.", + "", + "When pressing TAB after '/play ' it will autocomplete the filenames you recorded", + "", + "Objective: Type in '/play tas' (Or the filename you typed earlier)"}; + + private final String[] text7={"7. Now sit back and relax, as the mod plays Minecraft for you!"}; + + private final String[] text8={"8. Here you go, the playback is finished!", + "", + "You can abort the playback with typing /play during a playback", + "", + "Press RETURN to continue"}; + + private final String[] text9={"9. Let's do something fun! Press F8!", + "", + "Objective: Press F8"}; + + private final String[] text10={"10. Haha, you are softlocked now xDxDxD", + "", + "Well not actually... This is the wonderous state of tickrate 0.", + "The game is paused but you can still move your camera.", + "", + "Now, while still in tickrate 0, press F9 to advance one tick!", + "", + "<---You can see the tick counter over there", + "", + "Objective: Press F9"}; + + private final String[] text11= {"11. Now hold W and advance a few ticks.", + "You will see that you start walking", + "", + "Mouse buttons are buffered in mc, so if you press and release leftclick once", + "after advancing it will execute.", + "", + "Im sure you want to play around with this so enjoy :D", + "", + "Press RETURN to continue"}; + + private final String[] text12= {"12. To get out of this state you can press F8 again.", + "", + "Well I am kinda done for the moment... Hope this helped a bit", + "", + "If you have more questions ask them in the discord.", + "", + "Ah, before I forget, if you want to translate these lines into a different language hit me up!", + "", + "Press RETURN to close the tutorial"}; + +}