Fredashay's Ship Time 3.0

This plugin will calculate how long it takes for a starship to travel to a destination.

  1. Fredashay
    Tested Minecraft Versions:
    • 1.16
    Contributors:
    Fredashay
    This plugin will calculate how long it takes for a starship to travel to a destination.

    As with my Metric Time plugin, this is a rewrite of a program I wrote in college many years ago in Turbo Pascal 3.0.

    I had written a number of science fiction stories and wanted to know how long it would take a spaceship to reach various distant stars if it accelerated at a constant 1G to the halfway point, turned nose-over-ass, and decelerated at a constant 1G to the destination.

    To my surprise, you could travel almost anywhere within our Milky Way galaxy within a few years doing this (at least if Einstein hadn't gone and screwed it all up with his relativity theory and light speed limit).

    Further, I reasoned that if a nuclear aircraft carrier or submarine could travel the world for years and carry enough food for the crew, then why couldn't a starship do the same? It takes a tremendous amount of energy to push a gimungous aircraft carrier through the water at high speed. Accelerating a spaceship of far less mass for a few years non-stop should be trivial in comparison.

    At least, if I could make that argument sound plausible, it would be good enough for a science fiction story, right?

    So anyway, I dug up that old Pascal program and converted it to a Minecraft Spigot Java plugin.

    It bases its calculation on the formula:

    Code (Text):

           _____       _____
           / (2d)      / (2d)
    t  =  /  ----  =  /  ----  =  SQRT ((2d) / 9.8)
         V    a      V    9.8
     
    Where:
    t = time in seconds.
    d = distance in meters.
    a = accelerations in meters per second squared, which we use a constant value of 9.8, which is 1g on Earth and is the constant acceleration of our fictional starship.

    In English, these are the steps:

    1. Multiply the distance (in meters) by 2.
    2. Divide that by 9.8 (1g on earth).
    3. Take the square root of that.
    4. You have travel time in seconds.

    The trouble with this is you will arrive at your destination, and zoom by, at close to the speed of light. To solve that, you must calculate the time to travel half the distance then flip your ship bass-ackwards and double that time and calculate the time to travel the remaining distance. And if you're writing a sf story (as I was) knowing the distance and time to the midway point is an important detail.

    If your input is in light years, you'll need to multiply by 9460000000000 to get kilometers, and then multiply the kilometers by 1000 to get meters (this will be a really big number!).

    If you want your output in something more understandable such as years and days, you'll need to do some simple arithmetic on the seconds to convert them to years and days.

    This plugin is for entertainment purposes only. Do not use this plugin to navigate your starship. It does not take time dilation or other relativistic effects into account.

    To install this plugin, copy the plugin JAR file to your server's plugins folder.

    Code (Text):

    package FredashaySpigotShipTime;

    /* As with my Metric Time plugin, this is a rewrite of a program I wrote in college many years
     * ago in Turbo Pascal 3.0.
     *
     * I had written a number of science fiction stories and needed to know how long it would take a
     * spaceship to reach various distant stars if it accelerated at a constant 1G to the halfway point,
     * turned nose-over-ass, and decelerated at a constant 1G to the destination.
     *
     * To my surprise, you could travel almost anywhere within our Milky Way galaxy within
     * a few years doing this (at least if Einstein hadn't gone and screwed it all up with his
     * relativity theory and light speed limit).
     *
     * Further, I reasoned that if a nuclear aircraft carrier or submarine could travel the
     * world for years and carry enough food for the crew, then why couldn't a starship do
     * the same?  It takes a tremendous amount of energy to push a gimungous aircraft carrier
     * through the water.  Accelerating a spaceship of far less mass for a few years non-stop
     * should be trivial in comparison.
     *
     * At least, if I could make that argument sound plausible, it would be good enough
     * for a science fiction story, right?
     *
     * So anyway, I dug up that old Pascal program and converted it to a Minecraft
     * Spigot Java plugin.
     *
     * It bases its calculation on the formula:
     *         _____       _____
     *        / (2d)      / (2d)
     * t  =  /  ----  =  /  ----  =  SQRT ((2d) / 9.8)
     *      V    a      V    9.8
     *
     * Where:
     *       t = time in seconds.
     *       d = distance in meters.
     *       a = accelerations in meters per second squared, which we use a constant
     *           value of 9.8, which is 1g on Earth and is the constant acceleration
     *           of our fictional starship.
     *      
     * In English, these are the steps:
     *
     * 1. Multiply the distance (in meters) by 2.
     * 2. Divide that by 9.8 (1g on Earth).
     * 3. Take the square root of that.
     * 4. You have travel time in seconds.
     *
     * The trouble with this is you will arrive at your destination, and zoom by, at close to the
     * speed of light.  To solve that, you must calculate the time to travel half the distance
     * then flip your ship bass-ackwards and double that time and calculate the time to travel
     * the remaining distance.  In truth, the result will be exactly the same whether we calculate
     * the total time given the total distance, or we double the time we calculated for traveling
     * half the distance (rounding errors might vary the two results by an insignificant amount).
     * But if you're writing a sf story (as I was) knowing the distance and time to the midway
     * point is an important detail.  
     *
     * If your input is in light years, you'll need to multiply by 9460000000000 to get kilometers,
     * and then multiply the kilometers by 1000 to get meters (this will be a really big number!).
     *
     * If you want your output in something more understandable such as years and days, you'll
     * need to do some simple arithmetic on the seconds to convert them to years and days.
     *
     * This plugin is for entertainment purposes only.  Do not use this plugin to
     * navigate your starship.  It does not take time dilation or other relativistic
     * effects into account.
     *
     * I have included the original Pascal program at the end.
     */

    import java.util.logging.Logger;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;

    public class MyPlugin extends JavaPlugin implements Listener, CommandExecutor {

       private static Logger logger = null;
       private static PluginDescriptionFile pdfFile = null;
     
       @Override
        public void onEnable() {
           pdfFile = getDescription();
           getServer().getPluginManager().registerEvents(this,this);
           logger = Logger.getLogger("Minecraft");
            }
     
       @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
           double total_distance_ly = 0;
           double total_distance_km = 0;
           double total_distance_m = 0;
           double midway_distance_m = 0;
           double midway_time_s = 0;
           double midway_time_m = 0;
           double midway_time_h = 0;
           double midway_time_d = 0;
           double total_time_d = 0;
           double total_time_y = 0;
           if (label.equalsIgnoreCase("shiptime")) {
               if (args.length > 0) {
                   if (isNumeric(args[0])) {
                       total_distance_ly = Math.abs(toDouble(args[0]));
                       if (sender instanceof Player) {
                           Player player = (Player) sender;
                           logger.info ("[ShipTime] Player '" + player.getName() + "' invoked /SHIPTIME . ");
                           }
                       logger.info ("[ShipTime] " + total_distance_ly + " light years to destination. ");
                        total_distance_km = total_distance_ly * 9460000000000.0d;                  
                        logger.info ("[ShipTime] " + total_distance_km + " kilometers to destination. ");
                        total_distance_m = total_distance_km * 1000.0d;
                        logger.info ("[ShipTime] " + total_distance_m + " meters to destination. ");
                        midway_distance_m = total_distance_m / 2.0d;
                        logger.info ("[ShipTime] " + midway_distance_m + " meters to mid-point. ");
                        midway_time_s = Math.sqrt((2.0d * midway_distance_m) / 9.80665d);                     // t=sqrt(2d/a)
                        logger.info ("[ShipTime] " + midway_time_s + " seconds to mid-point. ");
                        midway_time_m = midway_time_s / 60d;
                        logger.info ("[ShipTime] " + midway_time_m + " minutes to mid-point. ");
                        midway_time_h = midway_time_m / 60d;
                        logger.info ("[ShipTime] " + midway_time_h + " hours to mid-point. ");
                        midway_time_d = midway_time_h / 24d;
                        logger.info ("[ShipTime] " + midway_time_d + " days to mid-point. ");
                        total_time_d = midway_time_d * 2d;
                        logger.info ("[ShipTime] " + total_time_d + " days to destination. ");
                        total_time_y = total_time_d / 365d;
                        logger.info ("[ShipTime] " + total_time_y + " years to destination. ");
                       if (sender instanceof Player) {
                           Player player = (Player) sender;
                           int int_y = (int) total_time_y;
                           double double_y = int_y;
                           double double_d = total_time_y - double_y;
                           double_d = double_d * 365;
                           int int_d = (int) double_d;
                           player.sendMessage("<ShipTime> It will take your ship " + int_y + " years and " + int_d + " days to travel " + total_distance_ly + " light years, assuming you accelerate at 1g (9.8 m/sec^2) to the halfway point, flip your ship over, and decelerate at 1g to the desination.  Thank you for using Fredashay's ShipTime plugin! ");
                           }                                          
                       }
                   else {
                       Player player = (Player) sender;
                       player.sendMessage("<ShipTime> Lightyears must be a number. ");
                       }
                   }
               else if (sender instanceof Player) {
                   Player player = (Player) sender;
                   player.sendMessage("<ShipTime> ShipTime will calculate the time needed for your starship to travel a given number of light years assuming you accelerate at 1G half-way, turn over, and decelerate at 1G to the destination.  Please issue /SHIPTIME [lightyears] . ");          
                   }
               return(true);
               }
           return(false);
           }
     
       public boolean isNumeric(String string) {
           double number = 0;
           if (number == 0) {
               try {      
                   number = Double.parseDouble(string);          
                   }
               catch(NumberFormatException oops) {
                   return (false);
                   }
               }
           return (true);
           }
     
       private double toDouble(String string) {
           double number = 0;
           try {
               number = Double.parseDouble(string.trim());
               }
           catch (NumberFormatException oops) {
               System.out.println("[" + pdfFile.getName() + "] We tried to convert '" + string + "' to a long number; it didn't end well.  ");
               System.out.println(oops.getMessage());
               oops.printStackTrace(System.err);
               number = 0;
               }
           return (number);
           }
                   
       /*
       PROCEDURE MAIN;
        VAR DISTANCE_TEXT:          STRING255;
        VAR DISTANCE_LY_REAL:       REAL;
        VAR DISTANCE_KM_REAL:       REAL;
        VAR DISTANCE_M_REAL:        REAL;
        VAR DISTANCE_HALF_M_REAL:   REAL;
        VAR TEMP_REAL:              REAL;
        VAR TIME_HALF_S_REAL:       REAL;
        VAR TIME_HALF_M_REAL:       REAL;
        VAR TIME_HALF_H_REAL:       REAL;
        VAR TIME_HALF_D_REAL:       REAL;
        VAR TIME_D_REAL:            REAL;
        VAR TIME_Y_REAL:            REAL;
        BEGIN
            INITIALIZE;
            RANDOMIZE;
            CLEAR (BLACK);
            DISTANCE_TEXT := ASK_TEXT ('ENTER DISTANCE IN LIGHT YEARS: ', 32);
            DISTANCE_LY_REAL := STRNUM (DISTANCE_TEXT);
            PUTSTRING ('DISTANCE IS ' + FORMAT (NUMSTR (DISTANCE_LY_REAL)) + ' LIGHT YEARS' + CR);
            DISTANCE_KM_REAL := DISTANCE_LY_REAL * 9460000000000;
            PUTSTRING ('DISTANCE IS ' + FORMAT (NUMSTR (DISTANCE_KM_REAL)) + ' KILOMETERS' + CR);
            DISTANCE_M_REAL := DISTANCE_KM_REAL * 1000;
            PUTSTRING ('DISTANCE IS ' + FORMAT (NUMSTR (DISTANCE_M_REAL)) + ' METERS' + CR);
            DISTANCE_HALF_M_REAL := DISTANCE_M_REAL / 2;
            PUTSTRING ('HALF DISTANCE IS ' + FORMAT (NUMSTR (DISTANCE_HALF_M_REAL)) + ' METERS' + CR);
            TIME_HALF_S_REAL := SQRT ((2 * DISTANCE_HALF_M_REAL) / 9.8);  
            PUTSTRING ('TIME TO TURNOVER IS ' + FORMAT (NUMSTR (TIME_HALF_S_REAL)) + ' SECONDS' + CR);
            TIME_HALF_M_REAL := TIME_HALF_S_REAL / 60;
            PUTSTRING ('TIME TO TURNOVER IS ' + FORMAT (NUMSTR (TIME_HALF_M_REAL)) + ' MINUTES' + CR);
            TIME_HALF_H_REAL := TIME_HALF_M_REAL / 60;
            PUTSTRING ('TIME TO TURNOVER IS ' + FORMAT (NUMSTR (TIME_HALF_H_REAL)) + ' HOURS' + CR);
            TIME_HALF_D_REAL := TIME_HALF_H_REAL / 24;
            PUTSTRING ('TIME TO TURNOVER IS ' + FORMAT (NUMSTR (TIME_HALF_D_REAL)) + ' DAYS' + CR);
            TIME_D_REAL := TIME_HALF_D_REAL * 2;
            PUTSTRING ('TIME TO DESTINATION IS ' + FORMAT (NUMSTR (TIME_D_REAL)) + ' DAYS' + CR);
            TIME_Y_REAL := TIME_D_REAL / 365;
            PUTSTRING ('TIME TO DESTINATION IS ' + FORMAT (NUMSTR (TIME_Y_REAL)) + ' YEARS' + CR);
            END;
       */
           
        }
     
    Govindas likes this.

Recent Updates

  1. Recompiled for 1.16