Skip to content

JonathanLydall/JavaScript-Redstone-Simulator

Repository files navigation

Mordritch's JavaScript Redstone Simulator

This is the same code as used at http://mordritch.com/mc_rss/.

For now feel free to contact me with questions regarding how this all works.

Getting Up and Running

The following is my own personal environment which works for me on my Windows 10 computer. While I haven't tried or tested with anything else, the production website is presently running on a Linux host, so this should also all be doable on Linux or MacOS. Please feel free to submit pull requests to update this documentation as needed for other environments.

Prerequisites

  • Latest 7.x version of PHP
    • Download the x64 Non Thread Safe zip file and extracted it to a folder on my hard drive. Other versions may work, but haven't been tested.
    • Copy php.ini-development to php.ini.
    • In php.ini set the extension_dir to the full absolute path of the folder with php with /ext on the end.
    • In php.ini uncomment the lines with extension=mysqli and extension=mbstring and extension=fileinfo (this last one is only needed for router.php and not for production).
  • VS Code (Visual Studio Code)
    • In settings, configure php.executablePath to point to the full path of where php.exe is, for example C:\PHP\php.exe.
    • Add the following extensions following the configuration guides of each:
  • TypeScript compiler
    • Ensure you have Node installed.
    • npm install-g typescript
  • MySQL (Optional)
    • It's possible to test the simulator without a database setup as it's only needed for functionality such as authentication and reading/saving user data. Due to no immediate need, I haven't yet taken the time to work out how get the database up and running again on my machine along with documenting the process. In theory MariaDB should also be a viable option. I have included below a dump of the SQL Schema from MySQL workbench.

      SQL Schema
        ```sql
        -- MySQL Script generated by MySQL Workbench
        -- Sat Oct 27 11:34:36 2018
        -- Model: New Model    Version: 1.0
        -- MySQL Workbench Forward Engineering
      
        SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
        SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
        SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
        
        -- -----------------------------------------------------
        -- Schema mordritc_mcrss
        -- -----------------------------------------------------
        CREATE SCHEMA IF NOT EXISTS `mordritc_mcrss` DEFAULT CHARACTER SET utf8 ;
        USE `mordritc_mcrss` ;
      
        -- -----------------------------------------------------
        -- Table `mordritc_mcrss`.`persistantsessions`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mordritc_mcrss`.`persistantsessions` (
        `id` INT(11) NOT NULL AUTO_INCREMENT,
        `userId` INT(11) NOT NULL,
        `cookieString` VARCHAR(64) NOT NULL,
        `lastIp` VARCHAR(45) NOT NULL,
        `lastLogin` DATETIME NOT NULL,
        PRIMARY KEY (`id`))
        ENGINE = InnoDB
        AUTO_INCREMENT = 7803
        DEFAULT CHARACTER SET = latin1;
      
      
        -- -----------------------------------------------------
        -- Table `mordritc_mcrss`.`schematics`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mordritc_mcrss`.`schematics` (
        `id` INT(11) NOT NULL AUTO_INCREMENT,
        `userId` INT(11) NULL DEFAULT NULL,
        `derivedFromId` INT(11) NULL DEFAULT NULL,
        `authorName` VARCHAR(32) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL,
        `email` VARCHAR(128) CHARACTER SET 'latin1' NULL DEFAULT NULL,
        `password` VARCHAR(60) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL,
        `passwordResetToken` VARCHAR(128) CHARACTER SET 'latin1' NULL DEFAULT NULL,
        `filename` VARCHAR(64) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
        `fileSize` BIGINT(20) NOT NULL,
        `title` VARCHAR(128) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
        `description` TEXT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL,
        `firstCreated` DATETIME NOT NULL,
        `lastModified` DATETIME NOT NULL,
        `dataBlob` MEDIUMBLOB NOT NULL,
        PRIMARY KEY (`id`))
        ENGINE = InnoDB
        AUTO_INCREMENT = 6931
        DEFAULT CHARACTER SET = utf8
        COLLATE = utf8_unicode_ci;
      
      
        -- -----------------------------------------------------
        -- Table `mordritc_mcrss`.`schematics_tempholder`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mordritc_mcrss`.`schematics_tempholder` (
        `id` INT(11) NOT NULL AUTO_INCREMENT,
        `timestamp` DATETIME NOT NULL,
        `data` MEDIUMBLOB NOT NULL,
        `fileName` VARCHAR(256) NULL DEFAULT NULL,
        PRIMARY KEY (`id`))
        ENGINE = InnoDB
        AUTO_INCREMENT = 5
        DEFAULT CHARACTER SET = latin1;
      
      
        -- -----------------------------------------------------
        -- Table `mordritc_mcrss`.`users`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `mordritc_mcrss`.`users` (
        `id` INT(11) NOT NULL AUTO_INCREMENT,
        `emailAddress` VARCHAR(45) CHARACTER SET 'latin1' NOT NULL,
        `displayName` VARCHAR(45) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
        `passwordHash` VARCHAR(60) CHARACTER SET 'latin1' NULL DEFAULT NULL,
        `passwordResetToken` VARCHAR(60) CHARACTER SET 'latin1' NULL DEFAULT NULL,
        `emailVerified` TINYINT(1) NOT NULL DEFAULT '0',
        `lastLogin` DATETIME NULL DEFAULT NULL,
        `loginCount` INT(11) NULL DEFAULT '0',
        `optionsBlob` BLOB NULL DEFAULT NULL,
        `bindingsBlob` BLOB NULL DEFAULT NULL,
        `userSettingsBlob` BLOB NULL DEFAULT NULL,
        PRIMARY KEY (`id`))
        ENGINE = InnoDB
        AUTO_INCREMENT = 2581
        DEFAULT CHARACTER SET = utf8
        COLLATE = utf8_unicode_ci;
      
      
        SET SQL_MODE=@OLD_SQL_MODE;
        SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
        SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
        ```
      

Compiling the code

Compile artifacts and the node_modules folder are in the .gitignore file, so even if the webserver is set up, the project will not run until the following two steps have been performed:

  • npm -i in your console. Required by TypeScript files which are using @types packages.
  • Running the a tsc task against the code's tsconfig.ts. The easiest way to do this in VS Code is to press Ctrl+Shift+B and then select tsc: watch - tsconfig.json. This will perform an immediate compile of all the files and then watches the files to automatically recompile them any time they change.

Running the Website

Inside the repository, /.vscode/tasks.json has a task which I have configured to run the PHP command line built-in web server. To run this task in VS Code, open the Command Palette (Ctrl+Shift+P), search for Tasks: Run Task, then select run php server, and then finally select Continue without scanning the output. The web server is now running in a terminal window and you can open the website in your browser at http://localhost:8088/. You can use Ctrl-C in the VS Code Terminal to stop the server or use the Bin icon near the top right of the pane.

Debugging the backend PHP

Ensure the PHP Debug VS Code extension is installed and properly configured. You can now start debugging in VS Code through the Debug menu or by using the F5 shortcut. If prompted to choose which debugger to run, then choose Listen for XDebug. You can now toggle breakpoints by clicking in the margin of a line of code or by using the F9 shortcut key.

Debugging the frontend JavaScript

I personally use Google Chrome's built in Development Tools which are available inside Google Chrome by using the F12 shortcut while browsing the website which you want to debug.

I'm sure there are ways in VS Code to attach it to Chrome for debugging, but I haven't looked into this at all, but if you know/find out how to do this and are prepared to update this readme with the relevant steps, I would be happy to accept such a pull request.

Using saved schematics to make testing of simulator behaviour easier

Often when testing the simulator's behaviour, it is often for a certain arrangement of blocks, and relaying out the blocks after each page refresh can quickly become quite tedious. So I have set up the development environment to be able to retrieve schematics straight from the production website, it is also useful for debugging uploaded schematics which don't seem to be working properly.

Create the layout of blocks that you want to test on the production website at https://mordritch.com/mc_rss/ and save it. It will be assigned an ID and it automatically updates the URL to be something like https://mordritch.com/mc_rss/1001, where 1001 is the unique ID of the schematic that was saved. You can then use this same URL scheme on your development environment to load that schematic, for example http://localhost:8088/1001. You can now refresh the browser page as often as you like and it will always automatically load up that schematic.

Roadmap

Move everything over to TypeScript

I have been wanting to port this over pretty much since TypeScript was released and since then TypeScript and its' tooling has only gotten better. This is something I will slowly be doing on the side, but I have many other commitments at the moment which make it a challenge to find the time.

(All the below was written back in 2013 and isn't all applicable with advances in available tooling. I have no immediate plans at this time to personally do any additional drastic changes to this code base as mentioned below.)

Seperate drawing logic out of same source files as block logic

Drawing logic used to live in the same source files as the block logic which was ported from the original game's source code. Part of my "glue" operation above is establishing a pattern for self contained draw routines which can also be interchaged which will enable use of different display themes.

Generate a tool which can take Minecraft's Java source files and convert their logic into JavaScript / TypeScript

Because the current block logic is essentially just a JavaScript port from the game's Java source code, a tool to automatically port the source will make it far easier to update the simulator anytime Minecraft changes.

This tool is now at a "good enough" stage and meets the needs of the project. It was an exceptionally interesting, but also long excercise. The end result is largely automatic conversion of Java syntax files to TypeScript syntax files, but with configuration to limit which methods and properties are ignored/converted.

Adding more of the games block types

My initial goal is to release the tool with the same block types as it has now but updated to the latest Minecraft version, then incrementally add more block types.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •