Someone on my team needed to create a ton of SQL insert statements to create some test data. We actually have a tool that does this, but he needed to pull data from a complex query with multiple joins and other nasty stuff. The insert statement that he needed was only 3 columns, but he had to insert a lot of data and didn’t want to write the insert scripts manually.
Stupid Dev Trick #1 to the Rescue
I showed him the super special column combinitorial power of a spread sheet copy and paste. With this he was able to create the insert statements in less than the time it took to write the query to get the data.
Here is the gist of the trick. Open a spread sheet, in the first column write the first half of the insert statement you want to produce, up to the point that you need to add your data:
| INSERT INTO Table1 (Column1, Column2, Column3) VALUES ( |
Then run your query and copy the first column of data into Column 2.
| Datavalue 1 | | Datavalue 2 | | Datavalue 3 | | remaining...|
Next add a comma in Column 3 next to each data value (use copy and paste), then do the same for the remaining values from your query results. Finally in the last columns close the insert statement.
| INSERT INTO Table1 (Column1... | Datavalue 1 | , | Other value 1 | ) | | INSERT INTO Table1 (Column1... | Datavalue 2 | , | Other value 2 | ) | | INSERT INTO Table1 (Column1... | Datavalue 3 | , | Other value 3 | ) | | INSERT INTO Table1 (Column1... | remaining...| , | remaining.... | ) |
Next copy the insert statement you wrote in column 1 to each row. Then you can just copy all of the columns to a text editor or SQL Management Studio in my case and the columns will be magically turned into white space and ready for running.
INSERT INTO Table1 (Column1, Column2, Column3) VALUES ( Datavalue 1, Other value 1 ) INSERT INTO Table1 (Column1, Column2, Column3) VALUES ( Datavalue 2, Other value 2 ) ...
I have used this stupid trick and variations thereof to save a ton of time to produce one-off solutions. Yes, it would be better to create a script or update our test data extraction tool to handle this, but with the pressure of time and not wanting to solve edge cases, this stupid trick is actually smart when you can’t squeeze another brain cell for a quick idea and you have nothing else up your sleeve.
Why Mod Minecraft
My kids love Minecraft. Actually, love is too weak a word. They are always asking me to get this mod and that skin and they are just sooo passionate about this game. They watch YouTube videos of mod developers showing off their new mods and it occurred to me that I could probably make a mod. I mean I am a software engineer. It’s just Java. Mind you, I haven’t touched Java in many years, but its object oriented programming, how different is it from C#. So, I told my kids what I wanted to do and that I would need there help and they were very excited. This gives me a chance to discover something they are into and I get to introduce them to programming… win-win. And the adventure begins.
Java Development Environment
The first order of business is to get a Java Development environment up and running. I decided on Eclipse as my IDE as it comes highly recommended and has an awesome community. Below is what I installed.
Java JDK (Java Development Kit) – I downloaded JDK 7 – http://www.oracle.com/technetwork/java/javase/downloads/index.html
Java JRE (Java Runtime Environment) – this actually came with the JDK and I already had it installed.
Eclipse – I downloaded the standard – http://www.eclipse.org/downloads/
While at it I decided to round out my Dev Rig with JUnit for testing and a private GitHub account for source control (I will open it up to the public when I have something that won’t crash and burn). You will also see later in this post that I also added a build server, Gradle, and some JAVA functional programming goodness with Scala. If I’m going to do this I’m going all out.
The Minecraft loader is the program that launches the Minecraft game. You purchase the loader on minecraft.net.
Minecraft Forge is a Minecraft Mod Loader and API. As I understand it right now, it is a wrapper around the official Minecraft game that allows you to load mods (modifications). Forge provides a simplified API for working with the Minecraft source code to make mods. The Forge Mod Loader allows you to load mods made with the Forge API.
I decided on Minecraft Forge as it seemed to have a good community. I wanted to use something called MCP, which from what I understand, Forge actually uses MCP for decompilation of the Minecraft source. Although, I also read that Forge is working on their own decompiler. I didn’t use MCP because I got frustrated as I am a noob and couldn’t figure some things out in the install process. Plus, the kids tell me that Forge has the cool mods.
Anyway you download the latest version of Forge for your version of Minecraft, but I was told by a community member that version 1.6.4 had the most mods at the time I wrote this. Minecraft.exe currently defaults the game version to 1.7.4 and Forge is at 1.7.2 and this gave me the biggest headache trying to get the two to work together until I figured out you can edit your Minecraft profile in the loader and select the version you want to play (this would have fixed my MCP issue too). So let’s get Minecraft 1.6.4 working with Forge 1.6.4. So here is how I got the Forge loader working:
- Launch Minecraft
- Update profile to use the 1.6.4 version and save it
- Click the Play button (this sets up the 1.6.4 files that are needed for Forge)
- Then download the recommended Forge 1.6.4 installer from http://files.minecraftforge.net/
- Run the installer
- Click windows start key plus R to open the run dialog and type %appdata% and click OK (you can also type this in Windows explorer)
- Open .minecraft folder, this holds all of the Minecraft assests
- Open the version folder
- Open the Forge folder for the Forge version you downloaded and copy the two files
- Go back to the version folder and create a new folder and name it whatever you want (remember this name you will need it)
- Open the folder and paste the files you copied
- Rename both files to the same name you used for the folder
- Open the file with extension .json and find the ID field and change it to the name you used for the folder and save
- Launch Minecraft
- Update profile to use the version that matches the name of the new version folder and save it
- Click the Play button
- You will be running the new Forge mod loader you just installed and you can add new Forge based mods to it by copying the mod zip files to the mod folder in the .minecraft folder (make sure your mods match the version you are running or it will crash and burn)
Mod Development Setup
Now we will continue with our Development Environment setup to get it ready for mod development.
- Download the recommended Forge 1.6.4 src from http://files.minecraftforge.net/ (you can get whatever version of Minecraft you want to develop for)
- Extract the zip to a folder any where you want
- Then open the folder and run the install.cmd
- After the install completes, open Eclipse
- Select a workspace by browsing to your Forge install, mcp/eclipse folder and click OK
This will import the Minecraft source code into the IDE and you can get to work modding your Minecraft world.The install took awhile so you can take a break when you start the install.
During the Forge install I noticed in the command window that it is working with MCP and it does a lot of decompiling, updating, and recompiling of the Mincecraft source code. I also noticed a message: “scalac” is not found on the PATH. Scala files will not be recompiled. I am not sure if I will need to use Scala, but I always wanted to use Scala so this is a good a time as any to get it set up in my Java Environment. I downloaded the Scala installer from http://www.scala-lang.org/ and I allowed the setup to update my system path variables. I didn’t feel like reruning the Forge installer so hopefully I won’t need the recompiled Scala files for basic learning.
In earlier versions of Forge you had to use the Gradle Build Server to setup your source code and Eclipse for development. Even though it isn’t necessary in the version I am using I still setup Gradle because it seems very cool, well Geek Cool. I really need to look into Gradle more for my .Net environment as they have some very interesting concepts for build environments. Anyway, you can install Gradle from http://www.gradle.org/downloads. You can just unzip to some location on your machine. Then copy the path to the Gradle bin folder and add it to your system path environment variable. That’s it, you have a Java build server.
I want to host our mods in our own Minecraft server, but I ran into the version issue again. I have 1.7.4 server, but my mods will be 1.6.4. Well with a little URL hacking you can download the 1.6.4 version of the server from the Minecraft download server. This is the same server jar URL as the latest release, I just change the release from 1.7.4 to 1.6.4. https://s3.amazonaws.com/Minecraft.Download/versions/1.6.4/minecraft_server.1.6.4.jar
That’s if for now, I will try to post some of my modding experience later. I am in a very strange land, but I think it will be great doing something both constructive and fun with my kids.
Welcome to my temporary home. Normally, I blog at charlesbryant.com, but because my former host basically SUCKS!!!!! I have to start all over again and I don’t feel like the hunt for a host, WordPress setup, config and repost of all of my blog posts manually. So, here I am. Hopefully, I can easily get these posts to their permanent home without a fight.
Thanks for stopping by and I hope that I helped you in some way. Drop me a line in the comments if you would like to discuss anything I have posted.