Skip to content

Commit

Permalink
Added ability to save/ load paths during runtime (will be deleted aft…
Browse files Browse the repository at this point in the history
…er restart)

Fixed being unable to remove points
  • Loading branch information
CreativeMD committed Feb 5, 2018
1 parent f2be844 commit c9a3001
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
4 changes: 4 additions & 0 deletions 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;
Expand Down Expand Up @@ -44,6 +46,8 @@ public class CMDCam {

public static double cameraFollowSpeed = 1D;

public static HashMap<String, CMDPath> savedPaths = new HashMap<>();

@EventHandler
public void Init(FMLInitializationEvent event)
{
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/com/creativemd/cmdcam/command/CamCommand.java
Expand Up @@ -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;

Expand Down Expand Up @@ -83,6 +84,9 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam follow-speed <number> " + ChatFormatting.RED + "default is 1.0"));
sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam show <all:" + String.join(":", Movement.getMovementNames()) + "> " + ChatFormatting.RED + "shows the path using the given interpolation"));
sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam hide <all:" + String.join(":", Movement.getMovementNames()) + "> " + ChatFormatting.RED + "hides the path using the given interpolation"));
sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam save <name> " + ChatFormatting.RED + "saves the current path (including settings) with the given name"));
sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam load <name> " + 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"))
Expand Down Expand Up @@ -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!"));
Expand Down Expand Up @@ -301,6 +305,37 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
}else
sender.sendMessage(new TextComponentString("" + ChatFormatting.BOLD + ChatFormatting.YELLOW + "/cam hide <all:" + String.join(":", Movement.getMovementNames()) + "> " + 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 <name> " + 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 <name> " + 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));
}
}
}

Expand Down
Expand Up @@ -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);
}

}
38 changes: 38 additions & 0 deletions 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<CamPoint> 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;
}
}

0 comments on commit c9a3001

Please sign in to comment.