From c9a30012c835169334448a1ccfd29b7feb1e6069 Mon Sep 17 00:00:00 2001 From: CreativeMD Date: Mon, 5 Feb 2018 17:45:46 +0100 Subject: [PATCH] Added ability to save/ load paths during runtime (will be deleted after restart) Fixed being unable to remove points --- .../java/com/creativemd/cmdcam/CMDCam.java | 4 ++ .../creativemd/cmdcam/command/CamCommand.java | 37 +++++++++++++++++- .../cmdcam/movement/OutsidePath.java | 1 + .../com/creativemd/cmdcam/utils/CMDPath.java | 38 +++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/creativemd/cmdcam/utils/CMDPath.java diff --git a/src/main/java/com/creativemd/cmdcam/CMDCam.java b/src/main/java/com/creativemd/cmdcam/CMDCam.java index a9781af..6d7e077 100644 --- a/src/main/java/com/creativemd/cmdcam/CMDCam.java +++ b/src/main/java/com/creativemd/cmdcam/CMDCam.java @@ -1,12 +1,14 @@ package com.creativemd.cmdcam; import java.util.ArrayList; +import java.util.HashMap; import com.creativemd.cmdcam.command.CamCommand; import com.creativemd.cmdcam.key.KeyHandler; import com.creativemd.cmdcam.movement.Movement; import com.creativemd.cmdcam.movement.Movement.MovementParseException; import com.creativemd.cmdcam.movement.Path; +import com.creativemd.cmdcam.utils.CMDPath; import com.creativemd.cmdcam.utils.CamPoint; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -44,6 +46,8 @@ public class CMDCam { public static double cameraFollowSpeed = 1D; + public static HashMap savedPaths = new HashMap<>(); + @EventHandler public void Init(FMLInitializationEvent event) { diff --git a/src/main/java/com/creativemd/cmdcam/command/CamCommand.java b/src/main/java/com/creativemd/cmdcam/command/CamCommand.java index c33809c..4037a55 100644 --- a/src/main/java/com/creativemd/cmdcam/command/CamCommand.java +++ b/src/main/java/com/creativemd/cmdcam/command/CamCommand.java @@ -3,6 +3,7 @@ import com.creativemd.cmdcam.CMDCam; import com.creativemd.cmdcam.CamEventHandler; import com.creativemd.cmdcam.movement.Movement; +import com.creativemd.cmdcam.utils.CMDPath; import com.creativemd.cmdcam.utils.CamPoint; import com.mojang.realmsclient.gui.ChatFormatting; @@ -83,6 +84,9 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam follow-speed " + ChatFormatting.RED + "default is 1.0")); sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam show " + ChatFormatting.RED + "shows the path using the given interpolation")); sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam hide " + ChatFormatting.RED + "hides the path using the given interpolation")); + sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam save " + ChatFormatting.RED + "saves the current path (including settings) with the given name")); + sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam load " + ChatFormatting.RED + "tries to load the saved path with the given name")); + sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam list " + ChatFormatting.RED + "lists all saved paths")); }else{ String subCommand = args[0]; if(subCommand.equals("clear")) @@ -145,7 +149,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args Integer index = Integer.parseInt(args[1])-1; if(index >= 0 && index < CMDCam.points.size()) { - CMDCam.points.remove(index); + CMDCam.points.remove((int) index); sender.sendMessage(new TextComponentString("Removed " + (index+1) + ". point!")); }else sender.sendMessage(new TextComponentString("The given index '" + args[1] + "' is too high/low!")); @@ -301,6 +305,37 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args }else sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam hide " + ChatFormatting.RED + "hides the path using the given interpolation")); } + if(subCommand.equals("save")) + { + if(args.length == 2) + { + CMDCam.savedPaths.put(args[1], new CMDPath()); + sender.sendMessage(new TextComponentString("Saved path '" + args[1] + "' successfully!")); + }else + sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam save " + ChatFormatting.RED + "saves the current path (including settings) with the given name")); + } + if(subCommand.equals("load")) + { + if(args.length == 2) + { + CMDPath path = CMDCam.savedPaths.get(args[1]); + if(path != null) + { + path.load(); + sender.sendMessage(new TextComponentString("Loaded path '" + args[1] + "' successfully!")); + }else + sender.sendMessage(new TextComponentString("Could not find path '" + args[1] + "'!")); + }else + sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam load " + ChatFormatting.RED + "tries to load the saved path with the given name")); + } + if(subCommand.equals("list")) + { + String output = "There are " + CMDCam.savedPaths.size() + " path(s) in total. "; + for (String key : CMDCam.savedPaths.keySet()) { + output += key + ", "; + } + sender.sendMessage(new TextComponentString(output)); + } } } diff --git a/src/main/java/com/creativemd/cmdcam/movement/OutsidePath.java b/src/main/java/com/creativemd/cmdcam/movement/OutsidePath.java index d5ea690..0e69153 100644 --- a/src/main/java/com/creativemd/cmdcam/movement/OutsidePath.java +++ b/src/main/java/com/creativemd/cmdcam/movement/OutsidePath.java @@ -53,6 +53,7 @@ public void processPoint(CamPoint point) ((EntityPlayer)camPlayer).capabilities.isFlying = true; camPlayer.setPositionAndRotation(point.x, point.y, point.z, (float)point.rotationYaw, (float)point.rotationPitch); camPlayer.setLocationAndAngles(point.x, point.y/*-mc.thePlayer.getEyeHeight()*/, point.z, (float)point.rotationYaw, (float)point.rotationPitch); + camPlayer.setRotationYawHead((float) 0); } } diff --git a/src/main/java/com/creativemd/cmdcam/utils/CMDPath.java b/src/main/java/com/creativemd/cmdcam/utils/CMDPath.java new file mode 100644 index 0000000..98205c2 --- /dev/null +++ b/src/main/java/com/creativemd/cmdcam/utils/CMDPath.java @@ -0,0 +1,38 @@ +package com.creativemd.cmdcam.utils; + +import java.util.ArrayList; +import java.util.List; + +import com.creativemd.cmdcam.CMDCam; + +public class CMDPath { + + public int loop; + public long duration; + public String path; + public String movement; + public Object target; + public List points; + public double cameraFollowSpeed; + + public CMDPath() { + this.loop = CMDCam.lastLoop; + this.duration = CMDCam.lastDuration; + this.path = CMDCam.lastPath; + this.movement = CMDCam.lastMovement; + this.target = CMDCam.target; + this.points = new ArrayList<>(CMDCam.points); + this.cameraFollowSpeed = CMDCam.cameraFollowSpeed; + } + + public void load() + { + CMDCam.lastLoop = this.loop; + CMDCam.lastDuration = this.duration; + CMDCam.lastPath = this.path; + CMDCam.lastMovement = this.movement; + CMDCam.target = this.target; + CMDCam.points = new ArrayList<>(this.points); + CMDCam.cameraFollowSpeed = this.cameraFollowSpeed; + } +}